Skip to content

Commit

Permalink
Inject venv site-packages at the top of collection path (test isolati…
Browse files Browse the repository at this point in the history
…on) (#447)

- Inject venv site-packages into collection patch in order to ensure
  that by default ansible-galaxy commands will install content in
  these instead of user configuration. (test isolation)
- Adapt smoke testing to test both molecule and ansible-lint, which
  before this change would have failed one test.
  • Loading branch information
ssbarnea authored Jan 27, 2025
1 parent 43229fe commit 83c5cfb
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 66 deletions.
6 changes: 2 additions & 4 deletions .config/pydoclint-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ src/ansible_compat/config.py
DOC201: Function `ansible_version` does not have a return section in docstring
DOC501: Function `ansible_version` has "raise" statements, but the docstring does not have a "Raises" section
DOC503: Function `ansible_version` exceptions in the "Raises" section in the docstring do not match those in the function body. Raised exceptions in the docstring: []. Raised exceptions in the body: ['MissingAnsibleError'].
DOC601: Class `AnsibleConfig`: Class docstring contains fewer class attributes than actual class attributes. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.)
DOC603: Class `AnsibleConfig`: Class docstring attributes are different from actual class attributes. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Attributes in the class definition but not in the docstring: [_aliases: , action_warnings: bool, agnostic_become_prompt: bool, allow_world_readable_tmpfiles: bool, ansible_connection_path: str | None, ansible_cow_acceptlist: list[str], ansible_cow_path: str | None, ansible_cow_selection: str, ansible_force_color: bool, ansible_nocolor: bool, ansible_nocows: bool, ansible_pipelining: bool, any_errors_fatal: bool, become_allow_same_user: bool, become_plugin_path: list[str], cache_plugin: str, cache_plugin_connection: str | None, cache_plugin_prefix: str, cache_plugin_timeout: int, callable_accept_list: list[str], callbacks_enabled: list[str], collections_on_ansible_version_mismatch: Literal['warning', 'ignore'], collections_paths: list[str], collections_scan_sys_path: bool, color_changed: str, color_console_prompt: str, color_debug: str, color_deprecate: str, color_diff_add: str, color_diff_lines: str, color_diff_remove: str, color_error: str, color_highlight: str, color_ok: str, color_skip: str, color_unreachable: str, color_verbose: str, color_warn: str, command_warnings: bool, conditional_bare_vars: bool, connection_facts_modules: dict[str, str], controller_python_warning: bool, coverage_remote_output: str | None, coverage_remote_paths: list[str], default_action_plugin_path: list[str], default_allow_unsafe_lookups: bool, default_ask_pass: bool, default_ask_vault_pass: bool, default_become: bool, default_become_ask_pass: bool, default_become_exe: str | None, default_become_flags: str, default_become_method: str, default_become_user: str, default_cache_plugin_path: list[str], default_callback_plugin_path: list[str], default_cliconf_plugin_path: list[str], default_collections_path: list[str], default_connection_plugin_path: list[str], default_debug: bool, default_executable: str, default_fact_path: str | None, default_filter_plugin_path: list[str], default_force_handlers: bool, default_forks: int, default_gather_subset: list[str], default_gather_timeout: int, default_gathering: Literal['smart', 'explicit', 'implicit'], default_handler_includes_static: bool, default_hash_behaviour: str, default_host_list: list[str], default_httpapi_plugin_path: list[str], default_internal_poll_interval: float, default_inventory_plugin_path: list[str], default_jinja2_extensions: list[str], default_jinja2_native: bool, default_keep_remote_files: bool, default_libvirt_lxc_noseclabel: bool, default_load_callback_plugins: bool, default_local_tmp: str, default_log_filter: list[str], default_log_path: str | None, default_lookup_lugin_path: list[str], default_managed_str: str, default_module_args: str, default_module_compression: str, default_module_name: str, default_module_path: list[str], default_module_utils_path: list[str], default_netconf_plugin_path: list[str], default_no_log: bool, default_no_target_syslog: bool, default_null_representation: str | None, default_poll_interval: int, default_private_key_file: str | None, default_private_role_vars: bool, default_remote_port: str | None, default_remote_user: str | None, default_roles_path: list[str], default_selinux_special_fs: list[str], default_stdout_callback: str, default_strategy: str, default_strategy_plugin_path: list[str], default_su: bool, default_syslog_facility: str, default_task_includes_static: bool, default_terminal_plugin_path: list[str], default_test_plugin_path: list[str], default_timeout: int, default_transport: str, default_undefined_var_behavior: bool, default_vars_plugin_path: list[str], default_vault_encrypt_identity: str | None, default_vault_id_match: bool, default_vault_identity: str, default_vault_identity_list: list[str], default_vault_password_file: str | None, default_verbosity: int, deprecation_warnings: bool, devel_warning: bool, diff_always: bool, diff_context: int, display_args_to_stdout: bool, display_skipped_hosts: bool, doc_fragment_plugin_path: list[str], docsite_root_url: str, duplicate_yaml_dict_key: Literal['warn', 'error', 'ignore'], enable_task_debugger: bool, error_on_missing_handler: bool, facts_modules: list[str], galaxy_cache_dir: str, galaxy_display_progress: str | None, galaxy_ignore_certs: bool, galaxy_role_skeleton: str | None, galaxy_role_skeleton_ignore: list[str], galaxy_server: str, galaxy_server_list: str | None, galaxy_token_path: str, host_key_checking: bool, host_pattern_mismatch: Literal['warning', 'error', 'ignore'], inject_facts_as_vars: bool, interpreter_python: str, interpreter_python_distro_map: dict[str, str], interpreter_python_fallback: list[str], invalid_task_attribute_failed: bool, inventory_any_unparsed_is_failed: bool, inventory_cache_enabled: bool, inventory_cache_plugin: str | None, inventory_cache_plugin_connection: str | None, inventory_cache_plugin_prefix: str, inventory_cache_timeout: int, inventory_enabled: list[str], inventory_export: bool, inventory_ignore_exts: str, inventory_ignore_patterns: list[str], inventory_unparsed_is_failed: bool, localhost_warning: bool, max_file_size_for_diff: int, module_ignore_exts: str, netconf_ssh_config: str | None, network_group_modules: list[str], old_plugin_cache_clearing: bool, paramiko_host_key_auto_add: bool, paramiko_look_for_keys: bool, persistent_command_timeout: int, persistent_connect_retry_timeout: int, persistent_connect_timeout: int, persistent_control_path_dir: str, playbook_dir: str | None, playbook_vars_root: Literal['top', 'bottom', 'all'], plugin_filters_cfg: str | None, python_module_rlimit_nofile: int, retry_files_enabled: bool, retry_files_save_path: str | None, run_vars_plugins: str, show_custom_stats: bool, string_conversion_action: Literal['warn', 'error', 'ignore'], string_type_filters: list[str], system_warnings: bool, tags_run: list[str], tags_skip: list[str], task_debugger_ignore_errors: bool, task_timeout: int, transform_invalid_group_chars: Literal['always', 'never', 'ignore', 'silently'], use_persistent_connections: bool, variable_plugins_enabled: list[str], variable_precedence: list[str], verbose_to_stderr: bool, win_async_startup_timeout: int, worker_shutdown_poll_count: int, worker_shutdown_poll_delay: float, yaml_filename_extensions: list[str]]. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.)
DOC604: Class `AnsibleConfig`: Attributes are the same in docstring and class def, but are in a different order. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.)
DOC605: Class `AnsibleConfig`: Attribute names match, but type hints in these attributes do not match: action_warnings, agnostic_become_prompt, allow_world_readable_tmpfiles, ansible_connection_path, ansible_cow_acceptlist, ansible_cow_path, ansible_cow_selection, ansible_force_color, ansible_nocolor, ansible_nocows, ansible_pipelining, any_errors_fatal, become_allow_same_user, become_plugin_path, cache_plugin, cache_plugin_connection, cache_plugin_prefix, cache_plugin_timeout, callable_accept_list, callbacks_enabled, collections_on_ansible_version_mismatch, collections_paths, collections_scan_sys_path, color_changed, color_console_prompt, color_debug, color_deprecate, color_diff_add, color_diff_lines, color_diff_remove, color_error, color_highlight, color_ok, color_skip, color_unreachable, color_verbose, color_warn, command_warnings, conditional_bare_vars, connection_facts_modules, controller_python_warning, coverage_remote_output, coverage_remote_paths, default_action_plugin_path, default_allow_unsafe_lookups, default_ask_pass, default_ask_vault_pass, default_become, default_become_ask_pass, default_become_exe, default_become_flags, default_become_method, default_become_user, default_cache_plugin_path, default_callback_plugin_path, default_cliconf_plugin_path, default_connection_plugin_path, default_debug, default_executable, default_fact_path, default_filter_plugin_path, default_force_handlers, default_forks, default_gather_subset, default_gather_timeout, default_gathering, default_handler_includes_static, default_hash_behaviour, default_host_list, default_httpapi_plugin_path, default_internal_poll_interval, default_inventory_plugin_path, default_jinja2_extensions, default_jinja2_native, default_keep_remote_files, default_libvirt_lxc_noseclabel, default_load_callback_plugins, default_local_tmp, default_log_filter, default_log_path, default_lookup_plugin_path, default_managed_str, default_module_args, default_module_compression, default_module_name, default_module_path, default_module_utils_path, default_netconf_plugin_path, default_no_log, default_no_target_syslog, default_null_representation, default_poll_interval, default_private_key_file, default_private_role_vars, default_remote_port, default_remote_user, default_collections_path, default_roles_path, default_selinux_special_fs, default_stdout_callback, default_strategy, default_strategy_plugin_path, default_su, default_syslog_facility, default_task_includes_static, default_terminal_plugin_path, default_test_plugin_path, default_timeout, default_transport, default_undefined_var_behavior, default_vars_plugin_path, default_vault_encrypt_identity, default_vault_id_match, default_vault_identity, default_vault_identity_list, default_vault_password_file, default_verbosity, deprecation_warnings, devel_warning, diff_always, diff_context, display_args_to_stdout, display_skipped_hosts, docsite_root_url, doc_fragment_plugin_path, duplicate_yaml_dict_key, enable_task_debugger, error_on_missing_handler, facts_modules, galaxy_cache_dir, galaxy_display_progress, galaxy_ignore_certs, galaxy_role_skeleton, galaxy_role_skeleton_ignore, galaxy_server, galaxy_server_list, galaxy_token_path, host_key_checking, host_pattern_mismatch, inject_facts_as_vars, interpreter_python, interpreter_python_distro_map, interpreter_python_fallback, invalid_task_attribute_failed, inventory_any_unparsed_is_failed, inventory_cache_enabled, inventory_cache_plugin, inventory_cache_plugin_connection, inventory_cache_plugin_prefix, inventory_cache_timeout, inventory_enabled, inventory_export, inventory_ignore_exts, inventory_ignore_patterns, inventory_unparsed_is_failed, localhost_warning, max_file_size_for_diff, module_ignore_exts, netconf_ssh_config, network_group_modules, old_plugin_cache_clearing, paramiko_host_key_auto_add, paramiko_look_for_keys, persistent_command_timeout, persistent_connect_retry_timeout, persistent_connect_timeout, persistent_control_path_dir, playbook_dir, playbook_vars_root, plugin_filters_cfg, python_module_rlimit_nofile, retry_files_enabled, retry_files_save_path, run_vars_plugins, show_custom_stats, string_conversion_action, string_type_filters, system_warnings, tags_run, tags_skip, task_debugger_ignore_errors, task_timeout, transform_invalid_group_chars, use_persistent_connections, variable_plugins_enabled, variable_precedence, verbose_to_stderr, win_async_startup_timeout, worker_shutdown_poll_count, worker_shutdown_poll_delay, yaml_filename_extensions (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.)
DOC101: Method `AnsibleConfig.__init__`: Docstring contains fewer arguments than in function signature.
DOC103: Method `AnsibleConfig.__init__`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [cache_dir: Path | None, config_dump: str | None, data: dict[str, object] | None].
DOC501: Method `AnsibleConfig.__init__` has "raise" statements, but the docstring does not have a "Raises" section
DOC503: Method `AnsibleConfig.__init__` exceptions in the "Raises" section in the docstring do not match those in the function body. Raised exceptions in the docstring: []. Raised exceptions in the body: ['RuntimeError'].
DOC101: Method `AnsibleConfig.__getattribute__`: Docstring contains fewer arguments than in function signature.
DOC103: Method `AnsibleConfig.__getattribute__`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [attr_name: str].
DOC201: Method `AnsibleConfig.__getattribute__` does not have a return section in docstring
Expand Down
19 changes: 9 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ arg-type-hints-in-docstring = false
baseline = ".config/pydoclint-baseline.txt"
check-return-types = false
check-yield-types = false
exclude = '\.cache|\.git|\.tox|build|out|venv'
quiet = true # no need to print out the files being checked
exclude = '\.ansible|\.cache|\.git|\.tox|build|ansible_collections|out|venv'
should-document-private-class-attributes = true
show-filenames-in-every-violation-message = true
skip-checking-short-docstrings = false
Expand Down Expand Up @@ -350,7 +349,7 @@ disable = [
]

[tool.pytest.ini_options]
addopts = "-p no:pytest_cov --durations=10 --durations-min=1.0 --failed-first"
addopts = "-p no:pytest_cov --durations=10 --durations-min=1.0 --failed-first --instafail"
# ensure we treat warnings as error
filterwarnings = [
"error",
Expand All @@ -369,6 +368,9 @@ target-version = "py310"
docstring-code-format = true

[tool.ruff.lint]
external = [
"DOC" # pydoclint
]
ignore = [
# Disabled on purpose:
"CPY001",
Expand Down Expand Up @@ -405,8 +407,11 @@ known-third-party = ["packaging"]
"PLR0917",
"S101",
"S404",
"S603", # subprocess
"S607", # subprocess
"SLF001"
]
"tools/*.py" = ["S603"]

[tool.ruff.lint.pydocstyle]
convention = "google"
Expand Down Expand Up @@ -439,10 +444,4 @@ sort_table_keys = true
[tool.uv.pip]
annotation-style = "line"
custom-compile-command = "tox run deps"
no-emit-package = [
"ansible-core",
"pip",
"resolvelib",
"typing_extensions",
"uv"
]
no-emit-package = ["ansible-core", "pip", "resolvelib", "typing_extensions", "uv"]
Loading

0 comments on commit 83c5cfb

Please sign in to comment.