From 61d32ede267276e4167c53f2d31412d41d496858 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 21 Nov 2019 18:02:55 +0100 Subject: [PATCH 1/8] [Issue272] Replaced occurences of Cython by cython --- doc/source/installation.rst | 2 +- .../release_notes/release_notes_141.rst | 4 ++-- setup.py | 6 +++--- tofu/geom/_GG.pyx | 20 +++++++++---------- tofu/geom/_distance_tools.pyx | 14 ++++++------- tofu/version.py | 2 +- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/doc/source/installation.rst b/doc/source/installation.rst index a529ef79c..a81cfd51c 100644 --- a/doc/source/installation.rst +++ b/doc/source/installation.rst @@ -143,6 +143,6 @@ To install tofu as a developer, we recommend using the conda ecosystem (Minicond (long) `__ or `this short one `__ - Run ``pip install -e .[dev]``. This will install dependencies, compile the - tofu Cython extensions and install it into your conda environment while you can still + tofu cython extensions and install it into your conda environment while you can still modify the source files in the current repository.` - Make sure tofu tests are running by typing ``nosetests`` diff --git a/doc/source/release_notes/release_notes_141.rst b/doc/source/release_notes/release_notes_141.rst index 3ad9c8380..bebf56516 100644 --- a/doc/source/release_notes/release_notes_141.rst +++ b/doc/source/release_notes/release_notes_141.rst @@ -225,7 +225,7 @@ Code structure and format Restructuring of the geometry modules ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Created Cython include files ``*.pxd`` and ``*.pyx`` for the following +Created cython include files ``*.pxd`` and ``*.pyx`` for the following group of functions: - ``_basic_geom_tools.*``: global variables definition (``_VSMALL`` and ``_SMALL``), and basic geometric tools (vector calculus, path distance point-point, point-vector,...) - @@ -244,7 +244,7 @@ Installation and portability impossible - git dependency is now optional (issue #67 ) - changes in ``setup.py`` for **Windows** portability -- Now only supporting ``Cython`` versions ``>=0.26`` +- Now only supporting ``cython`` versions ``>=0.26`` - Removed all **pandas** dependencies - Using ``-O3`` flag instead of ``-O0`` for faster execution time even if compilation is slower diff --git a/setup.py b/setup.py index b47fc41c1..b71e00433 100644 --- a/setup.py +++ b/setup.py @@ -11,9 +11,9 @@ import platform import subprocess from codecs import open -import Cython as cth -from Cython.Distutils import build_ext -from Cython.Build import cythonize +import cython as cth +from cython.Distutils import build_ext +from cython.Build import cythonize import numpy as np import _updateversion as up diff --git a/tofu/geom/_GG.pyx b/tofu/geom/_GG.pyx index 4ffa3a155..7143e078f 100644 --- a/tofu/geom/_GG.pyx +++ b/tofu/geom/_GG.pyx @@ -10,7 +10,7 @@ import numpy as np import scipy.integrate as scpintg from matplotlib.path import Path -# -- Cython libraries imports -------------------------------------------------- +# -- cython libraries imports -------------------------------------------------- from cpython cimport bool from cpython.array cimport array, clone from cython.parallel import prange @@ -3679,7 +3679,7 @@ def comp_dist_los_circle(np.ndarray[double,ndim=1,mode='c'] ray_vdir, to the circle --- This is the PYTHON function, use only if you need this computation from - Python, if you need it from Cython, use `dist_los_circle_core` + Python, if you need it from cython, use `dist_los_circle_core` """ cdef double[2] res _dt.dist_los_circle_core(ray_vdir.data, @@ -3714,7 +3714,7 @@ def comp_dist_los_circle_vec(int nlos, int ncircles, with the distance between each LOS to each circle --- This is the PYTHON function, use only if you need this computation from - Python, if you need it from Cython, use `dist_los_circle_core` + Python, if you need it from cython, use `dist_los_circle_core` """ cdef array kmin_tab = clone(array('d'), nlos*ncircles, True) cdef array dist_tab = clone(array('d'), nlos*ncircles, True) @@ -3748,7 +3748,7 @@ def is_close_los_circle(np.ndarray[double,ndim=1,mode='c'] ray_vdir, The result is True when distance < epsilon --- This is the PYTHON function, use only if you need this computation from - Python, if you need it from Cython, use `is_los_close_circle_core` + Python, if you need it from cython, use `is_los_close_circle_core` """ return _dt.is_close_los_circle_core(ray_vdir.data, ray_orig.data, @@ -3767,7 +3767,7 @@ def is_close_los_circle_vec(int nlos, int ncircles, double epsilon, The result is True when distance < epsilon --- This is the PYTHON function, use only if you need this computation from - Python, if you need it from Cython, use `is_los_close_circle_core` + Python, if you need it from cython, use `is_los_close_circle_core` """ cdef array res = clone(array('i'), nlos, True) @@ -3824,7 +3824,7 @@ def comp_dist_los_vpoly(double[:, ::1] ray_orig, `distance[i]` is the distance from P_i to the extruded polygon. --- This is the PYTHON function, use only if you need this computation from - Python, if you need it from Cython, use `simple_dist_los_vpoly_core` + Python, if you need it from cython, use `simple_dist_los_vpoly_core` """ cdef int npts_poly = ves_poly.shape[1] cdef int nlos = ray_orig.shape[1] @@ -3929,7 +3929,7 @@ def comp_dist_los_vpoly_vec(int nvpoly, int nlos, extruded poly. --- This is the PYTHON function, use only if you need this computation from - Python, if you need it from Cython, use `comp_dist_los_vpoly_vec_core` + Python, if you need it from cython, use `comp_dist_los_vpoly_vec_core` """ if not algo_type.lower() == "simple" or not ves_type.lower() == "tor": assert False, "The function is only implemented with the simple"\ @@ -4003,7 +4003,7 @@ def is_close_los_vpoly_vec(int nvpoly, int nlos, and j-th poly are closer than epsilon. (True if distance Date: Thu, 21 Nov 2019 22:11:41 +0100 Subject: [PATCH 2/8] Update version.py --- tofu/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tofu/version.py b/tofu/version.py index 9dcf42560..525838a45 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit, pipeline versioning governed by git tags! -__version__ = '1.4.2-alpha2' \ No newline at end of file +__version__ = '1.4.2-alpha2' From 0b33a97d3a05e9a4b48cb0f58522f72a1b0c53ef Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Thu, 21 Nov 2019 22:34:56 +0100 Subject: [PATCH 3/8] [Issue272] Replaced cython by Cython in import and dependencies (setup, requirements, conda_recipe/meta.yaml) --- conda_recipe/meta.yaml | 4 ++-- requirements.txt | 2 +- setup.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/conda_recipe/meta.yaml b/conda_recipe/meta.yaml index 77064c52a..caf994d59 100644 --- a/conda_recipe/meta.yaml +++ b/conda_recipe/meta.yaml @@ -26,7 +26,7 @@ requirements: - numpy - scipy - matplotlib - - cython >=0.26 + - Cython >=0.26 - nose - pygments @@ -39,7 +39,7 @@ requirements: - numpy - scipy - matplotlib - - cython >=0.26 + - Cython >=0.26 - nose - pygments diff --git a/requirements.txt b/requirements.txt index 08858cb0c..0632b2965 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ scipy matplotlib ######## Requirements with Version Specifier ######## -cython>=0.26 +Cython>=0.26 diff --git a/setup.py b/setup.py index b71e00433..15911e082 100644 --- a/setup.py +++ b/setup.py @@ -11,9 +11,9 @@ import platform import subprocess from codecs import open -import cython as cth -from cython.Distutils import build_ext -from cython.Build import cythonize +import Cython as cth +from Cython.Distutils import build_ext +from Cython.Build import cythonize import numpy as np import _updateversion as up @@ -339,7 +339,7 @@ def get_version_tofu(path=_HERE): # your project is installed. For an analysis of "install_requires" vs pip's # requirements files see: # https://packaging.python.org/en/latest/requirements.html - install_requires=["numpy", "scipy", "matplotlib", "cython>=0.26"], + install_requires=["numpy", "scipy", "matplotlib", "Cython>=0.26"], python_requires=">=3.6", # List additional groups of dependencies here (e.g. development # dependencies). You can install these using the following syntax, From bc89483d124f81c1c34d2099e212b7ec71209fee Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 22 Nov 2019 08:59:06 +0100 Subject: [PATCH 4/8] [Issue272] Added setup_requires=['numpy', 'Cython>=0.26'] in setup.py --- setup.py | 2 +- tofu/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 15911e082..4344acb4c 100644 --- a/setup.py +++ b/setup.py @@ -282,7 +282,7 @@ def get_version_tofu(path=_HERE): # The version is stored only in the setup.py file and read from it (option # 1 in https://packaging.python.org/en/latest/single_source_version.html) use_scm_version=False, - # setup_requires=['setuptools_scm'], + setup_requires=['numpy', 'Cython>=0.26'], description="A python library for Tomography for Fusion", long_description=long_description, long_description_content_type=long_description_content_type, diff --git a/tofu/version.py b/tofu/version.py index 525838a45..7cd47559c 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit, pipeline versioning governed by git tags! -__version__ = '1.4.2-alpha2' +__version__ = '1.4.2-alpha2-9-g0b33a97' From 5c99793ee1c40e0d909f81763179b0208398ba6e Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 22 Nov 2019 09:19:08 +0100 Subject: [PATCH 5/8] [Issue272] Workaround cython and numpy setup dependency using try / except at import time --- setup.py | 32 +++++++++++++++++++------------- tofu/version.py | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index 4344acb4c..788faee0f 100644 --- a/setup.py +++ b/setup.py @@ -11,19 +11,22 @@ import platform import subprocess from codecs import open -import Cython as cth -from Cython.Distutils import build_ext -from Cython.Build import cythonize -import numpy as np +try: + import numpy as np + import Cython as cth + from Cython.Distutils import build_ext + from Cython.Build import cythonize + + print("cython version =", cth.__version__) + print("numpy version =", np.__version__) + print("cython file =", cth.__file__) + print("numpy file =", np.__file__) +except ImportError: + def cythonize(*args, **kwargs): + from Cython.Build import cythonize + return cythonize(*args, **kwargs) import _updateversion as up -from distutils.command.clean import clean as Clean - - -print("cython version =", cth.__version__) -print("numpy version =", np.__version__) -print("cython version =", cth.__file__) -print("numpy version =", np.__file__) logging.basicConfig(level=logging.INFO) logger = logging.getLogger("tofu.setup") @@ -36,6 +39,9 @@ from distutils.core import setup from distutils.extension import Extension +# Is there a clean command from setuptools instead of distutils ? +from distutils.command.clean import clean as Clean + is_platform_windows = False if platform.system() == "Windows": is_platform_windows = True @@ -282,7 +288,7 @@ def get_version_tofu(path=_HERE): # The version is stored only in the setup.py file and read from it (option # 1 in https://packaging.python.org/en/latest/single_source_version.html) use_scm_version=False, - setup_requires=['numpy', 'Cython>=0.26'], + setup_requires=['numpy', 'cython>=0.26'], description="A python library for Tomography for Fusion", long_description=long_description, long_description_content_type=long_description_content_type, @@ -339,7 +345,7 @@ def get_version_tofu(path=_HERE): # your project is installed. For an analysis of "install_requires" vs pip's # requirements files see: # https://packaging.python.org/en/latest/requirements.html - install_requires=["numpy", "scipy", "matplotlib", "Cython>=0.26"], + install_requires=["numpy", "scipy", "matplotlib", "cython>=0.26"], python_requires=">=3.6", # List additional groups of dependencies here (e.g. development # dependencies). You can install these using the following syntax, diff --git a/tofu/version.py b/tofu/version.py index 7cd47559c..3d17bddd7 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit, pipeline versioning governed by git tags! -__version__ = '1.4.2-alpha2-9-g0b33a97' +__version__ = '1.4.2-alpha2-10-gbc89483' From e1cc209dab9d9c4fb019f9bb6b30e8b2afabe940 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 22 Nov 2019 09:23:19 +0100 Subject: [PATCH 6/8] [Issue272] Workaround cython and numpy setup dependency using try / except at import time also for build_ext --- setup.py | 7 ++++++- tofu/version.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 788faee0f..783de7ebd 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,8 @@ import Cython as cth from Cython.Distutils import build_ext from Cython.Build import cythonize + from Cython.Build import build_ext as cthBext + # Why do we need two different build_ext command ? print("cython version =", cth.__version__) print("numpy version =", np.__version__) @@ -25,6 +27,9 @@ def cythonize(*args, **kwargs): from Cython.Build import cythonize return cythonize(*args, **kwargs) + def cthBext(*args, **kwargs): + from Cython.Build import build_ext as cthBext + return cthBext(*args, **kwdargs) import _updateversion as up @@ -390,7 +395,7 @@ def get_version_tofu(path=_HERE): # ], # }, ext_modules=extensions, - cmdclass={"build_ext": cth.Build.build_ext, + cmdclass={"build_ext": cthBext, "clean": CleanCommand}, include_dirs=[np.get_include()], ) diff --git a/tofu/version.py b/tofu/version.py index 3d17bddd7..4acbd9824 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit, pipeline versioning governed by git tags! -__version__ = '1.4.2-alpha2-10-gbc89483' +__version__ = '1.4.2-alpha2-11-g5c99793' From 7db6643ff232b324bdfd2f50924f8c2a877f9a1e Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 22 Nov 2019 09:28:50 +0100 Subject: [PATCH 7/8] [Issue272] Workaround cython and numpy setup dependency using try / except at import time also for np.get_include() --- setup.py | 6 +++++- tofu/version.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 783de7ebd..3a95af8a4 100644 --- a/setup.py +++ b/setup.py @@ -19,11 +19,15 @@ from Cython.Build import build_ext as cthBext # Why do we need two different build_ext command ? + def npgetinclude(): return np.get_include() print("cython version =", cth.__version__) print("numpy version =", np.__version__) print("cython file =", cth.__file__) print("numpy file =", np.__file__) except ImportError: + def npgetinclude(): + import numpy as np + return np.get_include() def cythonize(*args, **kwargs): from Cython.Build import cythonize return cythonize(*args, **kwargs) @@ -397,5 +401,5 @@ def get_version_tofu(path=_HERE): ext_modules=extensions, cmdclass={"build_ext": cthBext, "clean": CleanCommand}, - include_dirs=[np.get_include()], + include_dirs=[npgetinclude()], ) diff --git a/tofu/version.py b/tofu/version.py index 4acbd9824..808143312 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit, pipeline versioning governed by git tags! -__version__ = '1.4.2-alpha2-11-g5c99793' +__version__ = '1.4.2-alpha2-12-ge1cc209' From 064e1b4bde3a604f6f0a28db39f7d6936a1c3dd1 Mon Sep 17 00:00:00 2001 From: VEZINET Didier Date: Fri, 22 Nov 2019 13:59:24 +0100 Subject: [PATCH 8/8] [Issue272] Working except for the np.get_include(). Further investigations showed that there exist a recommended solution from PEP517 and PEP518: introduce a tofu.toml file for listing build-time dependencies. Opening issue #276 accordingly --- setup.py | 2 +- tofu/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 3a95af8a4..e260e1edb 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ def cythonize(*args, **kwargs): return cythonize(*args, **kwargs) def cthBext(*args, **kwargs): from Cython.Build import build_ext as cthBext - return cthBext(*args, **kwdargs) + return cthBext(*args, **kwargs) import _updateversion as up diff --git a/tofu/version.py b/tofu/version.py index 808143312..ee4e25b5f 100644 --- a/tofu/version.py +++ b/tofu/version.py @@ -1,2 +1,2 @@ # Do not edit, pipeline versioning governed by git tags! -__version__ = '1.4.2-alpha2-12-ge1cc209' +__version__ = '1.4.2-alpha2-13-g7db6643'