Skip to content

Commit

Permalink
Dropping support for Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pacesm committed Jul 25, 2022
1 parent c220bef commit c511d1e
Show file tree
Hide file tree
Showing 20 changed files with 14 additions and 111 deletions.
6 changes: 0 additions & 6 deletions eoxmagmod/eoxmagmod/magnetic_model/field_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
# THE SOFTWARE.
#-------------------------------------------------------------------------------

try:
# Python 2 - range as an iterator
from buildins import xrange as range
except ImportError:
pass

from numpy import asarray, copy
from .._pymm import GEOCENTRIC_CARTESIAN, GEOCENTRIC_SPHERICAL, convert
from ..util import vnorm, vrotate
Expand Down
1 change: 0 additions & 1 deletion eoxmagmod/eoxmagmod/magnetic_model/loader_emm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from io import open
from .model import SphericalHarmomicGeomagneticModel
from .coefficients import (
SparseSHCoefficientsTimeDependentDecimalYear,
Expand Down
1 change: 0 additions & 1 deletion eoxmagmod/eoxmagmod/magnetic_model/loader_igrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from io import open
from .model import SphericalHarmomicGeomagneticModel
from .coefficients import SparseSHCoefficientsTimeDependentDecimalYear
from .parser_igrf import parse_igrf_file
Expand Down
1 change: 0 additions & 1 deletion eoxmagmod/eoxmagmod/magnetic_model/loader_mio.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from io import open
from numpy import arange
from .model_mio import (
DipoleMIOPrimaryGeomagneticModel, DipoleMIOGeomagneticModel,
Expand Down
1 change: 0 additions & 1 deletion eoxmagmod/eoxmagmod/magnetic_model/loader_wmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from io import open
from .model import SphericalHarmomicGeomagneticModel
from .coefficients import SparseSHCoefficientsTimeDependentDecimalYear
from .parser_wmm import parse_wmm_file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# pylint: disable=missing-docstring

from unittest import TestCase, main
from io import open
from numpy import inf, nan
from numpy.testing import assert_allclose
from eoxmagmod.time_util import decimal_year_to_mjd2000
Expand Down
1 change: 0 additions & 1 deletion eoxmagmod/eoxmagmod/magnetic_model/tests/model_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#-------------------------------------------------------------------------------
# pylint: disable=missing-docstring,no-self-use,invalid-name,too-many-public-methods

from __future__ import print_function
from unittest import TestCase, main
from itertools import product
from numpy import nan, inf, isinf, array, empty, full, nditer, asarray
Expand Down
1 change: 0 additions & 1 deletion eoxmagmod/eoxmagmod/magnetic_model/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#-------------------------------------------------------------------------------

from unittest import TestCase, main
from io import open
from hashlib import md5
from eoxmagmod.magnetic_model.util import parse_file
from eoxmagmod.magnetic_model.tests.data import SWARM_MIO_SHA_2_TEST_DATA
Expand Down
2 changes: 0 additions & 2 deletions eoxmagmod/eoxmagmod/magnetic_model/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
# THE SOFTWARE.
#-------------------------------------------------------------------------------

from io import open


def parse_file(parser, file_, *args, **kwargs):
if isinstance(file_, str):
Expand Down
24 changes: 1 addition & 23 deletions eoxmagmod/eoxmagmod/py_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,14 @@

/* checking the Python version */

#if PY_MAJOR_VERSION == 2
#define IS_PYTHON_2
#if PY_MINOR_VERSION < 6
#error "Non-supported Python minor version!"
#endif
#elif PY_MAJOR_VERSION == 3
#define IS_PYTHON_3
#if PY_MAJOR_VERSION == 3
#if PY_MINOR_VERSION < 4
#error "Non-supported Python minor version!"
#endif
#else
#error "Non-supported Python major version!"
#endif

/* Python 2/3 compatibility */

#ifdef IS_PYTHON_3
#define PyString_FromString PyUnicode_FromString
#endif

/* Python dictionary operations */

static void set_dict_item_str(PyObject *dict, const char * key, PyObject *value)
Expand All @@ -74,20 +62,14 @@ static void set_dict_item_str_double(PyObject *dict, const char * key, double va

static void set_dict_item_str_str(PyObject *dict, const char * key, const char *value)
{
#ifdef IS_PYTHON_2
set_dict_item_str(dict, key, PyString_FromString(value));
#else
set_dict_item_str(dict, key, PyUnicode_FromString(value));
#endif
}

/* Python module initialization */

#ifdef IS_PYTHON_3
static struct PyModuleDef module_definition = {
PyModuleDef_HEAD_INIT, NULL, NULL, -1, NULL, NULL, NULL, NULL, NULL
};
#endif

PyObject* init_python_module(
const char *name,
Expand All @@ -96,14 +78,10 @@ PyObject* init_python_module(
)
{
PyObject *module = NULL;
#ifdef IS_PYTHON_3
module_definition.m_name = name;
module_definition.m_doc = doc;
module_definition.m_methods = methods;
module = PyModule_Create(&module_definition);
#else /* IS_PYTHON2 */
module = Py_InitModule3(name, methods, doc);
#endif
return module;
}

Expand Down
16 changes: 3 additions & 13 deletions eoxmagmod/eoxmagmod/pymm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Author: Martin Paces <[email protected]>
*
*-----------------------------------------------------------------------------
* Copyright (C) 2014 EOX IT Services GmbH
* Copyright (C) 2014-2022 EOX IT Services GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -113,28 +113,18 @@ static PyObject* init_module(void)

/* module metadata */
set_dict_item_str_str(dict, "__author__", "Martin Paces ([email protected])");
set_dict_item_str_str(dict, "__copyright__", "Copyright (C) 2014 EOX IT Services GmbH");
set_dict_item_str_str(dict, "__copyright__", "Copyright (C) 2014-2022 EOX IT Services GmbH");
set_dict_item_str_str(dict, "__licence__", "EOX licence (MIT style)");
set_dict_item_str_str(dict, "__version__", VERSION);

exit:
return module;
}

#if PY_MAJOR_VERSION == 2

PyMODINIT_FUNC init_pymm(void)
{
import_array();
init_module();
}

#else
/*---------------------------------------------------------------------------*/

PyObject* PyInit__pymm(void)
{
import_array();
return init_module();
}

#endif
16 changes: 2 additions & 14 deletions eoxmagmod/eoxmagmod/pyqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Author: Martin Paces <[email protected]>
*
*-----------------------------------------------------------------------------
* Copyright (C) 2015 EOX IT Services GmbH
* Copyright (C) 2015-2022 EOX IT Services GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -80,7 +80,7 @@ static PyObject* init_module(void)

/* metadata */
set_dict_item_str_str(dict, "__author__", "Martin Paces ([email protected])");
set_dict_item_str_str(dict, "__copyright__", "Copyright (C) 2015 EOX IT Services GmbH");
set_dict_item_str_str(dict, "__copyright__", "Copyright (C) 2015-2022 EOX IT Services GmbH");
set_dict_item_str_str(dict, "__licence__", "EOX licence (MIT style)");
set_dict_item_str_str(dict, "__version__", VERSION);

Expand All @@ -90,20 +90,8 @@ static PyObject* init_module(void)

/*---------------------------------------------------------------------------*/

#if PY_MAJOR_VERSION == 2

PyMODINIT_FUNC init_pyqd(void)
{
import_array();
init_module();
}

#else

PyObject* PyInit__pyqd(void)
{
import_array();
return init_module();
}

#endif
16 changes: 3 additions & 13 deletions eoxmagmod/eoxmagmod/pysunpos.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Author: Martin Paces <[email protected]>
*
*-----------------------------------------------------------------------------
* Copyright (C) 2017 EOX IT Services GmbH
* Copyright (C) 2017-2022 EOX IT Services GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -70,28 +70,18 @@ static PyObject* init_module(void)

/* module metadata */
set_dict_item_str_str(dict, "__author__", "Martin Paces ([email protected])");
set_dict_item_str_str(dict, "__copyright__", "Copyright (C) 2017 EOX IT Services GmbH");
set_dict_item_str_str(dict, "__copyright__", "Copyright (C) 2017-2022 EOX IT Services GmbH");
set_dict_item_str_str(dict, "__licence__", "EOX licence (MIT style)");
set_dict_item_str_str(dict, "__version__", VERSION);

exit:
return module;
}

#if PY_MAJOR_VERSION == 2

PyMODINIT_FUNC init_pysunpos(void)
{
import_array();
init_module();
}

#else
/*---------------------------------------------------------------------------*/

PyObject* PyInit__pysunpos(void)
{
import_array();
return init_module();
}

#endif
16 changes: 3 additions & 13 deletions eoxmagmod/eoxmagmod/pytimeconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Author: Martin Paces <[email protected]>
*
*-----------------------------------------------------------------------------
* Copyright (C) 2018 EOX IT Services GmbH
* Copyright (C) 2018-2022 EOX IT Services GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -73,28 +73,18 @@ static PyObject* init_module(void)

/* metadata */
set_dict_item_str_str(dict, "__author__", "Martin Paces ([email protected])");
set_dict_item_str_str(dict, "__copyright__", "Copyright (C) 2018 EOX IT Services GmbH");
set_dict_item_str_str(dict, "__copyright__", "Copyright (C) 2018-2022 EOX IT Services GmbH");
set_dict_item_str_str(dict, "__licence__", "EOX licence (MIT style)");
set_dict_item_str_str(dict, "__version__", VERSION);

exit:
return module;
}

#if PY_MAJOR_VERSION == 2

PyMODINIT_FUNC init_pytimeconv(void)
{
import_array();
init_module();
}

#else
/*---------------------------------------------------------------------------*/

PyObject* PyInit__pytimeconv(void)
{
import_array();
return init_module();
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
#pylint: disable=missing-docstring

import sys
try:
# Python 2
from itertools import izip as zip
except ImportError:
pass
from itertools import product
from numpy import array, vectorize
from numpy.random import uniform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
#pylint: disable=missing-docstring

import sys
try:
# Python 2
from itertools import izip as zip
except ImportError:
pass
from itertools import product
from numpy import array
from numpy.random import uniform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
#pylint: disable=missing-docstring

import sys
try:
# Python 2
from itertools import izip as zip
except ImportError:
pass
from numpy import array
from eoxmagmod import mjd2000_to_decimal_year
from eoxmagmod.quasi_dipole_coordinates import (
Expand Down
1 change: 0 additions & 1 deletion eoxmagmod/eoxmagmod/tests/quasi_dipole_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#pylint: disable=missing-docstring

from unittest import TestCase, main
from io import open
from numpy import array
from numpy.testing import assert_allclose
from eoxmagmod.quasi_dipole_coordinates import (
Expand Down
1 change: 0 additions & 1 deletion eoxmagmod/eoxmagmod/tests/solar_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#pylint: disable=missing-docstring

from unittest import TestCase, main
from io import open
from numpy import array
from numpy.testing import assert_allclose
from eoxmagmod.quasi_dipole_coordinates import eval_subsol
Expand Down
5 changes: 2 additions & 3 deletions eoxmagmod/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@
'Operating System :: POSIX',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Scientific/Engineering :: Physics',
'Topic :: Utilities',
Expand Down

0 comments on commit c511d1e

Please sign in to comment.