From 260b0531027108b2f42a3a254d50ee2e9e13f86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Tue, 21 Jun 2022 07:48:20 +0300 Subject: [PATCH] Fix __version__, pdf annotate function --- qpms/__init__.py | 7 +++++-- qpms/argproc.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/qpms/__init__.py b/qpms/__init__.py index ea722d4..f83e93b 100644 --- a/qpms/__init__.py +++ b/qpms/__init__.py @@ -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 * diff --git a/qpms/argproc.py b/qpms/argproc.py index b06e9b7..c77e1f4 100644 --- a/qpms/argproc.py +++ b/qpms/argproc.py @@ -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)