diff --git a/.copier-answers.yml b/.copier-answers.yml index 0fabdb3..57a5383 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,8 +1,8 @@ -# Changes here will be overwritten by Copier -_commit: v0.3.0 +# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY +_commit: v0.5.2 _src_path: gl:climate-resource/copier-core-python-repository email: zebedee.nicholls@climate-energy-college.org -initial_setup: false +initial_setup: true name: Zebedee Nicholls notebook_dependencies: false pandas_doctests: false diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md new file mode 100644 index 0000000..d43f709 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -0,0 +1,41 @@ +--- +name: Bug report +about: Report a bug +title: '' +labels: bug +assignees: '' + +--- + +## Describe the bug + + +## Failing Test + + +## Expected behavior + + +## Screenshots + + +## System + + + - OS: [e.g. Windows, Linux, macOS] + - Python version [e.g. Python 3.11] + - Please also upload your `poetry.lock` file (first run `poetry lock` to make sure the lock file is up-to-date) + +## Additional context + diff --git a/.github/ISSUE_TEMPLATE/default.md b/.github/ISSUE_TEMPLATE/default.md new file mode 100644 index 0000000..8b7025e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/default.md @@ -0,0 +1,21 @@ +--- +name: Default +about: Report an issue or problem +title: '' +labels: triage +assignees: '' + +--- + +## The problem + + +## Definition of "done" + + +## Additional context + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 0fb696b..f297ebb 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,21 +1,32 @@ --- name: Feature Request -about: Suggest an idea for this project +about: Request a feature or suggest an idea for this project +title: '' +labels: feature +assignees: '' --- -**Is your feature request related to a problem? Please describe.** +## The motivation -A clear and concise description of what the problem is. Ex. It's annoying that I always have to [...] + -**Describe the solution you'd like** +## The proposed solution -A clear and concise description of the solution you would like to see. + -A clear and concise description of any alternative solutions or features you've considered. +## Alternatives -**Additional context** + + +## Additional context + + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 91d92f8..7ff7065 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,8 +1,9 @@ -# Pull request +## Description + +## Checklist Please confirm that this pull request has done the following: - [ ] Tests added - [ ] Documentation added (where applicable) -- [ ] Example added (either to an existing notebook or as a new notebook, where applicable) -- [ ] Added to `changelog/` +- [ ] Changelog item added to `changelog/` diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 622953d..376b67b 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -2,6 +2,10 @@ name: "Setup Python and Poetry" description: "setup Python and Poetry with caches" inputs: + os: + description: "Operating system to use" + required: false + default: "ubuntu-latest" python-version: description: "Python version to use" required: true @@ -20,38 +24,42 @@ inputs: runs: using: "composite" steps: + - name: Install poetry + shell: bash + run: | + pipx install poetry + which poetry + poetry --version # Check poetry installation + - name: Lock poetry # lock file is needed for the next step, but we don't track our lock file + shell: bash + run: poetry lock - name: Set up Python ${{ inputs.python-version }} id: setup-python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ inputs.python-version }} - - name: Load cached Poetry installation - id: cached-poetry - uses: actions/cache@v3 - with: - path: ~/.local # the path depends on the OS - key: poetry-2 # increment to reset cache - - name: Install Poetry - if: steps.cached-poetry.outputs.cache-hit != 'true' - uses: snok/install-poetry@v1 - - name: Load cached venv - if: ${{ inputs.run-poetry-install == 'true' }} - id: cached-poetry-dependencies - uses: actions/cache@v3 - with: - path: .venv - key: "venv-${{ inputs.venv-id }}-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }}" - # Install dependencies first so that our package doesn't appear in the cache by accident - - name: Install dependencies - if: ${{ inputs.run-poetry-install == 'true' }} + cache: poetry + - name: Set Poetry environment shell: bash run: | + # This line used to be needed, but seems to have been + # sorted with newer poetry versions. We can still check whether + # the right version of python is used by looking at the output of + # `poetry run which python` below and whether the right version + # of python is used in the tests (or whatever step is being done) + # poetry env use "python${{ inputs.python-version }}" poetry config virtualenvs.create true poetry config virtualenvs.in-project true - poetry env use ${{ inputs.python-version }} + - name: Install dependencies + if: ${{ (inputs.run-poetry-install == 'true') && (steps.setup-python.outputs.cache-hit != 'true') }} + shell: bash + run: | poetry install --no-interaction --no-root ${{ inputs.poetry-dependency-install-flags }} # Now run same command but let the package install too - name: Install package + # To ensure that the package is always installed, this step is run even if the cache was hit if: ${{ inputs.run-poetry-install == 'true' }} shell: bash - run: poetry install --no-interaction ${{ inputs.poetry-dependency-install-flags }} + run: | + poetry install --no-interaction ${{ inputs.poetry-dependency-install-flags }} + poetry run python --version # Check python version just in case diff --git a/.github/workflows/bump.yaml b/.github/workflows/bump.yaml index 83da53f..5ebbd00 100644 --- a/.github/workflows/bump.yaml +++ b/.github/workflows/bump.yaml @@ -47,14 +47,21 @@ jobs: - name: Create bump and changelog run: | - BASE_VERSION=`poetry version -s` - NEW_VERSION=`poetry version -s ${{ github.event.inputs.bump_rule }}` - poetry run towncrier build --yes --version v$NEW_VERSION - git config --global user.name "$GITHUB_ACTOR" git config --global user.email "$CI_COMMIT_EMAIL" + # Bump + BASE_VERSION=`poetry version -s` + NEW_VERSION=`poetry version -s ${{ github.event.inputs.bump_rule }}` + echo "Bumping version $BASE_VERSION > $NEW_VERSION" + poetry run towncrier build --yes --version v$NEW_VERSION git commit -a -m "bump: version $BASE_VERSION -> $NEW_VERSION" git tag v$NEW_VERSION + + # Bump to alpha (so that future commits do not have the same + # version as the tagged commit) + BASE_VERSION=`poetry version -s` + NEW_VERSION=`poetry version -s prerelease` + echo "Bumping version $BASE_VERSION > $NEW_VERSION" + git commit -a -m "bump(pre-release): version $BASE_VERSION > $NEW_VERSION" git push && git push --tags - echo "Bumped to version $NEW_VERSION" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 41b55a4..04465b6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,6 +15,7 @@ jobs: uses: actions/checkout@v3 - uses: ./.github/actions/setup with: + os: "ubuntu-latest" python-version: "3.9" venv-id: "docs" poetry-dependency-install-flags: "--all-extras --only 'main,dev'" @@ -29,6 +30,7 @@ jobs: uses: actions/checkout@v3 - uses: ./.github/actions/setup with: + os: "ubuntu-latest" python-version: "3.9" venv-id: "docs" poetry-dependency-install-flags: "--all-extras --only 'main,docs'" @@ -48,11 +50,18 @@ jobs: os: [ "ubuntu-latest" ] python-version: [ "3.9", "3.10", "3.11" ] runs-on: "${{ matrix.os }}" + defaults: + run: + # This might be needed for Windows and doesn't seem to affect unix-based systems + # so we include it. If you have better proof of whether this is needed or not, + # feel free to update. + shell: bash steps: - name: Check out repository uses: actions/checkout@v3 - uses: ./.github/actions/setup with: + os: "${{ matrix.os }}" python-version: "${{ matrix.python-version }}" venv-id: "tests-${{ runner.os }}" poetry-dependency-install-flags: "--all-extras" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 22bd9a2..530a9b6 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -39,9 +39,8 @@ jobs: uses: softprops/action-gh-release@v1 with: body_path: ".github/release_template.md" + token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" draft: true files: | dist/openscm_units-${{ env.PROJECT_VERSION }}-py3-none-any.whl dist/openscm_units-${{ env.PROJECT_VERSION }}.tar.gz - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/test-conda-install.yml b/.github/workflows/test-conda-install.yml index de69ae0..3469f5c 100644 --- a/.github/workflows/test-conda-install.yml +++ b/.github/workflows/test-conda-install.yml @@ -32,4 +32,4 @@ jobs: shell: bash -l {0} run: | which python - python scripts/test_install.py + python scripts/test-install.py diff --git a/.github/workflows/test-pypi-install.yml b/.github/workflows/test-pypi-install.yml index eea6b07..c963cb8 100644 --- a/.github/workflows/test-pypi-install.yml +++ b/.github/workflows/test-pypi-install.yml @@ -26,4 +26,4 @@ jobs: uses: actions/checkout@v2 - name: Test installation run: | - python scripts/test_install.py + python scripts/test-install.py diff --git a/.gitignore b/.gitignore index dbaaa52..fcd2a9a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ # Jupyter cache .jupyter_cache +# Ruff cache +.ruff_cache + # Licence check licence-check.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e583913..2e3e88b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ ci: # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 'v4.4.0' + rev: 'v4.5.0' hooks: - id: check-added-large-files - id: check-ast @@ -31,20 +31,12 @@ repos: language: fail files: "\\.rej$" - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.263' + rev: 'v0.1.8' hooks: - id: ruff args: [ --fix, --exit-non-zero-on-fix ] - - repo: https://github.com/psf/black - rev: '23.3.0' - hooks: - - id: black - # additional to the above, apply black to doctests in source code - - repo: https://github.com/keewis/blackdoc - rev: v0.3.8 - hooks: - - id: blackdoc + - id: ruff-format - repo: https://github.com/python-poetry/poetry - rev: '1.4.2' + rev: '1.7.0' hooks: - id: poetry-check diff --git a/Makefile b/Makefile index 81d7dea..b8011be 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ endef export PRINT_HELP_PYSCRIPT +.PHONY: help help: ## print short description of each target @python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) @@ -27,14 +28,13 @@ checks: ## run all the linting checks of the codebase echo "=== mypy ==="; MYPYPATH=stubs poetry run mypy src || echo "--- mypy failed ---" >&2; \ echo "======" -.PHONY: black -black: ## format the code using black - poetry run black src tests docs/source/conf.py scripts docs/source/notebooks/*.py - poetry run blackdoc src - .PHONY: ruff-fixes ruff-fixes: ## fix the code using ruff + # format before and after checking so that the formatted stuff is checked and + # the fixed stuff is formatted + poetry run ruff format src tests scripts docs/source/conf.py docs/source/notebooks/*.py poetry run ruff src tests scripts docs/source/conf.py docs/source/notebooks/*.py --fix + poetry run ruff format src tests scripts docs/source/conf.py docs/source/notebooks/*.py .PHONY: test diff --git a/changelog/49.trivial.md b/changelog/49.trivial.md new file mode 100644 index 0000000..5ed5c18 --- /dev/null +++ b/changelog/49.trivial.md @@ -0,0 +1 @@ +Updated to newer copier template version diff --git a/docs/source/conf.py b/docs/source/conf.py index 3d4ccef..0c06e6e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -144,8 +144,16 @@ def _generate_module_rst_new(*args, **kwargs): # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output # Pick your theme for html output, we typically use the read the docs theme -html_theme = "sphinx_rtd_theme" +html_theme = "sphinx_book_theme" html_static_path = ["_static"] +html_theme_options = { + "repository_url": "https://github.com/openscm/openscm-units", + "repository_branch": "main", + "path_to_docs": "docs/source", + "use_repository_button": True, + "use_issues_button": True, + "use_edit_page_button": True, +} # Ignore ipynb files when building (see https://github.com/executablebooks/MyST-NB/issues/363). diff --git a/docs/source/development.md b/docs/source/development.md index b8ddae0..4493945 100644 --- a/docs/source/development.md +++ b/docs/source/development.md @@ -2,6 +2,34 @@ # Development Notes for developers. If you want to get involved, please do! +We welcome all kinds of contributions, for example: + +- docs fixes/clarifications +- bug reports +- bug fixes +- feature requests +- pull requests +- tutorials + +## Workflows + + + +We don't mind whether you use a branching or forking workflow. +However, please only push to your own branches, +pushing to other people's branches is often a recipe for disaster, +is never required in our experience +so is best avoided. + +Try and keep your merge requests as small as possible +(focus on one thing if you can). +This makes life much easier for reviewers +which allows contributions to be accepted at a faster rate. ## Language @@ -28,13 +56,13 @@ The steps required are the following: 1. Bump the version: manually trigger the "bump" workflow from the main branch - (see here: https://github.com/openscm/openscm-units/actions/workflows/bump.yaml). - A valid "bump_rule" (see https://python-poetry.org/docs/cli/#version) will need to be specified. + (see here: [bump workflow](https://github.com/openscm/openscm-units/actions/workflows/bump.yaml)). + A valid "bump_rule" (see [poetry's docs](https://python-poetry.org/docs/cli/#version)) will need to be specified. This will then trigger a draft release. 1. Edit the draft release which has been created (see here: - https://github.com/openscm/openscm-units/releases). + [project releases](https://github.com/openscm/openscm-units/releases)). Once you are happy with the release (removed placeholders, added key announcements etc.) then hit 'Publish release'. This triggers a release to PyPI (which you can then add to the release if you want). diff --git a/docs/source/notebooks.md b/docs/source/notebooks.md index af3df83..34388eb 100644 --- a/docs/source/notebooks.md +++ b/docs/source/notebooks.md @@ -1,8 +1,8 @@ (notebooks-reference)= # Notebooks -Here we provide further documentation related to OpenSCM-Units. -The docs are derived from +Here we provide various examples of how to use OpenSCM-Units. +They are derived from [jupyter notebooks](https://docs.jupyter.org/en/latest/start/index.html), but are saved using [jupytext](https://jupytext.readthedocs.io/en/latest/) to keep our repository slim and make it easier to track changes. @@ -13,15 +13,6 @@ to keep our repository slim and make it easier to track changes. :caption: Contents :maxdepth: 1 notebooks/basic-demo.py -notebooks/custom-conversions.py -``` - -## For developers - -```{toctree} -:caption: Contents -:maxdepth: 1 -notebooks/design-principles.py ``` ## Notebook execution info diff --git a/docs/source/notebooks/basic-demo.py b/docs/source/notebooks/basic-demo.py index e60c763..d9c9653 100644 --- a/docs/source/notebooks/basic-demo.py +++ b/docs/source/notebooks/basic-demo.py @@ -5,7 +5,7 @@ # extension: .py # format_name: percent # format_version: '1.3' -# jupytext_version: 1.15.2 +# jupytext_version: 1.14.5 # kernelspec: # display_name: Python 3 (ipykernel) # language: python @@ -13,123 +13,12 @@ # --- # %% [markdown] -# # Introduction +# # Basic demo # -# Here we give a brief introduction to `openscm_units`. - -# %% [markdown] -# ## The unit registry -# -# ``openscm_units.unit_registry`` extends Pint's default unit registry by -# adding simple climate modelling related units. We'll spare the details here -# (they can be found in -# [our documentation](https://openscm-units.readthedocs.io/en/latest/unit_registry.html)), -# but the short idea is that you can now do all sorts of simple climate -# modelling related conversions which were previously impossible. +# This notebook gives a basic demonstration of how to use OpenSCM-Units. # %% -import traceback - -import pandas as pd -import seaborn as sns -from pint.errors import DimensionalityError - import openscm_units -from openscm_units import unit_registry # %% print(f"You are using openscm_units version {openscm_units.__version__}") - -# %% [markdown] -# ## Basics -# -# ``openscm_units.unit_registry`` knows about basic units, e.g. 'CO2'. - -# %% -unit_registry("CO2") - -# %% [markdown] -# Standard conversions are now trivial. - -# %% -unit_registry("CO2").to("C") - -# %% -emissions_aus = 0.34 * unit_registry("Gt C / yr") -emissions_aus.to("Mt CO2/yr") - -# %% [markdown] -# ## Contexts -# -# In general, we cannot simply convert e.g. CO$_2$ emissions into CH$_4$ emissions. - -# %% -try: - unit_registry("CH4").to("CO2") -except DimensionalityError: - traceback.print_exc(limit=0, chain=False) - -# %% [markdown] -# However, a number of metrics exist which do allow conversions between GHG -# species. Pint plus OpenSCM's inbuilt metric conversions allow you to perform -# such conversions trivially by specifying the `context` keyword. - -# %% -with unit_registry.context("AR4GWP100"): - ch4_ar4gwp100_co2e = unit_registry("CH4").to("CO2") - -ch4_ar4gwp100_co2e - -# %% [markdown] -# ## Gas mixtures -# -# Some gases (mainly, refrigerants) are actually mixtures of other gases, for -# example HFC407a (aka R-407A). In general, they can be used like any other -# gas. Additionally, `openscm_units` provides the ability to split these gases -# into their constituents. - -# %% -emissions = 20 * unit_registry("kt HFC407a / year") - -with unit_registry.context("AR4GWP100"): - print(emissions.to("Gg CO2 / year")) - -# %% -unit_registry.split_gas_mixture(emissions) - -# %% [markdown] -# ## Building up complexity -# -# `openscm_units` is meant to be a simple repository which does one thing, but -# does it well. We encourage you to use it wherever you like (and if you do -# please let us know via the -# [issue tracker](https://github.com/openscm/openscm-units/issues)). -# As an example of something we can do, we can quickly see how GWP100 has -# changed between assessment reports. - -# %% pycharm={"name": "#%%\n"} -units_of_interest = ["CO2", "CH4", "N2O", "HFC32", "CFC11"] -metrics_of_interest = ["SARGWP100", "AR4GWP100", "AR5GWP100"] -data = { - "unit": [], - "metric": [], - "value": [], -} -for metric in metrics_of_interest: - with unit_registry.context(metric): - for unit in units_of_interest: - data["unit"].append(unit) - data["metric"].append(metric) - data["value"].append(unit_registry(unit).to("CO2").magnitude) - -data = pd.DataFrame(data) - -sns.catplot( - data=data, - x="metric", - y="value", - kind="bar", - col="unit", - col_wrap=5, - sharey=False, -) diff --git a/docs/source/notebooks/custom-conversions.py b/docs/source/notebooks/custom-conversions.py index bae4790..628285f 100644 --- a/docs/source/notebooks/custom-conversions.py +++ b/docs/source/notebooks/custom-conversions.py @@ -48,7 +48,8 @@ metric_conversions_custom # %% [markdown] -# With such a `pd.DataFrame`, we can use custom conversions in our unit registry as shown. +# With such a `pd.DataFrame`, +# we can use custom conversions in our unit registry as shown. # %% # initialise the unit registry with custom conversions @@ -64,5 +65,6 @@ for context in ["Custom1", "Custom2"]: with unit_registry.context(context): print( - f"{nitrous_oxide} in CO2-equivalent in context {context} is {nitrous_oxide.to('tCO2 / yr')}" + f"{nitrous_oxide} in CO2-equivalent in context {context} " + "is {nitrous_oxide.to('tCO2 / yr')}" ) diff --git a/docs/source/notebooks/design-principles.py b/docs/source/notebooks/design-principles.py index ba66ed0..2a529bd 100644 --- a/docs/source/notebooks/design-principles.py +++ b/docs/source/notebooks/design-principles.py @@ -51,13 +51,14 @@ # # Emissions are a flux composed of three parts: mass, the species being emitted and the # time period e.g. "t CO2 / yr". As mass and time are part of SI units, all we need to -# define in OpenSCM-Units are emissions units i.e. the stuff. Here we include as many of the canonical -# emissions units, and their conversions, as possible. +# define in OpenSCM-Units are emissions units i.e. the stuff. +# Here we include as many of the canonical emissions units, +# and their conversions, as possible. # # For emissions units, there are a few cases to be considered: # -# - fairly obvious ones e.g. carbon dioxide emissions can be provided in 'C' or 'CO2' and -# converting between the two is possible +# - fairly obvious ones e.g. carbon dioxide emissions can be provided in 'C' or 'CO2' +# and converting between the two is possible # - less obvious ones e.g. NOx emissions can be provided in 'N' or 'NOx', we provide # conversions between these two which can be enabled if needed (see below). # - case-sensitivity. In order to provide a simplified interface, using all uppercase @@ -66,18 +67,19 @@ # - hyphens and underscores in units. In order to be Pint compatible and to simplify # things, we strip all hyphens and underscores from units. # -# As a convenience, we allow users to combine the mass and the type of emissions to make a -# 'joint unit' e.g. "tCO2". It should be recognised that this joint unit is a derived -# unit and not a base unit. +# As a convenience, we allow users to combine the mass and the type of emissions to make +# a 'joint unit' e.g. "tCO2". +# It should be recognised that this joint unit is a derived unit and not a base unit. # -# By defining these three separate components, it is much easier to track what conversions -# are valid and which are not. For example, as the emissions units are all defined as +# By defining these three separate components, +# it is much easier to track what conversions are valid and which are not. +# For example, as the emissions units are all defined as # emissions units, and not as atomic masses, we are able to prevent invalid conversions. # If emissions units were simply atomic masses, it would be possible to convert between # e.g. C and N2O which would be a problem. Conventions such as allowing carbon dioxide # emissions to be reported in C or CO2, despite the fact that they are fundamentally -# different chemical species, is a convention which is particular to emissions (as far as -# we can tell). +# different chemical species, is a convention which is particular to emissions +# (as far as we can tell). # # Pint's contexts are particularly useful for emissions as they facilitate # metric conversions. With a context, a conversion which wouldn't normally be allowed @@ -164,8 +166,9 @@ # ### NH$_3$ # # In order to prevent inadvertent conversions from 'NH3' to 'CO2', the conversion -# 'NH3' <--> 'N' is by default forbidden. It can be performed within the 'NH3_conversions' -# context analogous to the 'NOx_conversions' context: +# 'NH3' <--> 'N' is by default forbidden. +# It can be performed within the 'NH3_conversions' context, +# analogous to the 'NOx_conversions' context: # %% try: diff --git a/pyproject.toml b/pyproject.toml index 352b167..aa24b0e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ pytest = "^7.3.1" [tool.poetry.group.docs.dependencies] myst-nb = "^0.17.0" -sphinx-rtd-theme = "^1.2.0" +sphinx-book-theme = "^1.1.0" sphinx-autodoc-typehints = "^1.23.0" sphinx-autodocgen = "^1.3" jupytext = "^1.14.5" @@ -38,10 +38,8 @@ sphinx-copybutton = "^0.5.2" [tool.poetry.group.dev.dependencies] pytest-cov = "^4.0.0" coverage = "^7.2.0" -black = "23.3.0" -blackdoc = "0.3.8" mypy = "^1.2.0" -ruff = "0.0.264" +ruff = "^0.1.8" pre-commit = "^3.3.1" towncrier = "^23.6.0" liccheck = "^0.9.1" @@ -111,8 +109,10 @@ ignore = [ "D200", # One-line docstring should fit on one line with quotes "D400", # First line should end with a period ] -# Provide some leeway for long docstring, this is otherwise handled by black -line-length = 110 +line-length = 88 + +[tool.ruff.format] +docstring-code-format = true [tool.ruff.per-file-ignores] "test*.py" = [ diff --git a/src/openscm_units/_unit_registry.py b/src/openscm_units/_unit_registry.py index 1a6b820..1b9ef51 100644 --- a/src/openscm_units/_unit_registry.py +++ b/src/openscm_units/_unit_registry.py @@ -269,8 +269,8 @@ def _add_mass_emissions_joint_version(self, symbol: str) -> None: symbol The unit to add a joint version for """ - self.define("g{symbol} = g * {symbol}".format(symbol=symbol)) - self.define("t{symbol} = t * {symbol}".format(symbol=symbol)) + self.define(f"g{symbol} = g * {symbol}") + self.define(f"t{symbol} = t * {symbol}") def _add_gases(self, gases: dict[str, str | list[str]]) -> None: for symbol, value in gases.items(): @@ -495,13 +495,14 @@ def split_gas_mixture( if not mixture_dimensions: raise ValueError("Dimensions don't contain a gas mixture.") # noqa: TRY003 if len(mixture_dimensions) > 1: - raise NotImplementedError( # noqa: TRY003 + raise NotImplementedError( "More than one gas mixture in dimensions is not supported." ) mixture_dimension = mixture_dimensions[0] if quantity.dimensionality[mixture_dimension] != 1: - raise NotImplementedError( # noqa: TRY003 - f"Mixture has dimensionality {quantity.dimensionality[mixture_dimension]}" + raise NotImplementedError( + "Mixture has dimensionality " + f"{quantity.dimensionality[mixture_dimension]}" " != 1, which is not supported." )