Skip to content

Commit b38b7e3

Browse files
authored
perf: compatible with python3.7 (#51)
Closes #45 Signed-off-by: msclock <msclock@qq.com>
1 parent 4240837 commit b38b7e3

File tree

6 files changed

+35
-27
lines changed

6 files changed

+35
-27
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
strategy:
4141
fail-fast: false
4242
matrix:
43-
python-version: ["3.8", "3.12"]
43+
python-version: ["3.7", "3.8", "3.12"]
4444
runs-on: [ubuntu-latest, macos-latest, windows-latest]
4545

4646
include:

.pre-commit-config.yaml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ exclude: |
55
66
repos:
77
- repo: https://github.com/psf/black-pre-commit-mirror
8-
rev: "23.11.0"
8+
rev: "22.12.0"
99
hooks:
1010
- id: black-jupyter
1111

1212
- repo: https://github.com/adamchainz/blacken-docs
13-
rev: "1.16.0"
13+
rev: "1.14.0"
1414
hooks:
1515
- id: blacken-docs
16-
additional_dependencies: [black==23.*]
16+
additional_dependencies: [black==22.*]
1717

1818
- repo: https://github.com/pre-commit/pre-commit-hooks
19-
rev: "v4.5.0"
19+
rev: "v4.4.0"
2020
hooks:
2121
- id: check-added-large-files
2222
- id: check-case-conflict
@@ -56,26 +56,20 @@ repos:
5656
args: ["--fix", "--show-fixes"]
5757

5858
- repo: https://github.com/pre-commit/mirrors-mypy
59-
rev: "v1.7.0"
59+
rev: "v1.4.1"
6060
hooks:
6161
- id: mypy
6262
files: src|tests
63-
args: []
6463
additional_dependencies:
6564
- click
66-
- loguru
67-
- pytest
68-
- sphinx
69-
- gitpython
70-
- jinja2
7165

7266
- repo: https://github.com/codespell-project/codespell
73-
rev: "v2.2.6"
67+
rev: "v2.2.5"
7468
hooks:
7569
- id: codespell
7670

7771
- repo: https://github.com/shellcheck-py/shellcheck-py
78-
rev: "v0.9.0.6"
72+
rev: "v0.9.0.5"
7973
hooks:
8074
- id: shellcheck
8175

@@ -93,7 +87,7 @@ repos:
9387
- id: validate-pyproject
9488

9589
- repo: https://github.com/python-jsonschema/check-jsonschema
96-
rev: 0.27.0
90+
rev: 0.23.3
9791
hooks:
9892
- id: check-dependabot
9993
- id: check-github-workflows

pyproject.toml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "A versioned documentation deployment tool for sphinx."
99
dynamic = ["version"]
1010
license = { text = "Apache 2.0" }
1111
readme = "README.md"
12-
requires-python = ">=3.8"
12+
requires-python = ">=3.7"
1313
classifiers = [
1414
"Development Status :: 1 - Planning",
1515
"Intended Audience :: Science/Research",
@@ -28,13 +28,22 @@ classifiers = [
2828
"Topic :: Scientific/Engineering",
2929
"Typing :: Typed",
3030
]
31-
dependencies = ["click", "loguru", "sphinx>=7.0", "gitpython", "jinja2"]
31+
dependencies = [
32+
"importlib-metadata; python_version<'3.8'",
33+
"importlib-resources >=1.3; python_version<'3.9'",
34+
"typing-extensions >=3.10.0; python_version<'3.9'",
35+
"click",
36+
"loguru",
37+
"sphinx",
38+
"gitpython",
39+
"jinja2",
40+
]
3241

3342
[project.optional-dependencies]
3443
test = ["pytest >=6", "pytest-cov >=3"]
3544
docs = [
36-
"sphinx>=7.0",
37-
"furo>=2023.08.17",
45+
"sphinx",
46+
"furo",
3847
"myst_parser>=0.13",
3948
"sphinx_copybutton",
4049
"sphinx_autodoc_typehints",
@@ -68,7 +77,7 @@ port.exclude_lines = ['pragma: no cover', '\.\.\.', 'if typing.TYPE_CHECKING:']
6877

6978
[tool.mypy]
7079
files = ["src", "tests"]
71-
python_version = "3.8"
80+
python_version = "3.7"
7281
warn_unused_configs = true
7382
strict = true
7483
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
@@ -121,7 +130,7 @@ isort.required-imports = ["from __future__ import annotations"]
121130
"noxfile.py" = ["T20"]
122131

123132
[tool.pylint]
124-
py-version = "3.8"
133+
py-version = "3.7"
125134
ignore-paths = [".*/_version.py"]
126135
reports.output-format = "colorized"
127136
similarities.ignore-imports = "yes"

src/sphinx_deployment/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def create_command(
372372

373373
dest_dir = Path(output_path).joinpath(v.name)
374374
shutil.rmtree(str(dest_dir), ignore_errors=True)
375-
shutil.copytree(tmp, str(dest_dir), dirs_exist_ok=True)
375+
shutil.copytree(tmp, str(dest_dir))
376376

377377
redirect_html = Path(output_path).joinpath("index.html")
378378
if not redirect_html.exists():

src/sphinx_deployment/sphinx_ext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def _html_page_context(
7676
_ = (pagename, templatename, context, doctree)
7777

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

8383
# Expose the current versions
8484
versions_tpl = DIR.joinpath("_static", "templates", "versions.js")

tests/test_package.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
from __future__ import annotations
22

3-
import importlib.metadata
3+
import sys
4+
5+
if sys.version_info < (3, 8):
6+
import importlib_metadata as _metadata
7+
else:
8+
import importlib.metadata as _metadata
49

510
import sphinx_deployment as m
611

712

813
def test_version():
9-
assert importlib.metadata.version("sphinx_deployment") == m.__version__
14+
assert _metadata.version("sphinx_deployment") == m.__version__

0 commit comments

Comments
 (0)