Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Spack
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
Package registry
Container 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
eic_tools
Spack
Commits
9d90cb69
Commit
9d90cb69
authored
9 years ago
by
Ben Boeckel
Browse files
Options
Downloads
Patches
Plain Diff
python: use the setdefault method on dict
It allows more concise code and skips some key lookups.
parent
f76b3890
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/spack/llnl/util/lang.py
+1
-4
1 addition, 4 deletions
lib/spack/llnl/util/lang.py
lib/spack/spack/directives.py
+4
-6
4 additions, 6 deletions
lib/spack/spack/directives.py
lib/spack/spack/virtual.py
+2
-6
2 additions, 6 deletions
lib/spack/spack/virtual.py
with
7 additions
and
16 deletions
lib/spack/llnl/util/lang.py
+
1
−
4
View file @
9d90cb69
...
@@ -87,10 +87,7 @@ def index_by(objects, *funcs):
...
@@ -87,10 +87,7 @@ def index_by(objects, *funcs):
result
=
{}
result
=
{}
for
o
in
objects
:
for
o
in
objects
:
key
=
f
(
o
)
key
=
f
(
o
)
if
key
not
in
result
:
result
.
setdefault
(
key
,
[]).
append
(
o
)
result
[
key
]
=
[
o
]
else
:
result
[
key
].
append
(
o
)
for
key
,
objects
in
result
.
items
():
for
key
,
objects
in
result
.
items
():
result
[
key
]
=
index_by
(
objects
,
*
funcs
[
1
:])
result
[
key
]
=
index_by
(
objects
,
*
funcs
[
1
:])
...
...
This diff is collapsed.
Click to expand it.
lib/spack/spack/directives.py
+
4
−
6
View file @
9d90cb69
...
@@ -239,12 +239,10 @@ def patch(pkg, url_or_filename, level=1, when=None):
...
@@ -239,12 +239,10 @@ def patch(pkg, url_or_filename, level=1, when=None):
when
=
pkg
.
name
when
=
pkg
.
name
when_spec
=
parse_anonymous_spec
(
when
,
pkg
.
name
)
when_spec
=
parse_anonymous_spec
(
when
,
pkg
.
name
)
if
when_spec
not
in
pkg
.
patches
:
cur_patches
=
pkg
.
patches
.
setdefault
(
when_spec
,
[])
pkg
.
patches
[
when_spec
]
=
[
Patch
(
pkg
.
name
,
url_or_filename
,
level
)]
# if this spec is identical to some other, then append this
else
:
# patch to the existing list.
# if this spec is identical to some other, then append this
cur_patches
.
append
(
Patch
(
pkg
.
name
,
url_or_filename
,
level
))
# patch to the existing list.
pkg
.
patches
[
when_spec
].
append
(
Patch
(
pkg
.
name
,
url_or_filename
,
level
))
@directive
(
'
variants
'
)
@directive
(
'
variants
'
)
...
...
This diff is collapsed.
Click to expand it.
lib/spack/spack/virtual.py
+
2
−
6
View file @
9d90cb69
...
@@ -73,10 +73,8 @@ def update(self, spec):
...
@@ -73,10 +73,8 @@ def update(self, spec):
for
provided_spec
,
provider_spec
in
pkg
.
provided
.
iteritems
():
for
provided_spec
,
provider_spec
in
pkg
.
provided
.
iteritems
():
if
provider_spec
.
satisfies
(
spec
,
deps
=
False
):
if
provider_spec
.
satisfies
(
spec
,
deps
=
False
):
provided_name
=
provided_spec
.
name
provided_name
=
provided_spec
.
name
if
provided_name
not
in
self
.
providers
:
self
.
providers
[
provided_name
]
=
{}
provider_map
=
self
.
providers
[
provided_name
]
provider_map
=
self
.
providers
.
setdefault
(
provided_name
,
{})
if
not
provided_spec
in
provider_map
:
if
not
provided_spec
in
provider_map
:
provider_map
[
provided_spec
]
=
set
()
provider_map
[
provided_spec
]
=
set
()
...
@@ -133,9 +131,7 @@ def _cross_provider_maps(self, lmap, rmap):
...
@@ -133,9 +131,7 @@ def _cross_provider_maps(self, lmap, rmap):
if
lp_spec
.
name
==
rp_spec
.
name
:
if
lp_spec
.
name
==
rp_spec
.
name
:
try
:
try
:
const
=
lp_spec
.
copy
().
constrain
(
rp_spec
,
deps
=
False
)
const
=
lp_spec
.
copy
().
constrain
(
rp_spec
,
deps
=
False
)
if
constrained
not
in
result
:
result
.
setdefault
(
constrained
,
set
()).
add
(
const
)
result
[
constrained
]
=
set
()
result
[
constrained
].
add
(
const
)
except
spack
.
spec
.
UnsatisfiableSpecError
:
except
spack
.
spec
.
UnsatisfiableSpecError
:
continue
continue
return
result
return
result
...
...
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