-
Notifications
You must be signed in to change notification settings - Fork 38
/
install-packages.yml
executable file
·202 lines (200 loc) · 8.94 KB
/
install-packages.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
description: >
Setup a python environment and install the packages for your project either globally with pip or in a virtualenv with poetry or pipenv.
With pip as pkg-manager, the command will assume `-r requirements.txt`.
With poetry as pkg-manager, the command will assume `--no-ansi`.
For pipenv, no args are provided. Expect the default caching locations for packages and virtualenvs on a debian system with pyenv.
parameters:
pkg-manager:
type: enum
enum: [auto, poetry, pipenv, pip, pip-dist]
default: auto
description: Which package management tool to use, pipenv, pip or poetry with dependency file. Use `pip-dist` to install with project setup.py.
path-args:
type: string
default: "."
description: |
If using `pip-dist` these are the arguments after the command `pip install -e` that is by default set to `.`. Use of this parameter allows
for multiple paths to be specified. This is important when extra paths are required to install extra packages referenced via `extras_requires`.
args:
type: string
default: ""
description: |
Arguments to pass to install command for pipenv and poetry. For pip, arguments are after the command, `pip install -r requirements.txt <args>`.
For poetry, args are after `--no-ansi` as output option.
pip-dependency-file:
type: string
default: requirements.txt
description: |
Name of the requirements file that needs to be installed with pip. Prepended with `app-dir`. If using pipenv or poetry, this is ignored.
If using `pip-dist`, use this to use the cache checksum against the `setup.py` if desired.
If `pip-dependency-file` is set to an empty string, no dependency file is used in the `pip install` command.
app-dir:
type: string
default: "."
description: Path to the directory containing your python project. Not needed if dependency file lives in the root.
no_output_timeout:
type: string
default: "10m"
description: Elapsed time the command can run without output. Passed to install command.
venv-cache:
type: boolean
default: true
description: Use the lockfile to cache the virtualenv. Not used with pip as pkg-manager.
pypi-cache:
type: boolean
default: true
description: Keep all versions of pypi and site-package caches for faster rebuilding overall.
venv-path:
type: string
default: ""
description: Override venv path. As json array - ex '[ "path", "path2" ]'
cache-version:
type: string
default: v1
description: Change the default cache version if you need to clear the cache for any reason.
include-branch-in-cache-key:
type: boolean
default: true
description: >
If true, this cache bucket will only apply to jobs within the same branch.
pre-install-steps:
type: steps
default: []
description: >
Steps needed between restoring the cache and the install step.
include-python-in-cache-key:
type: boolean
default: true
description: >
If true, this cache bucket will checksum the pyenv python version with the cache-key.
steps:
- run:
name: "Export automatic environment detection script"
command: | # detect-env.sh
echo 'if [ "${PARAM_PKG_MNGR}" = "auto" ]; then
if [ -f "requirements.txt" ]; then
if [ -f "${PARAM_SETUP_FILE_PATH:-setup.py}" ]; then
export DETECT_PKG_MNGR="pip-dist"
else
export DETECT_PKG_MNGR="pip"
fi
elif [ -f "Pipfile" ]; then
export DETECT_PKG_MNGR="pipenv"
export PYTHON_ENV_TOOL="pipenv"
elif [ -f "pyproject.toml" ]; then
export DETECT_PKG_MNGR="poetry"
export PYTHON_ENV_TOOL="poetry"
fi
echo "INFO: Detected Package Manager ${DETECT_PKG_MNGR}"
fi' > /tmp/detect-env.sh
chmod +x /tmp/detect-env.sh
echo 'export AUTO_DETECT_ENV_SCRIPT="/tmp/detect-env.sh"' >> $BASH_ENV
# restore caches
- when:
condition:
or:
- << parameters.pypi-cache >>
- << parameters.venv-cache >>
steps:
- run:
name: Link lockfile
environment:
PARAM_PKG_MNGR: << parameters.pkg-manager >>
PARAM_APP_DIR: << parameters.app-dir >>
PARAM_DEPENDENCY_FILE: << parameters.pip-dependency-file >>
PARAM_PYPI_CACHE: << parameters.pypi-cache >>
PARAM_VENV_CACHE: << parameters.venv-cache >>
PARAM_VENV_PATH: << parameters.venv-path >>
command: <<include(scripts/cache-link-lockfile.sh)>>
working_directory: << parameters.app-dir >>
- restore_cache:
keys:
- <<parameters.cache-version>>-cci_pycache-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "/tmp/cci_pycache/lockfile" }}-<<#parameters.include-python-in-cache-key>>{{ checksum "/home/circleci/.pyenv/version" }}-<</parameters.include-python-in-cache-key>>
- run:
name: Move restored cache
working_directory: << parameters.app-dir >>
environment:
PARAM_PYPI_CACHE: << parameters.pypi-cache >>
PARAM_VENV_CACHE: << parameters.venv-cache >>
command: <<include(scripts/cache-restore.sh)>>
# run install steps
- steps: <<parameters.pre-install-steps>>
- when:
condition:
equal: [auto, << parameters.pkg-manager >>]
steps:
- run:
name: "Install dependencies with automatically determined project package manager"
working_directory: << parameters.app-dir >>
no_output_timeout: << parameters.no_output_timeout >>
environment:
PARAM_PKG_MNGR: << parameters.pkg-manager >>
PARAM_APP_DIR: << parameters.app-dir >>
PARAM_DEPENDENCY_FILE: << parameters.pip-dependency-file >>
PARAM_PATH_ARGS: << parameters.path-args >>
PARAM_ADDITIONAL_ARGS: << parameters.args >>
command: <<include(scripts/auto-install-command.sh)>>
- when:
condition:
equal: [pipenv, << parameters.pkg-manager >>]
steps:
- run:
name: "Install dependencies with pipenv using project Pipfile or inline packages"
working_directory: << parameters.app-dir >>
command: |
pipenv install << parameters.args >>
- when:
condition:
equal: [poetry, << parameters.pkg-manager >>]
steps:
- run:
name: "Install dependencies with poetry using project pyproject.toml"
working_directory: << parameters.app-dir >>
command: |
poetry install --no-ansi << parameters.args >>
- when:
condition:
# if pip == pkgmanager and args != "" or pip-dependency-file != ""
and:
- equal: [pip, << parameters.pkg-manager >>]
- or:
# true if no arguments
- <<parameters.args>>
# true if dep file
- <<parameters.pip-dependency-file>>
steps:
- run:
name: "Install dependencies with pip using project <<parameters.pip-dependency-file>>"
working_directory: <<parameters.app-dir>>
command: |
pip install <<#parameters.pip-dependency-file>>-r <<parameters.pip-dependency-file>><</parameters.pip-dependency-file>> << parameters.args >>
- when:
condition:
equal: [pip-dist, << parameters.pkg-manager >>]
steps:
- run:
name: "Install dependencies with pip using project setup.py"
working_directory: <<parameters.app-dir>>
command: |
pip install -e << parameters.path-args >> << parameters.args >>
- when:
condition:
or:
- << parameters.pypi-cache >>
- << parameters.venv-cache >>
steps:
- run:
name: Copy to cache directory
working_directory: << parameters.app-dir >>
environment:
PARAM_PKG_MNGR: << parameters.pkg-manager >>
PARAM_APP_DIR: << parameters.app-dir >>
PARAM_DEPENDENCY_FILE: << parameters.pip-dependency-file >>
PARAM_VENV_CACHE: << parameters.venv-cache >>
PARAM_PYPI_CACHE: << parameters.pypi-cache >>
PARAM_VENV_PATH: << parameters.venv-path >>
command: <<include(scripts/cache-save.sh)>>
- save_cache:
key: <<parameters.cache-version>>-cci_pycache-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "/tmp/cci_pycache/lockfile" }}-<<#parameters.include-python-in-cache-key>>{{ checksum "/home/circleci/.pyenv/version" }}-<</parameters.include-python-in-cache-key>>
paths:
- /tmp/cci_pycache