Skip to content

Commit

Permalink
fix version comparison in importexport
Browse files Browse the repository at this point in the history
it seems, the export version number in newer AiiDA versions is no
longer a string but a float.
Converting both to StrictVersion should solve the problem.

 + aiida.orm.group => aiida.orm.groups

 + disable pylint on distutils
   can be re-enabled after this bug is fixed
   pylint-dev/pylint#73
  • Loading branch information
ltalirz committed Mar 11, 2019
1 parent 5557c2e commit 0d22513
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ ignored-classes=optparse.Values,thread._local,_thread._local
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=
# This is a pylint issue https://github.com/PyCQA/pylint/issues/73
ignored-modules=distutils

# Show a hint with possible names when a member name was not found. The aspect
# of finding the hint is based on edit distance.
Expand Down
2 changes: 1 addition & 1 deletion aiida/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_strict_version():
:returns: StrictVersion instance with the current version
"""
from distutils.version import StrictVersion # pylint: disable=import-error,no-name-in-module
from distutils.version import StrictVersion
return StrictVersion(__version__)


Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/sqlalchemy/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_group_batch_size(self):
"""
Test that the group addition in batches works as expected.
"""
from aiida.orm.group import Group
from aiida.orm.groups import Group

# Create 100 nodes
nodes = []
Expand Down
15 changes: 9 additions & 6 deletions aiida/orm/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import six
from six.moves import zip
from six.moves.html_parser import HTMLParser
from distutils.version import StrictVersion
from aiida.common import exceptions
from aiida.common.utils import export_shard_uuid, get_class_string, grouper, get_new_uuid
from aiida.orm import Computer, Group, GroupTypeString, Node, QueryBuilder, User, Log, Comment
Expand Down Expand Up @@ -621,7 +622,7 @@ def import_data_dj(in_path, user_group=None, ignore_unknown_nodes=False,
from aiida.backends.djsite.db.models import suppress_auto_now

# This is the export version expected by this function
expected_export_version = '0.4'
expected_export_version = StrictVersion('0.4')

# The name of the subfolder in which the node files are stored
nodes_export_subfolder = 'nodes'
Expand Down Expand Up @@ -673,10 +674,11 @@ def import_data_dj(in_path, user_group=None, ignore_unknown_nodes=False,
######################
# PRELIMINARY CHECKS #
######################
if metadata['export_version'] != expected_export_version:
export_version = StrictVersion(str(metadata['export_version']))
if export_version != expected_export_version:
msg = "Export file version is {}, can import only version {}"\
.format(metadata['export_version'], expected_export_version)
if metadata['export_version'] < expected_export_version:
if export_version < expected_export_version:
msg += "\nUse 'verdi export migrate' to update this export file."
else:
msg += "\nUpdate your AiiDA version in order to import this file."
Expand Down Expand Up @@ -1278,7 +1280,7 @@ def import_data_sqla(in_path, user_group=None, ignore_unknown_nodes=False,
from aiida.common import json

# This is the export version expected by this function
expected_export_version = '0.4'
expected_export_version = StrictVersion('0.4')

# The name of the subfolder in which the node files are stored
nodes_export_subfolder = 'nodes'
Expand Down Expand Up @@ -1325,10 +1327,11 @@ def import_data_sqla(in_path, user_group=None, ignore_unknown_nodes=False,
######################
# PRELIMINARY CHECKS #
######################
if metadata['export_version'] != expected_export_version:
export_version = StrictVersion(str(metadata['export_version']))
if export_version != expected_export_version:
msg = "Export file version is {}, can import only version {}"\
.format(metadata['export_version'], expected_export_version)
if metadata['export_version'] < expected_export_version:
if export_version < expected_export_version:
msg += "\nUse 'verdi export migrate' to update this export file."
else:
msg += "\nUpdate your AiiDA version in order to import this file."
Expand Down
2 changes: 1 addition & 1 deletion docs/source/nitpick-exceptions
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ py:class collections.abc.Sized
py:class WorkChainSpec
py:class aiida.orm.nodes.Node
# This comes from ABCMeta
py:meth aiida.orm.group.Group.get_from_string
py:meth aiida.orm.groups.Group.get_from_string

py:mod click
py:class click.Choice
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
# pylint: disable=wrong-import-order
# Note: This speeds up command line scripts (e.g. verdi)
from utils import fastentrypoints # pylint: disable=unused-import
# This is a pylint issue https://github.com/PyCQA/pylint/issues/73
from distutils.version import StrictVersion # pylint: disable=import-error,no-name-in-module
from distutils.version import StrictVersion
from setuptools import setup, find_packages

if __name__ == '__main__':
Expand Down

0 comments on commit 0d22513

Please sign in to comment.