Skip to content

Commit

Permalink
build(deps): first major release (#323)
Browse files Browse the repository at this point in the history
- Numpy was upgraded to allow v2.0.0.
- Do formatting and linting with ruff, rather than black, isort, flak8,
  etc.
- Make mypy and docstring linting pass.
  • Loading branch information
engeir authored Jun 17, 2024
1 parent 9d9298e commit 42eca94
Show file tree
Hide file tree
Showing 36 changed files with 787 additions and 916 deletions.
4 changes: 2 additions & 2 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[tools]
python = {version = "3.12", virtualenv = ".venv"}
[env.'_'.python]
venv = ".venv"
44 changes: 18 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,48 @@ repos:
stages: [commit]
entry: check-added-large-files
language: system
- id: isort
name: isort
- id: ruff_fmt
name: Ruff format
stages: [commit]
language: system
entry: poetry run isort src
entry: ruff format
types: [python]

- id: black
name: black
- id: ruff_check
name: Ruff check
stages: [commit]
language: system
entry: poetry run black src
entry: ruff check --fix
types: [python]

- id: flake8
name: flake8
- id: xdoctest
name: xdoctest
stages: [commit]
language: system
entry: poetry run flake8 src
entry: poetry run xdoctest
types: [python]
exclude: setup.py

- id: mypy
name: mypy
stages: [commit]
language: system
entry: poetry run mypy
types: [python]
require_serial: true

- id: darglint
name: darglint
- id: pydoclint
name: pydoclint
stages: [commit]
language: system
entry: poetry run darglint src
entry: poetry run pydoclint # src tests
types: [python]
require_serial: true

- id: pyupgrade
name: pyupgrade
stages: [commit]
language: system
entry: poetry run pyupgrade
types: [python]
require_serial: true

- id: pytest
name: pytest
stages: [commit]
language: system
entry: poetry run pytest tests
types: [python]
pass_filenames: false
- id: pydocstringformatter
name: pydocstringformatter
stages: [commit]
language: system
entry: rye run pydocstringformatter src tests
types: [python]
18 changes: 10 additions & 8 deletions examples/custom_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@
from itertools import cycle

import numpy as np

import volcano_cooking.modules.convert as convert
import volcano_cooking.modules.create as create
from volcano_cooking.modules import convert, create

# We first need to create a generator class. This inherits from Generate. Let us just
# create the regular intervals generator again.


class GenerateRegularIntervals2(create.Generate):
"""Create a custom generator class."""

def gen_dates_totalemission_vei(self) -> None:
"""Implement necessary methods."""
self.yoes, self.moes, self.does, self.tes = regular_intervals2()
self.veis = convert.totalemission_to_vei(self.tes)


def regular_intervals2():
def regular_intervals2() -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
"""Create dates with regular intervals.
This function creates dates with regular intervals and a pre-defined magnitude as
VEI.
Returns
-------
yoes: np.ndarray
yoes : np.ndarray
Array of length 'size' with the year of a date
moes: np.ndarray
moes : np.ndarray
Array of length 'size' with the month of a date
does: np.ndarray
does : np.ndarray
Array of length 'size' with the day of a date
veis: np.ndarray
veis : np.ndarray
Array of length 'size' with the VEI
"""
year_sep = 2
Expand All @@ -51,6 +52,7 @@ def regular_intervals2():


def create_synthetic_file() -> None:
"""Run example."""
# CREATE DATA -------------------------------------------------------------------- #
size, init_year = 100, 1850
g = GenerateRegularIntervals2(size, init_year)
Expand Down
656 changes: 286 additions & 370 deletions poetry.lock

Large diffs are not rendered by default.

143 changes: 137 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "volcano-cooking"
version = "0.12.2"
version = "1.0.0"
description = "Make some volcanoes and simulate them in CESM2"
authors = ["engeir <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down Expand Up @@ -29,18 +29,18 @@ xarray = ">=2023.12,<2025.0"

[tool.poetry.dev-dependencies]
coverage = "^7.5"
black = "^24.4"
isort = "^5.13.2"
flake8 = "^7.1.0"
pre-commit = "^3.7.1"
pre-commit-hooks = "^4.6.0"
pyupgrade = "^3.16.0"
darglint = "^1.8.0"
pytest = "^8.2.2"
pytest-cov = "^5.0.0"
mypy = "^1.10"
xdoctest = "^1.1.5"
Pygments = "^2.18.0"

[tool.poetry.group.dev.dependencies]
ruff = "^0.4.9"
pydoclint = "^0.4.1"
pydocstringformatter = "^0.7.3"

[tool.coverage.paths]
source = ["src", "*/site-packages"]
Expand All @@ -55,3 +55,134 @@ show_missing = true
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
files = ["src"]
ignore_missing_imports = true
allow_redefinition = false
check_untyped_defs = true
ignore_errors = false
implicit_reexport = false
local_partial_types = true
no_implicit_optional = true
strict_equality = true
strict_optional = true
warn_no_return = true
warn_redundant_casts = true
warn_unreachable = true
warn_unused_configs = true
warn_unused_ignores = true

[tool.ruff]
# Same as Black.
line-length = 88

# Files that were downloaded
extend-exclude = []

# Allow unused variables when underscore-prefixed.

# Assume Python 3.9
target-version = "py39"

[tool.ruff.lint]
per-file-ignores = {}
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
select = [ # https://docs.astral.sh/ruff/rules/
"B", # flake8-bugbear
"D", # pydocstyle
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"NPY201",
"PL", # pylint
"Q", # flake8-quotes
"UP", # pyupgrade
]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
# select = ["E4", "E7", "E9", "F"] # These are the default
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
ignore = [
# "COM812", # Since we don't select COM, this is already ignored
# "COM819", # Since we don't select COM, this is already ignored
"D206",
"D300",
"E111",
"E114",
"E117",
"E266",
"E501",
# "ISC001", # Since we don't select ISC, this is already ignored
# "ISC002", # Since we don't select ISC, this is already ignored
"PLR0913", # Sometimes we want a lot of function signatures (6 not enough)
"Q000",
"Q001",
"Q002",
"Q003",
# "W191", # Since we don't select W, this is already ignored
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

[tool.ruff.lint.pydocstyle]
convention = "numpy"
ignore-decorators = ["typing.overload"]

[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"

[tool.ruff.lint.flake8-import-conventions.aliases]
# Declare the default aliases.
"matplotlib.pyplot" = "plt"
numpy = "np"
scipy = "sp"
xarray = "xr"

[tool.ruff.lint.isort]
case-sensitive = true
known-local-folder = ["src", "de_verify"]

[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
line_length = 88
profile = "black"
combine_as_imports = true

[tool.pydocstringformatter]
write = true
strip-whitespaces = true
split-summary-body = false
numpydoc-section-hyphen-length = false
style = ["pep257", "numpydoc"]
24 changes: 0 additions & 24 deletions setup.cfg

This file was deleted.

13 changes: 7 additions & 6 deletions src/volcano_cooking/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import ssl
import subprocess
import sys
from typing import List, Optional
from typing import Optional

import click
import wget

import volcano_cooking.configurations.shift_eruption_to_date as shift_eruption_to_date
import volcano_cooking.synthetic_volcanoes as sv
from volcano_cooking import __version__
from volcano_cooking.configurations import shift_eruption_to_date


@click.command()
Expand Down Expand Up @@ -97,7 +97,7 @@
)
def main(
frc: int,
init_year: List[int],
init_year: list[int],
size: int,
lst: bool,
option: int,
Expand All @@ -106,6 +106,7 @@ def main(
package_last: bool,
file: Optional[str],
) -> None:
"""Volcano cooking."""
# First handle list, run ncl and package commands which overrides all other.
if lst:
for cl in sv.__GENERATORS__:
Expand Down Expand Up @@ -163,11 +164,11 @@ def get_forcing_file(
Parameters
----------
file: str
file : str
The filename the file to download will be saved as.
url: str, optional
url : Optional[str]
Provide the full url for where to download the file.
not_forcing: bool
not_forcing : bool
If some other file is downloaded, use generic text without file size warning.
"""
here = os.path.join(os.getcwd(), "data", "originals")
Expand Down
Loading

0 comments on commit 42eca94

Please sign in to comment.