Skip to content

Commit

Permalink
fix: path mapping source_os renamed to source_path_format
Browse files Browse the repository at this point in the history
The field name `source_os` in a path mapping rule's definition was
determined to be somewhat ambiguous in its meaning. So, it is being
changed to `source_path_format`. This commit applies the change.

Signed-off-by: Daniel Neilson <[email protected]>
  • Loading branch information
ddneilson committed Sep 13, 2023
1 parent 443ffb2 commit afa6779
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 53 deletions.
22 changes: 17 additions & 5 deletions src/openjd/adaptor_runtime/adaptors/_path_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class PathMappingRule:
def __init__(
self,
*,
source_os: str,
source_path_format: str,
source_path: str,
destination_path: str,
destination_os: str = OSName(),
):
for label, value in (
("source_os", source_os),
("source_path_format", source_path_format),
("source_path", source_path),
("destination_path", destination_path),
):
Expand All @@ -60,8 +60,10 @@ def __init__(

self.source_path: str = source_path
self.destination_path: str = destination_path
self._source_os: str = OSName(source_os) # Raises ValueError if not valid OS
self._is_windows_source: bool = OSName.is_windows(self._source_os)
self._source_path_format: str = OSName(
source_path_format
) # Raises ValueError if not valid OS
self._is_windows_source: bool = OSName.is_windows(self._source_path_format)

self._destination_os: str = OSName(destination_os) # Raises ValueError if not valid OS
self._is_windows_destination: bool = OSName.is_windows(self._destination_os)
Expand Down Expand Up @@ -91,13 +93,23 @@ def from_dict(*, rule: dict[str, str]) -> PathMappingRule:
if not rule:
raise ValueError("Empty path mapping rule")

# TODO - DELETE ONCE MIGRATION COMPLETE
# The field "source_os" was renamed to "source_path_format", but interfaces may still
# provide the old name until they're updated. Remove once we're sure all interfaces are
# updated.
if "source_os" in rule:
new_rule = dict(**rule)
new_rule["source_path_format"] = new_rule["source_os"]
del new_rule["source_os"]
rule = new_rule
# END TODO
return PathMappingRule(**rule)

def to_dict(self) -> dict[str, str]:
"""Builds a PathMappingRule given a dict with the fields required by __init__
raises TypeError, ValueError: if rule is None, an empty dict, or nonvalid"""
return {
"source_os": self._source_os,
"source_path_format": self._source_path_format,
"source_path": self.source_path,
"destination_os": self._destination_os,
"destination_path": self.destination_path,
Expand Down
2 changes: 1 addition & 1 deletion src/openjd/adaptor_runtime_client/client_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# due to some applications running an older Python version that can't import newer typing
@_dataclass
class PathMappingRule:
source_os: str
source_path_format: str
source_path: str
destination_path: str
destination_os: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_one_rule(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage1",
Expand All @@ -59,13 +59,13 @@ def test_many_rules(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/asset_storage0",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage0",
},
{
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage1",
Expand All @@ -84,13 +84,13 @@ def test_many_rules(self) -> None:
def test_get_order_is_preserved(self) -> None:
# GIVEN
rule1 = {
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage1",
}
rule2 = {
"source_os": "windows",
"source_path_format": "windows",
"source_path": "Z:\\asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\should\\not\\reach\\this",
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_rule_list_is_read_only(self) -> None:
adaptor = FakeCommandAdaptor(expected)
rules = adaptor.path_mapping_rules
new_rule = PathMappingRule(
source_os="linux",
source_path_format="linux",
source_path="/mnt/shared/asset_storage1",
destination_os="windows",
destination_path="Z:\\asset_storage1",
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_linux_to_windows(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage1",
Expand All @@ -174,7 +174,7 @@ def test_windows_to_linux(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "windows",
"source_path_format": "windows",
"source_path": "Z:\\asset_storage1",
"destination_os": "linux",
"destination_path": "/mnt/shared/asset_storage1",
Expand All @@ -194,7 +194,7 @@ def test_linux_to_linux(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/my_custom_path/asset_storage1",
"destination_os": "linux",
"destination_path": "/mnt/shared/asset_storage1",
Expand All @@ -215,7 +215,7 @@ def test_windows_to_windows(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "windows",
"source_path_format": "windows",
"source_path": "Z:\\my_custom_asset_path\\asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage1",
Expand All @@ -235,7 +235,7 @@ def test_windows_capitalization_agnostic(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "windows",
"source_path_format": "windows",
"source_path": "Z:\\my_custom_asset_path\\asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage1",
Expand All @@ -255,7 +255,7 @@ def test_windows_directory_separator_agnostic(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "windows",
"source_path_format": "windows",
"source_path": "Z:\\my_custom_asset_path\\asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage1",
Expand All @@ -275,13 +275,13 @@ def test_multiple_rules(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/asset_storage0",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage0",
},
{
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage1",
Expand All @@ -301,13 +301,13 @@ def test_only_first_applied(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage1",
},
{
"source_os": "windows",
"source_path_format": "windows",
"source_path": "Z:\\asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\should\\not\\reach\\this",
Expand All @@ -327,13 +327,13 @@ def test_apply_order_is_preserved(self) -> None:
# GIVEN
path_mapping_rules = [
{
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\asset_storage1",
},
{
"source_os": "linux",
"source_path_format": "linux",
"source_path": "/mnt/shared/asset_storage1",
"destination_os": "windows",
"destination_path": "Z:\\should\\not\\reach\\this",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def on_run(self, run_data: dict):

path_mapping_rules = [
{
"source_os": "windows",
"source_path_format": "windows",
"source_path": "Z:\\asset_storage1",
"destination_os": "linux",
"destination_path": "/mnt/shared/asset_storage1",
},
{
"source_os": "windows",
"source_path_format": "windows",
"source_path": "🌚\\🌒\\🌓\\🌔\\🌝\\🌖\\🌗\\🌘\\🌚",
"destination_os": "linux",
"destination_path": "🌝/🌖/🌗/🌘/🌚/🌒/🌓/🌔/🌝",
Expand Down
Loading

0 comments on commit afa6779

Please sign in to comment.