Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.backend.python
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
Model registry
Operate
Environments
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
beat
beat.backend.python
Commits
818c5e71
Commit
818c5e71
authored
6 years ago
by
Samuel GAIST
Browse files
Options
Downloads
Patches
Plain Diff
[library] Pre-commit cleanup
parent
900b4f01
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!46
Improve asset information
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/backend/python/library.py
+35
-53
35 additions, 53 deletions
beat/backend/python/library.py
with
35 additions
and
53 deletions
beat/backend/python/library.py
+
35
−
53
View file @
818c5e71
...
...
@@ -67,14 +67,14 @@ class Storage(utils.CodeStorage):
def
__init__
(
self
,
prefix
,
name
,
language
=
None
):
if
name
.
count
(
'
/
'
)
!=
2
:
if
name
.
count
(
"
/
"
)
!=
2
:
raise
RuntimeError
(
"
invalid library name: `%s
'"
%
name
)
self
.
username
,
self
.
name
,
self
.
version
=
name
.
split
(
'
/
'
)
self
.
username
,
self
.
name
,
self
.
version
=
name
.
split
(
"
/
"
)
self
.
fullname
=
name
self
.
prefix
=
prefix
path
=
utils
.
hashed_or_simple
(
self
.
prefix
,
'
libraries
'
,
name
,
suffix
=
'
.json
'
)
path
=
utils
.
hashed_or_simple
(
self
.
prefix
,
"
libraries
"
,
name
,
suffix
=
"
.json
"
)
path
=
path
[:
-
5
]
super
(
Storage
,
self
).
__init__
(
path
,
language
)
...
...
@@ -144,10 +144,9 @@ class Library(object):
try
:
self
.
_load
(
name
,
library_cache
)
finally
:
if
self
.
_name
is
not
None
:
#
registers it into the cache, even if failed
if
self
.
_name
is
not
None
:
#
registers it into the cache, even if failed
library_cache
[
self
.
_name
]
=
self
def
_load
(
self
,
data
,
library_cache
):
"""
Loads the library
"""
...
...
@@ -156,16 +155,16 @@ class Library(object):
self
.
storage
=
Storage
(
self
.
prefix
,
data
)
json_path
=
self
.
storage
.
json
.
path
if
not
self
.
storage
.
exists
():
self
.
errors
.
append
(
'
Library declaration file not found: %s
'
%
json_path
)
self
.
errors
.
append
(
"
Library declaration file not found: %s
"
%
json_path
)
return
with
open
(
json_path
,
'
rb
'
)
as
f
:
self
.
data
=
simplejson
.
loads
(
f
.
read
().
decode
(
'
utf-8
'
))
with
open
(
json_path
,
"
rb
"
)
as
f
:
self
.
data
=
simplejson
.
loads
(
f
.
read
().
decode
(
"
utf-8
"
))
self
.
code_path
=
self
.
storage
.
code
.
path
# if no errors so far, make sense out of the library data
self
.
data
.
setdefault
(
'
uses
'
,
{})
self
.
data
.
setdefault
(
"
uses
"
,
{})
if
self
.
uses
is
not
None
:
for
name
,
value
in
self
.
uses
.
items
():
...
...
@@ -173,11 +172,10 @@ class Library(object):
self
.
libraries
[
self
.
_name
]
=
self
def
uses_dict
(
self
):
"""
Returns the usage dictionary for all dependent modules
"""
if
self
.
data
[
'
language
'
]
==
'
unknown
'
:
if
self
.
data
[
"
language
"
]
==
"
unknown
"
:
raise
RuntimeError
(
"
library has no programming language set
"
)
if
not
self
.
_name
:
...
...
@@ -189,95 +187,85 @@ class Library(object):
for
name
,
value
in
self
.
uses
.
items
():
retval
[
name
]
=
dict
(
path
=
self
.
libraries
[
value
].
storage
.
code
.
path
,
uses
=
self
.
libraries
[
value
].
uses_dict
(),
)
path
=
self
.
libraries
[
value
].
storage
.
code
.
path
,
uses
=
self
.
libraries
[
value
].
uses_dict
(),
)
return
retval
def
load
(
self
):
"""
Loads the Python module for this library resolving all references
Returns the loaded Python module.
"""
if
self
.
data
[
'
language
'
]
==
'
unknown
'
:
if
self
.
data
[
"
language
"
]
==
"
unknown
"
:
raise
RuntimeError
(
"
library has no programming language set
"
)
if
not
self
.
_name
:
raise
RuntimeError
(
"
library has no name
"
)
return
loader
.
load_module
(
self
.
name
.
replace
(
os
.
sep
,
'
_
'
),
self
.
storage
.
code
.
path
,
self
.
uses_dict
()
)
return
loader
.
load_module
(
self
.
name
.
replace
(
os
.
sep
,
"
_
"
),
self
.
storage
.
code
.
path
,
self
.
uses_dict
()
)
@property
def
name
(
self
):
"""
Returns the name of this object
"""
return
self
.
_name
or
'
__unnamed_library__
'
return
self
.
_name
or
"
__unnamed_library__
"
@name.setter
def
name
(
self
,
value
):
if
self
.
data
[
'
language
'
]
==
'
unknown
'
:
if
self
.
data
[
"
language
"
]
==
"
unknown
"
:
raise
RuntimeError
(
"
library has no programming language set
"
)
self
.
_name
=
value
self
.
storage
=
Storage
(
self
.
prefix
,
value
,
self
.
data
[
'
language
'
])
self
.
storage
=
Storage
(
self
.
prefix
,
value
,
self
.
data
[
"
language
"
])
@property
def
schema_version
(
self
):
"""
Returns the schema version
"""
return
self
.
data
.
get
(
'
schema_version
'
,
1
)
return
self
.
data
.
get
(
"
schema_version
"
,
1
)
@property
def
language
(
self
):
"""
Returns the current language set for the library code
"""
return
self
.
data
[
'
language
'
]
return
self
.
data
[
"
language
"
]
@language.setter
def
language
(
self
,
value
):
"""
Sets the current executable code programming language
"""
if
self
.
storage
:
self
.
storage
.
language
=
value
self
.
data
[
'
language
'
]
=
value
if
self
.
storage
:
self
.
storage
.
language
=
value
self
.
data
[
"
language
"
]
=
value
self
.
_check_language_consistence
()
@property
def
valid
(
self
):
"""
A boolean that indicates if this library is valid or not
"""
return
not
bool
(
self
.
errors
)
@property
def
uses
(
self
):
return
self
.
data
.
get
(
'
uses
'
)
return
self
.
data
.
get
(
"
uses
"
)
@uses.setter
def
uses
(
self
,
value
):
self
.
data
[
'
uses
'
]
=
value
self
.
data
[
"
uses
"
]
=
value
return
value
@property
def
description
(
self
):
"""
The short description for this object
"""
return
self
.
data
.
get
(
'
description
'
,
None
)
return
self
.
data
.
get
(
"
description
"
,
None
)
@description.setter
def
description
(
self
,
value
):
"""
Sets the short description for this object
"""
self
.
data
[
'
description
'
]
=
value
self
.
data
[
"
description
"
]
=
value
@property
def
documentation
(
self
):
...
...
@@ -290,7 +278,6 @@ class Library(object):
return
self
.
storage
.
doc
.
load
()
return
None
@documentation.setter
def
documentation
(
self
,
value
):
"""
Sets the full-length description for this object
"""
...
...
@@ -298,12 +285,11 @@ class Library(object):
if
not
self
.
_name
:
raise
RuntimeError
(
"
library has no name
"
)
if
hasattr
(
value
,
'
read
'
):
if
hasattr
(
value
,
"
read
"
):
self
.
storage
.
doc
.
save
(
value
.
read
())
else
:
self
.
storage
.
doc
.
save
(
value
)
def
hash
(
self
):
"""
Returns the hexadecimal hash for the current library
"""
...
...
@@ -312,7 +298,6 @@ class Library(object):
return
self
.
storage
.
hash
()
def
json_dumps
(
self
,
indent
=
4
):
"""
Dumps the JSON declaration of this object in a string
...
...
@@ -328,14 +313,11 @@ class Library(object):
"""
return
simplejson
.
dumps
(
self
.
data
,
indent
=
indent
,
cls
=
utils
.
NumpyJSONEncoder
)
return
simplejson
.
dumps
(
self
.
data
,
indent
=
indent
,
cls
=
utils
.
NumpyJSONEncoder
)
def
__str__
(
self
):
return
self
.
json_dumps
()
def
write
(
self
,
storage
=
None
):
"""
Writes contents to prefix location.
...
...
@@ -347,17 +329,16 @@ class Library(object):
"""
if
self
.
data
[
'
language
'
]
==
'
unknown
'
:
if
self
.
data
[
"
language
"
]
==
"
unknown
"
:
raise
RuntimeError
(
"
library has no programming language set
"
)
if
storage
is
None
:
if
not
self
.
_name
:
raise
RuntimeError
(
"
library has no name
"
)
storage
=
self
.
storage
#
overwrite
storage
=
self
.
storage
#
overwrite
storage
.
save
(
str
(
self
),
self
.
code
,
self
.
description
)
def
export
(
self
,
prefix
):
"""
Recursively exports itself into another prefix
...
...
@@ -387,8 +368,9 @@ class Library(object):
raise
RuntimeError
(
"
library is not valid
"
)
if
prefix
==
self
.
prefix
:
raise
RuntimeError
(
"
Cannot export library to the same prefix (
"
"
%s)
"
%
(
prefix
))
raise
RuntimeError
(
"
Cannot export library to the same prefix (
"
"
%s)
"
%
(
prefix
)
)
for
k
in
self
.
libraries
.
values
():
k
.
export
(
prefix
)
...
...
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