diff --git a/haas/plugins/discoverer.py b/haas/plugins/discoverer.py index 8290171..73caf31 100644 --- a/haas/plugins/discoverer.py +++ b/haas/plugins/discoverer.py @@ -8,6 +8,7 @@ from fnmatch import fnmatch from importlib import import_module +from pathlib import Path import logging import os import sys @@ -41,10 +42,11 @@ def test_error(self): def get_relpath(top_level_directory, fullpath): - normalized = os.path.normpath(fullpath) + top_level = Path(top_level_directory).resolve() + normalized = Path(fullpath).resolve() logger.debug('Determine if %r is within %r', - normalized, top_level_directory) - relpath = os.path.relpath(normalized, top_level_directory) + str(normalized), str(top_level_directory)) + relpath = str(normalized.relative_to(top_level)) logger.debug('Relative path is %r', relpath) if os.path.isabs(relpath) or relpath.startswith('..'): raise ValueError('Path not within project: {0}'.format(fullpath)) diff --git a/haas/tests/test_haas_application.py b/haas/tests/test_haas_application.py index 49820cf..036d987 100644 --- a/haas/tests/test_haas_application.py +++ b/haas/tests/test_haas_application.py @@ -380,9 +380,7 @@ def test_multiple_start_directories(self, runner_class, result_class, try: fixture.create(tempdir) - from pathlib import Path - - top_level = str(Path(os.path.join(tempdir, fixture.name)).resolve()) + top_level = os.path.join(tempdir, fixture.name) # When with cd(top_level):