Skip to content

Commit 98d8835

Browse files
rossbarjschueller
andauthored
TST,CI: Add workflow to check sdist. (#670)
* TST,CI: Add workflow to check sdist. * Split build + install, limit to one Python. * CI,TST: Prevent test file pickup from source dir. * TST: Update tst paths to pkged paths * replace relpath in example_module tst fixture. * Update __main__ rel to install path. * Update importlib.resources.path incantation to a pattern that works on 3.12 and 3.14. * Use cwd instead of requests.root_dir * pyproject: include example_module.py Closes #668 * Fixup after rebase. * Add note about strange importlib.resource pattern. --------- Co-authored-by: Julien Schueller <[email protected]>
1 parent 703133a commit 98d8835

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

.github/workflows/test.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,42 @@ jobs:
182182
- name: Test coverage
183183
run: |
184184
codecov
185+
186+
test-sdist:
187+
runs-on: ${{ matrix.os }}-latest
188+
strategy:
189+
matrix:
190+
os: [ubuntu]
191+
python-version: ["3.14"]
192+
steps:
193+
- uses: actions/checkout@v5
194+
195+
- name: Python setup
196+
uses: actions/setup-python@v6
197+
with:
198+
python-version: ${{ matrix.python-version }}
199+
200+
- name: Setup environment
201+
run: |
202+
python -m pip install --upgrade pip wheel setuptools build
203+
python -m pip list
204+
205+
- name: Install dependencies
206+
run: |
207+
python -m pip install --group test --group doc
208+
pip list
209+
210+
- name: Build numpydoc
211+
run: python -m build
212+
213+
- name: Install numpydoc from source tarball
214+
run: |
215+
python -m pip install --no-binary numpydoc dist/*.tar.gz
216+
pip list
217+
218+
- name: Run test suite
219+
# NOTE: Move outside of source directory to prevent any file pickup -
220+
# ensure all tests/tests files are derived from the package *only*
221+
run: |
222+
mkdir foo && cd foo
223+
pytest -v --pyargs numpydoc

numpydoc/tests/hooks/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_find_project_root(tmp_path, request, reason_file, files, expected_reaso
3030
for file in files:
3131
(tmp_path / file).touch()
3232
else:
33-
expected_dir = request.config.rootdir
33+
expected_dir = Path.cwd()
3434

3535
root_dir, reason = utils.find_project_root(files if not files else [tmp_path])
3636
assert reason == expected_reason

numpydoc/tests/hooks/test_validate_hook.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
"""Test the numpydoc validate pre-commit hook."""
22

3+
import importlib.resources
34
import inspect
45
import re
56
from pathlib import Path
67

78
import pytest
89

10+
import numpydoc
911
from numpydoc.hooks.validate_docstrings import run_hook
1012

1113

1214
@pytest.fixture
1315
def example_module(request):
14-
fullpath = (
15-
Path(request.config.rootdir)
16-
/ "numpydoc"
17-
/ "tests"
18-
/ "hooks"
19-
/ "example_module.py"
20-
)
21-
return str(fullpath.relative_to(request.config.rootdir))
16+
# TODO: When Python3.13 is the minimum version supported version, this
17+
# can be simplified to:
18+
# with importlib.resources.path(numpydoc, "tests/hooks/example_module.py") as fpath:
19+
# fullpath = str(fpath)
20+
with importlib.resources.path(numpydoc, "tests") as fpath:
21+
fullpath = str(fpath / "hooks/example_module.py")
22+
return str(fullpath)
2223

2324

2425
@pytest.mark.parametrize("config", [None, "fake_dir"])

numpydoc/tests/test_main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.resources
12
import inspect
23
import io
34
import sys
@@ -119,12 +120,15 @@ def test_validate_perfect_docstring():
119120

120121
@pytest.mark.parametrize("args", [[], ["--ignore", "SS03"]])
121122
def test_lint(capsys, args):
122-
argv = ["lint", "numpydoc/__main__.py"] + args
123+
with importlib.resources.path(numpydoc, "__main__.py") as fpath:
124+
strpath = str(fpath)
125+
126+
argv = ["lint", strpath] + args
123127
if args:
124128
expected = ""
125129
expected_status = 0
126130
else:
127-
expected = "numpydoc/__main__.py:1: SS03 Summary does not end with a period"
131+
expected = f"{strpath}:1: SS03 Summary does not end with a period"
128132
expected_status = 1
129133

130134
return_status = numpydoc.cli.main(argv)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ attr = 'numpydoc.__version__'
168168
[tool.setuptools.package-data]
169169
numpydoc = [
170170
'tests/test_*.py',
171-
'tests/hooks/test_*.py',
171+
'tests/hooks/*.py',
172172
'tests/tinybuild/Makefile',
173173
'tests/tinybuild/index.rst',
174174
'tests/tinybuild/*.py',

0 commit comments

Comments
 (0)