jjmccollum / teiphy

A Python package for converting TEI XML collations to NEXUS, BEAST 2.7 XML, and other formats
MIT License
11 stars 3 forks source link

refactor into separate files #23

Closed rbturnbull closed 2 years ago

rbturnbull commented 2 years ago

Hi @jjmccollum - the teiphy.py file is quite big. I think it would be good to split it up into separate files. How about one file per class. i.e. Collation can be in collation.py and Witness can be in witness.py.

I'd do the same with the tests and have a test_witness.py and a test_collation.py etc.

What do you think?

jjmccollum commented 2 years ago

@rbturnbull That makes sense to me. If I want the components of the package to be importable via statements like

from teiphy import Collation

do I leave the teiphy.py script in place and add something to it to export these variables?

rbturnbull commented 2 years ago

we can sort that out in the __init__.py. I've already added some code for that and we can adapt it when the files are split.

jjmccollum commented 2 years ago

Okay, I've separated teiphy.py into common.py (containing shared variables like xml_ns and tei_ns), witness.py, reading.py, variation_unit.py, and collation.py, and I've separated the test scripts similarly. How should I change __init__.py so that I can import these classes in the unit tests?

rbturnbull commented 2 years ago

Great work. You now need to add this to __init__.py:

from .witness import Witness from .variation_unit import VariationUnit from .collation import Collation from .reading import Reading

jjmccollum commented 2 years ago

All right, I have it split up with all tests passing! The old teiphy.py script is empty now; can it be removed since the teiphy package is now exposed via the __init__.py script?

rbturnbull commented 2 years ago

yep - that's right