Skip to content

Commit

Permalink
Remove the use of deprecated distutils package (#808)
Browse files Browse the repository at this point in the history
With the acceptance of PEP 632, this module was deprecated in Python 3.10
and it will be removed in Python 3.12. The `LooseVersion` and
`StrictVersion` classes are replaced by `packaging.version.Version` as
recommended by the PEP itself, see:

    https://peps.python.org/pep-0632/#migration-advice
  • Loading branch information
sphuber authored May 5, 2022
1 parent 22b27d2 commit 18dd972
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions aiida_quantumespresso/parsers/cp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
from distutils.version import LooseVersion

from aiida.orm import Dict, TrajectoryData
import numpy
from packaging.version import Version
from qe_tools import CONSTANTS

from .base import Parser
Expand Down Expand Up @@ -81,7 +80,7 @@ def parse(self, **kwargs):
]

# order of atom in the output trajectory changed somewhere after 6.5
if LooseVersion(out_dict['creator_version']) > LooseVersion('6.5'):
if Version(out_dict['creator_version']) > Version('6.5'):
new_cp_ordering = True
else:
new_cp_ordering = False
Expand Down Expand Up @@ -145,7 +144,7 @@ def parse(self, **kwargs):
except IndexError:
matrix = numpy.array(numpy.matrix(matrix))

if LooseVersion(out_dict['creator_version']) > LooseVersion('5.1'):
if Version(out_dict['creator_version']) > Version('5.1'):
# Between version 5.1 and 5.1.1, someone decided to change
# the .evp output format, without any way to know that this
# happened... SVN commit 11158.
Expand Down
6 changes: 3 additions & 3 deletions aiida_quantumespresso/parsers/parse_xml/parse.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from distutils.version import StrictVersion
from urllib.error import URLError

import numpy as np
from packaging.version import Version
from qe_tools import CONSTANTS
from xmlschema import XMLSchema

Expand Down Expand Up @@ -95,7 +95,7 @@ def parse_xml_post_6_2(xml):
for err in errors:
logs.error.append(str(err))

xml_version = StrictVersion(xml_dictionary['general_info']['xml_format']['@VERSION'])
xml_version = Version(xml_dictionary['general_info']['xml_format']['@VERSION'])
inputs = xml_dictionary.get('input', {})
outputs = xml_dictionary['output']

Expand Down Expand Up @@ -285,7 +285,7 @@ def parse_xml_post_6_2(xml):
degauss = smearing_xml['@degauss']

# Versions below 19.03.04 (Quantum ESPRESSO<=6.4.1) incorrectly print degauss in Ry instead of Hartree
if xml_version < StrictVersion('19.03.04'):
if xml_version < Version('19.03.04'):
degauss *= CONSTANTS.ry_to_ev
else:
degauss *= CONSTANTS.hartree_to_ev
Expand Down

0 comments on commit 18dd972

Please sign in to comment.