From da101a092aca4dd3f1dc41467de62ad1c20e5a95 Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Sat, 2 Mar 2019 09:36:55 +0800 Subject: [PATCH] Add initial python setup script --- .gitignore | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/index.hpp | 4 ++ setup.py | 60 +++++++++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 2fca53d..c6cf9bf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,122 @@ # IDE-specific .idea .vscode + +# PYTHON + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/lib/index.hpp b/lib/index.hpp index b54cc3e..20d3981 100644 --- a/lib/index.hpp +++ b/lib/index.hpp @@ -28,6 +28,10 @@ along with this program. If not, see . #define __COMFORTABLE_SWIPE__CONFIG__ "/usr/local/share/comfortable-swipe/comfortable-swipe.conf" #endif /* __COMFORTABLE_SWIPE__CONFIG__ */ +#ifndef __COMFORTABLE_SWIPE__VERSION__ +#error __COMFORTABLE_SWIPE__VERSION__ must be defined. +#endif /* __COMFORTABLE_SWIPE__VERSION__ */ + #include // std::map #include // std::string diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..fec3eb1 --- /dev/null +++ b/setup.py @@ -0,0 +1,60 @@ +import os +from setuptools import setup +from setuptools.extension import Extension + +__CWD__ = os.getcwd() +__DIR__ = os.path.abspath(os.path.dirname(__file__)) +__URL__ = 'https://github.com/Hikari9/comfortable-swipe-ubuntu' + +NAME = 'comfortable-swipe' +VERSION = '1.1.0' +PROGRAM = os.path.join('/usr/local/bin', NAME) +CONFIG = os.path.join(PROGRAM, 'comfortable-swipe.conf') + +try: + # make sure working directory is here + os.chdir(__DIR__) + + # save README as long_description + with open('README.md', 'r') as README_file: + README = README_file.read() + + # save LICENSE as license + with open('LICENSE', 'r') as LICENSE_file: + LICENSE = LICENSE_file.read() + + # have a dictionary of macros + macros = dict( + __COMFORTABLE_SWIPE__PROGRAM__=f'"{PROGRAM}"', + __COMFORTABLE_SWIPE__VERSION__=f'"{VERSION}"', + __COMFORTABLE_SWIPE__CONFIG__=f'"{CONFIG}"' + ) + + # read C++ library for comfortable swipe + comfortable_swipe = Extension( + name='comfortable_swipe', + define_macros=list(macros.items()), + libraries=['xdo'], + include_dirs=['/usr/local/lib'], + sources=['comfortable-swipe.cpp'], + extra_compile_args=['-O2', '-Wno-unused-result'] + + ) + + # setup python script + setup( + name=NAME, + version=VERSION, + description='Comfortable 3-finger and 4-finger swipe gestures', + long_description=README, + license=LICENSE, + author='Rico Tiongson', + author_email='thericotiongson@gmail.com', + url=__URL__, + # import external modules (aka. C++) + ext_modules=[comfortable_swipe], + ) + +finally: + # move working directory back to where it was before + os.chdir(__DIR__)