Fix __version__, pdf annotate function

This commit is contained in:
Marek Nečada 2022-06-21 07:48:20 +03:00
parent 78992188fd
commit 260b053102
2 changed files with 24 additions and 2 deletions

View File

@ -1,5 +1,3 @@
from pkg_resources import get_distribution
__version__ = get_distribution('qpms').version
import os as __os
from sys import platform as __platform
@ -24,6 +22,11 @@ from .cymaterials import MaterialInterpolator, EpsMu, LorentzDrudeModel, lorentz
from .cycommon import dbgmsg_enable, dbgmsg_disable, dbgmsg_active, BesselType, VSWFType
from .cywaves import vswf_single
def __version__():
from pkg_resources import get_distribution
librev = qpms_library_version()
return get_distribution('qpms').version + (("lr:"+librev) if librev else "")
#from .qpms_p import * # don't import automatically (adds around 0.5 s delay and depends on scipy)
from .constants import *

View File

@ -540,3 +540,22 @@ class ArgParser:
plist.extend([Particle(pos, t, bspec=bspec) for pos in poss])
return plist
#TODO perhaps move into another module
def annotate_pdf_metadata(pdfPages, scriptname=None, keywords=None, author=None, title=None, subject=None, **kwargs):
"""Adds QPMS version-related metadata to a matplotlib PdfPages object
Use before closing the PDF file.
"""
from .qpms_c import qpms_library_version
d = pdfPages.infodict()
d['Creator'] = "QPMS%s (lib rev. %s), https://qpms.necada.org" % (
"" if scriptname is None else (" "+scriptname), qpms_library_version())
if author is not None:
d['Author'] = author
if title is not None:
d['Title'] = title
if subject is not None:
d['Subject'] = subject
if keywords is not None:
d['Keywords'] = ' '.join(keywords)
d.update(kwargs)