Skip to content

Commit

Permalink
fix: remove eager checking of dependencies
Browse files Browse the repository at this point in the history
This makes strict dependencies only fail during the charm builder step
if extra binary dependencies exist, but allows dynamically created
requirements.txt files.
  • Loading branch information
lengau committed Aug 12, 2024
1 parent 2dbf8cf commit 2099f9e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
27 changes: 3 additions & 24 deletions charmcraft/parts/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,6 @@ def validate_strict_dependencies(
"'charm-strict-dependencies' requires at least one requirements file."
)

invalid_binaries = set()
for binary_package in values.get("charm_binary_python_packages", []):
if not PACKAGE_NAME_REGEX.fullmatch(binary_package):
invalid_binaries.add(binary_package)

if invalid_binaries:
raise ValueError(
"'charm-binary-python-packages' may contain only package names allowed "
"to be installed from binary if 'charm-strict-dependencies' is enabled. "
f"Invalid package names: {sorted(invalid_binaries)}"
)

try:
validate_strict_dependencies(
get_requirements_file_package_names(
*(pathlib.Path(r) for r in values["charm_requirements"])
),
values.get("charm_binary_python_packages", []),
)
except DependencyError as e:
raise ValueError(
"All dependencies must be specified in requirements files for strict dependencies."
) from e

return charm_strict_dependencies

@classmethod
Expand Down Expand Up @@ -274,6 +250,9 @@ def get_build_commands(self) -> list[str]:
"""Return a list of commands to run during the build step."""
options = cast(CharmPluginProperties, self._options)




build_env = {
"LANG": "C.UTF-8",
"LC_ALL": "C.UTF-8",
Expand Down
10 changes: 0 additions & 10 deletions tests/unit/test_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ def test_partconfig_strict_dependencies_success(fs: FakeFilesystem, part_config,
{"charm-requirements": ["req.txt"], "charm-python-packages": ["ops"]},
"'charm-python-packages' must not be set if 'charm-strict-dependencies' is enabled",
),
(
{"charm-requirements": ["req.txt"], "charm-binary-python-packages": ["not-here"]},
"All dependencies must be specified in requirements files for strict dependencies.",
),
(
{"charm-requirements": ["req.txt"], "charm-binary-python-packages": ["ops>=2.6"]},
"'charm-binary-python-packages' may contain only package names allowed to be "
"installed from binary if 'charm-strict-dependencies' is enabled. Invalid "
"package names: ['ops>=2.6']",
),
({}, "'charm-strict-dependencies' requires at least one requirements file."),
],
)
Expand Down

0 comments on commit 2099f9e

Please sign in to comment.