Skip to content

Commit a37124b

Browse files
committed
sort imports and groom docstrings
1 parent 17609b3 commit a37124b

File tree

8 files changed

+45
-23
lines changed

8 files changed

+45
-23
lines changed

netfoundry/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
""" Interface to NetFoundry API
2-
"""
1+
"""Interface to NetFoundry management API."""
32

3+
from . import _version
44
from .network import Network
55
from .network_group import NetworkGroup
66
from .organization import Organization
77

8-
from . import _version
98
__version__ = _version.get_versions()['version']

netfoundry/ctl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python3
2-
r"""Command-line interface to the NetFoundry API
2+
r"""[Experimental] command-line interface to the NetFoundry API
33
Usage::
44
$ python3 -m netfoundry.ctl --credentials credentials.json
55
66
PYTHON_ARGCOMPLETE_OK
77
"""
8+
89
import pkg_resources # part of setuptools
910
from milc import cli
1011

@@ -34,4 +35,4 @@ def main(cli):
3435
network_group = netfoundry.NetworkGroup(Organization)
3536

3637
if __name__ == '__main__':
37-
cli()
38+
cli()

netfoundry/demo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
import sys
1111
from pathlib import Path
1212

13-
from .organization import Organization
14-
from .network_group import NetworkGroup
1513
from .network import Network
14+
from .network_group import NetworkGroup
15+
from .organization import Organization
1616
from .utility import DC_PROVIDERS
1717

18+
1819
def main():
1920
"""Run the demo script."""
2021
print("DEBUG: running demo script in \"{:s}\"".format(sys.argv[0]))
@@ -453,4 +454,4 @@ def query_yes_no(question: str, default: str="no"):
453454
"(or 'y' or 'n').\n")
454455

455456
if __name__ == '__main__':
456-
main()
457+
main()

netfoundry/network.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Use a network and find and manage its resources."""
2+
13
import json
24
import re # regex
35
import sys
@@ -7,8 +9,9 @@
79

810
from .utility import (DC_PROVIDERS, EXCLUDED_PATCH_PROPERTIES, HOST_PROPERTIES,
911
MAJOR_REGIONS, RESOURCES, STATUS_CODES, VALID_SEPARATORS,
10-
VALID_SERVICE_PROTOCOLS, docstring_parameters, eprint,
11-
http, plural, singular, Utility)
12+
VALID_SERVICE_PROTOCOLS, Utility, docstring_parameters,
13+
eprint, http, plural, singular)
14+
1215
utility = Utility()
1316

1417
class Network:

netfoundry/network_group.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
"""Use a network group and find its networks."""
2+
13
import json
24

3-
from .utility import (RESOURCES, STATUS_CODES, eprint, http, Utility)
5+
from .utility import RESOURCES, STATUS_CODES, Utility, eprint, http
6+
47
utility = Utility()
58

69
class NetworkGroup:

netfoundry/organization.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Use an identity organization and find authorized network groups and networks."""
2+
13
import json
24
import os
35
import re # regex
@@ -10,12 +12,15 @@
1012

1113

1214
class Organization:
13-
""" Default is to use the Organization of the caller's user or API account identity
14-
:param: organization_id is optional string UUID of an alternative Organization
15-
:param: organization_label is optional string `label` property of an alternative Organization
16-
:param token: continue using a session with this optional token from an existing instance of Organization
17-
:param credentials: optional alternative path to API account credentials file, default is ~/.netfoundry/credentials.json
18-
:param proxy: optional HTTP proxy, e.g., http://localhost:8080
15+
"""Authenticate as an identity ID in an organization.
16+
17+
The default is to use the callering identity ID's organization.
18+
19+
:param str organization_id: optional UUID of an alternative organization
20+
:param str organization_label: is optional `label` property of an alternative organization
21+
:param str token: continue using a session with this optional token from an existing instance of organization
22+
:param str credentials: optional alternative path to API account credentials file, default is project, user, or device default directories containing file name credentials.json
23+
:param str proxy: optional HTTP proxy, e.g., http://localhost:8080
1924
"""
2025

2126
def __init__(self,
@@ -24,7 +29,7 @@ def __init__(self,
2429
organization_label: str=None,
2530
token=None,
2631
proxy=None):
27-
32+
"""Initialize an instance of Organization."""
2833
# verify auth endpoint's server certificate if proxy is type SOCKS or None
2934
self.proxy = proxy
3035
if proxy is None:

netfoundry/utility.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1+
"""Shared helper functions, constants, and classes."""
2+
13
import sys # open stderr
24
import unicodedata # case insensitive compare in Utility
35
from re import sub
46

57
import inflect # singular and plural nouns
68
from requests import \
79
Session # HTTP user agent will not emit server cert warnings if verify=False
8-
from urllib3.exceptions import InsecureRequestWarning
9-
1010
from requests import status_codes
1111
from requests.adapters import HTTPAdapter
12-
from urllib3.util.retry import Retry
1312
from urllib3 import disable_warnings
13+
from urllib3.exceptions import InsecureRequestWarning
14+
from urllib3.util.retry import Retry
1415

1516
disable_warnings(InsecureRequestWarning)
1617

1718
class Utility:
19+
"""Shared functions intended for use within the module and without."""
20+
1821
def __init__(self):
22+
"""No-op."""
1923
pass
2024

2125
def camel(self, snake_str):
@@ -40,7 +44,8 @@ def caseless_equal(self, left, right):
4044
return self.normalize_caseless(left) == self.normalize_caseless(right)
4145

4246
class LookupDict(dict):
43-
"""Dictionary lookup object."""
47+
"""Helper class to create a lookup dictionary from a set."""
48+
4449
def __init__(self, name=None):
4550
"""Initialize a lookup dictionary."""
4651
self.name = name
@@ -62,13 +67,15 @@ def eprint(*args, **kwargs):
6267

6368
p = inflect.engine()
6469
def plural(singular):
70+
"""Pluralize a singular form."""
6571
# if already plural then return, else pluralize
6672
if singular[-1:] == 's':
6773
return(singular)
6874
else:
6975
return(p.plural_noun(singular))
7076

7177
def singular(plural):
78+
"""Singularize a plural form."""
7279
return(p.singular_noun(plural))
7380

7481
STATUSES_BY_CODE = {
@@ -170,6 +177,8 @@ def decorated(ref):
170177
DEFAULT_TIMEOUT = 31 # seconds, Gateway Service waits 30s before responding with an error code e.g. 503 and
171178
# so waiting at least 31s is necessary to obtain that information
172179
class TimeoutHTTPAdapter(HTTPAdapter):
180+
"""Configure Python requests library to have retry and timeout defaults."""
181+
173182
def __init__(self, *args, **kwargs):
174183
self.timeout = DEFAULT_TIMEOUT
175184
if "timeout" in kwargs:
@@ -189,4 +198,4 @@ def send(self, request, **kwargs):
189198
http.mount("https://", adapter)
190199
http.mount("http://", adapter)
191200

192-
STATUS_CODES = status_codes
201+
STATUS_CODES = status_codes

netfoundry/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Print the version string."""
22
from ._version import get_versions
3+
34
try:
45
print("v"+get_versions()['version'] )
56
except:

0 commit comments

Comments
 (0)