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

dev: Migrate from flake8 to ruff #128

Merged
merged 4 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 4 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,13 @@ repos:
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.282
hooks:
- id: flake8
args: ["--max-line-length", "88", "--extend-ignore", "E203,E501,E722,W503"]
exclude: | # https://pre-commit.com/#regular-expressions
(?x)^(
src/initial_implementation/AlternativeFunctions.py|
src/pydrex/__init__.py
)$
- id: ruff

exclude: \.vtu$
exclude: \.*vtu$
19 changes: 18 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ dependencies = [
[project.optional-dependencies]
test = ["pytest", "matplotlib"]
doc = ["pdoc"]
dev = ["pytest", "matplotlib", "pdoc", "flake8", "black", "h5py", "isort", "ipython"]
dev = ["pytest", "matplotlib", "pdoc", "ruff", "black", "h5py", "isort", "ipython"]
lsp = ["python-lsp-server", "pyls-isort", "python-lsp-black", "python-lsp-ruff"]

[project.urls]
repository = "https://github.com/Patol75/PyDRex/"
Expand Down Expand Up @@ -72,3 +73,19 @@ testpaths = ["tests"]
# --show-capture=no : Don't show captured output (stdout/stderr/logs) for failed tests.
# --doctest-modules : Run doctest snippets in docstrings
addopts = "--tb=short --show-capture=no --doctest-modules"

# Global linter and devtools settings.
[tool.isort]
profile = "black"
filter_files = true
# Ruff is faster than flake8 and supports pyproject.toml config, line length is 88 by default.
[tool.ruff]
exclude = [
"src/initial_implementation",
".scsv",
".npz",
".vtu",
]
[tool.ruff.per-file-ignores]
"src/pydrex/__init__.py" = ["F401", "E501"] # Don't complain about unused imports or long lines in __init__.py file.
"tests/test_scsv.py" = ["E501"] # Don't complain about long lines here.
2 changes: 1 addition & 1 deletion src/pydrex/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def finite_strain(deformation_gradient, **kwargs):


def symmetry(orientations, axis="a"):
r"""Compute texture symmetry eigenvalue diagnostics from olivine orientation matrices.
r"""Compute texture symmetry eigenvalue diagnostics from grain orientation matrices.

Compute Point, Girdle and Random symmetry diagnostics
for ternary texture classification.
Expand Down
26 changes: 17 additions & 9 deletions src/pydrex/minerals.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"""Stiffness tensor for olivine (Voigt representation), with units of GPa.

The source of the values used here is unknown, but they are copied
from the original DRex code: <http://www.ipgp.fr/~kaminski/web_doudoud/DRex.tar.gz> [88K download]
from the original DRex code: <http://www.ipgp.fr/~kaminski/web_doudoud/DRex.tar.gz>
[88K download]

"""

Expand All @@ -45,7 +46,8 @@
"""Stiffness tensor for enstatite (Voigt representation), with units of GPa.

The source of the values used here is unknown, but they are copied
from the original DRex code: <http://www.ipgp.fr/~kaminski/web_doudoud/DRex.tar.gz> [88K download]
from the original DRex code: <http://www.ipgp.fr/~kaminski/web_doudoud/DRex.tar.gz>
[88K download]

"""

Expand Down Expand Up @@ -83,7 +85,8 @@ def voigt_averages(minerals, weights):
- `minerals` — list of `pydrex.minerals.Mineral` instances storing orientations and
fractional volumes of the grains within each distinct mineral phase
- `weights` (dict) — dictionary containing weights of each mineral
phase, as a fraction of 1, in keys named "<phase>_fraction", e.g. "olivine_fraction"
phase, as a fraction of 1, in keys named "<phase>_fraction",
e.g. "olivine_fraction"

Raises a ValueError if the minerals contain an unequal number of grains or stored
texture results.
Expand Down Expand Up @@ -176,7 +179,7 @@ class Mineral:
>>> regime=pydrex.DeformationRegime.dislocation,
>>> n_grains=2000,
>>> )
Mineral(phase=0, fabric=0, regime=1, n_grains=2000, fractions=<list of ndarray (2000,)>, orientations=<list of ndarray (2000, 3, 3)>)
Mineral(phase=0, fabric=0, regime=1, n_grains=2000, ...)

Mineral with specified initial texture and default phase, fabric and regime settings
which are for an olivine A-type mineral in the dislocation creep regime.
Expand All @@ -190,18 +193,22 @@ class Mineral:
>>> n_grains=n_grains,
>>> fractions_init=np.full(n_grains, 1 / n_grains),
>>> orientations_init=Rotation.from_euler(
>>> "zxz", [[x * np.pi / 2, np.pi / /2, np.pi / 2] for x in rng.random(n_grains)]
>>> "zxz", [
>>> [x * np.pi / 2, np.pi / /2, np.pi / 2] for x in rng.random(n_grains)
>>> ]
>>> ).inv().as_matrix(),
>>> )
Mineral(phase=0, fabric=0, regime=1, n_grains=2000, fractions=<list of ndarray (2000,)>, orientations=<list of ndarray (2000, 3, 3)>)
Mineral(phase=0, fabric=0, regime=1, n_grains=2000, ...)

**Attributes:**
- `phase` (`pydrex.core.MineralPhase`) — ordinal number of the mineral phase
- `fabric` (`pydrex.core.MineralFabric`) — ordinal number of the fabric type
- `regime` (`pydrex.core.DeformationRegime`) — ordinal number of the deformation regime
- `regime` (`pydrex.core.DeformationRegime`) — ordinal number of the deformation
regime
- `n_grains` (int) — number of grains in the aggregate
- `fractions` (list of arrays) — grain volume fractions for each texture snapshot
- `orientations` (list of arrays) — grain orientation matrices for each texture snapshot
- `orientations` (list of arrays) — grain orientation matrices for each texture
snapshot
- `seed` (`int`) — seed used by the random number generator to set up the isotropic
initial condition when `fractions_init` or `orientations_init` are not provided

Expand Down Expand Up @@ -241,7 +248,8 @@ def __str__(self):
+ f"fractions=<{self.fractions.__class__.__qualname__}"
+ f" of {self.fractions[0].__class__.__qualname__} {shape_of_fractions}>, "
+ f"orientations=<{self.orientations.__class__.__qualname__}"
+ f" of {self.orientations[0].__class__.__qualname__} {shape_of_orientations}>)"
+ f" of {self.orientations[0].__class__.__qualname__}"
+ f" {shape_of_orientations}>)"
)

def _repr_pretty_(self, p, cycle):
Expand Down
3 changes: 2 additions & 1 deletion src/pydrex/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def point_density(
- `gridsteps` (int) — the number of steps, i.e. number of points along a diameter of
the spherical counting grid
- `weights` (array) — auxiliary weights for each data point
- `kernel` (string) — the name of the kernel function to use, see `SPHERICAL_COUNTING_KERNELS`
- `kernel` (string) — the name of the kernel function to use, see
`SPHERICAL_COUNTING_KERNELS`
- `axial` (bool) — toggle axial versions of the kernel functions
(for crystallographic data this should normally be kept as `True`)

Expand Down