invoke-tasklib 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/PKG-INFO +6 -5
  2. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/README.md +5 -4
  3. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/typecheck.py +35 -2
  4. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/pyproject.toml +1 -1
  5. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_project.py +1 -0
  6. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_read_only.py +1 -0
  7. invoke_tasklib-0.1.1/tests/integration/test_typecheck.py +70 -0
  8. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_init.py +3 -1
  9. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_typecheck.py +48 -0
  10. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/.gitignore +0 -0
  11. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/LICENSE +0 -0
  12. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/__init__.py +0 -0
  13. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/_coverage.py +0 -0
  14. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/_discover.py +0 -0
  15. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/_files.py +0 -0
  16. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/_graph.py +0 -0
  17. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/_pyproject.py +0 -0
  18. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/_steps.py +0 -0
  19. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/check.py +0 -0
  20. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/clean.py +0 -0
  21. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/config/__init__.py +0 -0
  22. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/config/__main__.py +0 -0
  23. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/config/_constants.py +0 -0
  24. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/config/_derive.py +0 -0
  25. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/config/_invoke.py +0 -0
  26. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/config/_resolve.py +0 -0
  27. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/config/_schema.py +0 -0
  28. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/config/_validate.py +0 -0
  29. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/doc.py +0 -0
  30. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/env.py +0 -0
  31. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/fix.py +0 -0
  32. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/formatting.py +0 -0
  33. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/imports.py +0 -0
  34. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/lint.py +0 -0
  35. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/output.py +0 -0
  36. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/py.typed +0 -0
  37. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/release.py +0 -0
  38. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/runner.py +0 -0
  39. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/security.py +0 -0
  40. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/show.py +0 -0
  41. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/testing.py +0 -0
  42. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/invoke_tasklib/tools.py +0 -0
  43. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/__init__.py +0 -0
  44. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/benchmarks/__init__.py +0 -0
  45. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/benchmarks/test_config_benchmark.py +0 -0
  46. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/benchmarks/test_files_benchmark.py +0 -0
  47. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/benchmarks/test_graph_benchmark.py +0 -0
  48. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/benchmarks/test_init_benchmark.py +0 -0
  49. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/benchmarks/test_runner_benchmark.py +0 -0
  50. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/helpers.py +0 -0
  51. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/__init__.py +0 -0
  52. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/helpers.py +0 -0
  53. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_check.py +0 -0
  54. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_clean.py +0 -0
  55. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_doc.py +0 -0
  56. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_docs.py +0 -0
  57. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_doctest.py +0 -0
  58. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_env_config.py +0 -0
  59. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_env_install.py +0 -0
  60. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_env_python.py +0 -0
  61. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_env_tools.py +0 -0
  62. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_exit_codes.py +0 -0
  63. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_files.py +0 -0
  64. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_fix_converges.py +0 -0
  65. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_formatting.py +0 -0
  66. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_imports.py +0 -0
  67. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_output.py +0 -0
  68. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_quoting.py +0 -0
  69. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_readme.py +0 -0
  70. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_release.py +0 -0
  71. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_runner.py +0 -0
  72. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_security.py +0 -0
  73. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/integration/test_testing.py +0 -0
  74. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/__init__.py +0 -0
  75. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/config/__init__.py +0 -0
  76. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/config/conftest.py +0 -0
  77. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/config/test___main__.py +0 -0
  78. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/config/test__derive.py +0 -0
  79. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/config/test__invoke.py +0 -0
  80. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/config/test__resolve.py +0 -0
  81. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/config/test__schema.py +0 -0
  82. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/config/test__validate.py +0 -0
  83. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/conftest.py +0 -0
  84. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test__coverage.py +0 -0
  85. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test__discover.py +0 -0
  86. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test__files.py +0 -0
  87. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test__graph.py +0 -0
  88. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test__pyproject.py +0 -0
  89. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test__steps.py +0 -0
  90. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_architecture.py +0 -0
  91. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_check.py +0 -0
  92. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_clean.py +0 -0
  93. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_doc.py +0 -0
  94. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_docstrings.py +0 -0
  95. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_env.py +0 -0
  96. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_fix.py +0 -0
  97. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_formatting.py +0 -0
  98. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_helpers.py +0 -0
  99. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_imports.py +0 -0
  100. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_lint.py +0 -0
  101. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_output.py +0 -0
  102. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_program_hints.py +0 -0
  103. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_release.py +0 -0
  104. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_runner.py +0 -0
  105. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_security.py +0 -0
  106. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_show.py +0 -0
  107. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_testing.py +0 -0
  108. {invoke_tasklib-0.1.0 → invoke_tasklib-0.1.1}/tests/unit/test_tools.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: invoke-tasklib
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Reusable Invoke tasks shared across Python projects.
5
5
  Project-URL: Homepage, https://github.com/durandtibo/invoke-tasklib
6
6
  Project-URL: Repository, https://github.com/durandtibo/invoke-tasklib
@@ -75,7 +75,7 @@ Description-Content-Type: text/markdown
75
75
 
76
76
  Reusable [Invoke](https://www.pyinvoke.org/) tasks shared across Python
77
77
  projects: formatting, linting, type-checking, testing, environment setup,
78
- security auditing, releasing, documentation, and cleanup — all as a single
78
+ security auditing, releasing, documentation, and cleanup, all as a single
79
79
  importable package instead of a `tasks.py` you copy-paste and let drift
80
80
  between repositories.
81
81
 
@@ -138,7 +138,7 @@ for a full walkthrough.
138
138
 
139
139
  Tasks are grouped into namespaces, one per module. Each task either
140
140
  **checks/reports** (read-only, exits non-zero on violations) or
141
- **mutates** (formats, builds, publishes) — the table below flags which.
141
+ **mutates** (formats, builds, publishes); the table below flags which.
142
142
 
143
143
  | Namespace | Task | Behavior | Mutates? |
144
144
  | ---------- | ----------------------------- | ---------------------------------------------------------------------------------------- | :------: |
@@ -156,6 +156,7 @@ Tasks are grouped into namespaces, one per module. Each task either
156
156
  | `imports` | `imports.check-cycles` | Check for cyclic import dependencies | ❌ |
157
157
  | `imports` | `imports.check-isolated` | Check that every module imports on its own | ❌ |
158
158
  | `types` | `types.check` | Check type hints with ty (`--complete` also runs pyright) | ❌ |
159
+ | `types` | `types.check-public-api` | Check that the public API of the package is fully typed (pyright) | ❌ |
159
160
  | `test` | `test.doctest` | Run doctests on source code and markdown files | ❌ |
160
161
  | `test` | `test.doctest-src` | Run doctests on source code | ❌ |
161
162
  | `test` | `test.doctest-markdown` | Run doctests on Python examples in markdown files | ❌ |
@@ -196,7 +197,7 @@ tools each one wraps, see the
196
197
 
197
198
  ## Configuration
198
199
 
199
- Only `tasklib.package.name` is required — everything else has a sensible
200
+ Only `tasklib.package.name` is required; everything else has a sensible
200
201
  default derived from it:
201
202
 
202
203
  ```yaml
@@ -320,7 +321,7 @@ composition for things that are genuinely one-off to a single project.
320
321
  ## API Stability
321
322
 
322
323
  :warning: `invoke-tasklib` is under active development and its API is not
323
- yet stable — pin a specific version in your project's dependencies for
324
+ yet stable: pin a specific version in your project's dependencies for
324
325
  consistent behavior across releases.
325
326
 
326
327
  ## Contributing
@@ -47,7 +47,7 @@
47
47
 
48
48
  Reusable [Invoke](https://www.pyinvoke.org/) tasks shared across Python
49
49
  projects: formatting, linting, type-checking, testing, environment setup,
50
- security auditing, releasing, documentation, and cleanup — all as a single
50
+ security auditing, releasing, documentation, and cleanup, all as a single
51
51
  importable package instead of a `tasks.py` you copy-paste and let drift
52
52
  between repositories.
53
53
 
@@ -110,7 +110,7 @@ for a full walkthrough.
110
110
 
111
111
  Tasks are grouped into namespaces, one per module. Each task either
112
112
  **checks/reports** (read-only, exits non-zero on violations) or
113
- **mutates** (formats, builds, publishes) — the table below flags which.
113
+ **mutates** (formats, builds, publishes); the table below flags which.
114
114
 
115
115
  | Namespace | Task | Behavior | Mutates? |
116
116
  | ---------- | ----------------------------- | ---------------------------------------------------------------------------------------- | :------: |
@@ -128,6 +128,7 @@ Tasks are grouped into namespaces, one per module. Each task either
128
128
  | `imports` | `imports.check-cycles` | Check for cyclic import dependencies | ❌ |
129
129
  | `imports` | `imports.check-isolated` | Check that every module imports on its own | ❌ |
130
130
  | `types` | `types.check` | Check type hints with ty (`--complete` also runs pyright) | ❌ |
131
+ | `types` | `types.check-public-api` | Check that the public API of the package is fully typed (pyright) | ❌ |
131
132
  | `test` | `test.doctest` | Run doctests on source code and markdown files | ❌ |
132
133
  | `test` | `test.doctest-src` | Run doctests on source code | ❌ |
133
134
  | `test` | `test.doctest-markdown` | Run doctests on Python examples in markdown files | ❌ |
@@ -168,7 +169,7 @@ tools each one wraps, see the
168
169
 
169
170
  ## Configuration
170
171
 
171
- Only `tasklib.package.name` is required — everything else has a sensible
172
+ Only `tasklib.package.name` is required; everything else has a sensible
172
173
  default derived from it:
173
174
 
174
175
  ```yaml
@@ -292,7 +293,7 @@ composition for things that are genuinely one-off to a single project.
292
293
  ## API Stability
293
294
 
294
295
  :warning: `invoke-tasklib` is under active development and its API is not
295
- yet stable — pin a specific version in your project's dependencies for
296
+ yet stable: pin a specific version in your project's dependencies for
296
297
  consistent behavior across releases.
297
298
 
298
299
  ## Contributing
@@ -1,4 +1,8 @@
1
- r"""Type-checking task (``types.check``).
1
+ r"""Type-checking tasks (``types.*``).
2
+
3
+ The ``types.check`` task checks the type hints of the project. The
4
+ ``types.check-public-api`` task checks that the public API of the
5
+ package is fully typed.
2
6
 
3
7
  The module is named ``typecheck`` so that it does not shadow the
4
8
  standard library module ``types``; its namespace is ``types``, see
@@ -13,7 +17,7 @@ from invoke.tasks import task
13
17
 
14
18
  from invoke_tasklib.config import load_config
15
19
  from invoke_tasklib.output import say, step
16
- from invoke_tasklib.runner import PATHS_HELP, build_command, run
20
+ from invoke_tasklib.runner import ARGS_HELP, PATHS_HELP, build_command, run
17
21
 
18
22
  if TYPE_CHECKING:
19
23
  from invoke.context import Context
@@ -74,3 +78,32 @@ def check(
74
78
  ["pyright"], args=pyright_args, paths=paths, args_option="--pyright-args"
75
79
  ),
76
80
  )
81
+
82
+
83
+ @task(help={"args": ARGS_HELP})
84
+ def check_public_api(c: Context, *, args: str | None = None) -> None:
85
+ r"""Check that the public API of the package is fully typed.
86
+
87
+ It runs ``pyright --verifytypes <package> --ignoreexternal`` on
88
+ ``tasklib.package.import_name``, which fails if the type
89
+ completeness score is below 100 %. The symbols of the other
90
+ packages are ignored.
91
+
92
+ pyright reads the package of the first ``python`` of the ``PATH``,
93
+ which is the one of the environment that runs Invoke, so no
94
+ activation is needed. The package must be installed in that
95
+ environment (editable or not) and have a ``py.typed`` file.
96
+
97
+ Args:
98
+ c: The invoke context.
99
+ args: Extra arguments for pyright, e.g. ``"--verbose"``.
100
+
101
+ Raises:
102
+ Exit: If ``args`` cannot be split or ``pyright`` is not found.
103
+ UnexpectedExit: If pyright fails: the public API is not fully
104
+ typed, or the package or its ``py.typed`` file is not found.
105
+ """
106
+ name = load_config(c).package.import_name
107
+ with step(c, "🔬 Checking the types of the public API...", "✅ Public API check passed"):
108
+ words = ["pyright", "--verifytypes", name, "--ignoreexternal"]
109
+ run(c, build_command(words, args=args))
@@ -10,7 +10,7 @@ only-include = ["src", "tests"]
10
10
 
11
11
  [project]
12
12
  name = "invoke-tasklib"
13
- version = "0.1.0"
13
+ version = "0.1.1"
14
14
  description = "Reusable Invoke tasks shared across Python projects."
15
15
  readme = "README.md"
16
16
  authors = [{ name = "Thibaut Durand", email = "durand.tibo+gh@gmail.com" }]
@@ -70,6 +70,7 @@ def test_list_succeeds(project: Path) -> None:
70
70
  "security.audit",
71
71
  "test.unit",
72
72
  "types.check",
73
+ "types.check-public-api",
73
74
  ],
74
75
  )
75
76
  def test_list_contains_the_task(project: Path, task: str) -> None:
@@ -62,6 +62,7 @@ def project(tmp_path: Path) -> Path:
62
62
  "format.check-python",
63
63
  "lint.check-python",
64
64
  "types.check",
65
+ "types.check-public-api",
65
66
  "test.unit",
66
67
  "test.doctest",
67
68
  "imports.check-cycles",
@@ -0,0 +1,70 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import subprocess
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ import pytest
9
+
10
+ SRC = Path(__file__).parents[2] / "src"
11
+ TYPED = 'def one() -> int:\n r"""Return 1."""\n return 1\n'
12
+ UNTYPED = 'def one(x):\n r"""Return x."""\n return x\n'
13
+
14
+
15
+ def _check_public_api(project: Path) -> subprocess.CompletedProcess[str]:
16
+ r"""Run ``types.check-public-api`` in ``project``.
17
+
18
+ The virtual environment is not activated: its directory is not on
19
+ the ``PATH``. ``PYTHONPATH`` makes the packages of ``site``
20
+ importable, like installed ones.
21
+ """
22
+ bin_dir = Path(sys.executable).parent
23
+ path = [d for d in os.environ["PATH"].split(os.pathsep) if Path(d) != bin_dir]
24
+ pythonpath = os.pathsep.join([str(SRC), str(project / "site")])
25
+ env = {**os.environ, "PYTHONPATH": pythonpath, "PATH": os.pathsep.join(path)}
26
+ env.pop("VIRTUAL_ENV", None)
27
+ return subprocess.run(
28
+ [sys.executable, "-m", "invoke", "types.check-public-api"],
29
+ cwd=project,
30
+ capture_output=True,
31
+ text=True,
32
+ check=False,
33
+ env=env,
34
+ )
35
+
36
+
37
+ @pytest.fixture
38
+ def project(tmp_path: Path) -> Path:
39
+ r"""Create a project with a typed package ``demo`` in ``site``."""
40
+ (tmp_path / "tasks.py").write_text("from invoke_tasklib import make_ns\n\nns = make_ns()\n")
41
+ (tmp_path / "invoke.yaml").write_text("tasklib:\n package:\n name: demo\n")
42
+ package = tmp_path / "site" / "demo"
43
+ package.mkdir(parents=True)
44
+ (package / "__init__.py").write_text(TYPED)
45
+ (package / "py.typed").touch()
46
+ return tmp_path
47
+
48
+
49
+ ############################################
50
+ # Tests for types.check-public-api #
51
+ ############################################
52
+
53
+
54
+ def test_check_public_api_passes_on_a_typed_package(project: Path) -> None:
55
+ assert _check_public_api(project).returncode == 0
56
+
57
+
58
+ def test_check_public_api_fails_on_an_untyped_function(project: Path) -> None:
59
+ (project / "site" / "demo" / "__init__.py").write_text(UNTYPED)
60
+ assert _check_public_api(project).returncode == 1
61
+
62
+
63
+ def test_check_public_api_fails_without_py_typed(project: Path) -> None:
64
+ (project / "site" / "demo" / "py.typed").unlink()
65
+ assert "No py.typed file found" in _check_public_api(project).stdout
66
+
67
+
68
+ def test_check_public_api_finds_an_installed_package(project: Path) -> None:
69
+ (project / "invoke.yaml").write_text("tasklib:\n package:\n name: invoke_tasklib\n")
70
+ assert 'Symbols exported by "invoke_tasklib"' in _check_public_api(project).stdout
@@ -83,6 +83,7 @@ def test_ns_contains_the_complete_list_of_tasks() -> None:
83
83
  "test.integration",
84
84
  "test.unit",
85
85
  "types.check",
86
+ "types.check-public-api",
86
87
  ]
87
88
 
88
89
 
@@ -167,7 +168,8 @@ def test_make_ns_exclude_a_task_keeps_its_siblings() -> None:
167
168
 
168
169
 
169
170
  def test_make_ns_exclude_all_tasks_of_a_namespace_removes_it() -> None:
170
- assert "types" not in make_ns(exclude=["types.check"]).collections
171
+ ns = make_ns(exclude=["types.check", "types.check-public-api"])
172
+ assert "types" not in ns.collections
171
173
 
172
174
 
173
175
  def test_make_ns_exclude_a_namespace_keeps_its_step_in_check() -> None:
@@ -110,3 +110,51 @@ def test_check_args_go_to_the_configured_checker() -> None:
110
110
  def test_check_says_which_checker_it_runs(capsys: pytest.CaptureFixture[str]) -> None:
111
111
  typecheck.check(make_context(_with_checker("mypy")))
112
112
  assert capsys.readouterr().out == "🔬 Checking type hints with mypy...\n✅ Type check passed\n"
113
+
114
+
115
+ ######################################
116
+ # Tests for check_public_api #
117
+ ######################################
118
+
119
+
120
+ def test_check_public_api() -> None:
121
+ c = make_context(_CFG)
122
+ typecheck.check_public_api(c)
123
+ assert commands(c) == ["pyright --verifytypes mypkg --ignoreexternal"]
124
+
125
+
126
+ def test_check_public_api_uses_the_import_name() -> None:
127
+ c = make_context({"package": {"name": "my-pkg", "import_name": "my_module"}})
128
+ typecheck.check_public_api(c)
129
+ assert commands(c) == ["pyright --verifytypes my_module --ignoreexternal"]
130
+
131
+
132
+ @pytest.mark.parametrize("checker", ["ty", "pyright", "mypy"])
133
+ def test_check_public_api_runs_pyright_with_any_checker(checker: str) -> None:
134
+ c = make_context(_with_checker(checker))
135
+ typecheck.check_public_api(c)
136
+ assert commands(c) == ["pyright --verifytypes mypkg --ignoreexternal"]
137
+
138
+
139
+ def test_check_public_api_args() -> None:
140
+ c = make_context(_CFG)
141
+ typecheck.check_public_api(c, args="--verbose --outputjson")
142
+ assert commands(c) == ["pyright --verifytypes mypkg --ignoreexternal --verbose --outputjson"]
143
+
144
+
145
+ def test_check_public_api_args_are_quoted() -> None:
146
+ c = make_context(_CFG)
147
+ typecheck.check_public_api(c, args="--project 'my dir'")
148
+ assert commands(c) == ["pyright --verifytypes mypkg --ignoreexternal --project 'my dir'"]
149
+
150
+
151
+ def test_check_public_api_rejects_unbalanced_args() -> None:
152
+ with pytest.raises(Exit, match=r"Cannot parse the value of --args"):
153
+ typecheck.check_public_api(make_context(_CFG), args="'unclosed")
154
+
155
+
156
+ def test_check_public_api_says_what_it_does(capsys: pytest.CaptureFixture[str]) -> None:
157
+ typecheck.check_public_api(make_context(_CFG))
158
+ assert capsys.readouterr().out == (
159
+ "🔬 Checking the types of the public API...\n✅ Public API check passed\n"
160
+ )
File without changes