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.list_python_versions() not working on Linux #58

Closed Mandera closed 1 year ago

Mandera commented 1 year ago

Run: https://github.com/ManderaGeneral/generalpackager/actions/runs/4030507328/jobs/6929215543

Here's a good thread for linux: https://stackoverflow.com/questions/30464980/how-to-check-all-versions-of-python-installed-on-osx-and-centos

Examples with Terminal("ls", "-1", "/usr/bin/python*", "|", "grep", "-P", "'.*\d\.\d+$'").string_result

/usr/bin/python2.7
/usr/bin/python3.7

And the one for windows: https://stackoverflow.com/questions/53312590/how-can-i-check-all-the-installed-python-versions-on-windows

Examples with Terminal("py", "--list-paths").string_result

 *               C:\Python\Venvs\dev11\Scripts\python.exe
-V:3.11          C:\Users\ricka\AppData\Local\Programs\Python\Python311\python.exe
-V:3.10          C:\Users\ricka\AppData\Local\Programs\Python\Python310\python.exe
-V:3.9           C:\Users\ricka\AppData\Local\Programs\Python\Python39\python.exe
-V:3.8           C:\Python\Python38\python.exe
-V:2.7           C:\Python\Repos\Sources\python.exe
-V:3.11 *        C:\Users\ricka\AppData\Local\Programs\Python\Python311\python.exe
-V:3.10          C:\Users\ricka\AppData\Local\Programs\Python\Python310\python.exe
-V:3.9           C:\Users\ricka\AppData\Local\Programs\Python\Python39\python.exe
-V:3.8           C:\Python\Python38\python.exe
-V:2.7           C:\Python\Repos\Sources\python.exe """
Mandera commented 1 year ago

I should only return non-venv pythons

Mandera commented 1 year ago

Ok so issue is that I'm assuming all python executables end with 3.8 for examples. I should try calling --version on every python file to see if they are python distributions. Should I do this for windows too? A bit worried about launching random exe files but this could be a solution. Maybe I can take a closer look at how py works for windows? https://stackoverflow.com/questions/50896496/what-is-the-difference-between-py-and-python-in-the-windows-terminal

Got this on linux now with whereis python: "python: /usr/bin/python /opt/hostedtoolcache/Python/3.8.16/x64/bin/python /opt/hostedtoolcache/Python/3.8.16/x64/python /usr/share/man/man1/python.1.gz" Maybe ill just try that approach, calling is_file and then --version on these

Mandera commented 1 year ago

Hmm even though Terminal had error=False it raised an OSError

Maybe I'll throw in a regex too. First I'll check out why error wasn't suppressed

Mandera commented 1 year ago

When Venv() is called and there is an active venv it becomes that one. If there is no active venv it will become a non-existant Venv with cwd as path.


I don't really like this. I should make a specific class method to get active venv. Venv() should only be to get Venv with cwd.

Mandera commented 1 year ago

list_python_versions is not yielding any paths on linux, I'll try to debug. I dislike having to trigger the matrix everytime I'm testing it though, there's definitely a better/faster way. Not sure it's worth the time to find right now

Mandera commented 1 year ago

Regex now working, on to the next issue which was that Linux uses colon as PATH delimiter, not semi-colon like Windows.

https://github.com/ManderaGeneral/generalpackager/commit/3b657dd58a431274e23b3855c08f39cbb3b780a2

Mandera commented 1 year ago

Slowly getting there. Had issue where I didn't remove env var VIRTUAL_ENV. Also had to remove .exe on linux for python. Seems to work now!! https://github.com/ManderaGeneral/generalpackager/commit/3a3745f31575ccd36bd649bb1ffdfed19435939b