From d15f85bc0e619e222f849804eec6c30e7c762c90 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 17 Jul 2016 02:28:27 +0300 Subject: [PATCH] Update: makefiles, sphinx docs, tests --- project_template/MANIFEST.in | 6 +++-- project_template/Makefile | 30 +++++++++++++++++++++++ project_template/docs/.gitignore | 4 +++ project_template/docs/genapidocs | 4 +++ project_template/mk-distr | 4 +++ project_template/publish-docs | 8 ++++++ project_template/requirements.txt | 4 +++ project_template/setup.cfg | 10 +++++++- project_template/setup.py | 4 +-- project_template/tests/Makefile | 4 +++ project_template/tests/__init__.py | 22 +++++++++++++++++ project_template/tests/run_all.py | 38 +++++++++++++++++++++++++++++ project_template/tests/test_test.py | 14 +++++++++++ project_template/update | 2 ++ 14 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 project_template/Makefile create mode 100644 project_template/docs/.gitignore create mode 100755 project_template/docs/genapidocs create mode 100755 project_template/publish-docs create mode 100644 project_template/tests/Makefile create mode 100644 project_template/tests/__init__.py create mode 100755 project_template/tests/run_all.py create mode 100755 project_template/tests/test_test.py create mode 100755 project_template/update diff --git a/project_template/MANIFEST.in b/project_template/MANIFEST.in index bf0c60b..5014cb5 100644 --- a/project_template/MANIFEST.in +++ b/project_template/MANIFEST.in @@ -1,2 +1,4 @@ -include COPYING ChangeLog MANIFEST.in README.txt TODO mk-distr requirements.txt -recursive-include project *.py +include docs/genapidocs +include COPYING ChangeLog MANIFEST.in Makefile TODO mk-distr *.txt +recursive-include docs Makefile *.py *.rst *.txt *.css *.js *.html *.gif *.png +recursive-include tests Makefile *.py diff --git a/project_template/Makefile b/project_template/Makefile new file mode 100644 index 0000000..fc9c35e --- /dev/null +++ b/project_template/Makefile @@ -0,0 +1,30 @@ + +.PHONY: all +all: + @echo "Nothing to be done for 'all'" + +.PHONY: release +release: tests flake8 html distr + +.PHONY: distr +distr: + ./mk-distr + +.PHONY: flake8 +flake8: + flake8 + +.PHONY: html +html: + $(MAKE) -C docs html + +.PHONY: test +test: + $(MAKE) -C tests + +.PHONY: tests +tests: test + +.PHONY: clean +clean: + find . -name '*.py[co]' -type f -delete diff --git a/project_template/docs/.gitignore b/project_template/docs/.gitignore new file mode 100644 index 0000000..2be7eb5 --- /dev/null +++ b/project_template/docs/.gitignore @@ -0,0 +1,4 @@ +/_build/ +/_static/ +/_templates/ +/api/ diff --git a/project_template/docs/genapidocs b/project_template/docs/genapidocs new file mode 100755 index 0000000..533956b --- /dev/null +++ b/project_template/docs/genapidocs @@ -0,0 +1,4 @@ +#! /bin/sh + +cd "`dirname $0`"/.. && +exec sphinx-apidoc -Me -o docs/api project diff --git a/project_template/mk-distr b/project_template/mk-distr index 8576eac..6c946f6 100755 --- a/project_template/mk-distr +++ b/project_template/mk-distr @@ -5,6 +5,10 @@ umask 022 && git archive --format=tar --prefix=project/ "${1:-HEAD}" | (cd "$HOME/tmp" && exec tar xf -) && +cp -ap docs "$HOME/tmp/project" && + cd "$HOME/tmp/project" && +chmod -R u=rwX,go=rX docs && + python setup.py sdist --formats=bztar && cd dist && mv project-*.tar.bz2 ../.. && cd ../.. && exec rm -rf project diff --git a/project_template/publish-docs b/project_template/publish-docs new file mode 100755 index 0000000..6e52773 --- /dev/null +++ b/project_template/publish-docs @@ -0,0 +1,8 @@ +#! /bin/sh + +web="$HOME"/Internet/WWW/htdocs/phdru.name/Software/Python/project/docs + +cd "`dirname \"$0\"`"/docs/_build/html && +rsync -ahP --del * --exclude=objects.inv "$web" && + +exec chmod -R u=rwX,go=rX "$web" diff --git a/project_template/requirements.txt b/project_template/requirements.txt index e69de29..beed055 100644 --- a/project_template/requirements.txt +++ b/project_template/requirements.txt @@ -0,0 +1,4 @@ +--trusted-host phdru.name +--find-links=http://phdru.name/Software/Python/ +--install-option="--compile" + diff --git a/project_template/setup.cfg b/project_template/setup.cfg index bc17240..1872c40 100644 --- a/project_template/setup.cfg +++ b/project_template/setup.cfg @@ -2,6 +2,14 @@ universal = 1 [easy_install] +find_links = http://phdru.name/Software/Python/ +optimize = 2 + +[egg_info] +tag_build = +tag_date = 0 +tag_svn_revision = 0 [flake8] -exclude = .git +exclude = .git,docs/conf.py + diff --git a/project_template/setup.py b/project_template/setup.py index 3c7dc16..ba44c74 100755 --- a/project_template/setup.py +++ b/project_template/setup.py @@ -16,8 +16,8 @@ except ImportError: is_setuptools = False versionpath = join(abspath(dirname(__file__)), 'project', '__version__.py') -load_source('m_librarian_version', versionpath) -from m_librarian_version import __version__ +load_source('project_version', versionpath) +from project_version import __version__ setup(name='Template project', version=__version__, diff --git a/project_template/tests/Makefile b/project_template/tests/Makefile new file mode 100644 index 0000000..b990065 --- /dev/null +++ b/project_template/tests/Makefile @@ -0,0 +1,4 @@ + +.PHONY: all +all: + ./run_all.py diff --git a/project_template/tests/__init__.py b/project_template/tests/__init__.py new file mode 100644 index 0000000..3c09ede --- /dev/null +++ b/project_template/tests/__init__.py @@ -0,0 +1,22 @@ + +import unittest + +__all__ = ['TestCase', 'main'] + + +class TestCase(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + + +def main(): + try: + unittest.main(testRunner=unittest.TextTestRunner()) + except SystemExit, msg: + result = msg.args[0] + else: + result = 0 + raise SystemExit(result) diff --git a/project_template/tests/run_all.py b/project_template/tests/run_all.py new file mode 100755 index 0000000..2e217bf --- /dev/null +++ b/project_template/tests/run_all.py @@ -0,0 +1,38 @@ +#! /usr/bin/env python + + +import os +import sys +import subprocess + + +def isexecutable(filename): + infile = open(filename, 'r') + magic = infile.read(2) + infile.close() + return magic == "#!" + + +def collect_tests(): + tests = [] + for dirpath, dirs, files in os.walk("tests"): + tests.extend( + [os.path.join(dirpath, filename) for filename in files + if filename.startswith("test") and filename.endswith(".py") + ]) + return [test[:-3].replace(os.sep, '.') for test in tests + if isexecutable(test)] + + +def main(): + os.chdir(os.path.join(os.path.dirname(sys.argv[0]), os.pardir)) + tests = collect_tests() + + os.environ["PYTHONPATH"] = os.curdir + + for test in sorted(tests): + print test + subprocess.call((sys.executable, '-m', test)) + +if __name__ == '__main__': + main() diff --git a/project_template/tests/test_test.py b/project_template/tests/test_test.py new file mode 100755 index 0000000..422d67d --- /dev/null +++ b/project_template/tests/test_test.py @@ -0,0 +1,14 @@ +#! /usr/bin/env python + + +import unittest +from tests import main + + +class TestFormat(unittest.TestCase): + def test_test(self): + self.assertEqual() + + +if __name__ == "__main__": + main() diff --git a/project_template/update b/project_template/update new file mode 100755 index 0000000..690ecaa --- /dev/null +++ b/project_template/update @@ -0,0 +1,2 @@ +#! /bin/sh +exec "$HOME"/admin/prog/git-scripts/update -- 2.39.2