Skip to content

Commit becb053

Browse files
Add entry point to enable installing with pipx or uvx (#211)
* Add entry point to enable installing with pipx or uvx * Tests added for running the module and calling the entry point. * Add return type annotation * reformat * Try adding BINDIR to python and entry point * Add missing BINDIR paths * Add docstring to test.
1 parent 466d2b2 commit becb053

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@
3030
package_data={"": ["py.typed"]},
3131
use_calver="%Y.%m.%d.%H",
3232
setup_requires=["calver"],
33+
entry_points={
34+
"console_scripts": ["trove-classifiers=trove_classifiers.__main__:cli"],
35+
},
3336
)

src/trove_classifiers/__main__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
from trove_classifiers import sorted_classifiers
22

3-
for classifier in sorted_classifiers:
4-
print(classifier)
3+
4+
def cli() -> None:
5+
for classifier in sorted_classifiers:
6+
print(classifier)
7+
8+
9+
if __name__ == "__main__":
10+
cli()

tests/test_cli.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""test_cli.py - Tests to confirm that the CLI works and that both running the module and
2+
calling the entry point produce equivalent output.
3+
"""
4+
5+
import subprocess
6+
import sys
7+
from pathlib import Path
8+
9+
BINDIR = Path(sys.executable).parent
10+
11+
12+
def test_module_run():
13+
"""Simple test for no error when running the module. Output is not validated."""
14+
subprocess.check_call([f"{BINDIR}/python", "-m", "trove_classifiers"])
15+
16+
17+
def test_entry_point():
18+
"""Simple test for no error when calling the entry point. Output is not validated."""
19+
subprocess.check_call(f"{BINDIR}/trove-classifiers")
20+
21+
22+
def test_module_run_is_entry_point():
23+
"""Compare that module run output is the same as entry point output."""
24+
module_run_proc = subprocess.run(
25+
[f"{BINDIR}/python", "-m", "trove_classifiers"],
26+
capture_output=True,
27+
encoding="utf-8",
28+
)
29+
entry_point_proc = subprocess.run(
30+
f"{BINDIR}/trove-classifiers", capture_output=True, encoding="utf-8"
31+
)
32+
assert module_run_proc.stdout == entry_point_proc.stdout

0 commit comments

Comments
 (0)