Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: path mapping source_os renamed to source_path_format #2

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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