Skip to content

Commit 4af3425

Browse files
committed
sort output; prefix with _
1 parent d0b7914 commit 4af3425

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</p>
66

77
<a href="https://pypi.python.org/pypi/pythonloc/">
8-
<img src="https://img.shields.io/badge/pypi-0.1.1.1-blue.svg" /></a>
8+
<img src="https://img.shields.io/badge/pypi-0.1.1.2-blue.svg" /></a>
99

1010
**pythonloc** is a drop in replacement for `python` and `pip` that automatically recognizes a `__pypackages__` directory and prefers importing packages installed in this location over user or global site-packages. If you are familiar with node, `__pypackages__` works similarly to `node_modules`.
1111

@@ -181,7 +181,7 @@ Successfully uninstalled requests-2.21.0
181181

182182
While this PEP is pretty exciting, there are a some things it doesn't solve.
183183

184-
* entrypoints: when you install a package, any entry points a package may have in the `bin` folder (like `black` or `tox`) are not accessible based on this PEP. A tool designed to install packages globally, yet keep them sandboxed is [pipx](https://github.com/pipxproject/pipx) (also my project). This works well for installing a single version globally, but using virtual environments directly will let you run entry points as you'd expect.
184+
* entrypoints: when you install a package, any entry points a package may have in the `bin` folder (like `black` or `tox`) are not accessible based on this PEP. [pipx](https://github.com/pipxproject/pipx) (also my project), is the perfect tool to search in `__pypackages__/3.6/lib/bin` for the entry point you want to run. So you would run `pipx run tox` and it would locate `__pypackages__/3.6/lib/bin`. (It doesn't currently do this.) This is very similar to [npx](https://www.npmjs.com/package/npx), which will search in `node_modules/bin`.
185185
* OS-dependent packages: The directory structure in `__pypackages__` is namespaced on python version, so packages for Python 3.6 will not mix with 3.7, which is great. But sometimes packages install differently for different OS's, so Windows may not match mac, etc.
186186
* site-packages: This PEP first looks to `__pypackages__` but will fall back to looking in `site-packages`. This is not entirely hermetic and could lead to some confusion around which packages are being used. I would prefer the search path be **only** `__pypackages__` and nothing else.
187187
* perceived downside -- bloat: Many have brought this up in various forums, comparing it to `node_modules`, but I don't think it applies here. For one, the same if not more "bloat" is installed into a virtual environment, so this just moves it into a local directory. No additional bloat. In fact, it is more obvious and can be deleted because it's not hidden away in a virtual env directory. But more importantly, I think the assumption that it is bloated or will be abused stems from JavaScript's ecosystem. JavaScript has a notoriously limited standard library, and developers need to reach for third party packages more often. In addition, the JavaScript development heavily relies on many plugins and transpilation, something Python does not. I do not find the bloat argument convincing.

pythonloc/pythonloc.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pip
88

99

10-
def get_pypackages_lib_path(script_path=None):
10+
def _get_pypackages_lib_path(script_path=None):
1111
"""returns path in compliance with PEP 582
1212
https://www.python.org/dev/peps/pep-0582/
1313
"""
@@ -24,37 +24,27 @@ def get_pypackages_lib_path(script_path=None):
2424
)
2525

2626

27-
def get_env(script_path=None):
27+
def _get_env(script_path=None):
2828
env = dict(os.environ)
2929
env["PYTHONPATH"] = os.path.pathsep.join(
30-
[".", get_pypackages_lib_path(script_path)]
30+
[".", _get_pypackages_lib_path(script_path)]
3131
+ os.getenv("PYTHONPATH", "").split(os.path.pathsep)
3232
)
3333
return env
3434

3535

36-
def null_handler(signum, frame):
37-
pass
38-
39-
40-
def get_script_path():
36+
def _get_script_path():
4137
for arg in sys.argv[1:]:
4238
if not arg.startswith("-"):
4339
return os.path.abspath(arg)
4440
return None
4541

4642

47-
def pythonloc():
48-
args = [sys.executable] + sys.argv[1:]
49-
script_path = get_script_path()
50-
os.execve(sys.executable, args, get_env(script_path))
51-
52-
5343
def _get_pip_target_args(pip_args):
5444
if "install" in pip_args:
5545
if "--target" not in pip_args:
5646
# use target dir if installing
57-
target = ["--target", get_pypackages_lib_path()]
47+
target = ["--target", _get_pypackages_lib_path()]
5848
if (
5949
pip.__version__.startswith("9.") or pip.__version__.startswith("10.")
6050
) and "--system" not in pip_args:
@@ -64,16 +54,22 @@ def _get_pip_target_args(pip_args):
6454
return target
6555

6656

57+
def pythonloc():
58+
args = [sys.executable] + sys.argv[1:]
59+
script_path = _get_script_path()
60+
os.execve(sys.executable, args, _get_env(script_path))
61+
62+
6763
def piploc():
6864
pip_args = sys.argv[1:]
6965
target = _get_pip_target_args(pip_args)
7066
args = [sys.executable] + ["-m", "pip"] + pip_args + target
71-
os.execve(sys.executable, args, get_env())
67+
os.execve(sys.executable, args, _get_env())
7268

7369

7470
def pipfreezeloc():
7571
cmd = [sys.executable, "-m", "pip", "freeze"]
76-
p = subprocess.Popen(cmd, env=get_env(), stdout=subprocess.PIPE)
72+
p = subprocess.Popen(cmd, env=_get_env(), stdout=subprocess.PIPE)
7773
try:
7874
outs, errs = p.communicate()
7975
if outs is None:
@@ -94,7 +90,7 @@ def pipfreezeloc():
9490
except Exception:
9591
p.kill()
9692
exit("failed to run pip freeze")
97-
for i in all_reqs - sys_reqs:
93+
for i in sorted(all_reqs - sys_reqs):
9894
print(i)
9995

10096

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
setup(
2525
name="pythonloc",
26-
version="0.1.1.1",
26+
version="0.1.1.2",
2727
author="Chad Smith",
2828
author_email="[email protected]",
2929
description="Run Python using packages from local directory __pypackages__",

0 commit comments

Comments
 (0)