Bump version for release 0.1.0.
[crypto-install.git] / setup.py
1 #!/usr/bin/env python
2
3 import glob, os, os.path, re, sys
4
5 from distutils.command.build import build as _build
6 from distutils.command.clean import clean as _clean
7 from distutils.command.install import install as _install
8 from setuptools.command.test import test as _test
9 from distutils.core import setup
10 from distutils.dir_util import remove_tree
11 from setuptools import find_packages
12 from subprocess import check_call, check_output
13
14
15 def translations ():
16     return glob.glob("locale/*/*/*.po")
17
18
19 def message_catalog (translation):
20     return os.path.splitext (os.path.basename (translation))[0] + ".mo"
21
22
23 def message_catalogs ():
24     return [os.path.join (os.path.dirname (translation), message_catalog (translation)) for translation in translations ()]
25
26
27 class test (_test):
28     user_options = [("pytest-args=", "a", "Arguments to pass to py.test")]
29
30     def initialize_options (self):
31         _test.initialize_options (self)
32
33         self.pytest_args = []
34
35     def finalize_options (self):
36         _test.finalize_options (self)
37
38         self.test_args = []
39         self.test_suite = True
40
41     def run_tests (self):
42         _test.run_tests (self)
43
44         # import here, cause outside the eggs aren't loaded
45         import pytest
46         sys.exit (pytest.main (self.pytest_args))
47
48
49 class build (_build):
50     def run (self):
51         _build.run (self)
52
53         def update_version ():
54             with open (os.path.join (self.build_scripts, "crypto-install"), "r+") as file:
55                 data = file.read ()
56                 data = re.sub ("GIT-TAG", check_output (["git", "describe", "--abbrev=0", "--tags"]).strip (), data)
57                 data = re.sub ("GIT-COMMIT", check_output (["git", "rev-parse", "--short=7", "HEAD"]).strip (), data)
58                 data = re.sub ("GIT-BRANCH", check_output (["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip (), data)
59                 file.seek (0)
60                 file.write (data)
61
62         self.execute (update_version, [], "Updating version")
63
64         def compile_message_catalog (translation, output):
65             check_call (["msgfmt", "-o", os.path.join (output, message_catalog (translation)), translation])
66
67         for translation in translations ():
68             output = os.path.join (self.build_base, os.path.dirname (translation))
69
70             self.mkpath (output)
71
72             self.execute (compile_message_catalog, [translation, output], "Compiling message catalog {}".format (translation))
73
74
75 class install (_install):
76     def run (self):
77         _install.run (self)
78
79         self.copy_tree (os.path.join (self.build_base, "locale"),
80                         os.path.join (self.install_data, "share/locale"))
81
82
83 class clean (_clean):
84     def run (self):
85         _clean.run (self)
86
87         if os.path.exists (self.build_base):
88             remove_tree (self.build_base, dry_run = self.dry_run)
89
90
91 setup (
92     name = "crypto_install",
93     version = "0.1.0",
94     author = "Olof-Joachim Frahm",
95     author_email = "olof@macrolet.net",
96     url = "https://github.com/Ferada/crypto-install",
97     scripts = ["crypto-install"],
98     install_requires = [],
99     tests_require = ["pytest"],
100     cmdclass = {
101         "build": build,
102         "clean": clean,
103         "test": test,
104         "install": install
105     },
106     classifiers = [
107         "Development Status :: 3 - Alpha",
108         "Environment :: Console",
109         "Environment :: X11 Applications",
110         "Intended Audience :: End Users/Desktop",
111         "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
112         "Natural Language :: English",
113         "Natural Language :: German",
114         "Operating System :: POSIX",
115         "Programming Language :: Python :: 2.7",
116         "Programming Language :: Python :: 3.2",
117         "Topic :: Security :: Cryptography",
118         "Topic :: Utilities"
119     ])