-
Notifications
You must be signed in to change notification settings - Fork 12
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
Use relative (.xyz) and absolute (sssom.xyz) imports consistently #130
Comments
I've seen both used but sometimes using relative imports causes issues when a module is imported. Any other opinions? |
I prefer relative imports because it reminds you never to run packaged code as a script, except through the |
1. Closes #130 by switching to all relative imports 2. Removes some dead code 3. Updates docstrings and type annotations
I am happy either way, what you are saying makes sense, lets go with relative for now.. Thanks @cthoyt |
* Code cleanup 1. Closes #130 by switching to all relative imports 2. Removes some dead code 3. Updates docstrings and type annotations * More cleanup 1. Refactor the same validation code 2. Add more type annotations 3. standardize order of meta, curie map * Update parsers.py * Update text for output * Update function calls and error types * Update parsers.py * Use meaningful variable names
@joeflack4 had trouble getting sssom-py up and running for development. Putting this decision up for another vote, here is the related SO thread: https://stackoverflow.com/questions/4209641/absolute-vs-explicit-relative-import-of-python-module @joeflack4 do you have any opinion? |
Thanks, @matentzn . That thread you linked is one of a great many on this topic. Like most of those threads, the consensus is to use absolute imports. I've been having difficulty getting the relative imports to work with PyCharm, both in this project and other projects. As for this project, I'm using Python 3.9. I tried I've been working with Python for awhile and I wasn't sure if I agreed with @cthoyt . That doesn't seem to line up with my experience with Python. I've always used absolute imports when running my packages using I also just did an experiment locally, and as I expected, running a script directly which uses absolute imports did not work for me.
However, running as a module this way works fine whether I'm using absolute or relative in this specific case:
from .b import x
from pkg.a import z
print(x)
print(z) I assigned both
In any case, as I mentioned to Nico and Harshad, I've tried relative imports a number of times, and while relative imports make a lot of sense to me in theory, and I would prefer to use them if I could, they don't end up working out for me in a lot of situations. In the past, I've gotten them to work in some situations, but then if I hand my code to someone else with a different machine / project setup, or if I try running my code a different way, they don't always work. Meanwhile, I've found absolute imports to be very reliable. I think I've gotten them to work just about always. So, my recommendation is absolute imports (unless we can figure out some magic to make relative imports work reliably everywhere). |
I don't have a lot of energy/motivation for education at the moment, but the fact that you ran into this issue demonstrates that if you use the non- Best next step would be to adopt the standard |
@joeflack4 are you positive you cannot fix the problem in your setup? We do not have the time atm to change the SSSOM layout, and I also do not want to hastily push absolute package imports through now without a proper investigation.. |
@matentzn As I mentioned (maybe in another thread), I'll just debug using absolute imports, and change them back to relative before I submit a PR. |
If it aint too much of a pain... :) You know best! |
See @cthoyt comment here.
The text was updated successfully, but these errors were encountered: