Skip to content
This repository was archived by the owner on Feb 13, 2021. It is now read-only.

Commit e572ffd

Browse files
author
staticdev
committed
Support Python 3.9
1 parent ffafb3d commit e572ffd

4 files changed

Lines changed: 38 additions & 138 deletions

File tree

.github/workflows/constraints.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
pip==20.3.3
2-
nox==2020.12.31
3-
poetry==1.1.4
2+
nox==2020.8.22
3+
nox-poetry==0.7.1
4+
poetry==1.0.10
5+
virtualenv==20.2.1

.github/workflows/tests.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
include:
15-
- { python-version: 3.8, os: ubuntu-latest, session: "pre-commit" }
16-
- { python-version: 3.8, os: ubuntu-latest, session: "safety" }
15+
- { python-version: 3.9, os: ubuntu-latest, session: "pre-commit" }
16+
- { python-version: 3.9, os: ubuntu-latest, session: "safety" }
17+
- { python-version: 3.9, os: ubuntu-latest, session: "mypy" }
1718
- { python-version: 3.8, os: ubuntu-latest, session: "mypy" }
1819
- { python-version: 3.7, os: ubuntu-latest, session: "mypy" }
20+
- { python-version: 3.9, os: ubuntu-latest, session: "tests" }
1921
- { python-version: 3.8, os: ubuntu-latest, session: "tests" }
2022
- { python-version: 3.7, os: ubuntu-latest, session: "tests" }
21-
- { python-version: 3.8, os: windows-latest, session: "tests" }
22-
- { python-version: 3.8, os: macos-latest, session: "tests" }
23-
- { python-version: 3.8, os: ubuntu-latest, session: "typeguard" }
24-
- { python-version: 3.8, os: ubuntu-latest, session: "docs-build" }
23+
- { python-version: 3.9, os: windows-latest, session: "tests" }
24+
- { python-version: 3.9, os: macos-latest, session: "tests" }
25+
- { python-version: 3.9, os: ubuntu-latest, session: "typeguard" }
26+
- { python-version: 3.9, os: ubuntu-latest, session: "docs-build" }
2527

2628
env:
2729
NOXSESSION: ${{ matrix.session }}

noxfile.py

Lines changed: 25 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
"""Nox sessions."""
2-
import hashlib
32
import shutil
43
import sys
54
from pathlib import Path
65
from textwrap import dedent
76

87
import nox
8+
import nox_poetry.patch
99
from nox.sessions import Session
1010

1111

1212
package = "humanizer_portugues"
13-
# python_versions = ["3.9", "3.8", "3.7"]
14-
python_versions = ["3.8", "3.7"]
13+
python_versions = ["3.9", "3.8", "3.7"]
1514
nox.options.sessions = (
1615
"pre-commit",
1716
"safety",
@@ -22,110 +21,6 @@
2221
)
2322

2423

25-
class Poetry:
26-
"""Helper class for invoking Poetry inside a Nox session.
27-
28-
Attributes:
29-
session: The Session object.
30-
"""
31-
32-
def __init__(self, session: Session) -> None:
33-
"""Constructor."""
34-
self.session = session
35-
36-
def export(self, path: Path, *, dev: bool) -> None:
37-
"""Export the lock file to requirements format.
38-
39-
Args:
40-
path: The destination path.
41-
dev: If True, include development dependencies.
42-
"""
43-
options = ["--dev"] if dev else []
44-
self.session.run(
45-
"poetry",
46-
"export",
47-
"--format=requirements.txt",
48-
f"--output={path}",
49-
*options,
50-
external=True,
51-
)
52-
53-
def build(self, *args: str) -> str:
54-
"""Build the package.
55-
56-
Args:
57-
args: Command-line arguments for ``poetry build``.
58-
59-
Returns:
60-
The basename of the wheel built by Poetry.
61-
"""
62-
output = self.session.run(
63-
"poetry", "build", *args, external=True, silent=True, stderr=None
64-
)
65-
assert isinstance(output, str) # noqa: S101
66-
return output.split()[-1]
67-
68-
69-
def export_requirements(session: Session, *, dev: bool) -> Path:
70-
"""Export the lock file to requirements format.
71-
72-
Args:
73-
session: The Session object.
74-
dev: If True, include development dependencies.
75-
76-
Returns:
77-
The path to the requirements file.
78-
"""
79-
tmpdir = Path(session.create_tmp())
80-
name = "dev-requirements.txt" if dev else "requirements.txt"
81-
path = tmpdir / name
82-
hashfile = tmpdir / f"{name}.hash"
83-
84-
lockdata = Path("poetry.lock").read_bytes()
85-
digest = hashlib.blake2b(lockdata).hexdigest()
86-
87-
if not hashfile.is_file() or hashfile.read_text() != digest:
88-
Poetry(session).export(path, dev=dev)
89-
hashfile.write_text(digest)
90-
91-
return path
92-
93-
94-
def install_package(session: Session) -> None:
95-
"""Build and install the package.
96-
97-
Build a wheel from the package, and install it into the virtual environment
98-
of the specified Nox session.
99-
100-
The package requirements are installed using the versions specified in
101-
Poetry's lock file.
102-
103-
Args:
104-
session: The Session object.
105-
"""
106-
poetry = Poetry(session)
107-
wheel = poetry.build("--format=wheel")
108-
requirements = export_requirements(session, dev=False)
109-
110-
session.install(f"--requirement={requirements}")
111-
session.install("--no-deps", "--force-reinstall", f"dist/{wheel}")
112-
113-
114-
def install(session: Session, *args: str) -> None:
115-
"""Install development dependencies into the session's virtual environment.
116-
117-
This function is a wrapper for nox.sessions.Session.install.
118-
119-
The packages must be managed as development dependencies in Poetry.
120-
121-
Args:
122-
session: The Session object.
123-
args: Command-line arguments for ``pip install``.
124-
"""
125-
requirements = export_requirements(session, dev=True)
126-
session.install(f"--constraint={requirements}", *args)
127-
128-
12924
def activate_virtualenv_in_precommit_hooks(session: Session) -> None:
13025
"""Activate virtualenv in hooks installed by pre-commit.
13126
@@ -177,12 +72,11 @@ def activate_virtualenv_in_precommit_hooks(session: Session) -> None:
17772
hook.write_text("\n".join(lines))
17873

17974

180-
@nox.session(name="pre-commit", python="3.8")
75+
@nox.session(name="pre-commit", python="3.9")
18176
def precommit(session: Session) -> None:
18277
"""Lint using pre-commit."""
18378
args = session.posargs or ["run", "--all-files", "--show-diff-on-failure"]
184-
install(
185-
session,
79+
session.install(
18680
"black",
18781
"darglint",
18882
"flake8",
@@ -200,35 +94,36 @@ def precommit(session: Session) -> None:
20094
activate_virtualenv_in_precommit_hooks(session)
20195

20296

203-
@nox.session(python="3.8")
97+
@nox.session(python="3.9")
20498
def safety(session: Session) -> None:
20599
"""Scan dependencies for insecure packages."""
206-
install(session, "safety")
207-
requirements = export_requirements(session, dev=True)
100+
requirements = nox_poetry.export_requirements(session)
101+
session.install("safety")
208102
session.run("safety", "check", f"--file={requirements}", "--bare")
209103

210104

211105
@nox.session(python=python_versions)
212106
def mypy(session: Session) -> None:
213107
"""Type-check using mypy."""
214108
args = session.posargs or ["src", "tests", "docs/conf.py"]
215-
install_package(session)
216-
install(session, "mypy")
109+
session.install(".")
110+
session.install("mypy", "pytest")
217111
session.run("mypy", *args)
218112
if not session.posargs:
219113
session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
220114

221115

116+
222117
@nox.session(python=python_versions)
223118
def tests(session: Session) -> None:
224119
"""Run the test suite."""
225-
install_package(session)
226-
install(session, "coverage[toml]", "pygments", "pytest")
120+
session.install(".")
121+
session.install("coverage[toml]", "pytest", "pygments")
227122
try:
228123
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
229124
finally:
230-
session.notify("coverage")
231-
125+
if session.interactive:
126+
session.notify("coverage")
232127

233128
@nox.session
234129
def coverage(session: Session) -> None:
@@ -237,7 +132,7 @@ def coverage(session: Session) -> None:
237132
has_args = session.posargs and len(session._runner.manifest) == 1
238133
args = session.posargs if has_args else ["report"]
239134

240-
install(session, "coverage[toml]")
135+
session.install("coverage[toml]")
241136

242137
if not has_args and any(Path().glob(".coverage.*")):
243138
session.run("coverage", "combine")
@@ -248,26 +143,26 @@ def coverage(session: Session) -> None:
248143
@nox.session(python=python_versions)
249144
def typeguard(session: Session) -> None:
250145
"""Runtime type checking using Typeguard."""
251-
install_package(session)
252-
install(session, "pygments", "pytest", "typeguard")
146+
session.install(".")
147+
session.install("pytest", "typeguard", "pygments")
253148
session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
254149

255150

256151
@nox.session(python=python_versions)
257152
def xdoctest(session: Session) -> None:
258153
"""Run examples with xdoctest."""
259154
args = session.posargs or ["all"]
260-
install_package(session)
261-
install(session, "xdoctest")
155+
session.install(".")
156+
session.install("xdoctest[colors]")
262157
session.run("python", "-m", "xdoctest", package, *args)
263158

264159

265-
@nox.session(name="docs-build", python="3.8")
160+
@nox.session(name="docs-build", python="3.9")
266161
def docs_build(session: Session) -> None:
267162
"""Build the documentation."""
268163
args = session.posargs or ["docs", "docs/_build"]
269-
install_package(session)
270-
install(session, "sphinx")
164+
session.install(".")
165+
session.install("sphinx", "sphinx-click", "sphinx-rtd-theme")
271166

272167
build_dir = Path("docs", "_build")
273168
if build_dir.exists():
@@ -276,12 +171,12 @@ def docs_build(session: Session) -> None:
276171
session.run("sphinx-build", *args)
277172

278173

279-
@nox.session(python="3.8")
174+
@nox.session(python="3.9")
280175
def docs(session: Session) -> None:
281176
"""Build and serve the documentation with live reloading on file changes."""
282177
args = session.posargs or ["--open-browser", "docs", "docs/_build"]
283-
install_package(session)
284-
install(session, "sphinx", "sphinx-autobuild")
178+
session.install(".")
179+
session.install("sphinx", "sphinx-autobuild", "sphinx-click", "sphinx-rtd-theme")
285180

286181
build_dir = Path("docs", "_build")
287182
if build_dir.exists():

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ classifiers = [
1313
'Programming Language :: Python',
1414
'Programming Language :: Python :: 3.7',
1515
'Programming Language :: Python :: 3.8',
16+
'Programming Language :: Python :: 3.9',
1617
'Intended Audience :: Developers',
1718
'License :: OSI Approved :: MIT License',
1819
]

0 commit comments

Comments
 (0)