[mousetrap/gnome3-wip: 160/240] Work on making MouseTrap available over PyPI
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 160/240] Work on making MouseTrap available over PyPI
- Date: Mon, 8 Sep 2014 15:26:00 +0000 (UTC)
commit 0a4be2ebe8ecd02f61939f01db127ac6afa51d47
Author: Kevin Brown <kevin kevinbrown in>
Date: Tue Jun 24 21:33:16 2014 -0400
Work on making MouseTrap available over PyPI
In order to make MouseTrap available over PyPI and installable
using `pip` and `easy_install`, a `main` function was needed so it
could be used as a wrapper and the input function for the script.
The MouseTrap version has also been added to `__init__.py` and is
available as `__version__` so other scripts can reference it.
The requirements are dynamically generated based on whether
Python 2 or Python 3 is being used. Not all of the requirements
can be installed using `pip`, such as PyGObject (except under
Windows), but the requirement checks can still be done
automatically.
`MANIFEST.in` is used by `setuptools` to tell it what files must
be included when packaging the application.
This will automatically set up a `mousetrap` command that can be
run on the command line through the `entry_points` section of
`setup`.
MANIFEST.in | 5 ++++
setup.py | 48 +++++++++++++++++++++++++++++++++++++++++++++
src/mousetrap/__init__.py | 3 ++
src/mousetrap/i18n.py | 2 +-
src/mousetrap/main.py | 6 ++++-
5 files changed, 62 insertions(+), 2 deletions(-)
---
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..be54547
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,5 @@
+include src/mousetrap/mousetrap.yaml
+recursive-include src/mousetrap/locale *
+recursive-include src/mousetrap/haars *
+recursive-exclude * __pycache__
+recursive-exclude * *.py[co]
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..1aabab4
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,48 @@
+from setuptools import setup, find_packages
+import os
+import sys
+
+
+SRC_PATH = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "src"))
+
+sys.path.append(SRC_PATH)
+
+from mousetrap import __version__
+
+PYTHON_VERSION = sys.version_info
+
+all_requirements = [
+ "pygobject",
+ "pyyaml",
+]
+
+python2_requirements = all_requirements + [
+ "python-xlib",
+]
+
+python3_requirements = all_requirements + [
+ "python3-xlib",
+]
+
+if PYTHON_VERSION[0] > 2:
+ requirements = python3_requirements
+else:
+ requirements = python2_requirements
+
+setup(
+ name="mousetrap",
+ version=__version__,
+ url="https://wiki.gnome.org/Projects/MouseTrap",
+ license="GPL",
+ include_package_data=True,
+ install_requires=requirements,
+ packages=find_packages("src"),
+ package_dir={
+ "": "src",
+ },
+ entry_points={
+ "console_scripts": [
+ "mousetrap = mousetrap.main:main",
+ ],
+ },
+)
diff --git a/src/mousetrap/__init__.py b/src/mousetrap/__init__.py
index e69de29..9744b89 100644
--- a/src/mousetrap/__init__.py
+++ b/src/mousetrap/__init__.py
@@ -0,0 +1,3 @@
+__version__ = "1.0.0a"
+
+VERSION = __version__.split(".")
diff --git a/src/mousetrap/i18n.py b/src/mousetrap/i18n.py
index dc24fb0..3eee58e 100644
--- a/src/mousetrap/i18n.py
+++ b/src/mousetrap/i18n.py
@@ -2,7 +2,7 @@ import gettext
import locale
import os
-LOCALE_DIR = os.path.join(os.path.dirname(__file__), "locale")
+LOCALE_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "locale"))
translations = gettext.translation("mousetrap", localedir=LOCALE_DIR)
diff --git a/src/mousetrap/main.py b/src/mousetrap/main.py
index 65db5ad..ed2eb4a 100644
--- a/src/mousetrap/main.py
+++ b/src/mousetrap/main.py
@@ -106,5 +106,9 @@ class Loop(Observable):
return CONTINUE
-if __name__ == '__main__':
+def main():
App(CONFIG).run()
+
+
+if __name__ == '__main__':
+ main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]