Skip to content

Commit dba4245

Browse files
committed
Fix installation test for Python 3.12 and Windows
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.
1 parent c8e303f commit dba4245

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: test/test_installation.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ast
55
import os
66
import subprocess
7+
from git.compat import is_win
78
from test.lib import TestBase
89
from test.lib.helper import with_rw_directory
910

@@ -12,8 +13,9 @@ class TestInstallation(TestBase):
1213
def setUp_venv(self, rw_dir):
1314
self.venv = rw_dir
1415
subprocess.run(["virtualenv", self.venv], stdout=subprocess.PIPE)
15-
self.python = os.path.join(self.venv, "bin/python3")
16-
self.pip = os.path.join(self.venv, "bin/pip3")
16+
bin_name = "Scripts" if is_win else "bin"
17+
self.python = os.path.join(self.venv, bin_name, "python")
18+
self.pip = os.path.join(self.venv, bin_name, "pip")
1719
self.sources = os.path.join(self.venv, "src")
1820
self.cwd = os.path.dirname(os.path.dirname(__file__))
1921
os.symlink(self.cwd, self.sources, target_is_directory=True)
@@ -32,14 +34,14 @@ def test_installation(self, rw_dir):
3234
msg=result.stderr or result.stdout or "Can't install requirements",
3335
)
3436
result = subprocess.run(
35-
[self.python, "setup.py", "install"],
37+
[self.pip, "install", "."],
3638
stdout=subprocess.PIPE,
3739
cwd=self.sources,
3840
)
3941
self.assertEqual(
4042
0,
4143
result.returncode,
42-
msg=result.stderr or result.stdout or "Can't build - setup.py failed",
44+
msg=result.stderr or result.stdout or "Can't install project",
4345
)
4446
result = subprocess.run([self.python, "-c", "import git"], stdout=subprocess.PIPE, cwd=self.sources)
4547
self.assertEqual(

0 commit comments

Comments
 (0)