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

Convert setup.cfg to pyproject.toml, update tools #80

Merged
merged 18 commits into from
Sep 29, 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
13 changes: 13 additions & 0 deletions .github/workflows/sphinx_asdf_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,26 @@ on:
pull_request:
branches:

# Only cancel in-progress jobs or runs for the current workflow
# This cancels the already triggered workflows for a specific PR without canceling
# other instances of this workflow (other PRs, scheduled triggers, etc) when something
# within that PR re-triggers this CI
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tox_pytest:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- name: Python 3.12 Tests
python-version: "3.12-dev"
os: ubuntu-latest
toxenv: py312

- name: Python 3.11 Tests
python-version: "3.11"
os: ubuntu-latest
Expand Down
50 changes: 36 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,58 @@ repos:
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-yaml
args: ["--unsafe"]
- id: check-toml
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.13.0
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char

- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
- id: isort
- id: codespell
args: ["--write-changes"]
additional_dependencies:
- tomli

- repo: https://github.com/ikamensh/flynt/
rev: '1.0.1'
hooks:
- id: flynt
exclude: "asdf/(extern||_jsonschema)/.*"

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.288'
hooks:
- id: ruff
args: ["--fix"]

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
- repo: https://github.com/asottile/blacken-docs
rev: '1.16.0'
hooks:
- id: flake8
- id: blacken-docs

- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
- repo: https://github.com/abravalheri/validate-pyproject
rev: "v0.14"
hooks:
- id: bandit
args: ["-c", "bandit.yaml"]
- id: validate-pyproject
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ resolved as links, include the following in your ``docs/conf.py`` file:
.. code-block:: python

asdf_schema_reference_mappings = [
('tag:stsci.edu:asdf',
'http://asdf-standard.readthedocs.io/en/latest/generated/stsci.edu/asdf/'),
(
"tag:stsci.edu:asdf",
"http://asdf-standard.readthedocs.io/en/latest/generated/stsci.edu/asdf/",
),
]

Inline documentation
Expand Down
8 changes: 0 additions & 8 deletions bandit.yaml

This file was deleted.

70 changes: 68 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
[project]
name = "sphinx-asdf"
description = "Sphinx plugin for generating documentation from ASDF schemas"
readme = 'README.rst'
license = { file = 'LICENSE' }
authors = [{ name = 'The ASDF Developers', email = '[email protected]' }]
requires-python = '>=3.9'
classifiers = [
'Development Status :: 5 - Production/Stable',
"License :: OSI Approved :: BSD License",
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
]
dynamic = [
'version',
]
dependencies = [
"asdf",
"astropy>=5.0.4",
"docutils",
"mistune>=3",
"packaging",
"sphinx",
"sphinx-astropy",
"sphinx_bootstrap_theme",
"sphinx-rtd-theme",
"toml",

]
[project.optional-dependencies]
tests = [
"pytest",
]
[project.urls]
'documentation' = 'https://sphinx-asdf.readthedocs.io/en/stable'
'repository' = 'https://github.com/asdf-format/sphinx-asdf'
'tracker' = 'https://github.com/asdf-format/sphinx-asdf/issues'

[tool.setuptools.packages.find]
include = ['sphinx_asdf*']

[build-system]
requires = ["setuptools>=42", "setuptools_scm[toml]>=3.4", "wheel"]
build-backend = "setuptools.build_meta"
Expand All @@ -20,5 +65,26 @@ force-exclude = '''

[tool.isort]
profile = "black"
filter_files = true
line_length = 120
filter-files = true
line-length = 120

[tool.ruff]
target-version = "py38"
line-length = 120
select = [
# minimal set to match pre-ruff behavior
"E", # pycodestyle
"F", # pyflakes, autoflake
"I", # isort
"S", # bandit
"UP", # pyupgrade
"RUF", # ruff specific, includes yesqa
]
extend-ignore = [
"F403", "F405", # uses if import * should be removed
"S101", # asserts used in tests
"RUF012", # we don't use typing
]

[tool.codespell]
skip="*.pdf,*.asdf,.tox,build,./tags,.git,docs/_build"
51 changes: 0 additions & 51 deletions setup.cfg

This file was deleted.

4 changes: 1 addition & 3 deletions sphinx_asdf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os

from sphinx.builders.html import StandaloneHTMLBuilder

from .asdf2rst import AsdfDirective, RunCodeDirective
from .connections import (
add_labels_to_nodes,
Expand All @@ -10,7 +8,7 @@
on_build_finished,
update_app_config,
)
from .directives import AsdfAutoschemas, AsdfSchema, schema_def
from .directives import AsdfAutoschemas, AsdfSchema
from .nodes import add_asdf_nodes


Expand Down
8 changes: 4 additions & 4 deletions sphinx_asdf/asdf2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

try:
try:
exec(code, GLOBALS)
exec(code, GLOBALS) # noqa: S102

Check warning on line 32 in sphinx_asdf/asdf2rst.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/asdf2rst.py#L32

Added line #L32 was not covered by tests
except Exception:
print(code)
raise
Expand Down Expand Up @@ -75,7 +75,7 @@
if header["flags"] & key:
human_flags.append(val)
if len(human_flags):
lines.append(" flags: {}".format(" | ".join(human_flags)))
lines.append(f" flags: {' | '.join(human_flags)}")

Check warning on line 78 in sphinx_asdf/asdf2rst.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/asdf2rst.py#L78

Added line #L78 was not covered by tests
if header["compression"] and header["compression"] != b"\0\0\0\0":
lines.append(f" compression: {header['compression']}")
lines.append(f" allocated_size: {header['allocated_size']}")
Expand All @@ -100,8 +100,8 @@
cwd = os.getcwd()
os.chdir(TMPDIR)

show_header = not ("no_header" in self.arguments)
show_bocks = not ("no_blocks" in self.arguments)
show_header = "no_header" not in self.arguments
show_bocks = "no_blocks" not in self.arguments

Check warning on line 104 in sphinx_asdf/asdf2rst.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/asdf2rst.py#L103-L104

Added lines #L103 - L104 were not covered by tests

parts = []
try:
Expand Down
14 changes: 3 additions & 11 deletions sphinx_asdf/conf.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import datetime
# datetime is kept here as some downstream packages currently
# expect it to be imported when this file is star imported
import datetime # noqa: F401

Check warning on line 3 in sphinx_asdf/conf.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/conf.py#L3

Added line #L3 was not covered by tests
import os
import sys
from pathlib import Path

import numpy
import toml

# Ensure documentation examples are determinstically random.
try:
numpy.random.seed(int(os.environ["SOURCE_DATE_EPOCH"]))
except KeyError:
pass

try:
from sphinx_astropy.conf.v1 import *
Expand Down
1 change: 0 additions & 1 deletion sphinx_asdf/connections.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os
import posixpath
import warnings

import docutils
import packaging.version
Expand Down
24 changes: 15 additions & 9 deletions sphinx_asdf/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,17 @@
schema_id = self._resolve_reference(schema_id)
if fragment:
components = fragment.split("/")
fragment = "#{}".format("-".join(components[1:]))
fragment = f"#{'-'.join(components[1:])}"

Check warning on line 207 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L207

Added line #L207 was not covered by tests
if shorten and not schema_id:
refname = components[-1]
elif shorten:
rename = schema_id
# TODO this should probably be:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oopsies...

# refname = schema_id
# as it was previously
# rename = schema_id
# and ruff cleaned this up as unused. However, changing it
# to refname breaks some downstream packages
pass

return refname, schema_id + fragment

Expand Down Expand Up @@ -253,24 +259,24 @@
if not ("minLength" in schema or "maxLength" in schema):
node_list.append(nodes.emphasis(text="No length restriction"))
if schema.get("minLength", 0):
text = "Minimum length: {}".format(schema["minLength"])
text = f"Minimum length: {schema['minLength']}"

Check warning on line 262 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L262

Added line #L262 was not covered by tests
node_list.append(nodes.line(text=text))
if "maxLength" in schema:
text = "Maximum length: {}".format(schema["maxLength"])
text = f"Maximum length: {schema['maxLength']}"

Check warning on line 265 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L265

Added line #L265 was not covered by tests
node_list.append(nodes.line(text=text))
if "pattern" in schema:
node_list.append(nodes.line(text="Must match the following pattern:"))
node_list.append(nodes.literal_block(text=schema["pattern"], language="none"))

elif typename == "array":
if schema.get("minItems", 0):
text = "Minimum length: {}".format(schema["minItems"])
text = f"Minimum length: {schema['minItems']}"

Check warning on line 273 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L273

Added line #L273 was not covered by tests
node_list.append(nodes.line(text=text))
if "maxItems" in schema:
text = "Maximum length: {}".format(schema["maxItems"])
text = f"Maximum length: {schema['maxItems']}"

Check warning on line 276 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L276

Added line #L276 was not covered by tests
node_list.append(nodes.line(text=text))
if "additionalItems" in schema and "items" in schema:
if isinstance(schema["items"], list) and schema["additionalItems"] == False:
if isinstance(schema["items"], list) and schema["additionalItems"] is False:

Check warning on line 279 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L279

Added line #L279 was not covered by tests
node_list.append(nodes.emphasis(text="Additional items not permitted"))
elif not ("minItems" in schema or "maxItems" in schema):
node_list.append(nodes.emphasis(text="No length restriction"))
Expand All @@ -281,10 +287,10 @@
# TODO: more numerical validation keywords
elif typename in ["integer", "number"]:
if "minimum" in schema:
text = "Minimum value: {}".format(schema["minimum"])
text = f"Minimum value: {schema['minimum']}"

Check warning on line 290 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L290

Added line #L290 was not covered by tests
node_list.append(nodes.line(text=text))
if "maximum" in schema:
text = "Maximum value: {}".format(schema["maximum"])
text = f"Maximum value: {schema['maximum']}"

Check warning on line 293 in sphinx_asdf/directives.py

View check run for this annotation

Codecov / codecov/patch

sphinx_asdf/directives.py#L293

Added line #L293 was not covered by tests
node_list.append(nodes.line(text=text))

if "enum" in schema:
Expand Down
1 change: 0 additions & 1 deletion sphinx_asdf/md2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
rst converter that used to be in this file.
"""

import re
import textwrap

import mistune
Expand Down
Loading
Loading