Skip to content

Commit

Permalink
Merge pull request #1323 from pmgbergen/ruff
Browse files Browse the repository at this point in the history
Use Ruff formatting and linting. Install configuration moved to pyproject.toml
  • Loading branch information
keileg authored Feb 12, 2025
2 parents 2d74abe + 432c425 commit 0f77de0
Show file tree
Hide file tree
Showing 70 changed files with 309 additions and 333 deletions.
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

- 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 = "[email protected]" },
{ name = "Ivar Stefansson", email = "[email protected]" },
{ name = "Jakub Both", email = "[email protected]" }
]
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

0 comments on commit 0f77de0

Please sign in to comment.