Skip to content

Commit de8c43e

Browse files
authored
preparing to add additional endpoints and start of tests (#4)
* preparing to add additional endpoints and start of tests Signed-off-by: vsoch <[email protected]>
1 parent 62f057b commit de8c43e

File tree

15 files changed

+296
-19
lines changed

15 files changed

+296
-19
lines changed

.github/workflows/main.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ jobs:
1111
formatting:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v1
15-
14+
- uses: actions/checkout@v2
1615
- name: Setup black linter
1716
run: conda create --quiet --name black pyflakes
1817

@@ -37,3 +36,20 @@ jobs:
3736
pyflakes usrse/*.py
3837
pyflakes usrse/utils/fileio.py
3938
pyflakes usrse/utils/terminal.py
39+
40+
testing:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v2
44+
45+
- name: Setup black linter
46+
run: conda create --quiet --name testing pytest
47+
48+
- name: Run Tests
49+
run: |
50+
export PATH="/usr/share/miniconda/bin:$PATH"
51+
source activate testing
52+
pip install -e .
53+
cd usrse/tests
54+
/bin/bash test_client.sh
55+
pytest -xsv test_*.py

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.com/USRSE/usrse-python/tree/main) (0.0.x)
17+
- Adding support for jobs and member counts endpoint (0.0.11)
1718
- Initial creation of project (0.0.1)

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ See our ⭐️ [Documentation](https://us-rse.org/usrse-python/) to get started!
1111

1212
## Coming Soon / TODO
1313

14-
- full tests for all endpoints
1514
- automated deployment to pypi on release
1615
- nightly test run to ensure US-RSE static API functioning as expected
17-
- endpoints for jobs and then functions here
16+
- other endpoints and functions here
1817

1918
## Contributors
2019

docs/getting_started/index.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
Getting Started
55
===============
66

7-
Singularity Registry (HPC) is a tool that makes it easy to install containers as
8-
Lmod modules. You can create your own registry entries (e.g., a specification
9-
to pull a particular container and expose some number of entrypoints) or
10-
the library also provides you with a community set.
11-
12-
If you have any questions or issues, please `let us know <https://github.com/singularityhub/singularity-hpc/issues>`_
7+
USRSE-Python provides easy ways to interact with content from the US-RSE website
8+
and community!
9+
If you have any questions or issues, please `let us know <https://github.com/USRSE/usrse-python/issues>`_
1310

1411
.. toctree::
1512
:maxdepth: 2

docs/getting_started/user-guide.rst

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ Once you have usrse installed, you likely quickly want to get data
2828

2929
.. code-block:: console
3030
31-
$ usrse get posts
32-
$ usrse get newsletters
33-
$ usrse get dei
34-
$ usrse get events
31+
$ usrse get posts
32+
$ usrse get newsletters
33+
$ usrse get dei
34+
$ usrse get events
35+
$ usrse get member-counts
36+
$ usrse get jobs
3537
3638
Or snazz things up a bit!
3739

@@ -41,6 +43,8 @@ Or snazz things up a bit!
4143
$ usrse get newsletters --live
4244
$ usrse get dei --live
4345
$ usrse get events --live
46+
$ usrse get member-counts --live
47+
$ usrse get jobs --live
4448
4549
Or output as json or save to json for later.
4650

@@ -60,6 +64,36 @@ Commands
6064

6165
The following commands are available!
6266

67+
.. _getting_started-commands-list:
68+
69+
List
70+
----
71+
72+
The first thing you might want to do is see what endpoints are available.
73+
You can do that with ``list``:
74+
75+
.. code-block:: console
76+
77+
$ usrse list
78+
dei
79+
events
80+
jobs
81+
member-counts
82+
newsletters
83+
posts
84+
85+
86+
This is also nice to pipe into a bash loop for doing something:
87+
88+
.. code-block:: console
89+
90+
for endpoint in $(usrse list); do
91+
# do something here
92+
echo $endpoint;
93+
done
94+
95+
Once you know endpoints, then you can ``get`` them, discussed next.
96+
6397
.. _getting_started-commands-get:
6498

6599
Get
@@ -79,6 +113,8 @@ The most basic functionality is to get content. Here are all the types we can as
79113
posts
80114
dei
81115
newsletters
116+
member-counts
117+
jobs
82118
83119
optional arguments:
84120
-h, --help show this help message and exit
@@ -133,6 +169,8 @@ Here are all the content types you can ask for:
133169
$ usrse get newsletters
134170
$ usrse get dei
135171
$ usrse get events
172+
$ usrse get member-counts
173+
$ usrse get jobs
136174
137175
Want to have some fun? Try the live tables!
138176

@@ -143,6 +181,8 @@ Want to have some fun? Try the live tables!
143181
$ usrse get newsletters --live
144182
$ usrse get dei --live
145183
$ usrse get events --live
184+
$ usrse get member-counts --live
185+
$ usrse get jobs --live
146186
147187
148188
Changing the baseurl

usrse/client/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
__license__ = "MPL 2.0"
66

77
import usrse
8+
import usrse.main.endpoints as endpoints
89
from usrse.logger import setup_logger
910
import argparse
1011
import sys
@@ -59,6 +60,9 @@ def get_parser():
5960
# print version and exit
6061
subparsers.add_parser("version", description="show software version")
6162

63+
# List endpoints available
64+
subparsers.add_parser("list", description="list endpoints available")
65+
6266
# Local shell with client loaded
6367
shell = subparsers.add_parser(
6468
"shell",
@@ -82,7 +86,7 @@ def get_parser():
8286
)
8387
get.add_argument(
8488
"content_type",
85-
help="content type\nevents\nposts\ndei\nnewsletters",
89+
help="content type\n%s" % "\n".join(endpoints.register_names),
8690
)
8791
get.add_argument("--json", help="output json", default=False, action="store_true")
8892
get.add_argument("--all", help="output json", default=False, action="store_true")
@@ -151,6 +155,8 @@ def help(return_code=0):
151155
from .get import main
152156
elif args.command == "shell":
153157
from .shell import main
158+
elif args.command == "list":
159+
from .listing import main
154160

155161
# Pass on to the correct parser
156162
return_code = 0

usrse/client/listing.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
__author__ = "Vanessa Sochat"
2+
__copyright__ = "Copyright 2022, Vanessa Sochat"
3+
__license__ = "MPL 2.0"
4+
5+
import usrse.main.endpoints as endpoints
6+
7+
8+
def main(args, parser, extra, subparser):
9+
for endpoint in endpoints.register_names:
10+
print(endpoint)

usrse/main/client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ class Result:
2727
"""
2828

2929
def __init__(self, data, endpoint):
30-
self.data = data or {}
3130
self.endpoint = endpoint
3231

32+
# Does the endpoint want to sort or otherwise order?
33+
data = data or {}
34+
self.data = self.endpoint.order(data)
35+
3336
# Keep track of the max length for each field not truncated
3437
self.max_widths = {}
3538
self.ensure_complete()
@@ -42,7 +45,10 @@ def available_width(self, columns):
4245
Calculate available width based on fields we cannot truncate (urls)
4346
"""
4447
# We will determine column width based on terminal size
45-
width = os.get_terminal_size().columns
48+
try:
49+
width = os.get_terminal_size().columns
50+
except OSError:
51+
width = 120
4652

4753
# Calculate column width
4854
column_width = int(width / len(columns))
@@ -270,4 +276,5 @@ def get(self, name):
270276
result = requests.get(endpoint.url)
271277
if result.status_code != 200:
272278
sys.exit("Issue retrieving %s:\n%s" % (endpoint.url, result.txt))
279+
273280
return Result(result.json(), endpoint)

usrse/main/endpoints.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
__license__ = "MPL 2.0"
44

55
import usrse.defaults as defaults
6+
from datetime import datetime
67
import sys
78

89
# Registered endpoints (populated on init)
@@ -22,6 +23,10 @@ def __init__(self, baseurl):
2223
"Misconfigured endpoint %s missing %s attribute" % (self, attr)
2324
)
2425

26+
# If needed, make sure endpoint data is sorted
27+
def order(self, data):
28+
return data
29+
2530
@property
2631
def url(self):
2732
return self.baseurl + self.path
@@ -52,6 +57,28 @@ class Dei(Endpoint):
5257
emoji = "sparkles"
5358

5459

60+
class Jobs(Endpoint):
61+
name = "jobs"
62+
path = "/api/jobs.json"
63+
emoji = "briefcase"
64+
65+
66+
class MemberCounts(Endpoint):
67+
name = "member-counts"
68+
path = "/api/member-counts.json"
69+
emoji = "1234"
70+
71+
def order(self, data):
72+
"""
73+
Sort by month and year
74+
"""
75+
return sorted(
76+
data,
77+
key=lambda entry: datetime.strptime(entry["date"], "%B %Y"),
78+
reverse=True,
79+
)
80+
81+
5582
class Newsletters(Endpoint):
5683
name = "newsletters"
5784
path = "/api/newsletters.json"
@@ -72,6 +99,8 @@ class Events(Endpoint):
7299
skips = ["repeated", "published", "description"]
73100

74101

75-
for endpoint in [Dei, Newsletters, Posts, Events]:
102+
for endpoint in [Dei, Newsletters, Posts, Events, Jobs, MemberCounts]:
76103
register_names.append(endpoint.name)
77104
register[endpoint.name] = endpoint
105+
106+
register_names.sort()

usrse/tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)