From c730ea7b9991192f0a8f9fe9129e387aaddd8ff7 Mon Sep 17 00:00:00 2001 From: Laura Mendoza Date: Mon, 25 Nov 2019 10:38:25 +0100 Subject: [PATCH 1/2] [pypi packaging] added setup requires and toml file --- pyproject.toml | 2 ++ setup.cfg | 6 ++++++ setup.py | 27 +++++++++++++++++++-------- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..93b3bc0e5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[build-system] +requires = ["setuptools>=18.0", "wheel","numpy", "cython>=0.26"] \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 447bcbd4e..f8c8fb6c2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,3 +10,9 @@ with-coverage=1 cover-package=nose where=tofu/tests nologcapture=T + +[options] +setup_requires = + setuptools>=18.0 + cython>=0.26 + numpy \ No newline at end of file diff --git a/setup.py b/setup.py index 3a95af8a4..d3014e76b 100644 --- a/setup.py +++ b/setup.py @@ -11,29 +11,36 @@ import platform import subprocess from codecs import open + +from setuptools import dist # Install numpy right now +dist.Distribution().fetch_build_eggs(['Cython>=0.15.1', 'numpy>=1.10']) + try: - import numpy as np 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 ? - 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) def cthBext(*args, **kwargs): from Cython.Build import build_ext as cthBext return cthBext(*args, **kwdargs) + + +try: + import numpy as np + def npgetinclude(): return np.get_include() + print("numpy version =", np.__version__) + print("numpy file =", np.__file__) +except ImportError: + exit('Please install numpy>=1.11.2 first.') + import _updateversion as up @@ -297,7 +304,11 @@ 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=[ + 'setuptools>=18.0', + 'numpy', + 'cython>=0.26', + ], description="A python library for Tomography for Fusion", long_description=long_description, long_description_content_type=long_description_content_type, From 049dd71bb6b5b824bf0ac920ef61c575aa4b1e4e Mon Sep 17 00:00:00 2001 From: Laura Mendoza Date: Tue, 26 Nov 2019 17:03:30 +0100 Subject: [PATCH 2/2] [setup] cleaned the setup files, now pypi packaging should be working --- .travis.yml | 2 +- pyproject.toml | 3 +- setup.cfg | 6 --- setup.py | 99 +++++++++++++++++--------------------------------- 4 files changed, 37 insertions(+), 73 deletions(-) diff --git a/.travis.yml b/.travis.yml index 460d5e775..d5bd833db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,7 +59,7 @@ deploy: skip_cleanup: true - provider: pypi user: "Didou09" - distributions: "sdist" + distributions: "sdist bdist_wheel" skip_cleanup: true on: tags: true diff --git a/pyproject.toml b/pyproject.toml index 93b3bc0e5..914ec2419 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,3 @@ [build-system] -requires = ["setuptools>=18.0", "wheel","numpy", "cython>=0.26"] \ No newline at end of file +requires = ["setuptools>=40.8.0", "wheel", "cython>0.26", "numpy"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index f8c8fb6c2..447bcbd4e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,9 +10,3 @@ with-coverage=1 cover-package=nose where=tofu/tests nologcapture=T - -[options] -setup_requires = - setuptools>=18.0 - cython>=0.26 - numpy \ No newline at end of file diff --git a/setup.py b/setup.py index d3014e76b..8dd25cc59 100644 --- a/setup.py +++ b/setup.py @@ -4,66 +4,36 @@ https://github.com/ToFuProject/tofu """ import os -import sys import glob import shutil import logging import platform import subprocess from codecs import open - -from setuptools import dist # Install numpy right now -dist.Distribution().fetch_build_eggs(['Cython>=0.15.1', 'numpy>=1.10']) - -try: - 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("cython file =", cth.__file__) -except ImportError: - 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) - - -try: - import numpy as np - def npgetinclude(): return np.get_include() - print("numpy version =", np.__version__) - print("numpy file =", np.__file__) -except ImportError: - exit('Please install numpy>=1.11.2 first.') - +# ... setup tools +from setuptools import setup, find_packages +from setuptools import Extension +# ... packages that need to be in pyproject.toml +import Cython as cth +from Cython.Distutils import build_ext +import numpy as np +# ... import _updateversion as up +# ... for `clean` command +from distutils.command.clean import clean as Clean -logging.basicConfig(level=logging.INFO) -logger = logging.getLogger("tofu.setup") - -# Always prefer setuptools over distutils -try: - from setuptools import setup, find_packages - from setuptools import Extension -except ImportError: - 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 +# == Checking platform ========================================================= is_platform_windows = False if platform.system() == "Windows": is_platform_windows = True -# ============================================================================== +# === Setting clean command ==================================================== +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger("tofu.setup") + class CleanCommand(Clean): description = "Remove build artifacts from the source tree" @@ -127,8 +97,6 @@ def run(self): logger.info("removing '%s'", path) except OSError: pass - - # ============================================================================== @@ -166,23 +134,16 @@ def check_for_openmp(cc_var): shutil.rmtree(tmpdir) return result - # ....... Using function -print("................ checking if openmp installed...") if is_platform_windows: openmp_installed = False else: openmp_installed = not check_for_openmp("cc") -print("................ checking if openmp installed... > ", openmp_installed) - - - # ============================================================================== +# == Getting tofu version ====================================================== _HERE = os.path.abspath(os.path.dirname(__file__)) - - def get_version_tofu(path=_HERE): # Try from git @@ -218,14 +179,14 @@ def get_version_tofu(path=_HERE): version_tofu = version_tofu.lower().replace("v", "") return version_tofu - version_tofu = get_version_tofu(path=_HERE) print("") print("Version for setup.py : ", version_tofu) print("") +# ============================================================================== - +# ============================================================================== # Get the long description from the README file # Get the readme file whatever its extension (md vs rst) @@ -242,9 +203,11 @@ def get_version_tofu(path=_HERE): long_description_content_type = "text/markdown" else: long_description_content_type = "text/x-rst" +# ============================================================================== -# ... Compiling files ........................................................ +# ============================================================================== +# Compiling files if openmp_installed: extra_compile_args = ["-O3", "-Wall", "-fopenmp", "-fno-wrapv"] extra_link_args = ["-fopenmp"] @@ -304,21 +267,21 @@ 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>=18.0', - 'numpy', - 'cython>=0.26', - ], + + # Description of what tofu does description="A python library for Tomography for Fusion", long_description=long_description, long_description_content_type=long_description_content_type, + # The project's main homepage. url="https://github.com/ToFuProject/tofu", # Author details author="Didier VEZINET", author_email="didier.vezinet@gmail.com", + # Choose your license license="MIT", + # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ # How mature is this project? Common values are @@ -338,8 +301,10 @@ def get_version_tofu(path=_HERE): # In which language most of the code is written ? "Natural Language :: English", ], + # What does your project relate to? keywords="tomography geometry 3D inversion synthetic fusion", + # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). packages=find_packages( @@ -357,6 +322,7 @@ def get_version_tofu(path=_HERE): "tests10_plugins", ] ), + # packages = ['tofu','tofu.geom'], # Alternatively, if you want to distribute just a my_module.py, uncomment # this: @@ -367,6 +333,7 @@ def get_version_tofu(path=_HERE): # https://packaging.python.org/en/latest/requirements.html 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, # for example: @@ -381,6 +348,7 @@ def get_version_tofu(path=_HERE): "sphinx_bootstrap_theme", ] }, + # If there are data files included in your packages that need to be # installed, specify them here. If using Python 2.6 or less, then these # have to be included in MANIFEST.in as well. @@ -395,6 +363,7 @@ def get_version_tofu(path=_HERE): "tofu.geom.inputs": ["*.txt"], }, include_package_data=True, + # Although 'package_data' is the preferred approach, in some case you may # need to place data files outside of your packages. See: # http://docs.python.org/3.4/distutils/setupscript.html @@ -410,7 +379,7 @@ def get_version_tofu(path=_HERE): # ], # }, ext_modules=extensions, - cmdclass={"build_ext": cthBext, + cmdclass={"build_ext": build_ext, "clean": CleanCommand}, - include_dirs=[npgetinclude()], + include_dirs=[np.get_include()], )