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

experimental: use humanize for lists #997

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion craft_parts/packages/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from collections.abc import Sequence

import humanize

from craft_parts.errors import PartsError
from craft_parts.utils import formatting_utils

Expand Down Expand Up @@ -57,7 +59,7 @@ class PackagesNotFound(PackagesError):

def __init__(self, packages: Sequence[str]) -> None:
self.packages = packages
missing_pkgs = formatting_utils.humanize_list(packages, "and")
missing_pkgs = humanize.natural_list([repr(pkg) for pkg in sorted(packages)])
brief = f"Failed to find installation candidate for packages: {missing_pkgs}."
resolution = (
"Make sure the repository configuration and package names are correct."
Expand Down
6 changes: 4 additions & 2 deletions craft_parts/sources/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from collections.abc import Sequence

import humanize

from craft_parts import errors
from craft_parts.utils import formatting_utils

Expand Down Expand Up @@ -74,7 +76,7 @@ class InvalidSourceOptions(SourceError):
def __init__(self, *, source_type: str, options: list[str]) -> None:
self.source_type = source_type
self.options = options
humanized_options = formatting_utils.humanize_list(options, "and")
humanized_options = humanize.natural_list([repr(opt) for opt in sorted(options)])
brief = (
f"Failed to pull source: {humanized_options} cannot be used "
f"with a {source_type} source."
Expand All @@ -94,7 +96,7 @@ class IncompatibleSourceOptions(SourceError):
def __init__(self, source_type: str, options: list[str]) -> None:
self.source_type = source_type
self.options = options
humanized_options = formatting_utils.humanize_list(options, "and")
humanized_options = humanize.natural_list([repr(opt) for opt in sorted(options)])
brief = (
f"Failed to pull source: cannot specify both {humanized_options} "
f"for a {source_type} source."
Expand Down
44 changes: 0 additions & 44 deletions craft_parts/utils/formatting_utils.py

This file was deleted.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ classifiers = [
"Programming Language :: Python :: 3.12",
]
dependencies = [
"humanize>=4.11.0",
"overrides!=7.6.0",
"pydantic>=2.0.0",
"pyxdg",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/sources/test_rpm_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_valid_options(partitions):
"branch",
"submodule",
"depth",
"'source-branch', 'source-commit', 'source-depth', 'source-submodules', and 'source-tag'",
"'source-branch', 'source-commit', 'source-depth', 'source-submodules' and 'source-tag'",
id="all-values-bad",
),
],
Expand Down
47 changes: 0 additions & 47 deletions tests/unit/utils/test_formatting_utils.py

This file was deleted.

12 changes: 11 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading