Skip to content

Commit

Permalink
updated black version and re-ran across repo
Browse files Browse the repository at this point in the history
  • Loading branch information
raddessi committed Feb 5, 2022
1 parent 124c53f commit 348218a
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 73 deletions.
12 changes: 6 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
master_doc = "index"

# General information about the project.
project = u"pynetbox"
copyright = u"2017, DigitalOcean"
author = u"Zach Moody"
project = "pynetbox"
copyright = "2017, DigitalOcean"
author = "Zach Moody"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -128,15 +128,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "pynetbox.tex", u"pynetbox Documentation", u"Zach Moody", "manual"),
(master_doc, "pynetbox.tex", "pynetbox Documentation", "Zach Moody", "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "pynetbox", u"pynetbox Documentation", [author], 1)]
man_pages = [(master_doc, "pynetbox", "pynetbox Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -148,7 +148,7 @@
(
master_doc,
"pynetbox",
u"pynetbox Documentation",
"pynetbox Documentation",
author,
"pynetbox",
"A python library for NetBox.",
Expand Down
19 changes: 14 additions & 5 deletions pynetbox/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ class Api(object):
"""

def __init__(
self, url, token=None, private_key=None, private_key_file=None, threading=False,
self,
url,
token=None,
private_key=None,
private_key_file=None,
threading=False,
):
if private_key and private_key_file:
raise ValueError(
Expand Down Expand Up @@ -127,7 +132,8 @@ def version(self):
>>>
"""
version = Request(
base=self.base_url, http_session=self.http_session,
base=self.base_url,
http_session=self.http_session,
).get_version()
return version

Expand All @@ -149,7 +155,8 @@ def openapi(self):
>>>
"""
return Request(
base=self.base_url, http_session=self.http_session,
base=self.base_url,
http_session=self.http_session,
).get_openapi()

def status(self):
Expand Down Expand Up @@ -181,12 +188,14 @@ def status(self):
>>>
"""
status = Request(
base=self.base_url, token=self.token, http_session=self.http_session,
base=self.base_url,
token=self.token,
http_session=self.http_session,
).get_status()
return status

def create_token(self, username, password):
""" Creates an API token using a valid NetBox username and password.
"""Creates an API token using a valid NetBox username and password.
Saves the created token automatically in the API object.
Requires NetBox 3.0.0 or newer.
Expand Down
32 changes: 20 additions & 12 deletions pynetbox/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


class App(object):
""" Represents apps in NetBox.
"""Represents apps in NetBox.
Calls to attributes are returned as Endpoint objects.
Expand Down Expand Up @@ -79,7 +79,7 @@ def _set_session_key(self):
).get_session_key()

def choices(self):
""" Returns _choices response from App
"""Returns _choices response from App
.. note::
Expand All @@ -102,7 +102,7 @@ def choices(self):
return self._choices

def custom_choices(self):
""" Returns _custom_field_choices response from app
"""Returns _custom_field_choices response from app
.. note::
Expand All @@ -119,15 +119,18 @@ def custom_choices(self):
'Testfield2': {'Othervalue2': 4, 'Othervalue1': 3}}
"""
custom_field_choices = Request(
base="{}/{}/_custom_field_choices/".format(self.api.base_url, self.name,),
base="{}/{}/_custom_field_choices/".format(
self.api.base_url,
self.name,
),
token=self.api.token,
private_key=self.api.private_key,
http_session=self.api.http_session,
).get()
return custom_field_choices

def config(self):
""" Returns config response from app
"""Returns config response from app
:Returns: Raw response from NetBox's config endpoint.
:Raises: :py:class:`.RequestError` if called for an invalid endpoint.
Expand All @@ -143,7 +146,10 @@ def config(self):
'tags']}}}
"""
config = Request(
base="{}/{}/config/".format(self.api.base_url, self.name,),
base="{}/{}/config/".format(
self.api.base_url,
self.name,
),
token=self.api.token,
private_key=self.api.private_key,
http_session=self.api.http_session,
Expand Down Expand Up @@ -173,22 +179,24 @@ def __getattr__(self, name):
return App(self.api, "plugins/{}".format(name.replace("_", "-")))

def installed_plugins(self):
""" Returns raw response with installed plugins
"""Returns raw response with installed plugins
:returns: Raw response NetBox's installed plugins.
:Example:
>>> nb.plugins.installed_plugins()
[{
'name': 'test_plugin',
'package': 'test_plugin',
'author': 'Dmitry',
'description': 'Netbox test plugin',
'name': 'test_plugin',
'package': 'test_plugin',
'author': 'Dmitry',
'description': 'Netbox test plugin',
'verison': '0.10'
}]
"""
installed_plugins = Request(
base="{}/plugins/installed-plugins".format(self.api.base_url,),
base="{}/plugins/installed-plugins".format(
self.api.base_url,
),
token=self.api.token,
private_key=self.api.private_key,
http_session=self.api.http_session,
Expand Down
6 changes: 4 additions & 2 deletions pynetbox/core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def __init__(self, api, app, name, model=None):
self.token = api.token
self.session_key = api.session_key
self.url = "{base_url}/{app}/{endpoint}".format(
base_url=self.base_url, app=app.name, endpoint=self.name,
base_url=self.base_url,
app=app.name,
endpoint=self.name,
)
self._choices = None

Expand Down Expand Up @@ -443,7 +445,7 @@ def delete(self, objects):
return True if req.delete(data=[{"id": i} for i in cleaned_ids]) else False

def choices(self):
""" Returns all choices from the endpoint.
"""Returns all choices from the endpoint.
The returned dict is also saved in the endpoint object (in
``_choices`` attribute) so that later calls will return the same data
Expand Down
19 changes: 11 additions & 8 deletions pynetbox/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


def calc_pages(limit, count):
""" Calculate number of pages required for full results set. """
"""Calculate number of pages required for full results set."""
return int(count / limit) + (limit % count > 0)


Expand Down Expand Up @@ -165,7 +165,7 @@ def __init__(
self.offset = offset

def get_openapi(self):
""" Gets the OpenAPI Spec """
"""Gets the OpenAPI Spec"""
headers = {
"Content-Type": "application/json;",
}
Expand All @@ -179,7 +179,7 @@ def get_openapi(self):
raise RequestError(req)

def get_version(self):
""" Gets the API version of NetBox.
"""Gets the API version of NetBox.
Issues a GET request to the base URL to read the API version from the
response headers.
Expand All @@ -191,7 +191,10 @@ def get_version(self):
headers = {
"Content-Type": "application/json;",
}
req = self.http_session.get(self.normalize_url(self.base), headers=headers,)
req = self.http_session.get(
self.normalize_url(self.base),
headers=headers,
)
if req.ok:
return req.headers.get("API-Version", "")
else:
Expand Down Expand Up @@ -223,7 +226,7 @@ def get_session_key(self):
raise RequestError(req)

def get_status(self):
""" Gets the status from /api/status/ endpoint in NetBox.
"""Gets the status from /api/status/ endpoint in NetBox.
:Returns: Dictionary as returned by NetBox.
:Raises: RequestError if request is not successful.
Expand All @@ -232,16 +235,16 @@ def get_status(self):
if self.token:
headers["authorization"] = "Token {}".format(self.token)
req = self.http_session.get(
"{}status/".format(self.normalize_url(self.base)), headers=headers,
"{}status/".format(self.normalize_url(self.base)),
headers=headers,
)
if req.ok:
return req.json()
else:
raise RequestError(req)

def normalize_url(self, url):
""" Builds a url for POST actions.
"""
"""Builds a url for POST actions."""
if url[-1] != "/":
return "{}/".format(url)

Expand Down
2 changes: 1 addition & 1 deletion pynetbox/core/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def _add_cache(self, item):
self._init_cache.append((key, get_return(value)))

def _parse_values(self, values):
""" Parses values init arg.
"""Parses values init arg.
Parses values dict at init and sets object attributes with the
values within.
Expand Down
29 changes: 16 additions & 13 deletions pynetbox/models/dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def trace(self):
.path[len(urlsplit(self.api.base_url).path) :]
.split("/")[1:3]
)
return_obj_class = uri_to_obj_class_map.get(app_endpoint, Record,)
return_obj_class = uri_to_obj_class_map.get(
app_endpoint,
Record,
)
this_hop_ret.append(
return_obj_class(hop_item_data, self.endpoint.api, self.endpoint)
)
Expand All @@ -72,16 +75,16 @@ def __str__(self):
class Devices(Record):
"""Devices Object
Represents a device response from netbox.
Represents a device response from netbox.
Attributes:
primary_ip, ip4, ip6 (list): Tells __init__ in Record() to
take the `primary_ip` field's value from the API
response and return an initialized list of IpAddress
objects
device_type (obj): Tells __init__ in Record() to take the
`device_type` field's value from the API response and
return an initialized DeviceType object
Attributes:
primary_ip, ip4, ip6 (list): Tells __init__ in Record() to
take the `primary_ip` field's value from the API
response and return an initialized list of IpAddress
objects
device_type (obj): Tells __init__ in Record() to take the
`device_type` field's value from the API response and
return an initialized DeviceType object
"""

has_details = True
Expand All @@ -94,7 +97,7 @@ class Devices(Record):

@property
def napalm(self):
""" Represents the ``napalm`` detail endpoint.
"""Represents the ``napalm`` detail endpoint.
Returns a DetailEndpoint object that is the interface for
viewing response from the napalm endpoint.
Expand Down Expand Up @@ -171,7 +174,7 @@ class RearPorts(TraceableRecord):
class Racks(Record):
@property
def units(self):
""" Represents the ``units`` detail endpoint.
"""Represents the ``units`` detail endpoint.
Returns a DetailEndpoint object that is the interface for
viewing response from the units endpoint.
Expand All @@ -189,7 +192,7 @@ def units(self):

@property
def elevation(self):
""" Represents the ``elevation`` detail endpoint.
"""Represents the ``elevation`` detail endpoint.
Returns a DetailEndpoint object that is the interface for
viewing response from the elevation endpoint updated in
Expand Down
6 changes: 3 additions & 3 deletions pynetbox/models/ipam.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __str__(self):

@property
def available_ips(self):
""" Represents the ``available-ips`` detail endpoint.
"""Represents the ``available-ips`` detail endpoint.
Returns a DetailEndpoint object that is the interface for
viewing and creating IP addresses inside a prefix.
Expand Down Expand Up @@ -59,7 +59,7 @@ def available_ips(self):

@property
def available_prefixes(self):
""" Represents the ``available-prefixes`` detail endpoint.
"""Represents the ``available-prefixes`` detail endpoint.
Returns a DetailEndpoint object that is the interface for
viewing and creating prefixes inside a parent prefix.
Expand Down Expand Up @@ -107,7 +107,7 @@ def __str__(self):
class VlanGroups(Record):
@property
def available_vlans(self):
""" Represents the ``available-vlans`` detail endpoint.
"""Represents the ``available-vlans`` detail endpoint.
Returns a DetailEndpoint object that is the interface for
viewing and creating VLANs inside a VLAN group.
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
black==19.10b0
black==22.1.0
pytest==6.2.*
pytest-docker==0.10.*
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
use_scm_version=True,
setup_requires=["setuptools_scm"],
packages=find_packages(exclude=["tests", "tests.*"]),
install_requires=["requests>=2.20.0,<3.0", "six==1.*",],
install_requires=[
"requests>=2.20.0,<3.0",
"six==1.*",
],
zip_safe=False,
keywords=["netbox"],
classifiers=[
Expand Down
Loading

0 comments on commit 348218a

Please sign in to comment.