Skip to content

Commit

Permalink
build: update pyproject.toml to replace setup.cfg (#134)
Browse files Browse the repository at this point in the history
]* update README.md
* update version to 1.2.9.dev0
* add pytest conftest.py
* install test requirements for CI from pyproject.toml
  • Loading branch information
jdhughes-usgs committed Jul 7, 2023
1 parent 2d6ca3f commit fecade8
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 97 deletions.
29 changes: 29 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[flake8]
exclude =
.git
__pycache__
build
dist
examples
autotest
ignore =
# https://flake8.pycqa.org/en/latest/user/error-codes.html
F401,
# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# Indentation
E121, E122, E126, E127, E128,
# Whitespace
E203, E221, E222, E226, E231, E241,
# Import
E402,
# Line length
E501, E502,
# Statement
E722, E741,
# Whitespace warning
W291, W292, W293,
# Blank line warning
W391,
# Line break warning
W503, W504
statistics = True
9 changes: 0 additions & 9 deletions .github/common/install-python.sh

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ jobs:

- name: Install python packages
run: |
.github/common/install-python.sh
pip install --upgrade pip
pip install ".[test]"
- name: Download examples for pytest runs
run: |
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/pymake-gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:

- name: Install python packages
run: |
.github/common/install-python.sh
pip install --upgrade pip
pip install ".[test]"
- name: Install GNU Fortran
uses: modflowpy/install-gfortran-action@v1
Expand Down Expand Up @@ -85,7 +86,8 @@ jobs:

- name: Install python packages
run: |
.github/common/install-python.sh
pip install --upgrade pip
pip install ".[test]"
- name: Setup symbolic link to gfortran on Linux
run: |
Expand Down Expand Up @@ -140,7 +142,8 @@ jobs:

- name: Install python packages
run: |
.github/common/install-python.sh
pip install --upgrade pip
pip install ".[test]"
- name: Install GNU Fortran
uses: modflowpy/install-gfortran-action@v1
Expand All @@ -150,5 +153,6 @@ jobs:
.github/common/download-examples.sh
- name: Run pytest
working-directory: ./autotest
run: |
pytest -v --dist=loadfile -n=auto -m="base" --durations=0
3 changes: 2 additions & 1 deletion .github/workflows/pymake-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:

- name: Install python packages
run: |
.github/common/install-python.sh
pip install --upgrade pip
pip install ".[test]"
- name: Run pytest
working-directory: ./autotest
Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

Python package for building MODFLOW-based programs from source files.

### Version 1.2.8
### Version 1.2.9.dev0

![pymake continuous integration](https://github.com/modflowpy/pymake/workflows/pymake%20continuous%20integration/badge.svg)
[![PyPI Version](https://img.shields.io/pypi/v/mfpymake.png)](https://pypi.python.org/pypi/mfpymake)
[![Anaconda Version](https://anaconda.org/conda-forge/mfpymake/badges/version.svg)](https://anaconda.org/conda-forge/mfpymake)
[![pymake continuous integration](https://github.com/modflowpy/pymake/workflows/pymake%20continuous%20integration/badge.svg)](https://github.com/modflowpy/pymake/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/modflowpy/pymake/branch/master/graph/badge.svg)](https://codecov.io/gh/modflowpy/pymake)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/fe4275a3cfb84acf9c84aba7b4ae2086)](https://www.codacy.com/gh/modflowpy/pymake/dashboard?utm_source=github.com&utm_medium=referral&utm_content=modflowpy/pymake&utm_campaign=Badge_Grade)
[![Documentation Status](https://readthedocs.org/projects/mfpymake/badge/?version=latest)](https://mfpymake.readthedocs.io/en/latest/?badge=latest)
[![PyPI Version](https://img.shields.io/pypi/v/mfpymake.png)](https://pypi.python.org/pypi/mfpymake)
[![Documentation Status](https://readthedocs.org/projects/mfpymake/badge/?version=latest)](https://mfpymake.readthedocs.io/en/latest/?badge=latest)

This is a python package for compiling MODFLOW-based and other Fortran, C, and
C++ programs. The package determines the build order using a directed acyclic
graph and then compiles the source files using GNU compilers (`gcc`, `g++`,
`gfortran`), Clang compilers (`clang`, `clang++`), Intel compilers (`ifort`,
`icl`, `icc`, `mpiifort`), or the CRAY Fortran compiler (`ftn`).
`gfortran`), Clang compilers (`clang`, `clang++`), or the Intel compilers (`ifort`,
`icl`, `icc`, `mpiifort`).

pymake can be run from the command line or it can be called from within python.
By default, pymake sets the optimization level, Fortran flags, C/C++ flags, and
Expand Down Expand Up @@ -233,6 +234,12 @@ To install pymake using pip type:
pip install mfpymake
```

To install pymake using conda type:

```
conda install -c conda-forge mfpymake
```

To install pymake directly from the git repository type:

```
Expand Down
101 changes: 101 additions & 0 deletions autotest/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import contextlib
import os
import re
from importlib import metadata
from pathlib import Path

import pytest

# import modflow-devtools fixtures

pytest_plugins = ["modflow_devtools.fixtures"]


# constants


# misc utilities
@contextlib.contextmanager
def working_directory(path):
"""Changes working directory and returns to previous on exit."""
prev_cwd = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(prev_cwd)


def get_pymake_appdir():
appdir = Path.home() / ".pymake"
appdir.mkdir(parents=True, exist_ok=True)
return appdir


def get_project_root_path() -> Path:
return Path(__file__).parent.parent


# path fixtures


# pytest configuration hooks


@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
# this is necessary so temp dir fixtures can
# inspect test results and check for failure
# (see https://doc.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures)

outcome = yield
rep = outcome.get_result()

# report attribute for each phase (setup, call, teardown)
# we're only interested in result of the function call
setattr(item, "rep_" + rep.when, rep)


def pytest_report_header(config):
"""Header for pytest to show versions of packages."""

required = []
extra = {}
for item in metadata.requires("flopy"):
pkg_name = re.findall(r"[a-z0-9_\-]+", item, re.IGNORECASE)[0]
if res := re.findall("extra == ['\"](.+)['\"]", item):
assert len(res) == 1, item
pkg_extra = res[0]
if pkg_extra not in extra:
extra[pkg_extra] = []
extra[pkg_extra].append(pkg_name)
else:
required.append(pkg_name)

processed = set()
lines = []
items = []
for name in required:
processed.add(name)
try:
version = metadata.version(name)
items.append(f"{name}-{version}")
except metadata.PackageNotFoundError:
items.append(f"{name} (not found)")
lines.append("required packages: " + ", ".join(items))
installed = []
not_found = []
for name in extra["optional"]:
if name in processed:
continue
processed.add(name)
try:
version = metadata.version(name)
installed.append(f"{name}-{version}")
except metadata.PackageNotFoundError:
not_found.append(name)
if installed:
lines.append("optional packages: " + ", ".join(installed))
if not_found:
lines.append("optional packages not found: " + ", ".join(not_found))
return "\n".join(lines)
2 changes: 1 addition & 1 deletion pymake/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__author__ = "Joseph D. Hughes"
__date__ = "July 5, 2023"
__version__ = "1.2.8"
__version__ = "1.2.9.dev0"
__maintainer__ = "Joseph D. Hughes"
__email__ = "[email protected]"
__status__ = "Production"
Expand Down
90 changes: 87 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,98 @@
[build-system]
# Minimum requirements for the build system to execute
requires = [
"setuptools>=45",
"setuptools>=61",
"wheel",
]
build-backend = "setuptools.build_meta"

[project]
name = "mfpymake"
description = "pymake is a Python package to compile MODFLOW-based models."
authors = [
{ name = "mfpymake Team", email = "[email protected]" },
]
maintainers = [
{ name = "Joseph D. Hughes", email = "[email protected]" },
]
keywords = ["MODFLOW", "groundwater", "hydrogeology"]
license = { text = "CC0" }
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Hydrology",
]
requires-python = ">=3.8"
dependencies = [
"numpy",
"requests",
"networkx >= 2.6.3",
"meson",
"ninja",
"pydotplus",
]
dynamic = ["version", "readme"]
[project.optional-dependencies]
lint = [
"black",
"cffconvert",
"flake8",
"isort",
"pylint",
]
test = [
"mfpymake[lint]",
"coverage",
"flaky",
"filelock",
"pytest",
"pytest-benchmark",
"pytest-cases",
"pytest-cov",
"pytest-dotenv",
"pytest-virtualenv",
"pytest-xdist",
"appdirs",
"matplotlib",
"modflow-devtools",
"flopy",
]
[project.scripts]
mfpymake = "pymake.cmds.mfpymakecli:main"
make-program = "pymake.cmds.build:main"
make-code-json = "pymake.cmds.createjson:main"


[project.urls]
Documentation = "https://mfpymake.readthedocs.io"
"Release Notes" = "https://github.com/modflowpy/flopy/blob/develop/docs/version_changes.md"
"Bug Tracker" = "https://github.com/modflowpy/pymake/issues"
"Source Code" = "https://github.com/modflowpy/pymake"


[tool.setuptools]
include-package-data = true
zip-safe = false

[tool.setuptools.dynamic]
version = { attr = "pymake.config.__version__" }
readme = { file = ["README.md"], content-type = "text/markdown" }

[tool.setuptools.packages.find]
include = ["pymake", "pymake.*"]

[tool.setuptools.package-data]
"pymake.utils" = ["usgsprograms.txt"]

[tool.black]
line-length = 79
target_version = ["py37"]
target_version = ["py38"]

[tool.flynt]
line-length = 79
Expand All @@ -20,4 +104,4 @@ src_paths = ["pymake", "autotest", "examples"]
line_length = 79

[tool.setuptools_scm]
fallback_version = "999"
fallback_version = "999"
Loading

0 comments on commit fecade8

Please sign in to comment.