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

Commit 9648aa1

Browse files
author
Thiago C. D'Ávila
authored
Merge pull request #277 from staticdev/python-39
Python 39
2 parents ffafb3d + dbc3587 commit 9648aa1

5 files changed

Lines changed: 614 additions & 573 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: 54 additions & 11 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 }}
@@ -47,7 +49,7 @@ jobs:
4749
4850
- name: Install Nox
4951
run: |
50-
pip install --constraint=.github/workflows/constraints.txt nox
52+
pip install --constraint=.github/workflows/constraints.txt nox nox-poetry
5153
nox --version
5254
5355
- name: Compute pre-commit cache key
@@ -78,18 +80,59 @@ jobs:
7880
run: |
7981
nox --force-color --python=${{ matrix.python-version }}
8082
83+
- name: Upload coverage data
84+
if: always() && matrix.session == 'tests'
85+
uses: "actions/upload-artifact@v2.2.1"
86+
with:
87+
name: coverage-data
88+
path: ".coverage.*"
89+
8190
- name: Upload documentation
8291
if: matrix.session == 'docs-build'
83-
uses: actions/upload-artifact@v2
92+
uses: actions/upload-artifact@v2.2.1
8493
with:
8594
name: docs
8695
path: docs/_build
8796

97+
coverage:
98+
runs-on: ubuntu-latest
99+
needs: tests
100+
steps:
101+
- name: Check out the repository
102+
uses: actions/checkout@v2.3.4
103+
104+
- name: Set up Python 3.9
105+
uses: actions/setup-python@v2.2.1
106+
with:
107+
python-version: 3.9
108+
109+
- name: Upgrade pip
110+
run: |
111+
pip install --constraint=.github/workflows/constraints.txt pip
112+
pip --version
113+
114+
- name: Install Poetry
115+
run: |
116+
pip install --constraint=.github/workflows/constraints.txt poetry
117+
poetry --version
118+
119+
- name: Install Nox
120+
run: |
121+
pip install --constraint=.github/workflows/constraints.txt nox nox-poetry
122+
nox --version
123+
124+
- name: Download coverage data
125+
uses: actions/download-artifact@v2.0.7
126+
with:
127+
name: coverage-data
128+
129+
- name: Combine coverage data and display human readable report
130+
run: |
131+
nox --force-color --session=coverage
132+
88133
- name: Create coverage report
89-
if: always() && matrix.session == 'tests'
90134
run: |
91135
nox --force-color --session=coverage -- xml
92136
93137
- name: Upload coverage report
94-
if: always() && matrix.session == 'tests'
95-
uses: codecov/codecov-action@v1.2.1
138+
uses: codecov/codecov-action@v1.1.1

noxfile.py

Lines changed: 24 additions & 129 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,20 +94,20 @@ 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")
@@ -222,12 +116,13 @@ def mypy(session: Session) -> None:
222116
@nox.session(python=python_versions)
223117
def tests(session: Session) -> None:
224118
"""Run the test suite."""
225-
install_package(session)
226-
install(session, "coverage[toml]", "pygments", "pytest")
119+
session.install(".")
120+
session.install("coverage[toml]", "pytest", "pygments")
227121
try:
228122
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
229123
finally:
230-
session.notify("coverage")
124+
if session.interactive:
125+
session.notify("coverage")
231126

232127

233128
@nox.session
@@ -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():

0 commit comments

Comments
 (0)