Skip to content

Commit

Permalink
Fix installation test for Python 3.12 and Windows
Browse files Browse the repository at this point in the history
Starting in Python 3.12, global and virtual Python environments no
longer automatically ship setuptools (per the "ensurepip" item in
https://docs.python.org/3.12/whatsnew/3.12.html#removed). Projects
that use setuptools as a build backend are still supported,
including with setup.py using techniques such as "pip install .".

In Windows, the "bin" subdir of a virtual environment dir is called
"Scripts" instead. Unlike in a global environment (where no names
are universal, and "python3" and "pip3" are more common for the
Python 3 commands on some popular Unix-like systems), in a virtual
environment the "python" and "pip" commands are always present and
"python3" and "pip3" are not guaranteed to be present.

This commit changes test_installation accordingly. The CI workflows
and documentation still need to be updated.
  • Loading branch information
EliahKagan committed Sep 9, 2023
1 parent c8e303f commit dba4245
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ast
import os
import subprocess
from git.compat import is_win
from test.lib import TestBase
from test.lib.helper import with_rw_directory

Expand All @@ -12,8 +13,9 @@ class TestInstallation(TestBase):
def setUp_venv(self, rw_dir):
self.venv = rw_dir
subprocess.run(["virtualenv", self.venv], stdout=subprocess.PIPE)
self.python = os.path.join(self.venv, "bin/python3")
self.pip = os.path.join(self.venv, "bin/pip3")
bin_name = "Scripts" if is_win else "bin"
self.python = os.path.join(self.venv, bin_name, "python")
self.pip = os.path.join(self.venv, bin_name, "pip")
self.sources = os.path.join(self.venv, "src")
self.cwd = os.path.dirname(os.path.dirname(__file__))
os.symlink(self.cwd, self.sources, target_is_directory=True)
Expand All @@ -32,14 +34,14 @@ def test_installation(self, rw_dir):
msg=result.stderr or result.stdout or "Can't install requirements",
)
result = subprocess.run(
[self.python, "setup.py", "install"],
[self.pip, "install", "."],
stdout=subprocess.PIPE,
cwd=self.sources,
)
self.assertEqual(
0,
result.returncode,
msg=result.stderr or result.stdout or "Can't build - setup.py failed",
msg=result.stderr or result.stdout or "Can't install project",
)
result = subprocess.run([self.python, "-c", "import git"], stdout=subprocess.PIPE, cwd=self.sources)
self.assertEqual(
Expand Down

0 comments on commit dba4245

Please sign in to comment.