diff --git a/PKG-INFO b/PKG-INFO index c0ac50f216d61f1ea7bbdde9081ef7716a80b854..ee50d594037bae70cb7aa580678385bba6d6bb3b 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: swh.model -Version: 0.0.66 +Version: 0.0.67 Summary: Software Heritage data model Home-page: https://forge.softwareheritage.org/diffusion/DMOD/ Author: Software Heritage developers diff --git a/swh.model.egg-info/PKG-INFO b/swh.model.egg-info/PKG-INFO index c0ac50f216d61f1ea7bbdde9081ef7716a80b854..ee50d594037bae70cb7aa580678385bba6d6bb3b 100644 --- a/swh.model.egg-info/PKG-INFO +++ b/swh.model.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: swh.model -Version: 0.0.66 +Version: 0.0.67 Summary: Software Heritage data model Home-page: https://forge.softwareheritage.org/diffusion/DMOD/ Author: Software Heritage developers diff --git a/swh/model/cli.py b/swh/model/cli.py index ae51d190c6423b1f9f963d791465c3ded81ecd5b..ad7e2f5fe7e77e583a346d426d18b3bf7a305a42 100644 --- a/swh/model/cli.py +++ b/swh/model/cli.py @@ -37,7 +37,7 @@ class PidParamType(click.ParamType): pids.parse_persistent_identifier(value) return value # return as string, as we need just that except ValidationError as e: - self.fail("%s is not a valid PID. %s." % (value, e), param, ctx) + self.fail("%s is not a valid SWHID. %s." % (value, e), param, ctx) def pid_of_file(path): @@ -155,20 +155,22 @@ def identify_object(obj_type, follow_symlinks, obj): @click.option( "--verify", "-v", - metavar="PID", + metavar="SWHID", type=PidParamType(), help="reference identifier to be compared with computed one", ) -@click.argument("objects", nargs=-1) +@click.argument("objects", nargs=-1, required=True) def identify(obj_type, verify, show_filename, follow_symlinks, objects): - """Compute the Software Heritage persistent identifier (PID) for the given + """Compute the Software Heritage persistent identifier (SWHID) for the given source code object(s). - For more details about Software Heritage PIDs see: + For more details about SWHIDs see: \b https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html + Tip: you can pass "-" to identify the content of standard input. + \b Examples: @@ -188,8 +190,6 @@ def identify(obj_type, verify, show_filename, follow_symlinks, objects): swh:1:snp:510aa88bdc517345d258c1fc2babcd0e1f905e93 helloworld.git """ # NoQA # overlong lines in shell examples are fine - if not objects: - objects = ["-"] if verify and len(objects) != 1: raise click.BadParameter("verification requires a single object") @@ -199,10 +199,10 @@ def identify(obj_type, verify, show_filename, follow_symlinks, objects): if verify: pid = next(results)[1] if verify == pid: - click.echo("PID match: %s" % pid) + click.echo("SWHID match: %s" % pid) sys.exit(0) else: - click.echo("PID mismatch: %s != %s" % (verify, pid)) + click.echo("SWHID mismatch: %s != %s" % (verify, pid)) sys.exit(1) else: for (obj, pid) in results: diff --git a/swh/model/identifiers.py b/swh/model/identifiers.py index dd3451346a7226226a7dceab3413bfa243a7cb37..4d25184bef6227b27ea8473d2b86f3703c5ec202 100644 --- a/swh/model/identifiers.py +++ b/swh/model/identifiers.py @@ -743,11 +743,7 @@ class PersistentId(_PersistentId): def persistent_identifier(object_type, object_id, scheme_version=1, metadata={}): - """Compute persistent identifier (stable over time) as per - documentation. - - Documentation: - https://docs.softwareheritage.org/devel/swh-model/persistent-identifiers.html # noqa + """Compute :ref:`SWHID <persistent-identifiers>` persistent identifiers. Args: object_type (str): object's type, either 'content', 'directory', @@ -776,7 +772,7 @@ def persistent_identifier(object_type, object_id, scheme_version=1, metadata={}) def parse_persistent_identifier(persistent_id): - """Parse swh's :ref:`persistent-identifiers` scheme. + """Parse :ref:`SWHID <persistent-identifiers>` persistent identifiers. Args: persistent_id (str): A persistent identifier diff --git a/swh/model/tests/test_cli.py b/swh/model/tests/test_cli.py index fac1d89d7b414b395d876ea0e57f7090ea197050..21eb8c5c6cd573635f65bd4f3f011e8037c62016 100644 --- a/swh/model/tests/test_cli.py +++ b/swh/model/tests/test_cli.py @@ -26,6 +26,10 @@ class TestIdentify(DataMixin, unittest.TestCase): self.assertEqual(result.exit_code, 0) self.assertEqual(result.output.split()[0], pid) + def test_no_args(self): + result = self.runner.invoke(cli.identify) + self.assertNotEqual(result.exit_code, 0) + def test_content_id(self): """identify file content""" self.make_contents(self.tmpdir_name) @@ -38,7 +42,7 @@ class TestIdentify(DataMixin, unittest.TestCase): """identify file content""" self.make_contents(self.tmpdir_name) for _, content in self.contents.items(): - result = self.runner.invoke(cli.identify, input=content["data"]) + result = self.runner.invoke(cli.identify, ["-"], input=content["data"]) self.assertPidOK(result, "swh:1:cnt:" + hash_to_hex(content["sha1_git"])) def test_directory_id(self): diff --git a/version.txt b/version.txt index 13f286901ff637c38568784646672dfab3a33233..8ac5b0a6fb155c6bc6030ec75bcb80041d11ae2c 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.0.66-0-g401bc17 \ No newline at end of file +v0.0.67-0-gd52549f \ No newline at end of file