Skip to content

Commit 70509c3

Browse files
committed
python-setup: Add support for Poetry 1.2
1 parent aaca819 commit 70509c3

4 files changed

Lines changed: 31 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [UNRELEASED]
44

55
- We will soon be rolling out a feature of the CodeQL Action that stores some information used to make future runs faster in the GitHub Actions cache. Initially, this will only be enabled on JavaScript repositories, but we plan to add more languages to this soon. The new feature can be disabled by passing the `trap-caching: false` option to your workflow's `init` step, for example if you are already using the GitHub Actions cache for a different purpose and are near the storage limit for it.
6+
- Add support for Python automatic dependency installation with Poetry 1.2.
67

78
## 2.1.24 - 16 Sep 2022
89

python-setup/auto_install_packages.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,49 @@
99
import extractor_version
1010

1111

12-
def _check_call(command):
12+
def _check_call(command, extra_env=None):
1313
print('+ {}'.format(' '.join(command)), flush=True)
14-
subprocess.check_call(command, stdin=subprocess.DEVNULL)
1514

15+
# only pass `env` argument if we need to pass in an updated environment
16+
kwargs = {}
17+
if extra_env:
18+
new_env = os.environ.copy()
19+
new_env.update(extra_env)
20+
kwargs = {"env": new_env}
1621

17-
def _check_output(command):
22+
subprocess.check_call(command, stdin=subprocess.DEVNULL, **kwargs)
23+
24+
25+
def _check_output(command, extra_env=None):
1826
print('+ {}'.format(' '.join(command)), flush=True)
19-
out = subprocess.check_output(command, stdin=subprocess.DEVNULL)
27+
28+
# only pass `env` argument if we need to pass in an updated environment
29+
kwargs = {}
30+
if extra_env:
31+
new_env = os.environ.copy()
32+
new_env.update(extra_env)
33+
kwargs = {"env": new_env}
34+
35+
out = subprocess.check_output(command, stdin=subprocess.DEVNULL, **kwargs)
2036
print(out, flush=True)
2137
sys.stderr.flush()
2238
return out
2339

2440

2541
def install_packages_with_poetry():
42+
43+
# To handle poetry 1.2, which started to use keyring interaction MUCH more, we need
44+
# add a workaround. See
45+
# https://github.com/python-poetry/poetry/issues/2692#issuecomment-1235683370
46+
extra_poetry_env = {"PYTHON_KEYRING_BACKEND": "keyring.backends.null.Keyring"}
47+
2648
command = [sys.executable, '-m', 'poetry']
2749
if sys.platform.startswith('win32'):
2850
# In windows the default path were the deps are installed gets wiped out between steps,
2951
# so we have to set it up to a folder that will be kept
3052
os.environ['POETRY_VIRTUALENVS_PATH'] = os.path.join(os.environ['RUNNER_WORKSPACE'], 'virtualenvs')
3153
try:
32-
_check_call(command + ['install', '--no-root'])
54+
_check_call(command + ['install', '--no-root'], extra_env=extra_poetry_env)
3355
except subprocess.CalledProcessError:
3456
sys.exit('package installation with poetry failed, see error above')
3557

@@ -38,7 +60,7 @@ def install_packages_with_poetry():
3860
# virtualenv for the package, which was the case for using poetry for Python 2 when
3961
# default system interpreter was Python 3 :/
4062

41-
poetry_out = _check_output(command + ['run', 'which', 'python'])
63+
poetry_out = _check_output(command + ['run', 'which', 'python'], extra_env=extra_poetry_env)
4264
python_executable_path = poetry_out.decode('utf-8').splitlines()[-1]
4365

4466
if sys.platform.startswith('win32'):

python-setup/install_tools.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ py -3 -m pip install --user --upgrade pip setuptools wheel
88
py -2 -m pip install --user 'virtualenv<20.11'
99
py -3 -m pip install --user 'virtualenv<20.11'
1010

11-
# We aren't compatible with poetry 1.2
12-
py -3 -m pip install --user "poetry>=1.1,<1.2"
11+
py -3 -m pip install --user "poetry>=1.1"
1312
py -3 -m pip install --user pipenv

python-setup/install_tools.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ python3 -m pip install --user 'virtualenv<20.11'
2424
# "program uses threads.", RuntimeWarning)
2525
# LGTM_PYTHON_SETUP_VERSION=The currently activated Python version 2.7.18 is not supported by the project (^3.5). Trying to find and use a compatible version. Using python3 (3.8.2) 3
2626

27-
# We aren't compatible with poetry 1.2
28-
python3 -m pip install --user "poetry>=1.1,<1.2"
27+
python3 -m pip install --user "poetry>=1.1"
2928
python3 -m pip install --user pipenv
3029

3130
if command -v python2 >/dev/null 2>&1; then

0 commit comments

Comments
 (0)