Skip to content

Commit bb2a1f8

Browse files
authored
Add basic CI configuration (#8)
* Add basic CI configuration * Use Python 3.12 as lowest bound in test matrix * Shrink test matrix No need to be wasteful. * Include pytest-cov * Fix paths and other tweaks * Report positive comparison with example stubs * Fix tool.docstub section Got scrambled by an earlier partial commit. * Add basic statistics * Use "~" in doctype of Py2StubTransformer * Use correct config file for example_pkg * Match editable and normal install for test coverage * Don't upload docstub-stubs These multiple jobs conflict and I have no real use for these right now.
1 parent 0b048f3 commit bb2a1f8

File tree

5 files changed

+88
-11
lines changed

5 files changed

+88
-11
lines changed

.github/workflows/ci.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
env:
15+
# Many color libraries just need this to be set to any value, but at least
16+
# one distinguishes color depth, where "3" -> "256-bit color".
17+
FORCE_COLOR: 3
18+
19+
jobs:
20+
pre-commit:
21+
name: pre-commit
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
- uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.x"
30+
- uses: pre-commit/[email protected]
31+
with:
32+
extra_args: --hook-stage manual --all-files
33+
34+
checks:
35+
name: Test on ${{ matrix.runs-on }} Python ${{ matrix.python-version }}
36+
runs-on: ${{ matrix.runs-on }}
37+
needs: [pre-commit]
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
runs-on: [ubuntu-latest, windows-latest, macos-14]
42+
python-version: ["3.12"]
43+
44+
include:
45+
- runs-on: ubuntu-latest
46+
python-version: "3.13"
47+
48+
steps:
49+
- uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
53+
- uses: actions/setup-python@v5
54+
with:
55+
python-version: ${{ matrix.python-version }}
56+
allow-prereleases: true
57+
58+
- name: Install package
59+
run: python -m pip install .[test,optional]
60+
61+
- name: Run pytest
62+
run: >-
63+
python -m pytest --showlocals -ra --cov --cov-report=term
64+
65+
# TODO upload coverage statistics, and fail on decrease?
66+
67+
- name: Compare example stubs
68+
run: |
69+
python -m docstub -v --config=examples/docstub.toml examples/example_pkg
70+
git diff --exit-code examples/ && echo "Stubs for example_pkg did not change"
71+
72+
- name: Generate docstub stubs
73+
run: |
74+
python -m docstub -v src/docstub

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ pip install 'docstub [optional] @ git+https://github.com/scientific-python/docst
2020
## Usage & configuration
2121

2222
```shell
23-
docstub example/example_pkg/
23+
cd examples/
24+
docstub example_pkg/
2425
```
25-
will create stub files for `example_pkg/` in `example/example_pkg-stubs/`.
26+
will create stub files for `example_pkg/` in `examples/example_pkg-stubs/`.
2627
For now, refer to `docstub --help` for more.
2728

2829

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dev = [
4444
]
4545
test = [
4646
"pytest >=5.0.0",
47-
"coverage >=7.5.0",
47+
"pytest-cov >= 5.0.0",
4848
]
4949

5050
[project.urls]
@@ -90,6 +90,9 @@ ignore = [
9090
]
9191

9292

93-
[tool.docstub.docnames]
93+
[tool.coverage]
94+
run.source = ["docstub"]
95+
96+
[tool.docstub.known_imports]
9497
cst = {import = "libcst", as="cst"}
9598
lark = {import = "lark"}

src/docstub/_cli.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
logger = logging.getLogger(__name__)
1818

1919

20-
def _find_configuration(source_dir, config_path):
21-
"""Find and load configuration from multiple possible sources.
20+
def _load_configuration(config_path=None):
21+
"""Load and merge configuration from CWD and optional files.
2222
2323
Parameters
2424
----------
25-
source_dir : Path
2625
config_path : Path
2726
2827
Returns
@@ -31,13 +30,13 @@ def _find_configuration(source_dir, config_path):
3130
"""
3231
config = Config.from_toml(Config.DEFAULT_CONFIG_PATH)
3332

34-
pyproject_toml = source_dir.parent / "pyproject.toml"
33+
pyproject_toml = Path.cwd() / "pyproject.toml"
3534
if pyproject_toml.is_file():
3635
logger.info("using %s", pyproject_toml)
3736
add_config = Config.from_toml(pyproject_toml)
3837
config = config.merge(add_config)
3938

40-
docstub_toml = source_dir.parent / "docstub.toml"
39+
docstub_toml = Path.cwd() / "docstub.toml"
4140
if docstub_toml.is_file():
4241
logger.info("using %s", docstub_toml)
4342
add_config = Config.from_toml(docstub_toml)
@@ -87,7 +86,7 @@ def main(source_dir, out_dir, config_path, verbose):
8786
_setup_logging(verbose=verbose)
8887

8988
source_dir = Path(source_dir)
90-
config = _find_configuration(source_dir, config_path)
89+
config = _load_configuration(config_path)
9190

9291
# Build map of known imports
9392
known_imports = common_known_imports()

src/docstub/_stubs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def _annotations_from_node(self, node):
572572
573573
Returns
574574
-------
575-
annotations : DocstringAnnotations
575+
annotations : ~.DocstringAnnotations
576576
"""
577577
annotations = None
578578
docstring = node.get_docstring()

0 commit comments

Comments
 (0)