cs01 / pythonloc Goto Github PK
View Code? Open in Web Editor NEWdrop-in Python replacement that imports packages from local directory (attempt at PEP 582 implementation)
License: MIT License
drop-in Python replacement that imports packages from local directory (attempt at PEP 582 implementation)
License: MIT License
PEP 582's text reads
Python will use the pypackages from the base directory of the script when present.
However pythonloc
only looks for __pypackages__
in the current directory.
pythonloc
should be modified to identify the absolute path of the script that is running (if any) and add <script's parent dir>/__pypackages__/...
to PYTHONPATH rather than <current local dir>/__pypackages__
.
If there is no script being run (i.e. the repl is being used) or if the script is in the current directory, pythonloc
should continue its current behavior.
This seems like a great idea. I am unfortunately struggling to install it. The error is in the issue title. I am running Debian GNU/Linux 9 (stretch), Python 2.7.13, pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7).
I also have Python 3.5.3 installed and it behaves identically on that as well.
Just as a point of information, the --target
option to pip doesn't work with --upgrade
, so piploc -U
won't work as expected.
Demonstration:
>py -m pip install -t xxx wheel==0.30.0
Collecting wheel==0.30.0
Downloading https://files.pythonhosted.org/packages/0c/80/16a85b47702a1f47a63c104c91abdd0a6704ee8ae3b4ce4afc49bc39f9d9/wheel-0.30.0-py2.py3-none-any.whl (49kB)
100% |████████████████████████████████| 51kB 731kB/s
Installing collected packages: wheel
Successfully installed wheel-0.30.0
>py -m pip install -t xxx -U wheel
Collecting wheel
Using cached https://files.pythonhosted.org/packages/96/ba/a4702cbb6a3a485239fbe9525443446203f00771af9ac000fa3ef2788201/wheel-0.33.1-py2.py3-none-any.whl
Installing collected packages: wheel
Successfully installed wheel-0.33.1
>dir .\xxx
Directory: C:\Work\Scratch\xxx
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 01/03/2019 15:49 bin
d----- 01/03/2019 15:49 wheel
d----- 01/03/2019 15:49 wheel-0.30.0.dist-info
d----- 01/03/2019 15:49 wheel-0.33.1.dist-info
When freezing dependencies, requiring hashes would make environment recreation deterministic.
I've installed pythonloc on my macOS laptop, running Python 3.7 installed via homebrew:
$ python3 --version
Python 3.7.2
$ pip3 list
Package Version
--------------- -------
greenlet 0.4.15
jedi 0.13.2
msgpack 0.6.0
neovim 0.3.1
parso 0.3.1
pip 18.1
pydocstyle 3.0.0
pynvim 0.3.1
pythonloc 0.1.1.1
setuptools 40.6.3
snowballstemmer 1.2.1
wheel 0.32.3
$ python3 -m pip install --user pythonloc
Collecting pythonloc
Using cached https://files.pythonhosted.org/packages/02/02/88be53abb689d9570cd391db8c6bfe2137af2aeb63315fd81c04ad7d8911/pythonloc-0.1.1.1-py3-none-any.whl
Installing collected packages: pythonloc
The scripts pipfreezeloc, piploc and pythonloc are installed in '/Users/fredrik/Library/Python/3.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pythonloc-0.1.1.1
$ /Users/fredrik/Library/Python/3.7/bin/pythonloc --version
Python 3.7.2
$ /Users/fredrik/Library/Python/3.7/bin/piploc list
Package Version
--------------- -------
greenlet 0.4.15
jedi 0.13.2
msgpack 0.6.0
neovim 0.3.1
parso 0.3.1
pip 18.1
pydocstyle 3.0.0
pynvim 0.3.1
pythonloc 0.1.1.1
setuptools 40.6.3
snowballstemmer 1.2.1
wheel 0.32.3
But when I run piploc install
, I get an error:
$ /Users/fredrik/Library/Python/3.7/bin/piploc install requests
Collecting requests
Using cached https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl
Collecting urllib3<1.25,>=1.21.1 (from requests)
Using cached https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl
Collecting idna<2.9,>=2.5 (from requests)
Using cached https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
Using cached https://files.pythonhosted.org/packages/9f/e0/accfc1b56b57e9750eba272e24c4dddeac86852c2bebd1236674d7887e8a/certifi-2018.11.29-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Installing collected packages: urllib3, idna, certifi, chardet, requests
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 143, in main
status = self.run(options, args)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 366, in run
use_user_site=options.use_user_site,
File "/usr/local/lib/python3.7/site-packages/pip/_internal/req/__init__.py", line 49, in install_given_reqs
**kwargs
File "/usr/local/lib/python3.7/site-packages/pip/_internal/req/req_install.py", line 760, in install
use_user_site=use_user_site, pycompile=pycompile,
File "/usr/local/lib/python3.7/site-packages/pip/_internal/req/req_install.py", line 382, in move_wheel_files
warn_script_location=warn_script_location,
File "/usr/local/lib/python3.7/site-packages/pip/_internal/wheel.py", line 215, in move_wheel_files
prefix=prefix,
File "/usr/local/lib/python3.7/site-packages/pip/_internal/locations.py", line 165, in distutils_scheme
i.finalize_options()
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/command/install.py", line 248, in finalize_options
"must supply either home or prefix/exec-prefix -- not both")
distutils.errors.DistutilsOptionError: must supply either home or prefix/exec-prefix -- not both
In piploc, why you are adding --system
args for pip version starts from 9 and 10, if 10 has none of it and thus fails?
Pipenv is an official tool supported by pypa
And to my best understanding serves a similar idea in a different way.
Could you please describe the pros and cons of each?
As discussed in https://discuss.python.org/t/pep-582-python-local-packages-directory/963, switching the contents of __pypackages__
to be a collection of venvs that are automatically recognized will leverage and interoperate with existing tools well.
Is this expected?
antoine@elune /tmp/tmp.ucyPsHjPcy/untrusted_code % cat /usr/bin/grep.py
#!/usr/bin/env python3
import os
print('Running grep.')
antoine@elune /tmp/tmp.ucyPsHjPcy/untrusted_code % cat os.py
print('MALICIOUS')
antoine@elune /tmp/tmp.ucyPsHjPcy/untrusted_code % pythonloc /usr/bin/grep.py
MALICIOUS
Fatal Python error: initsite: Failed to import the site module
Traceback (most recent call last):
[...]
AttributeError: module 'os' has no attribute 'path'
It doesn't seem reasonable at all to me that running a random script installed on my system with pythonloc would override its libraries with potentially arbitrary code in the directory I'm running the script from.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.