Skip to content

Commit ebee999

Browse files
authored
Avoid get_cache_dir errors with read only virtualenvs (#465)
Fixes: ansible/ansible-lint#4501
1 parent 637ab63 commit ebee999

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,4 @@ src/ansible_compat/_version.py
137137
node_modules
138138
_readthedocs
139139
test/roles/acme.missing_deps/.ansible
140+
.ansible

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ repos:
8787
# empty args needed in order to match mypy cli behavior
8888
args: ["--strict"]
8989
additional_dependencies:
90-
- ansible-core
90+
- ansible-core>=2.16.0
9191
- cached_property
9292
- packaging
9393
- pytest

src/ansible_compat/runtime.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ def prepare_environment( # noqa: C901
661661
role_name_check: int = 0,
662662
) -> None:
663663
"""Make dependencies available if needed."""
664-
destination: Path | None = None
664+
destination: Path = self.cache_dir / "collections"
665665
if required_collections is None:
666666
required_collections = {}
667667

@@ -695,7 +695,6 @@ def prepare_environment( # noqa: C901
695695
destination=destination,
696696
)
697697

698-
destination = self.cache_dir / "collections"
699698
for name, min_version in required_collections.items():
700699
self.install_collection(
701700
f"{name}:>={min_version}",
@@ -704,22 +703,21 @@ def prepare_environment( # noqa: C901
704703

705704
galaxy_path = self.project_dir / "galaxy.yml"
706705
if (galaxy_path).exists():
707-
if destination:
708-
# while function can return None, that would not break the logic
709-
colpath = Path(
710-
f"{destination}/ansible_collections/{colpath_from_path(self.project_dir)}",
711-
)
712-
if colpath.is_symlink():
713-
if os.path.realpath(colpath) == str(Path.cwd()):
714-
_logger.warning(
715-
"Found symlinked collection, skipping its installation.",
716-
)
717-
return
706+
# while function can return None, that would not break the logic
707+
colpath = Path(
708+
f"{destination}/ansible_collections/{colpath_from_path(self.project_dir)}",
709+
)
710+
if colpath.is_symlink():
711+
if os.path.realpath(colpath) == str(Path.cwd()):
718712
_logger.warning(
719-
"Collection is symlinked, but not pointing to %s directory, so we will remove it.",
720-
Path.cwd(),
713+
"Found symlinked collection, skipping its installation.",
721714
)
722-
colpath.unlink()
715+
return
716+
_logger.warning(
717+
"Collection is symlinked, but not pointing to %s directory, so we will remove it.",
718+
Path.cwd(),
719+
)
720+
colpath.unlink()
723721

724722
# molecule scenario within a collection
725723
self.install_collection_from_disk(

0 commit comments

Comments
 (0)