From bd6f2af0ead3e56443b7a35cac6050a51209076e Mon Sep 17 00:00:00 2001 From: Guillaume Fraux Date: Thu, 7 Dec 2017 14:34:22 +0000 Subject: [PATCH] Change the build system to use standard setup.py This is way easier to do with scikit-build! --- .gitignore | 8 +- .gitmodules | 2 +- CMakeLists.txt | 95 +------------ MANIFEST.in | 3 + README.md | 24 +--- {src/chemfiles => chemfiles}/__init__.py | 8 +- {src/chemfiles => chemfiles}/atom.py | 0 {src/chemfiles => chemfiles}/cell.py | 0 {src/chemfiles => chemfiles}/clib.py | 45 +++--- {src/chemfiles => chemfiles}/ffi.py | 0 {src/chemfiles => chemfiles}/frame.py | 0 {src/chemfiles => chemfiles}/property.py | 0 {src/chemfiles => chemfiles}/residue.py | 0 {src/chemfiles => chemfiles}/selection.py | 0 {src/chemfiles => chemfiles}/topology.py | 0 {src/chemfiles => chemfiles}/trajectory.py | 0 {src/chemfiles => chemfiles}/utils.py | 0 cmake/FindSphinx.cmake | 140 ------------------- cmake/generate_location.cmake | 4 - doc/requirements.txt => dev-requirements.txt | 2 + doc/CMakeLists.txt | 47 ------- doc/Makefile | 19 +++ doc/{conf.py.in => conf.py} | 2 +- doc/reference.rst | 2 +- chemfiles => lib | 0 requirements.txt | 2 + setup.py | 45 ++++++ setup.py.in | 46 ------ tests/CMakeLists.txt | 39 ------ tests/trajectory.py | 21 +-- tests/utils.py | 1 + tox.ini | 11 ++ 32 files changed, 143 insertions(+), 423 deletions(-) create mode 100644 MANIFEST.in rename {src/chemfiles => chemfiles}/__init__.py (64%) rename {src/chemfiles => chemfiles}/atom.py (100%) rename {src/chemfiles => chemfiles}/cell.py (100%) rename {src/chemfiles => chemfiles}/clib.py (63%) rename {src/chemfiles => chemfiles}/ffi.py (100%) rename {src/chemfiles => chemfiles}/frame.py (100%) rename {src/chemfiles => chemfiles}/property.py (100%) rename {src/chemfiles => chemfiles}/residue.py (100%) rename {src/chemfiles => chemfiles}/selection.py (100%) rename {src/chemfiles => chemfiles}/topology.py (100%) rename {src/chemfiles => chemfiles}/trajectory.py (100%) rename {src/chemfiles => chemfiles}/utils.py (100%) delete mode 100644 cmake/FindSphinx.cmake delete mode 100644 cmake/generate_location.cmake rename doc/requirements.txt => dev-requirements.txt (63%) delete mode 100644 doc/CMakeLists.txt create mode 100644 doc/Makefile rename doc/{conf.py.in => conf.py} (97%) rename chemfiles => lib (100%) create mode 100644 requirements.txt create mode 100644 setup.py delete mode 100644 setup.py.in delete mode 100644 tests/CMakeLists.txt create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 378eac25..c75d9cfd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ -build +_skbuild/ +dist/ +chemfiles.egg-info/ +.tox/ +MANIFEST +chemfiles/lib/ +chemfiles/include/ diff --git a/.gitmodules b/.gitmodules index e7b8f5f1..c782af6b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "C++ library"] - path = chemfiles + path = lib url = https://github.com/chemfiles/chemfiles diff --git a/CMakeLists.txt b/CMakeLists.txt index 1358f789..5e3bdedb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,6 @@ -cmake_minimum_required(VERSION 2.8.11) -project(chemfiles.py) +cmake_minimum_required(VERSION 2.8.12) -set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") -cmake_policy(VERSION 2.8.11) - -option(CHFL_PY_CODE_COVERAGE "Enable python code coverage" OFF) -option(CHFL_PY_BUILD_DOCUMENTATION "Build the python documentation" OFF) +# set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") option(CHFL_PY_INTERNAL_CHEMFILES "Use the internal version of chemfiles" OFF) if(NOT ${CHFL_PY_INTERNAL_CHEMFILES}) @@ -25,94 +20,16 @@ if(${chemfiles_FOUND}) endif() else() # Use the git submodule - if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/chemfiles/CMakeLists.txt") + if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/CMakeLists.txt") message(FATAL_ERROR "The git submodule for chemfiles is not initalized.\n" "Please run `git submodule update --init." ) endif() - message(STATUS "Using internal chemfiles from ${CMAKE_CURRENT_SOURCE_DIR}/chemfiles") + 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(chemfiles) - file(READ chemfiles/VERSION CHEMFILES_VERSION) + add_subdirectory(lib) + file(READ lib/VERSION CHEMFILES_VERSION) string(STRIP ${CHEMFILES_VERSION} CHEMFILES_VERSION) endif() - -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in" - "${CMAKE_CURRENT_BINARY_DIR}/setup.py" -) - -find_package(PythonInterp REQUIRED) -set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py") - -file(GLOB_RECURSE PYTHON_SRC src/chemfiles/**.py) -set(SETUP_PY_BUILD_OUTPUT "") -set(COPY_SRC_OUTPUT "") -foreach(_file_ ${PYTHON_SRC}) - file(RELATIVE_PATH _path_ ${CMAKE_CURRENT_SOURCE_DIR} ${_file_}) - list(APPEND COPY_SRC_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_path_}) - - file(RELATIVE_PATH _path_ ${CMAKE_CURRENT_SOURCE_DIR}/src/chemfiles ${_file_}) - list(APPEND SETUP_PY_BUILD_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/build/lib/${_path_}) -endforeach() - -add_custom_command( - OUTPUT ${COPY_SRC_OUTPUT} - COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/src/ - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src/ ${CMAKE_CURRENT_BINARY_DIR}/src/ - DEPENDS ${PYTHON_SRC} - COMMENT "Copying python sources" -) - -# We configure the same file twice: the one in `build/lib` will be the one -# installed, and the one in `src/chemfiles` will be used for testing. -add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/src/chemfiles/location.py" - COMMAND ${CMAKE_COMMAND} - -DLOCATION_PY_PATH=${CMAKE_CURRENT_BINARY_DIR}/src/ - -DCHEMFILES_LOCATION=$ - -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/generate_location.cmake - COMMENT "Generating test location.py" -) - -add_custom_command( - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/lib/chemfiles/location.py" - COMMAND ${CMAKE_COMMAND} - -DLOCATION_PY_PATH=${CMAKE_CURRENT_BINARY_DIR}/build/lib - -DCHEMFILES_LOCATION=${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/$ - -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/generate_location.cmake - COMMENT "Generating install location.py" -) - -add_custom_target(location.py ALL - DEPENDS ${COPY_SRC_OUTPUT} - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/src/chemfiles/location.py - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/build/lib/chemfiles/location.py -) - -add_custom_command( - OUTPUT ${SETUP_PY_BUILD_OUTPUT} - COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} build - DEPENDS location.py - COMMENT "Running python setup.py build" -) - -set(ADDITIONAL_CLEANUP "${CMAKE_CURRENT_BINARY_DIR}/build/") -if(NOT "${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") - set(ADDITIONAL_CLEANUP "${ADDITIONAL_CLEANUP};${CMAKE_CURRENT_BINARY_DIR}/src/") -endif() -set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${ADDITIONAL_CLEANUP}) - -add_custom_target(chemfiles.py ALL DEPENDS ${SETUP_PY_BUILD_OUTPUT}) -add_dependencies(chemfiles.py chemfiles) - -install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install --prefix=${CMAKE_INSTALL_PREFIX})") - -enable_testing() -add_subdirectory(tests) - -if(${CHFL_PY_BUILD_DOCUMENTATION}) - add_subdirectory(doc) -endif() diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..3b95518f --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +recursive-include chemfiles * +recursive-include lib * +include requirements.txt diff --git a/README.md b/README.md index 7c69baba..3d143bd3 100644 --- a/README.md +++ b/README.md @@ -25,31 +25,21 @@ conda install -c conda-forge chemfiles ### Source compilation You can install this python module from sources if you have all the -[dependencies][installation] of the C++ chemfiles library installed on your -computer. +[dependencies] of the C++ chemfiles library installed on your computer. ```bash # To get the latest developement version: git clone https://github.com/chemfiles/chemfiles.py cd chemfiles.py git submodule update --init -mkdir build -cd build -cmake .. # see below for configuration options. -make -# Optionally -make test -make install +# Install developement dependencies +pip install -r dev-requirements.txt +pip install . +# Optionally run the test suite +tox ``` -You can use the same [configuration options][installation] as the C++ chemfiles -library. Additionally, you may also want to specify which python interpreter and -installation to use with `-DPYTHON_EXECUTABLE=/full/path/to/python`, and where -to install the code with `-DCMAKE_INSTALL_PREFIX=`. The C++ library will -be installed to `PREFIX/lib/`; and the python code will be installed in -`PREFIX/lib/python/site-packages/`. - -[installation]: http://chemfiles.readthedocs.org/en/latest/installation.html +[dependencies]: http://chemfiles.readthedocs.org/en/latest/installation.html ## Usage example diff --git a/src/chemfiles/__init__.py b/chemfiles/__init__.py similarity index 64% rename from src/chemfiles/__init__.py rename to chemfiles/__init__.py index b419381c..98acee22 100644 --- a/src/chemfiles/__init__.py +++ b/chemfiles/__init__.py @@ -11,10 +11,4 @@ from .selection import Selection from .property import Property -# Setup work -from .utils import _set_default_warning_callback -from .clib import _get_c_library -_set_default_warning_callback() - -__version__ = _get_c_library().chfl_version().decode("utf8") -assert(__version__.startswith("0.8")) +__version__ = "0.8.0" diff --git a/src/chemfiles/atom.py b/chemfiles/atom.py similarity index 100% rename from src/chemfiles/atom.py rename to chemfiles/atom.py diff --git a/src/chemfiles/cell.py b/chemfiles/cell.py similarity index 100% rename from src/chemfiles/cell.py rename to chemfiles/cell.py diff --git a/src/chemfiles/clib.py b/chemfiles/clib.py similarity index 63% rename from src/chemfiles/clib.py rename to chemfiles/clib.py index eeddd609..603e2847 100644 --- a/src/chemfiles/clib.py +++ b/chemfiles/clib.py @@ -1,12 +1,9 @@ # -* coding: utf-8 -* import os import sys -import struct from ctypes import cdll, c_double, POINTER from ctypes import sizeof, c_voidp -from .location import CHEMFILES_LOCATION, __file__ as location_file_path - class FindChemfilesLibrary(object): def __init__(self): @@ -14,18 +11,8 @@ def __init__(self): def __call__(self): if self._cache is None: - check_dll(CHEMFILES_LOCATION) - try: - self._cache = cdll.LoadLibrary(CHEMFILES_LOCATION) - except OSError: - if location_file_path.endswith(".pyc"): - path = location_file_path[:-1] - else: - path = location_file_path - raise ImportError( - "Could not find chemfiles c++ library. " + - "Please check the path defined in " + path - ) + path = _lib_path() + self._cache = cdll.LoadLibrary(path) from .ffi import set_interface from .ffi import CHFL_FRAME, CHFL_ATOM, chfl_vector3d @@ -36,15 +23,33 @@ def __call__(self): POINTER(CHFL_FRAME), POINTER(CHFL_ATOM), chfl_vector3d, POINTER(c_double) ] + + from .utils import _set_default_warning_callback + _set_default_warning_callback() return self._cache -def check_dll(path): - if not sys.platform.startswith("win"): - return - if not os.path.isfile(path): - return +def _lib_path(): + root = os.path.dirname(__file__) + if sys.platform.startswith("darwin"): + return os.path.join(root, "lib", "libchemfiles.dylib") + elif sys.platform.startswith("linux"): + return os.path.join(root, "lib", "libchemfiles.so") + elif sys.platform.startswith("win"): + candidates = [ + os.path.join(root, "bin", "libchemfiles.dll"), # MinGW + os.path.join(root, "bin", "chemfiles.dll"), # MSVC + ] + for path in candidates: + if os.path.isfile(path): + _check_dll(path) + return path + raise ImportError("Could not find chemfiles DLL") + else: + raise ImportError("Unknown platform. Please edit this file") + +def _check_dll(path): import struct IMAGE_FILE_MACHINE_I386 = 332 diff --git a/src/chemfiles/ffi.py b/chemfiles/ffi.py similarity index 100% rename from src/chemfiles/ffi.py rename to chemfiles/ffi.py diff --git a/src/chemfiles/frame.py b/chemfiles/frame.py similarity index 100% rename from src/chemfiles/frame.py rename to chemfiles/frame.py diff --git a/src/chemfiles/property.py b/chemfiles/property.py similarity index 100% rename from src/chemfiles/property.py rename to chemfiles/property.py diff --git a/src/chemfiles/residue.py b/chemfiles/residue.py similarity index 100% rename from src/chemfiles/residue.py rename to chemfiles/residue.py diff --git a/src/chemfiles/selection.py b/chemfiles/selection.py similarity index 100% rename from src/chemfiles/selection.py rename to chemfiles/selection.py diff --git a/src/chemfiles/topology.py b/chemfiles/topology.py similarity index 100% rename from src/chemfiles/topology.py rename to chemfiles/topology.py diff --git a/src/chemfiles/trajectory.py b/chemfiles/trajectory.py similarity index 100% rename from src/chemfiles/trajectory.py rename to chemfiles/trajectory.py diff --git a/src/chemfiles/utils.py b/chemfiles/utils.py similarity index 100% rename from src/chemfiles/utils.py rename to chemfiles/utils.py diff --git a/cmake/FindSphinx.cmake b/cmake/FindSphinx.cmake deleted file mode 100644 index 0ffeebaf..00000000 --- a/cmake/FindSphinx.cmake +++ /dev/null @@ -1,140 +0,0 @@ -# - This module looks for Sphinx -# Find the Sphinx documentation generator -# -# This modules defines -# SPHINX_EXECUTABLE -# SPHINX_FOUND - -find_program(SPHINX_EXECUTABLE - NAMES sphinx-build - PATHS - /usr/bin - /usr/local/bin - /opt/local/bin - DOC "Sphinx documentation generator" -) - -if( NOT SPHINX_EXECUTABLE ) - set(_Python_VERSIONS - 3.4 3.3 2.9 2.8 2.7 2.6 - ) - - foreach( _version ${_Python_VERSIONS} ) - set( _sphinx_NAMES sphinx-build-${_version} ) - - find_program( SPHINX_EXECUTABLE - NAMES ${_sphinx_NAMES} - PATHS - /usr/bin - /usr/local/bin - /opt/loca/bin - DOC "Sphinx documentation generator" - ) - endforeach() -endif() - -include(FindPackageHandleStandardArgs) - -find_package_handle_standard_args(Sphinx DEFAULT_MSG - SPHINX_EXECUTABLE -) - - - -option(SPHINX_HTML_OUTPUT "Build a single HTML with the whole content." ON) -option(SPHINX_DIRHTML_OUTPUT "Build HTML pages, but with a single directory per document." OFF) -option(SPHINX_HTMLHELP_OUTPUT "Build HTML pages with additional information for building a documentation collection in htmlhelp." OFF) -option(SPHINX_QTHELP_OUTPUT "Build HTML pages with additional information for building a documentation collection in qthelp." OFF) -option(SPHINX_DEVHELP_OUTPUT "Build HTML pages with additional information for building a documentation collection in devhelp." OFF) -option(SPHINX_EPUB_OUTPUT "Build HTML pages with additional information for building a documentation collection in epub." OFF) -option(SPHINX_LATEX_OUTPUT "Build LaTeX sources that can be compiled to a PDF document using pdflatex." OFF) -option(SPHINX_MAN_OUTPUT "Build manual pages in groff format for UNIX systems." OFF) -option(SPHINX_TEXT_OUTPUT "Build plain text files." OFF) - - -mark_as_advanced( - SPHINX_EXECUTABLE - SPHINX_HTML_OUTPUT - SPHINX_DIRHTML_OUTPUT - SPHINX_HTMLHELP_OUTPUT - SPHINX_QTHELP_OUTPUT - SPHINX_DEVHELP_OUTPUT - SPHINX_EPUB_OUTPUT - SPHINX_LATEX_OUTPUT - SPHINX_MAN_OUTPUT - SPHINX_TEXT_OUTPUT -) - -function(Sphinx_add_target target_name builder conf source destination) - add_custom_target( ${target_name} ALL - COMMAND ${SPHINX_EXECUTABLE} -b ${builder} - -c ${conf} - ${source} - ${destination} - COMMENT "Generating sphinx documentation: ${builder}" - ) - - set_property( - DIRECTORY APPEND PROPERTY - ADDITIONAL_MAKE_CLEAN_FILES - ${destination} - ) -endfunction() - -# Target dependencies can be optionally listed at the end. -function(Sphinx_add_targets target_base_name conf source base_destination) - - set(_dependencies) - - foreach(arg IN LISTS ARGN) - set(_dependencies ${_dependencies} ${arg}) - endforeach() - - if(${SPHINX_HTML_OUTPUT}) - Sphinx_add_target(${target_base_name}_html html ${conf} ${source} ${base_destination}/html) - - add_dependencies(${target_base_name}_html ${_dependencies}) - endif() - - if(${SPHINX_DIRHTML_OUTPUT}) - Sphinx_add_target(${target_base_name}_dirhtml dirhtml ${conf} ${source} ${base_destination}/dirhtml) - - add_dependencies(${target_base_name}_dirhtml ${_dependencies}) - endif() - - if(${SPHINX_QTHELP_OUTPUT}) - Sphinx_add_target(${target_base_name}_qthelp qthelp ${conf} ${source} ${base_destination}/qthelp) - - add_dependencies(${target_base_name}_qthelp ${_dependencies}) - endif() - - if(${SPHINX_DEVHELP_OUTPUT}) - Sphinx_add_target(${target_base_name}_devhelp devhelp ${conf} ${source} ${base_destination}/devhelp) - - add_dependencies(${target_base_name}_devhelp ${_dependencies}) - endif() - - if(${SPHINX_EPUB_OUTPUT}) - Sphinx_add_target(${target_base_name}_epub epub ${conf} ${source} ${base_destination}/epub) - - add_dependencies(${target_base_name}_epub ${_dependencies}) - endif() - - if(${SPHINX_LATEX_OUTPUT}) - Sphinx_add_target(${target_base_name}_latex latex ${conf} ${source} ${base_destination}/latex) - - add_dependencies(${target_base_name}_latex ${_dependencies}) - endif() - - if(${SPHINX_MAN_OUTPUT}) - Sphinx_add_target(${target_base_name}_man man ${conf} ${source} ${base_destination}/man) - - add_dependencies(${target_base_name}_man ${_dependencies}) - endif() - - if(${SPHINX_TEXT_OUTPUT}) - Sphinx_add_target(${target_base_name}_text text ${conf} ${source} ${base_destination}/text) - - add_dependencies(${target_base_name}_text ${_dependencies}) - endif() -endfunction() diff --git a/cmake/generate_location.cmake b/cmake/generate_location.cmake deleted file mode 100644 index 652cc4b4..00000000 --- a/cmake/generate_location.cmake +++ /dev/null @@ -1,4 +0,0 @@ -file(WRITE - ${LOCATION_PY_PATH}/chemfiles/location.py - "CHEMFILES_LOCATION = \"${CHEMFILES_LOCATION}\"\n" -) diff --git a/doc/requirements.txt b/dev-requirements.txt similarity index 63% rename from doc/requirements.txt rename to dev-requirements.txt index 585e3382..514676f6 100644 --- a/doc/requirements.txt +++ b/dev-requirements.txt @@ -1,2 +1,4 @@ +tox +scikit-build sphinx sphinx_bootstrap_theme diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt deleted file mode 100644 index e782caa3..00000000 --- a/doc/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -find_package(Sphinx REQUIRED) - -configure_file( - ${PROJECT_SOURCE_DIR}/doc/conf.py.in - ${PROJECT_BINARY_DIR}/doc/conf.py -) - -set(SPHINX_CONF_DIR ${PROJECT_BINARY_DIR}/doc) -set(SPHINX_INPUT_DIR ${PROJECT_SOURCE_DIR}/doc) -set(SPHINX_DESTINATION ${PROJECT_BINARY_DIR}/doc) -set(SPHINX_DEPENDENCIES chemfiles.py) - -set(sphinx_target_base_name python_doc) -Sphinx_add_targets(${sphinx_target_base_name} ${SPHINX_CONF_DIR} ${SPHINX_INPUT_DIR} ${SPHINX_DESTINATION} ${SPHINX_DEPENDENCIES}) - -if( ${SPHINX_HTML_OUTPUT} ) - install( DIRECTORY ${SPHINX_DESTINATION}/html - DESTINATION share/chemfiles/doc - COMPONENT Doc - PATTERN "${SPHINX_DESTINATION}/html/*" - ) -endif() - -if(${SPHINX_LATEX_OUTPUT}) - set(DOC_WITH_LOCAL_DOXYGEN OFF) - - # Build the PDF with pdflatex - find_package(LATEX) - if( NOT PDFLATEX_COMPILER ) - message("pdflatex compiler was not found. Please pass to advanced mode and provide its full path") - else() - # Needs to be executed twice to get table of contents. - add_custom_command( TARGET ${sphinx_target_base_name}_latex - POST_BUILD - COMMAND ${PDFLATEX_COMPILER} - ${SPHINX_DESTINATION}/latex/chemfiles.tex - -output-directory ${SPHINX_DESTINATION}/latex - COMMAND ${MAKEINDEX_COMPILER} - chemfiles.idx - COMMAND ${PDFLATEX_COMPILER} - ${SPHINX_DESTINATION}/latex/chemfiles.tex - -output-directory ${SPHINX_DESTINATION}/latex - WORKING_DIRECTORY ${SPHINX_DESTINATION}/latex - COMMENT "Building PDF" - ) - endif() -endif() diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 00000000..2717b54b --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,19 @@ +# Minimal makefile for Sphinx documentation + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXPROJ = chemfiles.py +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/doc/conf.py.in b/doc/conf.py similarity index 97% rename from doc/conf.py.in rename to doc/conf.py index 266d4a37..c2c57828 100644 --- a/doc/conf.py.in +++ b/doc/conf.py @@ -4,7 +4,7 @@ import sphinx_bootstrap_theme DOC_ROOT = os.path.abspath(os.path.dirname(__file__)) -sys.path.insert(1, "${PROJECT_BINARY_DIR}/src/") +sys.path.insert(1, os.path.join(DOC_ROOT, "..")) # -- General configuration ------------------------------------------------ diff --git a/doc/reference.rst b/doc/reference.rst index ada7f80d..2c88f906 100644 --- a/doc/reference.rst +++ b/doc/reference.rst @@ -13,7 +13,7 @@ Chemfiles uses exceptions for error handling, throwing :py:class:`ChemfilesError ` when an error occurs. -.. automodule:: chemfiles.errors +.. automodule:: chemfiles.utils :members: Trajectory class diff --git a/chemfiles b/lib similarity index 100% rename from chemfiles rename to lib diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..9a1d67ef --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy +enum34 diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..32dd603c --- /dev/null +++ b/setup.py @@ -0,0 +1,45 @@ +# -*- coding=utf-8 -*- +import sys +import chemfiles +from skbuild import setup + +with open('requirements.txt', 'r') as fp: + requirements = list(filter(bool, (line.strip() for line in fp))) + +LONG_DESCRIPTION = """Chemfiles is a library for reading and writing molecular +trajectory files. These files are created by your favorite theoretical chemistry +program, and contains informations about atomic or residues names and positions. +Chemfiles offers abstraction on top of these formats, and a consistent interface +for loading and saving data to these files.""" + +setup( + name="chemfiles", + long_description=LONG_DESCRIPTION, + version=chemfiles.__version__, + author="Guillaume Fraux", + author_email="luthaf@luthaf.fr", + description="Read and write chemistry trajectory files", + license="BSD", + 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 :: Mozilla Public License 2.0 (MPL 2.0)", + "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" +) diff --git a/setup.py.in b/setup.py.in deleted file mode 100644 index 06363dc5..00000000 --- a/setup.py.in +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding=utf-8 -*- -import sys -from setuptools import setup - - -LONG_DESCRIPTION = """Chemfiles is a library for reading and writing molecular -trajectory files. These files are created by your favorite theoretical -chemistry program, and contains informations about atomic or residues names -and positions. Chemfiles offers abstraction on top of these formats, and a -consistent interface for loading and saving data to these files.""" - -options = { - "name": "chemfiles", - "long_description": LONG_DESCRIPTION, - "version": "${CHEMFILES_VERSION}", - "author": "Guillaume Fraux", - "author_email": "luthaf@luthaf.fr", - "description": ("An efficient library for chemistry files IO"), - "license": "MPL-v2.0", - "keywords": "chemistry computational cheminformatics files formats", - "url": "http://github.com/chemfiles/chemfiles.py", - "packages": ['chemfiles'], - "package_dir": {'': 'src'}, - "zip_safe": False, - "install_requires": ["numpy"], - "classifiers": [ - "Development Status :: 4 - Beta", - "Environment :: Console", - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", - "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" - ], -} - -if sys.hexversion < 0x03040000: - options["install_requires"].append("enum34") - -setup(**options) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index c7ced7f3..00000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -if(${CHFL_PY_CODE_COVERAGE}) - set(TEST_COMMAND "coverage;run;--append") -else() - set(TEST_COMMAND ${PYTHON_EXECUTABLE}) -endif() - -set(TEST_RUNNER_PY "${CMAKE_CURRENT_BINARY_DIR}/test-runner.py") -file(WRITE ${TEST_RUNNER_PY} -"import os -import sys -sys.path.insert(1, '${PROJECT_BINARY_DIR}/src') - -path = sys.argv[1] - -# we need to remove sys.argv; as unittest main try to parse it and fails -del sys.argv[1] - -with open(path) as fd: - name = os.path.basename(path) - code = compile(fd.read(), name, 'exec') - exec(code) -") - -function(python_test _file_) - get_filename_component(_name_ ${_file_} NAME_WE) - add_test( - NAME ${_name_} - COMMAND ${TEST_COMMAND} ${TEST_RUNNER_PY} ${_file_} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) -endfunction() - -file(GLOB all_test_files - ${CMAKE_CURRENT_SOURCE_DIR}/*.py -) - -foreach(test_file IN LISTS all_test_files) - python_test(${test_file}) -endforeach(test_file) diff --git a/tests/trajectory.py b/tests/trajectory.py index a0151edb..4f614182 100644 --- a/tests/trajectory.py +++ b/tests/trajectory.py @@ -9,17 +9,18 @@ from chemfiles import ChemfilesError +def get_data_path(data): + root = os.path.dirname(__file__) + return os.path.join(root, "data", data) + + class TestTrajectory(unittest.TestCase): def test_errors(self): self.assertRaises( - ChemfilesError, - Trajectory, - os.path.join("data", "not-here.xyz") + ChemfilesError, Trajectory, get_data_path("not-here.xyz") ) self.assertRaises( - ChemfilesError, - Trajectory, - os.path.join("data", "empty.unknown") + ChemfilesError, Trajectory, get_data_path("empty.unknown") ) with Trajectory("test-tmp.xyz", "w") as trajectory: @@ -28,7 +29,7 @@ def test_errors(self): os.unlink("test-tmp.xyz") def test_read(self): - trajectory = Trajectory(os.path.join("data", "water.xyz")) + trajectory = Trajectory(get_data_path("water.xyz")) self.assertEqual(trajectory.nsteps(), 100) @@ -82,17 +83,17 @@ def test_read(self): frame = trajectory.read_step(10) self.assertEqual(frame.atom(10).name(), "Cs") - trajectory.set_topology(os.path.join("data", "topology.xyz"), "XYZ") + trajectory.set_topology(get_data_path("topology.xyz"), "XYZ") frame = trajectory.read() self.assertEqual(frame.atom(100).name(), "Rd") def test_protocols(self): - with Trajectory(os.path.join("data", "water.xyz")) as trajectory: + with Trajectory(get_data_path("water.xyz")) as trajectory: for frame in trajectory: self.assertEqual(frame.natoms(), 297) def test_close(self): - trajectory = Trajectory(os.path.join("data", "water.xyz")) + trajectory = Trajectory(get_data_path("water.xyz")) trajectory.close() self.assertRaises(ChemfilesError, trajectory.read) diff --git a/tests/utils.py b/tests/utils.py index bacb2690..dd51f9f3 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -8,6 +8,7 @@ class TestErrors(unittest.TestCase): def test_last_error(self): + chemfiles.utils._clear_errors() self.assertEqual(chemfiles.utils._last_error(), "") try: diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..44d28d31 --- /dev/null +++ b/tox.ini @@ -0,0 +1,11 @@ +[tox] +skipsdist = True +[testenv] +commands = + python setup.py install --quiet -- -DCHFL_PY_INTERNAL_CHEMFILES=ON + discover -p "*.py" tests +deps = + discover + scikit-build + numpy + enum34