🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

During seeding properly uninstall present versions of the wheels - #2186

Merged
gaborbernat merged 4 commits into
pypa:mainfrom
arcivanov:issue_2185
Sep 24, 2021
Merged

gaborbernat merged 4 commits into
pypa:mainfrom
arcivanov:issue_2185

Conversation

@arcivanov

@arcivanov arcivanov commented Sep 17, 2021 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

@gaborbernat

Comment thread src/virtualenv/seed/embed/via_app_data/pip_install/base.py Outdated

@gaborbernat gaborbernat left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/virtualenv/seed/embed/via_app_data/pip_install/base.py Outdated
Comment thread src/virtualenv/seed/embed/via_app_data/pip_install/base.py Outdated

@gaborbernat gaborbernat left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor Author

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

@gaborbernat

Copy link
Copy Markdown
Contributor

No thanks 👍

@codecov

codecov Bot commented Sep 20, 2021 •

Copy link
Copy Markdown

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
Copy Markdown
Contributor Author

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

@gaborbernat

Copy link
Copy Markdown
Contributor

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

@arcivanov

arcivanov commented Sep 23, 2021 •

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
Contributor

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

@arcivanov

Copy link
Copy Markdown
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>
@gaborbernat
gaborbernat merged commit e13ea2a into pypa:main Sep 24, 2021
# sync image
for filename in self._image_dir.iterdir():
into = self._creator.purelib / filename.name
if into.exists():

Copy link
Copy Markdown
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
Copy Markdown
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?

@arcivanov arcivanov Sep 24, 2021 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok.


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
Copy Markdown
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?

@gaborbernat gaborbernat Sep 24, 2021 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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