Skip to content

Commit

Permalink
Skip pinning of deps when running python >= 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
freyes committed Apr 10, 2024
1 parent 2fbbe1d commit fb7a586
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions charmtools/build/tactics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,9 @@ def __call__(self):
).exit_on_error()()
if self.upgrade_deps:
utils.upgrade_venv_core_packages(self._venv, env=self._get_env())
elif utils.get_python_version(self._venv,
env=self._get_env()) >= utils.PY312:
pass
else:
utils.pin_setuptools_for_pep440(self._venv, env=self._get_env())
log.debug(
Expand Down
22 changes: 22 additions & 0 deletions charmtools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from path import Path as path

log = logging.getLogger('utils')
PY312 = (3, 12, 0)


@contextmanager
Expand Down Expand Up @@ -702,3 +703,24 @@ def get_venv_package_list(venv_dir, env=None):
if result:
return result.output
result.exit_on_error()


def get_python_version(venv_dir, env=None):
"""Get the Python interpreter version in the virtualenv.
:param venv_dir: Full path to virtualenv in which packages will be listed
:type venv_dir: str
:param env: Environment to use when executing command
:type env: Optional[Dict[str,str]]
:returns: Tuple with major, minor and microversion
:rtype: Tuple[str]
"""
result = Process((os.path.join(venv_dir, 'bin/python3'), '--version'),
env=env)()
m = re.match(r'^Python[ ]+(\d+)\.(\d+)\.(\d+).*', result)
if not m:
raise ValueError('Cannot identify the python version: %s' % result)

return (int(m.group(1)),
int(m.group(2)),
int(m.group(3)))

0 comments on commit fb7a586

Please sign in to comment.