Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
Workers
Base Worker
Merge requests
!115
Add a check_required_types method
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add a check_required_types method
require-types
into
master
Overview
2
Commits
2
Pipelines
1
Changes
2
Merged
Erwan Rouchet
requested to merge
require-types
into
master
3 years ago
Overview
2
Commits
2
Pipelines
1
Changes
2
Expand
Closes
#73 (closed)
Edited
3 years ago
by
Erwan Rouchet
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
d36c601a
2 commits,
3 years ago
2 files
+
70
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
arkindex_worker/worker/element.py
+
27
−
0
Options
@@ -8,7 +8,34 @@ from arkindex_worker.cache import CachedElement, CachedImage
from
arkindex_worker.models
import
Element
class
MissingTypeError
(
Exception
):
"""
A required element type was not found in a corpus.
"""
class
ElementMixin
(
object
):
def
check_required_types
(
self
,
corpus_id
:
str
,
*
type_slugs
:
str
)
->
bool
:
"""
Check that a corpus has a list of required element types,
and raise an exception if any of them are missing.
"""
assert
len
(
type_slugs
),
"
At least one element type slug is required.
"
assert
all
(
isinstance
(
slug
,
str
)
for
slug
in
type_slugs
),
"
Element type slugs must be strings.
"
corpus
=
self
.
request
(
"
RetrieveCorpus
"
,
id
=
corpus_id
)
available_slugs
=
{
element_type
[
"
slug
"
]
for
element_type
in
corpus
[
"
types
"
]}
missing_slugs
=
set
(
type_slugs
)
-
available_slugs
if
missing_slugs
:
raise
MissingTypeError
(
f
'
Element type(s)
{
"
,
"
.
join
(
missing_slugs
)
}
were not found in the
{
corpus
[
"
name
"
]
}
corpus (
{
corpus
[
"
id
"
]
}
).
'
)
return
True
def
create_sub_element
(
self
,
element
,
type
,
name
,
polygon
):
"""
Create a child element on the given element through API
Loading