Skip to content

Commit

Permalink
Try nox in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
f-PLT committed Sep 23, 2024
1 parent c0128f5 commit 2d141cb
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 12 deletions.
19 changes: 8 additions & 11 deletions .make/base.make
Original file line number Diff line number Diff line change
Expand Up @@ -401,25 +401,22 @@ bump-patch: ## Bump application patch version <0.0.X>

.PHONY: check-lint
check-lint: ## Check code linting (black, isort, flake8, docformatter and pylint)
poetry run tox -e black,isort,flake8,docformatter,pylint

.PHONY: check-pylint
check-pylint: ## Check code with pylint
poetry run tox -e pylint
poetry run nox -s check

.PHONY: fix-lint
fix-lint: ## Fix code linting (black, isort, flynt, docformatter)
poetry run tox -e fix
poetry run nox -s fix

.PHONY: precommit
precommit: ## Run Pre-commit on all files manually
poetry run tox -e precommit
poetry run pre-commit run --all-files


## -- Tests targets ------------------------------------------------------------------------------------------------- ##

.PHONY: test
test: ## Run all tests
poetry run tox -e test
poetry run nox -s test

TEST_ARGS ?=
MARKER_TEST_ARGS = -m "$(TEST_ARGS)"
Expand All @@ -429,7 +426,7 @@ CUSTOM_TEST_ARGS = "$(TEST_ARGS)"
.PHONY: test-marker
test-marker: ## Run tests using pytest markers. Ex. make test-tag TEST_ARGS="<marker>"
@if [ -n "$(TEST_ARGS)" ]; then \
poetry run tox -e test-custom -- -- $(MARKER_TEST_ARGS); \
poetry run nox -s test-custom -- -- $(MARKER_TEST_ARGS); \
else \
echo "" ; \
echo 'ERROR : Variable TEST_ARGS has not been set, please rerun the command like so :' ; \
Expand All @@ -440,7 +437,7 @@ test-marker: ## Run tests using pytest markers. Ex. make test-tag TEST_ARGS="<ma
.PHONY: test-specific
test-specific: ## Run specific tests using the -k option. Ex. make test-specific TEST_ARGS="<name-of-test>"
@if [ -n "$(TEST_ARGS)" ]; then \
poetry run tox -e test-custom -- -- $(SPECIFIC_TEST_ARGS); \
poetry run nox -s test_custom -- -- $(SPECIFIC_TEST_ARGS); \
else \
echo "" ; \
echo 'ERROR : Variable TEST_ARGS has not been set, please rerun the command like so :' ; \
Expand All @@ -452,7 +449,7 @@ test-specific: ## Run specific tests using the -k option. Ex. make test-specific
.PHONY: test-custom
test-custom: ## Run tests with custom args. Ex. make test-custom TEST_ARGS="-m 'not offline'"
@if [ -n "$(TEST_ARGS)" ]; then \
poetry run tox -e test-custom -- -- $(CUSTOM_TEST_ARGS); \
poetry run nox -s test_custom -- -- $(CUSTOM_TEST_ARGS); \
else \
echo "" ; \
echo 'ERROR : Variable TEST_ARGS has not been set, please rerun the command like so :' ; \
Expand Down
137 changes: 137 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from pathlib import Path

import nox

nox.options.reuse_existing_virtualenvs = True # Reuse virtual environments
nox.options.sessions = ["precommit"]


def get_paths(session):
package_path = Path(session.bin).parent.parent.parent
return {
"all": [
package_path / "geospatial_tools",
package_path / "tests",
package_path / "scripts",
],
"module": [
package_path / "geospatial_tools",
package_path / "scripts",
],
}


#
# Sessions
#


@nox.session()
def pylint(session):
paths = get_paths(session)
session.run("poetry", "run", "pylint", *paths["module"], external=True)


@nox.session()
def flake8(session):
paths = get_paths(session)
session.run("poetry", "run", "flake8", *paths["all"], external=True)


@nox.session()
def docformatter(session):
paths = get_paths(session)
session.run(
"poetry",
"run",
"docformatter",
"--config",
f"{paths['all'][0].parent}/pyproject.toml",
*paths["all"],
external=True,
)


@nox.session()
def check(session):
paths = get_paths(session)
session.run("poetry", "run", "black", "--check", *paths["all"], external=True)
session.run("poetry", "run", "isort", *paths["all"], "--check", external=True)
session.run("poetry", "run", "flynt", *paths["all"], external=True)
session.run(
"poetry",
"run",
"docformatter",
"--config",
f"{paths['all'][0].parent}/pyproject.toml",
*paths["all"],
external=True,
)
session.run("poetry", "run", "flake8", *paths["all"], external=True)
session.run("poetry", "run", "pylint", *paths["module"], external=True)


@nox.session()
def fix(session):
paths = get_paths(session)
session.run("poetry", "run", "black", *paths["all"], external=True)
session.run("poetry", "run", "isort", *paths["all"], external=True)
session.run("poetry", "run", "flynt", *paths["all"], external=True)
session.run(
"poetry",
"run",
"docformatter",
"--in-place",
"--config",
f"{paths['all'][0].parent}/pyproject.toml",
*paths["all"],
external=True,
)


@nox.session()
def precommit(session):
session.run("poetry", "run", "pre-commit", "run", "--all-files", external=True)


@nox.session()
def black(session):
paths = get_paths(session)
session.run("poetry", "run", "black", "--check", *paths["all"], external=True)


@nox.session()
def isort(session):
paths = get_paths(session)
session.run("poetry", "run", "isort", *paths["all"], "--check", external=True)


@nox.session()
def flynt(session):
paths = get_paths(session)
session.run("poetry", "run", "flynt", *paths["all"], external=True)


@nox.session()
def test(session):
session.run("poetry", "run", "pytest", external=True)


@nox.session()
def test_custom(session):
session.run(
"poetry", "run", "pytest", external=True, *session.posargs
) # Pass additional arguments directly to pytest


@nox.session()
def test_nb(session):
session.run(
"poetry",
"run",
"pytest",
"--nbval",
"tests/test_notebooks/",
"--nbval-sanitize-with=tests/test_notebooks/sanitize_file.cfg",
external=True,
)
55 changes: 54 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ flake8-pyproject = "^1.2.3"
docformatter = {extras = ["tomli"], version = "^1.7.5"}
nbval = "^0.11.0"
black = "^24.8.0"
nox = "^2024.4.15"

[tool.poetry.group.lab.dependencies]
jupyterlab = "^4.0.10"
Expand Down

0 comments on commit 2d141cb

Please sign in to comment.