Skip to content

Commit

Permalink
flit: improve the --python option
Browse files Browse the repository at this point in the history
pip --python option can take both the path to a Python executable or the
path to a virtual environment, greatly improving the user experience.

Teach flit to do the same.
  • Loading branch information
perillo committed Dec 4, 2023
1 parent ee17c70 commit d9adf5c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions flit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def find_python_executable(python: Optional[str] = None) -> str:
python = os.environ.get("FLIT_INSTALL_PYTHON")
if not python:
return sys.executable
if os.path.isdir(python):
# Assume it's a virtual environment and look for the environment's
# Python executable. This is the same behavior used by pip.
#
# Try both Unix and Windows paths in case of odd cases like cygwin.
for exe in ("bin/python", "Scripts/python.exe"):
py = os.path.join(python, exe)
if os.path.exists(py):
python = py

Check warning on line 37 in flit/__init__.py

View check run for this annotation

Codecov / codecov/patch

flit/__init__.py#L37

Added line #L37 was not covered by tests
if os.path.isabs(python): # sys.executable is absolute too
return python
# get absolute filepath of {python}
Expand Down

0 comments on commit d9adf5c

Please sign in to comment.