IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
corsika
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
Issue 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
Air Shower Physics
corsika
Commits
378be4d6
Commit
378be4d6
authored
4 years ago
by
Remy Prechelt
Browse files
Options
Downloads
Patches
Plain Diff
Fix bug in loading of library from Python.
parent
95724831
No related branches found
No related tags found
1 merge request
!317
Output infrastructure and Python analysis library.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/corsika/io/library.py
+23
-11
23 additions, 11 deletions
python/corsika/io/library.py
with
23 additions
and
11 deletions
python/corsika/io/library.py
+
23
−
11
View file @
378be4d6
...
@@ -11,7 +11,7 @@ import logging
...
@@ -11,7 +11,7 @@ import logging
import
os
import
os
import
os.path
as
op
import
os.path
as
op
import
re
import
re
from
typing
import
Any
,
Dict
,
Optional
from
typing
import
Any
,
Dict
,
Optional
,
List
import
yaml
import
yaml
...
@@ -51,6 +51,20 @@ class Library(object):
...
@@ -51,6 +51,20 @@ class Library(object):
# build the list of outputs
# build the list of outputs
self
.
__outputs
=
self
.
__build_outputs
(
path
)
self
.
__outputs
=
self
.
__build_outputs
(
path
)
@property
def
names
(
self
)
->
List
[
str
]:
"""
Return the list of registered outputs.
"""
return
list
(
self
.
__outputs
.
keys
())
@property
def
modules
(
self
)
->
Dict
[
str
,
str
]:
"""
Return the list of registered outputs.
"""
pass
def
get
(
self
,
name
:
str
)
->
Optional
[
outputs
.
Output
]:
def
get
(
self
,
name
:
str
)
->
Optional
[
outputs
.
Output
]:
"""
"""
Return the output with a given name.
Return the output with a given name.
...
@@ -138,7 +152,7 @@ class Library(object):
...
@@ -138,7 +152,7 @@ class Library(object):
_
,
dirs
,
_
=
next
(
os
.
walk
(
path
))
_
,
dirs
,
_
=
next
(
os
.
walk
(
path
))
# this is the dictionary where we store our components
# this is the dictionary where we store our components
outpu
ts
:
Dict
[
str
,
Any
]
=
{}
componen
ts
:
Dict
[
str
,
Any
]
=
{}
# loop over the subdirectories
# loop over the subdirectories
for
subdir
in
dirs
:
for
subdir
in
dirs
:
...
@@ -166,13 +180,10 @@ class Library(object):
...
@@ -166,13 +180,10 @@ class Library(object):
try
:
try
:
# create the name of the module containing this output class
# create the name of the module containing this output class
module_name
=
re
.
sub
(
r
"
(?<!^)(?=[A-Z])
"
,
"
_
"
,
out_type
).
lower
()
#
module_name = re.sub(r"(?<!^)(?=[A-Z])", "_", out_type).lower()
# instantiate the output and store it in our dict
# instantiate the output and store it in our dict
# we use a regex to go from CamelCase to snake_case
component
=
getattr
(
outputs
,
out_type
)(
op
.
join
(
path
,
subdir
))
component
=
getattr
(
getattr
(
outputs
,
module_name
),
out_type
)(
op
.
join
(
path
,
subdir
)
)
# check if the read failed
# check if the read failed
if
not
component
.
is_good
():
if
not
component
.
is_good
():
...
@@ -182,15 +193,16 @@ class Library(object):
...
@@ -182,15 +193,16 @@ class Library(object):
)
)
logging
.
getLogger
(
"
corsika
"
).
warn
(
msg
)
logging
.
getLogger
(
"
corsika
"
).
warn
(
msg
)
else
:
else
:
outpu
ts
[
name
]
=
component
componen
ts
[
name
]
=
component
except
AttributeError
:
except
AttributeError
as
e
:
msg
=
(
msg
=
(
f
"
Unable to instantiate an instance of
'
{
out_type
}
'
"
f
"
Unable to instantiate an instance of
'
{
out_type
}
'
"
"
for a process called
'
{name}
'"
f
"
for a process called
'
{
name
}
'"
)
)
logging
.
getLogger
(
"
corsika
"
).
warn
(
msg
)
logging
.
getLogger
(
"
corsika
"
).
warn
(
msg
)
logging
.
getLogger
(
"
corsika
"
).
warn
(
e
)
continue
# skip to the next output, don't error
continue
# skip to the next output, don't error
# and we are done building - return the constructed outputs
# and we are done building - return the constructed outputs
return
outpu
ts
return
componen
ts
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