From ab2dc9008d0bf41c83d035f8636e2adb60366a64 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Sat, 25 May 2019 08:44:50 +0200 Subject: [PATCH] cite adds _cite attribute to non-callable instance --- mechcite/citation.py | 18 +++++++++++------- setup.py | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/mechcite/citation.py b/mechcite/citation.py index be81d3d..b2d5132 100644 --- a/mechcite/citation.py +++ b/mechcite/citation.py @@ -9,11 +9,15 @@ def __init__(self, key): self.bib = Bibliography() def __call__(self, f): - @wraps(f) - def wrapped_f(*args, **kwargs): - if not self.used: - self.bib.cite(self.key) - self.used = True - return f(*args, **kwargs) + if hasattr(f, '__call__'): + @wraps(f) + def wrapped_f(*args, **kwargs): + if not self.used: + self.bib.cite(self.key) + self.used = True + return f(*args, **kwargs) - return wrapped_f + return wrapped_f + else: + f._cite = self.key + return f diff --git a/setup.py b/setup.py index fcf4d31..6cfe679 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', ], - description="Python package for the definition of materials used during mechanical engineering calculations", + description="Python package for decorating classes and functions with a citation and generating a bibliography when those are used", install_requires=requirements, license="MIT license", long_description=readme + '\n\n' + history,