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 deps - option 2 #663

Closed
wants to merge 10 commits into from

Conversation

sivel
Copy link
Member

@sivel sivel commented Mar 21, 2024

Based on #647

---
version: 3.1

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 

TODO:

  • python excludes should work
  • excludes should not apply to user deps
  • system excludes should work
  • should there be a means to exclude collections?

NOTES:

  • Only supports exclusion of first level deps, does not offer a way to exclude deps of deps

@github-actions github-actions bot added docs Changes to documentation needs_triage New item that needs to be triaged labels Mar 21, 2024
@@ -203,11 +216,24 @@ def simple_combine(reqs):
continue

base_line = line.split('#')[0].strip()
name_match = REQ_NAME_RE.match(base_line)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional care is probably required here. This will have issues currently with things like:

  • URLs (git+..., https://...)
  • -r extra-requirements.txt or any other random pip flag

In this case, we probably just need to skip the exclude checks. But we can't have it both ways, in that we can't ignore requirements parsing, and still do requirements parsing, so URLs and such just wouldn't be supported. 🙂

The regex is also using the pep503 info, but I can't think of reasons it wouldn't work with RPM package names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not actually be a problem with -r but would still apply to URLs

if base_line in consolidated:
i = consolidated.index(base_line)
fancy_lines[i] += f', {collection}'
if not name_only:
fancy_lines[i] += f', {collection}'
Copy link
Member Author

@sivel sivel Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to kill off fancy lines, and just spit back out a concatenation, but not consolidate duplicates.

base_collections_path = '/usr/share/ansible/collections'
logger = logging.getLogger(__name__)

# https://peps.python.org/pep-0503/#normalized-names
REQ_NORM_RE = re.compile(r'[-_.]+')
REQ_NAME_RE = re.compile(r'^([-\w.]+)')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
REQ_NAME_RE = re.compile(r'^([-\w.]+)')
REQ_NAME_RE = re.compile(r'^([^-][-\w.]+)')

Copy link
Member

@nitzmahone nitzmahone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the best approach that seems the least likely to break existing usages, while still allowing for various "escape hatch" impls... Probably a few more bits to implement to fully close the loop:

  • A from_collection key for exclude, to allow a list of one or more collection names from which to completely ignore all deps. It's a big hammer, but would make things like "I only want to get my deps from downstream-packaged sources" at least possible without requiring EE creators to manually merge and exclude all the deps using the python/system/galaxy keys.
  • 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.
  • A suggestion to partner eng that PEP508-only requirements validation might be a good candidate for a certification gate (they could easily base such a thing off Drop requirements-parser in favor of pep508 #645).

except ValueError as e:
raise DefinitionError(f"Schema version not an integer: {ee_def['version']}") from e

if schema_version not in (1, 2, 3):
if schema_version not in (1, 2, 3, 3.1):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're abusing a combination of other tools in the absence of a first-class YAML "schema" for EE definitions , it's probably better to just support this in the existing version 3 schema, along with a small docs note that the exclude feature requires Builder >= 3.1 (and will be an error on < 3.1).

@Shrews
Copy link
Contributor

Shrews commented Mar 26, 2024

Closing this one and continuing work in #664 so as not to annoy @sivel with noise on this one.

@Shrews Shrews closed this Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Changes to documentation needs_triage New item that needs to be triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants