Skip to content

Commit

Permalink
fix(pip): set --no-binary=:all: if possible (#1740)
Browse files Browse the repository at this point in the history
This reduces the chances of having pip install binary packages as
indirect dependencies.

Partial fix for #1473
  • Loading branch information
lengau committed Jul 19, 2024
1 parent 18236ea commit 889254f
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 157 deletions.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age,
body size, disability, ethnicity, sex characteristics, gender identity and
expression, level of experience, education, socioeconomic status,
expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

Expand Down
31 changes: 0 additions & 31 deletions charmcraft/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,4 @@ class JujuConfig(ModelConfigDefaults, frozen=True):
and: https://juju.is/docs/sdk/config-yaml
"""

<<<<<<< HEAD
options: dict[str, JujuOption] | None
=======
options: Optional[Dict[str, Dict[str, Any]]]

@pydantic.validator("options", pre=True)
def validate_actions(cls, options):
"""Verify options section."""
if options is None:
return None
if not isinstance(options, dict):
raise ValueError("'options' is not a dictionary")
for name, option in options.items():
if not isinstance(option, dict):
raise ValueError(f"'{name}' is not a dictionary")

option_keys = set(option.keys())
if not option_keys.issubset({"description", "type", "default"}):
invalid_keys = option_keys - {"description", "type", "default"}
raise ValueError(f"'{name}' has an invalid key(s): {invalid_keys}")

if "type" not in option:
raise ValueError(f"'{name}' is missing a type")

if option["type"] not in ["string", "int", "float", "boolean", "secret"]:
raise ValueError(
f"'{option}' has an invalid type '{option['type']}', "
"must be one of: string, int, float, boolean, secret"
)

return options
>>>>>>> 0f7a56d (feat(config): support `type:secret` in config.options (#1623))
20 changes: 12 additions & 8 deletions charmcraft/utils/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,25 @@ def get_pip_command(
binary_packages = get_pypi_packages(binary_deps)
requirements_packages = get_requirements_file_package_names(*requirements_files)
all_packages = charm_packages | binary_packages | requirements_packages
source_only_packages = sorted(
get_package_names(all_packages) - get_package_names(binary_packages)
)

non_requirements_packages = sorted(
exclude_packages(
set(source_deps) | set(binary_deps),
excluded=get_package_names(requirements_packages),
)
)

if source_only_packages:
no_binary = [f"--no-binary={','.join(source_only_packages)}"]
else:
no_binary = []
if not binary_packages:
return [
*prefix,
"--no-binary=:all:",
*(f"--requirement={path}" for path in requirements_files),
*non_requirements_packages,
]

source_only_packages = sorted(
get_package_names(all_packages) - get_package_names(binary_packages)
)
no_binary = [f"--no-binary={','.join(source_only_packages)}"] if source_only_packages else ()

return [
*prefix,
Expand Down
120 changes: 56 additions & 64 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,92 +1,84 @@
attrs==23.1.0
black==23.12.1
cachetools==5.3.2
certifi==2023.7.22
attrs==23.2.0
certifi==2024.7.4
cffi==1.16.0
chardet==5.2.0
charset-normalizer==3.3.2
click==8.1.7
codespell==2.2.6
colorama==0.4.6
coverage==7.4.1
craft-cli==2.4.0
craft-parts==1.25.2
craft-providers==1.20.3
craft-store==2.5.0
cryptography==41.0.7
coverage==7.5.3
craft-application==3.2.0
craft-archives==1.2.0
craft-cli==2.6.0
craft-grammar==1.2.0
craft-parts==1.33.0
craft-providers==1.24.1
craft-store==2.6.2
cryptography==42.0.8
Deprecated==1.2.14
distlib==0.3.8
distro==1.8.0
filelock==3.13.1
distro==1.9.0
docker==7.1.0
flake8==7.0.0
humanize==4.8.0
idna==3.4
importlib-metadata==6.8.0
freezegun==1.5.1
httplib2==0.22.0
humanize==4.9.0
hypothesis==6.100.5
idna==3.7
importlib_metadata==7.1.0
iniconfig==2.0.0
jaraco.classes==3.3.0
jaraco.classes==3.4.0
jeepney==0.8.0
Jinja2==3.1.3
jsonschema==4.19.2
jsonschema-specifications==2023.7.1
keyring==24.2.0
lxml==5.1.0
Jinja2==3.1.4
jsonschema==4.22.0
jsonschema-specifications==2023.12.1
keyring==24.3.1
launchpadlib==1.11.0
lazr.restfulclient==0.14.6
lazr.uri==1.0.6
macaroonbakery==1.3.4
MarkupSafe==2.1.4
MarkupSafe==2.1.5
mccabe==0.7.0
more-itertools==10.1.0
mypy==1.8.0
mypy-extensions==1.0.0
nodeenv==1.8.0
overrides==7.4.0
packaging==23.2
pathspec==0.12.1
platformdirs==3.11.0
pluggy==1.4.0
protobuf==3.20.3
more-itertools==10.2.0
oauthlib==3.2.2
overrides==7.7.0
packaging==24.0
platformdirs==4.2.2
pluggy==1.5.0
protobuf==5.26.1
pycodestyle==2.11.1
pycparser==2.21
pydantic==1.10.14
pycparser==2.22
pydantic==1.10.15
pydantic-yaml==0.11.2
pydocstyle==6.3.0
pyfakefs==5.3.4
pyfakefs==5.4.1
pyflakes==3.2.0
pygit2==1.14.1
pymacaroons==0.13.0
PyNaCl==1.5.0
pyproject-api==1.6.1
pyparsing==3.1.2
pyRFC3339==1.1
pyright==1.1.332
pytest==8.0.0
pytest==8.2.0
pytest-check==2.3.1
pytest-cov==4.1.0
pytest-mock==3.12.0
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-subprocess==1.5.0
python-dateutil==2.8.2
pytz==2023.3.post1
python-dateutil==2.9.0.post0
pytz==2024.1
pyxdg==0.28
PyYAML==6.0.1
referencing==0.30.2
referencing==0.35.1
requests==2.31.0
requests-toolbelt==1.0.0
requests-unixsocket==0.3.0
responses==0.24.1
rpds-py==0.10.6
ruff==0.1.15
responses==0.25.0
rpds-py==0.18.1
SecretStorage==3.3.3
setuptools==70.0.0
six==1.16.0
snap-helpers==0.4.2
snowballstemmer==2.2.0
sortedcontainers==2.4.0
tabulate==0.9.0
tox==4.11.4
types-Deprecated==1.2.9.20240106
types-python-dateutil==2.8.19.20240106
types-PyYAML==6.0.12.12
types-requests==2.31.0.6
types-setuptools==69.0.0.20240125
types-tabulate==0.9.0.20240106
types-urllib3==1.26.25.14
typing_extensions==4.8.0
types-Deprecated==1.2.9.20240311
types-PyYAML==6.0.12.20240311
typing_extensions==4.11.0
urllib3==1.26.18
virtualenv==20.25.0
wrapt==1.15.0
yamllint==1.32.0
zipp==3.17.0
wadllib==1.3.6
wrapt==1.16.0
zipp==3.19.1
79 changes: 46 additions & 33 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,52 +1,65 @@
attrs==23.1.0
certifi==2023.7.22
attrs==23.2.0
certifi==2024.7.4
cffi==1.16.0
charset-normalizer==3.3.2
craft-cli==2.4.0
craft-parts==1.25.2
craft-providers==1.20.3
craft-store==2.5.0
cryptography==41.0.7
craft-application==3.2.0
craft-archives==1.2.0
craft-cli==2.6.0
craft-grammar==1.2.0
craft-parts==1.33.0
craft-providers==1.24.1
craft-store==2.6.2
cryptography==42.0.8
Deprecated==1.2.14
distro==1.8.0
humanize==4.8.0
idna==3.4
importlib-metadata==6.8.0
jaraco.classes==3.3.0
distro==1.9.0
docker==7.1.0
httplib2==0.22.0
humanize==4.9.0
idna==3.7
importlib_metadata==7.1.0
jaraco.classes==3.4.0
jeepney==0.8.0
Jinja2==3.1.3
jsonschema==4.19.2
jsonschema-specifications==2023.7.1
keyring==24.2.0
Jinja2==3.1.4
jsonschema==4.22.0
jsonschema-specifications==2023.12.1
keyring==24.3.1
launchpadlib==1.11.0
lazr.restfulclient==0.14.6
lazr.uri==1.0.6
macaroonbakery==1.3.4
MarkupSafe==2.1.4
more-itertools==10.1.0
overrides==7.4.0
packaging==23.2
platformdirs==3.11.0
protobuf==3.20.3
pycparser==2.21
pydantic==1.10.14
MarkupSafe==2.1.5
more-itertools==10.2.0
oauthlib==3.2.2
overrides==7.7.0
packaging==24.0
platformdirs==4.2.2
protobuf==5.26.1
pycparser==2.22
pydantic==1.10.15
pydantic-yaml==0.11.2
pygit2==1.14.1
pymacaroons==0.13.0
PyNaCl==1.5.0
pyparsing==3.1.2
pyRFC3339==1.1
python-dateutil==2.8.2
pytz==2023.4
python-dateutil==2.9.0.post0
pytz==2024.1
pyxdg==0.28
PyYAML==6.0.1
referencing==0.30.2
referencing==0.35.1
requests==2.31.0
requests-toolbelt==1.0.0
requests-unixsocket==0.3.0
rpds-py==0.10.6
rpds-py==0.18.1
SecretStorage==3.3.3
setuptools==70.0.0
six==1.16.0
snap-helpers==0.4.2
tabulate==0.9.0
types-Deprecated==1.2.9.20240106
types-PyYAML==6.0.12.12
typing_extensions==4.8.0
types-Deprecated==1.2.9.20240311
types-PyYAML==6.0.12.20240311
typing_extensions==4.11.0
urllib3==1.26.18
wrapt==1.15.0
zipp==3.17.0
wadllib==1.3.6
wrapt==1.16.0
zipp==3.19.1
4 changes: 2 additions & 2 deletions tests/commands/test_store_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4023,7 +4023,7 @@ def test_uploadresource_image_digest_missing_everywhere(emitter, store_mock, con
with pytest.raises(CraftError) as cm:
UploadResourceCommand(config).run(args)

assert str(cm.value).startswith("Error while running")
assert str(cm.value) == "Image not found locally."

# validate how local interfaces and store was used
assert im_mock.mock_calls == [
Expand Down Expand Up @@ -4078,7 +4078,7 @@ def test_uploadresource_image_id_missing(emitter, store_mock, config):
with pytest.raises(CraftError) as cm:
UploadResourceCommand(config).run(args)

assert str(cm.value).startswith("Error while")
assert str(cm.value) == "Image not found locally."

assert dock_mock.mock_calls == [
call.get_image_info_from_id(original_image_id),
Expand Down
Loading

0 comments on commit 889254f

Please sign in to comment.