Skip to content

Commit 945f3d9

Browse files
committed
Fix doctests and project script
1 parent 9a5cec3 commit 945f3d9

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ dependencies = [
3030
]
3131

3232
[project.optional-dependencies]
33-
dev = ["pyshp[test]", "pre-commit", "ruff"]
33+
dev = ["pyshp[test]", "pre-commit", "ruff", "mypy"]
3434
test = ["pytest"]
3535

3636
[project.urls]
3737
Repository = "https://github.com/GeospatialPython/pyshp"
3838

3939
[project.scripts]
40-
shapefile="__init__:main"
40+
shapefile="shapefile.__main__:main"
4141

4242
[tool.hatch.build.targets.sdist]
4343
only-include = ["src", "shapefiles", "test_shapefile.py"]

src/shapefile/__init__.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@
99
from __future__ import annotations
1010

1111
import logging
12-
import sys
1312

13+
from .__main__ import main
1414
from .__version__ import __version__
15-
from ._doctest_runner import _test
1615
from .classes import Field, ShapeRecord, ShapeRecords, Shapes
1716
from .constants import (
17+
FIRST_RING,
18+
INNER_RING,
19+
MISSING,
1820
MULTIPATCH,
1921
MULTIPOINT,
2022
MULTIPOINTM,
2123
MULTIPOINTZ,
24+
NODATA,
2225
NULL,
26+
OUTER_RING,
27+
PARTTYPE_LOOKUP,
2328
POINT,
2429
POINTM,
2530
POINTZ,
@@ -30,7 +35,11 @@
3035
POLYLINEM,
3136
POLYLINEZ,
3237
REPLACE_REMOTE_URLS_WITH_LOCALHOST,
38+
RING,
3339
SHAPETYPE_LOOKUP,
40+
SHAPETYPENUM_LOOKUP,
41+
TRIANGLE_FAN,
42+
TRIANGLE_STRIP,
3443
)
3544
from .exceptions import GeoJSON_Error, RingSamplingError, ShapefileException
3645
from .geometric_calculations import bbox_overlap
@@ -106,6 +115,16 @@
106115
"MULTIPATCH",
107116
"SHAPETYPE_LOOKUP",
108117
"REPLACE_REMOTE_URLS_WITH_LOCALHOST",
118+
"SHAPETYPENUM_LOOKUP",
119+
"TRIANGLE_STRIP",
120+
"TRIANGLE_FAN",
121+
"OUTER_RING",
122+
"INNER_RING",
123+
"FIRST_RING",
124+
"RING",
125+
"PARTTYPE_LOOKUP",
126+
"MISSING",
127+
"NODATA",
109128
"Reader",
110129
"Writer",
111130
"fsdecode_if_pathlike",
@@ -164,15 +183,7 @@
164183
"ShapeRecord",
165184
"ShapeRecords",
166185
"bbox_overlap",
186+
"main",
167187
]
168188

169189
logger = logging.getLogger(__name__)
170-
171-
172-
def main() -> None:
173-
"""
174-
Doctests are contained in the file 'README.md', and are tested using the built-in
175-
testing libraries.
176-
"""
177-
failure_count = _test()
178-
sys.exit(failure_count)

src/shapefile/__main__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sys
2+
3+
from ._doctest_runner import _test
4+
5+
6+
def main() -> None:
7+
"""
8+
Doctests are contained in the file 'README.md', and are tested using the built-in
9+
testing libraries.
10+
"""
11+
failure_count = _test()
12+
sys.exit(failure_count)
13+
14+
15+
if __name__ == "__main__":
16+
main()

src/shapefile/_doctest_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import doctest
22
import sys
33
from collections.abc import Iterable, Iterator
4+
from pathlib import Path
45
from urllib.parse import urlparse, urlunparse
56

67
from .constants import REPLACE_REMOTE_URLS_WITH_LOCALHOST
78

89

910
def _get_doctests() -> doctest.DocTest:
1011
# run tests
11-
with open("README.md", "rb") as fobj:
12+
with Path("README.md").open("rb") as fobj:
1213
tests = doctest.DocTestParser().get_doctest(
1314
string=fobj.read().decode("utf8").replace("\r\n", "\n"),
1415
globs={},

0 commit comments

Comments
 (0)