From e97bdbdfac13cf3e912fdc3c0a9db5ade8e55a9b Mon Sep 17 00:00:00 2001 From: David Verdeguer <daverlo@github.com> Date: Wed, 7 Oct 2020 11:58:55 +0200 Subject: [PATCH] Combine auto_install scripts --- .github/workflows/python-deps-windows.yml | 2 +- lib/init.js | 3 +- lib/init.js.map | 2 +- python-setup/auto_install_packages.py | 40 ++++- python-setup/auto_install_packages_windows.py | 150 ------------------ src/init.ts | 3 +- 6 files changed, 38 insertions(+), 162 deletions(-) delete mode 100644 python-setup/auto_install_packages_windows.py diff --git a/.github/workflows/python-deps-windows.yml b/.github/workflows/python-deps-windows.yml index 00b373aa8..5de085adb 100644 --- a/.github/workflows/python-deps-windows.yml +++ b/.github/workflows/python-deps-windows.yml @@ -49,7 +49,7 @@ jobs: powershell -File $cmd cd $Env:GITHUB_WORKSPACE\\${{ matrix.test_dir }} - py -3 $Env:GITHUB_WORKSPACE\\python-setup\\auto_install_packages_windows.py C:\\hostedtoolcache\\windows\\CodeQL\\0.0.0-20200826\\x64\\codeql + py -3 $Env:GITHUB_WORKSPACE\\python-setup\\auto_install_packages.py C:\\hostedtoolcache\\windows\\CodeQL\\0.0.0-20200826\\x64\\codeql - name: Setup for extractor run: | echo $Env:CODEQL_PYTHON diff --git a/lib/init.js b/lib/init.js index d4b13fe31..b63f7eaa2 100644 --- a/lib/init.js +++ b/lib/init.js @@ -129,10 +129,9 @@ async function installPythonDeps(codeql, logger) { return; } let install_tools_script = "install_tools.sh"; - let auto_install_packages_script = "auto_install_packages.py"; + const auto_install_packages_script = "auto_install_packages.py"; if (process.platform === "win32") { install_tools_script = "install_tools.ps1"; - auto_install_packages_script = "auto_install_packages_windows.py"; } const scriptsFolder = path.resolve(__dirname, "../python-setup"); // Setup tools on the Github hosted runners diff --git a/lib/init.js.map b/lib/init.js.map index 68aaa5736..8c055778b 100644 --- a/lib/init.js.map +++ b/lib/init.js.map @@ -1 +1 @@ -{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names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,WAAW,CAAC,UAAU,CAC9B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,4BAA4B,CAAC,EACtD,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CACjC,CAAC,IAAI,EAAE,CAAC;KACV;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClB,MAAM,CAAC,OAAO,CACZ,+IAA+I,CAChJ,CAAC;KACH;IACD,MAAM,CAAC,QAAQ,EAAE,CAAC;AACpB,CAAC;AAlDD,8CAkDC"} \ No newline at end of file +{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAE7B,0EAA4D;AAE5D,gEAAkD;AAClD,qCAA+C;AAC/C,4DAA8C;AAG9C,mDAAwE;AACxE,6CAA+B;AAExB,KAAK,UAAU,UAAU,CAC9B,SAA6B,EAC7B,UAAkB,EAClB,SAAiB,EACjB,OAAe,EACf,QAAgB,EAChB,IAAe,EACf,MAAc;IAEd,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,MAAM,oBAAW,CAC9B,SAAS,EACT,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,CACP,CAAC;IACF,MAAM,MAAM,CAAC,YAAY,EAAE,CAAC;IAC5B,MAAM,CAAC,QAAQ,EAAE,CAAC;IAClB,OAAO,MAAM,CAAC;AAChB,CAAC;AAtBD,gCAsBC;AAEM,KAAK,UAAU,UAAU,CAC9B,cAAkC,EAClC,YAAgC,EAChC,UAA8B,EAC9B,UAAyB,EACzB,OAAe,EACf,YAAoB,EACpB,MAAc,EACd,YAAoB,EACpB,UAAkB,EAClB,SAAiB,EACjB,MAAc;IAEd,MAAM,CAAC,UAAU,CAAC,6BAA6B,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,MAA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AI,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,SAAS,EAAE;QACxC,IAAI;YACF,MAAM,IAAI,WAAW,CAAC,UAAU,CAC9B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAC/C,CAAC,IAAI,EAAE,CAAC;SACV;QAAC,OAAO,CAAC,EAAE;YACV,mGAAmG;YACnG,uDAAuD;YACvD,MAAM,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,CAAC,OAAO,CACZ,kLAAkL,CACnL,CAAC;SACH;KACF;IAED,uBAAuB;IACvB,IAAI;QACF,MAAM,IAAI,WAAW,CAAC,UAAU,CAC9B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,4BAA4B,CAAC,EACtD,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CACjC,CAAC,IAAI,EAAE,CAAC;KACV;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClB,MAAM,CAAC,OAAO,CACZ,+IAA+I,CAChJ,CAAC;KACH;IACD,MAAM,CAAC,QAAQ,EAAE,CAAC;AACpB,CAAC;AAjDD,8CAiDC"} \ No newline at end of file diff --git a/python-setup/auto_install_packages.py b/python-setup/auto_install_packages.py index cdb70c6d6..ffc795592 100755 --- a/python-setup/auto_install_packages.py +++ b/python-setup/auto_install_packages.py @@ -23,6 +23,8 @@ def _check_output(command): def install_packages_with_poetry(): + if sys.platform.startswith('win32'): + os.environ['POETRY_VIRTUALENVS_PATH'] = os.environ['RUNNER_WORKSPACE'] + '\\virtualenvs' try: _check_call(['poetry', 'install', '--no-root']) except subprocess.CalledProcessError: @@ -36,10 +38,14 @@ def install_packages_with_poetry(): poetry_out = _check_output(['poetry', 'run', 'which', 'python']) python_executable_path = poetry_out.decode('utf-8').splitlines()[-1] + if sys.platform.startswith('win32'): + python_executable_path = python_executable_path[2:] return python_executable_path def install_packages_with_pipenv(): + if sys.platform.startswith('win32'): + os.environ['WORKON_HOME'] = os.environ['RUNNER_WORKSPACE'] + '\\virtualenvs' try: _check_call(['pipenv', 'install', '--keep-outdated', '--ignore-pipfile']) except subprocess.CalledProcessError: @@ -48,29 +54,43 @@ def install_packages_with_pipenv(): pipenv_out = _check_output(['pipenv', 'run', 'which', 'python']) python_executable_path = pipenv_out.decode('utf-8').splitlines()[-1] + if sys.platform.startswith('win32'): + python_executable_path = python_executable_path[2:] return python_executable_path def _create_venv(version: int): # create temporary directory ... that just lives "forever" - venv_path = mkdtemp(prefix='codeql-action-python-autoinstall-') + venv_path = os.environ['RUNNER_WORKSPACE']+'/codeql-action-python-autoinstall' + print ("Creating venv in "+venv_path, flush = True) # virtualenv is a bit nicer for setting up virtual environment, since it will provide # up-to-date versions of pip/setuptools/wheel which basic `python3 -m venv venv` won't - if version == 2: - _check_call(['python2', '-m', 'virtualenv', venv_path]) - elif version == 3: - _check_call(['python3', '-m', 'virtualenv', venv_path]) + if sys.platform.startswith('win32'): + if version == 2: + _check_call(['py', '-2', '-m', 'virtualenv', venv_path]) + elif version == 3: + _check_call(['py', '-3', '-m', 'virtualenv', venv_path]) + else: + if version == 2: + _check_call(['python2', '-m', 'virtualenv', venv_path]) + elif version == 3: + _check_call(['python3', '-m', 'virtualenv', venv_path]) return venv_path def install_requirements_txt_packages(version: int): venv_path = _create_venv(version) + venv_pip = os.path.join(venv_path, 'bin', 'pip') venv_python = os.path.join(venv_path, 'bin', 'python') + if sys.platform.startswith('win32'): + venv_pip = os.path.join(venv_path, 'Scripts', 'pip') + venv_python = os.path.join(venv_path, 'Scripts', 'python') + try: _check_call([venv_pip, 'install', '-r', 'requirements.txt']) except subprocess.CalledProcessError: @@ -81,9 +101,14 @@ def install_requirements_txt_packages(version: int): def install_with_setup_py(version: int): venv_path = _create_venv(version) + venv_pip = os.path.join(venv_path, 'bin', 'pip') venv_python = os.path.join(venv_path, 'bin', 'python') + if sys.platform.startswith('win32'): + venv_pip = os.path.join(venv_path, 'Scripts', 'pip') + venv_python = os.path.join(venv_path, 'Scripts', 'python') + try: # We have to choose between `python setup.py develop` and `pip install -e .`. # Modern projects use `pip install -e .` and I wasn't able to see any downsides @@ -137,7 +162,10 @@ def install_packages(codeql_base_dir) -> Optional[str]: # The binaries for packages installed with `pip install --user` are not available on # PATH by default, so we need to manually add them. - os.environ['PATH'] = os.path.expanduser('~/.local/bin') + os.pathsep + os.environ['PATH'] + if sys.platform.startswith('win32'): + os.environ['PATH'] = os.path.expandvars('%APPDATA%\Python\\Python38\\scripts') + os.pathsep + os.environ['PATH'] + else: + os.environ['PATH'] = os.path.expanduser('~/.local/bin') + os.pathsep + os.environ['PATH'] python_executable_path = install_packages(codeql_base_dir) diff --git a/python-setup/auto_install_packages_windows.py b/python-setup/auto_install_packages_windows.py deleted file mode 100644 index a9252f8c6..000000000 --- a/python-setup/auto_install_packages_windows.py +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/env python3 - -import sys -import os -import subprocess -from tempfile import mkdtemp - -import extractor_version - - -def _check_call(command): - print('+ {}'.format(' '.join(command)), flush=True) - subprocess.check_call(command, stdin=subprocess.DEVNULL) - - -def _check_output(command): - print('+ {}'.format(' '.join(command)), flush=True) - out = subprocess.check_output(command, stdin=subprocess.DEVNULL) - print(out, flush=True) - sys.stderr.flush() - return out - - -def install_packages_with_poetry(): - os.environ['POETRY_VIRTUALENVS_PATH'] = os.environ['RUNNER_WORKSPACE'] + '\\virtualenvs' - try: - _check_call(['poetry', 'install', '--no-root']) - except subprocess.CalledProcessError: - sys.exit('package installation with poetry failed, see error above') - - # poetry is super annoying with `poetry run`, since it will put lots of output on - # STDOUT if the current global python interpreter is not matching the one in the - # 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(['poetry', 'run', 'which', 'python']) - python_executable_path = poetry_out.decode('utf-8').splitlines()[-1] - - return python_executable_path[2:] - - -def install_packages_with_pipenv(): - os.environ['WORKON_HOME'] = os.environ['RUNNER_WORKSPACE'] + '\\virtualenvs' - try: - _check_call(['pipenv', 'install', '--keep-outdated', '--ignore-pipfile']) - except subprocess.CalledProcessError: - sys.exit('package installation with pipenv failed, see error above') - - pipenv_out = _check_output(['pipenv', 'run', 'which', 'python']) - python_executable_path = pipenv_out.decode('utf-8').splitlines()[-1] - - return python_executable_path[2:] - - -def _create_venv(version: int): - # create temporary directory ... that just lives "forever" - venv_path = os.environ['RUNNER_WORKSPACE']+'/codeql-action-python-autoinstall' - print ("Creating venv in "+venv_path, flush = True) - - # virtualenv is a bit nicer for setting up virtual environment, since it will provide - # up-to-date versions of pip/setuptools/wheel which basic `python3 -m venv venv` won't - - if version == 2: - _check_call(['py', '-2', '-m', 'virtualenv', venv_path]) - elif version == 3: - _check_call(['py', '-3', '-m', 'virtualenv', venv_path]) - - return venv_path - - -def install_requirements_txt_packages(version: int): - venv_path = _create_venv(version) - venv_pip = os.path.join(venv_path, 'Scripts', 'pip') - venv_python = os.path.join(venv_path, 'Scripts', 'python') - - try: - _check_call([venv_pip, 'install', '-r', 'requirements.txt']) - except subprocess.CalledProcessError: - sys.exit('package installation with `pip install -r requirements.txt` failed, see error above') - - return venv_python - - -def install_with_setup_py(version: int): - venv_path = _create_venv(version) - venv_pip = os.path.join(venv_path, 'Scripts', 'pip') - venv_python = os.path.join(venv_path, 'Scripts', 'python') - - try: - # We have to choose between `python setup.py develop` and `pip install -e .`. - # Modern projects use `pip install -e .` and I wasn't able to see any downsides - # to doing so. However, `python setup.py develop` has some downsides -- from - # https://stackoverflow.com/a/19048754 : - # > Note that it is highly recommended to use pip install . (install) and pip - # > install -e . (developer install) to install packages, as invoking setup.py - # > directly will do the wrong things for many dependencies, such as pull - # > prereleases and incompatible package versions, or make the package hard to - # > uninstall with pip. - - _check_call([venv_pip, 'install', '-e', '.']) - except subprocess.CalledProcessError: - sys.exit('package installation with `pip install -e .` failed, see error above') - - return venv_python - - -def install_packages() -> str: - if os.path.exists('poetry.lock'): - print('Found poetry.lock, will install packages with poetry', flush=True) - return install_packages_with_poetry() - - if os.path.exists('Pipfile') or os.path.exists('Pipfile.lock'): - if os.path.exists('Pipfile.lock'): - print('Found Pipfile.lock, will install packages with Pipenv', flush=True) - else: - print('Found Pipfile, will install packages with Pipenv', flush=True) - return install_packages_with_pipenv() - - version = extractor_version.get_extractor_version(sys.argv[1], quiet=False) - - if os.path.exists('requirements.txt'): - print('Found requirements.txt, will install packages with pip', flush=True) - return install_requirements_txt_packages(version) - - if os.path.exists('setup.py'): - print('Found setup.py, will install package with pip in editable mode', flush=True) - return install_with_setup_py(version) - - print("was not able to install packages automatically", flush=True) - - -if __name__ == "__main__": - if len(sys.argv) != 2: - sys.exit('Must provide base directory for codeql tool as only argument') - - # The binaries for packages installed with `pip install --user` are not available on - # PATH by default, so we need to manually add them. - os.environ['PATH'] = os.path.expandvars('%APPDATA%\Python\\Python38\\scripts') + os.pathsep + os.environ['PATH'] - - python_executable_path = install_packages() - - if python_executable_path is not None: - print("Setting CODEQL_PYTHON={}".format(python_executable_path)) - print("::set-env name=CODEQL_PYTHON::{}".format(python_executable_path)) - -# TODO: -# - no packages -# - poetry without version -# - pipenv without version -# - pipenv without lockfile diff --git a/src/init.ts b/src/init.ts index e39c7dcd7..d9af96d6c 100644 --- a/src/init.ts +++ b/src/init.ts @@ -195,11 +195,10 @@ export async function installPythonDeps(codeql: CodeQL, logger: Logger) { } let install_tools_script = "install_tools.sh"; - let auto_install_packages_script = "auto_install_packages.py"; + const auto_install_packages_script = "auto_install_packages.py"; if (process.platform === "win32") { install_tools_script = "install_tools.ps1"; - auto_install_packages_script = "auto_install_packages_windows.py"; } const scriptsFolder = path.resolve(__dirname, "../python-setup");