Skip to content

Commit

Permalink
Modernize build system (#42)
Browse files Browse the repository at this point in the history
* Modernize build system

Fixes #28. Also updating GitHub workflows, README/CONTRIBUTING, etc.

* Switch to using syrupy

pytest-snapshottest uses imp, which was deprecated in 3.11 and gone now.
They don't look like moving
syrusakbary/snapshottest#166

Conflicts:
	.github/workflows/python-build-test.yml
  • Loading branch information
kwinkunks authored Dec 21, 2023
1 parent c044d99 commit 7892da4
Show file tree
Hide file tree
Showing 24 changed files with 148 additions and 202 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/python-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -24,12 +25,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install -r test_requirements.txt
python -m pip install .[dev,test]
- name: Lint with flake8 and black
run: |
pip install flake8
pip install black
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# test remaining issues
Expand All @@ -38,7 +36,6 @@ jobs:
- name: Test
run: |
pytest .
- name: Run Examples
run: |
open_petro_elastic --data-file examples/example1.csv examples/example1.yaml
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish to PyPI

on:
release:
types: [created]
types: [published]

jobs:
deploy:
Expand All @@ -16,11 +16,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
python -m pip install .[dev]
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
5 changes: 2 additions & 3 deletions .github/workflows/python-sphinx-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install -r doc_requirements.txt
python -m pip install .[docs]
- name: Generate documentation
run: |
sphinx-build docs docs_out/
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ We expect commit messages to follow the style described [here](https://chris.bea
You can build the documentation after installation by running:

```bash
pip install -r dev-requirements.txt
python -m pip install .[docs]
sphinx-build -n -v -E -W ./docs ./tmp/ope_docs
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A Python library for petro-elastic modelling. It contains a `Material` class for
pip install open_petro_elastic
```

Developers and contributors can download the repository and do `pip install .` to install the package.
Developers and contributors can download the repository and do `pip install ".[dev,test,docs]"` to install the package with all its dependencies for development, testing, and building the docs.


## Usage
Expand Down
6 changes: 0 additions & 6 deletions doc_requirements.txt

This file was deleted.

90 changes: 90 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[build-system]
requires = ["setuptools>=68", "setuptools-scm>=8"]
build-backend = "setuptools.build_meta"

[project]
name="open_petro_elastic"
dynamic = ["version"]
requires-python = ">=3.8"
authors = [{ name="Equinor", email="fg_sib-scout@equinor.com" },]
description="Utility for calculating elastic properties of rocks and fluids."
license = {file = "LICENSE"}
readme = "README.md"
keywords = ["geophysics", "rock physics", "materials science"]
classifiers=[
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Hydrology",
"Topic :: Scientific/Engineering :: Physics",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"numpy<2",
"scipy",
"pyyaml",
"pandas",
"pydantic",
"sympy",
"typing_extensions",
]

[project.optional-dependencies]
test = [
"pytest",
"syrupy",
"hypothesis",
"matplotlib",
"pillow>=10.0.0", # Not directly required, pinned by Snyk to avoid a vulnerability
"Flake8-pyproject", # Work around Flake8 incompatibility with pyproject.toml
]
docs = [
"sphinx",
"sphinx-rtd-theme",
"sphinx-argparse",
"matplotlib",
"recommonmark",
"pygments-csv-lexer",
]
dev = [
"build",
"setuptools",
"flake8",
"black",
"isort",
"mypy",
]

[project.urls]
"documentation" = "https://equinor.github.io/open_petro_elastic"
"repository" = "https://github.com/equinor/open_petro_elastic"

[project.scripts]
open_petro_elastic = "open_petro_elastic.__main__:main"

[project.entry-points."open_petro_elastic.fluid_model_providers"]
batzle_wang = "open_petro_elastic.config.fluid_model_providers:BatzleWangFluidModelProvider"
span_wagner = "open_petro_elastic.config.fluid_model_providers:SpanWagnerFluidModelProvider"

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
open_petro_elastic = ["tutorial_config/*"]
"open_petro_elastic.material.span_wagner.tables" = [
"material/span_wagner/tables/carbon_dioxide_density.npz"
]

[tool.flake8]
max-line-length = 88
ignore = ["E302", "W503", "E501", "E741", "E203", "F405"]
per-file-ignores = [
"__init__.py:F401,F403",
"conftest.py: F401,F403",
]
7 changes: 0 additions & 7 deletions requirements.txt

This file was deleted.

11 changes: 0 additions & 11 deletions setup.cfg

This file was deleted.

57 changes: 0 additions & 57 deletions setup.py

This file was deleted.

5 changes: 0 additions & 5 deletions test_requirements.txt

This file was deleted.

4 changes: 4 additions & 0 deletions tests/__snapshots__/test_config_fluids.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_fluids_vectorized
Material(shear_modulus=0, bulk_modulus=[1.64734606e+08 1.83184882e+08], primary_velocity=[1144.72360384 1021.36998928], secondary_velocity=[0. 0.], density=[125.71397711 175.59956795])
# ---
7 changes: 7 additions & 0 deletions tests/__snapshots__/test_depth_trend.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# serializer version: 1
# name: test_dryrock_depthtrend_k_my
Material(shear_modulus=[12.], bulk_modulus=[20.], primary_velocity=[0.1165543], secondary_velocity=[0.06729266], density=[2650.])
# ---
# name: test_dryrock_depthtrend_vp_vs
Material(shear_modulus=[12.], bulk_modulus=[20.], primary_velocity=[0.1165543], secondary_velocity=[0.06729266], density=[2650.])
# ---
13 changes: 13 additions & 0 deletions tests/__snapshots__/test_dryrock.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# serializer version: 1
# name: test_dryrock_phi_fitted_vp_vs
tuple(
Material(shear_modulus=[7.6585e+09], bulk_modulus=[1.20751667e+10], primary_velocity=[2900.], secondary_velocity=[1700.], density=[2650.]),
Material(shear_modulus=44.0, bulk_modulus=36.8, primary_velocity=0.18980294316133353, secondary_velocity=0.128855630784633, density=2650.0),
)
# ---
# name: test_dryrock_phi_k_my
tuple(
Material(shear_modulus=[12.], bulk_modulus=[20.], primary_velocity=[0.1165543], secondary_velocity=[0.06729266], density=[2650.]),
Material(shear_modulus=44.0, bulk_modulus=36.8, primary_velocity=0.18980294316133353, secondary_velocity=0.128855630784633, density=2650.0),
)
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_fluid_substitution.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_fluid_substitution
Material(shear_modulus=[1.], bulk_modulus=[1.94708995], primary_velocity=[1.28070748], secondary_velocity=[0.70710678], density=[2.])
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_murphy_coordination_number.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_murphy_coordination_number
17.555560500000002
# ---
10 changes: 10 additions & 0 deletions tests/__snapshots__/test_pressure.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# serializer version: 1
# name: test_pressure_dependency_no_pressure_exp_fit
Material(shear_modulus=1.0, bulk_modulus=0.9999999999999998, primary_velocity=1.5275252316519465, secondary_velocity=1.0, density=1.0)
# ---
# name: test_pressure_dependency_no_pressure_poly_fit
Material(shear_modulus=1.0, bulk_modulus=0.9999999999999998, primary_velocity=1.5275252316519465, secondary_velocity=1.0, density=1.0)
# ---
# name: test_pressure_dependency_no_pressure_power_fit
Material(shear_modulus=1.0, bulk_modulus=0.9999999999999998, primary_velocity=1.5275252316519465, secondary_velocity=1.0, density=1.0)
# ---
Empty file removed tests/snapshots/__init__.py
Empty file.
12 changes: 0 additions & 12 deletions tests/snapshots/snap_test_config_fluids.py

This file was deleted.

16 changes: 0 additions & 16 deletions tests/snapshots/snap_test_depth_trend.py

This file was deleted.

26 changes: 0 additions & 26 deletions tests/snapshots/snap_test_dryrock.py

This file was deleted.

12 changes: 0 additions & 12 deletions tests/snapshots/snap_test_fluid_substitution.py

This file was deleted.

Loading

0 comments on commit 7892da4

Please sign in to comment.