Commit 8cc0fad4 authored by m_huelsberg's avatar m_huelsberg
Browse files

savefig now also saves a file resources.txt by default, which contains all...

savefig now also saves a file resources.txt by default, which contains all loaded package names and versions

wish for the future: 'pip freeze' functionality, where URLs are present with commit hashes (e.g. analyzebd @ git+https://git.tu-berlin.de/m_huelsberg/analyzebd.git@57a398a0e8a0d6e894260918dcdf18b4a60811d3)
parent 57a398a0
import pkg_resources
from pathlib import Path
import matplotlib.pyplot as plt
from analyzebd.helpers.clock import Clock
def savefig(fname, formats=None, verbose=True, **kwargs):
def writeSourcesToFile(fname="resources.txt", verbose=False):
fname = Path(fname)
installed_packages = pkg_resources.working_set
# needed step to sort list
installed_packages_list = sorted([f"{i.key}=={i.version}" for i in installed_packages])
installed_packages_str = ""
for s in installed_packages_list:
installed_packages_str += f"{s}\n"
with open(fname, "w") as f:
f.write(installed_packages_str)
if verbose:
print(f"Saved resources to {fname.name}")
return True
def savefig(fname, formats=None, save_resources=True, verbose=True, **kwargs):
"""
Save the current figure with the specified formats.
:param formats: str or list of str (default: ['.png', '.pdf'])
......@@ -27,4 +44,6 @@ def savefig(fname, formats=None, verbose=True, **kwargs):
if verbose:
clock.lap()
print(f"Saved plot to {outname.name} ... {clock(-2, -1)}")
return outnames
\ No newline at end of file
if save_resources:
writeSourcesToFile(verbose=verbose)
return outnames
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment