Skip to content
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
6 changes: 3 additions & 3 deletions src/zenml/utils/source_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def get_module_source_from_module(module: ModuleType) -> str:

# Kick out the .py and replace `/` with `.` to get the module source
module_path = module_path.replace(".py", "")
module_source = module_path.replace("/", ".")
module_source = module_path.replace(os.path.sep, ".")

logger.debug(
f"Resolved module source for module {module} to: {module_source}"
Expand All @@ -210,7 +210,7 @@ def get_relative_path_from_module_source(module_source: str) -> str:
Args:
module_source: A module e.g. zenml.core.step
"""
return module_source.replace(".", "/")
return module_source.replace(".", os.path.sep)


def get_absolute_path_from_module_source(module: str) -> str:
Expand Down Expand Up @@ -470,7 +470,7 @@ def import_python_file(file_path: str) -> types.ModuleType:
# module
full_module_path = os.path.splitext(
os.path.relpath(file_path, os.getcwd())
)[0].replace("/", ".")
)[0].replace(os.path.sep, ".")

if full_module_path not in sys.modules:
with prepend_python_path(os.path.dirname(file_path)):
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/utils/test_source_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ def test_is_third_party_module():
assert not source_utils.is_third_party_module(non_third_party_file)


class EmptyClass:
pass


def test_resolve_class():
"""Tests that class resolving works as expected."""
os.getcwd()
parent_directory = os.path.dirname(os.path.dirname(__file__))
os.chdir(parent_directory)
try:
assert (
source_utils.resolve_class(EmptyClass)
== "utils.test_source_utils.EmptyClass"
)
finally:
os.chdir(parent_directory)


def test_get_source():
"""Tests if source of objects is gotten properly."""
assert source_utils.get_source(pytest.Cache)
Expand Down