Skip to content

Commit

Permalink
Merge pull request #94 from greschd/remove_py2_support
Browse files Browse the repository at this point in the history
Remove python2 support
  • Loading branch information
giovannipizzi authored Mar 8, 2020
2 parents 54a432f + 058c960 commit dcda325
Show file tree
Hide file tree
Showing 25 changed files with 80 additions and 178 deletions.
10 changes: 0 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# Install pre-commit hooks via
# pre-commit install

# modernizer: make sure our code-base is Python 3 ready
- repo: https://github.com/python-modernize/python-modernize.git
rev: "0.7"
hooks:
- id: python-modernize
exclude: ^docs/
args:
- --write
- --nobackups

- repo: local
hooks:
- id: yapf
Expand Down
2 changes: 0 additions & 2 deletions .travis-data/check_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
Check version number in setup.json and aiida_wannier90/__init__.py and make sure
they match.
"""
from __future__ import absolute_import
from __future__ import print_function
import os
import json
import sys
Expand Down
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
language: python
python:
- "2.7"
- "3.6"
- "3.7"
- "3.8"
env:
- INSTALL_TYPE="testing" TEST_TYPE="tests"
- INSTALL_TYPE="testing_sdist" TEST_TYPE="tests"
jobs:
include:
- python: "2.7"
env: INSTALL_TYPE="dev_precommit" TEST_TYPE="pre-commit"
- python: "3.7"
env: INSTALL_TYPE="dev_precommit" TEST_TYPE="pre-commit"
- python: "2.7"
env: INSTALL_TYPE="docs" TEST_TYPE="docs"
- python: "3.7"
env: INSTALL_TYPE="docs" TEST_TYPE="docs"
cache: pip
Expand Down
2 changes: 0 additions & 2 deletions aiida_wannier90/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
`[arXiv link] <https://arxiv.org/abs/1504.01163>`_
"""

from __future__ import absolute_import

__authors__ = "Dominik Gresch, Antimo Marrazzo, Daniel Marchand, Giovanni Pizzi, Junfeng Qiao, Norma Rivano, and the AiiDA team."
__license__ = "MIT License, see LICENSE.txt file."
## If upgraded, remember to change it also in setup.json (for pip)
Expand Down
8 changes: 3 additions & 5 deletions aiida_wannier90/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-wannier90 #
# For further information on the license, see the LICENSE.txt file #
################################################################################
from __future__ import absolute_import, print_function, division
import os
import six
import fnmatch
from collections import namedtuple

Expand Down Expand Up @@ -145,17 +143,17 @@ def define(cls, spec): # pylint: disable=no-self-argument

spec.input(
'metadata.options.input_filename',
valid_type=six.string_types,
valid_type=str,
default=cls._DEFAULT_INPUT_FILE
)
spec.input(
'metadata.options.output_filename',
valid_type=six.string_types,
valid_type=str,
default=cls._DEFAULT_OUTPUT_FILE
)
spec.input(
'metadata.options.parser_name',
valid_type=six.string_types,
valid_type=str,
default='wannier90.wannier90'
)
# withmpi defaults to "False" in aiida-core 1.0. Below, we override to default to withmpi=True
Expand Down
1 change: 0 additions & 1 deletion aiida_wannier90/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
# Copyright (c), AiiDA team and individual contributors. #
Expand Down
4 changes: 0 additions & 4 deletions aiida_wannier90/io/_group_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
# Copyright (c), AiiDA team and individual contributors. #
Expand All @@ -9,9 +8,6 @@
# For further information on the license, see the LICENSE.txt file #
################################################################################

from __future__ import absolute_import
from six.moves import zip

__all__ = ('group_list', 'groups_to_string', 'list_to_grouped_string')


Expand Down
7 changes: 1 addition & 6 deletions aiida_wannier90/io/_write_win.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
# Copyright (c), AiiDA team and individual contributors. #
Expand All @@ -9,16 +8,12 @@
# For further information on the license, see the LICENSE.txt file #
################################################################################

from __future__ import unicode_literals

from __future__ import absolute_import
import copy

from aiida_wannier90.utils import conv_to_fortran_withlists
from aiida.common import InputValidationError

from ._group_list import list_to_grouped_string
import six

__all__ = ('write_win', )

Expand Down Expand Up @@ -292,7 +287,7 @@ def list2str(list_item):
Converts an input list item into a str
'''
list_item = copy.deepcopy(list_item)
if isinstance(list_item, (str, six.text_type)):
if isinstance(list_item, str):
return list_item
return ' ' + ' '.join(["{:18.10f}".format(_) for _ in list_item]) + ' '

Expand Down
12 changes: 4 additions & 8 deletions aiida_wannier90/orbitals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
# Copyright (c), AiiDA team and individual contributors. #
Expand All @@ -12,9 +11,6 @@
Creating OrbitalData instances
==============================
"""
from __future__ import absolute_import
import six
from six.moves import range

__all__ = ('generate_projections', )

Expand Down Expand Up @@ -47,7 +43,7 @@ def _generate_wannier_orbitals( # pylint: disable=too-many-arguments,too-many-lo
:param ang_mtm_name: orbital name or list of orbital names, cannot
be used in conjunction with ang_mtm_l_list or
ang_mtm_mr_list
:param ang_mtm_l_list: angular momentum (either an integer or a list), if
:param ang_mtm_l_list: angular momentum (either an integer or a list), if
ang_mtm_mr_list is not specified will return all orbitals associated with it
:param ang_mtm_mr_list: magnetic angular momentum number must be specified
along with ang_mtm_l_list. Note that if this is specified,
Expand Down Expand Up @@ -120,7 +116,7 @@ def combine_dictlists(dict_list1, dict_list2):
'Must supply a StructureData as '
'structure if using kind_name'
)
if not isinstance(kind_name, six.string_types):
if not isinstance(kind_name, str):
raise InputValidationError('kind_name must be a string')

if ang_mtm_name is None and ang_mtm_l_list is None:
Expand Down Expand Up @@ -276,14 +272,14 @@ def generate_projections(list_of_projection_dicts, structure):
:param ang_mtm_name: orbital name or list of orbital names, cannot
be used in conjunction with ``ang_mtm_l_list`` or ``ang_mtm_mr_list``
(see ``ang_mtm_l_list`` and ``ang_mtm_mr_list``).
:param ang_mtm_l_list: angular momentum (either an integer or a list), if
:param ang_mtm_l_list: angular momentum (either an integer or a list), if
``ang_mtm_mr_list`` is not specified will return all orbitals
associated with it (``angular_momentum``).
:param ang_mtm_mr_list: magnetic angular momentum number must be specified
along with ``ang_mtm_l_list`` (``magnetic_number + 1``). Note that
if this is specified, ``ang_mtm_l_list`` must be an
integer and not a list.
:param spin: the spin, spin up can be specified with ``1``, ``'u'`` or
:param spin: the spin, spin up can be specified with ``1``, ``'u'`` or
``'U'`` and spin down can be specified using ``-1``, ``'d'``
or ``'D'`` (``spin``)
:param zona: as specified in user guide, applied to all orbitals
Expand Down
8 changes: 2 additions & 6 deletions aiida_wannier90/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-wannier90 #
# For further information on the license, see the LICENSE.txt file #
################################################################################
from __future__ import absolute_import
import io
import os
import six
from six.moves import range
from aiida.parsers import Parser
from aiida.common import exceptions as exc

Expand Down Expand Up @@ -104,7 +100,7 @@ def parse(self, **kwargs): # pylint: disable=too-many-locals,inconsistent-retur
if temporary_folder is not None:
nnkp_temp_path = os.path.join(temporary_folder, nnkp_file_name)
if os.path.isfile(nnkp_temp_path):
with io.open(nnkp_temp_path, 'rb') as handle:
with open(nnkp_temp_path, 'rb') as handle:
node = SinglefileData(file=handle)
self.out('nnkp_file', node)

Expand Down Expand Up @@ -459,7 +455,7 @@ def band_parser_legacy(band_dat, band_kpt, special_points, structure): # pylint
appends.sort()

for i, append in enumerate(appends):
labels.insert(append[0] + i, (append[2], six.text_type(append[1])))
labels.insert(append[0] + i, (append[2], str(append[1])))
bands = BandsData()
k = KpointsData()
k.set_cell_from_structure(structure)
Expand Down
9 changes: 3 additions & 6 deletions aiida_wannier90/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-wannier90 #
# For further information on the license, see the LICENSE.txt file #
################################################################################
from __future__ import absolute_import
import numbers

import six

__all__ = ('plot_centres_xsf', 'conv_to_fortran', 'conv_to_fortran_withlists')


Expand Down Expand Up @@ -48,7 +45,7 @@ def conv_to_fortran(val, quote_strings=True):
val_str = "{:d}".format(val)
elif isinstance(val, numbers.Real):
val_str = ("{:18.10e}".format(val)).replace('e', 'd')
elif isinstance(val, six.string_types):
elif isinstance(val, str):
if quote_strings:
val_str = "'{!s}'".format(val)
else:
Expand Down Expand Up @@ -84,13 +81,13 @@ def conv_to_fortran_withlists(val, quote_strings=True):

return '.false.'

if isinstance(val, six.integer_types):
if isinstance(val, int):
return "{:d}".format(val)

if isinstance(val, float):
return "{:18.10e}".format(val).replace('e', 'd')

if isinstance(val, six.string_types):
if isinstance(val, str):
if quote_strings:
return "'{!s}'".format(val)

Expand Down
1 change: 0 additions & 1 deletion aiida_wannier90/workflows/minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-wannier90 #
# For further information on the license, see the LICENSE.txt file #
################################################################################
from __future__ import absolute_import, print_function, division
from aiida import orm
from aiida.plugins import CalculationFactory
from aiida.engine import WorkChain, ToContext, calcfunction
Expand Down
52 changes: 8 additions & 44 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,62 +20,26 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import contextlib

import os
import sys
import time
import contextlib

import aiida_wannier90

# -- General configuration ------------------------------------------------
# Note: this requires AiiDA v1.1+
from aiida.manage.configuration import load_documentation_profile
load_documentation_profile()

on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
# -- General configuration ------------------------------------------------

if not on_rtd:
# Set the RTD theme only when _not_ on readthedocs. On readthedocs,
# the READTHEDOCS environment variable is set to 'True'.
if not os.environ.get('READTHEDOCS', None) == 'True':
with contextlib.suppress(ImportError):
import sphinx_rtd_theme # pylint: disable=import-error
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

try:
# For AiiDA v1.1+
from aiida.manage.configuration import load_documentation_profile
load_documentation_profile()
except ImportError:
# AiiDA versions <1.1
# This can be removed when python2 support is dropped, because there
# will be no need to build the documentation with AiiDA v1.0.
sys.path.append(
os.path.join(os.path.split(__file__)[0], os.pardir, os.pardir)
)
sys.path.append(os.path.join(os.path.split(__file__)[0], os.pardir))
os.environ['DJANGO_SETTINGS_MODULE'] = 'rtd_settings'

if not on_rtd: # only import and set the theme if we're building docs locally
# Load the database environment by first loading the profile and then loading the backend through the manager
from aiida.manage.configuration import get_config, load_profile
from aiida.manage.manager import get_manager
config = get_config()
load_profile(config.default_profile_name)
get_manager().get_backend()
else:
from aiida.manage import configuration
from aiida.manage.configuration import load_profile, reset_config
from aiida.manage.manager import get_manager

# Set the global variable to trigger shortcut behavior in `aiida.manager.configuration.load_config`
configuration.IN_RT_DOC_MODE = True

# First need to reset the config, because an empty one will have been loaded when `aiida` module got imported
reset_config()

# Load the profile: this will first load the config, which will be the dummy one for RTD purposes
load_profile()

# Finally load the database backend but without checking the schema because there is no actual database
get_manager()._load_backend(schema_check=False) # pylint: disable=protected-access

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'

Expand Down
3 changes: 0 additions & 3 deletions examples/example01/create_local_input_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-wannier90 #
# For further information on the license, see the LICENSE.txt file #
################################################################################
from __future__ import absolute_import
from __future__ import print_function

import os
from six.moves import input

from aiida.plugins import DataFactory

Expand Down
2 changes: 0 additions & 2 deletions examples/example01/wannier_gaas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-wannier90 #
# For further information on the license, see the LICENSE.txt file #
################################################################################
from __future__ import absolute_import
from __future__ import print_function
import sys

from aiida.plugins import DataFactory
Expand Down
7 changes: 3 additions & 4 deletions examples/workflows/launch_w90_minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-wannier90 #
# For further information on the license, see the LICENSE.txt file #
################################################################################
from __future__ import absolute_import
from __future__ import print_function

import click
import os

import click

from aiida.engine import run
from aiida.orm import Str, Dict, Group
from aiida.orm.nodes.data import upf
Expand Down Expand Up @@ -95,7 +94,7 @@ def get_static_inputs():

def get_or_create_pseudo_family():
"""Check if the pseudos are already in the DB, create them otherwise.
Then create (if needed) also a pseudopotential family including it (or pick any already existing)
and return the name.
If the family does not exist, it will be created with name 'GaAs-Wannier-example' and a possible prefix.
Expand Down
6 changes: 6 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[pytest]
filterwarnings =
ignore::DeprecationWarning:frozendict:
ignore::DeprecationWarning:pkg_resources:
ignore::DeprecationWarning:reentry:
ignore::DeprecationWarning:sqlalchemy_utils:
Loading

0 comments on commit dcda325

Please sign in to comment.