Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Mambaforge
- name: Setup Miniforge
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-variant: Miniforge3
miniforge-version: latest
activate-environment: climateset
use-mamba: true
Expand All @@ -32,7 +32,7 @@ jobs:
shell: bash

- name: Cache Conda env
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/envs
key:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Mambaforge
- name: Setup Miniforge
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-variant: Miniforge3
miniforge-version: latest
activate-environment: climateset
use-mamba: true
Expand All @@ -32,7 +32,7 @@ jobs:
shell: bash

- name: Cache Conda env
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/envs
key:
Expand Down
39 changes: 23 additions & 16 deletions .make/base.make
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
########################################################################################
# DO NOT MODIFY!!!
# If necessary, override the corresponding variable and/or target, or create new ones
# in one of the following files, depending on the nature of the override :
Expand All @@ -8,13 +9,14 @@
# files to include.
#
# Please report bugs to francis.pelletier@mila.quebec
########################################################################################

# Basic variables
PROJECT_PATH := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
MAKEFILE_NAME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
SHELL := /usr/bin/env bash
BUMP_TOOL := bump-my-version
APP_VERSION := 0.0.0
MAKEFILE_VERSION := 0.2.0
DOCKER_COMPOSE ?= docker compose
AUTO_INSTALL ?=

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

.PHONY: _conda-poetry-install
_conda-poetry-install:
$(CONDA_TOOL) run -n $(CONDA_ENVIRONMENT) $(CONDA_TOOL) install -c conda-forge -y poetry; \


$(CONDA_TOOL) run -n $(CONDA_ENVIRONMENT) $(CONDA_TOOL) install -c conda-forge poetry; \
CURRENT_VERSION=$$(poetry --version | awk '{print $$NF}' | tr -d ')'); \
REQUIRED_VERSION="1.6.0"; \
if [ "$$(printf '%s\n' "$$REQUIRED_VERSION" "$$CURRENT_VERSION" | sort -V | head -n1)" != "$$REQUIRED_VERSION" ]; then \
echo "Poetry installed version $$CURRENT_VERSION is less than minimal version $$REQUIRED_VERSION, fixing urllib3 version to prevent problems"; \
poetry add "urllib3<2.0.0"; \
fi;

.PHONY:conda-poetry-install
conda-poetry-install: ## Install Poetry in currently active Conda environment. Will fail if Conda is not found
Expand Down Expand Up @@ -395,35 +401,36 @@ 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
poetry run nox -s check

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

.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 nox -s precommit


## -- 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)"
SPECIFIC_TEST_ARGS = -k "$(TEST_ARGS)"
CUSTOM_TEST_ARGS = "$(TEST_ARGS)"

.PHONY: test-marker
test-marker: ## Run tests using pytest markers. Ex. make test-tag TEST_ARGS="<marker>"
test-marker: ## Run tests using pytest markers. Ex. make test-marker 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 @@ -434,7 +441,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 @@ -446,7 +453,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
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ repos:
- id: check-docstring-first
- id: detect-private-key
- id: check-added-large-files
args: ["--maxkb=5000"]

- repo: https://github.com/psf/black
rev: 23.12.1
Expand All @@ -37,6 +38,7 @@ repos:
hooks:
- id: docformatter
args: [ -i ] # Format in-place
additional_dependencies: [tomli]

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
- Add linting tools
- Add CI
- Add basic structure of package
- Update makefile
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 / "climateset",
package_path / "tests",
package_path / "scripts",
],
"module": [
package_path / "climateset",
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,
)
Loading