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

rewrite feedback #1481

Closed
wants to merge 15 commits into from
Closed

rewrite feedback #1481

wants to merge 15 commits into from

Conversation

gaborbernat
Copy link
Contributor

@gaborbernat gaborbernat commented Jan 6, 2020

This is a PR meant to allow people to give feedback on the rewrite. For such big rewrite, I'm not sure Github UI is good so I'd recommend checking out the rewrite branch. Opened the PR though to allow people to comment in the code inline - or attach their feedback as a comment. If you take the time and give feedback I'd like to say thank you very much, appreciated 🙇

A bit of context on the design, the core rewrite idea is to make the project as fast as possible and relatively easy to extend/maintain. We now have a config file support, which allows users to choose their own defaults globally (virtualenv -h now shows where defaults come from, experience prooved that's there's no such thing as good default for everyone, and these can be also used to globally fix when some dependency pip/setuptools breaks the world). Furthermore, we still support python 2; and plan to support it for the foreseeable future - pypy is still supported, and we plan to support that. As such all code must support python 2.7+. That being said, the rewrite simplifies the python 2 env creation, to something that looks a lot more like python 3 style via a pyenv.cfg.

The idea is also to support a clean programmatic API for tox/pipenv/etc (e.g. what's the site-package folder for this env, without creating it; reuse environment discovery, etc).

The project is split into four main sections:

  • interpreter discovery (when the user passes in -p 3.8-64 discover/find an interpreter that satisfies those requirements - supports PEP-514 or path discovery mechanism)
  • interpreter creation (create the actual environment; either via delegation to venv, or ourselves - here we also implement ourselves creation code even when venv is available to avoid process creation overhead 🤷‍♂ which can be slow on some platforms especially)
  • seed packages (install pip/setuptools - either the old way via pip, or a faster method via app data image - 95% of the environment creation is spent within this phase, pip is slow mostly because has to support a lot of features, the app data image installation works around this by needing to support a smaller subset of pip - with this 200ms creation time is now possible)
  • activation scripts (now supports unicode paths, warns when a path would break, etc. - also now users can add plugins to add their own activation scripts)

CC @pfmoore @pradyunsg @RonnyPfannschmidt

PS: There still are some release blockers beyond this review -> https://github.com/pypa/virtualenv/milestone/7

gaborbernat and others added 10 commits December 18, 2019 14:16
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
- Use architecture, version, implementation and platform extensions for
candiates
- Cache PythonInfo.from_exe by path (resolving symlinks)
- Ensure what we discover has the same version, implementation and
architecture.
- Improve our test suite for this functionality.
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
* creator unicode support

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>

* activator support

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>

* fix

* add space

* python3.4 support

* Windows fixes

* some fixes

* fix powershell requires utf-16

* try to fix python2 windows

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>

* use utf-8 for activation scripts

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>

* fix

* more fix

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>

* fix

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>

* windows path py2.7

* fixes for Python 2 and unicode on Windows

* do not single out mbcs, but the file system encoder

* do not install pathlib python 2 windows

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>

* fix encoding on py35

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Ensure that what ran with virtualenv 17 will continue running in a post
rewrite world minus the deprecated flags, plus the relocatable feature.

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
* fix app data logic

Ensure that what ran with virtualenv 17 will continue running in a post
rewrite world minus the deprecated flags, plus the relocatable feature.

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>

* fix Windows

* fix

* fix

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
@gaborbernat gaborbernat changed the title link app data needs ro with symlinks (#1480) rewrite feedback Jan 6, 2020
@pfmoore
Copy link
Member

pfmoore commented Jan 6, 2020

Some initial (very simple) tests on Windows look OK.

  • Installing the new virtualenv in a venv works fine (which is good, as it makes it easier to test without affecting your system Python).
  • Similarly, the new virtualenv can be installed using pipx (good for providing a single central installation).
  • Using -p 3.8 resulted in a warning about invalid PEP 514 data in my registry for Python 2.7. No big deal as it's a warning, but as it's for a Python version I wasn't trying to use, the warning is unnecessary (and potentially scary for many users). I don't know how the data that was present - I no longer have Python 2.7 installed, although I did at one point. Maybe installing and uninstalling leaves it?

I tried to test with Python 2.7, using a custom Python 2.7 install (installed via Scoop) and virtualenv -p C:\Users\xxx\scoop\apps\python-2.7.17\1.0\Python-2.7.17\python.exe xx. The resulting environment didn't include a copy of python27.dll, and so python.exe failed. Virtualenv 16.7.9 doesn't have this issue with this Python installation. (I don't have anywhere I can install the "official" Python 2.7 at the moment, so I can't test this any further).

By the way, the new virtualenv seems to install pydoc.bat. The old one didn't - ideally I'd prefer this not to be installed, as it interferes with command completion (myenv\Scripts\py<TAB>). I realise this is a minor use case, but xkcd is on my side 🙂

But overall, this looks very nice. Good job!

Copy link
Contributor

@asottile asottile left a comment

Choose a reason for hiding this comment

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

(I didn't review the tests)

most of my comments are little things

some stuff I noticed from this:

  • the new structure ends up with lots of circular imports :S
  • while the new structure seems to separate logic nicely, it was kinda hard for me to follow the control flow (especially with the deep inheritance hierarchies)
  • I'm very concerned about virtualenv growing dependencies, this breaks a lot of my usecases

I haven't had a chance to actually try this out yet, will give that a spin

setup.cfg Show resolved Hide resolved
setup.cfg Show resolved Hide resolved
setup.cfg Show resolved Hide resolved
src/virtualenv/activation/bash/activate.sh Show resolved Hide resolved
setup.cfg Show resolved Hide resolved
src/virtualenv/seed/embed/wheels/__init__.py Show resolved Hide resolved
src/virtualenv/util/__init__.py Show resolved Hide resolved
src/virtualenv/util/path/_sync.py Show resolved Hide resolved
tasks/make_zipapp.py Show resolved Hide resolved
src/virtualenv/seed/embed/base_embed.py Show resolved Hide resolved
gaborbernat and others added 4 commits January 6, 2020 16:21
Co-Authored-By: Anthony Sottile <asottile@umich.edu>
Co-Authored-By: Anthony Sottile <asottile@umich.edu>
Co-Authored-By: Anthony Sottile <asottile@umich.edu>
Co-Authored-By: Anthony Sottile <asottile@umich.edu>
@gaborbernat
Copy link
Contributor Author

gaborbernat commented Jan 6, 2020

Using -p 3.8 resulted in a warning about invalid PEP 514 data in my registry for Python 2.7. No big deal as it's a warning, but as it's for a Python version I wasn't trying to use, the warning is unnecessary (and potentially scary for many users).

This seems a good idea, will try to add.

I tried to test with Python 2.7, using a custom Python 2.7 install (installed via Scoop) and virtualenv -p C:\Users\xxx\scoop\apps\python-2.7.17\1.0\Python-2.7.17\python.exe xx. The resulting environment didn't include a copy of python27.dll, and so python.exe failed.

Interesting, wonder why an official installation python does not need it. 🤔 this needs to be investigated and determined to see if it's reasonable or not to automatically and when to add it.

By the way, the new virtualenv seems to install pydoc.bat. The old one didn't - ideally I'd prefer this not to be installed, as it interferes with command completion (myenv\Scripts\py). I realise this is a minor use case, but xkcd is on my side 🙂

You can always disable the generation of the Batch activation scripts. pydoc working on other shells and not in Batch was a bug we solved now by adding it.

the new structure ends up with lots of circular imports :S

I know of 3 🤔 could not eliminate these three so kept it.

while the new structure seems to separate logic nicely, it was kinda hard for me to follow the control flow (especially with the deep inheritance hierarchies)

I personally find it easier to identify this way what's common across different things, and what's different. This might be just my maintainer POV. Having endless if/else branches in the old way made it hard to see just what each target interpreter needed, where things differed.

I'm very concerned about virtualenv growing dependencies, this breaks a lot of my usecases

Would like to hear with concrete examples here, and why those can't be solved via a zippapp (perhaps one where part of the build operation we bundle the dependencies). Vendoring would be my very last option.

Co-Authored-By: Anthony Sottile <asottile@umich.edu>
setup.cfg Show resolved Hide resolved
setup.cfg Show resolved Hide resolved
setup.py Show resolved Hide resolved
Copy link

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

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

first i want to recognize the sheer amount of work that went into this rewrite - thank you :)

also thanks to @asottile - your prior run review things made thins more easy

i like the overall restructuring and splitting things into smaller comprehensible things
the overall quality is just lovely, my key irks where about minor details of api style (which is neglect-able)

so again thank you and great work !

def supports(cls, interpreter):
return interpreter.os != "nt"

def templates(self):

Choose a reason for hiding this comment

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

this could be a list for all use cases i currently see, is there a use-case requiring this to be a callable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I follow here 🤔

src/virtualenv/activation/batch/__init__.py Show resolved Hide resolved
return session


def session_via_cli(args):

Choose a reason for hiding this comment

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

the control flow of this function is horrendous to follow, almost gives me hives

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reorganized under #1487

src/virtualenv/seed/embed/base_embed.py Show resolved Hide resolved
@pfmoore
Copy link
Member

pfmoore commented Jan 6, 2020

I tried to test with Python 2.7, using a custom Python 2.7 install (installed via Scoop) and virtualenv -p C:\Users\xxx\scoop\apps\python-2.7.17\1.0\Python-2.7.17\python.exe xx. The resulting environment didn't include a copy of python27.dll, and so python.exe failed.

Interesting, wonder why an official installation python does not need it. 🤔 this needs to be investigated and determined to see if it's reasonable or not to automatically and when to add it.

Maybe because an all-users Python 2 install using the python.org installer puts python27.dll in the Windows system directory, so the fact that it doesn't get copied doesn't matter in that case? (I think it does that, as I say no official Python 2 installation to hand at the moment to check this...)

By the way, the new virtualenv seems to install pydoc.bat. The old one didn't - ideally I'd prefer this not to be installed, as it interferes with command completion (myenv\Scripts\py). I realise this is a minor use case, but xkcd is on my side 🙂

You can always disable the generation of the Batch activation scripts. pydoc working on other shells and not in Batch was a bug we solved now by adding it.

Ah, if it's considered a "batch" activation script, then yes I could do this, as I use PowerShell, so the batch scripts are not very useful to me. Thanks for the suggestion.

@pfmoore
Copy link
Member

pfmoore commented Jan 6, 2020

with PEP-517/518 its increasingly unnecessary to have this build dependency, as pip would put it into its build env anyway, its however potentially still creating problems for certain legacy packages, as the pip cant build a wheel directly (unchecked, need to check if it holds true)

For some reason I can't reply inline to this comment :-(

Yes, when using the legacy (non-PEP 517) code path, pip will check if wheel is importable, and only build a wheel if it is. In the absence of wheel, it will fall back to setup.py install, which has a number of differences in semantics, as well as not being cache-able.

@pradyunsg pradyunsg self-requested a review January 8, 2020 10:22
@pfmoore
Copy link
Member

pfmoore commented Jan 9, 2020

The resulting environment didn't include a copy of python27.dll, and so python.exe failed

Confirmed with a clean install. #1484 raised for this.

@gaborbernat gaborbernat added this to the 20.0.0 milestone Jan 9, 2020
@gaborbernat
Copy link
Contributor Author

I've addressed all points raised inside #1487 (minus three that have their own issues); will close this now, if anyone has further feedback please open a new PR and do it there; or reach out to me. Thanks for everyone for their effort.

@Julian
Copy link

Julian commented Jan 10, 2020

Woohoo! In case it hasn't been said enough yet, @gaborbernat you are great thanks for moving this forward it is awesome.

Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

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

This is all pretty great looking. I haven't finished reviewing this yet, but it seems like you've closed the PR so I'll push these not-so-polished-or-complete review comments.

Items prefixed with "nit: " are exactly that -- nitpicks that IMO aren't worth anyone's time to spend discussing in detail if there are disagreements.

@@ -1,22 +1,12 @@
include virtualenv.py
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it's worth it to make this work, an orphan branch (see https://stackoverflow.com/a/30284471/1931274 for how to). Then we'd rename the current master to legacy (+ add a tag) and rename rewrite to master instead of doing a merge. :P

That'd also allow for the rewrite to be more representative of the degree of work. :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm pushing an orphan branch takes a while 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setup.cfg Show resolved Hide resolved
src/virtualenv/activation/__init__.py Show resolved Hide resolved
src/virtualenv/config/ini.py Show resolved Hide resolved
src/virtualenv/config/ini.py Show resolved Hide resolved

from virtualenv.util.path import Path, copy

from .common import CPython, CPythonPosix, CPythonWindows
Copy link
Member

@pradyunsg pradyunsg Jan 8, 2020

Choose a reason for hiding this comment

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

Why are some imports relative and some absolute? It'd be preferable to maintain the same style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mostly because I did not find a tool to automate it 😢 any suggestions? I'd prefer to make relative what's possible without (or at most 1 level .. and keep everything else as absolute)

src/virtualenv/config/ini.py Show resolved Hide resolved
src/virtualenv/interpreters/create/creator.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants