crate: error out if project arg looks like a path but is not a path
This commit is contained in:
parent
e879c9f857
commit
323dbea4b6
2 changed files with 22 additions and 18 deletions
|
@ -8,7 +8,7 @@ from cargo2rpm.semver import Version
|
||||||
from rust2rpm import log
|
from rust2rpm import log
|
||||||
from rust2rpm.cli import get_parser
|
from rust2rpm.cli import get_parser
|
||||||
from rust2rpm.conf import load_config
|
from rust2rpm.conf import load_config
|
||||||
from rust2rpm.crate import InvalidRequestError, process_project
|
from rust2rpm.crate import InvalidProjectError, process_project
|
||||||
from rust2rpm.cratesio import NoVersionsError
|
from rust2rpm.cratesio import NoVersionsError
|
||||||
from rust2rpm.distgit import get_package_info
|
from rust2rpm.distgit import get_package_info
|
||||||
from rust2rpm.generator import spec_render_crate, spec_render_project, spec_render_workspace
|
from rust2rpm.generator import spec_render_crate, spec_render_project, spec_render_workspace
|
||||||
|
@ -53,8 +53,8 @@ def main():
|
||||||
except NoVersionsError:
|
except NoVersionsError:
|
||||||
log.error(f"No versions are available for crate {args.crate!r}.")
|
log.error(f"No versions are available for crate {args.crate!r}.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except InvalidRequestError as exc:
|
except InvalidProjectError:
|
||||||
log.error(str(exc))
|
log.error(f"Invalid argument: {args.crate!r} is not a local file or directory")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if metadata.is_workspace():
|
if metadata.is_workspace():
|
||||||
|
|
|
@ -54,7 +54,7 @@ DOC_FILE_PATTERN = re.compile(
|
||||||
DOC_FILE_EXCLUDES = re.compile(r"CMakeLists\.txt|versions\.txt|.*\.tpl|.*\.in")
|
DOC_FILE_EXCLUDES = re.compile(r"CMakeLists\.txt|versions\.txt|.*\.tpl|.*\.in")
|
||||||
|
|
||||||
|
|
||||||
class InvalidRequestError(ValueError):
|
class InvalidProjectError(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -259,23 +259,27 @@ def process_project(
|
||||||
) -> tuple[
|
) -> tuple[
|
||||||
str, str, tuple[Optional[list[str]], Optional[list[str]]], Metadata, list[str], list[str], bool, Optional[str]
|
str, str, tuple[Optional[list[str]], Optional[list[str]]], Metadata, list[str], list[str], bool, Optional[str]
|
||||||
]:
|
]:
|
||||||
if project_is_path(project) and not project.endswith(".crate"):
|
if project_is_path(project):
|
||||||
# project points into unpacked sources:
|
if not os.path.exists(project):
|
||||||
if store_crate:
|
raise InvalidProjectError(project)
|
||||||
raise InvalidRequestError("The '--store-crate' / '-s' flag cannot be used for unpacked sources.")
|
|
||||||
|
if project.endswith(".crate"):
|
||||||
|
# project points at a local .crate file
|
||||||
|
crate_file_path = project
|
||||||
|
|
||||||
|
# determine name and version from the filename
|
||||||
|
name, version = parse_crate_file_name(project)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# project points at unpacked sources
|
||||||
|
if store_crate:
|
||||||
|
log.warn("The '--store-crate' flag has no effect for unpacked sources.")
|
||||||
|
|
||||||
# process unpacked sources
|
|
||||||
name, version, diffs, metadata, doc_files, license_files, vendor_tarball = process_project_local(
|
name, version, diffs, metadata, doc_files, license_files, vendor_tarball = process_project_local(
|
||||||
project, patch, patch_foreign, vendor
|
project, patch, patch_foreign, vendor
|
||||||
)
|
)
|
||||||
return name, version, diffs, metadata, doc_files, license_files, True, vendor_tarball
|
return name, version, diffs, metadata, doc_files, license_files, True, vendor_tarball
|
||||||
|
|
||||||
if project_is_path(project) and project.endswith(".crate"):
|
|
||||||
# project points at a local .crate file
|
|
||||||
crate_file_path = project
|
|
||||||
# determine name and version from the filename
|
|
||||||
name, version = parse_crate_file_name(project)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# project is just a crate name
|
# project is just a crate name
|
||||||
name = project
|
name = project
|
||||||
|
|
Loading…
Reference in a new issue