Skip to content

Commit 03b6a75

Browse files
Merge pull request #27 from xenserver-next/py3-move-to-tox
Initial Python3 support with Test-Driven-Development enforced by CI (git diff coverage and diff lint checking) with mypy, pyre and pytype
2 parents efa489e + 5110074 commit 03b6a75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1699
-240
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exclude_lines =
1212
# Don't complain if tests don't hit defensive assertion code:
1313
raise AssertionError
1414
raise NotImplementedError
15+
raise ValueError
1516
\<assert\>.*
1617

1718
# Don't complain if non-runnable code isn't run:

.env

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# Environment file picked up by act-cli.rpm, it can be run on Fedora 37 with podman:
3+
# act --bind --container-daemon-socket $XDG_RUNTIME_DIR/podman/podman.sock -W .github/workflows/main.yml
4+
# This offers lower minimum scores for tox.ini because the ACT containers don't
5+
# provides the cpio tool which is required for tests of xcp/cpiofile.py:
6+
#
7+
XCP_COV_MIN=53
8+
TESTS_COV_MIN=90
9+
DIFF_COV_MIN=75
10+
DIFF_COVCOMBINE_MIN=81
11+
GITHUB_STEP_SUMMARY=.github/workflows/.tox/GITHUB_STEP_SUMMARY.md

.github/workflows/main.yml

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,82 @@
1+
# actions can be run locally using act and docker, on Fedora 37 also with podman, using:
2+
# https://github.com/nektos/act
3+
# sudo dnf install -y act-cli podman-docker
4+
# act --bind --container-daemon-socket $XDG_RUNTIME_DIR/podman/podman.sock -W .github/workflows/main.yml
5+
16
name: Unit tests
27

8+
# Checks can be skipped by adding "skip-checks: true" to a commit message,
9+
# or requested by adding "request-checks: true" if disabled by default for pushes:
10+
# https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks#skipping-and-requesting-checks-for-individual-commits
311
on: [push, pull_request]
12+
env:
13+
PYTHONWARNINGS: "ignore:DEPRECATION"
14+
PIP_ROOT_USER_ACTION: "ignore" # For local testing using act-cli
15+
PIP_NO_WARN_SCRIPT_LOCATION: "0" # For local testing using act-cli
16+
PIP_DISABLE_PIP_VERSION_CHECK: "1" # Reduce noise in logs
417

518
jobs:
6-
test_py2:
7-
runs-on: ubuntu-20.04
8-
19+
test:
20+
strategy:
21+
# See: https://github.com/xenserver/python-libs/pull/26#discussion_r1179482169
22+
# max-parallel: 1
23+
# Want to get the results of all the tests, don't terminate all on a fail:
24+
fail-fast: false
25+
matrix:
26+
include:
27+
- python-version: '3.11'
28+
os: ubuntu-latest
29+
# This tests with Python 2.7 and with Ubuntu-20.04's Python 3.8 for combined py2+3 coverage:
30+
- python-version: '2.7'
31+
os: ubuntu-20.04
32+
- python-version: '3.10'
33+
os: ubuntu-latest
34+
- python-version: '3.9'
35+
os: ubuntu-latest
36+
- python-version: '3.7'
37+
os: ubuntu-latest
38+
- python-version: '3.6'
39+
os: ubuntu-20.04
40+
runs-on: ${{ matrix.os }}
941
steps:
10-
- uses: actions/checkout@v2
42+
- uses: actions/checkout@v3
1143
with:
12-
fetch-depth: 0
13-
- name: Set up Python 2.7
14-
uses: actions/setup-python@v2
44+
fetch-depth: 0 # Needed by diff-cover to get the changed lines: origin/master..HEAD
45+
- name: Set up Python ${{ matrix.python-version }}
46+
uses: actions/setup-python@v4
1547
with:
16-
python-version: '2.7'
48+
python-version: ${{ matrix.python-version }}
1749

18-
- name: Install dependencies
19-
run: |
20-
python -m pip install --upgrade pip
21-
pip install -r requirements-dev.txt
22-
# FIXME: branding.py still has no permanent home
23-
curl https://gist.github.com/ydirson/3c36a7e19d762cc529a6c82340894ccc/raw/5ca39f621b1feab813e171f535c1aad1bd483f1d/branding.py -O -L
24-
pip install pyliblzma
25-
pip install -e .
26-
command -v xz
27-
28-
- name: Test
50+
- name: Run of tox on ubuntu-latest
51+
if: ${{ startsWith(matrix.python-version, '3.') && matrix.python-version != 3.6 }}
2952
run: |
30-
pytest --cov -rP
31-
coverage xml
32-
coverage html
33-
coverage html -d htmlcov-tests --include="tests/*"
34-
diff-cover --html-report coverage-diff.html coverage.xml
53+
pip install 'virtualenv<20.22' 'tox>=4.5.1' tox-gh-actions
54+
tox --workdir .github/workflows/.tox --recreate
3555
36-
- name: Pylint
56+
# tox >= 4.0.0 is needed for using optional-dependencies from pyproject.toml, which is
57+
# is not available for python <= 3.6, so use the python3.8 of Ubuntu-20.04 to install it:
58+
- name: Install of tox on ubuntu-20.04 (to support optional-dependencies from pyproject.toml)
59+
if: ${{ matrix.python-version == 2.7 || matrix.python-version == 3.6 }}
3760
run: |
38-
pylint --version
39-
pylint --exit-zero xcp/ tests/ setup.py
40-
pylint --exit-zero --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" xcp/ tests/ setup.py > pylint.txt
41-
diff-quality --violations=pylint --html-report pylint-diff.html pylint.txt
61+
set -xv;curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
62+
python3.8 get-pip.py
63+
python3.8 -m pip install 'virtualenv<20.22' 'tox>=4.5.1' tox-gh-actions
64+
65+
- name: Run tox4 with Python 3.8(to support optional-dependencies from pyproject.toml) for Python3.6
66+
if: ${{ matrix.python-version == 3.6 }}
67+
run: tox --workdir .github/workflows/.tox --recreate -e py36-lint
68+
69+
- name: Generate combined test-coverage with Python 2.7 and 3.8 for Upload
70+
if: ${{ matrix.python-version == 2.7 }}
71+
run: tox --workdir .github/workflows/.tox --recreate -e py38-covcombine
4272

43-
- uses: actions/upload-artifact@v3
73+
- name: Upload coverage reports to Codecov
74+
if: ${{ matrix.python-version == 2.7 }}
75+
uses: codecov/codecov-action@v3
4476
with:
45-
name: Coverage and pylint reports
46-
path: |
47-
coverage-diff.html
48-
pylint-diff.html
49-
htmlcov
50-
htmlcov-tests
77+
directory: .github/workflows/.tox/py38-covcombine/log
78+
env_vars: OS,PYTHON
79+
fail_ci_if_error: true
80+
flags: unittest
81+
name: py27-py38-combined
82+
verbose: true

.github/workflows/pytype.cfg

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# NOTE: All relative paths are relative to the location of this file.
2+
3+
[pytype]
4+
5+
# Space-separated list of files or directories to exclude.
6+
exclude =
7+
8+
# Space-separated list of files or directories to process.
9+
inputs = ../../xcp ../../tests
10+
11+
# Keep going past errors to analyze as many files as possible.
12+
keep_going = True
13+
14+
# Run N jobs in parallel. When 'auto' is used, this will be equivalent to the
15+
# number of CPUs on the host system.
16+
jobs = 4
17+
18+
# All pytype output goes here.
19+
output = .pytype
20+
21+
# Platform (e.g., "linux", "win32") that the target code runs on.
22+
platform = linux
23+
24+
# Paths to source code directories, separated by ':'.
25+
# pythonpath = stubs
26+
27+
# Python version (major.minor) of the target code.
28+
python_version = 3.10
29+
30+
# Enable parameter count checks for overriding methods. This flag is temporary
31+
# and will be removed once this behavior is enabled by default.
32+
overriding_parameter_count_checks = True
33+
34+
# Use the enum overlay for more precise enum checking. This flag is temporary
35+
# and will be removed once this behavior is enabled by default.
36+
# use_enum_overlay = True
37+
38+
# Variables initialized as None retain their None binding. This flag is
39+
# temporary and will be removed once this behavior is enabled by default.
40+
# strict_none_binding = True
41+
42+
# Opt-in: Do not allow Any as a return type.
43+
# no_return_any = True
44+
45+
# Experimental: Infer precise return types even for invalid function calls.
46+
#precise_return = True
47+
48+
# Experimental: Solve unknown types to label with structural types.
49+
# protocols = True
50+
51+
# Experimental: Only load submodules that are explicitly imported.
52+
# strict_import = False
53+
54+
# Experimental: Enable exhaustive checking of function parameter types.
55+
#strict_parameter_checks = True
56+
57+
# Experimental: Emit errors for comparisons between incompatible primitive
58+
# types.
59+
#strict_primitive_comparisons = True
60+
61+
# Space-separated list of error names to ignore.
62+
# disable = pyi-error
63+
64+
# Don't report errors.
65+
#report_errors = True

README

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)