Skip to content

Commit 1847cbe

Browse files
authored
Pin pip<23.1 and setuptools<67 to allow PEP-440 non compliance (#653)
PEP-440 is more strict about requirement lines. As an example: pytz>dev is non-compliant, but is in 5.2.4 of kombu's requirements. This breaks building wheelhouses from source (such as the octavia charm). This patch pins pip and setuptools to the latest versions that will defintely still allow PEP-440 non-compliant packages to install. The option --upgrade-buildvenv-core-deps can be used to override this and will install the latest versions of pip and setuptools available. Fixes-Bug: #652
1 parent ce4b136 commit 1847cbe

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

charmtools/build/tactics.py

+2
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,8 @@ def __call__(self):
12521252
).exit_on_error()()
12531253
if self.upgrade_deps:
12541254
utils.upgrade_venv_core_packages(self._venv, env=self._get_env())
1255+
else:
1256+
utils.pin_setuptools_for_pep440(self._venv, env=self._get_env())
12551257
log.debug(
12561258
'Packages in buildvenv:\n{}'
12571259
.format(

charmtools/utils.py

+18
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,24 @@ def upgrade_venv_core_packages(venv_dir, env=None):
670670
env=env).exit_on_error()()
671671

672672

673+
def pin_setuptools_for_pep440(venv_dir, env=None):
674+
"""Pin setuptools so that pep440 non-compliant packages can be installed.
675+
676+
Also pins pip as it's a combination that definitely works.
677+
678+
:param venv_dir: Full path to virtualenv in which packages will be upgraded
679+
:type venv_dir: str
680+
:param env: Environment to use when executing command
681+
:type env: Optional[Dict[str,str]]
682+
:returns: This function is called for its side effect
683+
"""
684+
log.debug('Pinning setuptools < 67 for pep440 non compliant packages "{}"'
685+
.format(venv_dir))
686+
Process((os.path.join(venv_dir, 'bin/pip'),
687+
'install', '-U', 'pip<23.1', 'setuptools<67'),
688+
env=env).exit_on_error()()
689+
690+
673691
def get_venv_package_list(venv_dir, env=None):
674692
"""Get list of packages and their version in virtualenv.
675693

tests/test_utils.py

+8
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ def test_upgrade_venv_core_packages(self, mock_Process):
6868
('/some/dir/bin/pip', 'install', '-U', 'pip', 'setuptools'),
6969
env={'some': 'envvar'})
7070

71+
@unittest.mock.patch.object(utils, "Process")
72+
def test_pin_setuptools_for_pep440(self, mock_Process):
73+
utils.pin_setuptools_for_pep440('/some/dir', env={'some': 'envvar'})
74+
mock_Process.assert_called_once_with(
75+
('/some/dir/bin/pip', 'install', '-U', 'pip<23.1',
76+
'setuptools<67'),
77+
env={'some': 'envvar'})
78+
7179
@unittest.mock.patch("sys.exit")
7280
@unittest.mock.patch.object(utils, "Process")
7381
def test_get_venv_package_list(self, mock_Process, mock_sys_exit):

0 commit comments

Comments
 (0)