Skip to content

Commit 5bad59d

Browse files
authored
Merge pull request #21 from microsoft/dciborow/precommit
Create .pre-commit-config.yaml
2 parents a287b5b + 6473830 commit 5bad59d

4 files changed

Lines changed: 277 additions & 0 deletions

File tree

‎.github/workflows/nox.yml‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: CI
2+
on: [push, pull_request]
3+
env:
4+
FORCE_COLOR: "1"
5+
PRE_COMMIT_COLOR: "always"
6+
# See https://github.com/theacodes/nox/issues/545
7+
# and https://github.com/pre-commit/pre-commit/issues/2178#issuecomment-1002163763
8+
SETUPTOOLS_USE_DISTUTILS: "stdlib"
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-20.04, windows-2019]
15+
python-version: ["3.7", "3.8", "3.9", "3.10"]
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Set up Miniconda
23+
uses: conda-incubator/setup-miniconda@v2
24+
with:
25+
auto-update-conda: true
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install Nox-under-test
28+
run: |
29+
python -m pip install --disable-pip-version-check .
30+
- name: Run tests on ${{ matrix.os }}
31+
run: nox --non-interactive --error-on-missing-interpreter --session "tests-${{ matrix.python-version }}" -- --full-trace
32+
lint:
33+
runs-on: ubuntu-20.04
34+
steps:
35+
- uses: actions/checkout@v2
36+
- name: Set up Python 3.9
37+
uses: actions/setup-python@v2
38+
with:
39+
python-version: 3.9
40+
- name: Install Nox-under-test
41+
run: |
42+
python -m pip install --disable-pip-version-check .
43+
- name: Lint
44+
run: nox --non-interactive --error-on-missing-interpreter --session "lint"
45+
docs:
46+
runs-on: ubuntu-20.04
47+
steps:
48+
- uses: actions/checkout@v2
49+
- name: Set up Python 3.9
50+
uses: actions/setup-python@v2
51+
with:
52+
python-version: 3.9
53+
- name: Install Nox-under-test
54+
run: |
55+
python -m pip install --disable-pip-version-check .
56+
- name: Docs
57+
run: nox --non-interactive --error-on-missing-interpreter --session "docs"
58+
deploy:
59+
needs: build
60+
runs-on: ubuntu-20.04
61+
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
62+
steps:
63+
- uses: actions/checkout@v2
64+
- name: Build sdist and wheel
65+
run: pipx run build
66+
- name: Publish distribution PyPI
67+
uses: pypa/gh-action-pypi-publish@master
68+
with:
69+
password: ${{ secrets.PYPI_API_TOKEN }}

‎.pre-commit-config.yaml‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
ci:
2+
autoupdate_commit_msg: "chore: update pre-commit hooks"
3+
autofix_commit_msg: "style: pre-commit fixes"
4+
5+
repos:
6+
- repo: https://github.com/psf/black
7+
rev: "22.3.0"
8+
hooks:
9+
- id: black
10+
args:
11+
- "-l 120 --preview"
12+
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v4.1.0
15+
hooks:
16+
- id: check-added-large-files
17+
- id: check-case-conflict
18+
- id: check-merge-conflict
19+
- id: check-symlinks
20+
- id: check-yaml
21+
- id: debug-statements
22+
- id: end-of-file-fixer
23+
- id: mixed-line-ending
24+
- id: requirements-txt-fixer
25+
- id: trailing-whitespace
26+
27+
- repo: https://github.com/PyCQA/isort
28+
rev: 5.10.1
29+
hooks:
30+
- id: isort
31+
args: ["-a", "from __future__ import annotations"]
32+
33+
- repo: https://github.com/asottile/pyupgrade
34+
rev: v2.31.0
35+
hooks:
36+
- id: pyupgrade
37+
args: [--py37-plus]
38+
39+
- repo: https://github.com/hadialqattan/pycln
40+
rev: v1.2.5
41+
hooks:
42+
- id: pycln
43+
args: [--config=pyproject.toml]
44+
stages: [manual]
45+
46+
- repo: https://github.com/asottile/yesqa
47+
rev: v1.3.0
48+
hooks:
49+
- id: yesqa
50+
additional_dependencies: &flake8-dependencies
51+
- flake8-bugbear
52+
53+
- repo: https://github.com/pycqa/flake8
54+
rev: 4.0.1
55+
hooks:
56+
- id: flake8
57+
exclude: docs/conf.py
58+
additional_dependencies: *flake8-dependencies
59+
60+
- repo: https://github.com/pre-commit/mirrors-mypy
61+
rev: v0.931
62+
hooks:
63+
- id: mypy
64+
files: ^nox/
65+
args: [--show-error-codes]
66+
additional_dependencies:
67+
- types-jinja2
68+
- packaging
69+
- importlib_metadata
70+
71+
- repo: https://github.com/codespell-project/codespell
72+
rev: v2.1.0
73+
hooks:
74+
- id: codespell
75+
76+
- repo: https://github.com/pre-commit/pygrep-hooks
77+
rev: v1.9.0
78+
hooks:
79+
- id: python-check-blanket-noqa
80+
- id: python-check-blanket-type-ignore
81+
- id: python-no-log-warn
82+
exclude: ^tests/test_sessions.py$
83+
- id: python-no-eval
84+
exclude: ^nox/manifest.py$
85+
- id: python-use-type-annotations
86+
- id: rst-backticks
87+
- id: rst-directive-colons
88+
- id: rst-inline-touching-normal
89+
90+
- repo: https://github.com/mgedmin/check-manifest
91+
rev: "0.47"
92+
hooks:
93+
- id: check-manifest
94+
stages: [manual]

‎noxfile.py‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Copyright 2016 Alethea Katherine Flowers
2+
# Source - https://github.com/wntrblm/nox/blob/main/noxfile.py
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
17+
from __future__ import annotations
18+
19+
import functools
20+
import os
21+
import platform
22+
import shutil
23+
24+
import nox
25+
26+
ON_WINDOWS_CI = "CI" in os.environ and platform.system() == "Windows"
27+
28+
# Skip 'conda_tests' if user doesn't have conda installed
29+
nox.options.sessions = ["tests", "cover", "lint", "docs"]
30+
if shutil.which("conda"):
31+
nox.options.sessions.append("conda_tests")
32+
33+
34+
@nox.session(python=["3.7", "3.8", "3.9", "3.10"])
35+
def tests(session):
36+
"""Run test suite with pytest."""
37+
session.create_tmp()
38+
session.install("-r", "requirements-test.txt")
39+
session.install("-e", ".[tox_to_nox]")
40+
tests = session.posargs or ["tests/"]
41+
session.run(
42+
"pytest",
43+
"--cov=nox",
44+
"--cov-config",
45+
"pyproject.toml",
46+
"--cov-report=",
47+
*tests,
48+
env={"COVERAGE_FILE": f".coverage.{session.python}"},
49+
)
50+
session.notify("cover")
51+
52+
53+
@nox.session(python=["3.7", "3.8", "3.9", "3.10"], venv_backend="conda")
54+
def conda_tests(session):
55+
"""Run test suite with pytest."""
56+
session.create_tmp()
57+
session.conda_install(
58+
"--file", "requirements-conda-test.txt", "--channel", "conda-forge"
59+
)
60+
session.install("-e", ".", "--no-deps")
61+
tests = session.posargs or ["tests/"]
62+
session.run("pytest", *tests)
63+
64+
65+
@nox.session
66+
def cover(session):
67+
"""Coverage analysis."""
68+
if ON_WINDOWS_CI:
69+
return
70+
71+
session.install("coverage[toml]")
72+
session.run("coverage", "combine")
73+
session.run("coverage", "report", "--fail-under=100", "--show-missing")
74+
session.run("coverage", "erase")
75+
76+
77+
@nox.session(python="3.9")
78+
def lint(session):
79+
"""Run pre-commit linting."""
80+
session.install("pre-commit")
81+
# See https://github.com/theacodes/nox/issues/545
82+
# and https://github.com/pre-commit/pre-commit/issues/2178#issuecomment-1002163763
83+
session.run(
84+
"pre-commit",
85+
"run",
86+
"--all-files",
87+
"--show-diff-on-failure",
88+
"--hook-stage=manual",
89+
env={"SETUPTOOLS_USE_DISTUTILS": "stdlib"},
90+
*session.posargs,
91+
)
92+
93+
94+
@nox.session
95+
def docs(session):
96+
"""Build the documentation."""
97+
output_dir = os.path.join(session.create_tmp(), "output")
98+
doctrees, html = map(
99+
functools.partial(os.path.join, output_dir), ["doctrees", "html"]
100+
)
101+
shutil.rmtree(output_dir, ignore_errors=True)
102+
session.install("-r", "requirements-test.txt")
103+
session.install(".")
104+
session.cd("docs")
105+
sphinx_args = ["-b", "html", "-W", "-d", doctrees, ".", html]
106+
107+
if not session.interactive:
108+
sphinx_cmd = "sphinx-build"
109+
else:
110+
sphinx_cmd = "sphinx-autobuild"
111+
sphinx_args.insert(0, "--open-browser")
112+
113+
session.run(sphinx_cmd, *sphinx_args)

‎requirements.test.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ flake8-docstrings
66
flake8-formatter_junit_xml
77
flake8==4.0.1
88
mypy==0.941
9+
nox==2022.1.7
910
pre-commit==2.17.0
1011
pylint==2.12.2
1112
pylint_junit

0 commit comments

Comments
 (0)