Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pystencils_autodiff
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
pycodegen
pystencils_autodiff
Commits
f8071a9e
Commit
f8071a9e
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Add write_cached_content
parent
69e8ca3f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pystencils_autodiff/_file_io.py
+15
-0
15 additions, 0 deletions
src/pystencils_autodiff/_file_io.py
with
15 additions
and
0 deletions
src/pystencils_autodiff/_file_io.py
+
15
−
0
View file @
f8071a9e
...
@@ -7,8 +7,15 @@
...
@@ -7,8 +7,15 @@
"""
"""
"""
"""
import
hashlib
from
os.path
import
exists
,
join
import
jinja2
import
jinja2
from
pystencils.cpu.cpujit
import
get_cache_config
_hash
=
hashlib
.
md5
def
read_template_from_file
(
file
):
def
read_template_from_file
(
file
):
return
jinja2
.
Template
(
read_file
(
file
))
return
jinja2
.
Template
(
read_file
(
file
))
...
@@ -23,3 +30,11 @@ def read_file(file):
...
@@ -23,3 +30,11 @@ def read_file(file):
def
write_file
(
filename
,
content
):
def
write_file
(
filename
,
content
):
with
open
(
filename
,
'
w
'
)
as
f
:
with
open
(
filename
,
'
w
'
)
as
f
:
f
.
write
(
content
)
f
.
write
(
content
)
def
write_cached_content
(
content
,
suffix
):
filename
=
join
(
get_cache_config
()[
'
object_cache
'
],
_hash
(
content
.
encode
()).
hexdigest
()
+
suffix
)
if
not
exists
(
filename
):
with
open
(
filename
,
'
w
'
)
as
f
:
f
.
write
(
content
)
return
filename
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