Skip to content

Commit 1b8cc97

Browse files
author
Zach Moody
authored
Merge pull request #256 from digitalocean/5.0
5.0.0 Release
2 parents fb8aa8c + 522a3b8 commit 1b8cc97

31 files changed

+1000
-1000
lines changed

.github/workflows/py2pr.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: PR Test
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python: [2.7]
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Setup Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: ${{ matrix.python }}
20+
21+
- name: Install pynetbox and testing packages.
22+
run: pip install . mock
23+
24+
- name: Run Tests
25+
run: python -m unittest discover
26+

.github/workflows/pr.yml renamed to .github/workflows/py3pr.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python: [2.7, 3.6]
11+
python: [3.6, 3.8]
1212

1313
steps:
1414
- uses: actions/checkout@v2
@@ -19,13 +19,11 @@ jobs:
1919
python-version: ${{ matrix.python }}
2020

2121
- name: Install pynetbox and testing packages.
22-
run: pip install . pycodestyle mock
22+
run: pip install . black pytest
2323

2424
- name: Run Linter
25-
run: |
26-
pycodestyle pynetbox
27-
pycodestyle --ignore=E501 tests
25+
run: black --check .
2826

2927
- name: Run Tests
30-
run: python -m unittest discover
28+
run: pytest
3129

docs/advanced.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Custom Sessions
2+
===============
3+
4+
Custom sessions can be used to modify the default HTTP behavior. Below are a few examples, most of them from `here <https://hodovi.ch/blog/advanced-usage-python-requests-timeouts-retries-hooks/>`_.
5+
6+
Headers
7+
*******
8+
9+
To set a custom header on all requests. These headers are automatically merged with headers pynetbox sets itself.
10+
11+
:Example:
12+
13+
>>> import pynetbox
14+
>>> import requests
15+
>>> session = requests.Session()
16+
>>> session.headers = {"mycustomheader": "test"}
17+
>>> nb = pynetbox.api(
18+
... 'http://localhost:8000',
19+
... private_key_file='/path/to/private-key.pem',
20+
... token='d6f4e314a5b5fefd164995169f28ae32d987704f'
21+
... )
22+
>>> nb.http_session = session
23+
24+
25+
SSL Verification
26+
****************
27+
28+
To disable SSL verification. See `the docs <https://requests.readthedocs.io/en/stable/user/advanced/#ssl-cert-verification>`_.
29+
30+
:Example:
31+
32+
>>> import pynetbox
33+
>>> import requests
34+
>>> session = requests.Session()
35+
>>> session.verify = False
36+
>>> nb = pynetbox.api(
37+
... 'http://localhost:8000',
38+
... private_key_file='/path/to/private-key.pem',
39+
... token='d6f4e314a5b5fefd164995169f28ae32d987704f'
40+
... )
41+
>>> nb.http_session = session
42+
43+
44+
Timeouts
45+
********
46+
47+
Setting timeouts requires the use of Adapters.
48+
49+
:Example:
50+
51+
.. code-block:: python
52+
53+
from requests.adapters import HTTPAdapter
54+
55+
class TimeoutHTTPAdapter(HTTPAdapter):
56+
def __init__(self, *args, **kwargs):
57+
self.timeout = kwargs.get("timeout", 5)
58+
super().__init__(*args, **kwargs)
59+
60+
def send(self, request, **kwargs):
61+
kwargs['timeout'] = self.timeout
62+
return super().send(request, **kwargs)
63+
64+
adapter = TimeoutHTTPAdapter()
65+
session = requests.Session()
66+
session.mount("http://", adapter)
67+
session.mount("https://", adapter)
68+
69+
nb = pynetbox.api(
70+
'http://localhost:8000',
71+
private_key_file='/path/to/private-key.pem',
72+
token='d6f4e314a5b5fefd164995169f28ae32d987704f'
73+
)
74+
nb.http_session = session
75+

docs/conf.py

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
import os
2020
import sys
2121
from pkg_resources import get_distribution
22-
sys.path.insert(0, os.path.abspath('../'))
22+
23+
sys.path.insert(0, os.path.abspath("../"))
2324

2425

2526
# -- General configuration ------------------------------------------------
@@ -31,33 +32,33 @@
3132
# Add any Sphinx extension module names here, as strings. They can be
3233
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3334
# ones.
34-
extensions = ['sphinx.ext.autodoc']
35+
extensions = ["sphinx.ext.autodoc"]
3536

3637
# Add any paths that contain templates here, relative to this directory.
37-
templates_path = ['_templates']
38+
templates_path = ["_templates"]
3839

3940
# The suffix(es) of source filenames.
4041
# You can specify multiple suffix as a list of string:
4142
#
4243
# source_suffix = ['.rst', '.md']
43-
source_suffix = '.rst'
44+
source_suffix = ".rst"
4445

4546
# The master toctree document.
46-
master_doc = 'index'
47+
master_doc = "index"
4748

4849
# General information about the project.
49-
project = u'pynetbox'
50-
copyright = u'2017, DigitalOcean'
51-
author = u'Zach Moody'
50+
project = u"pynetbox"
51+
copyright = u"2017, DigitalOcean"
52+
author = u"Zach Moody"
5253

5354
# The version info for the project you're documenting, acts as replacement for
5455
# |version| and |release|, also used in various other places throughout the
5556
# built documents.
5657
# The full version, including alpha/beta/rc tags.
57-
release = get_distribution('pynetbox').version
58+
release = get_distribution("pynetbox").version
5859
#
5960
# The short X.Y version.
60-
version = '.'.join(release.split('.')[:2])
61+
version = ".".join(release.split(".")[:2])
6162

6263
# The language for content autogenerated by Sphinx. Refer to documentation
6364
# for a list of supported languages.
@@ -69,10 +70,10 @@
6970
# List of patterns, relative to source directory, that match files and
7071
# directories to ignore when looking for source files.
7172
# This patterns also effect to html_static_path and html_extra_path
72-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
73+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7374

7475
# The name of the Pygments (syntax highlighting) style to use.
75-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7677

7778
# If true, `todo` and `todoList` produce output, else they produce nothing.
7879
todo_include_todos = False
@@ -96,18 +97,14 @@
9697
# so a file named "default.css" will overwrite the builtin "default.css".
9798
# html_static_path = ['_static']
9899

99-
html_sidebars = {'**': [
100-
'globaltoc.html',
101-
'relations.html',
102-
'sourcelink.html',
103-
'searchbox.html'
104-
]
100+
html_sidebars = {
101+
"**": ["globaltoc.html", "relations.html", "sourcelink.html", "searchbox.html"]
105102
}
106103

107104
# -- Options for HTMLHelp output ------------------------------------------
108105

109106
# Output file base name for HTML help builder.
110-
htmlhelp_basename = 'pynetboxdoc'
107+
htmlhelp_basename = "pynetboxdoc"
111108

112109

113110
# -- Options for LaTeX output ---------------------------------------------
@@ -116,15 +113,12 @@
116113
# The paper size ('letterpaper' or 'a4paper').
117114
#
118115
# 'papersize': 'letterpaper',
119-
120116
# The font size ('10pt', '11pt' or '12pt').
121117
#
122118
# 'pointsize': '10pt',
123-
124119
# Additional stuff for the LaTeX preamble.
125120
#
126121
# 'preamble': '',
127-
128122
# Latex figure (float) alignment
129123
#
130124
# 'figure_align': 'htbp',
@@ -134,19 +128,15 @@
134128
# (source start file, target name, title,
135129
# author, documentclass [howto, manual, or own class]).
136130
latex_documents = [
137-
(master_doc, 'pynetbox.tex', u'pynetbox Documentation',
138-
u'Zach Moody', 'manual'),
131+
(master_doc, "pynetbox.tex", u"pynetbox Documentation", u"Zach Moody", "manual"),
139132
]
140133

141134

142135
# -- Options for manual page output ---------------------------------------
143136

144137
# One entry per manual page. List of tuples
145138
# (source start file, name, description, authors, manual section).
146-
man_pages = [
147-
(master_doc, 'pynetbox', u'pynetbox Documentation',
148-
[author], 1)
149-
]
139+
man_pages = [(master_doc, "pynetbox", u"pynetbox Documentation", [author], 1)]
150140

151141

152142
# -- Options for Texinfo output -------------------------------------------
@@ -155,7 +145,13 @@
155145
# (source start file, target name, title, author,
156146
# dir menu entry, description, category)
157147
texinfo_documents = [
158-
(master_doc, 'pynetbox', u'pynetbox Documentation',
159-
author, 'pynetbox', 'A python library for NetBox.',
160-
'Miscellaneous'),
148+
(
149+
master_doc,
150+
"pynetbox",
151+
u"pynetbox Documentation",
152+
author,
153+
"pynetbox",
154+
"A python library for NetBox.",
155+
"Miscellaneous",
156+
),
161157
]

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Instantiate the :py:class:`.Api`. Use the methods available on :py:class:`.Endpo
1414
API
1515
===
1616

17-
.. autoclass:: pynetbox.api.Api
17+
.. autoclass:: pynetbox.core.api.Api
1818
:members:
1919

2020
App
2121
===
2222

23-
.. autoclass:: pynetbox.api.App
23+
.. autoclass:: pynetbox.core.app.App
2424
:members:
2525

2626
Indices and tables

pynetbox/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pkg_resources import get_distribution, DistributionNotFound
22

33
from pynetbox.core.query import RequestError, AllocationError, ContentError
4-
from pynetbox.api import Api as api
4+
from pynetbox.core.api import Api as api
55

66
try:
77
__version__ = get_distribution(__name__).version

0 commit comments

Comments
 (0)