Skip to content

Commit d295261

Browse files
authored
Merge pull request #282 from networktocode/release-2.0.1
Release 2.0.1
2 parents ebc88b3 + d82d5b0 commit d295261

16 files changed

+170
-76
lines changed

.readthedocs.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ sphinx:
66
configuration: "docs/source/conf.py"
77
fail_on_warning: false
88

9+
build:
10+
os: "ubuntu-22.04"
11+
tools:
12+
python: "3.11"
13+
914
python:
10-
version: "3.7"
1115
install:
1216
- requirements: "docs/requirements.txt"
1317
- method: "pip"

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## [2.0.1]
8+
9+
### Changed
10+
11+
- #276 - Removed upper version boud for `structlog` dependency
12+
13+
### Fixed
14+
15+
- #281 - Properly deprecated `DiffSync` class name
16+
- #273 - Properly capitalized `DiffSync` in documentation
17+
- #273 - Removed more mentions of `DiffSync` in favor of `Adapter`
18+
- #274 - Fixed doc section title for getting started
19+
- #269 - Fixed wording for a couple of docstrings
20+
- #265 - Fixed readthedocs build
21+
722
## [2.0.0]
823

924
### Changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ DiffSync is at its most useful when you have multiple sources or sets of data to
1717

1818
DiffSync acts as an intermediate translation layer between all of the data sets you are diffing and/or syncing. In practical terms, this means that to use DiffSync, you will define a set of data models as well as the “adapters” needed to translate between each base data source and the data model. In Python terms, the adapters will be subclasses of the `Adapter` class, and each data model class will be a subclass of the `DiffSyncModel` class.
1919

20-
![Diffsync Components](https://raw.githubusercontent.com/networktocode/diffsync/develop/docs/images/diffsync_components.png "Diffsync Components")
20+
![DiffSync Components](https://raw.githubusercontent.com/networktocode/diffsync/develop/docs/images/diffsync_components.png "DiffSync Components")
2121

2222

2323
Once you have used each adapter to load each data source into a collection of data model records, you can then ask DiffSync to “diff” the two data sets, and it will produce a structured representation of the difference between them. In Python, this is accomplished by calling the `diff_to()` or `diff_from()` method on one adapter and passing the other adapter as a parameter.
2424

25-
![Diffsync Diff Creation](https://raw.githubusercontent.com/networktocode/diffsync/develop/docs/images/diffsync_diff_creation.png "Diffsync Diff Creation")
25+
![DiffSync Diff Creation](https://raw.githubusercontent.com/networktocode/diffsync/develop/docs/images/diffsync_diff_creation.png "DiffSync Diff Creation")
2626

2727
You can also ask DiffSync to “sync” one data set onto the other, and it will instruct your adapter as to the steps it needs to take to make sure that its data set accurately reflects the other. In Python, this is accomplished by calling the `sync_to()` or `sync_from()` method on one adapter and passing the other adapter as a parameter.
2828

29-
![Diffsync Sync](https://raw.githubusercontent.com/networktocode/diffsync/develop/docs/images/diffsync_sync.png "Diffsync Sync")
29+
![DiffSync Sync](https://raw.githubusercontent.com/networktocode/diffsync/develop/docs/images/diffsync_sync.png "DiffSync Sync")
3030

3131
# Simple Example
3232

diffsync/__init__.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
Any,
2929
Set,
3030
)
31-
import warnings
31+
from typing_extensions import deprecated
3232

3333
from pydantic import ConfigDict, BaseModel, PrivateAttr
3434
import structlog # type: ignore
@@ -425,7 +425,7 @@ def remove_child(self, child: "DiffSyncModel") -> None:
425425

426426

427427
class Adapter: # pylint: disable=too-many-public-methods
428-
"""Class for storing a group of DiffSyncModel instances and diffing/synchronizing to another DiffSync instance."""
428+
"""Class for storing a group of DiffSyncModel instances and diffing/synchronizing to another Adapter instance."""
429429

430430
# In any subclass, you would add mapping of names to specific model classes here:
431431
# modelname1 = MyModelClass1
@@ -480,7 +480,7 @@ def __init_subclass__(cls) -> None:
480480
raise AttributeError(f'top_level references attribute "{name}" but it is not a DiffSyncModel subclass!')
481481

482482
def __str__(self) -> StrType:
483-
"""String representation of a DiffSync."""
483+
"""String representation of an Adapter."""
484484
if self.type != self.name:
485485
return f'{self.type} "{self.name}"'
486486
return self.type
@@ -526,7 +526,7 @@ def dict(self, exclude_defaults: bool = True, **kwargs: Any) -> Dict[str, Dict[s
526526
return data
527527

528528
def str(self, indent: int = 0) -> StrType:
529-
"""Build a detailed string representation of this DiffSync."""
529+
"""Build a detailed string representation of this Adapter."""
530530
margin = " " * indent
531531
output = ""
532532
for modelname in self.top_level:
@@ -835,7 +835,7 @@ def remove(self, obj: DiffSyncModel, remove_children: bool = False) -> None:
835835
def get_or_instantiate(
836836
self, model: Type[DiffSyncModel], ids: Dict, attrs: Optional[Dict] = None
837837
) -> Tuple[DiffSyncModel, bool]:
838-
"""Attempt to get the object with provided identifiers or instantiate it with provided identifiers and attrs.
838+
"""Attempt to get the object with provided identifiers or instantiate and add it with provided identifiers and attrs.
839839
840840
Args:
841841
model: The DiffSyncModel to get or create.
@@ -848,7 +848,7 @@ def get_or_instantiate(
848848
return self.store.get_or_instantiate(model=model, ids=ids, attrs=attrs)
849849

850850
def get_or_add_model_instance(self, obj: DiffSyncModel) -> Tuple[DiffSyncModel, bool]:
851-
"""Attempt to get the object with provided obj identifiers or instantiate obj.
851+
"""Attempt to get the object with provided obj identifiers or add obj.
852852
853853
Args:
854854
obj: An obj of the DiffSyncModel to get or add.
@@ -894,15 +894,10 @@ def count(self, model: Union[StrType, "DiffSyncModel", Type["DiffSyncModel"], No
894894
return self.store.count(model=model)
895895

896896

897-
def DiffSync(*args: Any, **kwargs: Any) -> Adapter: # noqa pylint: disable=invalid-name
897+
@deprecated("'diffsync.DiffSync' is deprecated and will be removed with 2.1, use 'diffsync.Adapter' instead.")
898+
class DiffSync(Adapter):
898899
"""For backwards-compatibility, keep around the old name."""
899900

900-
warnings.warn(
901-
"'diffsync.DiffSync' is deprecated and will be removed with 2.1, use 'diffsync.Adapter' instead.",
902-
DeprecationWarning,
903-
)
904-
return Adapter(*args, **kwargs)
905-
906901

907902
# DiffSyncModel references Adapter and Adapter references DiffSyncModel. Break the typing loop:
908903
DiffSyncModel.model_rebuild()

docs/requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
m2r2==0.2.7
1+
m2r2==0.3.3.post2
22
mistune==0.8.4
3-
sphinx==4.5.0
3+
sphinx==6.2.1
44
toml==0.10.2
5-
sphinx-rtd-theme==1.0.0
5+
sphinx-rtd-theme==2.0.0

docs/source/core_engine/01-flags.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ diff = nautobot.diff_from(local, flags=flags)
2424
| Name | Description | Binary Value |
2525
|---|---|---|
2626
| CONTINUE_ON_FAILURE | Continue synchronizing even if failures are encountered when syncing individual models. | 0b1 |
27-
| SKIP_UNMATCHED_SRC | Ignore objects that only exist in the source/"from" DiffSync when determining diffs and syncing. If this flag is set, no new objects will be created in the target/"to" DiffSync. | 0b10 |
28-
| SKIP_UNMATCHED_DST | Ignore objects that only exist in the target/"to" DiffSync when determining diffs and syncing. If this flag is set, no objects will be deleted from the target/"to" DiffSync. | 0b100 |
27+
| SKIP_UNMATCHED_SRC | Ignore objects that only exist in the source/"from" adapter when determining diffs and syncing. If this flag is set, no new objects will be created in the target/"to" adapter. | 0b10 |
28+
| SKIP_UNMATCHED_DST | Ignore objects that only exist in the target/"to" adapter when determining diffs and syncing. If this flag is set, no objects will be deleted from the target/"to" adapter. | 0b100 |
2929
| SKIP_UNMATCHED_BOTH | Convenience value combining both SKIP_UNMATCHED_SRC and SKIP_UNMATCHED_DST into a single flag | 0b110 |
3030
| LOG_UNCHANGED_RECORDS | If this flag is set, a log message will be generated during synchronization for each model, even unchanged ones. | 0b1000 |
3131

@@ -57,8 +57,8 @@ class MyAdapter(Adapter):
5757
|---|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
5858
| IGNORE | Do not render diffs containing this model; do not make any changes to this model when synchronizing. Can be used to indicate a model instance that exists but should not be changed by DiffSync. | 0b1 |
5959
| SKIP_CHILDREN_ON_DELETE | When deleting this model, do not recursively delete its children. Can be used for the case where deletion of a model results in the automatic deletion of all its children. | 0b10 |
60-
| SKIP_UNMATCHED_SRC | Ignore the model if it only exists in the source/"from" DiffSync when determining diffs and syncing. If this flag is set, no new model will be created in the target/"to" DiffSync. | 0b100 |
61-
| SKIP_UNMATCHED_DST | Ignore the model if it only exists in the target/"to" DiffSync when determining diffs and syncing. If this flag is set, the model will not be deleted from the target/"to" DiffSync. | 0b1000 |
60+
| SKIP_UNMATCHED_SRC | Ignore the model if it only exists in the source/"from" adapter when determining diffs and syncing. If this flag is set, no new model will be created in the target/"to" adapter. | 0b100 |
61+
| SKIP_UNMATCHED_DST | Ignore the model if it only exists in the target/"to" adapter when determining diffs and syncing. If this flag is set, the model will not be deleted from the target/"to" adapter. | 0b1000 |
6262
| SKIP_UNMATCHED_BOTH | Convenience value combining both SKIP_UNMATCHED_SRC and SKIP_UNMATCHED_DST into a single flag | 0b1100 |
6363
| NATURAL_DELETION_ORDER | When deleting, delete children before instances of this model. | 0b10000 |
6464

docs/source/core_engine/03-store.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Store backends
22

3-
By default, `Diffsync` supports a local memory storage. All the loaded models from the adapters will be stored in memory, and become available for the diff calculation and sync process. This default behavior works well when executing all the steps in the same process, having access to the same memory space. However, if you want to scale out the execution of the tasks, running it in different processes or in totally different workers, a more distributed memory support is necessary.
3+
By default, DiffSync supports a local memory storage. All the loaded models from the adapters will be stored in memory, and become available for the diff calculation and sync process. This default behavior works well when executing all the steps in the same process, having access to the same memory space. However, if you want to scale out the execution of the tasks, running it in different processes or in totally different workers, a more distributed memory support is necessary.
44

55
The `store` is a class attribute in the `Adapter` class, but all the store operations in that class are abstracted in the following methods: `get_all_model_names`, `get`, `get_by_uids`, `add`, `update`, `remove`, `get_or_instantiate`, `update_or_instantiate` and `count`.
66

77
## Use the `LocalStore` Backend
88

9-
When you initialize the `Diffsync` Adapter class, there is an optional keyed-argument, `internal_storage_engine`, defaulting to the `LocalStore` class.
9+
When you initialize the `Adapter` class, there is an optional keyed-argument, `internal_storage_engine`, defaulting to the `LocalStore` class.
1010

1111
```python
1212
>> > from diffsync import Adapter

docs/source/getting_started/01-getting-started.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class Cable(DiffSyncModel):
9797
[...]
9898

9999

100-
class Nautobot(DiffSync):
100+
class Nautobot(Adapter):
101101
site = Site
102102
device = Device
103103
interface = Interface
@@ -121,15 +121,15 @@ Would result in processing in the following order for each element until there i
121121
- ip_address
122122
- cable
123123

124-
> Note: This applies to the actual diff sync (`Diffsync.sync_from/Diffsync.sync_to`), and not the loading of the data (`Diffsync.load`), which is up to the developer to determine the order.
124+
> Note: This applies to the actual diff sync (`Adapter.sync_from` and `Adapter.sync_to`), and not the loading of the data (`Adapter.load`), which is up to the developer to determine the order.
125125
126126
This can be visualized here in the included diagram.
127127

128128
![Preorder Tree Traversal](../../images/preorder-tree-traversal.drawio.png "Preorder Tree Traversal")
129129

130130
### Mapping Tree Traversal with `get_tree_traversal` method
131131

132-
For your convenience, there is a helper method that will provide a mapping of the order. The `DiffSync.get_tree_traversal()` class method will return a tree-like string, or optionally a dictionary when passing the `as_dict=True` parameter.
132+
For your convenience, there is a helper method that will provide a mapping of the order. The `Adapter.get_tree_traversal()` class method will return a tree-like string, or optionally a dictionary when passing the `as_dict=True` parameter.
133133

134134
```python
135135
>>> from nautobot_device_onboarding.network_importer.adapters.network_device.adapter import NetworkImporterAdapter
@@ -150,7 +150,7 @@ NetworkImporterAdapter
150150
To add a site to the local cache/store, you need to pass a valid `DiffSyncModel` object to the `add()` function.
151151

152152
```python
153-
class BackendA(DiffSync):
153+
class BackendA(Adapter):
154154
[...]
155155

156156
def load(self):
@@ -203,14 +203,14 @@ class Device(DiffSyncModel):
203203
If you prefer to update the entire remote system with the final state after performing all individual create/update/delete operations (as might be the case if your "remote system" is a single YAML or JSON file), the easiest place to implement this logic is in the `sync_complete()` callback method that is automatically invoked by DiffSync upon completion of a sync operation.
204204

205205
```python
206-
class BackendA(DiffSync):
206+
class BackendA(Adapter):
207207
[...]
208208

209-
def sync_complete(self, source: DiffSync, diff: Diff, flags: DiffSyncFlags, logger: structlog.BoundLogger):
209+
def sync_complete(self, source: Adapter, diff: Diff, flags: DiffSyncFlags, logger: structlog.BoundLogger):
210210
## TODO add your own logic to update the remote system now.
211211
# The various parameters passed to this method are for your convenience in implementing more complex logic, and
212212
# can be ignored if you do not need them.
213213
#
214-
# The default DiffSync.sync_complete() method does nothing, but it's always a good habit to call super():
214+
# The default Adapter.sync_complete() method does nothing, but it's always a good habit to call super():
215215
super().sync_complete(source, diff, flags, logger)
216216
```

docs/source/getting_started/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#########
2-
Upgrading
2+
Getting started
33
#########
44

55
.. mdinclude:: 01-getting-started.md

docs/source/upgrading/01-upgrading-to-2.0.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
With diffsync 2.0, there a couple of breaking changes. What they are and how to deal with them is described in this document.
44

5-
## Rename of the `diffsync.Diffsync` class to `diffsync.Adapter`
5+
## Rename of the `diffsync.DiffSync` class to `diffsync.Adapter`
66

7-
The main diffsync class `diffsync.Diffsync` has been renamed to `diffsync.Adapter` as we have found that this is the verbiage that is most often used by users and explains the intent of the class clearer. The old name will still be around until 2.1, but is considered deprecated at this point.
7+
The main diffsync class `diffsync.DiffSync` has been renamed to `diffsync.Adapter` as we have found that this is the verbiage that is most often used by users and explains the intent of the class clearer. The old name will still be around until 2.1, but is considered deprecated at this point.
88

99
As a consequence, a lot of fields have been renamed all across diffsync. To the end user, this will most prominently appear in the signature of the `create` method, where you will have to rename the `diffsync` parameter to `adapter`.
1010

examples/03-remote-system/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export NAUTOBOT_TOKEN = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
3434

3535
The first time you run this example, a lot of changes should be reported between Nautobot and the local data because by default the demo instance doesn't have the subregion defined.
3636
After the first sync, on subsequent runs, the diff should show no changes.
37-
At this point, `Diffsync` will be able to identify and fix all changes in Nautobot. You can try to add/update or delete any country in Nautobot and DiffSync will automatically catch it and it will fix it with running in sync mode.
37+
At this point, DiffSync will be able to identify and fix all changes in Nautobot. You can try to add/update or delete any country in Nautobot and DiffSync will automatically catch it and it will fix it with running in sync mode.
3838

3939
```
4040
### DIFF Compare the data between Nautobot and the local JSON file.

examples/05-nautobot-peeringdb/adapter_nautobot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Diffsync adapter class for Nautobot."""
1+
"""DiffSync adapter class for Nautobot."""
22
# pylint: disable=import-error,no-name-in-module
33
import pynautobot
44
from models import RegionModel, SiteModel

examples/05-nautobot-peeringdb/adapter_peeringdb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Diffsync adapter class for PeeringDB."""
1+
"""DiffSync adapter class for PeeringDB."""
22
# pylint: disable=import-error,no-name-in-module
33
import os
44
import requests

0 commit comments

Comments
 (0)