-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
How do I uninstall packages that have been removed from pyproject.toml? #648
Comments
I am not sure I understand. Why would your packages no longer be in |
Actually I just realized Here I remove a package from en1 and then switch to env2 and attempt to remove it from there and it fails
|
Oh. I think I understand. You update the lock locally and then deploy. Is that right? |
Because I have many virtualenvs - one per EC2 instance. So I copy over my poetry.lock and want to sync each virtualenv using that poetry.lock, adding/upgrading/removing packages as needed to keep the virtualenv in sync (similar to how |
We have this problem using Poetry as well. One developer |
The README mentions Edit: I have found that I can run |
Same here. Recreating a virtual environment each and every time is time consuming and unless it can happen automatically when checking out a branch, developers aren't going to do it. |
Another use-case for this is CI build caching. If you remove dependency in a branch and the CI build for that branch pulls from a cache that still has that dependency, I definitely want it removed. This is how Yarn works which is important because then This ticket is in conflict with #533 (though AFAICT Poetry indeed does not uninstall dependencies, so not sure what that ticket's about). |
It looks like if this line would loop over the installed packages, that it would result in obsolete packages to be cleaned up. I'm trying see what it does if I changed it, but I can't seem to get poetry running from it's own git repo inside PyCharm's debugger 🤔 |
@kevinkjt2000 AFAICT the only references to |
I did an attempts in pull request #1037 to remove obsolete packages when running |
@jobec a couple of comments if you don't mind: |
First of all, the PR is just a beginning. It's no where near finished nor fine tuned. And I'm open for all feedback.
|
a) I assert that it is a good default, though that depends on if (per my earlier comment) you view "install" to mean "make my build reproducible" (as I do) rather than "make sure I have all the dependencies I need" (which is a good start, but incomplete). Regarding point (c). From the linked comment:
The semantics of this use case seem weird and difficult. If the "temporary" package has overlapping dependencies with non-temporary packages, what happens? Does it change the versions of the common dependencies? If so, does it update the lock file? Does it instead just fail outright? The OP on that issue says:
In node, the accepted solution for this use-case is either (1) install it globally since it's not relevant to the project at hand or (2) install it as part of the project because you use it to develop the project (and hence it is a dev dependency). It seems to me that trying to support a third, middle road is likely to cause more confusion than help. |
@seansfkelley @jobec I, at the very least, hope that we can all agree that:
are both valid and discrete usecases :) WRT to which one should be the default, I honestly don't have a strong opinion. I tend to prefer the latter option as the default one since it is more common for development + it is the current behaviour. Adding an extra flag and/or using an explicit subcommand on deployment scripts seems more natural. @seansfkelley I transferred the discussion for installing packages without adding them to |
"orphan" is an option too |
|
Possession is 9/10ths of the law. :) You would almost certainly only want the more permissive behavior in development, but even in development, how desirable is it? Enough to be the default?
In general, yeah, I think requiring CI commands to bear the burden of extra configuration is okay. But at least from my experience using Yarn, npm and Cargo, stricter behavior by default leads to fewer red herrings and unexpected behavior. In fact, I assumed Poetry did do this until I discovered the hard way (leading to my first comment here, #648 (comment)) that it did not. |
I'd say: With a (new) default of removing untracked packages (e.g. not in poetry.lock), as I think the larger percentage of users expect it to work as such. From the main website:
|
Nice citation of the website! :) I also think "untracked" is a good word to describe these dependencies. |
+1 for untracked. Apart from that, I completely agree that having a way to have a "purged" virtualenv is really important. That being said though, I also think that not purging the virtualenv while developing can also be useful. The reason I don't really like changing the defaults is that I prefer adding a flag on a deployment script rather than having to add a cli flag when using poetry interactively (i.e. while developing) |
Why? What we are talking about is removing packages, not installing. |
@drunkwcodes this discussion is related to #951 |
I won't look at that for a while... There are many ways to install untracked packages, not just with This is useful when you have local editable installations not packaged, and do not want to create new venv. |
Well, this is the point under discussion. I think there is value in increasing the scope of That said, in writing this comment I did discover a couple of interesting related commands in other tools:
My preferred style here is Yarn's, which has to tolerate users installing extra stuff (like npm) but by default tries to assert total control over On the topic of whether it should be default-on or default-off, I think that depends on one's preferred development flow. As someone who does not install untracked dependencies hardly ever, I clearly prefer @jobec's suggestion of |
It's absolutly doable. And doing it professionally and better than a brutal virtualenv restart is the only concern. |
@drunkwcodes In my opinion, this comment does not add anything of value to this discussion. Please refrain from providing your commentary unless you're representing a position that has not already been presented in the various open issues on this project. |
Running This is really surprising behavior, given that
Or with an image: |
Maybe add a command (And much shorter than |
Just wondering if this is moving anywhere? It looks like there was a good proposal: To clarify the use case if it's not obvious, if you collaborate with anyone, including CI or have multiple machines, you probably add and remove dependencies organically, it makes no sense to keep removed ones around, especially if they interact with other tools |
I had a PR partially implementing this. But is has been closed in the meanwhile. Also, without a go or direction from a maintainer, there's not much fun in working on it of it won't be merged. |
Hello @jobec, I guess I closed your PR as this has the status WIP for a very long time and you didn't react on the stale bot message. So I thought you didn't work anymore on it. I found this feature very useful and appreciate your contribution. So please go on! 👍 fin swimmer |
Still the question remains: Maintainers, what direction to go in? Remove obsolete/stale/untracked/... packages by default, or keep them. |
At the end @sdispater has to decide, because it's a new feature. I support the version to remove untracked packages by default and have the |
This is very important and I don't know of any way to do this. Say several developers work on a project. One performs an update which removes a package from the pyproject and lock files. How will the other developers ever remove this package? Pipenv, for all of its flaws, at least has EDIT: Seems the poetry/poetry/installation/installer.py Line 409 in d27a119
|
@sdispater did you have any input on finswimmers suggestion of |
Unfortunately, we can't make this the default behavior since it's a breaking change in my opinion. We should add an option that requires opt-in like |
Sure! I'll modify my PR, then? We could add a configuration file that sets the default behavior, no problem. |
@sdispater @finswimmer |
#2172 fixes this issue and should be available in the next release. |
@stephsamson , is there any date for the next release? We are waiting for this feature. |
I am running into the exact same problem. |
Is this closed without a solution? Seems a little overkill to have to destroy my venv to bring my venv back in check with a projects packages. Teams do remove packages .... |
In newer poetry you can run |
Awesome thanks @trim21 , I didn't see this option in |
|
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Question
pipenv has
pipenv clean
which removes all packages that are no longer in Pipfile.lock from the virtualenv. What is the equivalent with poetry? The docs say there is no need forpipenv sync
andpipenv clean
due to theremove
command https://github.com/sdispater/poetry#remove-commandBut how does this work? I would need to run
poetry remove XXX
against all my virtualenvs - manually keeping track of all packages that have been removed and remembering to remove them myself?Is there not any way to sync my poetry.lock to my virtualenv to ensure the virtualenv only has the packages specified in poetry.lock installed?
I have a virtualenv on each box I deploy to, and keep pyproject.toml and poetry.lock under source code control. I then want a way to ensure each of those virtualenvs only has the packages in poetry.lock installed.
The text was updated successfully, but these errors were encountered: