Skip to content

Commit 6444632

Browse files
committed
Update base makefile and tools
1 parent 514e9a6 commit 6444632

File tree

7 files changed

+227
-145
lines changed

7 files changed

+227
-145
lines changed

.make/base.make

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
########################################################################################
12
# DO NOT MODIFY!!!
23
# If necessary, override the corresponding variable and/or target, or create new ones
34
# in one of the following files, depending on the nature of the override :
@@ -8,13 +9,14 @@
89
# files to include.
910
#
1011
# Please report bugs to francis.pelletier@mila.quebec
12+
########################################################################################
1113

1214
# Basic variables
1315
PROJECT_PATH := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
1416
MAKEFILE_NAME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
1517
SHELL := /usr/bin/env bash
1618
BUMP_TOOL := bump-my-version
17-
APP_VERSION := 0.0.0
19+
MAKEFILE_VERSION := 0.2.0
1820
DOCKER_COMPOSE ?= docker compose
1921
AUTO_INSTALL ?=
2022

@@ -94,8 +96,8 @@ conda-install: ## Install Conda on your local machine
9496
echo "Fetching and installing miniconda"; \
9597
echo " "; \
9698
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh; \
97-
bash ~/miniconda.sh -b -p ${HOME}/.conda; \
98-
export PATH=${HOME}/.conda/bin:$PATH; \
99+
bash ~/miniconda.sh -b -p $${HOME}/.conda; \
100+
export PATH=$${HOME}/.conda/bin:$$PATH; \
99101
conda init; \
100102
/usr/bin/rm ~/miniconda.sh; \
101103
;; \
@@ -118,9 +120,13 @@ conda-env-info: ## Print information about active Conda environment using <CONDA
118120

119121
.PHONY: _conda-poetry-install
120122
_conda-poetry-install:
121-
$(CONDA_TOOL) run -n $(CONDA_ENVIRONMENT) $(CONDA_TOOL) install -c conda-forge -y poetry; \
122-
123-
123+
$(CONDA_TOOL) run -n $(CONDA_ENVIRONMENT) $(CONDA_TOOL) install -c conda-forge poetry; \
124+
CURRENT_VERSION=$$(poetry --version | awk '{print $$NF}' | tr -d ')'); \
125+
REQUIRED_VERSION="1.6.0"; \
126+
if [ "$$(printf '%s\n' "$$REQUIRED_VERSION" "$$CURRENT_VERSION" | sort -V | head -n1)" != "$$REQUIRED_VERSION" ]; then \
127+
echo "Poetry installed version $$CURRENT_VERSION is less than minimal version $$REQUIRED_VERSION, fixing urllib3 version to prevent problems"; \
128+
poetry add "urllib3<2.0.0"; \
129+
fi;
124130

125131
.PHONY:conda-poetry-install
126132
conda-poetry-install: ## Install Poetry in currently active Conda environment. Will fail if Conda is not found
@@ -395,35 +401,36 @@ bump-patch: ## Bump application patch version <0.0.X>
395401

396402
.PHONY: check-lint
397403
check-lint: ## Check code linting (black, isort, flake8, docformatter and pylint)
398-
poetry run tox -e black,isort,flake8,docformatter,pylint
404+
poetry run nox -s check
399405

400406
.PHONY: check-pylint
401-
check-pylint: ## Check code with pylint
402-
poetry run tox -e pylint
407+
check-pylint: ## Check code linting with pylint
408+
poetry run nox -s pylint
403409

404410
.PHONY: fix-lint
405411
fix-lint: ## Fix code linting (black, isort, flynt, docformatter)
406-
poetry run tox -e fix
412+
poetry run nox -s fix
407413

408414
.PHONY: precommit
409415
precommit: ## Run Pre-commit on all files manually
410-
poetry run tox -e precommit
416+
poetry run nox -s precommit
417+
411418

412419
## -- Tests targets ------------------------------------------------------------------------------------------------- ##
413420

414421
.PHONY: test
415422
test: ## Run all tests
416-
poetry run tox -e test
423+
poetry run nox -s test
417424

418425
TEST_ARGS ?=
419426
MARKER_TEST_ARGS = -m "$(TEST_ARGS)"
420427
SPECIFIC_TEST_ARGS = -k "$(TEST_ARGS)"
421428
CUSTOM_TEST_ARGS = "$(TEST_ARGS)"
422429

423430
.PHONY: test-marker
424-
test-marker: ## Run tests using pytest markers. Ex. make test-tag TEST_ARGS="<marker>"
431+
test-marker: ## Run tests using pytest markers. Ex. make test-marker TEST_ARGS="<marker>"
425432
@if [ -n "$(TEST_ARGS)" ]; then \
426-
poetry run tox -e test-custom -- -- $(MARKER_TEST_ARGS); \
433+
poetry run nox -s test_custom -- -- $(MARKER_TEST_ARGS); \
427434
else \
428435
echo "" ; \
429436
echo 'ERROR : Variable TEST_ARGS has not been set, please rerun the command like so :' ; \
@@ -434,7 +441,7 @@ test-marker: ## Run tests using pytest markers. Ex. make test-tag TEST_ARGS="<ma
434441
.PHONY: test-specific
435442
test-specific: ## Run specific tests using the -k option. Ex. make test-specific TEST_ARGS="<name-of-test>"
436443
@if [ -n "$(TEST_ARGS)" ]; then \
437-
poetry run tox -e test-custom -- -- $(SPECIFIC_TEST_ARGS); \
444+
poetry run nox -s test_custom -- -- $(SPECIFIC_TEST_ARGS); \
438445
else \
439446
echo "" ; \
440447
echo 'ERROR : Variable TEST_ARGS has not been set, please rerun the command like so :' ; \
@@ -446,7 +453,7 @@ test-specific: ## Run specific tests using the -k option. Ex. make test-specific
446453
.PHONY: test-custom
447454
test-custom: ## Run tests with custom args. Ex. make test-custom TEST_ARGS="-m 'not offline'"
448455
@if [ -n "$(TEST_ARGS)" ]; then \
449-
poetry run tox -e test-custom -- -- $(CUSTOM_TEST_ARGS); \
456+
poetry run nox -s test_custom -- -- $(CUSTOM_TEST_ARGS); \
450457
else \
451458
echo "" ; \
452459
echo 'ERROR : Variable TEST_ARGS has not been set, please rerun the command like so :' ; \

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ repos:
1515
- id: check-docstring-first
1616
- id: detect-private-key
1717
- id: check-added-large-files
18+
args: ["--maxkb=5000"]
1819

1920
- repo: https://github.com/psf/black
2021
rev: 23.12.1
@@ -37,6 +38,7 @@ repos:
3738
hooks:
3839
- id: docformatter
3940
args: [ -i ] # Format in-place
41+
additional_dependencies: [tomli]
4042

4143
- repo: https://github.com/PyCQA/flake8
4244
rev: 7.0.0

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
- Add linting tools
88
- Add CI
99
- Add basic structure of package
10+
- Update makefile

noxfile.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
from pathlib import Path
2+
3+
import nox
4+
5+
nox.options.reuse_existing_virtualenvs = True # Reuse virtual environments
6+
nox.options.sessions = ["precommit"]
7+
8+
9+
def get_paths(session):
10+
package_path = Path(session.bin).parent.parent.parent
11+
return {
12+
"all": [
13+
package_path / "climateset",
14+
package_path / "tests",
15+
package_path / "scripts",
16+
],
17+
"module": [
18+
package_path / "climateset",
19+
package_path / "scripts",
20+
],
21+
}
22+
23+
24+
#
25+
# Sessions
26+
#
27+
28+
29+
@nox.session()
30+
def pylint(session):
31+
paths = get_paths(session)
32+
session.run("poetry", "run", "pylint", *paths["module"], external=True)
33+
34+
35+
@nox.session()
36+
def flake8(session):
37+
paths = get_paths(session)
38+
session.run("poetry", "run", "flake8", *paths["all"], external=True)
39+
40+
41+
@nox.session()
42+
def docformatter(session):
43+
paths = get_paths(session)
44+
session.run(
45+
"poetry",
46+
"run",
47+
"docformatter",
48+
"--config",
49+
f"{paths['all'][0].parent}/pyproject.toml",
50+
*paths["all"],
51+
external=True,
52+
)
53+
54+
55+
@nox.session()
56+
def check(session):
57+
paths = get_paths(session)
58+
session.run("poetry", "run", "black", "--check", *paths["all"], external=True)
59+
session.run("poetry", "run", "isort", *paths["all"], "--check", external=True)
60+
session.run("poetry", "run", "flynt", *paths["all"], external=True)
61+
session.run(
62+
"poetry",
63+
"run",
64+
"docformatter",
65+
"--config",
66+
f"{paths['all'][0].parent}/pyproject.toml",
67+
*paths["all"],
68+
external=True,
69+
)
70+
session.run("poetry", "run", "flake8", *paths["all"], external=True)
71+
session.run("poetry", "run", "pylint", *paths["module"], external=True)
72+
73+
74+
@nox.session()
75+
def fix(session):
76+
paths = get_paths(session)
77+
session.run("poetry", "run", "black", *paths["all"], external=True)
78+
session.run("poetry", "run", "isort", *paths["all"], external=True)
79+
session.run("poetry", "run", "flynt", *paths["all"], external=True)
80+
session.run(
81+
"poetry",
82+
"run",
83+
"docformatter",
84+
"--in-place",
85+
"--config",
86+
f"{paths['all'][0].parent}/pyproject.toml",
87+
*paths["all"],
88+
external=True,
89+
)
90+
91+
92+
@nox.session()
93+
def precommit(session):
94+
session.run("poetry", "run", "pre-commit", "run", "--all-files", external=True)
95+
96+
97+
@nox.session()
98+
def black(session):
99+
paths = get_paths(session)
100+
session.run("poetry", "run", "black", "--check", *paths["all"], external=True)
101+
102+
103+
@nox.session()
104+
def isort(session):
105+
paths = get_paths(session)
106+
session.run("poetry", "run", "isort", *paths["all"], "--check", external=True)
107+
108+
109+
@nox.session()
110+
def flynt(session):
111+
paths = get_paths(session)
112+
session.run("poetry", "run", "flynt", *paths["all"], external=True)
113+
114+
115+
@nox.session()
116+
def test(session):
117+
session.run("poetry", "run", "pytest", external=True)
118+
119+
120+
@nox.session()
121+
def test_custom(session):
122+
session.run(
123+
"poetry", "run", "pytest", external=True, *session.posargs
124+
) # Pass additional arguments directly to pytest
125+
126+
127+
@nox.session()
128+
def test_nb(session):
129+
session.run(
130+
"poetry",
131+
"run",
132+
"pytest",
133+
"--nbval",
134+
"tests/test_notebooks/",
135+
"--nbval-sanitize-with=tests/test_notebooks/sanitize_file.cfg",
136+
external=True,
137+
)

0 commit comments

Comments
 (0)