Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
law-analysis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
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
qcd-public
law-analysis
Commits
2093f86b
Commit
2093f86b
authored
1 year ago
by
Daniel Savoiu
Browse files
Options
Downloads
Patches
Plain Diff
Update law to `v0.1.12`. Adapt `SpaceSeparatedListParameter`.
parent
f3328dbe
Branches
fix/space_separated_parameter_for_law_v0.1.12
Branches containing commit
No related tags found
2 merge requests
!6
Update law to `v0.1.12`, reduction of code duplication, and various small fixes.
,
!5
Update law to `v0.1.12`. Adapt `SpaceSeparatedListParameter`.
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
analysis/framework.py
+86
-6
86 additions, 6 deletions
analysis/framework.py
law
+1
-1
1 addition, 1 deletion
law
six
+1
-1
1 addition, 1 deletion
six
with
88 additions
and
8 deletions
analysis/framework.py
+
86
−
6
View file @
2093f86b
...
...
@@ -2,13 +2,16 @@
import
os
import
csv
import
re
import
logging
import
luigi
import
law
import
law.contrib.htcondor
import
six
from
law.parameter
import
CSVParameter
from
law.parameter
import
CSVParameter
,
NO_STR
from
law.util
import
is_lazy_iterable
,
make_tuple
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -17,14 +20,91 @@ law.contrib.load("wlcg")
class
SpaceSeparatedListParameter
(
CSVParameter
):
CSV_SEP
=
"
"
# developed for `law` revision df3d1fd0a15fd73f80eee859a616373d829f4513 (v0.1.12)
# might need to be changed when updating to newer `law` versions
def
__init__
(
self
,
*
args
,
**
kwargs
):
# warn that brace expansion is not supported
if
kwargs
.
pop
(
"
brace_expand
"
,
False
):
logger
.
warning
(
"
{!r} does not support brace expansion
"
.
format
(
self
))
super
(
SpaceSeparatedListParameter
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
_check_len
(
self
,
value
):
value
=
tuple
(
v
.
replace
(
"
,
"
,
"
\\
,
"
)
if
isinstance
(
v
,
six
.
string_types
)
else
v
for
v
in
value
)
super
(
SpaceSeparatedListParameter
,
self
).
_check_len
(
value
)
def
parse
(
self
,
inp
):
# collapse contiguous whitespace
if
self
.
CSV_SEP
in
inp
:
inp
=
re
.
sub
(
r
'
\s+
'
,
'
'
,
inp
)
"""
Parse the SpaceSeparatedListParameter, splitting the `inp` string on
contiguous whitespace.
"""
if
not
inp
or
inp
==
NO_STR
:
value
=
tuple
()
elif
isinstance
(
inp
,
(
tuple
,
list
))
or
is_lazy_iterable
(
inp
):
value
=
make_tuple
(
inp
)
elif
isinstance
(
inp
,
six
.
string_types
):
# replace escaped separators
if
self
.
_escape_sep
:
escaped_sep
=
"
__law_escaped_csv_sep__
"
inp
=
inp
.
replace
(
"
\\
"
,
escaped_sep
)
# replace literal commas so they are not parsed
# by CSV reader
escaped_comma
=
"
__law_escaped_comma__
"
inp
=
inp
.
replace
(
"
,
"
,
escaped_comma
)
# strip initial and final spaces
inp
=
re
.
sub
(
r
"
(^\s+|\s+$)
"
,
""
,
inp
)
# collapse contiguous whitespace to commas
inp
=
re
.
sub
(
r
"
\s+
"
,
"
,
"
,
inp
)
# proper csv split
elems
=
list
(
csv
.
reader
([
inp
]))[
0
]
# add back escaped commas per element
elems
=
[
elem
.
replace
(
escaped_comma
,
"
,
"
)
for
elem
in
elems
]
# add back escaped separators per element
if
self
.
_escape_sep
:
elems
=
[
elem
.
replace
(
escaped_sep
,
"
"
)
for
elem
in
elems
]
value
=
tuple
(
map
(
self
.
_inst
.
parse
,
elems
))
else
:
value
=
(
inp
,)
# apply uniqueness, sort, length and choices checks
value
=
self
.
_check_unique
(
value
)
value
=
self
.
_check_sort
(
value
)
self
.
_check_len
(
value
)
self
.
_check_choices
(
value
)
return
value
def
serialize
(
self
,
value
):
"""
Serialize a value into a string that, when parsed as a
SpaceSeparatedListParameter, yields that value.
"""
if
not
value
:
value
=
tuple
()
value
=
make_tuple
(
value
)
# escape any literal spaces in value elements
value
=
tuple
(
v
.
replace
(
"
"
,
"
\\
"
)
if
isinstance
(
v
,
six
.
string_types
)
else
v
for
v
in
value
)
# apply uniqueness, sort, length and choices checks
value
=
self
.
_check_unique
(
value
)
value
=
self
.
_check_sort
(
value
)
self
.
_check_len
(
value
)
self
.
_check_choices
(
value
)
return
"
"
.
join
(
str
(
self
.
_inst
.
serialize
(
elem
))
for
elem
in
value
)
return
super
(
SpaceSeparatedListParameter
,
self
).
parse
(
inp
)
class
Task
(
law
.
Task
):
...
...
This diff is collapsed.
Click to expand it.
law
@
df3d1fd0
Compare
8c7ae918
...
df3d1fd0
Subproject commit
8c7ae918cf4ed874db518be3d98424b18401282
3
Subproject commit
df3d1fd0a15fd73f80eee859a616373d829f451
3
This diff is collapsed.
Click to expand it.
six
@
65486e43
Compare
3a3db751
...
65486e43
Subproject commit
3a3db7510b33eb22c63ad94bc735a9032949249f
Subproject commit
65486e4383f9f411da95937451205d3c7b61b9e1
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