Skip to content

Commit

Permalink
Output a readable error for workspace root
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Górny <[email protected]>
  • Loading branch information
mgorny committed Jan 31, 2024
1 parent dc7168c commit 45e052f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 11 additions & 2 deletions pycargoebuild/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pycargoebuild.cargo import (
Crate,
FileCrate,
WorkspaceCargoTomlError,
get_crates,
get_package_metadata,
)
Expand Down Expand Up @@ -260,8 +261,16 @@ def repack_crates(tar_out: tarfile.TarFile,
with f:
workspace = get_workspace_root(directory)
crates.update(workspace.crates)
pkg_metas.append(
get_package_metadata(f, workspace.workspace_metadata))
try:
pkg_metas.append(
get_package_metadata(f, workspace.workspace_metadata))
except WorkspaceCargoTomlError as e:
logging.error("The specified directory is a workspace root: "
f"{str(directory)!r}")
logging.info(
"Please run pycargoebuild in one of its members: "
f"{' '.join(e.members)}")
return 1
pkg_meta = pkg_metas[0]

if args.no_license:
Expand Down
9 changes: 5 additions & 4 deletions pycargoebuild/cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ def with_replaced_license(self, new_license: typing.Optional[str]

class WorkspaceCargoTomlError(RuntimeError):
"""Cargo.toml belongs to a workspace root"""
pass

def __init__(self, members: list[str]) -> None:
super().__init__()
self.members = members


def cargo_to_spdx(license_str: str) -> str:
Expand Down Expand Up @@ -226,9 +229,7 @@ def get_package_metadata(f: typing.BinaryIO,

if "package" not in cargo_toml and "workspace" in cargo_toml:
raise WorkspaceCargoTomlError(
"Specified directory seems to be a workspace root, please run "
"pycargoebuild on one of its members instead: "
f"{' '.join(cargo_toml['workspace']['members'])}")
cargo_toml["workspace"]["members"])

pkg_meta = cargo_toml["package"]
_get_meta_key = functools.partial(get_meta_key,
Expand Down

0 comments on commit 45e052f

Please sign in to comment.