Skip to content

Commit

Permalink
Merge pull request #1258 from github/rasmuswl/poetry-v1.2
Browse files Browse the repository at this point in the history
python-setup: Add support for Poetry 1.2
  • Loading branch information
RasmusWL authored Sep 21, 2022
2 parents c2c7bba + ca8a78d commit 417059f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [UNRELEASED]

- 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.
- Add support for Python automatic dependency installation with Poetry 1.2 [#1258](https://github.com/github/codeql-action/pull/1258).

## 2.1.24 - 16 Sep 2022

Expand Down
26 changes: 20 additions & 6 deletions python-setup/auto_install_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,41 @@
import extractor_version


def _check_call(command):
def _check_call(command, extra_env={}):
print('+ {}'.format(' '.join(command)), flush=True)
subprocess.check_call(command, stdin=subprocess.DEVNULL)

env = os.environ.copy()
env.update(extra_env)
subprocess.check_call(command, stdin=subprocess.DEVNULL, env=env)
sys.stdout.flush()
sys.stderr.flush()


def _check_output(command):
def _check_output(command, extra_env={}):
print('+ {}'.format(' '.join(command)), flush=True)
out = subprocess.check_output(command, stdin=subprocess.DEVNULL)

env = os.environ.copy()
env.update(extra_env)
out = subprocess.check_output(command, stdin=subprocess.DEVNULL, env=env)
print(out, flush=True)
sys.stderr.flush()
return out


def install_packages_with_poetry():

# To handle poetry 1.2, which started to use keyring interaction MUCH more, we need
# add a workaround. See
# https://github.com/python-poetry/poetry/issues/2692#issuecomment-1235683370
extra_poetry_env = {"PYTHON_KEYRING_BACKEND": "keyring.backends.null.Keyring"}

command = [sys.executable, '-m', 'poetry']
if sys.platform.startswith('win32'):
# In windows the default path were the deps are installed gets wiped out between steps,
# so we have to set it up to a folder that will be kept
os.environ['POETRY_VIRTUALENVS_PATH'] = os.path.join(os.environ['RUNNER_WORKSPACE'], 'virtualenvs')
try:
_check_call(command + ['install', '--no-root'])
_check_call(command + ['install', '--no-root'], extra_env=extra_poetry_env)
except subprocess.CalledProcessError:
sys.exit('package installation with poetry failed, see error above')

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

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

if sys.platform.startswith('win32'):
Expand Down
3 changes: 1 addition & 2 deletions python-setup/install_tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ py -3 -m pip install --user --upgrade pip setuptools wheel
py -2 -m pip install --user 'virtualenv!=20.12.0'
py -3 -m pip install --user virtualenv

# We aren't compatible with poetry 1.2
py -3 -m pip install --user "poetry>=1.1,<1.2"
py -3 -m pip install --user "poetry>=1.1"
py -3 -m pip install --user pipenv
3 changes: 1 addition & 2 deletions python-setup/install_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ python3 -m pip install --user virtualenv
# "program uses threads.", RuntimeWarning)
# 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

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

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

0 comments on commit 417059f

Please sign in to comment.