Skip to content

Commit

Permalink
cite adds _cite attribute to non-callable instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jellespijker committed May 25, 2019
1 parent 41f4d3b commit ab2dc90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions mechcite/citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ab2dc90

Please # to comment.