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

fix(charm-plugin): remove existence checks for reqs #1808

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions charmcraft/parts/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
from craft_parts.utils import os_utils

from charmcraft import charm_builder, env, instrum
from charmcraft.errors import DependencyError
from charmcraft.utils import (
get_requirements_file_package_names,
validate_strict_dependencies,
)

PACKAGE_NAME_REGEX = re.compile(r"[A-Za-z0-9_.-]+")

Expand Down Expand Up @@ -91,12 +86,6 @@ def validate_requirements(cls, charm_requirements, values):
)
project_dirpath = pathlib.Path(values["source"])

# check that all indicated files are present
for reqs_filename in charm_requirements:
reqs_path = project_dirpath / reqs_filename
if not reqs_path.is_file():
raise ValueError(f"requirements file {str(reqs_path)!r} not found")

# if nothing indicated, and default file is there, use it
default_reqs_name = "requirements.txt"
if not charm_requirements and (project_dirpath / default_reqs_name).is_file():
Expand Down Expand Up @@ -126,30 +115,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
12 changes: 0 additions & 12 deletions tests/unit/parts/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,6 @@ def test_charmpluginproperties_requirements_default(tmp_path):
assert properties.charm_requirements == []


def test_charmpluginproperties_requirements_must_exist(tmp_path):
"""The configured files must be present."""
reqs_path = tmp_path / "reqs.txt" # not in disk, really
content = {"source": str(tmp_path), "charm-requirements": [str(reqs_path)]}
with pytest.raises(pydantic.ValidationError) as raised:
parts.CharmPlugin.properties_class.unmarshal(content)
err = raised.value.errors()
assert len(err) == 1
assert err[0]["loc"] == ("charm-requirements",)
assert err[0]["msg"] == f"requirements file {str(reqs_path)!r} not found"


def test_charmpluginproperties_requirements_filepresent_ok(tmp_path):
"""If a specific file is present in disk it's used."""
(tmp_path / "requirements.txt").write_text("somedep")
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
Loading