Skip to content
Snippets Groups Projects
Commit d944d522 authored by Jenkins for Software Heritage's avatar Jenkins for Software Heritage
Browse files

New upstream version 0.0.53

parents 30a38988 4b779e1e
No related branches found
Tags debian/upstream/0.0.53
No related merge requests found
Metadata-Version: 2.1 Metadata-Version: 2.1
Name: swh.model Name: swh.model
Version: 0.0.52 Version: 0.0.53
Summary: Software Heritage data model Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/ Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers Author: Software Heritage developers
......
Metadata-Version: 2.1 Metadata-Version: 2.1
Name: swh.model Name: swh.model
Version: 0.0.52 Version: 0.0.53
Summary: Software Heritage data model Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/ Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers Author: Software Heritage developers
......
...@@ -45,6 +45,11 @@ def pid_of_file(path): ...@@ -45,6 +45,11 @@ def pid_of_file(path):
return pids.persistent_identifier(pids.CONTENT, object) return pids.persistent_identifier(pids.CONTENT, object)
def pid_of_file_content(data):
object = Content.from_bytes(mode=644, data=data).get_data()
return pids.persistent_identifier(pids.CONTENT, object)
def pid_of_dir(path): def pid_of_dir(path):
object = Directory.from_disk(path=path).get_data() object = Directory.from_disk(path=path).get_data()
return pids.persistent_identifier(pids.DIRECTORY, object) return pids.persistent_identifier(pids.DIRECTORY, object)
...@@ -85,7 +90,7 @@ def pid_of_git_repo(path): ...@@ -85,7 +90,7 @@ def pid_of_git_repo(path):
def identify_object(obj_type, follow_symlinks, obj): def identify_object(obj_type, follow_symlinks, obj):
if obj_type == 'auto': if obj_type == 'auto':
if os.path.isfile(obj): if obj == '-' or os.path.isfile(obj):
obj_type = 'content' obj_type = 'content'
elif os.path.isdir(obj): elif os.path.isdir(obj):
obj_type = 'directory' obj_type = 'directory'
...@@ -101,7 +106,10 @@ def identify_object(obj_type, follow_symlinks, obj): ...@@ -101,7 +106,10 @@ def identify_object(obj_type, follow_symlinks, obj):
pid = None pid = None
if obj_type in ['content', 'directory']: if obj == '-':
content = sys.stdin.buffer.read()
pid = pid_of_file_content(content)
elif obj_type in ['content', 'directory']:
path = obj.encode(sys.getfilesystemencoding()) path = obj.encode(sys.getfilesystemencoding())
if follow_symlinks and os.path.islink(obj): if follow_symlinks and os.path.islink(obj):
path = os.path.realpath(obj) path = os.path.realpath(obj)
...@@ -134,7 +142,7 @@ def identify_object(obj_type, follow_symlinks, obj): ...@@ -134,7 +142,7 @@ def identify_object(obj_type, follow_symlinks, obj):
help='type of object to identify (default: auto)') help='type of object to identify (default: auto)')
@click.option('--verify', '-v', metavar='PID', type=PidParamType(), @click.option('--verify', '-v', metavar='PID', type=PidParamType(),
help='reference identifier to be compared with computed one') help='reference identifier to be compared with computed one')
@click.argument('objects', nargs=-1, required=True) @click.argument('objects', nargs=-1)
def identify(obj_type, verify, show_filename, follow_symlinks, objects): 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 (PID) for the given
source code object(s). source code object(s).
...@@ -163,6 +171,9 @@ def identify(obj_type, verify, show_filename, follow_symlinks, objects): ...@@ -163,6 +171,9 @@ def identify(obj_type, verify, show_filename, follow_symlinks, objects):
swh:1:snp:510aa88bdc517345d258c1fc2babcd0e1f905e93 helloworld.git swh:1:snp:510aa88bdc517345d258c1fc2babcd0e1f905e93 helloworld.git
""" # NoQA # overlong lines in shell examples are fine """ # NoQA # overlong lines in shell examples are fine
if not objects:
objects = ['-']
if verify and len(objects) != 1: if verify and len(objects) != 1:
raise click.BadParameter('verification requires a single object') raise click.BadParameter('verification requires a single object')
......
...@@ -200,6 +200,7 @@ def snapshots(draw, *, min_size=0, max_size=100, only_objects=False): ...@@ -200,6 +200,7 @@ def snapshots(draw, *, min_size=0, max_size=100, only_objects=False):
for alias in unresolved_aliases: for alias in unresolved_aliases:
branches[alias] = draw(branch_targets(only_objects=True)) branches[alias] = draw(branch_targets(only_objects=True))
# Ensure no cycles between aliases
while True: while True:
try: try:
id_ = snapshot_identifier({ id_ = snapshot_identifier({
......
...@@ -119,7 +119,7 @@ class TimestampWithTimezone(BaseModel): ...@@ -119,7 +119,7 @@ class TimestampWithTimezone(BaseModel):
@classmethod @classmethod
def from_dict(cls, d): def from_dict(cls, d):
"""Builds a TimestampWithTimezone from any of the formats """Builds a TimestampWithTimezone from any of the formats
accepted by :py:`swh.model.normalize_timestamp`.""" accepted by :func:`swh.model.normalize_timestamp`."""
d = normalize_timestamp(d) d = normalize_timestamp(d)
return cls( return cls(
timestamp=Timestamp.from_dict(d['timestamp']), timestamp=Timestamp.from_dict(d['timestamp']),
...@@ -296,8 +296,8 @@ class Revision(BaseModel, HashableObject): ...@@ -296,8 +296,8 @@ class Revision(BaseModel, HashableObject):
message = attr.ib(type=bytes) message = attr.ib(type=bytes)
author = attr.ib(type=Person) author = attr.ib(type=Person)
committer = attr.ib(type=Person) committer = attr.ib(type=Person)
date = attr.ib(type=TimestampWithTimezone) date = attr.ib(type=Optional[TimestampWithTimezone])
committer_date = attr.ib(type=TimestampWithTimezone) committer_date = attr.ib(type=Optional[TimestampWithTimezone])
type = attr.ib(type=RevisionType) type = attr.ib(type=RevisionType)
directory = attr.ib(type=Sha1Git) directory = attr.ib(type=Sha1Git)
synthetic = attr.ib(type=bool) synthetic = attr.ib(type=bool)
...@@ -314,12 +314,20 @@ class Revision(BaseModel, HashableObject): ...@@ -314,12 +314,20 @@ class Revision(BaseModel, HashableObject):
@classmethod @classmethod
def from_dict(cls, d): def from_dict(cls, d):
d = d.copy() d = d.copy()
date = d.pop('date')
if date:
date = TimestampWithTimezone.from_dict(date)
committer_date = d.pop('committer_date')
if committer_date:
committer_date = TimestampWithTimezone.from_dict(
committer_date)
return cls( return cls(
author=Person.from_dict(d.pop('author')), author=Person.from_dict(d.pop('author')),
committer=Person.from_dict(d.pop('committer')), committer=Person.from_dict(d.pop('committer')),
date=TimestampWithTimezone.from_dict(d.pop('date')), date=date,
committer_date=TimestampWithTimezone.from_dict( committer_date=committer_date,
d.pop('committer_date')),
type=RevisionType(d.pop('type')), type=RevisionType(d.pop('type')),
**d) **d)
......
...@@ -37,6 +37,15 @@ class TestIdentify(DataMixin, unittest.TestCase): ...@@ -37,6 +37,15 @@ class TestIdentify(DataMixin, unittest.TestCase):
self.assertPidOK(result, self.assertPidOK(result,
'swh:1:cnt:' + hash_to_hex(content['sha1_git'])) 'swh:1:cnt:' + hash_to_hex(content['sha1_git']))
def test_content_id_from_stdin(self):
"""identify file content"""
self.make_contents(self.tmpdir_name)
for _, content in self.contents.items():
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): def test_directory_id(self):
"""identify an entire directory""" """identify an entire directory"""
self.make_from_tarball(self.tmpdir_name) self.make_from_tarball(self.tmpdir_name)
......
...@@ -66,49 +66,49 @@ def test_directory_model_id_computation(): ...@@ -66,49 +66,49 @@ def test_directory_model_id_computation():
dir_dict = dict(directory_example) dir_dict = dict(directory_example)
del dir_dict['id'] del dir_dict['id']
dir_model = Directory(**dir_dict) dir_id = hash_to_bytes(directory_identifier(dir_dict))
assert dir_model.id for dir_model in [Directory(**dir_dict), Directory.from_dict(dir_dict)]:
assert dir_model.id == hash_to_bytes(directory_identifier(dir_dict)) assert dir_model.id == dir_id
dir_model = Directory.from_dict(dir_dict)
assert dir_model.id
assert dir_model.id == hash_to_bytes(directory_identifier(dir_dict))
def test_revision_model_id_computation(): def test_revision_model_id_computation():
rev_dict = dict(revision_example) rev_dict = dict(revision_example)
del rev_dict['id'] del rev_dict['id']
rev_model = Revision(**rev_dict) rev_id = hash_to_bytes(revision_identifier(rev_dict))
assert rev_model.id for rev_model in [Revision(**rev_dict), Revision.from_dict(rev_dict)]:
assert rev_model.id == hash_to_bytes(revision_identifier(rev_dict)) assert rev_model.id == rev_id
def test_revision_model_id_computation_with_no_date():
"""We can have revision with date to None
"""
rev_dict = dict(revision_example)
rev_dict['date'] = None
rev_dict['committer_date'] = None
del rev_dict['id']
rev_model = Revision.from_dict(rev_dict) rev_id = hash_to_bytes(revision_identifier(rev_dict))
assert rev_model.id for rev_model in [Revision(**rev_dict), Revision.from_dict(rev_dict)]:
assert rev_model.id == hash_to_bytes(revision_identifier(rev_dict)) assert rev_model.date is None
assert rev_model.committer_date is None
assert rev_model.id == rev_id
def test_release_model_id_computation(): def test_release_model_id_computation():
rel_dict = dict(release_example) rel_dict = dict(release_example)
del rel_dict['id'] del rel_dict['id']
rel_model = Release(**rel_dict) rel_id = hash_to_bytes(release_identifier(rel_dict))
assert rel_model.id for rel_model in [Release(**rel_dict), Release.from_dict(rel_dict)]:
assert rel_model.id == hash_to_bytes(release_identifier(rel_dict)) assert rel_model.id == hash_to_bytes(rel_id)
rel_model = Release.from_dict(rel_dict)
assert rel_model.id
assert rel_model.id == hash_to_bytes(release_identifier(rel_dict))
def test_snapshot_model_id_computation(): def test_snapshot_model_id_computation():
snp_dict = dict(snapshot_example) snp_dict = dict(snapshot_example)
del snp_dict['id'] del snp_dict['id']
snp_model = Snapshot(**snp_dict) snp_id = hash_to_bytes(snapshot_identifier(snp_dict))
assert snp_model.id for snp_model in [Snapshot(**snp_dict), Snapshot.from_dict(snp_dict)]:
assert snp_model.id == hash_to_bytes(snapshot_identifier(snp_dict)) assert snp_model.id == snp_id
snp_model = Snapshot.from_dict(snp_dict)
assert snp_model.id
assert snp_model.id == hash_to_bytes(snapshot_identifier(snp_dict))
v0.0.52-0-g4e4c4ff v0.0.53-0-g4b779e1
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment