Skip to content

Commit

Permalink
Use pathlib in relative path computation
Browse files Browse the repository at this point in the history
  • Loading branch information
sjagoe committed Dec 3, 2023
1 parent aac5455 commit 4d163b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 5 additions & 3 deletions haas/plugins/discoverer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from fnmatch import fnmatch
from importlib import import_module
from pathlib import Path
import logging
import os
import sys
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions haas/tests/test_haas_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4d163b8

Please sign in to comment.