Skip to content

Commit c734ade

Browse files
committed
add Python 3.10 support
1 parent 4bcd948 commit c734ade

File tree

13 files changed

+158
-105
lines changed

13 files changed

+158
-105
lines changed

.github/workflows/ci-tests.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ on:
55
branches: [ main ]
66
pull_request:
77
branches: [ main ]
8-
workflow_dispatch:
8+
9+
concurrency:
10+
group: build-${{ github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
912

1013
jobs:
1114

@@ -17,7 +20,7 @@ jobs:
1720
strategy:
1821
matrix:
1922
py-ver-major: [3]
20-
py-ver-minor: [6, 7, 8, 9]
23+
py-ver-minor: [6, 7, 8, 9, 10]
2124
step: [lint, unit, mypy]
2225

2326
env:
@@ -26,8 +29,6 @@ jobs:
2629

2730
steps:
2831
- uses: actions/checkout@v2
29-
with:
30-
fetch-depth: 0
3132

3233
- name: Set up Python
3334
uses: actions/setup-python@v2
@@ -57,7 +58,7 @@ jobs:
5758

5859
- name: Upload coverage to Codecov
5960
if: ${{ matrix.step == 'unit' }}
60-
uses: codecov/codecov-action@v1
61+
uses: codecov/codecov-action@v2.1.0
6162
with:
6263
fail_ci_if_error: true
6364

@@ -68,11 +69,11 @@ jobs:
6869

6970
strategy:
7071
matrix:
71-
step: [lint-readme, pydocstyle]
72+
step: [lintreadme, pydocstyle]
7273

7374
env:
74-
py-semver: 3.9
75-
TOXENV: ${{ format('py39-{0}', matrix.step) }}
75+
py-semver: "3.10"
76+
TOXENV: ${{ format('py310-{0}', matrix.step) }}
7677

7778
steps:
7879
- uses: actions/checkout@v2
@@ -102,7 +103,6 @@ jobs:
102103
- name: Test with tox
103104
run: tox
104105

105-
106106
release_test:
107107
name: cwl-utils release test
108108

@@ -114,7 +114,7 @@ jobs:
114114
- name: Set up Python
115115
uses: actions/setup-python@v2
116116
with:
117-
python-version: 3.9
117+
python-version: "3.10" # quoted, otherwise that turns into the number 3.1
118118

119119
- name: Cache for pip
120120
uses: actions/cache@v2

Makefile

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,39 @@
2222

2323
MODULE=cwl-upgrader
2424
PACKAGE=cwlupgrader
25+
EXTRAS=
2526

2627
# `SHELL=bash` doesn't work for some, so don't use BASH-isms like
2728
# `[[` conditional expressions.
2829
PYSOURCES=$(wildcard cwlupgrader/**.py tests/*.py) setup.py
29-
DEVPKGS=diff_cover black pylint coverage pep257 pytest-xdist \
30-
flake8 flake8-bugbear pyupgrade mypy
30+
DEVPKGS=diff_cover black pylint pep257 pydocstyle flake8 tox tox-pyenv \
31+
isort wheel autoflake flake8-bugbear pyupgrade bandit \
32+
-rtest-requirements.txt -rmypy-requirements.txt
3133
DEBDEVPKGS=pylint python3-coverage sloccount \
3234
python3-flake8 shellcheck
33-
VERSION=1.2.1 # please also update setup.py
35+
VERSION=1.2.2 # please also update setup.py
3436

3537
## all : default task
36-
all:
37-
pip install -e .
38+
all: dev
3839

3940
## help : print this help message and exit
4041
help: Makefile
4142
@sed -n 's/^##//p' $<
4243

4344
## install-dep : install most of the development dependencies via pip
44-
install-dep:
45-
pip install --upgrade $(DEVPKGS)
45+
install-dep: install-dependencies
4646

47-
## install-deb-dep: install most of the dev dependencies via apt-get
48-
install-deb-dep:
49-
sudo apt-get install $(DEBDEVPKGS)
47+
install-dependencies: FORCE
48+
pip install --upgrade $(DEVPKGS)
49+
pip install -r requirements.txt -r mypy-requirements.txt
5050

51-
## install : install the ${MODULE} module and scripts
51+
## install : install the ${MODULE} module and script(s)
5252
install: FORCE
53-
pip install .
53+
pip install .$(EXTRAS)
54+
55+
## dev : install the ${MODULE} module in dev mode
56+
dev: install-dep
57+
pip install -e .$(EXTRAS)
5458

5559
## dist : create a module package for distribution
5660
dist: dist/${MODULE}-$(VERSION).tar.gz
@@ -67,8 +71,11 @@ clean: FORCE
6771

6872
# Linting and code style related targets
6973
## sorting imports using isort: https://github.com/timothycrosley/isort
70-
sort_imports:
71-
isort ${PACKAGE}/*.py tests/*.py setup.py
74+
sort_imports: $(PYSOURCES)
75+
isort $^ typeshed
76+
77+
remove_unused_imports: $(PYSOURCES)
78+
autoflake --in-place --remove-all-unused-imports $^
7279

7380
pep257: pydocstyle
7481
## pydocstyle : check Python code style
@@ -83,14 +90,17 @@ diff_pydocstyle_report: pydocstyle_report.txt
8390

8491
## format : check/fix all code indentation and formatting (runs black)
8592
format:
86-
black setup.py cwlupgrader
93+
black setup.py cwlupgrader tests
94+
95+
format-check:
96+
black --diff --check cwlupgrader setup.py typeshed
8797

8898
## pylint : run static code analysis on Python code
8999
pylint: $(PYSOURCES)
90100
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
91101
$^ -j0|| true
92102

93-
pylint_report.txt: ${PYSOURCES}
103+
pylint_report.txt: $(PYSOURCES)
94104
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
95105
$^ -j0> $@ || true
96106

@@ -121,47 +131,51 @@ diff-cover.html: coverage.xml
121131
diff-cover --compare-branch main $^ --html-report $@
122132

123133
## test : run the ${MODULE} test suite
124-
test: FORCE
134+
test: $(PYSOURCES)
125135
python setup.py test
126136

127137
## testcov : run the ${MODULE} test suite and collect coverage
128-
testcov: $(pysources)
129-
python setup.py test --addopts "--cov ${PACKAGE}"
138+
testcov: $(PYSOURCES)
139+
python setup.py test --addopts "--cov" ${PYTEST_EXTRA}
130140

131-
sloccount.sc: ${PYSOURCES} Makefile
141+
sloccount.sc: $(PYSOURCES) Makefile
132142
sloccount --duplicates --wide --details $^ > $@
133143

134144
## sloccount : count lines of code
135-
sloccount: ${PYSOURCES} Makefile
145+
sloccount: $(PYSOURCES) Makefile
136146
sloccount $^
137147

138148
list-author-emails:
139149
@echo 'name, E-Mail Address'
140150
@git log --format='%aN,%aE' | sort -u | grep -v 'root'
141151

142152
mypy3: mypy
143-
mypy: ${PYSOURCES}
153+
mypy: $(PYSOURCES)
144154
if ! test -f $(shell python3 -c 'import ruamel.yaml; import os.path; print(os.path.dirname(ruamel.yaml.__file__))')/py.typed ; \
145155
then \
146-
rm -Rf typeshed/2and3/ruamel/yaml ; \
156+
rm -Rf typeshed/ruamel/yaml ; \
147157
ln -s $(shell python3 -c 'import ruamel.yaml; import os.path; print(os.path.dirname(ruamel.yaml.__file__))') \
148-
typeshed/2and3/ruamel/ ; \
158+
typeshed/ruamel/ ; \
149159
fi # if minimally required ruamel.yaml version is 0.15.99 or greater, than the above can be removed
150-
MYPYPATH=$$MYPYPATH:typeshed/3:typeshed/2and3 mypy --disallow-untyped-calls \
151-
--warn-redundant-casts \
152-
${PACKAGE}
160+
MYPYPATH=$$MYPYPATH:typeshed mypy $^
153161

154-
pyupgrade: $(filter-out schema_salad/metaschema.py,${PYSOURCES})
162+
pyupgrade: $(PYSOURCES)
155163
pyupgrade --exit-zero-even-if-changed --py36-plus $^
156164

157-
release: FORCE
165+
release-test: FORCE
166+
git diff-index --quiet HEAD -- || ( echo You have uncommited changes, please commit them and try again; false )
158167
./release-test.sh
168+
169+
release: release-test
159170
. testenv2/bin/activate && \
160171
python testenv2/src/${MODULE}/setup.py sdist bdist_wheel && \
161172
pip install twine && \
162173
twine upload testenv2/src/${MODULE}/dist/* && \
163174
git tag v${VERSION} && git push --tags
164175

176+
flake8: $(PYSOURCES)
177+
flake8 $^
178+
165179
FORCE:
166180

167181
# Use this to print the value of a Makefile variable

cwlupgrader/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
_logger.addHandler(defaultStreamHandler)
2020
_logger.setLevel(logging.INFO)
2121

22+
yaml = ruamel.yaml.main.YAML(typ="rt")
23+
yaml.allow_duplicate_keys = True
24+
yaml.preserve_quotes = True # type: ignore
25+
yaml.default_flow_style = False
26+
2227

2328
def parse_args(args: List[str]) -> argparse.Namespace:
2429
"""Argument parser."""
@@ -121,9 +126,6 @@ def load_cwl_document(path: str) -> Any:
121126
Also ensures that the filename is recorded so that SourceLine can produce
122127
informative error messages.
123128
"""
124-
yaml = ruamel.yaml.main.YAML(typ="rt")
125-
yaml.allow_duplicate_keys = True
126-
yaml.preserve_quotes = True # type: ignore
127129
with open(path) as entry:
128130
document = yaml.load(entry)
129131
add_lc_filename(document, entry.name)
@@ -142,9 +144,7 @@ def write_cwl_document(document: Any, name: str, dirname: str) -> None:
142144
with open(path, "w") as handle:
143145
if "cwlVersion" in document:
144146
handle.write("#!/usr/bin/env cwl-runner\n")
145-
ruamel.yaml.main.round_trip_dump(
146-
document, default_flow_style=False, stream=handle
147-
)
147+
yaml.dump(document, stream=handle)
148148
if "cwlVersion" in document:
149149
path.chmod(path.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
150150

mypy-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mypy==0.910
2+
types-setuptools

mypy.ini

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
[mypy]
2-
# --strict options as of mypy 0.720
2+
show_error_context = true
3+
show_column_numbers = true
4+
show_error_codes = true
5+
pretty = true
6+
7+
# --strict options as of mypy 0.910
38
warn_unused_configs = True
4-
disallow_subclassing_any = True
59
disallow_any_generics = True
10+
disallow_subclassing_any = True
611
disallow_untyped_calls = True
712
disallow_untyped_defs = True
813
disallow_incomplete_defs = True
@@ -13,6 +18,7 @@ warn_redundant_casts = True
1318
warn_unused_ignores = True
1419
warn_return_any = True
1520
implicit_reexport = False
21+
strict_equality = True
1622

1723
[mypy-ruamel.*]
1824
ignore_errors = True

release-test.sh

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export LC_ALL=C
77

88
package=cwl-upgrader
99
module=cwlupgrader
10+
extras=
11+
1012
if [ "$GITHUB_ACTIONS" = "true" ]; then
1113
# We are running as a GH Action
1214
repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git
@@ -15,12 +17,9 @@ else
1517
repo=https://github.com/common-workflow-language/cwl-upgrader.git
1618
HEAD=$(git rev-parse HEAD)
1719
fi
18-
test_prefix=""
19-
run_tests() {
20-
${test_prefix}bin/py.test --pyargs -x ${module}
21-
}
22-
pipver=20.3b1 # minimum required version of pip for Python 3.9
23-
setuptoolsver=41.1.0 # required for Python 3.9
20+
run_tests="bin/py.test --pyargs ${module}"
21+
pipver=20.3.3 # minimum required version of pip for Python 3.10
22+
setuptoolsver=50.0.0 # required for Python 3.10
2423
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
2524

2625
rm -Rf testenv? || /bin/true
@@ -36,22 +35,22 @@ then
3635
rm -f testenv1/lib/python-wheels/setuptools* \
3736
&& pip install --force-reinstall -U pip==${pipver} \
3837
&& pip install setuptools==${setuptoolsver} wheel
39-
make install-dep
40-
pip install .
38+
pip install -rtest-requirements.txt ".${extras}"
4139
make test
4240
pip uninstall -y ${package} || true; pip uninstall -y ${package} || true; make install
4341
mkdir testenv1/not-${module}
4442
# if there is a subdir named '${module}' py.test will execute tests
4543
# there instead of the installed module's tests
4644
pushd testenv1/not-${module}
4745
# shellcheck disable=SC2086
48-
test_prefix=../ run_tests; popd
46+
../${run_tests}; popd
4947
fi
5048

5149
python3 -m venv testenv2
5250
python3 -m venv testenv3
5351
python3 -m venv testenv4
54-
rm -Rf testenv[234]/local
52+
python3 -m venv testenv5
53+
rm -Rf testenv[2345]/local
5554

5655
# Secondly we test via pip
5756

@@ -62,16 +61,17 @@ rm -f lib/python-wheels/setuptools* \
6261
&& pip install --force-reinstall -U pip==${pipver} \
6362
&& pip install setuptools==${setuptoolsver} wheel
6463
# The following can fail if you haven't pushed your commits to ${repo}
65-
pip install -e "git+${repo}@${HEAD}#egg=${package}"
64+
pip install -e "git+${repo}@${HEAD}#egg=${package}${extras}"
6665
pushd src/${package}
67-
make install-dep
66+
pip install -rtest-requirements.txt
6867
make dist
6968
make test
7069
cp dist/${package}*tar.gz ../../../testenv3/
70+
cp dist/cwl_upgrader*whl ../../../testenv4/
7171
pip uninstall -y ${package} || true; pip uninstall -y ${package} || true; make install
7272
popd # ../.. no subdir named ${proj} here, safe for py.testing the installed module
7373
# shellcheck disable=SC2086
74-
run_tests
74+
${run_tests}
7575
popd
7676

7777
# Is the source distribution in testenv2 complete enough to build
@@ -85,18 +85,34 @@ rm -f lib/python-wheels/setuptools* \
8585
&& pip install setuptools==${setuptoolsver} wheel
8686
package_tar=$(find . -name "${package}*tar.gz")
8787
pip install "-r${DIR}/test-requirements.txt"
88-
pip install "${package_tar}"
88+
pip install "${package_tar}${extras}"
8989
mkdir out
9090
tar --extract --directory=out -z -f ${package}*.tar.gz
9191
pushd out/${package}*
92-
make install-dep
93-
pip install "-r${DIR}/mypy_requirements.txt"
94-
make mypy
9592
make dist
9693
make test
94+
pip install "-r${DIR}/mypy-requirements.txt"
95+
make mypy
9796
pip uninstall -y ${package} || true; pip uninstall -y ${package} || true; make install
9897
mkdir ../not-${module}
9998
pushd ../not-${module}
10099
# shellcheck disable=SC2086
101-
test_prefix=../../ run_tests; popd
100+
../../${run_tests}; popd
101+
popd
102+
popd
103+
104+
# Is the wheel in testenv2 installable and will it pass the tests
105+
106+
pushd testenv4/
107+
# shellcheck source=/dev/null
108+
source bin/activate
109+
rm -f lib/python-wheels/setuptools* \
110+
&& pip install --force-reinstall -U pip==${pipver} \
111+
&& pip install setuptools==${setuptoolsver} wheel
112+
pip install "$(ls cwl_upgrader*.whl)${extras}"
113+
pip install "-r${DIR}/test-requirements.txt"
114+
mkdir not-${module}
115+
pushd not-${module}
116+
# shellcheck disable=SC2086
117+
../${run_tests}; popd
102118
popd

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
ruamel.yaml >= 0.14.12, < 0.17.18
2-
typing
32
schema-salad

0 commit comments

Comments
 (0)