-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd5b506
commit 54a94bf
Showing
4 changed files
with
313 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Lint | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
|
||
lint: | ||
name: Check for lint | ||
# We want to run on external PRs, but not on our own internal PRs as they'll be run | ||
# by the push to the branch. Without this if check, checks are duplicated since | ||
# internal PRs match both the push and pull_request events. | ||
if: | ||
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != | ||
github.repository | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11 | ||
|
||
- name: Lint | ||
run: | | ||
pip install nox | ||
nox -s lint -- --no-skip |
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,54 @@ | ||
name: Test | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build-and-test: | ||
# We want to run on external PRs, but not on our own internal PRs as they'll be run | ||
# by the push to the branch. Without this if check, checks are duplicated since | ||
# internal PRs match both the push and pull_request events. | ||
if: | ||
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != | ||
github.repository | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
python-version: ["3.10", "3.11", "3.12"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Test | ||
run: | | ||
pip install nox | ||
nox --non-interactive --error-on-missing-interpreter -s test test-notebooks | ||
- name: Coveralls | ||
if: matrix.os == 'ubuntu-latest' | ||
uses: AndreMiras/coveralls-python-action@develop | ||
with: | ||
parallel: true | ||
flag-name: py${{ matrix.python-version }}-${{ matrix.os }} | ||
|
||
debug: true | ||
|
||
coveralls_finish: | ||
needs: build-and-test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Coveralls Finished | ||
uses: AndreMiras/coveralls-python-action@develop | ||
with: | ||
parallel-finished: true | ||
debug: true |
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,92 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 23.12.1 | ||
hooks: | ||
- id: black | ||
name: black | ||
description: "Black: The uncompromising Python code formatter" | ||
entry: black | ||
language: python | ||
language_version: python3 | ||
minimum_pre_commit_version: 2.9.2 | ||
require_serial: true | ||
types_or: [python, pyi] | ||
- id: black-jupyter | ||
name: black-jupyter | ||
description: | ||
"Black: The uncompromising Python code formatter (with Jupyter Notebook support)" | ||
entry: black | ||
language: python | ||
minimum_pre_commit_version: 2.9.2 | ||
require_serial: true | ||
types_or: [python, pyi, jupyter] | ||
additional_dependencies: [".[jupyter]"] | ||
|
||
- repo: https://github.com/adamchainz/blacken-docs | ||
rev: 1.16.0 | ||
hooks: | ||
- id: blacken-docs | ||
|
||
- repo: https://github.com/keewis/blackdoc | ||
rev: "v0.3.9" | ||
hooks: | ||
- id: blackdoc | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: 7.0.0 | ||
hooks: | ||
- id: flake8 | ||
additional_dependencies: | ||
- flake8-bugbear | ||
- flake8-comprehensions | ||
- flake8-simplify | ||
|
||
- repo: https://github.com/nbQA-dev/nbQA | ||
rev: 1.7.1 | ||
hooks: | ||
- id: nbqa-pyupgrade | ||
args: ["--py310-plus"] | ||
- id: nbqa-isort | ||
- id: nbqa-flake8 | ||
args: ["--extend-ignore=E402"] | ||
|
||
- repo: https://github.com/kynan/nbstripout | ||
rev: 0.6.1 | ||
hooks: | ||
- id: nbstripout | ||
description: Strip output from jupyter notebooks | ||
args: [--drop-empty-cells] | ||
|
||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v3.15.0 | ||
hooks: | ||
- id: pyupgrade | ||
args: [--py310-plus] | ||
|
||
- repo: https://github.com/asottile/reorder-python-imports | ||
rev: v3.12.0 | ||
hooks: | ||
- id: reorder-python-imports | ||
args: [--py310-plus, --add-import, "from __future__ import annotations"] | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: check-builtin-literals | ||
- id: check-added-large-files | ||
- id: check-case-conflict | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: debug-statements | ||
- id: end-of-file-fixer | ||
- id: forbid-new-submodules | ||
- id: mixed-line-ending | ||
- id: trailing-whitespace | ||
- id: name-tests-test | ||
- id: file-contents-sorter | ||
files: | | ||
(?x)^( | ||
.*requirements(-\w+)?.(in|txt)| | ||
requirements/.*\.txt| | ||
.gitignore | ||
) |
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,140 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import pathlib | ||
import shutil | ||
|
||
import nox | ||
|
||
PROJECT = "bmi_dbseabed" | ||
ROOT = pathlib.Path(__file__).parent | ||
|
||
|
||
@nox.session | ||
def test(session: nox.Session) -> None: | ||
"""Run the tests.""" | ||
session.install(".[testing]") | ||
|
||
args = ["--cov", PROJECT, "-vvv"] + session.posargs | ||
|
||
if "CI" in os.environ: | ||
args.append(f"--cov-report=xml:{ROOT.absolute()!s}/coverage.xml") | ||
session.run("pytest", *args) | ||
|
||
if "CI" not in os.environ: | ||
session.run("coverage", "report", "--ignore-errors", "--show-missing") | ||
|
||
|
||
@nox.session(name="test-notebooks") | ||
def test_notebooks(session: nox.Session) -> None: | ||
"""Run the notebooks.""" | ||
session.install(".[testing,notebooks]") | ||
|
||
session.run( | ||
"pytest", | ||
"notebooks", | ||
"--nbmake", | ||
"--nbmake-kernel=python3", | ||
"--nbmake-timeout=3000", | ||
"-vvv", | ||
) | ||
|
||
|
||
@nox.session | ||
def lint(session: nox.Session) -> None: | ||
"""Look for lint.""" | ||
session.install("pre-commit") | ||
session.run("pre-commit", "run", "--all-files") | ||
|
||
|
||
@nox.session | ||
def build(session: nox.Session) -> None: | ||
"""Build sdist and wheel dists.""" | ||
session.install("pip") | ||
session.install("build") | ||
session.run("python", "--version") | ||
session.run("pip", "--version") | ||
session.run("python", "-m", "build", "--outdir", "./build/wheelhouse") | ||
|
||
|
||
@nox.session(name="build-docs", reuse_venv=True) | ||
def build_docs(session: nox.Session) -> None: | ||
"""Build the docs.""" | ||
session.install("myst-parser", "sphinx", "sphinx_copybutton", "sphinx-inline-tabs") | ||
session.install(".") | ||
|
||
pathlib.Path("build").mkdir(exist_ok=True) | ||
with session.chdir(ROOT): | ||
session.run( | ||
"sphinx-build", | ||
"-b", | ||
"html", | ||
"-W", | ||
"--keep-going", | ||
"docs/source", | ||
"build/html", | ||
) | ||
|
||
|
||
@nox.session | ||
def release(session): | ||
"""Tag, build and publish a new release to PyPI.""" | ||
session.install("zest.releaser[recommended]") | ||
session.run("fullrelease") | ||
|
||
|
||
@nox.session(name="publish-testpypi") | ||
def publish_testpypi(session): | ||
"""Publish wheelhouse/* to TestPyPI.""" | ||
session.run("twine", "check", "build/wheelhouse/*") | ||
session.run( | ||
"twine", | ||
"upload", | ||
"--skip-existing", | ||
"--repository-url", | ||
"https://test.pypi.org/legacy/", | ||
"build/wheelhouse/*.tar.gz", | ||
) | ||
|
||
|
||
@nox.session(name="publish-pypi") | ||
def publish_pypi(session): | ||
"""Publish wheelhouse/* to PyPI.""" | ||
session.run("twine", "check", "build/wheelhouse/*") | ||
session.run( | ||
"twine", | ||
"upload", | ||
"--skip-existing", | ||
"build/wheelhouse/*.tar.gz", | ||
) | ||
|
||
|
||
@nox.session(python=False) | ||
def clean(session): | ||
"""Remove all .venv's, build files and caches in the directory.""" | ||
for folder in _args_to_folders(session.posargs): | ||
with session.chdir(folder): | ||
shutil.rmtree("build", ignore_errors=True) | ||
shutil.rmtree("build/wheelhouse", ignore_errors=True) | ||
shutil.rmtree(f"src/{PROJECT}.egg-info", ignore_errors=True) | ||
shutil.rmtree(".pytest_cache", ignore_errors=True) | ||
shutil.rmtree(".venv", ignore_errors=True) | ||
|
||
for pattern in ["*.py[co]", "__pycache__"]: | ||
_clean_rglob(pattern) | ||
|
||
|
||
def _args_to_folders(args): | ||
return [ROOT] if not args else [pathlib.Path(f) for f in args] | ||
|
||
|
||
def _clean_rglob(pattern): | ||
nox_dir = pathlib.Path(".nox") | ||
|
||
for p in pathlib.Path(".").rglob(pattern): | ||
if nox_dir in p.parents: | ||
continue | ||
if p.is_dir(): | ||
p.rmdir() | ||
else: | ||
p.unlink() |