Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
catalog
Tools
Commits
ded67dc2
Commit
ded67dc2
authored
1 year ago
by
Florian Ziemen
Browse files
Options
Downloads
Patches
Plain Diff
Moving to @dataclasses
parent
09d25b0b
No related branches found
No related tags found
1 merge request
!2
draft: Basic dataset
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dataset.py
+16
-17
16 additions, 17 deletions
dataset.py
test_dataset.py
+2
-2
2 additions, 2 deletions
test_dataset.py
with
18 additions
and
19 deletions
dataset.py
+
16
−
17
View file @
ded67dc2
from
collections.abc
import
Sequence
from
dataclasses
import
dataclass
@dataclass
class
dataset_location
:
def
__init__
(
self
,
method
:
str
,
host
:
str
,
path
:
str
,
):
self
.
method
=
method
self
.
host
=
host
self
.
path
=
path
method
:
str
host
:
str
path
:
str
def
is_valid
(
self
)
->
bool
:
return
all
(
x
is
not
None
for
x
in
vars
(
self
).
values
())
...
...
@@ -19,15 +15,18 @@ class dataset_location:
return
vars
(
self
)
@dataclass
class
dataset
:
def
__init__
(
self
,
name
:
str
,
serve
:
bool
,
locations
:
Sequence
[
dataset_location
],
**
kwargs
):
self
.
name
=
name
self
.
serve
=
serve
self
.
locations
=
set
(
locations
)
for
k
,
v
in
kwargs
.
items
():
setattr
(
self
,
k
,
v
)
name
:
str
serve
:
bool
locations
:
Sequence
[
dataset_location
]
def
__post_init__
(
self
):
self
.
locations
=
list
(
self
.
locations
)
if
not
all
(
isinstance
(
x
,
dataset_location
)
for
x
in
self
.
locations
):
raise
TypeError
(
f
"
Dateset locations must be of type dataset_location, found
{
[
type
(
x
)
for
x
in
self
.
locations
]
}
"
)
def
is_valid
(
self
)
->
bool
:
return
(
...
...
This diff is collapsed.
Click to expand it.
test_dataset.py
+
2
−
2
View file @
ded67dc2
...
...
@@ -39,8 +39,8 @@ class test_dataset(unittest.TestCase):
bad_location
=
dataset
.
dataset
(
name
=
None
,
serve
=
True
,
locations
=
(
badpath
,))
self
.
assertFalse
(
bad_location
.
is_valid
())
bad_location
=
dataset
.
dataset
(
name
=
None
,
serve
=
True
,
locations
=
(
None
,))
self
.
assertFalse
(
bad_location
.
is_valid
(
))
with
self
.
assertRaises
(
TypeError
):
bad_location
=
dataset
.
dataset
(
name
=
None
,
serve
=
True
,
locations
=
(
None
,
))
if
__name__
==
"
__main__
"
:
...
...
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