From de05a573a42653f969bd709e4b8577d72d3a5c77 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle Date: Wed, 16 Aug 2023 15:34:51 +0530 Subject: [PATCH 1/2] config option for ANSIBLE_COLLECTIONS_PATH --- src/pytest_ansible/units.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pytest_ansible/units.py b/src/pytest_ansible/units.py index 3b9fd36c..eaec8f1d 100644 --- a/src/pytest_ansible/units.py +++ b/src/pytest_ansible/units.py @@ -102,23 +102,26 @@ def inject(start_path: Path) -> None: logger.info("Collections dir: %s", collections_dir) - # TODO: Make this a configuration option, check COLLECTIONS_PATH # noqa: TD002, FIX002 - # https://github.com/ansible-community/pytest-ansible/issues/153 - # Add the user location for any dependencies - paths = [str(collections_dir), "~/.ansible/collections"] - logger.info("Paths: %s", paths) + # Configuration option for additional collection paths + additional_collections_paths = [os.path.expanduser("~/.ansible/collections")] - acf_inject(paths=paths) + # Check if the environment variable is set for additional paths + if "COLLECTIONS_PATH" in os.environ: + additional_collections_paths.extend( + os.environ["COLLECTIONS_PATH"].split(os.pathsep), + ) + + logger.info("Additional Collections Paths: %s", additional_collections_paths) + + acf_inject(paths=[str(collections_dir)] + additional_collections_paths) # Inject the path for the collection into sys.path - # This is needed for import udring mock tests sys.path.insert(0, str(collections_dir)) logger.debug("sys.path updated: %s", sys.path) - # Set the environment variable as courtesy for integration tests - + # Set the environment variable as a courtesy for integration tests envvar_name = determine_envvar() - env_paths = os.pathsep.join(paths) + env_paths = os.pathsep.join([str(collections_dir)] + additional_collections_paths) logger.info("Setting %s to %s", envvar_name, env_paths) os.environ[envvar_name] = env_paths From 1fcf8a53fe40a5df439851bc33f5400d2339b3b8 Mon Sep 17 00:00:00 2001 From: Ruchi Pakhle Date: Wed, 13 Sep 2023 18:14:25 +0530 Subject: [PATCH 2/2] review changes --- .config/requirements.txt | 30 +++++++++++++++++++++++++++++- src/pytest_ansible/units.py | 6 +++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.config/requirements.txt b/.config/requirements.txt index 7349efff..103a90ea 100644 --- a/.config/requirements.txt +++ b/.config/requirements.txt @@ -2,11 +2,39 @@ # This file is autogenerated by pip-compile with Python 3.9 # by the following command: # -# pip-compile --extra=docs --extra=test --no-annotate --output-file=.config/requirements.txt --resolver=backtracking --strip-extras --unsafe-package=ruamel-yaml-clib pyproject.toml +# pip-compile --extra=docs --extra=test --no-annotate --output-file=.config/requirements.txt --strip-extras --unsafe-package=ruamel-yaml-clib pyproject.toml # +ansible-compat==4.1.10 +ansible-core==2.15.4 attrs==22.2.0 +bracex==2.4 +cffi==1.15.1 +click==8.1.7 +click-help-colors==0.9.2 coverage==7.2.2 +cryptography==41.0.3 +enrich==1.2.7 +exceptiongroup==1.1.3 +importlib-resources==5.0.7 iniconfig==2.0.0 +jinja2==3.1.2 +jsonschema==4.19.0 +jsonschema-specifications==2023.7.1 +markdown-it-py==3.0.0 +markupsafe==2.1.3 +mdurl==0.1.2 +molecule==6.0.2 packaging==23.0 pluggy==1.0.0 +pycparser==2.21 +pygments==2.16.1 pytest==7.2.2 +pyyaml==6.0.1 +referencing==0.30.2 +resolvelib==1.0.1 +rich==13.5.2 +rpds-py==0.10.2 +subprocess-tee==0.4.1 +tomli==2.0.1 +typing-extensions==4.7.1 +wcmatch==8.5 diff --git a/src/pytest_ansible/units.py b/src/pytest_ansible/units.py index eaec8f1d..2e7e5484 100644 --- a/src/pytest_ansible/units.py +++ b/src/pytest_ansible/units.py @@ -106,11 +106,11 @@ def inject(start_path: Path) -> None: additional_collections_paths = [os.path.expanduser("~/.ansible/collections")] # Check if the environment variable is set for additional paths - if "COLLECTIONS_PATH" in os.environ: + if "COLLECTIONS_PATH" in os.environ and "COLLECTIONS_PATHS" in os.environ: additional_collections_paths.extend( - os.environ["COLLECTIONS_PATH"].split(os.pathsep), + os.environ.get("COLLECTIONS_PATH", "").split(os.pathsep) + + os.environ.get("COLLECTIONS_PATHS", "").split(os.pathsep), ) - logger.info("Additional Collections Paths: %s", additional_collections_paths) acf_inject(paths=[str(collections_dir)] + additional_collections_paths)