From 14e10feafee8c1a1fb900aab0a328553a1869ed3 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 14:24:36 -0600 Subject: [PATCH 01/20] remove old travis/appveyor config files --- .travis.yml | 62 ------------------------------------------- LICENSE => LICENSE.md | 0 appveyor.yml | 37 -------------------------- 3 files changed, 99 deletions(-) delete mode 100644 .travis.yml rename LICENSE => LICENSE.md (100%) delete mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4155f2c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,62 +0,0 @@ -language: generic -os: -- linux -- osx -env: - matrix: - - PYTHON="3.8" - - PYTHON="3.7" - - PYTHON="3.6" - global: - - secure: If5+q1H1EQwEZrhYvQAGoYBaVTu1Bfkw+J5OrIY5CanuhLExXK1CLVHMKML2sZdMEHIOGhBYaeUqHlEVbvP94Wb8RobfL4NT5FjOfXk9zbiT3vRdAbgJzCVy2ervx6m4acZcnrn0LCu6FQW294M7DUEK77ZQJToj3Qy0ypWDwzijAN/wWD5NZWc8Kndg2yH76qBXCQO79S242/gryPq83dbjwVW79+uUCsmhKsV5r8MIKib0Xm6zbd8a5qLsSveTNlx6zNMaVadkZM6r7mKt6mk6pEZxuL8GWWUo0SntZCW3FNncO9SrTfC2uOsBRF3BWDIWZHVqcedkdahNsOkVr95rYk+XjeKj0alWY8RsBwGl1XWMIJAFEQdgVfy+wvccOB41ZZXwICaT8TKKGpY/Za97DJF1g6rU/PCojA578YCyBjrqng5X7nQh9FBS74VpItt2oHE3KnAwyTrcboatXL2z1lpeHenAK8+rijYzLY288MMzTXw4risaPEI32QxGtPlzymDCbIAJqi3tZ5dTRTbffEmSjmRp3aBer0gY2qajq7uKo4TLiqhOIpWeQZA/ncF2PUqbkFtkd9ZejcZakUoAZ8wsAhfUTvebVsWMf7A7g1BKrStNdlo8OnNX0soIMLUSzGACag8khHUOdSKYEEtxMQC2wW5diq3VC36HbKs= -sudo: false -jobs: - include: - - stage: lint - os: linux - script: - - pip install flake8 - - make lint - - stage: deploy - if: tag=~ v.*$ - os: linux - env: PYTHON=3.8 - script: &1 - - pip install twine wheel - - python setup.py sdist - - twine upload -u mcflugen -p$PYPI_PASS dist/*compaction* -before_install: -- | - if [[ $TRAVIS_OS_NAME == "osx" ]]; then - brew remove --force $(brew list) - brew cleanup -s - rm -rf $(brew --cache) - fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - curl -L https://micromamba.snakepit.net/api/micromamba/osx-64/latest | tar -xvj bin/micromamba - else - curl -L https://micromamba.snakepit.net/api/micromamba/linux-64/latest | tar -xvj bin/micromamba - fi -- ./bin/micromamba shell init -s bash -p ~/micromamba -- | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - source $HOME/.bash_profile - else - source $HOME/.bashrc - fi -- micromamba activate -- micromamba install python=$PYTHON pip mamba --yes -c conda-forge -- mamba info -a && mamba list -install: -- pip install -e . -script: -- pip install -r requirements-testing.txt -- pip install pytest pytest-cov pytest-datadir pytest-benchmark coveralls -- pytest -vvv --cov=compaction --cov-report=xml:$(pwd)/coverage.xml --mypy -- compaction --help -- compaction --version -- compaction generate compaction.toml -- compaction generate porosity.csv -- mkdir example -- compaction --cd=example setup run -after_success: coveralls diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index cc6447f..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,37 +0,0 @@ -environment: - - matrix: - - - PYTHON: "3.8" - MINICONDA: C:\\Miniconda38-x64 - - - PYTHON: "3.7" - MINICONDA: C:\\Miniconda37-x64 - - - PYTHON: "3.6" - MINICONDA: C:\\Miniconda36-x64 - - -platform: - - x64 - -os: Visual Studio 2019 - -init: - - "ECHO %PYTHON% %HOME% %PLATFORM%" - - "ECHO %APPVEYOR_REPO_BRANCH%" - -install: - - cmd: call %MINICONDA%\Scripts\activate.bat - - cmd: conda install mamba -c conda-forge --yes - - cmd: set PYTHONUNBUFFERED=1 - - cmd: mamba info - - cmd: mamba list - - cmd: python --version - -build: false - -test_script: - - cmd: pip install -r requirements-testing.txt - - cmd: pip install -e . - - cmd: pytest -vvv From 02187e1c9690b8ae4b509a27187554235ea7b72b Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 14:36:17 -0600 Subject: [PATCH 02/20] add a pre-commit file --- .pre-commit-config.yaml | 112 ++++++++++++++++++++++++++++++++++++++++ Makefile | 96 ---------------------------------- 2 files changed, 112 insertions(+), 96 deletions(-) create mode 100644 .pre-commit-config.yaml delete mode 100644 Makefile diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ac73c53 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,112 @@ +repos: +- repo: https://github.com/psf/black + rev: 23.3.0 + 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/pycqa/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + additional_dependencies: + - flake8-bugbear + - flake8-comprehensions + - flake8-simplify + +- repo: https://github.com/nbQA-dev/nbQA + rev: 1.7.0 + hooks: + - id: nbqa-pyupgrade + args: ["--py39-plus"] + - id: nbqa-isort + - id: nbqa-flake8 + args: ["--extend-ignore=E402"] + exclude: | + (?x)^( + notebooks/tutorials/making_components/making_components.ipynb + ) + +- 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.3.1 + hooks: + - id: pyupgrade + args: [--py39-plus] + +- repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + files: \.py$ + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.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 + +- repo: https://github.com/regebro/pyroma + rev: "4.2" + hooks: + - id: pyroma + args: ["-d", "--min=10", "."] + additional_dependencies: + - numpy + - cython + +- repo: https://github.com/mgedmin/check-manifest + rev: "0.49" + hooks: + - id: check-manifest + args: ["--ignore=.nox,build", "--no-build-isolation"] + additional_dependencies: + - numpy + - cython~=3.0.0b3 + +- repo: https://github.com/PyCQA/pydocstyle + rev: 6.1.1 + hooks: + - id: pydocstyle + files: landlab/.*\.py$ + args: + - --convention=numpy + - --add-select=D417 + additional_dependencies: [".[toml]"] + +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.982 + hooks: + - id: mypy + additional_dependencies: [types-all] diff --git a/Makefile b/Makefile deleted file mode 100644 index 53212bb..0000000 --- a/Makefile +++ /dev/null @@ -1,96 +0,0 @@ -.PHONY: clean clean-test clean-pyc clean-build docs help -.DEFAULT_GOAL := help - -define BROWSER_PYSCRIPT -import os, webbrowser, sys - -try: - from urllib import pathname2url -except: - from urllib.request import pathname2url - -webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) -endef -export BROWSER_PYSCRIPT - -define PRINT_HELP_PYSCRIPT -import re, sys - -for line in sys.stdin: - match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) - if match: - target, help = match.groups() - print("%-20s %s" % (target, help)) -endef -export PRINT_HELP_PYSCRIPT - - -BROWSER := python -c "$$BROWSER_PYSCRIPT" - -help: - @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) - -clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts - -clean-build: ## remove build artifacts - rm -fr build/ - rm -fr dist/ - rm -fr .eggs/ - find . -name '*.egg-info' -exec rm -fr {} + - find . -name '*.egg' -exec rm -f {} + - -clean-pyc: ## remove Python file artifacts - find . -name '*.pyc' -exec rm -f {} + - find . -name '*.pyo' -exec rm -f {} + - find . -name '*~' -exec rm -f {} + - find . -name '__pycache__' -exec rm -fr {} + - -clean-test: ## remove test and coverage artifacts - rm -fr .tox/ - rm -f .coverage - rm -fr htmlcov/ - rm -fr .pytest_cache - -lint: ## check style with flake8 - flake8 compaction tests - -pretty: ## reformat files to make them look pretty - find compaction tests -name '*.py' | xargs isort - black setup.py compaction tests - -test: ## run tests quickly with the default Python - pytest --cov=compaction - -benchmark: ## run benchmarks only - pytest --benchmark-only --benchmark-autosave - -test-all: ## run tests on every Python version with tox - tox - -coverage: ## check code coverage quickly with the default Python - coverage run --source compaction -m pytest - coverage report -m - coverage html - $(BROWSER) htmlcov/index.html - -docs: ## generate Sphinx HTML documentation, including API docs - rm -f docs/compaction.rst - rm -f docs/modules.rst - sphinx-apidoc -o docs/ compaction - $(MAKE) -C docs clean - $(MAKE) -C docs html - $(BROWSER) docs/_build/html/index.html - -servedocs: docs ## compile the docs watching for changes - watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . - -release: dist ## package and upload a release - twine upload dist/* - -dist: clean ## builds source and wheel package - python setup.py sdist - python setup.py bdist_wheel - ls -l dist - -install: clean ## install the package to the active Python's site-packages - python setup.py install From 915f6641c6c023e4ff326c9f9f82c9c148c0d2dd Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 14:38:14 -0600 Subject: [PATCH 03/20] remove old conda-recipe folder --- conda-recipe/meta.yaml | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 conda-recipe/meta.yaml diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml deleted file mode 100644 index 4c4a1a6..0000000 --- a/conda-recipe/meta.yaml +++ /dev/null @@ -1,33 +0,0 @@ -{% set name = "compaction" %} -{% set version = "0.1" %} - -package: - name: {{ name }} - version: {{ version }} - -source: - path: .. - -requirements: - build: - - python - - setuptools - - run: - - python - - scipy - - pandas - - pyyaml - -test: - commands: - - compact -h - imports: - - compaction - -about: - summary: Compact a column of sediment. - -build: - number: 0 - script: python setup.py install --single-version-externally-managed --record record.txt From 78bd88e7fd98ebfc574c4f04ebe8f8c1ca0bd982 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 14:44:57 -0600 Subject: [PATCH 04/20] switch from versioneer to zest.releaser --- compaction/__init__.py | 6 ++--- compaction/_version.py | 1 + setup.cfg | 50 ++++++++++-------------------------------- 3 files changed, 14 insertions(+), 43 deletions(-) create mode 100644 compaction/_version.py diff --git a/compaction/__init__.py b/compaction/__init__.py index 16bb165..f6b8160 100644 --- a/compaction/__init__.py +++ b/compaction/__init__.py @@ -1,6 +1,4 @@ -import pkg_resources - +from ._version import __version__ from .compaction import compact -__version__ = pkg_resources.get_distribution("compaction").version -__all__ = ["compact"] +__all__ = ["__version__", "compact"] diff --git a/compaction/_version.py b/compaction/_version.py new file mode 100644 index 0000000..46d2e70 --- /dev/null +++ b/compaction/_version.py @@ -0,0 +1 @@ +__version__ = "v0.3.0.dev0" diff --git a/setup.cfg b/setup.cfg index 6ff8d7e..77370a6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,41 +1,13 @@ -[versioneer] -VCS = git -style = pep440 -versionfile_source = compaction/_version.py -versionfile_build = compaction/_version.py -tag_prefix = v -parentdir_prefix = compaction- - -[tool:pytest] -minversion = 3.0 -testpaths = compaction tests -norecursedirs = .* *.egg* build dist -# usefixtures = suppress_resource_warning -addopts = - --ignore setup.py - --ignore versioneer.py - --ignore compaction/_version.py - --tb native - --strict - --durations 16 - --doctest-modules - -vvv -doctest_optionflags = - NORMALIZE_WHITESPACE - IGNORE_EXCEPTION_DETAIL - ALLOW_UNICODE - -[isort] -multi_line_output=3 -include_trailing_comma=True -force_grid_wrap=0 -combine_as_imports=True -line_length=88 - [flake8] -exclude = docs -ignore = - E203 - E501 - W503 +exclude = docs, build, .nox +ignore = C901, E203, E266, E501, W503, B905 max-line-length = 88 +max-complexity = 18 +select = B,C,E,F,W,T4,B9 + +[zest.releaser] +tag-format = v{version} +python-file-with-version = compaction/_version.py + +[coverage:run] +relative_files = True From f41d6e2891c4033d2ab02f35304fc9e2617f4e04 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 14:45:54 -0600 Subject: [PATCH 05/20] switch to myst --- AUTHORS.md | 9 +++++++++ LICENSE.md | 4 ++-- README.md | 8 -------- 3 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 AUTHORS.md diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 0000000..dc66855 --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,9 @@ +# Credits + +## Development Lead + +* [Eric Hutton](https://github.com/mcflugen) + +# Contributors + +None yet. Why not be the first? diff --git a/LICENSE.md b/LICENSE.md index 508c3f2..aee0a89 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ -MIT License +# The MIT License (MIT) -Copyright (c) 2017 Eric Hutton +Copyright (c) `2023` `Eric Hutton` Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index d370c72..358e1d1 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,3 @@ -[![Build -Status](https://travis-ci.org/mcflugen/compaction.svg?branch=master)](https://travis-ci.org/mcflugen/compaction) - -[![Build status](https://ci.appveyor.com/api/projects/status/yle29j1hl6a8yu8p?svg=true)](https://ci.appveyor.com/project/mcflugen/compaction) - -[![Coverage -Status](https://coveralls.io/repos/github/mcflugen/compaction/badge.svg?branch=mcflugen%2Fadd-unit-tests)](https://coveralls.io/github/mcflugen/compaction?branch=master) - # compaction: Compact layers of sediment Compact a column of sediment following Bahr et al., 2001. From 07fd78b3533af00245df28cd3ed242b2fd870c0c Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 14:46:34 -0600 Subject: [PATCH 06/20] move static metadata into pyproject.toml --- pyproject.toml | 138 +++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 31 +---------- 2 files changed, 140 insertions(+), 29 deletions(-) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..295524f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,138 @@ +[build-system] +requires = ["cython~=3.0.0b3", "numpy", "setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "compaction" +description = "Compact a column of sediment following Bahr et al., 2001." +authors = [ + {email = "mcflugen@gmail.com"}, + {name = "Eric Hutton"} +] +maintainers = [ + {email = "mcflugen@gmail.com"}, + {name = "Eric Hutton"} +] +keywords = [ + "earth science", + "landlab", + "numerical modeling", + "sediment compaction", +] +license = {file = "LICENSE.md"} +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Cython", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "Topic :: Scientific/Engineering :: Physics", +] +requires-python = ">=3.9" +dependencies = [ + "click", + "landlab", + "numpy", + "pandas", + "pyyaml", + "tomlkit", + "scipy", +] +dynamic = ["readme", "version"] + +[project.urls] +homepage = "https://github.com/mcflugen/compaction" +documentation = "https://compaction.readthedocs.io" +repository = "https://github.com/mcflugen/compaction" +changelog = "https://github.com/mcflugen/compaction/blob/develop/CHANGES.rst" + +[project.optional-dependencies] +dev = ["nox"] +testing = [ + "coveralls", + "hypothesis", + "pytest", + "pytest-cov", + "pytest-datadir", + "pytest-xdist", +] + +[project.entry-points."landlab.components"] +Compact = "compaction.landlab:Compact" + +[project.scripts] +compaction = "compaction.cli:compaction" + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.packages.find] +where = ["."] +include = ["compaction*"] + +[tool.setuptools.dynamic] +readme = {file = ["README.md", "AUTHORS.md"]} +version = {attr = "compaction._version.__version__"} + +[tool.pytest.ini_options] +minversion = "6.0" +testpaths = ["compaction", "tests"] +norecursedirs = [".*", "*.egg*", "build", "dist"] +addopts = """ + --ignore setup.py + --tb native + --durations 16 + --strict-markers + --doctest-modules + -vvv +""" +doctest_optionflags = [ + "NORMALIZE_WHITESPACE", + "IGNORE_EXCEPTION_DETAIL", + "ALLOW_UNICODE" +] +markers = [ + "slow: marks tests as slow (deselect with '-m \"not slow\"')", + "notebook: marks tests as notebook (deselect with '-m \"not notebook\"')" +] + +[tool.isort] +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +combine_as_imports = true +line_length = 88 + +[tool.check-manifest] +ignore = [".nox", "build"] + +[tool.cibuildwheel] +build = "cp39-* cp310-* cp311-*" +skip = "*-musllinux_*" +archs = "x86_64,i686,aarch64,arm64,AMD64,x86" + +[tool.conda-lock] +channels = ["conda-forge", "defaults"] +platforms = ["osx-arm64", "linux-64", "osx-64", "win-64"] + +[tool.towncrier] +directory = "news" +package = "compaction" +filename = "CHANGES.rst" +single_file = true +underlines = "-`^" +issue_format = "`#{issue} `_" +title_format = "{version} ({project_date})" + +type = [ + {name="New Tutorial Notebooks", directory="notebook", showcontent=true}, + {name="New Features", directory="feature", showcontent=true}, + {name="Bug Fixes", directory="bugfix", showcontent=true}, + {name="Documentation Enhancements", directory="docs", showcontent=true}, + {name="Other Changes and Additions", directory="misc", showcontent=true}, +] diff --git a/setup.py b/setup.py index e36f99b..6068493 100644 --- a/setup.py +++ b/setup.py @@ -1,30 +1,3 @@ -from setuptools import setup, find_packages +from setuptools import setup - -setup( - name="compaction", - description="Compact sediment", - long_description=open("README.md", encoding="utf-8").read(), - long_description_content_type="text/markdown", - author="Eric Hutton", - author_email="huttone@colorado.edu", - url="http://csdms.colorado.edu", - classifiers=[ - "Intended Audience :: Science/Research", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Topic :: Scientific/Engineering :: Physics", - ], - keywords=["landlab"], - install_requires=open("requirements.txt", "r").read().splitlines(), - setup_requires=[], - packages=find_packages(), - entry_points={ - "console_scripts": ["compaction=compaction.cli:compaction"], - "landlab.components": ["Compact=compaction.landlab:Compact"], - }, - version="v0.3.0.dev0", -) +setup() From 40bd0599f5387af2dad99d49a8de042ce9d9f372 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 14:46:53 -0600 Subject: [PATCH 07/20] remove lint --- .coveragerc | 2 +- compaction/cli.py | 19 +++++++++++-------- compaction/compaction.py | 2 +- compaction/landlab.py | 7 ++----- tests/test_cli.py | 10 ++++++++-- tests/test_component.py | 8 ++++---- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/.coveragerc b/.coveragerc index c91d88a..d162779 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,3 +1,3 @@ [run] -omit = +omit = */_version.py diff --git a/compaction/cli.py b/compaction/cli.py index dda3f3c..0b94403 100644 --- a/compaction/cli.py +++ b/compaction/cli.py @@ -58,7 +58,7 @@ def _tomlkit_to_popo(d): False """ try: - result = getattr(d, "value") + result = d.value except AttributeError: result = d @@ -79,9 +79,10 @@ def _tomlkit_to_popo(d): else: if not isinstance(result, (int, float, str, bool)): warnings.warn( # pragma: no cover - "unexpected type ({0!r}) encountered when converting toml to a dict".format( + "unexpected type ({!r}) encountered when converting toml to a dict".format( result.__class__.__name__ - ) + ), + stacklevel=2, ) return result @@ -138,7 +139,7 @@ def as_csv(data, header=None): return contents contents = { - "compaction.toml": toml.dumps(dict(compacton=params)), + "compaction.toml": toml.dumps({"compacton": params}), "porosity.csv": as_csv( [[100.0, 0.5], [100.0, 0.5], [100.0, 0.5]], header="Layer Thickness [m], Porosity [-]", @@ -195,7 +196,7 @@ def compaction(cd) -> None: @click.option("--dry-run", is_flag=True, help="Do not actually run the model") def run(dry_run: bool, verbose: bool) -> None: """Run a simulation.""" - with open("compaction.toml", "r") as fp: + with open("compaction.toml") as fp: params = load_config(fp) if verbose: @@ -207,12 +208,13 @@ def run(dry_run: bool, verbose: bool) -> None: run_compaction("porosity.csv", "porosity-out.csv", **params["constants"]) out("💥 Finished! 💥") - out("Output written to {0}".format("porosity-out.csv")) + out("Output written to {}".format("porosity-out.csv")) @compaction.command() @click.argument( - "infile", type=click.Choice(["compaction.toml", "porosity.csv"]), + "infile", + type=click.Choice(["compaction.toml", "porosity.csv"]), ) def generate(infile: str) -> None: """Show example input files.""" @@ -228,7 +230,8 @@ def setup() -> None: if existing_files: for name in existing_files: err( - f"{name}: File exists. Either remove and then rerun or choose a different destination folder", + f"{name}: File exists." + " Either remove and then rerun or choose a different destination folder" ) else: for file_ in files: diff --git a/compaction/compaction.py b/compaction/compaction.py index 1b132b4..1646aa5 100644 --- a/compaction/compaction.py +++ b/compaction/compaction.py @@ -75,7 +75,7 @@ def compact( return_dz[~contains_sediment] = 0.0 else: raise TypeError( - "size and shape of return_dz ({0}, {1}) must be that of dz ({2}, {3})".format( + "size and shape of return_dz ({}, {}) must be that of dz ({}, {})".format( return_dz.dtype, return_dz.shape, dz.dtype, dz.shape ) ) diff --git a/compaction/landlab.py b/compaction/landlab.py index 5509403..d9632d7 100644 --- a/compaction/landlab.py +++ b/compaction/landlab.py @@ -1,6 +1,4 @@ """Compact layers of sediment due to overlying load.""" -from typing import Dict - from landlab import Component # type: ignore from scipy.constants import g # type: ignore @@ -8,7 +6,6 @@ class Compact(Component): - _name = "Compaction" _time_units = "" _input_var_names = ("sediment_layer_thickness", "sediment_layer_porority") @@ -84,9 +81,9 @@ def __init__( [ True, True, True], [False, False, False]], dtype=bool) """ - self._compaction_params: Dict[str, float] = {} + self._compaction_params: dict[str, float] = {} - super(Compact, self).__init__(grid) + super().__init__(grid) self.c = c self.rho_grain = rho_grain diff --git a/tests/test_cli.py b/tests/test_cli.py index 45e85fc..55293ba 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -32,7 +32,10 @@ def test_dry_run(tmpdir, datadir): shutil.copy(datadir / "porosity.csv", ".") runner = CliRunner() - result = runner.invoke(cli.run, ["--dry-run"],) + result = runner.invoke( + cli.run, + ["--dry-run"], + ) assert result.exit_code == 0 assert "Nothing to do" in result.output assert not (tmpdir / "porosity-out.csv").exists() @@ -44,7 +47,10 @@ def test_verbose(tmpdir, datadir): shutil.copy(datadir / "porosity.csv", ".") runner = CliRunner() - result = runner.invoke(cli.run, ["--verbose"],) + result = runner.invoke( + cli.run, + ["--verbose"], + ) assert result.exit_code == 0 assert (tmpdir / "porosity-out.csv").exists() diff --git a/tests/test_component.py b/tests/test_component.py index aebaf19..48ac716 100644 --- a/tests/test_component.py +++ b/tests/test_component.py @@ -18,7 +18,7 @@ def test_matches_module(grid): phi = np.full((100, 3), 0.5) phi_expected = compaction.compact(dz, phi, porosity_max=0.5) - for layer in range(100): + for _ in range(100): grid.event_layers.add(1.0, porosity=0.5) compact = Compact(grid, porosity_min=0.0, porosity_max=0.5) compact.calculate() @@ -37,7 +37,7 @@ def test_init_without_layers_added(grid): @mark.benchmark(group="landlab") def test_grid_size(benchmark, size): grid = RasterModelGrid((3, 101)) - for layer in range(size): + for _ in range(size): grid.event_layers.add(1.0, porosity=0.5) compact = Compact(grid, porosity_min=0.0, porosity_max=0.5) @@ -51,7 +51,7 @@ def test_grid_size(benchmark, size): def test_init_with_layers_added(grid): - for layer in range(5): + for _ in range(5): grid.event_layers.add(100.0, porosity=0.7) compact = Compact(grid, porosity_min=0.1, porosity_max=0.7) compact.run_one_step() @@ -64,7 +64,7 @@ def test_init_with_layers_added(grid): def test_layers_compact_evenly(grid): - for layer in range(1): + for _ in range(1): grid.event_layers.add(100.0, porosity=0.7) compact = Compact(grid, porosity_min=0.1, porosity_max=0.7) compact.run_one_step() From 17cad60cbd2d40c484715f2cd6ccc0b543ff704f Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 14:47:05 -0600 Subject: [PATCH 08/20] add a nox file --- noxfile.py | 247 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 noxfile.py diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..cb02278 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,247 @@ +import os +import pathlib +import shutil +import tempfile + +import nox + +PROJECT = "compaction" +ROOT = pathlib.Path(__file__).parent + + +@nox.session(venv_backend="mamba") +def test(session: nox.Session) -> None: + """Run the tests.""" + os.environ["WITH_OPENMP"] = "1" + + # session.conda_install("c-compiler", "cxx-compiler") + session.log(f"CC = {os.environ.get('CC', 'NOT FOUND')}") + session.conda_install("--file", "requirements.in") + session.conda_install("--file", "requirements-testing.in") + session.install("-e", ".", "--no-deps") + + args = [ + "-n", + "auto", + "--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-cli") +def test_cli(session: nox.Session) -> None: + """Test the command line interface.""" + session.install(".") + session.run("compaction", "--help") + session.run("compaction", "--version") + session.run("compaction", "generate", "--help") + session.run("compaction", "run", "--help") + session.run("compaction", "setup", "--help") + + +@nox.session +def lint(session: nox.Session) -> None: + """Look for lint.""" + skip_hooks = [] if "--no-skip" in session.posargs else ["check-manifest", "pyroma"] + + session.install("pre-commit") + session.run("pre-commit", "run", "--all-files", env={"SKIP": ",".join(skip_hooks)}) + + +@nox.session +def towncrier(session: nox.Session) -> None: + """Check that there is a news fragment.""" + session.install("towncrier") + session.run("towncrier", "check", "--compare-with", "origin/master") + + +@nox.session(name="build-index") +def build_index(session: nox.Session) -> None: + session.install("sphinx") + session.install(".") + + +# @nox.session(name="build-docs", venv_backend="conda") +@nox.session(name="build-docs") +def build_docs(session: nox.Session) -> None: + """Build the docs.""" + build_dir = ROOT / "build" + docs_dir = ROOT / "docs" + + session.install("-r", docs_dir / "requirements.in") + session.install("-e", ".") + + build_dir.mkdir(exist_ok=True) + session.run( + "sphinx-build", + "-b", + "html", + "-W", + "--keep-going", + docs_dir / "source", + build_dir / "html", + ) + session.log(f"generated docs at {build_dir / 'html'!s}") + + +@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 +def release(session): + """Tag, build and publish a new release to PyPI.""" + session.install("zest.releaser[recommended]") + session.install("zestreleaser.towncrier") + 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"{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) + + +@nox.session(python=False, name="clean-checkpoints") +def clean_checkpoints(session): + """Remove jupyter notebook checkpoint files.""" + for folder in _args_to_folders(session.posargs): + with session.chdir(folder): + _clean_rglob("*-checkpoint.ipynb") + _clean_rglob(".ipynb_checkpoints") + + +@nox.session(python=False, name="clean-docs") +def clean_docs(session: nox.Session) -> None: + """Clean up the docs folder.""" + build_dir = ROOT / "build" + + if (build_dir / "html").is_dir(): + with session.chdir(build_dir): + shutil.rmtree("html") + + if (ROOT / "build").is_dir(): + session.chdir(ROOT / "build") + if os.path.exists("html"): + shutil.rmtree("html") + + +@nox.session(python=False, name="clean-ext") +def clean_ext(session: nox.Session) -> None: + """Clean shared libraries for extension modules.""" + for folder in _args_to_folders(session.posargs): + with session.chdir(folder): + _clean_rglob("*.so") + + +@nox.session(python=False) +def nuke(session): + """Run all clean sessions.""" + clean_checkpoints(session) + clean_docs(session) + clean(session) + clean_ext(session) + + +@nox.session(name="list-wheels") +def list_wheels(session): + print(os.linesep.join(_get_wheels(session))) + + +@nox.session(name="list-ci-matrix") +def list_ci_matrix(session): + def _os_from_wheel(name): + if "linux" in name: + return "linux" + elif "macos" in name: + return "macos" + elif "win" in name: + return "windows" + + for wheel in _get_wheels(session): + print(f"- cibw-only: {wheel}") + print(f" os: {_os_from_wheel(wheel)}") + + +def _get_wheels(session): + platforms = session.posargs or ["linux", "macos", "windows"] + session.install("cibuildwheel") + + wheels = [] + for platform in platforms: + with tempfile.TemporaryFile("w+") as fp: + session.run( + "cibuildwheel", + "--print-build-identifiers", + "--platform", + platform, + stdout=fp, + ) + fp.seek(0) + wheels += fp.read().splitlines() + return wheels + + +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() From eff3028317911339842ce939b8f157ce7f61e525 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 15:04:10 -0600 Subject: [PATCH 09/20] set up towncrier --- NEWS.md | 5 +++++ news/.gitignore | 1 + news/changelog_template.jinja | 15 +++++++++++++++ pyproject.toml | 10 ++++++---- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 NEWS.md create mode 100644 news/.gitignore create mode 100644 news/changelog_template.jinja diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..206a115 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,5 @@ +# Release Notes + + + + diff --git a/news/.gitignore b/news/.gitignore new file mode 100644 index 0000000..f935021 --- /dev/null +++ b/news/.gitignore @@ -0,0 +1 @@ +!.gitignore diff --git a/news/changelog_template.jinja b/news/changelog_template.jinja new file mode 100644 index 0000000..0cf429a --- /dev/null +++ b/news/changelog_template.jinja @@ -0,0 +1,15 @@ +{% if sections[""] %} +{% for category, val in definitions.items() if category in sections[""] %} + +### {{ definitions[category]['name'] }} + +{% for text, values in sections[""][category].items() %} +- {{ text }} {{ values|join(', ') }} +{% endfor %} + +{% endfor %} +{% else %} +No significant changes. + + +{% endif %} diff --git a/pyproject.toml b/pyproject.toml index 295524f..4591df6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -123,11 +123,13 @@ platforms = ["osx-arm64", "linux-64", "osx-64", "win-64"] [tool.towncrier] directory = "news" package = "compaction" -filename = "CHANGES.rst" +filename = "NEWS.md" +underlines = ["", "", ""] +start_string = "\n" +template = "news/changelog_template.jinja" single_file = true -underlines = "-`^" -issue_format = "`#{issue} `_" -title_format = "{version} ({project_date})" +issue_format = "[#{issue}](https://github.com/mcflugen/compaction/issues/{issue})" +title_format = "## [{version}](https://github.com/mcflugen/compaction/tree/{version}) - {project_date}" type = [ {name="New Tutorial Notebooks", directory="notebook", showcontent=true}, From b3a9069ebcb6c2e647437cf1622560e84d942176 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 15:07:59 -0600 Subject: [PATCH 10/20] add some github actions for testing/linting --- .github/workflows/changelog.yml | 28 ++++++++++++++ .github/workflows/lint.yml | 27 ++++++++++++++ .github/workflows/test.yml | 66 +++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 .github/workflows/changelog.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 0000000..8e5fc65 --- /dev/null +++ b/.github/workflows/changelog.yml @@ -0,0 +1,28 @@ +name: changelog + +on: + pull_request: + types: [labeled, unlabeled, opened, reopened, synchronize] + +permissions: + contents: read + +jobs: + check-changelog-entry: + name: changelog entry + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + # `towncrier check` runs `git diff --name-only origin/main...`, which + # needs a non-shallow clone. + fetch-depth: 0 + + - name: Check changelog + if: contains(github.event.pull_request.labels.*.name, 'skip news') != true + run: | + if ! pipx run towncrier check --compare-with origin/${{ github.base_ref }}; then + echo "Please see https://landlab.readthedocs.io/en/master/development/contribution/index.html?highlight=towncrier#news-entries for guidance." + false + fi diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..8adee4e --- /dev/null +++ b/.github/workflows/lint.yml @@ -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@v3 + - 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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ef0061a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,66 @@ +name: Test + +on: [push, pull_request] + +jobs: + build-and-test: + name: Run the tests + # 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.9", "3.10", "3.11"] + pytest-marker: ["slow", "not slow"] + + steps: + - uses: actions/checkout@v3 + + - uses: conda-incubator/setup-miniconda@v2 + with: + auto-update-conda: true + python-version: ${{ matrix.python-version }} + channels: conda-forge + channel-priority: true + + - name: Show conda installation info + run: | + conda install mamba + pip install nox + conda info + conda list + + - name: Test + env: + HYPOTHESIS_PROFILE: "ci" + run: | + nox -s test -- -m "${{ matrix.pytest-marker }}" + + - name: Coveralls + if: matrix.os == 'ubuntu-latest' + uses: AndreMiras/coveralls-python-action@develop + with: + parallel: true + flag-name: py${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.pytest-marker }} + 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 From 76b8fd765b8ba721eb446b152320221202a22c12 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 15:11:38 -0600 Subject: [PATCH 11/20] give requirements files .in extension --- requirements-testing.txt => requirements-testing.in | 0 requirements.txt => requirements.in | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename requirements-testing.txt => requirements-testing.in (100%) rename requirements.txt => requirements.in (100%) diff --git a/requirements-testing.txt b/requirements-testing.in similarity index 100% rename from requirements-testing.txt rename to requirements-testing.in diff --git a/requirements.txt b/requirements.in similarity index 100% rename from requirements.txt rename to requirements.in From 0fb07534109cf1b86f4d65d7ad79f359fef8447b Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 15:23:31 -0600 Subject: [PATCH 12/20] install testing requirements with pip --- noxfile.py | 6 +++--- requirements-testing.in | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index cb02278..e8fdeee 100644 --- a/noxfile.py +++ b/noxfile.py @@ -9,15 +9,15 @@ ROOT = pathlib.Path(__file__).parent -@nox.session(venv_backend="mamba") +@nox.session() def test(session: nox.Session) -> None: """Run the tests.""" os.environ["WITH_OPENMP"] = "1" # session.conda_install("c-compiler", "cxx-compiler") session.log(f"CC = {os.environ.get('CC', 'NOT FOUND')}") - session.conda_install("--file", "requirements.in") - session.conda_install("--file", "requirements-testing.in") + session.install("-r", "requirements.in") + session.install("-r", "requirements-testing.in") session.install("-e", ".", "--no-deps") args = [ diff --git a/requirements-testing.in b/requirements-testing.in index 18c566d..9042c1a 100644 --- a/requirements-testing.in +++ b/requirements-testing.in @@ -3,3 +3,4 @@ pytest-benchmark pytest-cov pytest-datadir pytest-mypy +pytest-xdist From 27d4b9fe55caf23339cdb06dcd89e1133768b209 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 15:35:41 -0600 Subject: [PATCH 13/20] update the manifest --- MANIFEST.in | 11 +++++++++-- README.md | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 096dd50..e427fc7 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,9 @@ -include LICENSE -include requirements.txt +include .coveragerc +include .pre-commit-config.yaml +include LICENSE.md +include NEWS.md +include noxfile.py +include requirements*.in + +recursive-exclude news * +recursive-exclude tests * diff --git a/README.md b/README.md index 358e1d1..38acf9b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Compact a column of sediment following Bahr et al., 2001. -Cite as: +Cite as:: @article{bahr2001exponential, title={Exponential approximations to compacted sediment porosity profiles}, From 0ca519005ad54808ab4237e5b603d390be611012 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 15:36:32 -0600 Subject: [PATCH 14/20] turn off pytest-xdist --- noxfile.py | 2 -- requirements-testing.in | 1 - 2 files changed, 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index e8fdeee..3e29a01 100644 --- a/noxfile.py +++ b/noxfile.py @@ -21,8 +21,6 @@ def test(session: nox.Session) -> None: session.install("-e", ".", "--no-deps") args = [ - "-n", - "auto", "--cov", PROJECT, "-vvv", diff --git a/requirements-testing.in b/requirements-testing.in index 9042c1a..18c566d 100644 --- a/requirements-testing.in +++ b/requirements-testing.in @@ -3,4 +3,3 @@ pytest-benchmark pytest-cov pytest-datadir pytest-mypy -pytest-xdist From a791cc8852d9af9836e4e64b46dd82027e1844ed Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 15:49:37 -0600 Subject: [PATCH 15/20] remove pytest markers from tests --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ef0061a..8fc06ec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,6 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.9", "3.10", "3.11"] - pytest-marker: ["slow", "not slow"] steps: - uses: actions/checkout@v3 @@ -45,7 +44,7 @@ jobs: env: HYPOTHESIS_PROFILE: "ci" run: | - nox -s test -- -m "${{ matrix.pytest-marker }}" + nox -s test - name: Coveralls if: matrix.os == 'ubuntu-latest' From 6b22ee62e6146708de57c2b5ff63f54494f88d72 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 16:06:20 -0600 Subject: [PATCH 16/20] add a badge for the tests --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 38acf9b..cda7541 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +[![Test][test_badge]][test_workflow] +[test_badge]: https://github.com/mcflugen/compaction/actions/workflows/test.yml/badge.svg +[test_workflow]: https://github.com/mcflugen/compaction/actions/workflows/test.yml + + # compaction: Compact layers of sediment Compact a column of sediment following Bahr et al., 2001. From e452e768acfab6f6187101851dcf3eb146555678 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 16:11:17 -0600 Subject: [PATCH 17/20] add news fragments --- news/16.misc.1 | 3 +++ news/16.misc.2 | 3 +++ news/16.misc.3 | 3 +++ news/16.misc.4 | 3 +++ news/16.misc.5 | 3 +++ 5 files changed, 15 insertions(+) create mode 100644 news/16.misc.1 create mode 100644 news/16.misc.2 create mode 100644 news/16.misc.3 create mode 100644 news/16.misc.4 create mode 100644 news/16.misc.5 diff --git a/news/16.misc.1 b/news/16.misc.1 new file mode 100644 index 0000000..187367b --- /dev/null +++ b/news/16.misc.1 @@ -0,0 +1,3 @@ + +Moved static project metadata from *setup.py* to the now standard +*pyproject.toml*. diff --git a/news/16.misc.2 b/news/16.misc.2 new file mode 100644 index 0000000..101f7d5 --- /dev/null +++ b/news/16.misc.2 @@ -0,0 +1,3 @@ + +Added a [nox](https://nox.thea.codes/en/stable/) file for routine +project management like running the tests and linting. diff --git a/news/16.misc.3 b/news/16.misc.3 new file mode 100644 index 0000000..588bfb3 --- /dev/null +++ b/news/16.misc.3 @@ -0,0 +1,3 @@ + +Added a [pre-commit](https://pre-commit.com/) hook file for running +the linters. diff --git a/news/16.misc.4 b/news/16.misc.4 new file mode 100644 index 0000000..3298f29 --- /dev/null +++ b/news/16.misc.4 @@ -0,0 +1,3 @@ + +Set up [towncrier](https://towncrier.readthedocs.io/en/stable/index.html) +to manage the changelog. diff --git a/news/16.misc.5 b/news/16.misc.5 new file mode 100644 index 0000000..ace1c9c --- /dev/null +++ b/news/16.misc.5 @@ -0,0 +1,3 @@ + +Added GitHub Actions for running the continuous integration tests, which +includes running the tests and linters. From 8fc4dcbea429ec2d2a6e5925d0f11310d12e63af Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 16:21:38 -0600 Subject: [PATCH 18/20] more source code to src folder --- pyproject.toml | 6 +----- {compaction => src/compaction}/__init__.py | 0 {compaction => src/compaction}/_version.py | 0 {compaction => src/compaction}/cli.py | 0 {compaction => src/compaction}/compaction.py | 0 {compaction => src/compaction}/landlab.py | 0 6 files changed, 1 insertion(+), 5 deletions(-) rename {compaction => src/compaction}/__init__.py (100%) rename {compaction => src/compaction}/_version.py (100%) rename {compaction => src/compaction}/cli.py (100%) rename {compaction => src/compaction}/compaction.py (100%) rename {compaction => src/compaction}/landlab.py (100%) diff --git a/pyproject.toml b/pyproject.toml index 4591df6..4ab75cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,17 +71,13 @@ compaction = "compaction.cli:compaction" [tool.setuptools] include-package-data = true -[tool.setuptools.packages.find] -where = ["."] -include = ["compaction*"] - [tool.setuptools.dynamic] readme = {file = ["README.md", "AUTHORS.md"]} version = {attr = "compaction._version.__version__"} [tool.pytest.ini_options] minversion = "6.0" -testpaths = ["compaction", "tests"] +testpaths = ["src/compaction", "tests"] norecursedirs = [".*", "*.egg*", "build", "dist"] addopts = """ --ignore setup.py diff --git a/compaction/__init__.py b/src/compaction/__init__.py similarity index 100% rename from compaction/__init__.py rename to src/compaction/__init__.py diff --git a/compaction/_version.py b/src/compaction/_version.py similarity index 100% rename from compaction/_version.py rename to src/compaction/_version.py diff --git a/compaction/cli.py b/src/compaction/cli.py similarity index 100% rename from compaction/cli.py rename to src/compaction/cli.py diff --git a/compaction/compaction.py b/src/compaction/compaction.py similarity index 100% rename from compaction/compaction.py rename to src/compaction/compaction.py diff --git a/compaction/landlab.py b/src/compaction/landlab.py similarity index 100% rename from compaction/landlab.py rename to src/compaction/landlab.py From cca5d9c4a57cd49e3dee3a3aa3637ccc1a68fe39 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 16:25:20 -0600 Subject: [PATCH 19/20] clean egg from src folder --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 3e29a01..9763164 100644 --- a/noxfile.py +++ b/noxfile.py @@ -141,7 +141,7 @@ def clean(session): with session.chdir(folder): shutil.rmtree("build", ignore_errors=True) shutil.rmtree("build/wheelhouse", ignore_errors=True) - shutil.rmtree(f"{PROJECT}.egg-info", 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) From e3a5eea8d3827569793b92d0ebdae5f9e6742768 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Fri, 28 Jul 2023 16:28:26 -0600 Subject: [PATCH 20/20] add release and prerelease actions --- .github/workflows/prerelease.yml | 46 ++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 .github/workflows/prerelease.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml new file mode 100644 index 0000000..4910b43 --- /dev/null +++ b/.github/workflows/prerelease.yml @@ -0,0 +1,46 @@ +name: TestPyPI + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+[ab][0-9]+' + +env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} + TWINE_REPOSITORY_URL: 'https://test.pypi.org/legacy/' + +jobs: + build-and-publish: + name: Build and publish to TestPyPI + runs-on: ubuntu-latest + + defaults: + run: + shell: bash -l {0} + + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v4 + with: + python-version: "3.9" + + - name: Install twine + run: | + pip install --upgrade pip wheel setuptools + pip install twine + python --version + pip --version + twine --version + + - name: Create source distribution + run: | + python setup.py sdist --dist-dir wheelhouse + + - name: Upload source distribution + run: | + twine upload --skip-existing wheelhouse/*.tar.gz diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..40edc3a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +name: PyPI + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + - '!v[0-9]+.[0-9]+.[0-9]+[ab][0-9]+' + +env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + +jobs: + build-and-publish: + name: Build and publish to PyPI + runs-on: ubuntu-latest + + defaults: + run: + shell: bash -l {0} + + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install twine + run: | + pip install --upgrade pip wheel setuptools + pip install twine + python --version + pip --version + twine --version + + - name: Create source distribution + run: | + python setup.py sdist --dist-dir wheelhouse + + - name: Upload source distribution + run: | + twine upload --skip-existing wheelhouse/*.tar.gz