Skip to content

Commit

Permalink
tests/helpers: remove python 2 compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Apr 9, 2022
1 parent cacb0bf commit 2ec33e8
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from poetry.packages import Locker
from poetry.repositories import Repository
from poetry.repositories.exceptions import PackageNotFound
from poetry.utils._compat import WINDOWS


if TYPE_CHECKING:
Expand Down Expand Up @@ -67,27 +66,12 @@ def fixture(path: str | None = None) -> Path:


def copy_or_symlink(source: Path, dest: Path) -> None:
if dest.exists():
if dest.is_symlink():
os.unlink(str(dest))
elif dest.is_dir():
shutil.rmtree(str(dest))
else:
os.unlink(str(dest))

# Python2 does not support os.symlink on Windows whereas Python3 does.
# os.symlink requires either administrative privileges or developer mode on Win10,
# throwing an OSError if neither is active.
if WINDOWS:
try:
os.symlink(str(source), str(dest), target_is_directory=source.is_dir())
except OSError:
if source.is_dir():
shutil.copytree(str(source), str(dest))
else:
shutil.copyfile(str(source), str(dest))
else:
os.symlink(str(source), str(dest))
if dest.is_symlink() or dest.is_file():
dest.unlink() # missing_ok is only available in Python >= 3.8
elif dest.is_dir():
shutil.rmtree(dest)

os.symlink(str(source), str(dest), target_is_directory=source.is_dir())


class MockDulwichRepo:
Expand Down

0 comments on commit 2ec33e8

Please sign in to comment.