From 716c3fe7f33d59b9e2341626f1797379e16024ca Mon Sep 17 00:00:00 2001 From: Luthaf Date: Tue, 1 Dec 2020 17:01:51 +0100 Subject: [PATCH] Update the project to use pyproject.toml --- codecov.yml => .codecov.yml | 0 CMakeLists.txt | 18 +++++--- MANIFEST.in | 1 - chemfiles/.gitignore | 6 ++- chemfiles/clib.py | 10 ++-- dev-requirements.txt | 5 -- pyproject.toml | 22 +++++++++ requirements.txt | 2 - scripts/clean.sh | 6 ++- setup.cfg | 31 +++++++++++++ setup.py | 91 ++++++++++++++++++++----------------- tox.ini | 12 ----- 12 files changed, 126 insertions(+), 78 deletions(-) rename codecov.yml => .codecov.yml (100%) delete mode 100644 dev-requirements.txt create mode 100644 pyproject.toml delete mode 100644 requirements.txt create mode 100644 setup.cfg delete mode 100644 tox.ini diff --git a/codecov.yml b/.codecov.yml similarity index 100% rename from codecov.yml rename to .codecov.yml diff --git a/CMakeLists.txt b/CMakeLists.txt index d8275640..660a1f24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,8 +10,8 @@ if(NOT ${CHFL_PY_INTERNAL_CHEMFILES}) find_package(chemfiles CONFIG QUIET 0.9) endif() -file(REMOVE ${CMAKE_BINARY_DIR}/external.py) -file(REMOVE ${CMAKE_BINARY_DIR}/external.pyc) +file(REMOVE ${PROJECT_SOURCE_DIR}/chemfiles/external.py) +file(REMOVE ${PROJECT_SOURCE_DIR}/chemfiles/external.py) if(${chemfiles_FOUND}) set(CHEMFILES_VERSION "${chemfiles_VERSION}") @@ -25,10 +25,9 @@ if(${chemfiles_FOUND}) "Define CHFL_PY_INTERNAL_CHEMFILES=ON to use use the internal chemfiles." ) endif() - file(WRITE ${CMAKE_BINARY_DIR}/external.py + file(WRITE ${PROJECT_SOURCE_DIR}/chemfiles/external.py "EXTERNAL_CHEMFILES = \"${CHEMFILES_LOCATION}\"\n" ) - install(FILES ${CMAKE_BINARY_DIR}/external.py DESTINATION ".") else() # Use the git submodule if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/CMakeLists.txt") @@ -40,7 +39,12 @@ else() message(STATUS "Using internal chemfiles from ${CMAKE_CURRENT_SOURCE_DIR}/lib") set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries instead of static ones" FORCE) - add_subdirectory(lib) - file(READ lib/VERSION CHEMFILES_VERSION) - string(STRIP ${CHEMFILES_VERSION} CHEMFILES_VERSION) + add_subdirectory(lib EXCLUDE_FROM_ALL) + + add_custom_target(build_chemfiles ALL) + add_dependencies(build_chemfiles chemfiles) + install(TARGETS chemfiles + LIBRARY DESTINATION "chemfiles" + RUNTIME DESTINATION "chemfiles" + ) endif() diff --git a/MANIFEST.in b/MANIFEST.in index 69c20ea9..4c3725d6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,7 +2,6 @@ recursive-include chemfiles * recursive-include lib * prune lib/tests prune lib/doc -include requirements.txt include CMakeLists.txt include README.md include LICENSE diff --git a/chemfiles/.gitignore b/chemfiles/.gitignore index 4f1534a5..b95f5578 100644 --- a/chemfiles/.gitignore +++ b/chemfiles/.gitignore @@ -1,3 +1,5 @@ -lib/ -include/ external.py + +*.dylib +*.so +*.dll diff --git a/chemfiles/clib.py b/chemfiles/clib.py index 610d1dac..afc66719 100644 --- a/chemfiles/clib.py +++ b/chemfiles/clib.py @@ -40,15 +40,15 @@ def __call__(self): def _lib_path(): if EXTERNAL_CHEMFILES: return EXTERNAL_CHEMFILES - root = os.path.dirname(__file__) + root = os.path.abspath(os.path.dirname(__file__)) if sys.platform.startswith("darwin"): - return os.path.join(root, "lib", "libchemfiles.dylib") + return os.path.join(root, "libchemfiles.dylib") elif sys.platform.startswith("linux"): - return os.path.join(root, "lib", "libchemfiles.so") + return os.path.join(root, "libchemfiles.so") elif sys.platform.startswith("win"): candidates = [ - os.path.join(root, "bin", "libchemfiles.dll"), # MinGW - os.path.join(root, "bin", "chemfiles.dll"), # MSVC + os.path.join(root, "libchemfiles.dll"), # MinGW + os.path.join(root, "chemfiles.dll"), # MSVC ] for path in candidates: if os.path.isfile(path): diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index cb489007..00000000 --- a/dev-requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -tox -scikit-build -sphinx -sphinx_bootstrap_theme --r requirements.txt diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..e8c470ab --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,22 @@ +[build-system] +requires = ["setuptools", "wheel", "scikit-build"] #, "cmake", "ninja"] +build-backend = "setuptools.build_meta" + +[tool.tox] +legacy_tox_ini = """ +[tox] +skipsdist = True + +[testenv] +; this is required on windows to ensure the compiler finds the standard lib +; files (kernel32.lib, etc.) and headers +passenv = LIB INCLUDE LIBPATH +setenv = + CHFL_PY_INTERNAL_CHEMFILES = 1 +commands = + pip install -e . + discover -p "*.py" tests +deps = + discover + numpy +""" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 9a1d67ef..00000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -numpy -enum34 diff --git a/scripts/clean.sh b/scripts/clean.sh index c878f566..288723f8 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -10,6 +10,8 @@ rm -rf _skbuild rm -rf dist rm -rf MANIFEST rm -rf chemfiles.egg-info -rm -rf chemfiles/lib -rm -rf chemfiles/include + +rm -rf chemfiles/*.dylib +rm -rf chemfiles/*.so +rm -rf chemfiles/*.dll rm -rf chemfiles/external.py diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..a028c24a --- /dev/null +++ b/setup.cfg @@ -0,0 +1,31 @@ +[metadata] +name = chemfiles +long_description = file: README.md +long_description_content_type = text/markdown + +license_files = LICENSE +author = Guillaume Fraux +author_email = guillaume@fraux.fr +description = Read and write computational chemistry files +keywords = chemistry computational cheminformatics files formats +url = http://github.com/chemfiles/chemfiles.py +classifiers = + Development Status :: 4 - Beta + Environment :: Console + Intended Audience :: Developers + Intended Audience :: Science/Research + License :: OSI Approved :: BSD License + Operating System :: MacOS :: MacOS X + Operating System :: Microsoft :: Windows + Operating System :: Unix + Programming Language :: Python :: 2 + Programming Language :: Python :: 3 + Topic :: Scientific/Engineering :: Chemistry + Topic :: Software Development :: Libraries :: Python Modules + Topic :: Utilities + +[options] +zip_safe = False + +[bdist_wheel] +universal = 1 diff --git a/setup.py b/setup.py index 0a93e399..def5dd01 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,17 @@ # -*- coding=utf-8 -*- -import chemfiles -import sys from wheel.bdist_wheel import bdist_wheel from skbuild import setup +import sys +import os +import re + + +# Read the version from chemfiles/__init__.py without importing chemfiles +__version__ = re.search( + r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', open("chemfiles/__init__.py").read() +).group(1) + class universal_wheel(bdist_wheel): # Workaround until https://github.com/pypa/wheel/issues/185 is resolved @@ -12,49 +20,48 @@ def get_tag(self): return ("py2.py3", "none") + tag[2:] -with open("requirements.txt", "r") as fd: - requirements = list(filter(bool, (line.strip() for line in fd))) - if sys.hexversion >= 0x03040000: - requirements = list(filter(lambda r: r != "enum34", requirements)) +install_requires = ["numpy"] +if sys.hexversion < 0x03040000: + install_requires.append("enum34") + +# scikit-build options +cmake_args = [] +if sys.platform.startswith("darwin"): + cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9") + +if os.getenv("CHFL_PY_INTERNAL_CHEMFILES"): + cmake_args.append("-DCHFL_PY_INTERNAL_CHEMFILES=ON") + + +def _get_lib_ext(): + if sys.platform.startswith("win32"): + ext = ".dll" + elif sys.platform.startswith("darwin"): + ext = ".dylib" + elif sys.platform.startswith("linux"): + ext = ".so" + else: + raise Exception("Unknown operating system: %s" % sys.platform) + return ext -long_description = "" -with open("README.md", "r") as fd: - for line in fd: - # remove github badges - if not line.startswith("[!["): - long_description += line setup( - name="chemfiles", - long_description=long_description, - long_description_content_type="text/markdown", - version=chemfiles.__version__, - author="Guillaume Fraux", - author_email="luthaf@luthaf.fr", - description="Read and write chemistry trajectory files", - keywords="chemistry computational cheminformatics files formats", - url="http://github.com/chemfiles/chemfiles.py", - packages=["chemfiles"], - zip_safe=False, - install_requires=requirements, - setup_requires=["scikit-build"], - classifiers=[ - "Development Status :: 4 - Beta", - "Environment :: Console", - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: BSD License", - "Operating System :: MacOS :: MacOS X", - "Operating System :: Microsoft :: Windows", - "Operating System :: Unix", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 3", - "Topic :: Scientific/Engineering :: Chemistry", - "Topic :: Software Development :: Libraries :: Python Modules", - "Topic :: Utilities", - ], - cmake_install_dir="chemfiles", - cmake_args=['-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9'], + version=__version__, + install_requires=install_requires, cmdclass={"bdist_wheel": universal_wheel}, + # cmake_install_dir="chemfiles", + cmake_args=cmake_args, + packages=["chemfiles"], + package_data={ + "chemfiles": [ + "*" + _get_lib_ext(), + "bin/*" + _get_lib_ext(), + ] + }, + exclude_package_data={ + "chemfiles": [ + "include/*", + ] + }, ) diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 4fd86150..00000000 --- a/tox.ini +++ /dev/null @@ -1,12 +0,0 @@ -[tox] -skipsdist = True - -[testenv] -commands = - python setup.py --quiet install -- -DCHFL_PY_INTERNAL_CHEMFILES=ON - discover -p "*.py" tests -deps = - discover - scikit-build - numpy - enum34