Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
orchestra-v3
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
Alessandro Di Federico
orchestra-v3
Commits
4072b31d
Commit
4072b31d
authored
4 years ago
by
Filippo Cremonese
Browse files
Options
Downloads
Patches
Plain Diff
Improved configuration cache handling
parent
a669223e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
orchestra/config.py
+14
-5
14 additions, 5 deletions
orchestra/config.py
with
14 additions
and
5 deletions
orchestra/config.py
+
14
−
5
View file @
4072b31d
...
...
@@ -3,25 +3,34 @@ import yaml
import
os
def
hash_config_dir
(
config_dir
):
hash_script
=
f
"""
find
"
{
config_dir
}
"
-type f -print0 | sort -z | xargs -0 sha1sum | sha1sum
"""
config_hash
=
subprocess
.
check_output
(
hash_script
,
shell
=
True
).
decode
(
"
utf-8
"
).
strip
().
partition
(
"
"
)[
0
]
return
config_hash
def
gen_yaml
(
config_dir
,
use_cache
=
True
):
# TODO: this method of obtaining the orchestra directory is a hack and is duplicated in environment.py
orchestra_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
+
"
/..
"
))
config_cache_dir
=
f
"
{
orchestra_dir
}
/.orchestra/config_cache
"
config_cache_dir
=
f
"
{
orchestra_dir
}
/.orchestra
"
config_cache_file
=
f
"
{
config_cache_dir
}
/config_cache
"
if
use_cache
:
hash_script
=
f
"""
find
"
{
config_dir
}
"
-type f -print0 | sort -z | xargs -0 sha1sum | sha1sum
"""
config_hash
=
subprocess
.
check_output
(
hash_script
,
shell
=
True
).
decode
(
"
utf-8
"
).
strip
().
partition
(
"
"
)[
0
]
config_cache_file
=
f
"
{
config_cache_dir
}
/
{
config_hash
}
.yml
"
config_hash
=
hash_config_dir
(
config_dir
)
if
os
.
path
.
exists
(
config_cache_file
):
with
open
(
config_cache_file
,
"
rb
"
)
as
f
:
return
f
.
read
()
cached_hash
=
f
.
readline
().
decode
(
"
utf-8
"
).
strip
()
if
config_hash
==
cached_hash
:
return
f
.
read
()
expanded_yaml
=
subprocess
.
check_output
(
f
"
GOGC=off ytt -f
{
config_dir
}
"
,
shell
=
True
)
if
use_cache
:
os
.
makedirs
(
config_cache_dir
,
exist_ok
=
True
)
with
open
(
config_cache_file
,
"
wb
"
)
as
f
:
f
.
write
(
config_hash
.
encode
(
"
utf-8
"
)
+
b
"
\n
"
)
f
.
write
(
expanded_yaml
)
return
expanded_yaml
...
...
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