Skip to content
Snippets Groups Projects
Commit 726f5dc5 authored by Klaas Kliffen's avatar Klaas Kliffen :satellite:
Browse files

Merge branch 'features/CWG-11_add_tox' into 'main'

Resolve CWG-11 "Features/ add tox"

Closes CWG-11

See merge request !5
parents 61b812c5 0f7dc5b0
No related branches found
No related tags found
1 merge request!5Resolve CWG-11 "Features/ add tox"
dist/* dist/*
*.egg-info *.egg-info
*.pyc
.coverage
default: default:
image: python:3.7 # minimum supported version image: python:3.10 # use latest for building/linting
# Make sure each step is executed in a virtual environment with some basic dependencies present
before_script: before_script:
- python --version # For debugging - python --version # For debugging
- python -m venv venv
- source venv/bin/activate
- python -m pip install --upgrade pip - python -m pip install --upgrade pip
# install common packages required for linting, building, docs etc. - pip install --upgrade tox twine
- pip install --upgrade black build flake8 pylint setuptools sphinx twine wheel
cache: cache:
paths: paths:
- .cache/pip - .cache/pip
- venv/ # Do not cache .tox, to recreate virtualenvs for every step
stages: stages:
- lint - lint
...@@ -29,22 +25,19 @@ variables: ...@@ -29,22 +25,19 @@ variables:
run_black: run_black:
stage: lint stage: lint
script: script:
- python -m black --version - tox -e black
- python -m black --check --diff .
allow_failure: true allow_failure: true
run_flake8: run_flake8:
stage: lint stage: lint
script: script:
- python -m flake8 --version - tox -e pep8
- python -m flake8 map
allow_failure: true allow_failure: true
run_pylint: run_pylint:
stage: lint stage: lint
script: script:
- python -m pylint --version - tox -e pylint
- python -m pylint map
allow_failure: true allow_failure: true
# build_extensions: # build_extensions:
...@@ -54,9 +47,12 @@ run_pylint: ...@@ -54,9 +47,12 @@ run_pylint:
run_unit_tests: run_unit_tests:
stage: test stage: test
image: python:3.${PY_VERSION}
script: script:
- pip install -r requirements.txt - tox -e py3${PY_VERSION}
- echo "run python unit tests /w coverage" parallel:
matrix: # use the matrix for testing
- PY_VERSION: [7, 8, 9, 10]
package_files: package_files:
stage: package stage: package
...@@ -65,7 +61,7 @@ package_files: ...@@ -65,7 +61,7 @@ package_files:
paths: paths:
- dist/* - dist/*
script: script:
- python -m build # or something similar - tox -e build
package_docs: package_docs:
stage: package stage: package
...@@ -95,11 +91,11 @@ publish_on_gitlab: ...@@ -95,11 +91,11 @@ publish_on_gitlab:
- if: $CI_COMMIT_TAG - if: $CI_COMMIT_TAG
script: script:
- echo "run twine for gitlab" - echo "run twine for gitlab"
# - | - |
# TWINE_PASSWORD=${CI_JOB_TOKEN} \ TWINE_PASSWORD=${CI_JOB_TOKEN} \
# TWINE_USERNAME=gitlab-ci-token \ TWINE_USERNAME=gitlab-ci-token \
# python -m twine upload \ python -m twine upload \
# --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/* --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
publish_on_test_pypi: publish_on_test_pypi:
stage: publish stage: publish
......
...@@ -3,5 +3,4 @@ include README.md ...@@ -3,5 +3,4 @@ include README.md
include VERSION include VERSION
recursive-include docs * recursive-include docs *
recursive-exclude tests * recursive-exclude tests *
# Example Python Package # Example Python Package
An example repository of an CI/CD pipeline for building, testing and publishing a python package An example repository of an CI/CD pipeline for building, testing and publishing a python package.
If you find some missing functionality with regards to CI/CD, testing, linting or something else, feel free to make a merge request with the proposed changes.
## Example of README.md contents below:
## Installation ## Installation
``` ```
...@@ -15,5 +19,10 @@ from map import cool_module ...@@ -15,5 +19,10 @@ from map import cool_module
cool_module.greeter() # prints "Hello World" cool_module.greeter() # prints "Hello World"
``` ```
## Contributing
To contribute, please create a feature branch and a "Draft" merge request.
Upon completion, the merge request should be marked as ready and a reviewer should be assigned.
## License ## License
This project is licensed under the Apache License Version 2.0 This project is licensed under the Apache License Version 2.0
black
build
flake8
pylint
pytest
pytest-cov
"""Testing of the Cool Module"""
from unittest import TestCase
from map.cool_module import greeter
class TestCoolModule(TestCase):
"""Test Case of the Cool Module"""
def test_greeter(self):
"""Testing that the greeter does not crash"""
greeter()
self.assertEqual(2 + 2, 4)
tox.ini 0 → 100644
[tox]
# Generative environment list to test all supported Python versions
envlist = py3{7,8,9,10},black,pep8,pylint
minversion = 3.18.0
# Source distributions are explicitly build using tox -e build
skipsdist = True
[testenv]
usedevelop = True
setenv =
LANGUAGE=en_US
LC_ALL=en_US.UTF-8
PYTHONWARNINGS=default::DeprecationWarning
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/tests/requirements.txt
commands =
{envpython} --version
{envpython} -m pytest --cov=map
# Use generative name and command prefixes to reuse the same virtualenv
# for all linting jobs.
[testenv:{pep8,black,pylint}]
usedevelop = False
envdir = {toxworkdir}/linting
commands =
pep8: {envpython} -m flake8 --version
pep8: {envpython} -m flake8 --extend-exclude './.venv/','./venv/'
black: {envpython} -m black --version
black: {envpython} -m black --check --diff .
pylint: {envpython} -m pylint --version
pylint: {envpython} -m pylint map tests
[testenv:build]
usedevelop = False
commands = {envpython} -m build
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment