Skip to content

Commit 5288b5f

Browse files
committed
Pylint and pydocstyle
1 parent 9b0ffb1 commit 5288b5f

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

Diff for: examples/example3/diff.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Custom Diff class for DiffSync to influence the behavior of the core Engine."""
12
from diffsync.diff import Diff
23

34

Diff for: examples/example3/local_adapter.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
"""DiffSync adapter to load data from a local file."""
12
import json
23

34
from slugify import slugify
45

5-
from diffsync import DiffSync
66
from models import Region, Country
7+
from diffsync import DiffSync
8+
79

810
COUNTRIES_FILE = "countries.json"
911

@@ -25,14 +27,13 @@ class LocalAdapter(DiffSync):
2527

2628
def load(self, filename=COUNTRIES_FILE):
2729
"""Load all regions and countries from a local JSON file."""
28-
2930
data_file = open(filename, "r")
3031
countries = json.loads(data_file.read())
3132

3233
# Load all regions first
3334
# A Region object will be create for each region and it will be store inside the object with self.add
3435
# To create a Region we are using "self.region" instead of "Region" directly to allow someone to extend this adapter without redefining everything.
35-
region_names = set([country.get("region") for country in countries])
36+
region_names = {country.get("region") for country in countries}
3637
for region in region_names:
3738
self.add(self.region(slug=slugify(region), name=region))
3839

Diff for: examples/example3/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"""Main executable for DiffSync "example2"."""
33
import sys
44
import argparse
5-
import pprint
65

7-
from diffsync import Diff
86
from diffsync.enum import DiffSyncFlags
97
from diffsync.logging import enable_console_logging
108

Diff for: examples/example3/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Main DiffSync models for example3."""
12
from typing import List, Optional
23
from diffsync import DiffSyncModel
34

Diff for: examples/example3/nautobot_adapter.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
"""DiffSync Adapter for Nautobot to manage regions."""
12
import os
23
import pynautobot
34

5+
from nautobot_models import NautobotCountry, NautobotRegion
6+
47
from diffsync import DiffSync
58

6-
from nautobot_models import NautobotCountry, NautobotRegion
79

810
NAUTOBOT_URL = os.getenv("NAUTOBOT_URL", "https://demo.nautobot.com")
911
NAUTOBOT_TOKEN = os.getenv("NAUTOBOT_TOKEN", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
@@ -40,10 +42,11 @@ class NautobotAdapter(DiffSync):
4042

4143
def load(self):
4244
"""Load all data from Nautobot into the internal cache after transformation."""
43-
4445
# Initialize pynautobot to interact with Nautobot and store it within the adapter
4546
# to reuse it later
46-
self.nautobot = pynautobot.api(url=NAUTOBOT_URL, token=NAUTOBOT_TOKEN)
47+
self.nautobot = pynautobot.api(
48+
url=NAUTOBOT_URL, token=NAUTOBOT_TOKEN
49+
) # pylint: disable=attribute-defined-outside-init
4750

4851
# Pull all regions from Nautobot, which includes all regions and all countries
4952
regions = self.nautobot.dcim.regions.all()
@@ -75,10 +78,9 @@ def load(self):
7578

7679
def sync_from(self, *args, **kwargs):
7780
"""Sync the data with Nautobot but first ensure that all the required Custom fields are present in Nautobot."""
78-
7981
# Check if all required custom fields exist, create them if they don't
8082
for custom_field in CUSTOM_FIELDS:
81-
nb_cfs = self.cfs = self.nautobot.extras.custom_fields.filter(name=custom_field.get("name"))
83+
nb_cfs = self.nautobot.extras.custom_fields.filter(name=custom_field.get("name"))
8284
if not nb_cfs:
8385
self.nautobot.extras.custom_fields.create(**custom_field)
8486

Diff for: examples/example3/nautobot_models.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import os
1+
"""Extension of the Base model for the Nautobot DiffSync Adapter to manage the CRUD operations."""
22
import pynautobot
33

4-
54
from diffsync import DiffSync
65
from models import Region, Country
76

@@ -18,7 +17,7 @@ class NautobotRegion(Region):
1817

1918
class NautobotCountry(Country):
2019
"""Extend the Country to manage Country in Nautobot. CREATE/UPDATE/DELETE.
21-
20+
2221
Country are represented in Nautobot as a dcim.region object as well but a country must have a parent.
2322
Subregion information will be store in the description of the object in Nautobot
2423
"""
@@ -38,7 +37,6 @@ def create(cls, diffsync: DiffSync, ids: dict, attrs: dict):
3837
Returns:
3938
NautobotCountry: DiffSync object newly created
4039
"""
41-
4240
# Retrieve the parent region in internal cache to access its UUID
4341
# because the UUID is required to associate the object to its parent region in Nautobot
4442
region = diffsync.get(diffsync.region, attrs.get("region"))
@@ -75,7 +73,6 @@ def update(self, attrs: dict):
7573
Raises:
7674
ObjectNotUpdated: if an error occurred.
7775
"""
78-
7976
# Retrive the pynautobot object from Nautobot since we only have the UUID internally
8077
remote = self.diffsync.nautobot.dcim.regions.get(self.remote_id)
8178

0 commit comments

Comments
 (0)