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

Expose a way to exclude dependencies #664

Open
wants to merge 27 commits into
base: devel
Choose a base branch
from

Conversation

Shrews
Copy link
Contributor

@Shrews Shrews commented Mar 26, 2024

Based on #647

Changes

  • Removes requirements_parser Python dependency.
  • Dependency sanitization functionality is removed.
    • The --sanitize option still exists, but is hidden, and it does nothing.
    • EXCLUDE_REQUIREMENTS only applied to pip before, simply because sanitize_requirements was only ever used for pip, but it now applies to system as well.
    • Most Python requirements.txt entries are simply pushed down to pip (-r still causes recursive inclusion inline).
  • Ability to exclude top-level Python or system dependencies from collections.
    • New exclude schema keyword is added to version 3 EE format and requires ansible-builder version 3.1 or higher. Using an older builder version simply errors.
    • Only supports exclusion of first level deps, does not offer a way to exclude deps of deps.
    • Exclusion matching is done with the simple name of the requirement (no versions, etc.).
    • Exclusions can be either straight string matching, or an advanced form using regular expressions.

Bug Fixes

  • Comment parsing fix to no longer strip the # anchor from requirement URLs (e.g., git+https://git.repo/some_pkg.git#egg=SomePackage)

Example

---
version: 3

images:
  base_image:
    name: quay.io/centos/centos:stream9

dependencies:
  python_interpreter:
    package_system: python3.11
    python_path: /usr/bin/python3.11

  ansible_core:
    package_pip: ansible-core

  ansible_runner:
    package_pip: ansible-runner

  galaxy:
    collections:
      - name: community.docker
      - name: ansible.netcommon

  exclude:
    python:
      - docker
    system:
      - python3-Cython
    all_from_collection:
      - a.b
      - c.d

TODO:

  • python excludes should work
  • excludes should not apply to user deps
  • system excludes should work
  • a means to exclude all deps from a collection (all_from_collection or from_collection?)
  • A docs note that Python requirements in collections should be limited to features defined by PEP508, and that any deviation from that will be considered undefined/unsupported behavior, even if it happens to work today.

@kurokobo
Copy link

Hi, thanks for working on this!
Sorry for adding a comment before making enough test, but since this PR at this moment simply uses \n to separate lines for requirements.txt for collections (in pip_file_data) and process them line by line, I wonder if the collections' requirements.txt would behave unexpectedly if it contained line continuations with backslashes.

@sivel
Copy link
Member

sivel commented Mar 28, 2024

I wonder if the collections' requirements.txt would behave unexpectedly if it contained line continuations with backslashes

@kurokobo that is correct. We discussed this when architecting the functionality, and should a package that is excluded have a backslash with a newline, it will likely cause problems.

We don't plan to add any specific functionality to permit or deny newlines, but we do intend to add documentation that states that it is in the best interest of everyone for collection maintainers, and EE creators to use pep508 formatted requirements files. We may be going so far to add linting rules, potentially via galaxy-importer to warn when a collection defines non-pep508 formatted requirements files.

@kurokobo
Copy link

@sivel
Thanks for providing detailed background! I have no objection to the policy, but I want to know details a bit.

If we strictly follow pep508, even any comments (#) would not be allowed. But this PR does not remove an implementation that intentionally ignores comments; is it a policy that requires strictly forrowing pep508, but allows comments as an exception? Or is my understanding incorrect?

F.Y.I., to support line continuations, we need just one modification (I don't think it will be adopted, but I'll write it down as I think of it😅 ).

diff --git a/src/ansible_builder/_target_scripts/introspect.py b/src/ansible_builder/_target_scripts/introspect.py
index 553cf81..c32d121 100644
--- a/src/ansible_builder/_target_scripts/introspect.py
+++ b/src/ansible_builder/_target_scripts/introspect.py
@@ -26,7 +26,7 @@ def read_req_file(path):
 
 
 def pip_file_data(path):
-    pip_content = read_req_file(path)
+    pip_content = read_req_file(path).replace('\\\n', '')
 
     pip_lines = []
     for line in pip_content.split('\n'):

@Shrews Shrews force-pushed the escape-hatch-2 branch 4 times, most recently from 214ab87 to 482de8d Compare April 1, 2024 20:14
@Shrews
Copy link
Contributor Author

Shrews commented Apr 1, 2024

@sivel Thanks for providing detailed background! I have no objection to the policy, but I want to know details a bit.

If we strictly follow pep508, even any comments (#) would not be allowed. But this PR does not remove an implementation that intentionally ignores comments; is it a policy that requires strictly forrowing pep508, but allows comments as an exception? Or is my understanding incorrect?

Comments will be allowed. Any non-pep508 compliant entries are going to be passed through without change, unchecked and unverified. We plan to update the docs that using such non-compliant entries will be considered undefined/unsupported behavior.

@Shrews Shrews force-pushed the escape-hatch-2 branch 2 times, most recently from 1b471af to ecb1fbf Compare May 2, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment