Skip to content

Commit 79f8d46

Browse files
committedMay 29, 2015
add Python Project Template
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent 2e8e0db commit 79f8d46

File tree

8 files changed

+831
-0
lines changed

8 files changed

+831
-0
lines changed
 

Diff for: ‎.pypt/LICENSE.PyPT

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Python Project Template is licensed under a BSD-like license. You are free to
2+
relicense your code to another open source license. If you want to apply a
3+
commercial (a.k.a. proprietary) license, you must contact me first.
4+
5+
HOWEVER, the following files must remain under the BSD license:
6+
7+
* /.pypt/aursend
8+
* /.pypt/commitlog
9+
* /.pypt/localegen
10+
* /.pypt/README.PyPT
11+
* /.pypt/LICENSE.PyPT
12+
* /docs/CONTRIBUTING.rst
13+
* /CONTRIBUTING.rst
14+
* /release
15+
16+
17+
The README file for PyPT MAY NOT be relicensed.
18+
19+
The actual license is: (the name may have been replaced by yours if you did the
20+
Getting up to speed in 15 easy steps, it was mine originally, and the
21+
version in .pypt/ should reflect that.)
22+
23+
LICENSE
24+
-------
25+
26+
Copyright © 2013-2015, Chris Warrick.
27+
All rights reserved.
28+
29+
Redistribution and use in source and binary forms, with or without
30+
modification, are permitted provided that the following conditions are
31+
met:
32+
33+
1. Redistributions of source code must retain the above copyright
34+
notice, this list of conditions, and the following disclaimer.
35+
36+
2. Redistributions in binary form must reproduce the above copyright
37+
notice, this list of conditions, and the following disclaimer in the
38+
documentation and/or other materials provided with the distribution.
39+
40+
3. Neither the name of the author of this software nor the names of
41+
contributors to this software may be used to endorse or promote
42+
products derived from this software without specific prior written
43+
consent.
44+
45+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
47+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
48+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
49+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Diff for: ‎.pypt/README.rst

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
===============================================
2+
Python Project Template. INSERT TAGLINE HERE.™
3+
===============================================
4+
:Info: This is the README file for the Python Project Template.
5+
:Author: Chris Warrick <chris@chriswarrick.com>
6+
:Copyright: © 2013-2015, Chris Warrick.
7+
:License: BSD (see /LICENSE or :doc:`Appendix B <LICENSE>`.)
8+
:Date: 2015-01-03
9+
:Version: 1.0.6
10+
11+
.. index: README
12+
.. image:: https://travis-ci.org/Kwpolska/python-project-template.png?branch=master
13+
14+
USING THE TEMPLATE
15+
------------------
16+
17+
Requirements
18+
============
19+
20+
* ``zsh`` installed (required by ``/release`` and ``/.pypt/localegen`` scripts)
21+
* Python with ``requests`` (required by ``/.pypt/{commitlog,aursend}``) and ``twine`` (required by ``/release``) installed
22+
* `git-flow extensions by nvie <https://github.com/nvie/gitflow>`_ (alternatively yo can manually alter the ``/release`` script, and that is much harder than
23+
installing the extensions)
24+
* A git repository. The PyPT is ready to go if you use GitHub. If you do not
25+
want GitHub, edit the ``/PKGBUILD{,-2}{,-git}`` files and any other places
26+
where GitHub is mentioned, including this document which you should edit
27+
mentally.
28+
29+
Recommended possessions
30+
=======================
31+
32+
* Travis CI account (if you do not want Travis CI, remove ``/.travis.yml``)
33+
* AUR account (if you do not want AUR uploads, remove the
34+
``/PKGBUILD{,-2}{,-git}`` files and modify the ``/.pypt/config`` file)
35+
36+
Contents
37+
========
38+
39+
The template contains the following files to get you started:
40+
41+
* pre-configured Sphinx with:
42+
43+
* ``CONTRIBUTING.rst`` guide (used by GitHub when sending a pull request or an issue)
44+
* ``LICENSE.rst``
45+
* an empty ``CHANGELOG.rst``
46+
* this (worthless for most people) ``README.rst`` and a bare-bones ``index.rst`` page
47+
48+
* The exact same files in ``/``, which are fragile and **MAY NOT** be modified
49+
as they are replaced with copies in ``/docs`` by the ``release``
50+
script
51+
* ``__init__.py`` and ``template.py`` files in the Python package directory
52+
* A good-enough ``setup.py`` file
53+
* ``tests.py`` containing some *Is My Python Sane?*-style tests
54+
* A sample ``/usr/bin/`` script
55+
* Addons for Qt users
56+
* PKGBUILDs for the Arch Linux User Repository (AUR)
57+
* A state-of-the-art ``release`` script, the operations of which are:
58+
59+
* querying the current branch for version number
60+
* updating ``/docs/CHANGELOG.rst``
61+
* bumping the version number in all the files, changing dates where necessary
62+
* copying over ``/docs/README.rst``, ``/docs/CHANGELOG.rst`` and ``/docs/CONTRIBUTING.rst`` to ``/``
63+
* locale generation (via the ``.pypt/localegen`` script)
64+
* running ``import $project`` and the testsuite
65+
* creating and uploading AUR packages
66+
* committing into git, finishing the ``git flow`` release
67+
68+
69+
Getting up to speed in 15 easy steps
70+
====================================
71+
72+
1. Create the repository for the project on GitHub and enable it on Travis CI.
73+
2. Manually change ``Kwpolska`` to your GitHub name in the following files:
74+
75+
1. ``/docs/README.rst``, line 10
76+
2. ``/docs/CHANGELOG.rst``, line 10
77+
3. ``/setup.py``, line 14
78+
4. ``/PKGBUILD{,-2}{,-git}``, in ``url`` and ``source`` (git only)
79+
80+
3. Manually change the ``Maintainer`` line in ``/PKGBUILD{,-2}{,-git}``.
81+
4. Replace the following patterns (eg. with sed), in all files, **excluding
82+
dotfiles**:
83+
84+
1. ``TEMPLATE`` with the full name of the project
85+
2. ``tEmplate`` with a “light” name of the project [a-z0-9\_\\-], which will
86+
be used in the PyPI, AUR, and a few other places. You can use capital
87+
letters if you feel like it, but it is discouraged and was not tested.
88+
3. ``python-project-template`` with the GitHub repo name
89+
4. ``INSERT TAGLINE HERE.`` with a tagline of your choice
90+
5. ``chris@chriswarrick.com`` with your e-mail address
91+
6. ``Kwpolska`` and/or ``Chris Warrick`` with your name (affects mostly copyright notices)
92+
93+
WARNING: some files are in the copyright of Chris Warrick and must stay this
94+
way! They are listed in the license, please keep my name there, otherwise
95+
you risk breaking the law.
96+
97+
Also, if ``len(computer_friendly_name) != len('tEmplate')``, you may want to
98+
change the amount of tildes in docstrings of Python files.
99+
100+
4. Rename ``/tEmplate`` to the name used in 4.2.
101+
5. Modify ``/docs/README.rst`` to reflect your project and not the Template
102+
(and make a copy if you are reading it locally from those files)
103+
6. Copy: (when using the included ``release`` script, it happens automatically)
104+
105+
1. ``/docs/README.rst`` to ``/README.rst`` and ``/README``
106+
2. ``/docs/CHANGELOG.rst`` to ``/CHANGELOG.rst``
107+
108+
7. Modify ``/.pypt/config``
109+
8. Modify ``/bin/tEmplate`` and rename it OR remove the directory
110+
9. Customize ``/setup.py`` to your liking. You should pay attention to the
111+
classifiers and the commented parts.
112+
10. Customize requirements.txt.
113+
11. If you are using PyQt4 or PySide, make sure to put your UI code in a ``ui``
114+
submodule. Copy over the ``/QT-ADDONS/resources.py`` file to that
115+
submodule, even if you are not using resources now.
116+
12. Remove the ``/QT-ADDONS/`` directory.
117+
13. If you are using Qt, make sure to create a ``.pro`` file with your sources
118+
and locales.
119+
14. Read the COPYRIGHT section below (or ``LICENSE.PyPT``) and remove
120+
``/LICENSE.PyPT`` and ``/README.PyPT``. If you believe the BSD license presented by the
121+
``/LICENSE`` file is not the license you want, here is a list of files you
122+
should modify:
123+
124+
1. ``/tests.py``
125+
2. Everything in the Python package directory (twice in many cases)
126+
3. Everything in ``/docs``
127+
4. ``/LICENSE``, which is **not** equivalent to ``/docs/LICENSE.rst``
128+
129+
PS. GNU GPL is not a good idea. You can use it, but the world would be
130+
much happier if you did not.
131+
132+
15. Remove ``/.git``, and run the following commands, replacing stuff with ``$``
133+
in front::
134+
135+
git init
136+
git remote add origin git@github.com:$GITUSERNAME/$GITREPO
137+
git flow init #(change version tag prefix to `v`)
138+
git add *
139+
git checkout develop
140+
git commit -sm 'initial commit via @Kwpolska’s Python Project Template'
141+
git checkout master
142+
git merge --ff-only develop
143+
git push -u origin master develop
144+
145+
COPYRIGHT
146+
---------
147+
148+
Python Project Template is licensed under a BSD-like license. You are free to
149+
relicense your code to another open source license. If you want to apply a
150+
commercial (a.k.a. proprietary) license, you must contact me first.
151+
152+
**However, the following files must remain under the BSD license:**
153+
154+
* /.pypt/aursend
155+
* /.pypt/commitlog
156+
* /.pypt/localegen
157+
* /.pypt/README.PyPT
158+
* /.pypt/LICENSE.PyPT
159+
* /docs/CONTRIBUTING.rst
160+
* /CONTRIBUTING.rst
161+
* /release
162+
163+
**This README file MAY NOT be relicensed.**
164+
165+
Copyright © 2013-2015, Chris Warrick.
166+
All rights reserved.
167+
168+
Redistribution and use in source and binary forms, with or without
169+
modification, are permitted provided that the following conditions are
170+
met:
171+
172+
1. Redistributions of source code must retain the above copyright
173+
notice, this list of conditions, and the following disclaimer.
174+
175+
2. Redistributions in binary form must reproduce the above copyright
176+
notice, this list of conditions, and the following disclaimer in the
177+
documentation and/or other materials provided with the distribution.
178+
179+
3. Neither the name of the author of this software nor the names of
180+
contributors to this software may be used to endorse or promote
181+
products derived from this software without specific prior written
182+
consent.
183+
184+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
185+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
187+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
188+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
189+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
190+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
191+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
192+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
193+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
194+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Diff for: ‎.pypt/aursend

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/python
2+
# -*- encoding: utf-8 -*-
3+
# Kw’s Release Tools/Python Project Template
4+
# AUR Uploader
5+
# Copyright © 2013-2015, Chris Warrick.
6+
# All rights reserved.
7+
#
8+
# Redistribution and use in source and binary forms, with or without
9+
# modification, are permitted provided that the following conditions are
10+
# met:
11+
#
12+
# 1. Redistributions of source code must retain the above copyright
13+
# notice, this list of conditions, and the following disclaimer.
14+
#
15+
# 2. Redistributions in binary form must reproduce the above copyright
16+
# notice, this list of conditions, and the following disclaimer in the
17+
# documentation and/or other materials provided with the distribution.
18+
#
19+
# 3. Neither the name of the author of this software nor the names of
20+
# contributors to this software may be used to endorse or promote
21+
# products derived from this software without specific prior written
22+
# consent.
23+
#
24+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35+
import json
36+
import requests
37+
import getpass
38+
import sys
39+
import tarfile
40+
41+
# This was nicely stolen from PKGBUILDer.
42+
CATEGORIES = ['none', 'none', 'daemons', 'devel', 'editors',
43+
'emulators', 'games', 'gnome', 'i18n', 'kde',
44+
'lib', 'modules', 'multimedia', 'network',
45+
'office', 'science', 'system', 'x11',
46+
'xfce', 'kernels', 'wayland']
47+
48+
AURURL = 'https://aur.archlinux.org/'
49+
SESSION = requests.Session()
50+
51+
if __name__ == '__main__':
52+
if sys.version_info[0] == 2:
53+
input = raw_input
54+
55+
username = input('Username: ')
56+
password = getpass.getpass('Password: ')
57+
58+
r = SESSION.post(AURURL + 'login', data={'user': username,
59+
'passwd': password})
60+
sid = SESSION.cookies['AURSID']
61+
62+
for pkgorder, filename in enumerate(sys.argv[1:]):
63+
thandle = tarfile.open(filename, 'r:gz')
64+
# Warning: this is fragile. However, as part of the PyPT, we know that
65+
# archives built by the release script have a sane order, allowing us
66+
# to drop worthless magic or PKGBUILD parsing.
67+
pkgname = thandle.next().name
68+
thandle.close()
69+
70+
try:
71+
import pkgbuilder.utils
72+
try:
73+
category = pkgbuilder.utils.info(pkgname)[0]._categoryid
74+
except IndexError:
75+
category = None
76+
except ImportError:
77+
# The user does not have PKGBUILDer installed. Because PyPT caters
78+
# to all sorts of audiences and is meant to be portable, I
79+
# copy-pasted PKGBUILDer code down here and used it for the above.
80+
# Note that this uses an info requests, something PKGBUILDer does
81+
# not do since multiinfo requests were implemented upstream.
82+
r = SESSION.get(AURURL + 'rpc.php', params={'type': 'info', 'arg': pkgname})
83+
r.raise_for_status()
84+
pkgdata = json.loads(r.text)
85+
try:
86+
category = pkgdata['results']['CategoryID']
87+
except TypeError:
88+
# The AUR RPC returns an empty list in the 'results' field if
89+
# there is no such package and a dict (aka object) in the
90+
# 'results' field if the package exists.
91+
# Why am I using 'info'?
92+
category = None
93+
# Now that we are done with this procedure, time to upload them.
94+
# But wait: what if the category is `None` Or if the user chose a
95+
# wrong category? ↓ because ERROR is invalid (1-19)
96+
while category not in range(1, len(CATEGORIES)):
97+
catlist = list(enumerate(CATEGORIES[1:], 1))
98+
print('Choose a category for {0}.'.format(pkgname))
99+
formatted = [catlist[i:i + 5] for i in range(0, len(catlist), 5)]
100+
formatted[-1] = formatted[-1] + (5 - len(formatted[-1])) * [('', '')]
101+
# 'multimedia' is 10, and we use this as our width.
102+
for i in formatted:
103+
print('{0[0]:>2}: {0[1]:<10} {1[0]:>2}: {1[1]:<10} {2[0]:>2}'
104+
': {2[1]:<10} {3[0]:>2}: {3[1]:<10} {4[0]:>2}: '
105+
'{4[1]:<10} {5[0]:>2}: {5[1]:<10}'.format(i))
106+
107+
category = input('Category: ')
108+
109+
r = SESSION.post(AURURL + 'submit/',
110+
data={'pkgsubmit': 1, 'token': sid,
111+
'category': category},
112+
files={'pfile': open(filename, 'rb')})
113+
r.raise_for_status()
114+
115+
# Note that I do not perform any sanity checks. There is a reason: I believe
116+
# that PyPT is so awesome and wonderful that it cann— oh wait, stop this
117+
# bullshit. I actually had a little Heisenbug in here and removed a sanity check.

Diff for: ‎.pypt/commitlog

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/python
2+
# -*- encoding: utf-8 -*-
3+
# Kw’s Release Tools/Python Project Template
4+
# Commit and Changelog Parser
5+
# Copyright © 2013-2015, Chris Warrick.
6+
# All rights reserved.
7+
#
8+
# Redistribution and use in source and binary forms, with or without
9+
# modification, are permitted provided that the following conditions are
10+
# met:
11+
#
12+
# 1. Redistributions of source code must retain the above copyright
13+
# notice, this list of conditions, and the following disclaimer.
14+
#
15+
# 2. Redistributions in binary form must reproduce the above copyright
16+
# notice, this list of conditions, and the following disclaimer in the
17+
# documentation and/or other materials provided with the distribution.
18+
#
19+
# 3. Neither the name of the author of this software nor the names of
20+
# contributors to this software may be used to endorse or promote
21+
# products derived from this software without specific prior written
22+
# consent.
23+
#
24+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35+
36+
# Arguments:
37+
# FILE BASEDIR OLDVERSION
38+
39+
import re
40+
from os.path import join as pjoin
41+
from sys import argv
42+
from textwrap import indent
43+
44+
with open(argv[1]) as fh:
45+
e = re.findall('#~ C(.*?) MESSAGE START ~#\n(.*?)\n#~ C(.*?) MESSAGE '
46+
'END ~#', fh.read(), flags=re.S)
47+
48+
for i in e:
49+
i = list(i)
50+
if i[0] != i[2]:
51+
print('ERROR: mismatched tags')
52+
exit(1)
53+
else:
54+
i[0] = 'C' + i[0] # regexp hack
55+
if i[0] == 'COMMIT':
56+
with open(argv[1] + 'commit', 'w') as fh:
57+
fh.write(i[1])
58+
elif i[0] == 'CHANGELOG':
59+
with open(pjoin(argv[2], 'docs', 'CHANGELOG.rst')) as fh:
60+
currentfile = fh.read()
61+
62+
# A bit fragile...
63+
currentver = re.search(':Version: (.*)', currentfile).groups()[0]
64+
clog = indent(i[1], 4 * ' ')
65+
66+
with open(pjoin(argv[2], 'docs', 'CHANGELOG.rst'), 'w') as fh:
67+
fh.write(currentfile.replace('\n' + currentver,
68+
'\n{0}\n{1}\n\n{2}'.format(
69+
argv[3], clog, currentver)))

Diff for: ‎.pypt/config

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Human-friendly project name.
3+
PROJECT="Coil"
4+
# Computer-friendly project name, [a-z0-9_\-]
5+
PROJECTLC="coil"
6+
7+
# Git repository name. Using $PROJECTLC is recommended.
8+
GITREPO=$PROJECTLC
9+
10+
# Locale type. One of:
11+
# none Do not generate nor use any locales.
12+
# gettext Use GNU gettext (gettext module).
13+
# pyqt4 Use the Qt locale tools (stock Qt + PyQt4).
14+
# pyside Use the Qt locale tools (stock Qt + PySide).
15+
LOCALETYPE="none"
16+
17+
# Python versions supported.
18+
PYTHON2=1
19+
PYTHON3=1
20+
21+
# AUR packages creation mode. One of:
22+
# none Do not create nor upload AUR packages.
23+
# python Create python{,2}-$PROJECTLC{,-git} packages (4 in total)
24+
# app Create $AURNAME{,-git} packages with Python 3
25+
AURTYPE="none"
26+
27+
# AUR package name. Defaults to $PROJECTLC. Ignored by `python`.
28+
# WARNING: you still need to edit the PKGBUILDs.
29+
AURNAME=$PROJECTLC

Diff for: ‎.pypt/hooks/pre-sdist.hook

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/zsh
2+
. .pypt/config

Diff for: ‎.pypt/localegen

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/zsh
2+
# Kw’s Release Tools/Python Project Template
3+
# Locale Generator
4+
# Copyright © 2013-2015, Chris Warrick.
5+
# All rights reserved.
6+
#
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions are
9+
# met:
10+
#
11+
# 1. Redistributions of source code must retain the above copyright
12+
# notice, this list of conditions, and the following disclaimer.
13+
#
14+
# 2. Redistributions in binary form must reproduce the above copyright
15+
# notice, this list of conditions, and the following disclaimer in the
16+
# documentation and/or other materials provided with the distribution.
17+
#
18+
# 3. Neither the name of the author of this software nor the names of
19+
# contributors to this software may be used to endorse or promote
20+
# products derived from this software without specific prior written
21+
# consent.
22+
#
23+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
. .pypt/config
35+
36+
case "$LOCALETYPE" in
37+
'gettext')
38+
version=$(cat setup.py | grep 'version=' | sed -e 's/.*version=.//g' -e 's/.,$//g')
39+
date=$(date '+%Y-%m-%d')
40+
datel=$(date '+%Y-%m-%d %H:%M%z')
41+
datep=$(date '+%Y%m%d')
42+
43+
xgettext -c ./$PROJECTLC/**/*.py localeprovider.py -o ./messages.pot
44+
45+
sed '1,+17d' ./messages.pot > ./messages.pot.tmp
46+
47+
pot='# '$PROJECT' pot file.
48+
# Copyright © 2015, Chris Warrick.
49+
# This file is distributed under the same license as the '$PROJECT' package.
50+
# Chris Warrick <chris@chriswarrick.com>, 2015.
51+
#
52+
msgid ""
53+
msgstr ""
54+
"Project-Id-Version: #version\\n"
55+
"Report-Msgid-Bugs-To: Chris Warrick <chris@chriswarrick.com>\\n"
56+
"POT-Creation-Date: #datel\\n"
57+
"PO-Revision-Date: #datel\\n"
58+
"Last-Translator: Chris Warrick <chris@chriswarrick.com>\\n"
59+
"Language-Team: Chris Warrick <chris@chriswarrick.com>\\n"
60+
"Language: en\\n"
61+
"MIME-Version: 1.0\\n"
62+
"Content-Type: text/plain; charset=UTF-8\\n"
63+
"Content-Transfer-Encoding: 8bit\\n"'
64+
65+
echo $pot > messages.pot
66+
cat ./messages.pot.tmp >> messages.pot
67+
rm ./messages.pot.tmp
68+
69+
sed "s/#version/$version/g" messages.pot -i
70+
sed "s/#datel/$datel/g" messages.pot -i
71+
72+
for i in ./locale/*; do
73+
language=$(basename $i)
74+
75+
podir="./locale/$language/LC_MESSAGES"
76+
popath="./locale/$language/LC_MESSAGES/$PROJECTLC.po"
77+
sed 's/\"Project-Id-Version: .*/\"Project-Id-Version: '$version'\\n\"/' $popath -i
78+
msgmerge $popath messages.pot -o $popath
79+
fuzzy=$(cat $popath | grep -c '#, fuzzy')
80+
empty=$(cat $popath | pcregrep -cM 'msgstr ""\n$')
81+
if [ $fuzzy != '0' ]; then
82+
echo "WARNING: $fuzzy fuzzy strings in language $language."
83+
fi
84+
85+
if [ $empty != '0' ]; then
86+
echo "WARNING: $empty empty strings in language $language."
87+
fi
88+
89+
msgfmt -o $podir/$PROJECTLC.mo $popath
90+
done
91+
;;
92+
'pyqt4')
93+
pylupdate4 -verbose $PROJECTLC.pro
94+
for i in ./locale/*.ts; do
95+
# pylupdate4 is dumb and mangles encodings
96+
sed -i -e 's|filename="|filename="../|g' -e \
97+
's|&#xe2;&#x80;&#x9c;|“|g' -e 's|&#xe2;&#x80;&#x9d;|”|g' -e \
98+
's|&#xe2;&#x80;&#x98;|‘|g' -e 's|&#xe2;&#x80;&#x99;|’|g' -e \
99+
's|&#xe2;&#x80;&#xa6;|…|g' -e 's|&#xe2;&#x80;&#x93;|–|g' -e \
100+
's|&#xe2;&#x80;&#x94;|—|g' $i
101+
done
102+
lrelease $PROJECTLC.pro
103+
pyrcc4 -py2 $PROJECTLC.qrc -o $PROJECTLC/ui/resources2.py
104+
pyrcc4 -py3 $PROJECTLC.qrc -o $PROJECTLC/ui/resources3.py
105+
;;
106+
'pyside')
107+
pyside-lupdate -verbose $PROJECTLC.pro
108+
for i in ./locale/*.ts; do
109+
# pyside may be dumb, too
110+
sed -i -e 's|filename="|filename="../|g' -e \
111+
's|&#xe2;&#x80;&#x9c;|“|g' -e 's|&#xe2;&#x80;&#x9d;|”|g' -e \
112+
's|&#xe2;&#x80;&#x98;|‘|g' -e 's|&#xe2;&#x80;&#x99;|’|g' -e \
113+
's|&#xe2;&#x80;&#xa6;|…|g' -e 's|&#xe2;&#x80;&#x93;|–|g' -e \
114+
's|&#xe2;&#x80;&#x94;|—|g' $i
115+
done
116+
lrelease $PROJECTLC.pro
117+
pyside-rcc -py2 $PROJECTLC.qrc -o $PROJECTLC/ui/resources2.py
118+
pyside-rcc -py3 $PROJECTLC.qrc -o $PROJECTLC/ui/resources3.py
119+
120+
121+
;;
122+
'none') true ;;
123+
*) echo 'ERROR: unknown locale type.'; false
124+
esac

Diff for: ‎release

+241
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
#!/bin/zsh
2+
# The Release Script
3+
# Part of the Python Project Template.
4+
# Copyright © 2013-2015, Chris Warrick.
5+
# All rights reserved.
6+
#
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions are
9+
# met:
10+
#
11+
# 1. Redistributions of source code must retain the above copyright
12+
# notice, this list of conditions, and the following disclaimer.
13+
#
14+
# 2. Redistributions in binary form must reproduce the above copyright
15+
# notice, this list of conditions, and the following disclaimer in the
16+
# documentation and/or other materials provided with the distribution.
17+
#
18+
# 3. Neither the name of the author of this software nor the names of
19+
# contributors to this software may be used to endorse or promote
20+
# products derived from this software without specific prior written
21+
# consent.
22+
#
23+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
35+
. .pypt/config
36+
function status {
37+
echo $@
38+
}
39+
40+
function warning {
41+
echo 'WARNING: '$@
42+
}
43+
44+
function error {
45+
echo 'ERROR: '$@
46+
}
47+
48+
function cleanup {
49+
rm -rf $PROJECTLC.egg-info **/__pycache__ dist build
50+
}
51+
52+
function cleanup_cmfn {
53+
[[ -e $cmfn ]] && rm $cmfn
54+
[[ -e $cmfn"-commit" ]] && mv $cmfn"-commit" $cmfn2
55+
}
56+
57+
status '*** Kw’s Release Scripts'
58+
59+
branch=$(git rev-parse --abbrev-ref HEAD)
60+
if [[ $? != 0 ]]; then
61+
error 'Cannot fetch the current branch.'
62+
exit 2
63+
fi
64+
65+
echo $branch | grep '^release/' > /dev/null
66+
if [[ $? != 0 ]]; then
67+
error 'Not on a git-flow release branch.'
68+
status 'Run: git flow release start [version number here]'
69+
exit 2
70+
fi
71+
72+
version=$(echo $branch | sed 's|^release/||')
73+
74+
echo $version | grep '^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}$' > /dev/null
75+
76+
if [[ $? != 0 ]]; then
77+
echo $version | grep '^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\-[0-9A-Za-z-]\{1,\}$' > /dev/null
78+
if [[ $? != 0 ]]; then
79+
warning 'version number is not compliant with versioning scheme (Semantic Versioning 2.0)'
80+
echo -n 'Continue? [y/N] '
81+
read vercont
82+
if [[ $vercont == 'y' || $vercont == 'Y' ]]; then
83+
echo 'Continuing.'
84+
else
85+
exit 2
86+
fi
87+
else
88+
status 'NOTICE: pre-release version number in use.'
89+
echo -n 'Continue? [Y/n] '
90+
read vercont
91+
if [[ $vercont == 'n' || $vercont == 'N' ]]; then
92+
exit 2
93+
else
94+
echo 'Continuing.'
95+
fi
96+
fi
97+
fi
98+
99+
# I am creating all the dates at the exact same time.
100+
date=$(date '+%Y-%m-%d')
101+
datel=$(date '+%Y-%m-%d %H:%M%z')
102+
#datep=$(date '+%Y%m%d')
103+
dates=$(date '+%s')
104+
105+
cmfn=$PWD/.git/kwrs-$dates
106+
cmfn2=/tmp/kwrs-commit-$dates
107+
108+
cleanup
109+
cleanup_cmfn
110+
git add -A --ignore-errors .
111+
112+
cat > $cmfn <<EOF
113+
#~ Kw’s Release Scripts
114+
#~ Please write your commit and changelog messages.
115+
#~ You may use reST formatting in the latter.
116+
#~ Please make the first line of your commit message short.
117+
#~ The second line of multi-line commits should be empty.
118+
119+
#~ COMMIT MESSAGE START ~#
120+
#~version~#
121+
#~ COMMIT MESSAGE END ~#
122+
123+
#~ CHANGELOG MESSAGE START ~#
124+
125+
#~ CHANGELOG MESSAGE END ~#
126+
127+
#~~~#
128+
EOF
129+
130+
sed -i "s/#~version~#/v$version: /" $cmfn
131+
git status >> $cmfn
132+
133+
if [[ "$EDITOR" == 'vim' || "$EDITOR" == '/usr/bin/vim' ]]; then
134+
$EDITOR -c 'set filetype=gitcommit' $cmfn
135+
elif [[ $EDITOR == '' ]]; then
136+
vim -c 'set filetype=gitcommit' $cmfn
137+
else
138+
$EDITOR $cmfn
139+
fi
140+
141+
.pypt/commitlog $cmfn $PWD $version
142+
[[ $? != 0 ]] && exit $?
143+
144+
status 'Replacing versions and dates in files...'
145+
sed "s/version=.*/version='$version',/g" setup.py -i
146+
sed "s/release = .*/release = '$version'/g" docs/conf.py -i
147+
sed "s/:Version: .*/:Version: $version/g" docs/**/*.rst -i
148+
sed "s/# $PROJECT v.*/# $PROJECT v$version/" $PROJECTLC/**/*.py -i
149+
sed "s/__version__ = .*/__version__ = '$version'/g" $PROJECTLC/__init__.py -i
150+
sed "s/:Date: .*/:Date: $date/g" docs/*.rst -i
151+
152+
[[ -e PKGBUILD ]] && sed "s/pkgver=.*/pkgver=$version/g" PKGBUILD -i
153+
[[ -e PKGBUILD-git ]] && sed "s/pkgver=.*/pkgver=$version/g" PKGBUILD-git -i
154+
[[ -e PKGBUILD-2 ]] && sed "s/pkgver=.*/pkgver=$version/g" PKGBUILD-2 -i
155+
[[ -e PKGBUILD-2-git ]] && sed "s/pkgver=.*/pkgver=$version/g" PKGBUILD-2-git -i
156+
157+
cp docs/README.rst docs/CHANGELOG.rst docs/CONTRIBUTING.rst .
158+
cp docs/README.rst README
159+
160+
status 'Generating locales...'
161+
./.pypt/localegen
162+
163+
status 'Importing...'
164+
python -c "import $PROJECTLC"
165+
if [[ $? = 1 ]]; then
166+
error "Import failed. Fix your code or don't come back."
167+
exit 1
168+
fi
169+
170+
status 'Running tests...'
171+
./setup.py test
172+
if [[ $? = 1 ]]; then
173+
error "Tests failed. Fix your code or don't come back."
174+
exit 1
175+
fi
176+
177+
status 'Running pre-sdist.hook...'
178+
179+
. .pypt/hooks/pre-sdist.hook
180+
181+
status 'This is the last chance to quit. Hit ^C now if you want to.'
182+
read bailout
183+
184+
./setup.py sdist
185+
twine upload -s dist/$PROJECTLC-$version.tar.gz
186+
187+
status 'Creating AUR packages...'
188+
[[ -e PKGBUILD ]] && md5out=$(md5sum 'dist/'$PROJECTLC'-'$version'.tar.gz'|awk '{print $1}')
189+
sed "s/md5sums=.*/md5sums=('$md5out')/" PKGBUILD -i
190+
[[ -e PKGBUILD-2 ]] && sed "s/md5sums=.*/md5sums=('$md5out')/" PKGBUILD-2 -i
191+
192+
if [[ $AURTYPE != "none" ]]; then
193+
rm -rf MKPKGBUILD
194+
mkdir MKPKGBUILD
195+
cd MKPKGBUILD
196+
197+
case "$AURTYPE" in
198+
"app")
199+
mkdir $AURNAME{,-git}
200+
cp ../PKGBUILD ./$AURNAME
201+
cp ../PKGBUILD-git ./$AURNAME"-git/PKGBUILD"
202+
for d in $AURNAME $AURNAME"-git"; do
203+
cd $d
204+
makepkg --source
205+
mv *.src.tar.gz ..
206+
cd ..
207+
done
208+
;;
209+
"python")
210+
mkdir python{,2}'-'$PROJECTLC{,-git}
211+
cp ../PKGBUILD ./python-$PROJECTLC
212+
cp ../PKGBUILD-git ./python-$PROJECTLC"-git/PKGBUILD"
213+
cp ../PKGBUILD-2 ./python2-$PROJECTLC/PKGBUILD
214+
cp ../PKGBUILD-2-git ./python2-$PROJECTLC"-git/PKGBUILD"
215+
for d in python-$PROJECTLC python-$PROJECTLC"-git" python2-$PROJECTLC python2-$PROJECTLC"-git"; do
216+
cd $d
217+
makepkg --source
218+
mv *.src.tar.gz ..
219+
cd ..
220+
done
221+
;;
222+
*) warning 'incorrect $AURTYPE value.'
223+
esac
224+
../.pypt/aursend *.src.tar.gz
225+
cd ..
226+
rm -rf MKPKGBUILD
227+
fi
228+
229+
cleanup
230+
231+
git add -A --ignore-errors .
232+
233+
git commit -asF $cmfn"commit"
234+
235+
cleanup_cmfn
236+
237+
git flow release finish $version
238+
git push
239+
git push --tags
240+
241+
status "Done!"

0 commit comments

Comments
 (0)
Please sign in to comment.