Skip to content
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

fix: import error for parsers #327

Open
ycexiao opened this issue Feb 6, 2025 · 1 comment · May be fixed by #329
Open

fix: import error for parsers #327

ycexiao opened this issue Feb 6, 2025 · 1 comment · May be fixed by #329

Comments

@ycexiao
Copy link
Contributor

ycexiao commented Feb 6, 2025

Problem

Running pytest for diffpy.pdfmorph in the main branch.

FAILED tests/test_pdfmorphapp.py::TestApp::test_parser_systemexits - AttributeError: module 'diffpy.utils.parsers' has no attribute 'loaddata'
FAILED tests/test_pdfmorphapp.py::TestApp::test_morphsequence - AttributeError: module 'diffpy.utils.parsers' has no attribute 'loaddata'
FAILED tests/test_pdfmorphio.py::TestApp::test_morph_outputs - AttributeError: module 'diffpy.utils.parsers' has no attribute 'loaddata'
FAILED tests/test_tools.py::TestTools::test_field_sort - AttributeError: module 'diffpy.utils.parsers' has no attribute 'loaddata'

It comes from diffpy.pdfmorph tools.py

import diffpy.utils.parsers as parsers 
# ...
rv = parsers.loaddata.loadData(fname, unpack=True) 

The problem is related to diffpy.utils's sub-package parsers. Old parser is reconstructed as a sub-package and loaddata is a module now.

Proposed solution

A similar structure found in other projects under diffpy.
e.g. for diffpy.pdfmorph 's sub-package morph. The problem is avoided by importing the package's modules in its __init__.py.

from diffpy.pdfmorph.morphs.morph import Morph  # noqa: F401
from diffpy.pdfmorph.morphs.morphchain import MorphChain  # noqa: F401
# ...

Mirroring this method may solve the problem

@ycexiao ycexiao changed the title Fix: import error for parsers fix: import error for parsers Feb 6, 2025
@bobleesj
Copy link
Contributor

bobleesj commented Feb 7, 2025

@ycexiao

am a bit confused. If the API of 'loaddata' has been changed in diffpy.utils, why dont we import it using a new path?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants