Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Renaud Boyer
swh-model
Commits
fd2279ef
Commit
fd2279ef
authored
4 years ago
by
Jenkins for Software Heritage
Browse files
Options
Downloads
Plain Diff
New upstream version 0.9.0
parents
71b254bd
a3b6a644
No related branches found
Branches containing commit
Tags
debian/upstream/0.9.0
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
PKG-INFO
+1
-1
1 addition, 1 deletion
PKG-INFO
swh.model.egg-info/PKG-INFO
+1
-1
1 addition, 1 deletion
swh.model.egg-info/PKG-INFO
swh/model/model.py
+10
-44
10 additions, 44 deletions
swh/model/model.py
swh/model/tests/test_model.py
+4
-23
4 additions, 23 deletions
swh/model/tests/test_model.py
with
16 additions
and
69 deletions
PKG-INFO
+
1
−
1
View file @
fd2279ef
Metadata-Version: 2.1
Name: swh.model
Version: 0.
8
.0
Version: 0.
9
.0
Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers
...
...
This diff is collapsed.
Click to expand it.
swh.model.egg-info/PKG-INFO
+
1
−
1
View file @
fd2279ef
Metadata-Version: 2.1
Name: swh.model
Version: 0.
8
.0
Version: 0.
9
.0
Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers
...
...
This diff is collapsed.
Click to expand it.
swh/model/model.py
+
10
−
44
View file @
fd2279ef
...
...
@@ -8,7 +8,6 @@ import datetime
from
enum
import
Enum
from
hashlib
import
sha256
from
typing
import
Any
,
Dict
,
Iterable
,
Optional
,
Tuple
,
TypeVar
,
Union
import
warnings
import
attr
from
attrs_strict
import
type_validator
...
...
@@ -854,26 +853,10 @@ class MetadataTargetType(Enum):
ORIGIN
=
"
origin
"
def
mangle_raw_extrinsic_metadata_dict
(
d
:
Dict
[
str
,
Any
])
->
Dict
[
str
,
Any
]:
"""
Rename the raw_extrinsic_metadata `id` field to `target`, throwing a
DeprecationWarning if appropriate
"""
if
"
id
"
in
d
:
target
=
d
.
pop
(
"
id
"
)
if
d
.
get
(
"
target
"
)
is
None
:
warnings
.
warn
(
"
RawExtrinsicMetadata `id` attribute is now called `target`
"
,
DeprecationWarning
,
)
d
[
"
target
"
]
=
target
elif
d
[
"
target
"
]
!=
target
:
raise
ValueError
(
"
Different values for `id` and `target` in RawExtrinsicMetadata
"
)
return
d
@attr.s
(
frozen
=
True
)
class
_RawExtrinsicMetadata
(
BaseModel
):
class
RawExtrinsicMetadata
(
BaseModel
):
object_type
:
Final
=
"
raw_extrinsic_metadata
"
# target object
type
=
attr
.
ib
(
type
=
MetadataTargetType
,
validator
=
type_validator
())
target
=
attr
.
ib
(
type
=
Union
[
str
,
SWHID
],
validator
=
type_validator
())
...
...
@@ -1041,7 +1024,7 @@ class _RawExtrinsicMetadata(BaseModel):
def
to_dict
(
self
):
d
=
super
().
to_dict
()
d
[
"
id
"
]
=
d
[
"
target
"
]
context_keys
=
(
"
origin
"
,
"
visit
"
,
...
...
@@ -1058,14 +1041,12 @@ class _RawExtrinsicMetadata(BaseModel):
@classmethod
def
from_dict
(
cls
,
d
):
d
=
mangle_raw_extrinsic_metadata_dict
(
{
**
d
,
"
type
"
:
MetadataTargetType
(
d
[
"
type
"
]),
"
authority
"
:
MetadataAuthority
.
from_dict
(
d
[
"
authority
"
]),
"
fetcher
"
:
MetadataFetcher
.
from_dict
(
d
[
"
fetcher
"
]),
}
)
d
=
{
**
d
,
"
type
"
:
MetadataTargetType
(
d
[
"
type
"
]),
"
authority
"
:
MetadataAuthority
.
from_dict
(
d
[
"
authority
"
]),
"
fetcher
"
:
MetadataFetcher
.
from_dict
(
d
[
"
fetcher
"
]),
}
if
d
[
"
type
"
]
!=
MetadataTargetType
.
ORIGIN
:
d
[
"
target
"
]
=
parse_swhid
(
d
[
"
target
"
])
...
...
@@ -1087,18 +1068,3 @@ class _RawExtrinsicMetadata(BaseModel):
"
fetcher_name
"
:
self
.
fetcher
.
name
,
"
fetcher_version
"
:
self
.
fetcher
.
version
,
}
class
RawExtrinsicMetadata
(
_RawExtrinsicMetadata
):
object_type
:
Final
=
"
raw_extrinsic_metadata
"
def
__init__
(
self
,
**
kwargs
):
super
().
__init__
(
**
mangle_raw_extrinsic_metadata_dict
(
kwargs
))
@property
def
id
(
self
):
warnings
.
warn
(
"
RawExtrinsicMetadata `id` attribute is now called `target`
"
,
DeprecationWarning
,
)
return
self
.
target
This diff is collapsed.
Click to expand it.
swh/model/tests/test_model.py
+
4
−
23
View file @
fd2279ef
...
...
@@ -807,9 +807,7 @@ def test_metadata_valid():
)
@pytest.mark.filterwarnings
(
"
ignore: RawExtrinsicMetadata `id`
"
)
@pytest.mark.parametrize
(
"
argument_name
"
,
[
"
id
"
,
"
target
"
])
def
test_metadata_to_dict
(
argument_name
):
def
test_metadata_to_dict
():
"""
Checks valid RawExtrinsicMetadata objects don
'
t raise an error.
"""
common_fields
=
{
...
...
@@ -821,25 +819,23 @@ def test_metadata_to_dict(argument_name):
}
m
=
RawExtrinsicMetadata
(
type
=
MetadataTargetType
.
ORIGIN
,
**
{
argument_name
:
_origin_url
,
**
_common_metadata_fields
},
type
=
MetadataTargetType
.
ORIGIN
,
target
=
_origin_url
,
**
_common_metadata_fields
,
)
assert
m
.
to_dict
()
==
{
"
type
"
:
"
origin
"
,
"
target
"
:
_origin_url
,
"
id
"
:
_origin_url
,
**
common_fields
,
}
assert
RawExtrinsicMetadata
.
from_dict
(
m
.
to_dict
())
==
m
m
=
RawExtrinsicMetadata
(
type
=
MetadataTargetType
.
CONTENT
,
**
{
argument_name
:
_content_swhid
,
**
_common_metadata_fields
},
target
=
_content_swhid
,
**
_common_metadata_fields
,
)
assert
m
.
to_dict
()
==
{
"
type
"
:
"
content
"
,
"
target
"
:
"
swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2
"
,
"
id
"
:
"
swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2
"
,
**
common_fields
,
}
assert
RawExtrinsicMetadata
.
from_dict
(
m
.
to_dict
())
==
m
...
...
@@ -1227,18 +1223,3 @@ def test_metadata_validate_context_directory():
),
**
_common_metadata_fields
,
)
def
test_metadata_id_attr
():
"""
Checks the legacy id attribute on RawExtrinsicMetadata objects
"""
# Simplest case
meta
=
RawExtrinsicMetadata
(
type
=
MetadataTargetType
.
ORIGIN
,
target
=
_origin_url
,
**
_common_metadata_fields
)
assert
meta
is
not
None
with
pytest
.
deprecated_call
()
as
messages
:
assert
meta
.
id
==
_origin_url
assert
"
RawExtrinsicMetadata `id`
"
in
str
(
messages
[
0
].
message
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment