diff --git a/src/openjd/adaptor_runtime/adaptors/_path_mapping.py b/src/openjd/adaptor_runtime/adaptors/_path_mapping.py index b5b4996..c27cc59 100644 --- a/src/openjd/adaptor_runtime/adaptors/_path_mapping.py +++ b/src/openjd/adaptor_runtime/adaptors/_path_mapping.py @@ -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), ): @@ -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) @@ -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, diff --git a/src/openjd/adaptor_runtime_client/client_interface.py b/src/openjd/adaptor_runtime_client/client_interface.py index 9c98d27..1c28ecf 100644 --- a/src/openjd/adaptor_runtime_client/client_interface.py +++ b/src/openjd/adaptor_runtime_client/client_interface.py @@ -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 diff --git a/test/openjd/adaptor_runtime/integ/adaptors/test_integration_path_mapping.py b/test/openjd/adaptor_runtime/integ/adaptors/test_integration_path_mapping.py index f7d813a..1aa6c0b 100644 --- a/test/openjd/adaptor_runtime/integ/adaptors/test_integration_path_mapping.py +++ b/test/openjd/adaptor_runtime/integ/adaptors/test_integration_path_mapping.py @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/test/openjd/adaptor_runtime/integ/application_ipc/test_integration_adaptor_ipc.py b/test/openjd/adaptor_runtime/integ/application_ipc/test_integration_adaptor_ipc.py index e8d36f3..4ef5d1a 100644 --- a/test/openjd/adaptor_runtime/integ/application_ipc/test_integration_adaptor_ipc.py +++ b/test/openjd/adaptor_runtime/integ/application_ipc/test_integration_adaptor_ipc.py @@ -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": "🌝/🌖/🌗/🌘/🌚/🌒/🌓/🌔/🌝", diff --git a/test/openjd/adaptor_runtime/unit/adaptors/test_path_mapping.py b/test/openjd/adaptor_runtime/unit/adaptors/test_path_mapping.py index 4a7b1d7..879d981 100644 --- a/test/openjd/adaptor_runtime/unit/adaptors/test_path_mapping.py +++ b/test/openjd/adaptor_runtime/unit/adaptors/test_path_mapping.py @@ -10,16 +10,22 @@ @pytest.mark.parametrize( "rule", [ - pytest.param({"source_os": "", "source_path": "", "destination_path": ""}), - pytest.param({"source_os": None, "source_path": None, "destination_path": None}), - pytest.param({"source_os": "", "source_path": None, "destination_path": ""}), - pytest.param({"source_os": "", "source_path": "C:/", "destination_path": "/mnt/"}), - pytest.param({"source_os": "windows", "source_path": "", "destination_path": "/mnt/"}), - pytest.param({"source_os": "windows", "source_path": "C:/", "destination_path": ""}), - pytest.param({"source_os": "nonvalid", "source_path": "C:/", "destination_path": "/mnt/"}), + pytest.param({"source_path_format": "", "source_path": "", "destination_path": ""}), + pytest.param({"source_path_format": None, "source_path": None, "destination_path": None}), + pytest.param({"source_path_format": "", "source_path": None, "destination_path": ""}), + pytest.param({"source_path_format": "", "source_path": "C:/", "destination_path": "/mnt/"}), + pytest.param( + {"source_path_format": "windows", "source_path": "", "destination_path": "/mnt/"} + ), + pytest.param( + {"source_path_format": "windows", "source_path": "C:/", "destination_path": ""} + ), + pytest.param( + {"source_path_format": "nonvalid", "source_path": "C:/", "destination_path": "/mnt/"} + ), pytest.param( { - "source_os": "windows", + "source_path_format": "windows", "destination_os": "nonvalid", "source_path": "C:/", "destination_path": "/mnt/", @@ -55,7 +61,7 @@ def test_no_args(rule): def test_good_args(): # GIVEN rule = { - "source_os": "windows", + "source_path_format": "windows", "destination_os": "windows", "source_path": "Y:/movie1", "destination_path": "Z:/movie2", @@ -79,7 +85,9 @@ def test_good_args(): ) def test_path_mapping_linux_is_match(path): # GIVEN - rule = PathMappingRule(source_os="linux", source_path="/usr", destination_path="/mnt/shared") + rule = PathMappingRule( + source_path_format="linux", source_path="/usr", destination_path="/mnt/shared" + ) pure_path = PurePosixPath(path) # WHEN @@ -104,7 +112,7 @@ def test_path_mapping_linux_is_match(path): def test_path_mapping_linux_is_not_match(path): # GIVEN rule = PathMappingRule( - source_os="linux", source_path="/usr/Movie1", destination_path="/mnt/shared/Movie1" + source_path_format="linux", source_path="/usr/Movie1", destination_path="/mnt/shared/Movie1" ) pure_path = PurePosixPath(path) @@ -130,7 +138,7 @@ def test_path_mapping_linux_is_not_match(path): def test_path_mapping_windows_is_match(path): # GIVEN rule = PathMappingRule( - source_os="windows", source_path="Z:\\Movie1", destination_path="/mnt/shared" + source_path_format="windows", source_path="Z:\\Movie1", destination_path="/mnt/shared" ) pure_path = PureWindowsPath(path) @@ -152,7 +160,7 @@ def test_path_mapping_windows_is_match(path): def test_path_mapping_windows_is_not_match(path): # GIVEN rule = PathMappingRule( - source_os="windows", source_path="Z:\\Movie1", destination_path="/mnt/shared" + source_path_format="windows", source_path="Z:\\Movie1", destination_path="/mnt/shared" ) pure_path = PureWindowsPath(path) @@ -168,7 +176,7 @@ def test_no_change(self): # GIVEN rule = PathMappingRule.from_dict( rule={ - "source_os": "linux", + "source_path_format": "linux", "source_path": "/mnt/shared/asset_storage2", "destination_os": "linux", "destination_path": "/mnt/shared/movie2", @@ -187,7 +195,7 @@ def test_linux_to_windows(self): # GIVEN rule = PathMappingRule.from_dict( rule={ - "source_os": "linux", + "source_path_format": "linux", "source_path": "/mnt/shared/asset_storage1", "destination_os": "windows", "destination_path": "Z:\\asset_storage1", @@ -206,7 +214,7 @@ def test_windows_to_linux(self): # GIVEN rule = PathMappingRule.from_dict( rule={ - "source_os": "windows", + "source_path_format": "windows", "source_path": "Z:\\asset_storage1", "destination_os": "linux", "destination_path": "/mnt/shared/asset_storage1", @@ -225,7 +233,7 @@ def test_linux_to_linux(self): # GIVEN rule = PathMappingRule.from_dict( rule={ - "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", @@ -245,7 +253,7 @@ def test_windows_to_windows(self): # GIVEN rule = rule = PathMappingRule.from_dict( rule={ - "source_os": "windows", + "source_path_format": "windows", "source_path": "Z:\\my_custom_asset_path\\asset_storage1", "destination_os": "windows", "destination_path": "Z:\\asset_storage1", @@ -264,7 +272,7 @@ def test_windows_capitalization_agnostic(self): # GIVEN rule = PathMappingRule.from_dict( rule={ - "source_os": "windows", + "source_path_format": "windows", "source_path": "Z:\\my_custom_asset_path\\asset_storage1", "destination_os": "windows", "destination_path": "Z:\\asset_storage1", @@ -283,7 +291,7 @@ def test_windows_directory_separator_agnostic(self): # GIVEN rule = PathMappingRule.from_dict( rule={ - "source_os": "windows", + "source_path_format": "windows", "source_path": "Z:\\my_custom_asset_path\\asset_storage1", "destination_os": "windows", "destination_path": "Z:\\asset_storage1", @@ -302,7 +310,7 @@ def test_windows_directory_separator_agnostic_inverted(self): # GIVEN rule = PathMappingRule.from_dict( rule={ - "source_os": "windows", + "source_path_format": "windows", "source_path": "Z:/my_custom_asset_path/asset_storage1", "destination_os": "windows", "destination_path": "Z:\\asset_storage1", @@ -321,7 +329,7 @@ def test_starts_with_partial_match(self): # GIVEN rule = PathMappingRule.from_dict( rule={ - "source_os": "linux", + "source_path_format": "linux", "source_path": "a/b", "destination_os": "linux", "destination_path": "/c", @@ -340,7 +348,7 @@ def test_partial_match(self): # GIVEN rule = PathMappingRule.from_dict( rule={ - "source_os": "linux", + "source_path_format": "linux", "source_path": "/bar/baz", "destination_os": "linux", "destination_path": "/bla", @@ -358,7 +366,7 @@ def test_partial_match(self): def test_to_dict(self): # GIVEN rule_dict = { - "source_os": "linux", + "source_path_format": "linux", "source_path": "/bar/baz", "destination_os": "linux", "destination_path": "/bla", diff --git a/test/openjd/adaptor_runtime/unit/application_ipc/test_adaptor_http_request_handler.py b/test/openjd/adaptor_runtime/unit/application_ipc/test_adaptor_http_request_handler.py index 55ab875..c6b43e0 100644 --- a/test/openjd/adaptor_runtime/unit/application_ipc/test_adaptor_http_request_handler.py +++ b/test/openjd/adaptor_runtime/unit/application_ipc/test_adaptor_http_request_handler.py @@ -71,7 +71,7 @@ def test_get_returns_mapped_path(self): path_mapping_data={ "path_mapping_rules": [ { - "source_os": "windows", + "source_path_format": "windows", "source_path": SOURCE_PATH, "destination_os": "linux", "destination_path": DEST_PATH, @@ -104,7 +104,7 @@ def test_get_returns_rules(self): SOURCE_PATH = "Z:\\asset_storage1" DEST_PATH = "/mnt/shared/asset_storage1" rules = { - "source_os": "Windows", + "source_path_format": "Windows", "source_path": SOURCE_PATH, "destination_os": "Linux", "destination_path": DEST_PATH, diff --git a/test/openjd/adaptor_runtime_client/unit/test_client_interface.py b/test/openjd/adaptor_runtime_client/unit/test_client_interface.py index 49982ad..e1ec6de 100644 --- a/test/openjd/adaptor_runtime_client/unit/test_client_interface.py +++ b/test/openjd/adaptor_runtime_client/unit/test_client_interface.py @@ -96,7 +96,7 @@ def test_map_path( ( [ { - "source_os": "one", + "source_path_format": "one", "source_path": "here", "destination_os": "two", "destination_path": "there",