From 52b612977907835d096da3ee90a4cdd9a711efbc Mon Sep 17 00:00:00 2001 From: Klaas <kliffen@astron.nl> Date: Tue, 19 Jul 2022 14:41:03 +0200 Subject: [PATCH] Initial tox in CI/CD --- .gitlab-ci.yml | 32 ++++++++++++-------------------- tox.ini | 42 +----------------------------------------- 2 files changed, 13 insertions(+), 61 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f5d308f..d5362db 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,17 +1,13 @@ default: image: python:3.7 # minimum supported version - # Make sure each step is executed in a virtual environment with some basic dependencies present before_script: - python --version # For debugging - - python -m venv venv - - source venv/bin/activate - python -m pip install --upgrade pip - # install common packages required for linting, building, docs etc. - - pip install --upgrade black build flake8 pylint setuptools sphinx twine wheel + - pip install --upgrade tox twine cache: paths: - .cache/pip - - venv/ + # Do not cache .tox, to recreate virtualenvs for every step stages: - lint @@ -29,22 +25,19 @@ variables: run_black: stage: lint script: - - python -m black --version - - python -m black --check --diff . + - tox -e black allow_failure: true run_flake8: stage: lint script: - - python -m flake8 --version - - python -m flake8 map + - tox -e pep8 allow_failure: true run_pylint: stage: lint script: - - python -m pylint --version - - python -m pylint map + - tox -e pylint allow_failure: true # build_extensions: @@ -55,8 +48,7 @@ run_pylint: run_unit_tests: stage: test script: - - pip install -r requirements.txt - - echo "run python unit tests /w coverage" + - tox -e py37,py38,py39,py310 package_files: stage: package @@ -65,7 +57,7 @@ package_files: paths: - dist/* script: - - python -m build # or something similar + - tox -e build package_docs: stage: package @@ -95,11 +87,11 @@ publish_on_gitlab: - if: $CI_COMMIT_TAG script: - echo "run twine for gitlab" - # - | - # TWINE_PASSWORD=${CI_JOB_TOKEN} \ - # TWINE_USERNAME=gitlab-ci-token \ - # python -m twine upload \ - # --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/* + - | + TWINE_PASSWORD=${CI_JOB_TOKEN} \ + TWINE_USERNAME=gitlab-ci-token \ + python -m twine upload \ + --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/* publish_on_test_pypi: stage: publish diff --git a/tox.ini b/tox.ini index 31c19d9..f55d5bb 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,6 @@ deps = -r{toxinidir}/tests/requirements.txt commands = {envpython} --version - stestr run {posargs} # Use generative name and command prefixes to reuse the same virtualenv # for all linting jobs. @@ -29,47 +28,8 @@ commands = black: {envpython} -m black --version black: {envpython} -m black --check --diff . pylint: {envpython} -m pylint --version - pylint: {envpython} -m pylint lofar_station_client - -[testenv:debug] -commands = {envpython} -m testtools.run {posargs} - -[testenv:coverage] -; stestr does not natively support generating coverage reports use -; `PYTHON=python -m coverage run....` to overcome this. -setenv = - PYTHON={envpython} -m coverage run --source lofar_station_client --omit='*tests*' --parallel-mode -commands = - {envpython} -m coverage erase - {envpython} -m stestr run {posargs} - {envpython} -m coverage combine - {envpython} -m coverage html -d cover --omit='*tests*' - {envpython} -m coverage xml -o coverage.xml - {envpython} -m coverage report --omit='*tests*' + pylint: {envpython} -m pylint map [testenv:build] usedevelop = False commands = {envpython} -m build - -[testenv:docs] -deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/docs/requirements.txt -commands = sphinx-build -b html -W docs/source docs/build/html - -[testenv:integration] -# Do no install the lofar station client package, force packaged version install -skip_install = true -# Intentionally break import paths if not installed from package -changedir={toxinidir}/integration -# Allow bash for wheel file substitution -allowlist_external = - bash -commands = - # We need the bash substitutions here - bash -ec 'pip install --force-reinstall {toxinidir}/dist/*.whl' - {envpython} -m stestr run --serial {posargs} - -[flake8] -filename = *.py -exclude=.tox,.egg-info -- GitLab