Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor experience with (use-package :ensure t ... :straight ...) #425

Closed
ieure opened this issue Oct 24, 2019 · 5 comments
Closed

Poor experience with (use-package :ensure t ... :straight ...) #425

ieure opened this issue Oct 24, 2019 · 5 comments

Comments

@ieure
Copy link

ieure commented Oct 24, 2019

I moved my Emacs config over to use-package earlier this year to improve startup times, and am trying out straight.el this week to better keep things in sync across machines.

I have a few packages I've written that I haven't gotten around to submitting to MELPA, and these are presenting problems for me. My assumption was that if I provided a recipe, straight.el would use it to install the package, and that would be that. However, there's a bad interaction with use-package.

Here's an example:

(use-package nssh
  :defer t
  :ensure t
  :straight (nssh :host github
                  :repo "ieure/nssh-el"
                  :tag "v0.9.10"))

When I eval this, my package archives are refreshed:

Importing package-keyring.gpg...done
Contacting host: stable.melpa.org:80 [2 times]
Contacting host: elpa.gnu.org:443
Package refresh done

And then I get this warning:

Error (use-package): Failed to install nssh: Package ‘nssh-’ is unavailable

Despite all that, my package is installed and works fine:

phaktory!ieure:~$ ls -ld ~/.emacs.d/straight/repos/nssh-el
drwxr-xr-x 1 ieure ieure 40 Oct 24 13:39 /home/ieure/.emacs.d/straight/repos/nssh-el/

However, this unacceptably delays Emacs initialization, as it refreshes packages multiple times (once per recipe which doesn't exist in package-archives) and spams the fresh Emacs with *Warnings*.

A similar experience can be had if you use-package anything which isn't available in package-archives, for example if you remove GNU ELPA and try to install exwm.

The issue appears to be that :ensure t causes use-package to install via package.el, even though :straight ... causes installation via the provided recipe.

It would be ideal if :ensure t was ignored when :straight was provided, but failing that, a warning or item in the documentation would be welcome.

@vyp
Copy link
Contributor

vyp commented Oct 25, 2019

I think it might be use-package handling the :ensure t, not straight.el.

@ieure
Copy link
Author

ieure commented Oct 25, 2019

I think it might be use-package handling the :ensure t, not straight.el.

It is.

@vyp
Copy link
Contributor

vyp commented Oct 25, 2019

So I'm not sure if straight.el can do anything about this. I think you just have to comment out any :ensure t anytime you add a :straight form, and uncomment it if you want to switch back. Readme already has this which mentions removing any :ensure t:

You should remove any code that relates to package.el; for example, references to package-initialize, package-archives, and (if you're using use-package) :ensure or use-package-always-ensure. While it is technically possible to use both package.el and straight.el at the same time, there is no real reason to, and it might result in oddities like packages getting loaded more than once.

Isn't that already suggesting incompatibility between :ensure t and :straight? Or how do you think it could be made clearer?

@raxod502
Copy link
Member

The issue appears to be that :ensure t causes use-package to install via package.el, even though :straight ... causes installation via the provided recipe.

Yes. If you provide :straight, you are explicitly requesting the package to be installed via straight.el. If you provide :ensure, you are explicitly requesting the package to be installed via package.el. If you provide both, well, you get what you asked for. That's why the documentation for straight.el suggests to remove all traces of :ensure from your init-file.

I will also point out that straight.el doesn't really have anything to do with your original problem. If you removed :straight from (use-package nssh :ensure t ...) then you'd get exactly the same startup delay and warnings.

It would be ideal if :ensure t was ignored when :straight was provided, but failing that, a warning or item in the documentation would be welcome.

As per your suggestion, I made it so that :ensure is ignored when :straight is provided. Let me know what you think.

@progfolio
Copy link
Contributor

Let me know what you think.

Looks like it's working fine to me!

vidbina added a commit to vidbina/org-hyperscheduler that referenced this issue May 3, 2022
* Avoiding ensure and straight in the same use-package sexp

The use of the `:ensure` and `:straight` keywords in the same use-package call
is discouraged by the author of straight (see
radian-software/straight.el#425 (comment)) and
thus I propose removing the =:ensure t= bit to avoid confusion.

* Formatting with a focus on readability

Furthermore, I just aligned the sexp within the block (which removed some
leading whitespace 🤷🏿‍♂️ (sorry for the larger diff). What is perhaps more
useful, is the space that I added before `:repo` to trick the emacs indenter to
format the sexp in a manner that more clearly outlines the relationship between
the keywords (siblings, same level) which kind of gets lost in the older
indentation.

```elisp
(use-package org-hyperscheduler
  :ensure t
  :straight
  (:repo "dmitrym0/org-hyperscheduler"
         :host github
         :type git
         :files ("*")))
```

I considered rephrasing the value of the `straight` keyword to the _long-form_:

```elisp
(org-hyperscheduler :repo "dmitrym0/org-hyperscheduler"
                    :host github
                    :type git
                    :files ("*"))
```

instead of the current _short-form_:

```elisp
( :repo "dmitrym0/org-hyperscheduler"
  :host github
  :type git
  :files ("*"))
```

but since the straight README
https://github.com/raxod502/straight.el#integration-with-use-package-1 outlines
that the _short-form_ macroexpands to contain the _package name_ (which looks
more like the _long-form_, I have no reason to be difficult and poke the bear
so, I'm leaving this alone.
KarlJoad added a commit to KarlJoad/Emacs_dotfiles that referenced this issue Dec 8, 2023
According to
radian-software/straight.el#425 (comment),
using use-package's :ensure property directly conflicts with
straight.el's :straight property.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants