Skip to content

Commit b54f933

Browse files
authored
Add: mypy coverage to scripts. (#452)
* Add: mypy coverage to scripts. * Fix: Missing type annotation in tests. * Fix: Ignore tomli for now.
1 parent e0dc785 commit b54f933

12 files changed

Lines changed: 25 additions & 18 deletions

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ script_launch_mode = "subprocess"
7979
# This section `must <https://mypy.readthedocs.io/en/stable/config_file.html#config-file-format>`_ be present.
8080
[tool.mypy]
8181
# See `files <https://mypy.readthedocs.io/en/stable/config_file.html#confval-files>`_.
82-
files = "pretext"
82+
files = "pretext,scripts,tests"
8383
exclude = "^pretext/core/pretext\\.py$"
8484
check_untyped_defs = true
8585
disallow_untyped_defs = true
@@ -93,6 +93,10 @@ module = [
9393
"ghp_import",
9494
# We're installing ``lxml-stubs``, but it doesn't have stubs for this yet.
9595
"lxml.ElementInclude",
96+
# TODO: Currently, the ``tomli`` package doesn't support Python 3.11, so
97+
# it's not installed there. For now, ignore this module. Remove the ignore
98+
# when ``tomli`` provide support for Python 3.11.
99+
"tomli",
96100
]
97101
ignore_missing_imports = true
98102

scripts/build_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import zip_templates
44

55

6-
def main():
6+
def main() -> None:
77
import pretext
88

99
print(f"Building package for version {pretext.VERSION}.")

scripts/fetch_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from remove_path import remove_path
99

1010

11-
def main():
11+
def main() -> None:
1212
# grab copy of necessary PreTeXtBook/pretext files from specified commit
1313

1414
print(f"Requesting core PreTeXtBook/pretext commit {CORE_COMMIT} from GitHub.")

scripts/fetch_core_commit.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import json
44
from datetime import datetime
55
import fileinput
6+
from typing import Any, Dict
67

78

8-
def commit_data(repo):
9+
def commit_data(repo: str) -> Dict[str, Any]:
910
"""
1011
Returns a dictionary containing the date and commit sha from the most recent commit to `repo`
1112
"""
@@ -20,7 +21,7 @@ def commit_data(repo):
2021
return lastcommit
2122

2223

23-
def main():
24+
def main() -> None:
2425
last_core_commit = commit_data("pretext")
2526

2627
# Update core commit:

scripts/prep_nightly.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import json
44
from datetime import datetime
55
import fileinput
6+
from typing import Any, Dict
67

78

8-
def commit_data(repo):
9+
def commit_data(repo: str) -> Dict[str, Any]:
910
lastcommit = {}
1011
url = f"https://api.github.com/repos/pretextbook/{repo}/commits"
1112
response = urlopen(url)
@@ -17,7 +18,7 @@ def commit_data(repo):
1718
return lastcommit
1819

1920

20-
def should_release(coredate, clidate):
21+
def should_release(coredate: datetime, clidate: datetime) -> bool:
2122
if (datetime.now() - coredate).days < 1:
2223
print(
2324
f"There has been an update to core pretext in the last 24 hours, at {coredate}"
@@ -30,7 +31,7 @@ def should_release(coredate, clidate):
3031
return True
3132

3233

33-
def main():
34+
def main() -> None:
3435
last_core_commit = commit_data("pretext")
3536
last_cli_commit = commit_data("pretext-cli")
3637

scripts/release_alpha.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import build_package
55

66

7-
def main():
7+
def main() -> None:
88
repo = git.Repo()
99
if repo.bare or repo.is_dirty() or len(repo.untracked_files) > 0:
1010
raise Exception("Must commit outstanding changes to project source.")

scripts/release_nightly.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from datetime import datetime
66
import fileinput
77
import pytest
8+
from typing import Any, Dict
89

910

10-
def commit_data(repo):
11+
def commit_data(repo: str) -> Dict[str, Any]:
1112
lastcommit = {}
1213
url = f"https://api.github.com/repos/pretextbook/{repo}/commits"
1314
response = urlopen(url)
@@ -19,7 +20,7 @@ def commit_data(repo):
1920
return lastcommit
2021

2122

22-
def should_release(coredate, clidate):
23+
def should_release(coredate: datetime, clidate: datetime) -> bool:
2324
if (datetime.now() - coredate).days < 1:
2425
print(
2526
f"There has been an update to core pretext in the last 24 hours, at {coredate}"
@@ -32,7 +33,7 @@ def should_release(coredate, clidate):
3233
return True
3334

3435

35-
def main():
36+
def main() -> None:
3637
last_core_commit = commit_data("pretext")
3738
last_cli_commit = commit_data("pretext-cli")
3839

scripts/release_stable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import build_package
77

88

9-
def main(level="patch"):
9+
def main(level: str = "patch") -> None:
1010
repo = git.Repo()
1111
if repo.bare or repo.is_dirty() or len(repo.untracked_files) > 0:
1212
raise Exception("Must commit outstanding changes to project source.")

scripts/remove_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33

44

5-
def remove_path(path: Path):
5+
def remove_path(path: Path) -> None:
66
if path.is_file() or path.is_symlink():
77
path.unlink() # remove the file
88
elif path.is_dir():

scripts/symlink_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pretext.core.resources
55

66

7-
def main(core_path: Path = Path("../pretext")):
7+
def main(core_path: Path = Path("../pretext")) -> None:
88
for subdir in ["xsl", "schema", "script", "css"]:
99
original_path = (core_path / subdir).resolve()
1010
link_path = pretext.core.resources.path(subdir)

0 commit comments

Comments
 (0)