Skip to content

Commit f98b182

Browse files
authored
Add pydocstyle to tox (#215)
1 parent 67b2b90 commit f98b182

File tree

9 files changed

+85
-27
lines changed

9 files changed

+85
-27
lines changed

pyntc/__init__.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""Kickoff functions for getting instancs of device objects.
2-
"""
1+
"""Kickoff functions for getting instancs of device objects."""
32

43
import os
54
import warnings
@@ -22,9 +21,10 @@
2221

2322

2423
def ntc_device(device_type, *args, **kwargs):
25-
"""Instantiate and return an instance of a device subclassed
26-
from ``pyntc.devices.BaseDevice``. ``*args`` and ``*kwargs`` are passed
27-
directly to the device initializer.
24+
"""
25+
Instantiate an instance of a ``pyntc.devices.BaseDevice`` by ``device_type``.
26+
27+
The ``*args`` and ``*kwargs`` are passed directly to the device initializer.
2828
2929
Arguments:
3030
device_type (string): A valid device_type
@@ -36,7 +36,6 @@ def ntc_device(device_type, *args, **kwargs):
3636
Raises:
3737
UnsupportedDeviceError: if the device_type is unsupported.
3838
"""
39-
4039
try:
4140
device_class = supported_devices[device_type]
4241
return device_class(*args, **kwargs)
@@ -45,9 +44,8 @@ def ntc_device(device_type, *args, **kwargs):
4544

4645

4746
def ntc_device_by_name(name, filename=None):
48-
"""Instantiate and return an instance of a device subclassed
49-
from ``pyntc.devices.BaseDevice`` based on its name in an
50-
NTC configuration file.
47+
"""
48+
Instantiate an instance of a ``pyntc.devices.BaseDevice`` from ntc.conf file.
5149
5250
If no filename is given the environment variable PYNTC_CONF is checked
5351
for a path, and then ~/.ntc.conf.
@@ -58,9 +56,8 @@ def ntc_device_by_name(name, filename=None):
5856
the ``name`` argument as section header.
5957
6058
Raises:
61-
DeviceNameNotFoundError: if the name is not found in the
62-
NTC configuration file.
63-
ConfFileNotFoundError: if no NTC configuration can be found.
59+
DeviceNameNotFoundError: If the name is not found in the NTC configuration file.
60+
ConfFileNotFoundError: If no NTC configuration can be found.
6461
"""
6562
config, filename = _get_config_from_file(filename=filename)
6663
sections = config.sections()

pyntc/devices/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""Supported devices are stored here. Every supported device needs a
2-
device_type stored as a string, and a class subclassed from BaseDevice.
3-
"""
1+
"""Device drivers."""
42

53
from .eos_device import EOSDevice
64
from .nxos_device import NXOSDevice

pyntc/devices/base_device.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,8 @@ def vlans(self):
220220
"""
221221
raise NotImplementedError
222222

223-
def facts(self): # noqa: D403
224-
"""
225-
DEPRECATED - Use individual properties to get facts.
226-
"""
223+
def facts(self): # noqa 401
224+
"""DEPRECATED - Use individual properties to get facts."""
227225
warnings.warn("facts() is deprecated; use individual fact properties.", DeprecationWarning)
228226
facts = {
229227
fact: getattr(self, fact, None)

pyntc/devices/ios_device.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,10 @@ def uptime(self):
472472

473473
@property
474474
def uptime_string(self):
475-
"""
476-
Get uptime in format dd:hh:mm.
475+
"""Get uptime in format dd:hh:mm.
476+
477+
Returns:
478+
str: Uptime of device.
477479
"""
478480
if self._uptime_string is None:
479481
version_data = self._raw_version_data()

pyntc/devices/iosxewlc_device.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,14 @@ def install_os(self, image_name, install_mode_delay_factor=20, **vendor_specific
8888
return False
8989

9090
def show(self, command, expect_string=None, **netmiko_args):
91+
"""Run command on device.
92+
93+
Args:
94+
command (str): Command to be ran.
95+
expect_string (str, optional): Expected string from command output. Defaults to None.
96+
97+
Returns:
98+
str: Output of command.
99+
"""
91100
self.enable()
92101
return self._send_command(command, expect_string=expect_string, **netmiko_args)

pyntc/devices/jnpr_device.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ def running_config(self):
403403
def save(self, filename=None):
404404
"""
405405
Save current configuration to device.
406+
406407
If filename is provided, save current configuration to file.
407408
408409
Args:

pyntc/utils/converters.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,21 @@ def convert_dict_by_key(original, key_map, fill_in=False, whitelist=[], blacklis
4242

4343

4444
def convert_list_by_key(original_list, key_map, fill_in=False, whitelist=[], blacklist=[]):
45-
"""Apply a dictionary conversion for all dictionaries in original_list."""
45+
"""Apply a list conversion for all items in original_list.
46+
47+
Args:
48+
original_list (list): Original list to be converted.
49+
key_map (dict): Key map to use to convert list.
50+
fill_in (dict): Whether the returned list should contain
51+
keys and values from the original dictionary if not specified in the key map.
52+
whitelist: If fill_in is True, and whitelist isn't empty, only fill in the keys
53+
in the whitelist in the returned dictionary.
54+
blacklist: If fill_in is True, and blacklist isn't empty, fill in with all keys from
55+
the original dictionary besides those in the blacklist.
56+
57+
Returns:
58+
list: A converted list.
59+
"""
4660
converted_list = []
4761
for original in list(original_list):
4862
converted_list.append(
@@ -53,8 +67,19 @@ def convert_list_by_key(original_list, key_map, fill_in=False, whitelist=[], bla
5367

5468

5569
def recursive_key_lookup(keys, obj):
56-
"""Return obj[keys] if keys is actually a single key.
57-
Otherwise return obj[keys[0]][keys[1]]...[keys[n]] if keys is a list."""
70+
"""
71+
Lookup nested object by indexing through a dictionary sequentally through ``keys``.
72+
73+
Args:
74+
keys (list): The dictionary keys to use to lookup an object.
75+
obj (dict): The dictionary to traverse.
76+
77+
Example:
78+
>>> keys = ["a", "b", "c"]
79+
>>> data = {"a": {"b": {"c": 1}}}
80+
>>> recursive_key_lookup(keys, data)
81+
1
82+
"""
5883
if not isinstance(keys, list):
5984
return obj.get(keys)
6085

pyntc/utils/templates/__init__.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Module to use NTC_TEMPLATES."""
12
import os
23
import textfsm
34

@@ -6,8 +7,14 @@
67

78

89
def get_structured_data(template_name, rawtxt):
9-
"""Returns structured data given raw text using
10-
TextFSM templates
10+
"""Return structured data given raw text using TextFSM templates.
11+
12+
Args:
13+
template_name (str): Name of template to use.
14+
rawtxt (str): Raw output from device.
15+
16+
Returns:
17+
list: A dict per entry returned by TextFSM.
1118
"""
1219
template_file = get_template(template_name)
1320
with open(template_file) as template:
@@ -23,11 +30,24 @@ def get_structured_data(template_name, rawtxt):
2330

2431

2532
def get_template(template_name):
33+
"""Path to the template passed in.
34+
35+
Args:
36+
template_name (str): Name of the template.
37+
38+
Returns:
39+
str: Path to the template.
40+
"""
2641
template_dir = get_template_dir()
2742
return os.path.join(template_dir, template_name)
2843

2944

3045
def get_template_dir():
46+
"""Get directory of NTC_TEMPLATE os environment.
47+
48+
Returns:
49+
str: Path to NTC_TEMPLATES environment variable if set. Otherwise, path to this file.
50+
"""
3151
try:
3252
return os.environ[TEMPLATE_PATH_ENV_VAR]
3353
except KeyError:

tox.ini

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# TODO: Migrate this to unified interface under invoke
77
[tox]
8-
envlist = py{36,37,38},black,flake8,bandit
8+
envlist = py{36,37,38},black,flake8,bandit,pydocstyle
99
skip_missing_interpreters=true
1010
isolated_build = True
1111
download=true
@@ -29,6 +29,10 @@ commands = black ./ --diff --check
2929
deps = flake8
3030
commands = flake8 ./
3131

32+
[testenv:pydocstyle]
33+
deps = pydocstyle
34+
commands = pydocstyle ./
35+
3236
[testenv:bandit]
3337
deps = bandit==1.6.2
3438
commands = bandit -r ./pyntc/ -c .bandit.yml
@@ -52,3 +56,7 @@ exclude =
5256

5357
# line length is handled by black
5458
ignore = E501
59+
60+
[pydocstyle]
61+
match = (?!test_|error).*\.py
62+
match_dir = ^(?!(tmp|\..*|venv|\.venv|test|tables|system_features)).*

0 commit comments

Comments
 (0)