Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.pipelines
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
bob
bob.pipelines
Commits
aa994f82
Commit
aa994f82
authored
4 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
[DelayedSample] Allow for arbitrary delayed attributes
Also, Disable caching
parent
6ea25543
No related branches found
No related tags found
1 merge request
!47
Multiple changes
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/pipelines/sample.py
+21
-7
21 additions, 7 deletions
bob/pipelines/sample.py
with
21 additions
and
7 deletions
bob/pipelines/sample.py
+
21
−
7
View file @
aa994f82
...
...
@@ -87,7 +87,7 @@ class DelayedSample(_ReprMixin):
Parameters
----------
load
:
load
A python function that can be called parameterlessly, to load the
sample in question from whatever medium
...
...
@@ -95,24 +95,38 @@ class DelayedSample(_ReprMixin):
If passed, consider this as a parent of this sample, to copy
information
delayed_attributes : dict or None
A dictionary of name : load_fn pairs that will be used to create
attributes of name : load_fn() in this class. Use this to option
to create more delayed attributes than just ``sample.data``.
kwargs : dict
Further attributes of this sample, to be stored and eventually
transmitted to transformed versions of the sample
"""
def
__init__
(
self
,
load
,
parent
=
None
,
**
kwargs
):
self
.
load
=
load
def
__init__
(
self
,
load
,
parent
=
None
,
delayed_attributes
=
None
,
**
kwargs
):
if
parent
is
not
None
:
_copy_attributes
(
self
,
parent
.
__dict__
)
_copy_attributes
(
self
,
kwargs
)
self
.
_data
=
None
self
.
load
=
load
self
.
delayed_attributes
=
delayed_attributes
def
__getattr__
(
self
,
name
:
str
):
if
self
.
delayed_attributes
is
None
:
raise
AttributeError
(
name
)
load_fn
=
self
.
delayed_attributes
.
get
(
name
)
if
load_fn
is
None
:
raise
AttributeError
(
name
)
return
load_fn
()
@property
def
data
(
self
):
"""
Loads the data from the disk file.
"""
if
self
.
_data
is
None
:
self
.
_data
=
self
.
load
()
return
self
.
_data
return
self
.
load
()
class
SampleSet
(
MutableSequence
,
_ReprMixin
):
...
...
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