Skip to content

Install executables in virtual environments with flit install --python #274

Closed
@madsmtm

Description

@madsmtm

So this is a bit of a wierd one: When installing into a virtual environment via. flit install --python, installed executables link to the wrong python executable in the shebang header.

How to reproduce

Put a requirement like black (or any other package tool that creates an executable) into the requires key, and install your package under a virtual environment.

$ cat flittest/__init__.py
"""Test"""
__version__ = "1.2.3"

$ cat pyproject.toml
[build-system]
requires = ["flit"]
build-backend = "flit.buildapi"
[tool.flit.metadata]
module = "flittest"
author = ""
author-email = ""
requires = ["black"]  # Or any other tool that creates an executable

$ python -m virtualenv test-venv
New python executable in ./test-venv/bin/python
Installing setuptools, pip, wheel...done.

$ flit install --python ./test-venv/bin/python
Copying package file(s) from flittest
------ Download and installation output omitted ------
Installing collected packages: click, toml, appdirs, attrs, black, flittest
  WARNING: The scripts black and blackd are installed in './test-venv/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 appdirs-1.4.3 attrs-19.1.0 black-19.3b0 click-7.0 flittest-1.2.3 toml-0.10.0

$ head -n 1 ./test-venv/bin/black
#!/usr/local/Cellar/python/3.7.3/bin/python3.7

Notice the last line - The shebang points the python executable that was used to run flit, not the virtual environment's python!

If I install the package manually, then I get the expected result:

$ ./test-venv/bin/python -m pip install black
------ Download output omitted ------
Installing collected packages: click, toml, appdirs, attrs, black, flittest
Successfully installed appdirs-1.4.3 attrs-19.1.0 black-19.3b0 click-7.0 flittest-1.2.3 toml-0.10.0

$ head -n 1 ./test-venv/bin/black
#![path-to-current-folder]/test-venv/bin/python

Environment

  • Flit 1.3
  • MacOS Mojave
  • Python 3.7

Please guide me if I'm doing something wrong, or if it's a bug in flit, how I could help fix it 😉

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions