New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
duecredits #1822
Merged
Merged
duecredits #1822
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
931c170
File for duecredit module to load
ayushsuhane bbe9fe5
Changed the format of due.py to resolve the error in test
ayushsuhane 0060430
add citations for MDAnalysis
ayushsuhane b15e8ea
Added the test case for Duecredit
ayushsuhane dde9250
Updated docs, authors, and changelog
ayushsuhane 46fe093
omit due.py from coverage reporting
ayushsuhane e3d5cac
fixed duecredit import error reporting in due stub
orbeckst f68f884
duecredit: small fixes
orbeckst d97c75e
remove UTF-8 from duecredit citation
orbeckst ffc7b7a
mock out calls to fork() in duecredit
zemanj File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ omit = | |
*/visualization/* | ||
*/MDAnalysis/tests/* | ||
*/legacy/* | ||
*/due.py | ||
|
||
[report] | ||
exclude_lines = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# emacs: at the end of the file | ||
# ex: set sts=4 ts=4 sw=4 et: | ||
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # | ||
"""Stub file for a guaranteed safe import of duecredit constructs: if duecredit | ||
is not available. | ||
|
||
To use it, place it into your project codebase to be imported, e.g. copy as | ||
|
||
cp stub.py /path/tomodule/module/due.py | ||
|
||
Note that it might be better to avoid naming it duecredit.py to avoid shadowing | ||
installed duecredit. | ||
|
||
Then use in your code as | ||
|
||
from .due import due, Doi, BibTeX | ||
|
||
See https://github.com/duecredit/duecredit/blob/master/README.md for examples. | ||
|
||
Origin: Originally a part of the duecredit | ||
Copyright: 2015-2016 DueCredit developers | ||
License: BSD-2 | ||
|
||
Modified for MDAnalysis to avoid calls to fork which raises cryptic | ||
warning under MPI(see PR #1794 for rationale) | ||
|
||
""" | ||
|
||
__version__ = '0.0.5' | ||
|
||
|
||
class InactiveDueCreditCollector(object): | ||
"""Just a stub at the Collector which would not do anything""" | ||
def _donothing(self, *args, **kwargs): | ||
"""Perform no good and no bad""" | ||
pass | ||
|
||
def dcite(self, *args, **kwargs): | ||
"""If I could cite I would""" | ||
def nondecorating_decorator(func): | ||
return func | ||
return nondecorating_decorator | ||
|
||
cite = load = add = _donothing | ||
|
||
def __repr__(self): | ||
return self.__class__.__name__ + '()' | ||
|
||
|
||
def _donothing_func(*args, **kwargs): | ||
"""Perform no good and no bad""" | ||
pass | ||
|
||
|
||
try: | ||
# Avoid call of fork inside duecredit; see | ||
# https://github.com/MDAnalysis/mdanalysis/pull/1822#issuecomment-373009050 | ||
import sys | ||
import os | ||
if sys.version_info >= (3, 7): | ||
import duecredit | ||
else: | ||
from mock import patch | ||
if sys.version_info <= (2, ): | ||
from contextlib import nested | ||
with nested(patch('os.fork'), patch('os.popen')) \ | ||
as (os_dot_fork, os_dot_popen): | ||
import duecredit | ||
else: | ||
with patch('os.fork') as os_dot_fork, patch('os.popen') as os_dot_popen: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this doing the same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good, afaik that is the correct Python 3 way of "nesting" context managers. |
||
import duecredit | ||
|
||
from duecredit import due, BibTeX, Doi, Url | ||
if 'due' in locals() and not hasattr(due, 'cite'): | ||
raise RuntimeError( | ||
"Imported due lacks .cite. DueCredit is now disabled") | ||
except Exception as err: | ||
if not isinstance(err, ImportError): | ||
import logging | ||
import warnings | ||
errmsg = "Failed to import duecredit due to {}".format(str(err)) | ||
warnings.warn(errmsg) | ||
logging.getLogger("duecredit").error( | ||
"Failed to import duecredit due to {}".format(str(err))) | ||
else: | ||
# for debugging | ||
import warnings | ||
warnings.warn(str(err)) | ||
# Initiate due stub | ||
due = InactiveDueCreditCollector() | ||
BibTeX = Doi = Url = _donothing_func | ||
|
||
# Emacs mode definitions | ||
# Local Variables: | ||
# mode: python | ||
# py-indent-offset: 4 | ||
# tab-width: 4 | ||
# indent-tabs-mode: nil | ||
# End: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- | ||
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8 | ||
# | ||
# MDAnalysis --- https://www.mdanalysis.org | ||
# Copyright (c) 2006-2017 The MDAnalysis Development Team and contributors | ||
# (see the file AUTHORS for the full list of names) | ||
# | ||
# Released under the GNU Public Licence, v2 or any higher version | ||
# | ||
# Please cite your use of MDAnalysis in published work: | ||
# | ||
# R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler, | ||
# D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein. | ||
# MDAnalysis: A Python package for the rapid analysis of molecular dynamics | ||
# simulations. In S. Benthall and S. Rostrup editors, Proceedings of the 15th | ||
# Python in Science Conference, pages 102-109, Austin, TX, 2016. SciPy. | ||
# | ||
# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein. | ||
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. | ||
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 | ||
# | ||
from __future__ import absolute_import | ||
import os | ||
import pytest | ||
|
||
# environment variable DUECREDIT_ENABLE is set to yes in MDAnalysisTests/__init__.py | ||
# (if set to 'no', the tests will be SKIPPED; has to be yes, true, or 1 for duecredit | ||
# to work; duecredit must also be installed) | ||
import MDAnalysis as mda | ||
|
||
|
||
@pytest.mark.skipif((os.environ.get('DUECREDIT_ENABLE', 'yes').lower() | ||
in ('no', '0', 'false')), | ||
reason= | ||
"duecredit is explicitly disabled with DUECREDIT_ENABLE=no") | ||
class TestDuecredits(object): | ||
|
||
def test_duecredit_active(self): | ||
assert mda.due.active == True | ||
|
||
|
||
def test_duecredit_collector_citations(self): | ||
|
||
assert mda.due.citations[('MDAnalysis/', | ||
'gowers2016')].cites_module == True | ||
assert mda.due.citations[('MDAnalysis/', | ||
'10.1002/jcc.21787')].cites_module == True |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
author isn't added to changelog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done