Skip to content

Commit 808c292

Browse files
committed
Support Pipfile without Pipfile.lock
As previously written, if codeql finds a `Pipfile`, but no `Pipfile.lock`, it will run `pipenv install` with args that require `Pipfile.lock` to exist. Pipfile will fail with this message: ``` Usage: python -m pipenv install [OPTIONS] [PACKAGES]... ERROR:: Pipfile.lock must exist to use --keep-outdated! package installation with pipenv failed, see error above ``` This changeset enables auto_install to work with Pipfile when there is no lock. (Bonus: `--skip-lock` is generally a bit faster.)
1 parent 8b2f5d7 commit 808c292

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

python-setup/auto_install_packages.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ def install_packages_with_poetry():
4848
return python_executable_path
4949

5050

51-
def install_packages_with_pipenv():
51+
def install_packages_with_pipenv(skip_lock=False):
5252
command = [sys.executable, '-m', 'pipenv']
5353
if sys.platform.startswith('win32'):
5454
# In windows the default path were the deps are installed gets wiped out between steps,
5555
# so we have to set it up to a folder that will be kept
5656
os.environ['WORKON_HOME'] = os.path.join(os.environ['RUNNER_WORKSPACE'], 'virtualenvs')
57+
lock_args = ['--skip-lock'] if skip_lock else ['--keep-outdated', '--ignore-pipfile']
5758
try:
58-
_check_call(command + ['install', '--keep-outdated', '--ignore-pipfile'])
59+
_check_call(command + ['install'] + lock_args)
5960
except subprocess.CalledProcessError:
6061
sys.exit('package installation with pipenv failed, see error above')
6162

@@ -145,9 +146,11 @@ def install_packages(codeql_base_dir) -> Optional[str]:
145146
if os.path.exists('Pipfile') or os.path.exists('Pipfile.lock'):
146147
if os.path.exists('Pipfile.lock'):
147148
print('Found Pipfile.lock, will install packages with Pipenv', flush=True)
149+
return install_packages_with_pipenv()
148150
else:
149151
print('Found Pipfile, will install packages with Pipenv', flush=True)
150-
return install_packages_with_pipenv()
152+
return install_packages_with_pipenv(skip_lock=True)
153+
151154

152155
# get_extractor_version returns the Python version the extractor thinks this repo is using
153156
version = extractor_version.get_extractor_version(codeql_base_dir, quiet=False)

0 commit comments

Comments
 (0)