Skip to content

Commit 6608756

Browse files
committed
Fix collection installation with custom project_dir
- fix bug that disregarded passed project_dir and used cwd instead - updated test dependencies - fixed codecov config
1 parent 443ae74 commit 6608756

File tree

10 files changed

+111
-43
lines changed

10 files changed

+111
-43
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ jobs:
2323
TOX_PARALLEL_NO_SPINNER: 1
2424

2525
steps:
26-
- name: Switch to using Python 3.9 by default
26+
- name: Switch to using Python 3.12 by default
2727
uses: actions/setup-python@v5
2828
with:
29-
python-version: 3.9
29+
python-version: "3.12"
3030
- name: Install tox
3131
run: python3 -m pip install --user "tox>=4.0.0"
3232
- name: Check out src from Git

.github/workflows/tox.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
with:
2525
min_python: "3.9"
2626
max_python: "3.12"
27+
default_python: "3.10"
2728
other_names: |
2829
lint
2930
docs
@@ -32,7 +33,10 @@ jobs:
3233
py39-ansible213
3334
py39-ansible214
3435
py39-ansible215
35-
py311-devel
36+
py310-ansible215
37+
py311-ansible215
38+
py312-ansible216
39+
py312-devel
3640
smoke
3741
platforms: linux,macos
3842
macos: minmax

.pre-commit-config.yaml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ ci:
99
for more information, see https://pre-commit.ci
1010
skip:
1111
# https://github.com/pre-commit-ci/issues/issues/55
12+
- ccv
1213
- pip-compile
1314
# No docker on pre-commit.ci
1415
- validate-config-in-container
1516
default_language_version:
1617
# Needed in order to make pip-compile output predictable.
17-
python: python3.9
18+
python: python3.10
1819
exclude: |
1920
(?x)^(
2021
test/assets/.*
2122
)$
2223
repos:
2324
- repo: https://github.com/astral-sh/ruff-pre-commit
24-
rev: "v0.0.291"
25+
rev: "v0.1.9"
2526
hooks:
2627
- id: ruff
2728
args: [--fix, --exit-non-zero-on-fix]
@@ -35,7 +36,7 @@ repos:
3536
- prettier-plugin-toml
3637
- prettier-plugin-sort-json
3738
- repo: https://github.com/pre-commit/pre-commit-hooks.git
38-
rev: v4.4.0
39+
rev: v4.5.0
3940
hooks:
4041
- id: end-of-file-fixer
4142
- id: trailing-whitespace
@@ -51,23 +52,23 @@ repos:
5152
- id: debug-statements
5253
language_version: python3
5354
- repo: https://github.com/codespell-project/codespell
54-
rev: v2.2.5
55+
rev: v2.2.6
5556
hooks:
5657
- id: codespell
5758
- repo: https://github.com/adrienverge/yamllint.git
58-
rev: v1.32.0
59+
rev: v1.33.0
5960
hooks:
6061
- id: yamllint
6162
files: \.(yaml|yml)$
6263
types: [file, yaml]
6364
entry: yamllint --strict
6465
- repo: https://github.com/psf/black
65-
rev: 23.9.1
66+
rev: 23.12.1
6667
hooks:
6768
- id: black
6869
language_version: python3
6970
- repo: https://github.com/pre-commit/mirrors-mypy
70-
rev: v1.5.1
71+
rev: v1.8.0
7172
hooks:
7273
- id: mypy
7374
# empty args needed in order to match mypy cli behavior
@@ -84,7 +85,7 @@ repos:
8485
- types-pkg_resources
8586
- types-jsonschema>=4.4.9
8687
- repo: https://github.com/pycqa/pylint
87-
rev: v3.0.0b0
88+
rev: v3.0.3
8889
hooks:
8990
- id: pylint
9091
additional_dependencies:
@@ -117,4 +118,10 @@ repos:
117118
rev: v1.2.0
118119
hooks:
119120
- id: validate-config-in-container
121+
name: packit
120122
alias: packit
123+
- repo: https://github.com/mashi/codecov-validator
124+
rev: "1.0.1"
125+
hooks:
126+
- id: ccv
127+
name: codecov

.vscode/settings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
},
55
"[python]": {
66
"editor.codeActionsOnSave": {
7-
"source.fixAll": true,
8-
"source.fixAll.ruff": false,
9-
"source.organizeImports": false
7+
"source.fixAll": "explicit",
8+
"source.fixAll.ruff": "never",
9+
"source.organizeImports": "never"
1010
}
1111
},
1212
"editor.formatOnSave": true,

codecov.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ codecov:
33
comment: false
44
coverage:
55
status:
6-
patch: false
7-
project:
8-
threshold: 0.5%
6+
patch: true # we want github annotations

requirements.txt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.9
2+
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
55
# pip-compile --extra=docs --extra=test --output-file=requirements.txt --strip-extras --unsafe-package=ansible-core --unsafe-package=resolvelib --unsafe-package=typing_extensions pyproject.toml
@@ -68,7 +68,7 @@ defusedxml==0.7.1
6868
# via
6969
# cairosvg
7070
# mkdocs-ansible
71-
exceptiongroup==1.1.3
71+
exceptiongroup==1.2.0
7272
# via pytest
7373
ghp-import==2.1.0
7474
# via
@@ -87,14 +87,7 @@ idna==3.4
8787
# mkdocs-ansible
8888
# requests
8989
importlib-metadata==6.8.0
90-
# via
91-
# build
92-
# markdown
93-
# mkdocs
94-
# mkdocs-ansible
95-
# mkdocstrings
96-
importlib-resources==5.0.7
97-
# via ansible-core
90+
# via mkdocs-ansible
9891
iniconfig==2.0.0
9992
# via pytest
10093
jinja2==3.1.2
@@ -147,7 +140,9 @@ mkdocs==1.5.3
147140
# mkdocs-monorepo-plugin
148141
# mkdocstrings
149142
mkdocs-ansible==0.2.0
150-
# via ansible-compat (pyproject.toml)
143+
# via
144+
# ansible-compat (pyproject.toml)
145+
# mkdocs-ansible
151146
mkdocs-autorefs==0.5.0
152147
# via
153148
# mkdocs-ansible
@@ -300,12 +295,10 @@ tomli==2.0.1
300295
# pip-tools
301296
# pyproject-hooks
302297
# pytest
303-
typing-extensions==4.8.0 ; python_version < "3.10"
298+
typing-extensions==4.8.0
304299
# via
305-
# ansible-compat (pyproject.toml)
306300
# black
307301
# mkdocs-ansible
308-
# mkdocstrings
309302
urllib3==2.0.5
310303
# via
311304
# mkdocs-ansible

src/ansible_compat/runtime.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def install_collection(
435435
if isinstance(collection, Path):
436436
collection = str(collection)
437437
# As ansible-galaxy install is not able to automatically determine
438-
# if the range requires a pre-release, we need to manuall add the --pre
438+
# if the range requires a pre-release, we need to manually add the --pre
439439
# flag when needed.
440440
matches = version_re.search(collection)
441441

@@ -614,14 +614,14 @@ def prepare_environment( # noqa: C901
614614
destination=destination,
615615
)
616616

617-
if Path("galaxy.yml").exists():
617+
if (self.project_dir / "galaxy.yml").exists():
618618
if destination:
619619
# while function can return None, that would not break the logic
620620
colpath = Path(
621-
f"{destination}/ansible_collections/{colpath_from_path(Path.cwd())}",
621+
f"{destination}/ansible_collections/{colpath_from_path(self.project_dir)}",
622622
)
623623
if colpath.is_symlink():
624-
if os.path.realpath(colpath) == Path.cwd():
624+
if os.path.realpath(colpath) == str(Path.cwd()):
625625
_logger.warning(
626626
"Found symlinked collection, skipping its installation.",
627627
)
@@ -741,7 +741,7 @@ def _prepare_ansible_paths(self) -> None:
741741
msg = "Unexpected ansible configuration"
742742
raise RuntimeError(msg) from exc
743743

744-
alterations_list = [
744+
alterations_list: list[tuple[list[str], str, bool]] = [
745745
(library_paths, "plugins/modules", True),
746746
(roles_path, "roles", True),
747747
]
@@ -762,7 +762,7 @@ def _prepare_ansible_paths(self) -> None:
762762
if must_be_present:
763763
continue
764764
path.mkdir(parents=True, exist_ok=True)
765-
if path not in path_list:
765+
if str(path) not in path_list:
766766
path_list.insert(0, str(path))
767767

768768
if library_paths != self.config.DEFAULT_MODULE_PATH:
@@ -910,7 +910,10 @@ def _get_galaxy_role_ns(galaxy_infos: dict[str, Any]) -> str:
910910

911911
def _get_galaxy_role_name(galaxy_infos: dict[str, Any]) -> str:
912912
"""Compute role name from meta/main.yml."""
913-
return galaxy_infos.get("role_name", "")
913+
result = galaxy_infos.get("role_name", "")
914+
if not isinstance(result, str):
915+
return ""
916+
return result
914917

915918

916919
def search_galaxy_paths(search_dir: Path) -> list[str]:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: minimal
2+
namespace: acme
3+
version: 1.0.0
4+
readme: README.md
5+
authors:
6+
- Red Hat
7+
description: Sample collection to use with molecule
8+
build_ignore:
9+
- "*.egg-info"
10+
- .DS_Store
11+
- .eggs
12+
- .gitignore
13+
- .mypy_cache
14+
- .pytest_cache
15+
- .stestr
16+
- .stestr.conf
17+
- .tox
18+
- .vscode
19+
- MANIFEST.in
20+
- build
21+
- dist
22+
- doc
23+
- report.html
24+
- setup.cfg
25+
- setup.py
26+
- "tests/unit/*.*"
27+
- README.rst
28+
- tox.ini
29+
30+
license_file: LICENSE

test/test_runtime.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,3 +861,20 @@ def test_galaxy_path(path: str, result: list[str]) -> None:
861861
def test_is_url(name: str, result: bool) -> None:
862862
"""Checks functionality of is_url."""
863863
assert is_url(name) == result
864+
865+
def test_prepare_environment_repair_broken_symlink(caplog: pytest.LogCaptureFixture) -> None:
866+
"""Ensure we can deal with broken symlinks in collections."""
867+
caplog.set_level(logging.INFO)
868+
project_dir = Path(__file__).parent / "collections" / "acme.minimal"
869+
runtime = Runtime(isolated=True, project_dir=project_dir)
870+
assert runtime.cache_dir
871+
acme = runtime.cache_dir / "collections" / "ansible_collections" / "acme"
872+
acme.mkdir(parents=True, exist_ok=True)
873+
goodies = acme / "minimal"
874+
rmtree(goodies)
875+
goodies.unlink(missing_ok=True)
876+
goodies.symlink_to("/invalid/destination")
877+
runtime.prepare_environment(install_local=True)
878+
assert any(
879+
msg.startswith("Collection is symlinked, but not pointing to") for msg in caplog.messages
880+
)

tox.ini

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@ envlist =
44
lint
55
pkg
66
docs
7-
# matrix assumed current (implicit) is 2.13:
8-
py{39,310,311}{,-devel,-ansible212,-ansible213,-ansible214,-ansible215}
7+
py
8+
py-devel
9+
py39-ansible212
10+
py39-ansible213
11+
py39-ansible214
12+
py39-ansible215
13+
py310-ansible212
14+
py310-ansible213
15+
py310-ansible214
16+
py310-ansible215
17+
py311-ansible212
18+
py311-ansible213
19+
py311-ansible214
20+
py311-ansible215
21+
py312-ansible216
22+
923
isolated_build = true
1024
skip_missing_interpreters = True
1125
requires =
@@ -14,18 +28,20 @@ requires =
1428

1529
[testenv]
1630
description =
17-
Run the tests with {basepython}
31+
Run the tests
1832
devel: ansible devel branch
1933
ansible212: ansible-core 2.12
2034
ansible213: ansible-core 2.13
2135
ansible214: ansible-core 2.14
2236
ansible215: ansible-core 2.15
37+
ansible216: ansible-core 2.16
2338

2439
deps =
2540
ansible212: ansible-core>=2.12,<2.13
2641
ansible213: ansible-core>=2.13,<2.14
2742
ansible214: ansible-core>=2.14,<2.15
2843
ansible215: ansible-core>=2.15,<2.16
44+
ansible216: ansible-core>=2.16,<2.17
2945

3046
devel: ansible-core @ git+https://github.com/ansible/ansible.git@c5d18c39d81e2b3b10856b2fb76747230e4fac4a # GPLv3+
3147
# avoid installing ansible-core on -devel envs:
@@ -71,7 +87,7 @@ setenv =
7187
PIP_DISABLE_PIP_VERSION_CHECK = 1
7288
PIP_CONSTRAINT = {toxinidir}/requirements.txt
7389
PRE_COMMIT_COLOR = always
74-
PYTEST_REQPASS = 91
90+
PYTEST_REQPASS = 92
7591
FORCE_COLOR = 1
7692
allowlist_externals =
7793
ansible
@@ -83,7 +99,7 @@ package = editable
8399
[testenv:lint]
84100
description = Run all linters
85101
# locked basepython is needed because to keep constrains.txt predictable
86-
basepython = python3.9
102+
basepython = python3.10
87103
deps =
88104
pre-commit>=2.6.0
89105
skip_install = true

0 commit comments

Comments
 (0)