-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from kiudee/130_nox
Migrate to Github Actions & Nox
- Loading branch information
Showing
13 changed files
with
249 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Tests | ||
on: | ||
- push | ||
- pull_request | ||
jobs: | ||
tests: | ||
runs-on: "${{ matrix.os }}" | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- { python-version: 3.8, os: ubuntu-latest, session: "pre-commit" } | ||
- { python-version: 3.8, os: ubuntu-latest, session: "tests" } | ||
- { python-version: 3.9, os: ubuntu-latest, session: "tests" } | ||
- { python-version: 3.8, os: macos-latest, session: "tests" } | ||
- { python-version: 3.9, os: macos-latest, session: "tests" } | ||
|
||
name: "${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }}" | ||
env: | ||
NOXSESSION: "${{ matrix.session }}" | ||
steps: | ||
- uses: actions/checkout@v2.3.4 | ||
- uses: actions/setup-python@v2.2.1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
architecture: x64 | ||
- run: pip install nox==2021.6.12 | ||
- run: pip install nox-poetry==0.8.6 | ||
- run: pip install poetry==1.1.4 | ||
- name: Compute pre-commit cache key | ||
if: matrix.session == 'pre-commit' | ||
id: pre-commit-cache | ||
shell: python | ||
run: | | ||
import hashlib | ||
import sys | ||
python = "py{}.{}".format(*sys.version_info[:2]) | ||
payload = sys.version.encode() + sys.executable.encode() | ||
digest = hashlib.sha256(payload).hexdigest() | ||
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8]) | ||
print("::set-output name=result::{}".format(result)) | ||
- name: Restore pre-commit cache | ||
uses: actions/cache@v2.1.4 | ||
if: matrix.session == 'pre-commit' | ||
with: | ||
path: ~/.cache/pre-commit | ||
key: "${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}" | ||
restore-keys: | | ||
"${{ steps.pre-commit-cache.outputs.result }}-" | ||
- name: Run Nox | ||
run: | | ||
nox --force-color --python=${{ matrix.python-version }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
"""Nox sessions.""" | ||
from pathlib import Path | ||
from textwrap import dedent | ||
|
||
import nox | ||
from nox_poetry import session | ||
|
||
locations = "tune", "noxfile.py" | ||
nox.options.sessions = ("pre-commit", "tests") | ||
python_versions = ["3.8", "3.9"] | ||
|
||
|
||
def activate_virtualenv_in_precommit_hooks(session): | ||
"""Activate virtualenv in hooks installed by pre-commit. | ||
This function patches git hooks installed by pre-commit to activate the | ||
session's virtual environment. This allows pre-commit to locate hooks in | ||
that environment when invoked from git. | ||
Args: | ||
session: The Session object. | ||
""" | ||
if session.bin is None: | ||
return | ||
|
||
virtualenv = session.env.get("VIRTUAL_ENV") | ||
if virtualenv is None: | ||
return | ||
|
||
hookdir = Path(".git") / "hooks" | ||
if not hookdir.is_dir(): | ||
return | ||
|
||
for hook in hookdir.iterdir(): | ||
if hook.name.endswith(".sample") or not hook.is_file(): | ||
continue | ||
|
||
text = hook.read_text() | ||
bindir = repr(session.bin)[1:-1] # strip quotes | ||
if not ( | ||
Path("A") == Path("a") and bindir.lower() in text.lower() or bindir in text | ||
): | ||
continue | ||
|
||
lines = text.splitlines() | ||
if not (lines[0].startswith("#!") and "python" in lines[0].lower()): | ||
continue | ||
|
||
header = dedent( | ||
f"""\ | ||
import os | ||
os.environ["VIRTUAL_ENV"] = {virtualenv!r} | ||
os.environ["PATH"] = os.pathsep.join(( | ||
{session.bin!r}, | ||
os.environ.get("PATH", ""), | ||
)) | ||
""" | ||
) | ||
|
||
lines.insert(1, header) | ||
hook.write_text("\n".join(lines)) | ||
|
||
|
||
@session(python=python_versions) | ||
def tests(session): | ||
"""Run the test suite.""" | ||
session.install(".[data]") | ||
session.install("pytest", "nox", "nox-poetry") | ||
session.run("pytest", *session.posargs) | ||
|
||
|
||
@session(python="3.8") | ||
def black(session): | ||
"""Run black code formatter.""" | ||
args = session.posargs or locations | ||
session.install("black") | ||
session.run("black", *args) | ||
|
||
|
||
@session(name="pre-commit", python="3.8") | ||
def precommit(session): | ||
args = session.posargs or ["run", "--all-files", "--show-diff-on-failure"] | ||
session.install( | ||
"pre-commit", "black", "flake8", "doc8", "zimports", | ||
) | ||
session.run("pre-commit", *args) | ||
if args and args[0] == "install": | ||
activate_virtualenv_in_precommit_hooks(session) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.