Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Ruff formatting and linting. Install configuration moved to pyproject.toml #1323

Merged
merged 25 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b5a1117
STY: Formatting with ruff
keileg Feb 5, 2025
1fe4687
STY: Prepare for linting with ruff
keileg Feb 5, 2025
0482cd7
BLD: Migrating to a pyproject.toml setup file
keileg Feb 5, 2025
5019bc4
BLD: Migrate setup information to pyproject.toml
keileg Feb 6, 2025
72d40a1
STY: Reformat f-strings without expressions
keileg Feb 6, 2025
aed4bfd
BLD: Introduce ruff in static GH actions
keileg Feb 6, 2025
d3791c2
BLD: Split out development dependencies in pyproject.toml
keileg Feb 6, 2025
31660ed
BLD: Update GH actions installation of PorePy
keileg Feb 6, 2025
8a62a50
BLD: Deleted old setup.cfg and requiremnets files
keileg Feb 6, 2025
57a99f5
BLD: Fixes of GH action files
keileg Feb 6, 2025
b4ca5ea
BLD: One more fix in GH action.
keileg Feb 6, 2025
9b31d45
BLD: Update to GH action static checks
keileg Feb 6, 2025
8521852
BLD: Update of static check GH action
keileg Feb 6, 2025
74e4c18
BLD: Update to pyproject and GH action files
keileg Feb 6, 2025
5d7f8d6
STY: Mypy errors
keileg Feb 6, 2025
2ac81f4
BLD: Update GH static check action
keileg Feb 6, 2025
3e55333
STY: Remove unused import
keileg Feb 6, 2025
99e4396
Merge branch 'develop' into ruff
keileg Feb 6, 2025
07de26d
Merge branch 'develop' into ruff
IvarStefansson Feb 6, 2025
4549b03
Apply suggestions from code review
keileg Feb 6, 2025
c559ec3
STY: Ruff formatting
keileg Feb 7, 2025
24b485c
DOC: Update Readme, badges for tests
keileg Feb 7, 2025
34e519e
Merge branch 'develop' into ruff
keileg Feb 12, 2025
ed15e8d
BLD: Limit numpy version to <2.2 to avoid mypy issues
keileg Feb 12, 2025
432c425
Merge branch 'develop' into ruff
keileg Feb 12, 2025
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
26 changes: 10 additions & 16 deletions .github/workflows/check_tutorials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version}}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
# Version range or exact version of a Python version to use, using SemVer's version range syntax.
python-version: ${{ matrix.python-version}}
Expand All @@ -50,37 +50,31 @@ jobs:
# Cache pip dependencies
# Source: https://github.com/actions/cache/blob/main/examples.md#python---pip
- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
id: cache
with:
# Cache the full python environment, this is more efficient than just caching pip
# https://blog.allenai.org/python-caching-in-github-actions-e9452698e98d
path: ${{ env.pythonLocation }}
# Hash both ordinary requirements and those specific for developmnet.
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
key: ${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}

- name: Install external libraries
run: |
# Various packages that must be installed
sudo apt-get install libglu1-mesa libgeos-dev libffi-dev
export LD_LIBRARY_PATH=/usr/local/lib64/:$LD_LIBRARY_PATH

- name: Install requirements
# Install the requirements, including the extras needed for testing, and PorePy
# itself.
- name: Install requirements and PorePy
run: |
pip install -U pip
# Install requirements, using eager updates to avoid stalled dependencies due to caching
# https://blog.allenai.org/python-caching-in-github-actions-e9452698e98d
pip install --upgrade --upgrade-strategy eager -r requirements.txt
pip install .[testing]
pip freeze

# Install jupyter - needed to run the tutorial notebooks.
- name: Install jupyter
run: |
pip install jupyter

- name: Install PorePy
run: |
pip install .
pip freeze

- name: Check tutorials
if: ${{always()}}
run: pytest tests -m tutorials
34 changes: 10 additions & 24 deletions .github/workflows/run-pytest-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4
IvarStefansson marked this conversation as resolved.
Show resolved Hide resolved

- name: Setup Python ${{ matrix.python-version}}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
# Version range or exact version of a Python version to use, using SemVer's version range syntax.
python-version: ${{ matrix.python-version}}
Expand All @@ -41,44 +41,30 @@ jobs:
# Cache pip dependencies
# Source: https://github.com/actions/cache/blob/main/examples.md#python---pip
- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
id: cache
with:
# Cache the full python environment, this is more efficient than just caching pip
# https://blog.allenai.org/python-caching-in-github-actions-e9452698e98d
path: ${{ env.pythonLocation }}
# Hash requirements.
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('**/requirements.txt') }}
key: ${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}

- name: Install external libraries
run: |
# Various packages that must be installed
sudo apt-get install libglu1-mesa libgeos-dev libffi-dev
export LD_LIBRARY_PATH=/usr/local/lib64/:$LD_LIBRARY_PATH

- name: Install requirements
# Install the requirements, including the extras needed for testing, and PorePy
# itself.
- name: Install requirements and PorePy
run: |
pip install -U pip
# Install requirements, using eager updates to avoid stalled dependencies due to caching
# https://blog.allenai.org/python-caching-in-github-actions-e9452698e98d
pip install --upgrade --upgrade-strategy eager -r requirements.txt
pip install .[testing]
pip freeze

- name: Install pypardiso
run: |
pip install pypardiso

- name: Install jupyter
run: |
pip install jupyter

- name: Install PorePy
run: |
pip install .
pip freeze

- name: all tests
if: ${{always()}}
run: pytest --run-skipped -m "not tutorials"



run: pytest --run-skipped -m "not tutorials"
25 changes: 9 additions & 16 deletions .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version}}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
# Version range or exact version of a Python version to use, using SemVer's version range syntax.
python-version: ${{ matrix.python-version}}
Expand All @@ -49,32 +49,25 @@ jobs:
# Cache pip dependencies
# Source: https://github.com/actions/cache/blob/main/examples.md#python---pip
- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
id: cache
with:
# Cache the full python environment, this is more efficient than just caching pip
# https://blog.allenai.org/python-caching-in-github-actions-e9452698e98d
path: ${{ env.pythonLocation }}
# Hash requirements.
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('**/requirements.txt') }}
key: ${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}

- name: Install external libraries
run: |
# Various packages that must be installed
sudo apt-get install libglu1-mesa libgeos-dev libffi-dev
export LD_LIBRARY_PATH=/usr/local/lib64/:$LD_LIBRARY_PATH

- name: Install requirements
# Install the requirements, including the extras needed for testing, and PorePy
# itself.
- name: Install requirements and PorePy
run: |
pip install -U pip
# Install requirements, using eager updates to avoid stalled dependencies due to caching
# https://blog.allenai.org/python-caching-in-github-actions-e9452698e98d
pip install --upgrade --upgrade-strategy eager -r requirements.txt

- name: Install PorePy
run: |
pip install .
pip freeze
pip install .[testing]
pip freeze

- name: Run tests
if: ${{always()}}
Expand Down
48 changes: 28 additions & 20 deletions .github/workflows/run-static-checks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Run static tests for code quality: Isort, black, flake8, mypy.
# Run static tests for code quality: Isort, ruff (formatting and linting), mypy.

name: Static tests

Expand Down Expand Up @@ -55,10 +55,10 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it.
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version}}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
# Version range or exact version of a Python version to use, using SemVer's version range syntax.
python-version: ${{ matrix.python-version}}
Expand All @@ -68,43 +68,51 @@ jobs:
# Cache pip dependencies
# Source: https://github.com/actions/cache/blob/main/examples.md#python---pip
- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
id: cache
with:
# Cache the full python environment, this is more efficient than just caching pip
# https://blog.allenai.org/python-caching-in-github-actions-e9452698e98d
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
key: ${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}

- name: Cache mypy
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-mypy
with:
path: mypy-cache-${{ matrix.python-version}}
key: ${{ runner.os }}-mypy

# Install the requirements. Mypy needs this to access stubs for numpy etc.
# Install the dependencies, which is needed to make mypy happy. Unravelling of the
# second command: The expression in the angular brackets is a python command that
# fetches the dependencies section in pyproject.toml; this is then made available to
# pip via -r. Option --no-bulid-isolation makes pip not use an isolated environment
# for the install (hence the installed packages are sure to be available also after
# the build), while --no-deps will only install the specified packages (in this
# case, the dependencies of PorePy). The third line similarly installs the
# development dependencies.
#
# Thanks, copilot!
- name: Install requirements
run: |
pip install -U pip
# Install requirements, using eager updates to avoid stalled dependencies due to caching
# https://blog.allenai.org/python-caching-in-github-actions-e9452698e98d
pip install --upgrade --upgrade-strategy eager -r requirements.txt
pip install toml
pip install --no-build-isolation --no-deps -r <(python -c "import toml; print('\n'.join(toml.load('pyproject.toml')['project']['dependencies']))")
pip install --no-build-isolation --no-deps -r <(python -c "import toml; print('\n'.join(toml.load('pyproject.toml')['project']['optional-dependencies']['development']))")
pip freeze

# Run black, isort, flake8, and mypy.
# Note that since these are static checks, we have not installed PorePy.
- name: black
# Run the various checks
- name: Ruff linting
if: ${{ always() }}
run: black --check src
run: ruff check src

- name: isort
- name: Ruff formatting
if: ${{always()}}
run: isort --check src
run: ruff format --check src

- name: flake8
# EK note to self: Ruff may introduce sorting of imports in the future, if so, we
# should use that instead of isort.
- name: isort
if: ${{ always() }}
run: flake8 src
run: isort src

- name: mypy
if: ${{ always() }}
Expand Down
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
![Pytest](https://github.com/pmgbergen/porepy/actions/workflows/run-pytest.yml/badge.svg)
![Pytest including slow](https://github.com/pmgbergen/porepy/actions/workflows/run-pytest-all.yml/badge.svg)
![Mypy, black, isort, flake8](https://github.com/pmgbergen/porepy/actions/workflows/run-static-checks.yml/badge.svg)
![Mypy, ruff, isort](https://github.com/pmgbergen/porepy/actions/workflows/run-static-checks.yml/badge.svg)
![Tutorials](https://github.com/pmgbergen/porepy/actions/workflows/check_tutorials.yml/badge.svg)
[![DOI](https://zenodo.org/badge/89228838.svg)](https://zenodo.org/badge/latestdoi/89228838)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

Expand Down
81 changes: 81 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

# Project information.
[project]
name = "porepy"
version = "1.10.0"
description = "Simulation tool for fractured and deformable porous media"
readme = "Readme.md"
license = { text = "GPL" }
keywords = ["porous media simulation fractures deformable"]
maintainers = [
{ name = "Eirik Keilegavlen", email = "Eirik.Keilegavlen@uib.no" },
{ name = "Ivar Stefansson", email = "Ivar.Stefansson@uib.no" },
{ name = "Jakub Both", email = "Jakub.Both@uib.no" }
]
urls = { "Homepage" = "https://github.com/pmgbergen/porepy" }
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent"
]
dependencies = [
"deepdiff",
"future",
"gmsh",
"matplotlib < 3.11",
"meshio",
"networkx",
"numba",
"numpy < 2.2",
"scipy",
"seaborn",
"shapely",
"six",
"sympy",
"typing_extensions",
]

[project.optional-dependencies]
development = [
"isort",
"ruff",
"mypy",
"mypy-extensions"
]
testing = [
"pytest >= 4.6",
"pytest-cov",
"pytest-runner"
]

# Information for the build system.
[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
"porepy" = [
"py.typed",
"applications/md_grids/gmsh_file_library/**/*.csv",
"applications/md_grids/gmsh_file_library/**/*.geo"
]

# Testing.
[tool.pytest.ini_options]
python_files = "tests/*.py"
addopts = "--cov=src/porepy --cov-report term-missing -p no:warnings"

# Static analysis.
[tool.ruff.lint]
ignore = [
"E731", # do not assign a lambda expression, use a def
"E266", # too many leading '#' for block comment
]
exclude = [
"src/porepy/__init__.py",
"src/porepy/numerics/ad/__init__.py",
"src/porepy/compositional/__init__.py"
]
22 changes: 0 additions & 22 deletions requirements.txt

This file was deleted.

Loading
Loading