duecredit / duecredit

Automated collection and reporting of citations for used software/methods/datasets
Other
238 stars 28 forks source link

ImportError when using duecredit #218

Closed lvotapka closed 3 months ago

lvotapka commented 3 months ago

Hello,

I've got a Git repo (https://github.com/seekrcentral/seekr2.git) that I'd like to add duecredit to, so that I and my users can cite our project and all our dependences.

First, I installed duecredit with pip install duecredit

Then, within seekr2/seekr2/modules/, I've downloaded stub.py wget -q -O due.py https://raw.githubusercontent.com/duecredit/duecredit/master/duecredit/stub.py

Then, since I have a module named common_base.py in that directory, I placed a citation in there:

from .due import due, Doi, BibTeX
due.cite(BibTeX("""
         @article{votapka2022seekr2,
         title={SEEKR2: Versatile multiscale milestoning utilizing the OpenMM molecular dynamics engine},
         author={Votapka, Lane W and Stokely, Andrew M and Ojha, Anupam A and Amaro, Rommie E},
         journal={Journal of chemical information and modeling},
         volume={62},
         number={13},
         pages={3253--3262},
         year={2022},
         publisher={ACS Publications}
         }
         """),
         description="Multiscale molecular kinetics and thermodynamics with milestoning.",
         path="seekr2/modules", cite_module=True)

But when I run, I get the following error and incomplete output:

python -m duecredit common_base.py 
Traceback (most recent call last):
  File "/home/lvotapka/mambaforge/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/lvotapka/mambaforge/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/lvotapka/mambaforge/lib/python3.10/site-packages/duecredit/__main__.py", line 100, in <module>
    main()
  File "/home/lvotapka/mambaforge/lib/python3.10/site-packages/duecredit/__main__.py", line 90, in main
    runctx(code, globs, globs)
  File "/home/lvotapka/mambaforge/lib/python3.10/site-packages/duecredit/__main__.py", line 40, in runctx
    exec(cmd, global_ctx, local_ctx)
  File "common_base.py", line 15, in <module>
    from .due import due, Doi, BibTeX
  File "/home/lvotapka/mambaforge/lib/python3.10/site-packages/duecredit/injections/injector.py", line 342, in __import
    mod = self._orig_import(name, *args, **kwargs)
ImportError: attempted relative import with no known parent package

DueCredit Report:
- Scientific tools library / numpy (v 1.26.4) [1]

1 package cited
0 modules cited
0 functions cited

References
----------

[1] Van Der Walt, S., Colbert, S.C. & Varoquaux, G., 2011. The NumPy array: a structure for efficient numerical computation. Computing in Science & Engineering, 13(2), pp.22–30.

My package also imports more than just numpy (matplotlib and scipy), and when I attempt to set: export DUECREDIT_ENABLE=yes I still cannot see my package or the other listed (besides numpy).

yarikoptic commented 3 months ago

Since you used relative import (from .due ...) you cannot just "run"/import that common_base.py as an independent package/module. Try smth like python -c 'import seekr2.modules.common_base' and it should work.

There is nothing really to address in duecredit so I will close this issue but feel welcome to follow up if any further question.