Skip to content

Commit d47dc47

Browse files
committed
Define pg_activity script as an entry point
We move pg_activity script as pgactivity/cli.py and transform the __main__ section as a main() function. Then the 'script' keyword in setup() is changed into an 'entry_points'+'console_scripts'; this is the recommended way of shipping script and should fix the wrong shebang on some systems.
1 parent 40c7b68 commit d47dc47

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

Diff for: pg_activity renamed to pgactivity/cli.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
import os
42
import socket
53
import sys
@@ -10,7 +8,7 @@
108
from blessed import Terminal
119
from psycopg2.errors import OperationalError
1210

13-
from pgactivity import __version__, data, types, ui
11+
from . import __version__, data, types, ui
1412

1513

1614
# Customized OptionParser
@@ -255,8 +253,7 @@ def exit(msg: str) -> None:
255253
sys.exit(1)
256254

257255

258-
# Call the main function
259-
if __name__ == "__main__":
256+
def main() -> None:
260257
if os.name != "posix":
261258
sys.exit("FATAL: Platform not supported.")
262259
try:

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.black]
22
line-length = 88
3-
include = '/(pg_activity|\.pyi?)$'
3+
include = '\.pyi?$'
44
exclude = '''
55
(
66
/(

Diff for: setup.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def get_version() -> str:
2929
version=get_version(),
3030
author="Dalibo",
3131
author_email="[email protected]",
32-
scripts=["pg_activity"],
3332
packages=find_packages("."),
3433
include_package_data=True,
3534
url="https://github.com/dalibo/pg_activity",
@@ -61,4 +60,9 @@ def get_version() -> str:
6160
],
6261
},
6362
data_files=data_files,
63+
entry_points={
64+
"console_scripts": [
65+
"pg_activity=pgactivity.cli:main",
66+
],
67+
},
6468
)

Diff for: tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ deps =
2626
flake8
2727
commands =
2828
black --check --diff {toxinidir}
29-
flake8 {toxinidir} {toxinidir}/pg_activity
29+
flake8 {toxinidir}
3030

3131
[testenv:mypy]
3232
deps =
3333
mypy
3434
commands =
35-
mypy pg_activity pgactivity
35+
mypy pgactivity

0 commit comments

Comments
 (0)