-
Notifications
You must be signed in to change notification settings - Fork 189
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
Replace site.species_and_occu with site.species property for compatible pymatgen versions #3480
Replace site.species_and_occu with site.species property for compatible pymatgen versions #3480
Conversation
use site.species for pymatgen versions >= 2019.3.13 and keep backward compatability by falling back to the old site.species_and_occu for versions < 2019.3.13.
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.
Thanks for taking care of this! 😃 Looks good overall.
aiida/orm/nodes/data/structure.py
Outdated
for site in struct.sites: | ||
|
||
# site.species property first introduced in pymatgen version 2019.3.13 | ||
if pymatgen_version < (2019, 3, 13): |
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.
I think here it'd be better to just do plain string comparison - something like "2019.3.13b2"
would also be a legal version string (although pymatgen doesn't seem to use it). That would break the int
conversion above.
Sorry for the nit-pick 😬
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.
Better still I would say is to use something like:
from distutils.version import StrictVersion
current_version = StrictVersion(get_pymatgen_version())
required_version = StrictVersion('2019.3.13')
if current_version < required_version:
species_and_occu = site.species_and_occu
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.
Nice 👍
Btw, do we want to bump the pymatgen
version in setup.json
? It's currently at "pymatgen<=2018.12.12"
. Not sure what the differences are though, tbh.
This issue came up because some dependency of mine changed the pymatgen
version.
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.
We can't unfortunately because they dropped python 2 support after that.
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.
Soon... 😎
I think you can ignore the coverall failure, but I'll leave that to @sphuber to confirm. |
aiida/orm/nodes/data/structure.py
Outdated
@@ -18,6 +18,7 @@ | |||
import itertools | |||
import copy | |||
from functools import reduce | |||
from packaging import version |
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.
Thanks for the update @astamminger . One question: is there a reason you prefer the dependency packaging
over the standard library distutils
?
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.
Was about to write a comment on that but you were too fast :D Mainly the reason was that AFAIK StrictVersion
provided by distutils
does not comply to PEP440 so I thoughtpackaging
might be a better alternative (But I'm happy to change that if you prefer to use distutils
)
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.
Thanks, I didn't know that. It seems indeed that packaging
seems the more reliable option. I was just worried about it being third-party and therefore adding an implicit dependency, but since it gets installed by setuptools
that is ok
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.
From looking at the list of maintainers on PyPI, packaging
seems pretty solid. We should add it as an explicit dependency in setup.json
if we use it explicitly, though.
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.
Could you add the dependency to the atomic_tools
extra @astamminger ? Since it is only used in combination with pymatgen
I think it is ok to just put it in that extra
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.
Shouldn't we move the import to the function itself then? Might be easier to just put it in the general dependencies.
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.
We could also use pkg_resources.parse_version()
which is distributed with setuptools
so we can avoid adding an additional dependency plus being PEP440 conform. What do you think?
// EDIT: No idea what's going on with the coveralls, though!
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.
Go for it 👍 Let's try not to bike-shed too hard here..
I have a feeling the coveralls can be a bit flaky sometimes.
@astamminger if you can move the |
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.
Thanks @astamminger
Fixes #3297
Added check for the used pymatgen version and dynamically switch to
Site.species
property if applicable (i.e.pymatgen>=2019.3.13
). Prior to2019.3.13
the oldSite.species_and_occu
property is used.