Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 3ba1569

Browse files
committed
add paperspace exe shim for login/logout
1 parent c4b095a commit 3ba1569

File tree

5 files changed

+62
-27
lines changed

5 files changed

+62
-27
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ Sample usage
1818

1919
4. Download your api key by executing the following:
2020

21-
python -m paperspace.login
21+
paperspace login
2222

23-
Follow the prompts to enter your Paperspace email and password.
23+
Follow the prompts to enter your Paperspace email and password.
2424

25-
You can also enter your credentials directly on the command line as follows:
25+
You can also enter your credentials directly on the command line as follows:
2626

27-
python -m paperspace.login <email> <password> [<api_token_name>]
27+
paperspace login <email> <password> [<api_token_name>]
2828

29-
Note: your api key is cached in ~/.paperspace/config.json
30-
You can remove your cached api key by executing:
29+
Note: your api key is cached in ~/.paperspace/config.json
30+
You can remove your cached api key by executing:
3131

32-
python -m paperspace.logout
32+
paperspace logout
3333

3434
5. Execute the sample script hello.py:
3535

3636
python hello.py
3737

38-
The script will be run on the remote job cluster node, and its output will be
39-
logged locally.
38+
The script will be run on the remote job cluster node, and its output will be
39+
logged locally.
4040

4141

4242
A slightly more complex example
@@ -71,9 +71,10 @@ Other Authentication options
7171

7272
(on linux:) export PAPERSPACE_API_KEY=1qks1hKsU7e1k...
7373

74-
Note: the above methods take precedence over use of the cached api key in
74+
Note: the above methods take precedence over use of the cached api key in
7575
~/.paperspace/config.json
7676

77+
7778
Contributing
7879
============
7980

paperspace/login.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,4 @@ def logout():
110110
with open(config_path, 'w') as outfile:
111111
json.dump(config_data, outfile, indent=2, sort_keys=True)
112112
outfile.write('\n')
113-
114-
if __name__ == '__main__':
115-
email = None
116-
password = None
117-
apiToken = None
118-
if len(sys.argv) > 1:
119-
email = sys.argv[1]
120-
if len(sys.argv) > 2:
121-
password = sys.argv[2]
122-
if len(sys.argv) > 3:
123-
apiToken = sys.argv[3]
124-
if not login(email, password, apiToken):
125-
sys.exit(1)
113+
return True

paperspace/logout.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

paperspace/main.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import sys
2+
import os
3+
4+
from .login import login, logout
5+
6+
7+
def main():
8+
args = sys.argv[:]
9+
prog = os.path.basename(args.pop(0))
10+
11+
if not args:
12+
usage(prog)
13+
14+
cmd = args.pop(0)
15+
16+
if cmd == 'login':
17+
email = None
18+
password = None
19+
apiToken = None
20+
while args:
21+
opt = args.pop(0)
22+
if opt == '--email':
23+
if args:
24+
email = args.pop(0)
25+
elif opt == '--password':
26+
if args:
27+
password = args.pop(0)
28+
elif opt == '--apiToken':
29+
if args:
30+
apiToken = args.pop(0)
31+
elif not email:
32+
email = opt
33+
elif not password:
34+
password = opt
35+
elif not apiToken:
36+
apiToken = opt
37+
return not login(email, password, apiToken)
38+
39+
if cmd == 'logout':
40+
return not logout()
41+
42+
usage(prog)
43+
44+
45+
def usage(prog):
46+
print('usage: %s login [[--email] <user@domain.com>] [[--password] <secretpw>] [[--apiToken] <api token name>]\n %s logout' % (prog, prog))
47+
sys.exit(1)

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@
2929
keywords='paperspace api development library',
3030
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
3131
install_requires=['requests[security]', 'boto3', 'botocore', 'six'],
32+
entry_points={'console_scripts': [
33+
'paperspace = paperspace.main:main',
34+
]},
3235
)

0 commit comments

Comments
 (0)