Skip to content

Commit

Permalink
Update to Python 3.13 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 authored Oct 15, 2024
1 parent 50b335e commit 1c46b7c
Show file tree
Hide file tree
Showing 20 changed files with 203 additions and 134 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: pre-commit/[email protected].0
python-version: '3.12'
- uses: pre-commit/[email protected].1
4 changes: 2 additions & 2 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
- uses: actions/checkout@v4
with:
ref: main
- name: Set up Python 3.10
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'

- name: Install setuptools
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: pre-commit/[email protected].0
python-version: '3.12'
- uses: pre-commit/[email protected].1

test:
needs: pre-commit
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v4
Expand Down
23 changes: 21 additions & 2 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.5.0
rev: v5.0.0
hooks:
- id: check-ast
- id: check-builtin-literals
Expand All @@ -13,9 +13,28 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11 # check that this version matches the requirements.txt
rev: v0.6.9
hooks:
- id: ruff
name: ruff unused imports
# F401 [*] {name} imported but unused
args: [ "--select", "F401", "--extend-exclude", "__init__.py", "--fix"]

- id: ruff
# I001 [*] Import block is un-sorted or un-formatted
# UP035 [*] Import from {target} instead: {names}
# Q000 [*] Double quote found but single quotes preferred
# Q001 [*] Double quote multiline found but single quotes preferred
args: [ "--select", "I001,UP035,Q000,Q001", "--fix"]


- repo: https://github.com/JelleZijlstra/autotyping
rev: 24.9.0
hooks:
- id: autotyping
types: [python]
args: [--safe]


- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
Expand Down
133 changes: 72 additions & 61 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,85 +1,96 @@

line-length = 120
indent-width = 4
line-length = 120

target-version = "py38"
src = ["src", "test"]

# https://docs.astral.sh/ruff/settings/#ignore-init-module-imports
ignore-init-module-imports = true

extend-exclude = ["__init__.py"]

select = [
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"I", # https://docs.astral.sh/ruff/rules/#isort-i
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up

"A", # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
"ASYNC", # https://docs.astral.sh/ruff/rules/#flake8-async-async
"C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
"FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix
"INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp
"ISC", # https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc
"PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
"RET", # https://docs.astral.sh/ruff/rules/#flake8-return-ret
"SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
"SLOT", # https://docs.astral.sh/ruff/rules/#flake8-slots-slot
"T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
"TCH", # https://docs.astral.sh/ruff/rules/#flake8-type-checking-tch
"TD", # https://docs.astral.sh/ruff/rules/#flake8-todos-td

"TRY", # https://docs.astral.sh/ruff/rules/#tryceratops-try
"FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly
"PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf

"PL", # https://docs.astral.sh/ruff/rules/#pylint-pl

src = [
"src",
"tests"
]


[lint]
select = ["ALL"]

ignore = [
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d
"T20", # https://docs.astral.sh/ruff/rules/#flake8-print-t20
"DTZ", # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
"SLF", # https://docs.astral.sh/ruff/rules/#flake8-self-slf

"RET501", # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501
"TRY400", # https://docs.astral.sh/ruff/rules/error-instead-of-exception/

"A003", # https://docs.astral.sh/ruff/rules/builtin-attribute-shadowing/
# https://docs.astral.sh/ruff/rules/#flake8-builtins-a
"A003", # Python builtin is shadowed by class attribute {name} from {row}

# https://docs.astral.sh/ruff/rules/#pyflakes-f
"F401", # {name} imported but unused; consider using importlib.util.find_spec to test for availability

# https://docs.astral.sh/ruff/rules/#flake8-bandit-s
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes

# https://docs.astral.sh/ruff/rules/#pyupgrade-up
"UP038", # Use X | Y in {} call instead of (X, Y)

# https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
"ANN101", # Missing type annotation for {name} in method
"ANN102", # Missing type annotation for {name} in classmethod
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in {name}

# https://docs.astral.sh/ruff/rules/#flake8-blind-except-ble
"BLE001", # Do not catch blind exception: {name}

# https://docs.astral.sh/ruff/rules/#flake8-raise-rse
"RSE102", # Unnecessary parentheses on raised exception

# https://docs.astral.sh/ruff/rules/#flake8-commas-com
"COM812", # Trailing comma missing
"COM819", # Trailing comma prohibited

# https://docs.astral.sh/ruff/rules/#warning-w_1
"PLW0603", # Using the global statement to update {name} is discouraged

# https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
"G004", # Logging statement uses f-string

# https://docs.astral.sh/ruff/rules/#refactor-r
"PLR1711", # Useless return statement at end of function

# https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
"RUF005", # Consider {expression} instead of concatenation
]


[format]
# Use single quotes for non-triple-quoted strings.
quote-style = "single"


# https://docs.astral.sh/ruff/settings/#lintflake8-quotes
[lint.flake8-quotes]
inline-quotes = "single"
multiline-quotes = "single"

[lint.per-file-ignores]
"doc/*" = [
"A001", # A001 Variable `copyright` is shadowing a Python builtin
"E402", # E402 Module level import not at top of file
"INP001", # INP001 File `FILE_NAME` is part of an implicit namespace package. Add an `__init__.py`.
"PTH100", # PTH100 `os.path.abspath()` should be replaced by `Path.resolve()`
"PTH118", # PTH118 `os.path.join()` should be replaced by `Path` with `/` operator
]

"tests/*" = [
"INP001", # INP001 File `FILE_NAME` is part of an implicit namespace package. Add an `__init__.py`.
"ISC002", # ISC002 Implicitly concatenated string literals over multiple lines
]
[lint.flake8-builtins]
builtins-ignorelist = ["id", "input"]

"setup.py" = ["PTH123"]

"src/sphinx_exec_code/code_exec_error.py" = [
"PERF401", # PERF401 Use a list comprehension to create a transformed list
"PLW2901", # PLW2901 `for` loop variable `tb_line` overwritten by assignment target
]
# https://docs.astral.sh/ruff/settings/#lintisort
[lint.isort]
lines-after-imports = 2 # https://docs.astral.sh/ruff/settings/#lint_isort_lines-after-imports


[lint.isort]
# https://docs.astral.sh/ruff/settings/#isort-lines-after-imports
lines-after-imports = 2
[lint.per-file-ignores]
"setup.py" = ["PTH123"]

"tests/*" = [
"ANN", # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann

# https://docs.astral.sh/ruff/rules/#flake8-bandit-s
"S101", # Use of assert detected

[lint.pylint]
max-args = 6
# https://docs.astral.sh/ruff/rules/#refactor-r
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
"PLR0913", # Too many arguments in function definition ({c_args} > {max_args})
]
17 changes: 12 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
pytest == 7.4.4
pre-commit == 3.5.0
# Dependencies for old python versions
pre-commit == 3.5.0; python_version < '3.9'
pytest == 7.4.4; python_version < '3.10'
sphinx == 7.4.7; python_version == '3.9'
sphinx == 7.1.2; python_version == '3.8'

ruff == 0.1.11
# Current dependencies
pre-commit == 4.0.1; python_version >= '3.9'
pytest == 8.3.3; python_version >= '3.10'
sphinx == 8.1.3; python_version >= '3.10'

sphinx == 7.1.2
sphinx-rtd-theme == 2.0.0
ruff == 0.6.9

sphinx-rtd-theme == 3.0.1
35 changes: 18 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def load_version() -> str:
version: typing.Dict[str, str] = {}
with open("src/sphinx_exec_code/__version__.py") as fp:
with open('src/sphinx_exec_code/__version__.py') as fp:
exec(fp.read(), version)
assert version['__version__'], version
return version['__version__']
Expand All @@ -21,42 +21,43 @@ def load_version() -> str:
readme = Path(__file__).with_name('readme.md')
long_description = ''
if readme.is_file():
with readme.open("r", encoding='utf-8') as fh:
with readme.open('r', encoding='utf-8') as fh:
long_description = fh.read()

setup(
name="sphinx-exec-code",
name='sphinx-exec-code',
version=__version__,
author="spaceman_spiff",
author='spaceman_spiff',
# author_email="",
description="Execute code blocks in Sphinx and display the output",
description='Execute code blocks in Sphinx and display the output',
keywords=[
'sphinx',
'execute',
'exec',
'code'
],
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/spacemanspiff2007/sphinx-exec-code",
long_description_content_type='text/markdown',
url='https://github.com/spacemanspiff2007/sphinx-exec-code',
project_urls={
'GitHub': 'https://github.com/spacemanspiff2007/sphinx-exec-code',
'Documentation': 'https://sphinx-exec-code.readthedocs.io/',
},
package_dir={'': 'src'},
packages=find_packages('src', exclude=['tests*']),
classifiers=[
"Development Status :: 5 - Production/Stable",
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Framework :: Sphinx :: Extension',
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: 3 :: Only',
],
)
6 changes: 2 additions & 4 deletions src/sphinx_exec_code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from .__version__ import __version__

# isort: split

from sphinx_exec_code.sphinx_api import setup

from .__version__ import __version__
2 changes: 1 addition & 1 deletion src/sphinx_exec_code/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.12'
__version__ = '0.13'
2 changes: 1 addition & 1 deletion src/sphinx_exec_code/code_exec_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class CodeExceptionError(Exception):
def __init__(self, code: str, file: Path, first_loc: int, ret: int, stderr: str):
def __init__(self, code: str, file: Path, first_loc: int, ret: int, stderr: str) -> None:
self.code = code

self.file: Path = file
Expand Down
4 changes: 2 additions & 2 deletions src/sphinx_exec_code/code_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class VisibilityMarkerError(Exception):
class CodeMarker:
MARKERS = ('hide', 'skip')

def __init__(self, marker: str):
def __init__(self, marker: str) -> None:
assert marker in CodeMarker.MARKERS
self.start = f'#{marker}:start'
self.stop = f'#{marker}:stop'
Expand Down Expand Up @@ -40,7 +40,7 @@ def is_marker(self, line: str) -> bool:

return False

def add_line(self, line: str):
def add_line(self, line: str) -> None:
if not self.do_add:
return None

Expand Down
6 changes: 3 additions & 3 deletions src/sphinx_exec_code/configuration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class SphinxConfigValue(Generic[TYPE_VALUE]):
SPHINX_TYPE: Union[Tuple[Type[Any], ...], Type[Any]]

def __init__(self, sphinx_name: str, initial_value: Optional[TYPE_VALUE] = None):
def __init__(self, sphinx_name: str, initial_value: Optional[TYPE_VALUE] = None) -> None:
self.sphinx_name: Final = sphinx_name
self._value: Optional[TYPE_VALUE] = initial_value

Expand All @@ -23,7 +23,7 @@ def value(self) -> TYPE_VALUE:
raise ConfigError(msg)
return self._value

def transform_value(self, app: SphinxApp, value):
def transform_value(self, app: SphinxApp, value: Any) -> TYPE_VALUE:
return value

def validate_value(self, value) -> TYPE_VALUE:
Expand All @@ -42,6 +42,6 @@ def from_app(self, app: SphinxApp) -> TYPE_VALUE:
self._value = self.validate_value(value)
return self._value

def add_config_value(self, app: SphinxApp, sphinx_default: TYPE_VALUE):
def add_config_value(self, app: SphinxApp, sphinx_default: TYPE_VALUE) -> None:
self.validate_value(sphinx_default)
app.add_config_value(self.sphinx_name, sphinx_default, 'env', self.SPHINX_TYPE)
Loading

0 comments on commit 1c46b7c

Please sign in to comment.