Skip to content

Commit

Permalink
Merge pull request #256 from digitalocean/5.0
Browse files Browse the repository at this point in the history
5.0.0 Release
  • Loading branch information
Zach Moody authored Jun 25, 2020
2 parents fb8aa8c + 522a3b8 commit 1b8cc97
Show file tree
Hide file tree
Showing 31 changed files with 1,000 additions and 1,000 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/py2pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: PR Test

on: [pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python: [2.7]

steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Install pynetbox and testing packages.
run: pip install . mock

- name: Run Tests
run: python -m unittest discover

10 changes: 4 additions & 6 deletions .github/workflows/pr.yml → .github/workflows/py3pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [2.7, 3.6]
python: [3.6, 3.8]

steps:
- uses: actions/checkout@v2
Expand All @@ -19,13 +19,11 @@ jobs:
python-version: ${{ matrix.python }}

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

- name: Run Linter
run: |
pycodestyle pynetbox
pycodestyle --ignore=E501 tests
run: black --check .

- name: Run Tests
run: python -m unittest discover
run: pytest

75 changes: 75 additions & 0 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Custom Sessions
===============

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/>`_.

Headers
*******

To set a custom header on all requests. These headers are automatically merged with headers pynetbox sets itself.

:Example:

>>> import pynetbox
>>> import requests
>>> session = requests.Session()
>>> session.headers = {"mycustomheader": "test"}
>>> nb = pynetbox.api(
... 'http://localhost:8000',
... private_key_file='/path/to/private-key.pem',
... token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.http_session = session


SSL Verification
****************

To disable SSL verification. See `the docs <https://requests.readthedocs.io/en/stable/user/advanced/#ssl-cert-verification>`_.

:Example:

>>> import pynetbox
>>> import requests
>>> session = requests.Session()
>>> session.verify = False
>>> nb = pynetbox.api(
... 'http://localhost:8000',
... private_key_file='/path/to/private-key.pem',
... token='d6f4e314a5b5fefd164995169f28ae32d987704f'
... )
>>> nb.http_session = session


Timeouts
********

Setting timeouts requires the use of Adapters.

:Example:

.. code-block:: python
from requests.adapters import HTTPAdapter
class TimeoutHTTPAdapter(HTTPAdapter):
def __init__(self, *args, **kwargs):
self.timeout = kwargs.get("timeout", 5)
super().__init__(*args, **kwargs)
def send(self, request, **kwargs):
kwargs['timeout'] = self.timeout
return super().send(request, **kwargs)
adapter = TimeoutHTTPAdapter()
session = requests.Session()
session.mount("http://", adapter)
session.mount("https://", adapter)
nb = pynetbox.api(
'http://localhost:8000',
private_key_file='/path/to/private-key.pem',
token='d6f4e314a5b5fefd164995169f28ae32d987704f'
)
nb.http_session = session
58 changes: 27 additions & 31 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import os
import sys
from pkg_resources import get_distribution
sys.path.insert(0, os.path.abspath('../'))

sys.path.insert(0, os.path.abspath("../"))


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

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'pynetbox'
copyright = u'2017, DigitalOcean'
author = u'Zach Moody'
project = u"pynetbox"
copyright = u"2017, DigitalOcean"
author = u"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
# built documents.
# The full version, including alpha/beta/rc tags.
release = get_distribution('pynetbox').version
release = get_distribution("pynetbox").version
#
# The short X.Y version.
version = '.'.join(release.split('.')[:2])
version = ".".join(release.split(".")[:2])

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

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

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

html_sidebars = {'**': [
'globaltoc.html',
'relations.html',
'sourcelink.html',
'searchbox.html'
]
html_sidebars = {
"**": ["globaltoc.html", "relations.html", "sourcelink.html", "searchbox.html"]
}

# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'pynetboxdoc'
htmlhelp_basename = "pynetboxdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -116,15 +113,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -134,19 +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", u"pynetbox Documentation", u"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", u"pynetbox Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -155,7 +145,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pynetbox', u'pynetbox Documentation',
author, 'pynetbox', 'A python library for NetBox.',
'Miscellaneous'),
(
master_doc,
"pynetbox",
u"pynetbox Documentation",
author,
"pynetbox",
"A python library for NetBox.",
"Miscellaneous",
),
]
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Instantiate the :py:class:`.Api`. Use the methods available on :py:class:`.Endpo
API
===

.. autoclass:: pynetbox.api.Api
.. autoclass:: pynetbox.core.api.Api
:members:

App
===

.. autoclass:: pynetbox.api.App
.. autoclass:: pynetbox.core.app.App
:members:

Indices and tables
Expand Down
2 changes: 1 addition & 1 deletion pynetbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pkg_resources import get_distribution, DistributionNotFound

from pynetbox.core.query import RequestError, AllocationError, ContentError
from pynetbox.api import Api as api
from pynetbox.core.api import Api as api

try:
__version__ = get_distribution(__name__).version
Expand Down
Loading

0 comments on commit 1b8cc97

Please sign in to comment.