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

During seeding properly uninstall present versions of the wheels #2186

Merged
merged 4 commits into from
Sep 24, 2021

Conversation

arcivanov
Copy link
Contributor

@arcivanov arcivanov commented Sep 17, 2021

An existing dist-info may contain entrypoints that may interfere with
normal functioning of the redeployed seeded wheel if there is a version
mismatch

fixes #2185

Thanks for contributing, make sure you address all the checklists (for details on how see

development documentation)!

  • ran the linter to address style issues (tox -e fix_lint)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

@arcivanov
Copy link
Contributor Author

@gaborbernat

Copy link
Contributor

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to add a test to validate the change and defend against regressions.

Copy link
Contributor

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test for this and ensure that the diff coverage is 💯🙏 thanks

@arcivanov
Copy link
Contributor Author

Yep, that's the next step.

@arcivanov arcivanov changed the title During seeding remove dist-info for present versions of the wheels During seeding properly uninstall present versions of the wheels Sep 19, 2021
@arcivanov
Copy link
Contributor Author

@gaborbernat Please let me know if you'd like me to squash the changes into a single commit

@gaborbernat
Copy link
Contributor

No thanks 👍

@codecov
Copy link

codecov bot commented Sep 20, 2021

Codecov Report

Merging #2186 (ddda7ce) into main (40d2f18) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2186   +/-   ##
=======================================
  Coverage   93.56%   93.57%           
=======================================
  Files          88       88           
  Lines        4380     4402   +22     
=======================================
+ Hits         4098     4119   +21     
- Misses        282      283    +1     
Flag Coverage Δ
tests 93.57% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ualenv/seed/embed/via_app_data/pip_install/base.py 96.05% <100.00%> (+0.66%) ⬆️
src/virtualenv/seed/embed/base_embed.py 96.22% <0.00%> (-1.89%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 40d2f18...ddda7ce. Read the comment docs.

@arcivanov
Copy link
Contributor Author

@gaborbernat anything else you require or is this ready for merge?

@gaborbernat
Copy link
Contributor

I want to do some cleanup, so currently waiting on my availability.

@arcivanov
Copy link
Contributor Author

arcivanov commented Sep 23, 2021

@gaborbernat do you want to cleanup this commit? or cleanup in general?
Thing is, lack of this fix is blocking pybuilder/pybuilder release as we bundle VEnv and it's critical to our function.

Would it be possible to release VEnv with this fix and perform the cleanup later?

@gaborbernat
Copy link
Contributor

I want to restructure a bit the code you've contributed 👍 will try to do this tomorrow morning.

@arcivanov
Copy link
Contributor Author

Thanks a lot!

An existing dist-info may contain entrypoints that may interfere with
normal functioning of the redeployed seeded wheel if there is a version
mismatch

fixes pypa#2185
Remove other recorded files from RECORD
Remove dist-info itself
In the test ensure the directories are compared as sets and not lists
Add setuptools downgrade to ensure proper cleanup of the existing version
Signed-off-by: Bernát Gábor <gaborjbernat@gmail.com>
# sync image
for filename in self._image_dir.iterdir():
into = self._creator.purelib / filename.name
if into.exists():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaborbernat I'm sorry, this is NOT an equivalent change.

We went from "delete target prior to copying into" into "uninstall previous distro but do not delete target directory if it wasn't part of the distro".

I specifically preserved that functionality because if there are extraneous files that are NOT part of a valid distro, venv would override them on install and won't fail. Now VEnv will fail as soon as it encounters a directory/file that exists which can happen if overwriting a partially created VEnv directory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, how do you end up with a partially created venv? Do you have some real-world examples of this or are you talking HYPOTHETICALS?

Copy link
Contributor Author

@arcivanov arcivanov Sep 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ctrl-C during venv installation with partial install of the package. This will occur intermittently and how intermittent it'll be will depend on the PIP package installation logic which will also change from time to time (whether they write dist-info first or they write package data first etc).

My point is: there was specific logic here that I preserved (not introduced!) that resulted in a very specific behavior that made venv more robust. The cleanup resulted in that logic being removed which made venv less robust and more error prone while the problem I tried to fix was fixed.

Can we please make venv less brittle again and reintroduce the logic that was there before?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is virtualenv, not venv 😊 please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change you introduced relies on everything else (PIP, wheel, bdist_wheel) working 100% correctly 100% of the time: fully installed packages with 100% correct RECORD file that recorded all the files that were actually installed and that package is installed successfully 100% of the time and never interrupted in the process of installation by user action or running out of disk space.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@@ -150,6 +147,36 @@ def _create_console_entry_point(self, name, value, to_folder, version_info):
result.extend(Path(i) for i in new_files)
return result

def _uninstall_previous_version(self):
dist_name = self._dist_info.stem.split("-")[0]
in_folders = chain.from_iterable([i.iterdir() for i in {self._creator.purelib, self._creator.platlib}])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The installation happens only into the purelib: https://github.com/pypa/virtualenv/pull/2186/files#diff-05dbe4fcecab074226aa3cf0e1d6285e9a47e4a1c529a20ab49f2b572c3d49eaR38

Why bother with platlib when install will never actually touch it?

Copy link
Contributor

@gaborbernat gaborbernat Sep 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the package is either in the purelib or platlib is an implementation detail of the installer. Our installer uses purelib, but is completely legal for someone else to use platlib for it. We don't control the previous state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it's even more important to restore the logic above. If the package being removed is in the platlib but the extraneous files are in purelib then while the package is removed from platlib the purelib will stay polluted and installation will fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Virtualenv corrupts dist-info during embedded downgrade overlaying existing venv
2 participants