Skip to content

Commit

Permalink
Merged upstream/main into nox-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
abkfenris committed May 2, 2024
2 parents 24f442c + b44708f commit fe27eb5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 44 deletions.
66 changes: 29 additions & 37 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,67 @@
import nox
import yaml

with open("./.github/workflows/main.yaml") as f:
with open('./.github/workflows/main.yaml') as f:
workflow = yaml.safe_load(f)

python_versions = workflow['jobs']['test']['strategy']['matrix']['python-version']
# pydantic_versions = workflow['jobs']['test']['strategy']['matrix']['pydantic-version']

nox.options.default_venv_backend = "uv"
nox.options.default_venv_backend = 'uv'


@nox.session(python=python_versions)
@nox.parametrize("pydantic", ["<2", ">=2"])
@nox.parametrize('pydantic', ['<2', '>=2'])
def tests(session: nox.Session, pydantic: str):
"""Run py.test"""
session.install("-r", "dev-requirements.txt")
session.install(".")
"""Run py.test."""
session.install('-r', 'dev-requirements.txt')
session.install('.')
session.install(f"pydantic{pydantic}")
session.run("pytest", "--verbose", "--pdb")
session.run('pytest', '--verbose', '--pdb')


@nox.session
def pre_commit(session: nox.Session):
"""Run pre-commit"""
session.install("pre-commit")
session.run("pre-commit", "run")
"""Run pre-commit."""
session.install('pre-commit')
session.run('pre-commit', 'run')


@nox.session
def docs(session: nox.Session):
"""
Build docs using Sphinx.
"""Build docs using Sphinx.
Add --live (nox -s docs -- --live) to run a live server
Add --clean to clean docs directory first
"""
parser = argparse.ArgumentParser()
parser.add_argument("--clean", action="store_true", help="Clean the build directory first")
parser.add_argument("--live", action="store_true", help="Run a live updating server for docs")
parser.add_argument('--clean', action='store_true', help='Clean the build directory first')
parser.add_argument('--live', action='store_true', help='Run a live updating server for docs')
args, posargs = parser.parse_known_args(session.posargs)

session.install("-r", "dev-requirements.txt")
session.install(".")
session.install('-r', 'dev-requirements.txt')
session.install('.')

session.chdir("docs")
session.install("-r", "requirements.txt")
session.install("sphinx-autobuild")
session.chdir('docs')
session.install('-r', 'requirements.txt')
session.install('sphinx-autobuild')

BUILDDIR = "_build"
BUILDDIR = '_build'

if args.clean:
session.run(
"rm", "-rf", f"{BUILDDIR}/*"
)
session.run('rm', '-rf', f"{BUILDDIR}/*")

if args.live:
session.run(
"sphinx-autobuild",
"-b",
"dirhtml",
"source/",
"_build/dirhtml/"
)
session.run('sphinx-autobuild', '-b', 'dirhtml', 'source/', '_build/dirhtml/')
else:
session.run(
"sphinx-build",
"-b",
"dirhtml",
"-d",
'sphinx-build',
'-b',
'dirhtml',
'-d',
f"{BUILDDIR}/doctrees",
"source/dirhtml",
'source/dirhtml',
)


nox.options.sessions = ["tests"]
nox.options.sessions = ['tests']
26 changes: 22 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ module_version = "xpublish.plugins.included.module_version:ModuleVersionPlugin"
plugin_info = "xpublish.plugins.included.plugin_info:PluginInfoPlugin"
zarr = "xpublish.plugins.included.zarr:ZarrPlugin"

[tool.setuptools]
packages = ["xpublish"]

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }

Expand All @@ -58,6 +61,9 @@ line-length = 100
skip-string-normalization = true

[tool.ruff]
line-length = 100

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"C",
Expand All @@ -73,6 +79,7 @@ ignore = [
"D100", # Missing docstring in public module
"D107", # Missing docstring in `__init__`
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
# "E203",
# "E266",
"E501",
Expand All @@ -81,17 +88,28 @@ ignore = [
"E402",
"C901",
]
line-length = 100
exclude = [
"tests/",
"docs/",
]

[tool.ruff.mccabe]
[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"D103", # Missing docstring in public function
"D205", # blank line between summary and description
"D415", # first line should end with punctuation
]
"docs/*" = [
"D101", # missing docstring in public class
"D102", # missing docstring in public method
"D103", # missing docstring in public function
]

[tool.ruff.lint.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 18

[tool.ruff.isort]
[tool.ruff.lint.isort]
combine-as-imports = true
known-first-party = ["xpublish"]
known-third-party = [
Expand Down Expand Up @@ -121,7 +139,7 @@ convention = "google"
inline-quotes = "single"
docstring-quotes = "double"

[tool.ruff.flake8-bugbear]
[tool.ruff.lint.flake8-bugbear]
# Allow fastapi.Depends and other dependency injection style function arguments
extend-immutable-calls = ["fastapi.Depends", "fastapi.Query", "fastapi.Path"]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_zarr_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_zmetadata_identical_coords(
def test_zmetadata_identical_coords_sorted(
start, end, freq, nlats, nlons, var_const, calendar, use_cftime
):
"""Test that zmetadata passes when coords are explicitly sorted"""
"""Test that zmetadata passes when coords are explicitly sorted."""
ds = create_dataset(
start=start,
end=end,
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class TestMapper(TestClient, BaseStore):
"""A simple subclass to support getitem syntax on Starlette TestClient Objects"""
"""A simple subclass to support getitem syntax on Starlette TestClient Objects."""

def __getitem__(self, key):
zarr_key = f'/zarr/{key}'
Expand Down Expand Up @@ -46,7 +46,7 @@ def create_dataset(
var_const=None,
use_xy_dim=False,
):
"""Utility function for creating test data"""
"""Utility function for creating test data."""
if use_cftime:
end = xr.coding.cftime_offsets.to_cftime_datetime(end, calendar=calendar)
dates = xr.cftime_range(start=start, end=end, freq=freq, calendar=calendar)
Expand Down

0 comments on commit fe27eb5

Please sign in to comment.