Skip to content
Open
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
13 changes: 8 additions & 5 deletions lean/components/util/project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def _format_local_path(self, cloud_path: str) -> str:
"""Converts the given cloud path into a local path which is valid for the current operating system.

:param cloud_path: the path of the project in the cloud
:return: the converted cloud_path so that it is valid locally
:return: a valid relative local path, or "_" if the cloud path names no components
"""
# Remove forbidden characters and OS-specific path separator that are not path separators on QuantConnect
# Windows, \":*?"<>| are forbidden
Expand All @@ -459,6 +459,10 @@ def _format_local_path(self, cloud_path: str) -> str:
new_components = []

for component in cloud_path.split("/"):
# Leading, trailing and repeated separators don't name a directory
if not component:
continue

# Some names are reserved
for reserved_name in reserved_names:
# If the component is a reserved name, we add an underscore to it so it can be used
Expand All @@ -471,11 +475,10 @@ def _format_local_path(self, cloud_path: str) -> str:
# Components cannot end with a period
component = component.rstrip(".")

new_components.append(component)

cloud_path = "/".join(new_components)
# An empty component would be dropped from the path or make it absolute, outside the workspace
new_components.append(component or "_")

return cloud_path
return "/".join(new_components) or "_"


def _generate_python_library_projects_config(self) -> None:
Expand Down
17 changes: 17 additions & 0 deletions tests/components/util/test_project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,20 @@ def test_get_cloud_projects_libraries_filters_libraries_that_cannot_be_accessed(

assert _lists_are_equal(libraries, own_project_libraries)
assert _lists_are_equal(libraries_not_found, collab_libraries)


@pytest.mark.parametrize("cloud_name,expected_name", [(":/Strategy", "_/Strategy"),
("Folder/ /Strategy", "Folder/_/Strategy"),
("../Strategy", "_/Strategy"),
("::", "_"),
("/Strategy", "Strategy"),
("Folder/Strategy/", "Folder/Strategy"),
("", "_"),
("///", "_")])
def test_get_local_project_path_stays_inside_workspace_when_a_component_sanitizes_to_nothing(cloud_name: str,
expected_name: str) -> None:
project_manager = _create_project_manager()

local_path = project_manager.get_local_project_path(cloud_name, cloud_id=1)

assert local_path == Path.cwd() / expected_name
Loading