-
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
Fix for the removal of all the environments using the --all
option
#8665
Conversation
Now updates the envs.toml file accordingly.
I never use well this looks plausible too, hopefully someone who remembers something about this code will take a look |
Looks like it is used pervasively through the code dealing with envs to me. I don't think it should be deleted. |
I meant: would an alternative fix have been to remove the file at the same time as removing all environments? I assume the world starts off with no environments and no But it doesn't matter anyway, you've taken a different approach and as I say that looks plausible to me. |
Ah, there is a misunderstanding I think! The command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't added new tests because one is already here for this command (there is a test for poetry env remove --all)
I don't follow this argument. If I understand correctly, this PR fixes a bug. In that case, there should be a test that fails without the fix. If there isn't such a test, then it should be added. (It shouldn't be too difficult to create an envs.toml
in a test and check that the concerning section is removed.)
if not env_path.exists(): | ||
raise ValueError(f'<warning>Environment "{name}" does not exist.</warning>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this warning? At least raising a ValueError
seems to be wrong, especially for a warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValueError
is the error type that was chosen for this kind of warning I guess. I sticked to the behavior of the original .remove()
method which uses ValueError
in this exact same way.
if base_env_name in envs: | ||
del envs[base_env_name] | ||
envs_file.write(envs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may not make a difference for remove --all
but considering that this method removes exactly one venv, we should only remove the entry if the Python version matches the version of the venv we are removing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, this may no make a difference. The check is only there if there is an inconsistency between the TOML env file and the virtual env folders.
|
||
self.remove_venv_dir(env_path) | ||
|
||
return VirtualEnv(env_path, env_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we return a venv?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I sticked to what appears to be the norm in the Poetry repository. The original .remove()
method returns a virtual env, thus I kept that design parttern here too.
Major version number was missing
I wasn't able to tell if consistency between the TOML file and the env folders has to be strictly enforced since no test for the remove command seems to validate this assertion. I was simply conservative and preferred not to change the tests. The TOML could be out of sync with the env folders for many reasons, for instance a user manually removing them from the cache because they take too much space on their device. I checked the tests for the create command (triggered by I you confirm that doing basic consistency checks makes sense, i'll considerer adding tests for that. |
Ah, now I understand: the new method is just a partial copy of the existing poetry/src/poetry/utils/env/env_manager.py Lines 339 to 359 in 0578ed8
In that case, we should avoid code duplication. Can you please do a small refactoring so that
We can't expect the envs.toml to be consistent, but we should keep it consistent when running a Poetry command.
I think a test that checks that the entry is removed when calling
|
I got some time to advance on this issue. first, I don't think it would be straightforward to make Second, I tried to implement the tests for I start to feel very confused about the purpose of that file and what is its expected state but I wasn't able to find any specification about it. Where can I find the documentation about Poetry's internals? |
In some places, tests are more incomplete than in others. There is a permanent issue to improve the tests suite.
The file is probably not present because we do not always create a real virtualenv if we do not need one for a unit test. If we need an
Afaik, there is not such documentation. You have to look into the code. I have just added some tests, improved the (in-code) documentation a bit and tried another approach, which I think covers more cases: #8831 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Resolves: #8631
I didn't added new tests because one is already here for this command (there is a test for
poetry env remove --all
) and don't think new documentation is required since this is a simple bug fix. I ran all the tests and linting/formatting tools listed in the contribution guidelines before submitting this PR.The previous code did't remove the TOML sections in
envs.toml
when removing all virtual environment usingpoetry env remove --all
. I implemented a new method on theEnvManager
for this specific case. I also renamed the previous methodEnvManager.remove_venv
to the more explicit nameEnvManager.remove_venv_dir
and updated the references.I struggled a little to understand if the environments listed in
envs.toml
should be kept in sync with the virtual environments present in the parent folder. I supposed the negative since I think that this assertion is never checked in the tests, thus I haven't modified the tests to check this.Feel free to suggest improvements.