Skip to content

Commit

Permalink
perf: compatible with python3.7 (#51)
Browse files Browse the repository at this point in the history
Closes #45

Signed-off-by: msclock <msclock@qq.com>
  • Loading branch information
msclock authored Feb 3, 2024
1 parent 4240837 commit b38b7e3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.12"]
python-version: ["3.7", "3.8", "3.12"]
runs-on: [ubuntu-latest, macos-latest, windows-latest]

include:
Expand Down
22 changes: 8 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ exclude: |
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: "23.11.0"
rev: "22.12.0"
hooks:
- id: black-jupyter

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
rev: "1.14.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.*]
additional_dependencies: [black==22.*]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.5.0"
rev: "v4.4.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand Down Expand Up @@ -56,26 +56,20 @@ repos:
args: ["--fix", "--show-fixes"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.7.0"
rev: "v1.4.1"
hooks:
- id: mypy
files: src|tests
args: []
additional_dependencies:
- click
- loguru
- pytest
- sphinx
- gitpython
- jinja2

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
rev: "v2.2.5"
hooks:
- id: codespell

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.9.0.6"
rev: "v0.9.0.5"
hooks:
- id: shellcheck

Expand All @@ -93,7 +87,7 @@ repos:
- id: validate-pyproject

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.0
rev: 0.23.3
hooks:
- id: check-dependabot
- id: check-github-workflows
Expand Down
21 changes: 15 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "A versioned documentation deployment tool for sphinx."
dynamic = ["version"]
license = { text = "Apache 2.0" }
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.7"
classifiers = [
"Development Status :: 1 - Planning",
"Intended Audience :: Science/Research",
Expand All @@ -28,13 +28,22 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Typing :: Typed",
]
dependencies = ["click", "loguru", "sphinx>=7.0", "gitpython", "jinja2"]
dependencies = [
"importlib-metadata; python_version<'3.8'",
"importlib-resources >=1.3; python_version<'3.9'",
"typing-extensions >=3.10.0; python_version<'3.9'",
"click",
"loguru",
"sphinx",
"gitpython",
"jinja2",
]

[project.optional-dependencies]
test = ["pytest >=6", "pytest-cov >=3"]
docs = [
"sphinx>=7.0",
"furo>=2023.08.17",
"sphinx",
"furo",
"myst_parser>=0.13",
"sphinx_copybutton",
"sphinx_autodoc_typehints",
Expand Down Expand Up @@ -68,7 +77,7 @@ port.exclude_lines = ['pragma: no cover', '\.\.\.', 'if typing.TYPE_CHECKING:']

[tool.mypy]
files = ["src", "tests"]
python_version = "3.8"
python_version = "3.7"
warn_unused_configs = true
strict = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
Expand Down Expand Up @@ -121,7 +130,7 @@ isort.required-imports = ["from __future__ import annotations"]
"noxfile.py" = ["T20"]

[tool.pylint]
py-version = "3.8"
py-version = "3.7"
ignore-paths = [".*/_version.py"]
reports.output-format = "colorized"
similarities.ignore-imports = "yes"
Expand Down
2 changes: 1 addition & 1 deletion src/sphinx_deployment/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def create_command(

dest_dir = Path(output_path).joinpath(v.name)
shutil.rmtree(str(dest_dir), ignore_errors=True)
shutil.copytree(tmp, str(dest_dir), dirs_exist_ok=True)
shutil.copytree(tmp, str(dest_dir))

redirect_html = Path(output_path).joinpath("index.html")
if not redirect_html.exists():
Expand Down
6 changes: 3 additions & 3 deletions src/sphinx_deployment/sphinx_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def _html_page_context(
_ = (pagename, templatename, context, doctree)

# Get the path to the versions.json file
sphinx_deployment_versions_file = str(
Path(context["content_root"]) / ".." / "versions.json"
)
current_page = Path(context["pagename"])
root_ = Path().joinpath("../" * (len(current_page.parts) - 1))
sphinx_deployment_versions_file = str(Path(root_) / ".." / "versions.json")

# Expose the current versions
versions_tpl = DIR.joinpath("_static", "templates", "versions.js")
Expand Down
9 changes: 7 additions & 2 deletions tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from __future__ import annotations

import importlib.metadata
import sys

if sys.version_info < (3, 8):
import importlib_metadata as _metadata
else:
import importlib.metadata as _metadata

import sphinx_deployment as m


def test_version():
assert importlib.metadata.version("sphinx_deployment") == m.__version__
assert _metadata.version("sphinx_deployment") == m.__version__

0 comments on commit b38b7e3

Please sign in to comment.