eight04 / vpip

A CLI which aims to provide an npm-like experience when installing Python packages.
MIT License
4 stars 1 forks source link

link_console_script global install tries to write to /usr/bin #14

Closed jayvdb closed 5 years ago

jayvdb commented 5 years ago

On Unix, global installs of console scripts attempt to write to /usr/bin.

> ~/.local/bin/vpip install -g story
building venv at /home/jayvdb/.vpip/pkg_venvs/story
Collecting pip
  Using cached https://files.pythonhosted.org/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 19.0.3
    Uninstalling pip-19.0.3:
      Successfully uninstalled pip-19.0.3
Successfully installed pip-19.3.1
...
link console script 'story'
Traceback (most recent call last):
  File "/home/jayvdb/.local/bin/vpip", line 11, in <module>
    load_entry_point('vpip', 'console_scripts', 'vpip')()
  File "/home/jayvdb/projects/python/vpip/vpip/cli.py", line 57, in cli
    module.run(ns)
  File "/home/jayvdb/projects/python/vpip/vpip/commands/install.py", line 33, in run
    install_global(ns.PACKAGE)
  File "/home/jayvdb/projects/python/vpip/vpip/commands/install.py", line 60, in install_global
    link_console_script(pkg, overwrite=True)
  File "/home/jayvdb/projects/python/vpip/vpip/commands/link.py", line 43, in link_console_script
    linker.dest.unlink()
  File "/usr/lib64/python3.7/pathlib.py", line 1287, in unlink
    self._accessor.unlink(self)
PermissionError: [Errno 13] Permission denied: '/usr/bin/story'

The script story is already installed in /home/jayvdb/.vpip/pkg_venvs/story/bin, and the next step would be to be create a symlink in /home/jayvdb/.local/bin/ , but instead it is writing to /usr/bin/ which isnt allowed.

install.py includes # TODO: make pip support install_scripts which may be referring to some part of this problem.

However the comment also mentions https://github.com/pypa/pip/issues/3934 , which has a recent comment indicating it has been fixed indirectly, but not in a way that helps with a target-scripts-dir different from the target-dir.

I think it is a good idea to let the scripts be installed into the venv as normal, and then copy them to the GLOBAL_SCRIPT_FOLDER. And the global script directory for unix should be ~/.local/bin rather than /usr/bin

jayvdb commented 5 years ago

If another path needs to be added to the PATH, https://github.com/ofek/userpath is likely to be the solution. That is what pipx is using.

eight04 commented 5 years ago

I thought sys.base_prefix should be writable. In Linux, where does sys.base_prefix points to? https://docs.python.org/3/library/sys.html#sys.prefix

eight04 commented 5 years ago

Maybe we should use something like:

path.os.dirname(shutil.which("vpip"))
jayvdb commented 5 years ago

Will try it. Sounds sane.

jayvdb commented 5 years ago

Hmm. Maybe wont work so well with python -m vpip

eight04 commented 5 years ago

In case the vpip CLI is not in the path, we can fallback to other methods. (Or, maybe we should warn the user and link nothing?)