Skip to content

Commit

Permalink
enh: add python 3.12, cleanup (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-eschle committed Apr 15, 2024
1 parent f80a54a commit 7e2d1f9
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 88 deletions.
21 changes: 0 additions & 21 deletions .codeclimate.yml

This file was deleted.

3 changes: 1 addition & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions monthly
interval: "monthly"
interval: "quarterly"
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ jobs:
max-parallel: 8
fail-fast: False
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10" , "3.11" ]
python-version: [ "3.7", "3.8", "3.9", "3.10" , "3.11", "3.12" ]
include:
- os: macos-latest
python-version: "3.12"
- os: windows-latest
python-version: "3.12"
- os: macos-14 # Apple silicon runner
python-version: '3.12'
name: tests on ubuntu with ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
Expand Down
33 changes: 19 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -18,52 +18,57 @@ repos:


- repo: https://github.com/myint/docformatter
rev: v1.5.0
rev: v1.7.5
hooks:
- id: docformatter
args: [ -r, --in-place, --wrap-descriptions, '120', --wrap-summaries, '120', -- ]

- repo: https://github.com/mattlqx/pre-commit-sign
rev: v1.1.3
rev: v1.2.0
hooks:
- id: sign-commit
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0 # Use the ref you want to point at
rev: v1.10.0 # Use the ref you want to point at
hooks:
- id: python-use-type-annotations
- id: python-check-mock-methods
- id: rst-directive-colons


- repo: https://github.com/asottile/pyupgrade
rev: v3.2.3
rev: v3.15.2
hooks:
- id: pyupgrade
args: [ --py36-plus ]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.2.0
rev: v2.5.0
hooks:
- id: setup-cfg-fmt

# Notebook formatting
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.5.3
rev: 1.8.5
hooks:
- id: nbqa-isort
additional_dependencies: [ isort==5.6.4 ]
additional_dependencies: [ isort ]

- id: nbqa-pyupgrade
additional_dependencies: [ pyupgrade==2.7.4 ]
args: [ --py37-plus ]
additional_dependencies: [ pyupgrade ]
args: [ --py36-plus ]

- repo: https://github.com/mgedmin/check-manifest
rev: '0.48'
rev: '0.49'
hooks:
- id: check-manifest
stages: [ manual ]

- repo: https://github.com/ambv/black
rev: 22.10.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.3.7"
hooks:
- id: black
- id: ruff
types_or: [ python, pyi, jupyter ]
args: [ --fix, --unsafe-fixes, --show-fixes , --line-length=120]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi, jupyter ]
33 changes: 0 additions & 33 deletions .scrutinizer.yml

This file was deleted.

15 changes: 8 additions & 7 deletions docs/api/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
#
# yamlloader documentation build configuration file, created by
# sphinx-quickstart on Wed Dec 13 13:46:00 2017.
Expand All @@ -16,10 +15,12 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath("../.."))
sys.path.insert(0, Path("../..").resolve())


# -- General configuration ------------------------------------------------
Expand All @@ -29,16 +30,16 @@
# needs_sphinx = '1.0'

# Manually added things
import os

import sphinx_rtd_theme

import yamlloader

here = os.path.abspath(os.path.dirname(__file__))
here = Path(__file__).resolve().parent

autoclass_content = "both" # document modules and packages

# Sphinx theme
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"

Expand All @@ -59,7 +60,7 @@
"sphinx.ext.githubpages",
]

html_logo = os.path.join(here, "static/img/phynix_logo_medium.png")
html_logo = here / "static/img/phynix_logo_medium.png"

# Napoleon settings (convert numpy/google docstrings to proper ReST
napoleon_google_docstring = False
Expand Down
9 changes: 5 additions & 4 deletions docs/api/tools/change_headline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

import argparse
from pathlib import Path

parser = argparse.ArgumentParser(description="replace first two line")

Expand All @@ -7,15 +10,13 @@

n_files = 0
for rest_file in parsed_args.files:
with open(rest_file) as f:
with Path(rest_file).open() as f:
first_word = f.readline().strip().split()[0]
if "." not in first_word:
continue
replacement = first_word.split(".")[-1]
underline = f.readline()[0] * len(replacement)
lower_file = f.read()
with open(rest_file, "w") as f:
with Path(rest_file).open("w") as f:
f.write("\n".join((replacement, underline, lower_file)))
n_files += 1

print(f"finished successfully parsing {n_files} files")
54 changes: 54 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,57 @@ requires = [
]

build-backend = "setuptools.build_meta"

[tool.ruff]
#src = ["src"]
line-length = 120
exclude = [
".tox/*",
"*/test*",
"*/__init__.py",
"*/_version.py",
]
[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"NPY", # NumPy specific rules
"PD", # pandas-vet
]
ignore = [
"UP007", # type annotation upgrade, breaks pydantic for Python 3.9 (remove once above)
"PLR09", # Too many <...>
"PLR2004", # Magic value used in comparison
"ISC001", # Conflicts with formatter
"RET505", # This is sometimes wanted, protets against accidental intendation
"PD901", # "avoid using `df[...].values`" -> no, this is a very good name if there is only one df
"PD011", # "replace `df[...].values` with `df[...].to_numpy()`" -> not yet, it's not deprecated.
# Prefer to have a single way to access the data if we don't care about whether it's a numpy array or not.
"PLW0603", # updating global variables with a function is bad, but we use it for
"PLW2901", # "for loop overwritten by assignment" -> we use this to update the loop variable
"PD013", # "melt over stack": df function, but triggers on tensors
"NPY002", # "Use rnd generator in numpy" -> we use np.random for some legacy stuff but do use the new one where we can

]
isort.required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.per-file-ignores]
"tests/**" = ["T20"]
"noxfile.py" = ["T20"]
12 changes: 8 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import os
from __future__ import annotations

from pathlib import Path

from setuptools import setup

here = os.path.abspath(os.path.dirname(__file__))
here = Path(__file__).resolve().parent

with open(os.path.join(here, "requirements.txt")) as f:
with (here / "requirements.txt").open() as f:
requirements = f.read().split("\n")


def long_description():
"""Load README.rst."""
with open("README.rst", encoding="utf-8") as f:
with Path("README.rst").open(encoding="utf-8") as f:
return f.read()


Expand Down Expand Up @@ -41,6 +43,8 @@ def long_description():
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries",
"Topic :: Utilities",
],
packages=["yamlloader", "yamlloader.ordereddict"],
Expand Down
2 changes: 2 additions & 0 deletions yamlloader/ordereddict/dumpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Dumpers for `:py:class:~collections.OrderedDict`."""

from __future__ import annotations

from collections import OrderedDict

import yaml
Expand Down
7 changes: 5 additions & 2 deletions yamlloader/ordereddict/loaders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Loaders for `:py:class:~collections.OrderedDict`."""

from __future__ import annotations

from collections import OrderedDict

import yaml
Expand Down Expand Up @@ -30,12 +32,13 @@ def construct_mapping(self, node, deep=False):
try:
hash(key)
except TypeError as err:
msg = "while constructing a mapping"
raise yaml.constructor.ConstructorError(
"while constructing a mapping",
msg,
node.start_mark,
f"found unacceptable key ({err})",
key_node.start_mark,
)
) from err
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
Expand Down
2 changes: 2 additions & 0 deletions yamlloader/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Global settings for the behavior of the module."""

from __future__ import annotations

ALLOW_NON_C_FALLBACK = True

0 comments on commit 7e2d1f9

Please sign in to comment.