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"
Pipeline #39021 passed
dist/*
*.egg-info
*.pyc
.coverage
default:
image: python:3.7 # minimum supported version
# Make sure each step is executed in a virtual environment with some basic dependencies present
image: python:3.10 # use latest for building/linting
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:
......@@ -54,9 +47,12 @@ run_pylint:
run_unit_tests:
stage: test
image: python:3.${PY_VERSION}
script:
- pip install -r requirements.txt
- echo "run python unit tests /w coverage"
- tox -e py3${PY_VERSION}
parallel:
matrix: # use the matrix for testing
- PY_VERSION: [7, 8, 9, 10]
package_files:
stage: package
......@@ -65,7 +61,7 @@ package_files:
paths:
- dist/*
script:
- python -m build # or something similar
- tox -e build
package_docs:
stage: package
......@@ -95,11 +91,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
......
......@@ -3,5 +3,4 @@ include README.md
include VERSION
recursive-include docs *
recursive-exclude tests *
# 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
```
......@@ -15,5 +19,10 @@ from map import cool_module
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
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