Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-deposit
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
Antoine R. Dumont
swh-deposit
Commits
6d1089cb
Commit
6d1089cb
authored
2 years ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Add support for HAL-ID as identifier
parent
a8cda2cb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
swh/deposit/api/checks.py
+25
-13
25 additions, 13 deletions
swh/deposit/api/checks.py
swh/deposit/tests/api/test_checks.py
+32
-0
32 additions, 0 deletions
swh/deposit/tests/api/test_checks.py
swh/deposit/xsd/codemeta.xsd
+13
-1
13 additions, 1 deletion
swh/deposit/xsd/codemeta.xsd
with
70 additions
and
14 deletions
swh/deposit/api/checks.py
+
25
−
13
View file @
6d1089cb
...
@@ -16,6 +16,7 @@ Suggested fields:
...
@@ -16,6 +16,7 @@ Suggested fields:
import
dataclasses
import
dataclasses
import
functools
import
functools
import
re
from
typing
import
Dict
,
Iterator
,
Optional
,
Tuple
,
cast
from
typing
import
Dict
,
Iterator
,
Optional
,
Tuple
,
cast
import
urllib
import
urllib
from
xml.etree
import
ElementTree
from
xml.etree
import
ElementTree
...
@@ -55,22 +56,33 @@ def extra_validator(
...
@@ -55,22 +56,33 @@ def extra_validator(
# </xsd:simpleType>
# </xsd:simpleType>
# However, this would give an unreadable error, so we implement it here
# However, this would give an unreadable error, so we implement it here
# in Python instead.
# in Python instead.
try
:
yield
from
absolute_uri_validator
(
element
,
xsd_element
)
url
=
urllib
.
parse
.
urlparse
(
element
.
text
)
elif
type_name
==
"
{https://doi.org/10.5063/SCHEMA/CODEMETA-2.0}identifierType
"
:
except
ValueError
:
# Made-up type, that allows both absolute URIs and HAL-IDs
if
not
re
.
match
(
"
hal-[0-9]+
"
,
element
.
text
or
""
):
yield
from
absolute_uri_validator
(
element
,
xsd_element
)
def
absolute_uri_validator
(
element
:
ElementTree
.
Element
,
xsd_element
:
xmlschema
.
validators
.
elements
.
Xsd11Element
,
)
->
Iterator
[
xmlschema
.
XMLSchemaValidationError
]:
try
:
url
=
urllib
.
parse
.
urlparse
(
element
.
text
)
except
ValueError
:
yield
xmlschema
.
XMLSchemaValidationError
(
xsd_element
,
element
,
f
"
{
element
.
text
!r}
is not a valid URI
"
,
)
else
:
if
not
url
.
scheme
or
not
url
.
netloc
:
yield
xmlschema
.
XMLSchemaValidationError
(
xsd_element
,
element
,
f
"
{
element
.
text
!r}
is not an absolute URI
"
,
)
elif
"
"
in
url
.
netloc
:
# urllib is a little too permissive...
yield
xmlschema
.
XMLSchemaValidationError
(
yield
xmlschema
.
XMLSchemaValidationError
(
xsd_element
,
element
,
f
"
{
element
.
text
!r}
is not a valid URI
"
,
xsd_element
,
element
,
f
"
{
element
.
text
!r}
is not a valid URI
"
,
)
)
else
:
if
not
url
.
scheme
or
not
url
.
netloc
:
yield
xmlschema
.
XMLSchemaValidationError
(
xsd_element
,
element
,
f
"
{
element
.
text
!r}
is not an absolute URI
"
,
)
elif
"
"
in
url
.
netloc
:
# urllib is a little too permissive...
yield
xmlschema
.
XMLSchemaValidationError
(
xsd_element
,
element
,
f
"
{
element
.
text
!r}
is not a valid URI
"
,
)
@dataclasses.dataclass
@dataclasses.dataclass
...
...
This diff is collapsed.
Click to expand it.
swh/deposit/tests/api/test_checks.py
+
32
−
0
View file @
6d1089cb
...
@@ -146,6 +146,38 @@ _parameters1 = [
...
@@ -146,6 +146,38 @@ _parameters1 = [
</entry>
</entry>
"""
,
"""
,
),
),
(
"
identifier-is-halid
"
,
f
"""
\
<entry
{
XMLNS
}
>
<url>some url</url>
<codemeta:name>bar</codemeta:name>
<codemeta:author>
<codemeta:name>The Author</codemeta:name>
</codemeta:author>
<codemeta:identifier>hal-12345</codemeta:identifier>
{
PROVENANCE_XML
}
</entry>
"""
,
),
(
"
identifier-is-propertyvalue
"
,
f
"""
\
<entry
{
XMLNS
}
>
<url>some url</url>
<codemeta:name>bar</codemeta:name>
<codemeta:author>
<codemeta:name>The Author</codemeta:name>
</codemeta:author>
<schema:identifier>
<codemeta:type>schema:PropertyValue</codemeta:type>
<schema:propertyID>HAL-ID</schema:propertyID>
<schema:value>hal-02527911</schema:value>
</schema:identifier>
{
PROVENANCE_XML
}
</entry>
"""
,
),
(
(
"
codemeta-dates
"
,
"
codemeta-dates
"
,
f
"""
\
f
"""
\
...
...
This diff is collapsed.
Click to expand it.
swh/deposit/xsd/codemeta.xsd
+
13
−
1
View file @
6d1089cb
...
@@ -52,11 +52,23 @@
...
@@ -52,11 +52,23 @@
Therefore, more custom checks are implemented in swh/deposit/api/checks.py
Therefore, more custom checks are implemented in swh/deposit/api/checks.py
in order to allow either. -->
in order to allow either. -->
<xsd:simpleType
name=
"halId"
>
<xsd:restriction
base=
"xsd:string"
>
<xsd:pattern
value=
"hal-[0-9]+"
/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType
name=
"identifierType"
>
<!-- CodeMeta only allows URIs, but we make an exception for HAL-IDs,
in order not to break backward-compatibility. -->
<xsd:union
memberTypes=
"xsd:anyURI codemeta:halId"
/>
</xsd:simpleType>
<xsd:element
name=
"identifier"
type=
"codemeta:identifierType"
/>
<xsd:element
name=
"name"
type=
"xsd:string"
/>
<xsd:element
name=
"name"
type=
"xsd:string"
/>
<xsd:element
name=
"givenName"
type=
"xsd:string"
/>
<xsd:element
name=
"givenName"
type=
"xsd:string"
/>
<xsd:element
name=
"familyName"
type=
"xsd:string"
/>
<xsd:element
name=
"familyName"
type=
"xsd:string"
/>
<xsd:element
name=
"email"
type=
"xsd:string"
/>
<xsd:element
name=
"email"
type=
"xsd:string"
/>
<xsd:element
name=
"identifier"
type=
"xsd:anyURI"
/>
<xsd:element
name=
"applicationCategory"
type=
"xsd:string"
/>
<xsd:element
name=
"applicationCategory"
type=
"xsd:string"
/>
<xsd:element
name=
"applicationSubCategory"
type=
"xsd:string"
/>
<xsd:element
name=
"applicationSubCategory"
type=
"xsd:string"
/>
...
...
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