diff --git a/.cirrus.yml b/.cirrus.yml index f61d9e9..281a022 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -7,9 +7,10 @@ auto_cancellation: false env: PATH: ${HOME}/.local/bin:${PATH} # ^ add user paths - COVERALLS_REPO_TOKEN: ENCRYPTED[93a2e96a39f5179862d8bd0ee99000dd18df330c2cf0123d3486569b34f2752fbb45085a9e034df76bcee6d13a14ced3] - # ^ ADD YOUR ENCRYPTED TOKEN HERE: https://cirrus-ci.org/guide/writing-tasks/#encrypted-variables + # COVERALLS_REPO_TOKEN: ENCRYPTED[] + # ^ You can add an encrypted token or use CirrusCI web interface to set the variable # See discussion in: https://github.com/cirruslabs/cirrus-ci-docs/discussions/866 + TYPE_CHECKING: true # Enable/disable type checking PIP_CACHE: ${HOME}/.cache/pip LC_ALL: C.UTF-8 LANG: C.UTF-8 @@ -42,36 +43,49 @@ env: # ^ tox is better if invoked as a module on Windows/OSX +# Deep clone script for POSIX environments (required for setuptools-scm) +.clone_script: &clone | + if [ -z "$CIRRUS_PR" ]; then + git clone --recursive --branch=$CIRRUS_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR + git reset --hard $CIRRUS_CHANGE_IN_REPO + else + git clone --recursive https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR + git fetch origin pull/$CIRRUS_PR/head:pull/$CIRRUS_PR + git reset --hard $CIRRUS_CHANGE_IN_REPO + fi + + # ---- Task definitions ---- +typecheck_task: + name: typecheck (Linux - 3.9) + only_if: $TYPE_CHECKING == 'true' + clone_script: *clone + container: {image: "python:3.9-buster"} # most recent => better type support + pip_cache: *pip-cache + mypy_cache: + folder: .mypy_cache + tox_install_script: + - python -m pip install --upgrade pip setuptools tox + prepare_script: *prepare + typecheck_script: + - python -m tox -e typecheck + + linux_mac_task: # Use custom cloning since otherwise git tags are missing - clone_script: &clone | - if [ -z "$CIRRUS_PR" ]; then - git clone --recursive --branch=$CIRRUS_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR - git reset --hard $CIRRUS_CHANGE_IN_REPO - else - git clone --recursive https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR - git fetch origin pull/$CIRRUS_PR/head:pull/$CIRRUS_PR - git reset --hard $CIRRUS_CHANGE_IN_REPO - fi + clone_script: *clone matrix: - name: test (Linux - 3.6) container: {image: "python:3.6-buster"} - install_script: &debian-install - - apt-get install -y git - name: test (Linux - 3.7) container: {image: "python:3.7-buster"} - install_script: *debian-install - name: test (Linux - 3.8) container: {image: "python:3.8-buster"} - install_script: *debian-install - name: test (Linux - 3.9) container: {image: "python:3.9-buster"} - install_script: *debian-install - name: test (Linux - Anaconda) container: {image: "continuumio/anaconda3:2021.05"} - install_script: *debian-install extra_install_script: - conda install -y -c conda-forge virtualenv build setuptools setuptools-scm pip tox - name: test (OS X) @@ -166,7 +180,6 @@ coverage_task: - test (Linux - 3.8) - test (Linux - Anaconda) - test (OS X) - install_script: *debian-install pip_install_script: pip install --user --upgrade coverage coveralls pre-commit precommit_script: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 21ec0f9..457f46e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,18 +28,18 @@ repos: ] - repo: https://github.com/pycqa/isort - rev: 5.9.2 + rev: 5.9.3 hooks: - id: isort - repo: https://github.com/psf/black - rev: 21.7b0 + rev: 21.8b0 hooks: - id: black language_version: python3 - repo: https://github.com/asottile/blacken-docs - rev: v1.10.0 + rev: v1.11.0 hooks: - id: blacken-docs additional_dependencies: [black] diff --git a/README.rst b/README.rst index 73f6cca..12d2ef8 100644 --- a/README.rst +++ b/README.rst @@ -67,5 +67,5 @@ Don't forget to tell your contributors to also install and use pre-commit. Note ==== -This project has been set up using PyScaffold 4.0.2.post1.dev60+g1585605. For details and usage +This project has been set up using PyScaffold 4.1rc1. For details and usage information on PyScaffold see https://pyscaffold.org/. diff --git a/setup.cfg b/setup.cfg index 713a2c1..93a8f7e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -118,11 +118,24 @@ exclude = .eggs docs/conf.py +[mypy] +pretty = True +show_error_codes = True +show_error_context = True +show_traceback = True +ignore_missing_imports = True +warn_redundant_casts = True +warn_unused_ignores = True +# Add here plugins +# plugins = mypy_django_plugin.main, returns.contrib.mypy.returns_plugin + [pyscaffold] # PyScaffold's parameters when the project was created. # This will be used when updating. Do not change! -version = 4.0.2.post1.dev60+g1585605 +version = 4.1rc1.post1.dev18+g423b773 package = ci_tester extensions = cirrus pre_commit + typed +typed = True diff --git a/setup.py b/setup.py index 8d0f8c9..87fa59b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ Setup file for ci-tester. Use setup.cfg to configure your project. - This file was generated with PyScaffold 4.0.2.post1.dev60+g1585605. + This file was generated with PyScaffold 4.1rc1.post1.dev18+g423b773. PyScaffold helps you to put up the scaffold of your new Python project. Learn more under: https://pyscaffold.org/ """ diff --git a/src/ci_tester/py.typed b/src/ci_tester/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/src/ci_tester/skeleton.py b/src/ci_tester/skeleton.py index 020fda2..9ec07f9 100644 --- a/src/ci_tester/skeleton.py +++ b/src/ci_tester/skeleton.py @@ -23,6 +23,7 @@ import argparse import logging import sys +from typing import List # required for Python < 3.9 from ci_tester import __version__ @@ -40,7 +41,7 @@ # when using this Python module as a library. -def fib(n): +def fib(n: int) -> int: """Fibonacci example function Args: @@ -62,7 +63,7 @@ def fib(n): # executable/script. -def parse_args(args): +def parse_args(args: List[str]) -> argparse.Namespace: """Parse command line parameters Args: @@ -98,7 +99,7 @@ def parse_args(args): return parser.parse_args(args) -def setup_logging(loglevel): +def setup_logging(loglevel: int): """Setup basic logging Args: @@ -110,7 +111,7 @@ def setup_logging(loglevel): ) -def main(args): +def main(args: List[str]): """Wrapper allowing :func:`fib` to be called with string arguments in a CLI fashion Instead of returning the value from :func:`fib`, it prints the result to the @@ -120,10 +121,10 @@ def main(args): args (List[str]): command line parameters as list of strings (for example ``["--verbose", "42"]``). """ - args = parse_args(args) - setup_logging(args.loglevel) + params = parse_args(args) + setup_logging(params.loglevel) _logger.debug("Starting crazy calculations...") - print("The {}-th Fibonacci number is {}".format(args.n, fib(args.n))) + print("The {}-th Fibonacci number is {}".format(params.n, fib(params.n))) _logger.info("Script ends here") diff --git a/tox.ini b/tox.ini index d12958d..1ff644f 100644 --- a/tox.ini +++ b/tox.ini @@ -5,11 +5,11 @@ [tox] minversion = 3.15 envlist = default +isolated_build = True [testenv] description = Invoke pytest to run automated tests -isolated_build = True setenv = TOXINIDIR = {toxinidir} passenv = @@ -20,6 +20,18 @@ commands = pytest {posargs} +[testenv:typecheck] +description = invoke mypy to typecheck the source code +changedir = {toxinidir} +passenv = + TERM + # ^ ensure colors +deps = + mypy +commands = + python -m mypy {posargs:src/} + + [testenv:{build,clean}] description = build: Build the package in isolation according to PEP517, see https://github.com/pypa/build @@ -42,7 +54,6 @@ description = docs: Invoke sphinx-build to build the docs doctests: Invoke sphinx-build to run doctests linkcheck: Check for broken links in the documentation -usedevelop = True setenv = DOCSDIR = {toxinidir}/docs BUILDDIR = {toxinidir}/docs/_build