-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
148 lines (134 loc) · 4.86 KB
/
.gitlab-ci.yml
File metadata and controls
148 lines (134 loc) · 4.86 KB
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
image:
name: "python:3.7"
stages:
- build
- test
- doc
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PYTHONTOOLS_VENV_PATH: "$CI_PROJECT_DIR/venv/simdb"
PYTHONTOOLS_DIR: "$CI_PROJECT_DIR"
PACKAGE: "simdb"
# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
.cache_python: &cache_python
paths:
- $PIP_CACHE_DIR
########################################
# General Docker environment templates #
########################################
##############################
# Global tests and templates #
##############################
before_script:
- export USER=root
.collect_deps_manually: &collect_deps_manually |
export BUILD_DEPS=$(cat pyproject.toml | grep requires | cut -d'=' -f2- | tr -d ,\"\' | sed "s/^ \[//" | sed "s/\]$//")
export RUN_DEP_FILES=dev_requirements.txt
.print_debugging: &print_debugging |
python --version # Print out python version for debugging
pip --version # Show pip version for debugging
echo $PYTHONPATH
echo $PATH
echo BUILD_DEPS=$BUILD_DEPS
echo RUN_DEP_FILES=$RUN_DEP_FILES
# venv editable install
.install_venv_editable_template:
script:
- *collect_deps_manually
- *print_debugging
# Now we install dependencies manually
- pip install --upgrade $BUILD_DEPS # Install build deps manually
- python setup.py --version # Print setuptools found version
- python -m pip freeze > $PYTHONTOOLS_DIR/pre_install_packages.txt
- for file in $RUN_DEP_FILES; do echo Installing $file; pip install -r $file; done; # Install run deps manually
# Install from wheel
# Should install almost nothing, as we installed most of it ourselves
# Install without extras here. We installed these manually.
- pip install ---no-build-isolation --upgrade --editable . # Install local folder in editable mode
- pip freeze > $PYTHONTOOLS_DIR/post_install_packages.txt
# Do basic sanity checking
- mkdir tmp && cd tmp
- python -c "import $PACKAGE; print($PACKAGE.__version__); print($PACKAGE.__path__)" # Try regular import
# Run the real test, pytest
- which pytest
- pytest --version
- echo Running "pytest --cov=$PACKAGE --cov-report=term --cov-report=xml:$PYTHONTOOLS_DIR/coverage.xml --junit-xml=$PYTHONTOOLS_DIR/junit.xml --ignore=../tests/NNDB '"$PYTHONTOOLS_DIR"'"
- pytest --cov=$PACKAGE --cov-report=term --cov-report=xml:$PYTHONTOOLS_DIR/coverage.xml --junit-xml=$PYTHONTOOLS_DIR/junit.xml "$PYTHONTOOLS_DIR"
# One pipeline has one artifact. We need both the test report _and_ the installed packages to pass on
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
reports:
junit: [$PYTHONTOOLS_DIR/junit.xml]
cobertura: [$PYTHONTOOLS_DIR/coverage.xml]
when: always
expire_in: 1 day # These are only used in quick interactive CI debugging, and in next jobs
stage: test
cache:
<<: *cache_python
policy: push
needs: [] # Only needs a sane python env
# editable venv-like install
install_venv_editable:
extends: .install_venv_editable_template
flake8:
stage: test
before_script:
- pip install flake8 pyflakes anybadge
script:
- mkdir -p ./flake8
- flake8 --exit-zero --doctests --statistics --count $(find $PACKAGE -name '*.py') | tee flake8.txt
- PEP8_VIOLATIONS=$(tail flake8.txt -n1)
- echo "Flake8 finds $PEP8_VIOLATIONS PEP8 violations"
- anybadge -ou --label=flake8 --value=$PEP8_VIOLATIONS --file=flake8/flake8.svg -c silver
artifacts:
paths:
- ./flake8/
pylint:
stage: test
before_script:
- pip install pylint pylint-exit anybadge
script:
- mkdir -p ./pylint
- pylint --rcfile=.pylintrc --output-format=text src | tee ./pylint/pylint.log || pylint-exit $?
- PYLINT_SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./pylint/pylint.log)
- echo "Pylint score is $PYLINT_SCORE"
- anybadge -ou --label=pylint --value=$PYLINT_SCORE --file=pylint/pylint.svg 2=red 4=orange 8=yellow 10=green
artifacts:
paths:
- ./pylint/
black:
stage: test
script:
- pip install black
- black --diff --color src
pages:
stage: doc
script:
- pip install -r dev_requirements.txt
- pip install --upgrade --editable .
- cd docs
- sphinx-apidoc -f -o sphinx -e -M ../src/simdb && rm sphinx/modules.rst
- cp *.md sphinx
- cp *.svg sphinx
- make clean
- make html
- mv _build/html/ ../public/
artifacts:
paths:
- public/
- docs/_build/
- docs/source/generated/
only:
- master
- /^release.*$/
- feature/ukaea-gitlab-ci
cache:
<<: *cache_python
policy: pull
needs: ["install_venv_editable"]