Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add the agent_install_dependency_modules project config option #7312

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,8 +1,9 @@
---
description: Dropped the project configuration option `agent_install_dependency_modules`. The installation of module dependencies is now always enabled.
description: "The default value of the project configuration option `agent_install_dependency_modules` changed to True."
issue-nr: 7026
issue-repo: inmanta-core
change-type: patch
destination-branches: [master, iso7]
sections:
upgrade-note: "{{description}}"
deprecation-note: "The project configuration option `agent_install_dependency_modules` is deprecated and will be removed in a next major release."
5 changes: 4 additions & 1 deletion src/inmanta/loader.py
Expand Up @@ -105,7 +105,10 @@ def requires(self) -> list[str]:
if self._requires is None:
project: module.Project = module.Project.get()
mod: module.Module = project.modules[self._get_module_name()]
self._requires = mod.get_all_python_requirements_as_list()
if project.metadata.agent_install_dependency_modules:
self._requires = mod.get_all_python_requirements_as_list()
else:
self._requires = mod.get_strict_python_requirements_as_list()
return self._requires


Expand Down
16 changes: 16 additions & 0 deletions src/inmanta/module.py
Expand Up @@ -1618,6 +1618,21 @@ class ProjectMetadata(Metadata, MetadataFieldRequires):
result in an error.
When a non-strict check is done, only version conflicts in a direct dependency will result in an error.
All other violations will only result in a warning message.
:param agent_install_dependency_modules: [DEPRECATED] If true, when a module declares Python dependencies on
other (v2) modules, the agent will install these dependency modules with pip. This option should only be enabled
if the agent is configured with the appropriate pip related environment variables. The option allows to an extent
for inter-module dependencies within handler code, even if the dependency module doesn't have any handlers that
would otherwise be considered relevant for this agent.
Care should still be taken when you use inter-module imports. The current code loading mechanism does not explicitly
order reloads. A general guideline is to use qualified imports where you can (import the module rather than objects
from the module). When this is not feasible, you should be aware of
`Python's reload semantics <https://docs.python.org/3/library/importlib.html#importlib.reload>`_ and take this into
account when making changes to handler code.
Another caveat is that if the dependency module does contain code that is relevant for the agent, it will be loaded
like any other handler code and it will be this code that is imported by any dependent modules (though depending on
the load order the very first import may use the version installed by pip). If at some point this dependency module's
handlers cease to be relevant for this agent, its code will remain stale. Therefore this feature should not be depended
on in transient scenarios like this.
:param pip: A configuration section that holds information about the pip configuration that should be taken into account
when installing Python packages (See: :py:class:`inmanta.module.ProjectPipConfig` for more details).
"""
Expand All @@ -1640,6 +1655,7 @@ class ProjectMetadata(Metadata, MetadataFieldRequires):
Annotated[str, StringConstraints(strip_whitespace=True, pattern=_re_relation_precedence_rule, min_length=1)]
] = []
strict_deps_check: bool = True
agent_install_dependency_modules: bool = True
pip: ProjectPipConfig = ProjectPipConfig()

@field_validator("modulepath", mode="before")
Expand Down
6 changes: 6 additions & 0 deletions tests/test_loader.py
Expand Up @@ -106,7 +106,13 @@ def assert_content(source_info: SourceInfo, handler) -> str:

# verify requirements behavior
source_info: SourceInfo = single_type_list[0]
# by default also install dependencies on other modules
assert source_info.requires == ["inmanta-module-std", "lorem"]
project._metadata.agent_install_dependency_modules = False
# reset cache
source_info._requires = None
# when disabled only install non-module dependencies
assert source_info.requires == ["lorem"]


def test_code_loader(tmp_path, caplog):
Expand Down