From cfe44975e80618da05a63e8736669c4e43f50511 Mon Sep 17 00:00:00 2001 From: Olof-Joachim Frahm Date: Wed, 21 Jan 2015 23:31:03 +0000 Subject: [PATCH] Packaging improvements. `setup.py install` now installs both compiled message catalogs as well as the script itself. Note that isn't the best solution yet, as with a proper wheel configuration we could get rid of the script in favour of a library oriented approach (apparently). --- Makefile | 12 +++-- git_hooks/pre-commit/20-flake8 | 3 ++ git_hooks/pre-commit/20-pep8 | 3 -- setup.cfg | 2 +- setup.py | 113 ++++++++++++++++++++++++++++++++-------- 5 files changed, 105 insertions(+), 28 deletions(-) create mode 100755 git_hooks/pre-commit/20-flake8 delete mode 100755 git_hooks/pre-commit/20-pep8 diff --git a/Makefile b/Makefile index 96d1b4e..9d16253 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ run: build/crypto-install build/crypto-install check: - pep8 . + flake8 . test: ./setup.py test @@ -20,8 +20,14 @@ build/crypto-install: crypto-install build locale/*/LC_MESSAGES/crypto-install.m crypto-install > build/crypto-install chmod a+rx build/crypto-install -locale/*/LC_MESSAGES/crypto-install.mo: locale/*/LC_MESSAGES/crypto-install.po - msgfmt $< +%.mo: %.po + msgfmt -o $@ $< + +locale/crypto-install.pot: crypto-install + xgettext -L Python -o $@ $< + +%.po: locale/crypto-install.pot + msgmerge -U $@ $< clean: rm -rf build diff --git a/git_hooks/pre-commit/20-flake8 b/git_hooks/pre-commit/20-flake8 new file mode 100755 index 0000000..50037b4 --- /dev/null +++ b/git_hooks/pre-commit/20-flake8 @@ -0,0 +1,3 @@ +#!/bin/sh + +exec flake8 . diff --git a/git_hooks/pre-commit/20-pep8 b/git_hooks/pre-commit/20-pep8 deleted file mode 100755 index b85163a..0000000 --- a/git_hooks/pre-commit/20-pep8 +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exec pep8 . diff --git a/setup.cfg b/setup.cfg index ead359c..328cd3c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,4 @@ -[pep8] +[flake8] exclude = build select = E123,E226,E241,E242 ignore = E211,E251,E401 diff --git a/setup.py b/setup.py index 26d908e..9a24727 100755 --- a/setup.py +++ b/setup.py @@ -1,48 +1,119 @@ #!/usr/bin/env python -import sys +import glob, os, os.path, re, sys -from distutils.command.build import build +from distutils.command.build import build as _build +from distutils.command.clean import clean as _clean +from distutils.command.install import install as _install +from setuptools.command.test import test as _test from distutils.core import setup +from distutils.dir_util import remove_tree from setuptools import find_packages -from setuptools.command.test import test as TestCommand -from subprocess import call +from subprocess import check_call, check_output -class PyTest (TestCommand): +def translations (): + return glob.glob("locale/*/*/*.po") + + +def message_catalog (translation): + return os.path.splitext (os.path.basename (translation))[0] + ".mo" + + +def message_catalogs (): + return [os.path.join (os.path.dirname (translation), message_catalog (translation)) for translation in translations ()] + + +class test (_test): user_options = [("pytest-args=", "a", "Arguments to pass to py.test")] def initialize_options (self): - TestCommand.initialize_options (self) + _test.initialize_options (self) + self.pytest_args = [] def finalize_options (self): - TestCommand.finalize_options (self) + _test.finalize_options (self) + self.test_args = [] self.test_suite = True def run_tests (self): + _test.run_tests (self) + # import here, cause outside the eggs aren't loaded import pytest sys.exit (pytest.main (self.pytest_args)) -class UpdateVersion (build): +class build (_build): def run (self): - build.run (self) + _build.run (self) + + def update_version (): + with open (os.path.join (self.build_scripts, "crypto-install"), "r+") as file: + data = file.read () + data = re.sub ("GIT-TAG", check_output (["git", "describe", "--abbrev=0", "--tags"]).strip (), data) + data = re.sub ("GIT-COMMIT", check_output (["git", "rev-parse", "--short=7", "HEAD"]).strip (), data) + data = re.sub ("GIT-BRANCH", check_output (["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip (), data) + file.seek (0) + file.write (data) + + self.execute (update_version, [], "Updating version") - def compile (): - call (["make", "build/crypto-install"]) + def compile_message_catalog (translation, output): + check_call (["msgfmt", "-o", os.path.join (output, message_catalog (translation)), translation]) + + for translation in translations (): + output = os.path.join (self.build_base, os.path.dirname (translation)) + + self.mkpath (output) + + self.execute (compile_message_catalog, [translation, output], "Compiling message catalog {}".format (translation)) + + +class install (_install): + def run (self): + _install.run (self) + + self.copy_tree (os.path.join (self.build_base, "locale"), + os.path.join (self.install_data, "share/locale")) + + +class clean (_clean): + def run (self): + _clean.run (self) - self.execute (compile, [], "Updating version") + if os.path.exists (self.build_base): + remove_tree (self.build_base, dry_run = self.dry_run) -setup (name = "crypto_install", - version = "0.0.1", - scripts = ["crypto-install"], - install_requires = [], - tests_require = ["pytest"], - cmdclass = { - "test": PyTest, - "build": UpdateVersion - }) +setup ( + name = "crypto_install", + version = "0.0.1", + author = "Olof-Joachim Frahm", + author_email = "olof@macrolet.net", + url = "https://github.com/Ferada/crypto-install", + scripts = ["crypto-install"], + install_requires = [], + tests_require = ["pytest"], + cmdclass = { + "build": build, + "clean": clean, + "test": test, + "install": install + }, + classifiers = [ + "Development Status :: 3 - Alpha", + "Environment :: Console", + "Environment :: X11 Applications", + "Intended Audience :: End Users/Desktop", + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", + "Natural Language :: English", + "Natural Language :: German", + "Operating System :: POSIX", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.2", + "Topic :: Security :: Cryptography", + "Topic :: Utilities" + ]) -- 1.7.10.4