@@ -23,8 +23,13 @@ def _check_output(command):
2323
2424
2525def install_packages_with_poetry ():
26+ command = [sys .executable , '-m' , 'poetry' ]
27+ if sys .platform .startswith ('win32' ):
28+ # In windows the default path were the deps are installed gets wiped out between steps,
29+ # so we have to set it up to a folder that will be kept
30+ os .environ ['POETRY_VIRTUALENVS_PATH' ] = os .path .join (os .environ ['RUNNER_WORKSPACE' ], 'virtualenvs' )
2631 try :
27- _check_call ([ 'poetry' , 'install' , '--no-root' ])
32+ _check_call (command + [ 'install' , '--no-root' ])
2833 except subprocess .CalledProcessError :
2934 sys .exit ('package installation with poetry failed, see error above' )
3035
@@ -33,44 +38,69 @@ def install_packages_with_poetry():
3338 # virtualenv for the package, which was the case for using poetry for Python 2 when
3439 # default system interpreter was Python 3 :/
3540
36- poetry_out = _check_output ([ 'poetry' , 'run' , 'which' , 'python' ])
41+ poetry_out = _check_output (command + [ 'run' , 'which' , 'python' ])
3742 python_executable_path = poetry_out .decode ('utf-8' ).splitlines ()[- 1 ]
3843
44+ if sys .platform .startswith ('win32' ):
45+ # Poetry produces a path that starts by /d instead of D:\ and Windows doesn't like that way of specifying the drive letter.
46+ # We completely remove it because it is not needed as everything is in the same drive (We are installing the dependencies in the RUNNER_WORKSPACE)
47+ python_executable_path = python_executable_path [2 :]
3948 return python_executable_path
4049
4150
4251def install_packages_with_pipenv ():
52+ command = [sys .executable , '-m' , 'pipenv' ]
53+ if sys .platform .startswith ('win32' ):
54+ # In windows the default path were the deps are installed gets wiped out between steps,
55+ # so we have to set it up to a folder that will be kept
56+ os .environ ['WORKON_HOME' ] = os .path .join (os .environ ['RUNNER_WORKSPACE' ], 'virtualenvs' )
4357 try :
44- _check_call ([ 'pipenv' , 'install' , '--keep-outdated' , '--ignore-pipfile' ])
58+ _check_call (command + [ 'install' , '--keep-outdated' , '--ignore-pipfile' ])
4559 except subprocess .CalledProcessError :
4660 sys .exit ('package installation with pipenv failed, see error above' )
4761
48- pipenv_out = _check_output ([ 'pipenv' , 'run' , 'which' , 'python' ])
62+ pipenv_out = _check_output (command + [ 'run' , 'which' , 'python' ])
4963 python_executable_path = pipenv_out .decode ('utf-8' ).splitlines ()[- 1 ]
5064
65+ if sys .platform .startswith ('win32' ):
66+ # Pipenv produces a path that starts by /d instead of D:\ and Windows doesn't like that way of specifying the drive letter.
67+ # We completely remove it because it is not needed as everything is in the same drive (We are installing the dependencies in the RUNNER_WORKSPACE)
68+ python_executable_path = python_executable_path [2 :]
5169 return python_executable_path
5270
5371
5472def _create_venv (version : int ):
5573 # create temporary directory ... that just lives "forever"
56- venv_path = mkdtemp (prefix = 'codeql-action-python-autoinstall-' )
74+ venv_path = os .path .join (os .environ ['RUNNER_WORKSPACE' ], 'codeql-action-python-autoinstall' )
75+ print ("Creating venv in " + venv_path , flush = True )
5776
5877 # virtualenv is a bit nicer for setting up virtual environment, since it will provide
5978 # up-to-date versions of pip/setuptools/wheel which basic `python3 -m venv venv` won't
6079
61- if version == 2 :
62- _check_call (['python2' , '-m' , 'virtualenv' , venv_path ])
63- elif version == 3 :
64- _check_call (['python3' , '-m' , 'virtualenv' , venv_path ])
80+ if sys .platform .startswith ('win32' ):
81+ if version == 2 :
82+ _check_call (['py' , '-2' , '-m' , 'virtualenv' , venv_path ])
83+ elif version == 3 :
84+ _check_call (['py' , '-3' , '-m' , 'virtualenv' , venv_path ])
85+ else :
86+ if version == 2 :
87+ _check_call (['python2' , '-m' , 'virtualenv' , venv_path ])
88+ elif version == 3 :
89+ _check_call (['python3' , '-m' , 'virtualenv' , venv_path ])
6590
6691 return venv_path
6792
6893
6994def install_requirements_txt_packages (version : int ):
7095 venv_path = _create_venv (version )
96+
7197 venv_pip = os .path .join (venv_path , 'bin' , 'pip' )
7298 venv_python = os .path .join (venv_path , 'bin' , 'python' )
7399
100+ if sys .platform .startswith ('win32' ):
101+ venv_pip = os .path .join (venv_path , 'Scripts' , 'pip' )
102+ venv_python = os .path .join (venv_path , 'Scripts' , 'python' )
103+
74104 try :
75105 _check_call ([venv_pip , 'install' , '-r' , 'requirements.txt' ])
76106 except subprocess .CalledProcessError :
@@ -81,9 +111,14 @@ def install_requirements_txt_packages(version: int):
81111
82112def install_with_setup_py (version : int ):
83113 venv_path = _create_venv (version )
114+
84115 venv_pip = os .path .join (venv_path , 'bin' , 'pip' )
85116 venv_python = os .path .join (venv_path , 'bin' , 'python' )
86117
118+ if sys .platform .startswith ('win32' ):
119+ venv_pip = os .path .join (venv_path , 'Scripts' , 'pip' )
120+ venv_python = os .path .join (venv_path , 'Scripts' , 'python' )
121+
87122 try :
88123 # We have to choose between `python setup.py develop` and `pip install -e .`.
89124 # Modern projects use `pip install -e .` and I wasn't able to see any downsides
@@ -135,12 +170,11 @@ def install_packages(codeql_base_dir) -> Optional[str]:
135170
136171 codeql_base_dir = sys .argv [1 ]
137172
138- # The binaries for packages installed with `pip install --user` are not available on
139- # PATH by default, so we need to manually add them.
140- os .environ ['PATH' ] = os .path .expanduser ('~/.local/bin' ) + os .pathsep + os .environ ['PATH' ]
141-
142173 python_executable_path = install_packages (codeql_base_dir )
143174
144175 if python_executable_path is not None :
176+ # see https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
177+ env_file = open (os .environ ["GITHUB_ENV" ], mode = "at" )
178+
145179 print ("Setting CODEQL_PYTHON={}" .format (python_executable_path ))
146- print ("::set-env name= CODEQL_PYTHON:: {}" .format (python_executable_path ))
180+ print ("CODEQL_PYTHON= {}" .format (python_executable_path ), file = env_file )
0 commit comments