From 145392108b232529e1d414e444f79b589b6bebdd Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Tue, 2 Mar 2021 17:13:33 +0100 Subject: [PATCH] PyPI setup --- .gitignore | 2 ++ README.md | 13 ++++++++++++ makefile | 52 +++++++++++++++++++++++++++++++++++++++++----- pip/Dockerfile | 25 ++++++++++++++++++++++ pip/MANIFEST.in | 1 + pip/pyproject.toml | 7 +++++++ pip/setup.cfg | 21 +++++++++++++++++++ pip/setup.py | 40 +++++++++++++++++++++++++++++++++++ 8 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 pip/Dockerfile create mode 100644 pip/MANIFEST.in create mode 100644 pip/pyproject.toml create mode 100644 pip/setup.cfg create mode 100644 pip/setup.py diff --git a/.gitignore b/.gitignore index 5dea18d..8ab811e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ tdmripper tdmreaper cython/*.cpp tdmtermite +dist/ +*.egg-info/ diff --git a/README.md b/README.md index 41d515b..01ff4ef 100644 --- a/README.md +++ b/README.md @@ -313,3 +313,16 @@ meta-data and provide these headers for usage in file output (see this - https://pugixml.org/ - https://github.com/zeux/pugixml - https://cython.readthedocs.io/en/latest/src/userguide/wrapping_CPlusPlus.html + +### Packaging + +- https://packaging.python.org/tutorials/packaging-projects/ +- https://medium.com/swlh/distributing-python-packages-protected-with-cython-40fc29d84caf +- https://levelup.gitconnected.com/how-to-deploy-a-cython-package-to-pypi-8217a6581f09 +- https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html +- https://test.pypi.org/account/register/ +- https://malramsay.com/post/perils-of-packaging/ +- https://github.com/pypa/auditwheel +- https://github.com/pypa/python-manylinux-demo +- https://github.com/pypa/manylinux +- https://github.com/neuronsimulator/nrn/issues/329 diff --git a/makefile b/makefile index 2e86ebc..1381dd1 100644 --- a/makefile +++ b/makefile @@ -58,7 +58,7 @@ main.o : src/main.cpp lib/$(SRC).hpp $(HPP) $(SRC).o : lib/$(SRC).cpp lib/$(SRC).hpp $(HPP) $(CC) -c $(OPT) -I $(LIB) $< -o $@ -clean-cpp : +cpp-clean : rm -f $(EXE) *.o src/main.cpp.cpp # --------------------------------------------------------------------------- # @@ -87,7 +87,7 @@ cython-build : cython/setup.py cython/tdm_termite.pxd cython/py_tdm_termite.pyx cython-install : cython/setup.py cython/tdm_termite.pxd cython/py_tdm_termite.pyx $(HPP) lib/tdm_termite.cpp python3 $< install -clean-cython : +cython-clean : rm -vf cython/py_tdm_termite.cpp rm -vf tdm_termite.cpython-*.so python/tdm_termite.cpython-*.so rm -rf build @@ -102,8 +102,50 @@ docker-run: mkdir -pv data/{input,output} docker run -it --rm --volume $(CWD)/data:/home/data tdmtermite:latest /bin/bash -# --------------------------------------------------------------------------- # - -clean : clean-cpp clean-cython +docker-clean: + rm -rv data + docker image remove tdmtermite + +# --------------------------------------------------------------------------- # +# pip + +pip-setup: + apt-get install -y python3-setuptools \ + python3-pip \ + python3-venv + python3 -m pip install --upgrade build + python3 -m pip install twine wheel auditwheel cython + python3 -m pip install --user --upgrade twine + +pip-build: + #python3 -m build + # python3 setup.py sdist bdist_wheel + python3 setup.py bdist_wheel + +# actually it seems we have to use CentOS container +# docker run -i -t -v `pwd`:/io quay.io/pypa/manylinux1_x86_64 /bin/bash +# see https://github.com/neuronsimulator/nrn/issues/329 for setup of the container + +pip-audit: + auditwheel repair $(shell find dist/ -name "*-cp38-cp38-linux_x86_64.whl") + +# username: __token__ +# password: API-token including "pypi-" +# !! RUN AS ROOT!! +pip-upload: + python3 -m twine upload --repository testpypi dist/* + +pip-test-install: + python3 -m pip install --index-url https://test.pypi.org/simple --no-deps TDMtermite-RecordEvolution + # python3 -m pip install -i https://test.pypi.org/simple/ TDMtermite-RecordEvolution==0.5 + +pip-clean: + rm -rvf dist/ + rm -rvf *.egg-info + rm -rvf build/ wheelhouse/ + +# --------------------------------------------------------------------------- # + +clean : cpp-clean cython-clean pip-clean # --------------------------------------------------------------------------- # diff --git a/pip/Dockerfile b/pip/Dockerfile new file mode 100644 index 0000000..29e5000 --- /dev/null +++ b/pip/Dockerfile @@ -0,0 +1,25 @@ + +FROM quay.io/pypa/manylinux2010_x86_64 + +RUN yum -y install \ + git \ + python34-devel \ + gcc-c++ \ + python34-tkinter \ + make \ + python34-pip \ + +RUN sudo yum -y install rh-python36-python-devel.x86_64 rh-python35-python-devel.x86_64 python27-python-devel.x86_64 + +ENV PATH /opt/rh/python27/root/usr/bin:/opt/rh/rh-python35/root/usr/bin/:/opt/rh/rh-python36/root/usr/bin/:$PATH + +RUN python3.6 -m pip install --user --upgrade cython wheel twine auditwheel + +WORKDIR /home/${USERNAME}/neuron-yale + +RUN git checkout setuppy \ + && python3.6 setup.py bdist_wheel + +# repair wheel? see : https://malramsay.com/post/perils_of_packaging/ +RUN python3.6 -m pip install --user --upgrade auditwheel +RUN LD_LIBRARY_PATH=`pwd`/_install/lib auditwheel repair dist/NEURON-7.8-cp36-cp36m-linux_x86_64.whl diff --git a/pip/MANIFEST.in b/pip/MANIFEST.in new file mode 100644 index 0000000..1b7a9c2 --- /dev/null +++ b/pip/MANIFEST.in @@ -0,0 +1 @@ +include cython/tdm_termite.pxd diff --git a/pip/pyproject.toml b/pip/pyproject.toml new file mode 100644 index 0000000..4a9e9f0 --- /dev/null +++ b/pip/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = [ + "setuptools", + "wheel", + "Cython>=0.29.21" +] +build-backend = "setuptools.build_meta" diff --git a/pip/setup.cfg b/pip/setup.cfg new file mode 100644 index 0000000..421e933 --- /dev/null +++ b/pip/setup.cfg @@ -0,0 +1,21 @@ +[metadata] +name = TDMtermite-RecordEvolution +version = 0.5 +author = Record Evolution GmbH +author_email = mario.fink@record-evolution.de +maintainer = Record Evolution GmbH +license = MIT +description = Extract and read data from National Instruments LabVIEW tdx/tdm files and export them as csv files +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/RecordEvolution/TDMtermite.git +project_urls = + Bug Tracker = https://github.com/RecordEvolution/TDMtermite/issues +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: MIT License + Operating System :: OS Independent + +[options] +packages = find: +python_requires = >=3.6 diff --git a/pip/setup.py b/pip/setup.py new file mode 100644 index 0000000..c3a4eda --- /dev/null +++ b/pip/setup.py @@ -0,0 +1,40 @@ +import setuptools +from distutils.core import setup +from distutils.extension import Extension +from Cython.Build import cythonize + +with open("README.md", "r", encoding="utf-8") as fh: + long_description = fh.read() + +extensions = Extension( + name="tdm_termite", + sources=["cython/py_tdm_termite.pyx"], + # libraries=[""], + # library_dirs=["lib"], + include_dirs=["lib","pugixml"], + language='c++', + extra_compile_args=['-std=c++17','-Wno-unused-variable'], + extra_link_args=['-std=c++17'], +) + +setuptools.setup( + name="TDMtermite-RecordEvolution", + version="0.5", + author="Record Evolution GmbH", + author_email="mario.fink@record-evolution.de", + description="Extract and read data from National Instruments LabVIEW tdx/tdm files and export them as csv files", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/RecordEvolution/TDMtermite.git", + project_urls={ + "Bug Tracker": "https://github.com/RecordEvolution/TDMtermite/issues", + }, + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], + ext_modules=cythonize(extensions), + packages=setuptools.find_packages(), + python_requires=">=3.6", +)