Skip to content

Commit 120f15b

Browse files
authored
Merge pull request #4 from iwr-redmond/main
Add CLI entry point (#3)
2 parents 12d9ce6 + 7e6d7e5 commit 120f15b

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "torchruntime"
7-
version = "1.4.1"
7+
version = "1.4.2"
88
description = "Meant for app developers. A convenient way to install and configure the appropriate version of PyTorch on the user's computer, based on the OS and GPU manufacturer and model number."
99
readme = "README.md"
1010
requires-python = ">=3.0"
@@ -15,6 +15,9 @@ dynamic = [ "dependencies",]
1515
name = "cmdr2"
1616
1717

18+
[project.scripts]
19+
torchruntime = "torchruntime.__main__:main"
20+
1821
[project.urls]
1922
Homepage = "https://github.com/easydiffusion/torchruntime"
2023
"Bug Tracker" = "https://github.com/easydiffusion/torchruntime/issues"

torchruntime/__main__.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
from .installer import install
22

33

4-
def print_usage():
4+
def print_usage(entry_command: str):
55
"""Print usage information with examples."""
66
usage = """
7-
Usage: python -m torchruntime <command> [arguments]
7+
Usage: {entry_command} <command> [arguments]
88
99
Commands:
1010
install Install PyTorch packages
1111
--help Show this help message
1212
1313
Examples:
14-
python -m torchruntime install
15-
python -m torchruntime install torch==2.2.0 torchvision==0.17.0
16-
python -m torchruntime install torch>=2.0.0 torchaudio
17-
python -m torchruntime install torch==2.1.* torchvision>=0.16.0 torchaudio==2.1.0
14+
{entry_command} install
15+
{entry_command} install torch==2.2.0 torchvision==0.17.0
16+
{entry_command} install torch>=2.0.0 torchaudio
17+
{entry_command} install torch==2.1.* torchvision>=0.16.0 torchaudio==2.1.0
1818
1919
If no packages are specified, the latest available versions
2020
of torch, torchaudio and torchvision will be installed.
@@ -26,15 +26,21 @@ def print_usage():
2626
package~=2.1.0 Compatible release
2727
package==2.1.* Any 2.1.x version
2828
package Latest version
29-
"""
29+
""".format(entry_command=entry_command)
3030
print(usage.strip())
3131

3232

3333
def main():
3434
import sys
3535

3636
if len(sys.argv) < 2 or sys.argv[1] in ["--help", "-h"]:
37-
print_usage()
37+
# get the entry point
38+
entry_path = sys.argv[0]
39+
if "__main__.py" in entry_path:
40+
cli = "python -m torchruntime"
41+
else:
42+
cli = "torchruntime"
43+
print_usage(cli)
3844
return
3945

4046
command = sys.argv[1]

0 commit comments

Comments
 (0)