ManderaGeneral / generalpackager

Tools to interface GitHub, PyPI, NPM and local modules / repos. Used for generating files to keep projects dry and synced. Tailored for ManderaGeneral for now.
https://pypi.org/project/generalpackager/
Apache License 2.0
0 stars 0 forks source link

Venv API #57

Closed Mandera closed 1 year ago

Mandera commented 1 year ago

From #17

What's the difference between venv and virtualenv? venv is builtin, virtualenv is one of many third party packages

Mandera commented 1 year ago

pyvenv.cfg looks different for every venv package. Here is built-in venv vs virtualenv

Name | venv | virtualenv 20.17.1 -- | -- | -- home | C:\Users\ricka\AppData\Local\Programs\Python\Python311 | C:\Users\ricka\AppData\Local\Programs\Python\Python311 implementation |   | CPython version_info |   | 3.11.0.final.0 virtualenv |   | 20.17.1 include-system-site-packages | false | false base-prefix |   | C:\Users\ricka\AppData\Local\Programs\Python\Python311 base-exec-prefix |   | C:\Users\ricka\AppData\Local\Programs\Python\Python311 base-executable |   | C:\Users\ricka\AppData\Local\Programs\Python\Python311\python.exe version | 3.11.0 |   executable | C:\Python\Venvs\dev11\Scripts\python.exe |   command | C:\Python\Venvs\dev11\Scripts\python.exe -m venv C:\Python\Venvs\test2 |  
Mandera commented 1 year ago

A general solution for activating a venv is not straight-forward. I should learn what happens when you activate a venv.

virtualenv creates an activate_this.py file in Scripts, it modified these values:

Maybe I should not bother with this. There are 6 ways to run the activate file depending on os and cmd.

Options:

Mandera commented 1 year ago

Doesn't seem too complicated to activate venv manually.

Name | Example | Info | Type -- | -- | -- | -- Environment Variable: PATH | C:\Python\Venvs\dev11\Scripts;C:\Windows\system32; ..... | Operating system paths | str Environment Variable: VIRTUAL_ENV | C:\Python\Venvs\dev11 |   | str sys.prefix | C:\Python\Venvs\dev11 |   | str sys.path | ['C:\\Python\\Repos\\generalpackager', .....] | Python paths | list of str sys.executable | C:\Python\Venvs\dev11\Scripts\python.exe |   | str sys.real_prefix | Undefined | Probably used by virtulenv only | str
Mandera commented 1 year ago

Seems to work nicely to activate venv manually https://github.com/ManderaGeneral/generalpackager/commit/b229a6b62d5398045202a2cfbd644ffeee700456

Mandera commented 1 year ago

Just noticed 'C:\Python\Venvs\dev11' is in sys.path as well. Should do something similar as to env var PATH when activating

Mandera commented 1 year ago

Found this to list installed python versions, super neat! https://stackoverflow.com/a/53330912/3936044

Extract from py --list-paths

Mandera commented 1 year ago

It yielded two paths that no longer exist, I need to figure out where these paths are defined. Otherwise I should do an is_file check before returning