Skip to content

Commit

Permalink
add Python Project Template
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 29, 2015
1 parent 2e8e0db commit 79f8d46
Show file tree
Hide file tree
Showing 8 changed files with 831 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .pypt/LICENSE.PyPT
@@ -0,0 +1,55 @@
Python Project Template is licensed under a BSD-like license. You are free to
relicense your code to another open source license. If you want to apply a
commercial (a.k.a. proprietary) license, you must contact me first.

HOWEVER, the following files must remain under the BSD license:

* /.pypt/aursend
* /.pypt/commitlog
* /.pypt/localegen
* /.pypt/README.PyPT
* /.pypt/LICENSE.PyPT
* /docs/CONTRIBUTING.rst
* /CONTRIBUTING.rst
* /release


The README file for PyPT MAY NOT be relicensed.

The actual license is: (the name may have been replaced by yours if you did the
Getting up to speed in 15 easy steps, it was mine originally, and the
version in .pypt/ should reflect that.)

LICENSE
-------

Copyright © 2013-2015, Chris Warrick.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the author of this software nor the names of
contributors to this software may be used to endorse or promote
products derived from this software without specific prior written
consent.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
194 changes: 194 additions & 0 deletions .pypt/README.rst
@@ -0,0 +1,194 @@
===============================================
Python Project Template. INSERT TAGLINE HERE.™
===============================================
:Info: This is the README file for the Python Project Template.
:Author: Chris Warrick <chris@chriswarrick.com>
:Copyright: © 2013-2015, Chris Warrick.
:License: BSD (see /LICENSE or :doc:`Appendix B <LICENSE>`.)
:Date: 2015-01-03
:Version: 1.0.6

.. index: README
.. image:: https://travis-ci.org/Kwpolska/python-project-template.png?branch=master

USING THE TEMPLATE
------------------

Requirements
============

* ``zsh`` installed (required by ``/release`` and ``/.pypt/localegen`` scripts)
* Python with ``requests`` (required by ``/.pypt/{commitlog,aursend}``) and ``twine`` (required by ``/release``) installed
* `git-flow extensions by nvie <https://github.com/nvie/gitflow>`_ (alternatively yo can manually alter the ``/release`` script, and that is much harder than
installing the extensions)
* A git repository. The PyPT is ready to go if you use GitHub. If you do not
want GitHub, edit the ``/PKGBUILD{,-2}{,-git}`` files and any other places
where GitHub is mentioned, including this document which you should edit
mentally.

Recommended possessions
=======================

* Travis CI account (if you do not want Travis CI, remove ``/.travis.yml``)
* AUR account (if you do not want AUR uploads, remove the
``/PKGBUILD{,-2}{,-git}`` files and modify the ``/.pypt/config`` file)

Contents
========

The template contains the following files to get you started:

* pre-configured Sphinx with:

* ``CONTRIBUTING.rst`` guide (used by GitHub when sending a pull request or an issue)
* ``LICENSE.rst``
* an empty ``CHANGELOG.rst``
* this (worthless for most people) ``README.rst`` and a bare-bones ``index.rst`` page

* The exact same files in ``/``, which are fragile and **MAY NOT** be modified
as they are replaced with copies in ``/docs`` by the ``release``
script
* ``__init__.py`` and ``template.py`` files in the Python package directory
* A good-enough ``setup.py`` file
* ``tests.py`` containing some *Is My Python Sane?*-style tests
* A sample ``/usr/bin/`` script
* Addons for Qt users
* PKGBUILDs for the Arch Linux User Repository (AUR)
* A state-of-the-art ``release`` script, the operations of which are:

* querying the current branch for version number
* updating ``/docs/CHANGELOG.rst``
* bumping the version number in all the files, changing dates where necessary
* copying over ``/docs/README.rst``, ``/docs/CHANGELOG.rst`` and ``/docs/CONTRIBUTING.rst`` to ``/``
* locale generation (via the ``.pypt/localegen`` script)
* running ``import $project`` and the testsuite
* creating and uploading AUR packages
* committing into git, finishing the ``git flow`` release


Getting up to speed in 15 easy steps
====================================

1. Create the repository for the project on GitHub and enable it on Travis CI.
2. Manually change ``Kwpolska`` to your GitHub name in the following files:

1. ``/docs/README.rst``, line 10
2. ``/docs/CHANGELOG.rst``, line 10
3. ``/setup.py``, line 14
4. ``/PKGBUILD{,-2}{,-git}``, in ``url`` and ``source`` (git only)

3. Manually change the ``Maintainer`` line in ``/PKGBUILD{,-2}{,-git}``.
4. Replace the following patterns (eg. with sed), in all files, **excluding
dotfiles**:

1. ``TEMPLATE`` with the full name of the project
2. ``tEmplate`` with a “light” name of the project [a-z0-9\_\\-], which will
be used in the PyPI, AUR, and a few other places. You can use capital
letters if you feel like it, but it is discouraged and was not tested.
3. ``python-project-template`` with the GitHub repo name
4. ``INSERT TAGLINE HERE.`` with a tagline of your choice
5. ``chris@chriswarrick.com`` with your e-mail address
6. ``Kwpolska`` and/or ``Chris Warrick`` with your name (affects mostly copyright notices)

WARNING: some files are in the copyright of Chris Warrick and must stay this
way! They are listed in the license, please keep my name there, otherwise
you risk breaking the law.

Also, if ``len(computer_friendly_name) != len('tEmplate')``, you may want to
change the amount of tildes in docstrings of Python files.

4. Rename ``/tEmplate`` to the name used in 4.2.
5. Modify ``/docs/README.rst`` to reflect your project and not the Template
(and make a copy if you are reading it locally from those files)
6. Copy: (when using the included ``release`` script, it happens automatically)

1. ``/docs/README.rst`` to ``/README.rst`` and ``/README``
2. ``/docs/CHANGELOG.rst`` to ``/CHANGELOG.rst``

7. Modify ``/.pypt/config``
8. Modify ``/bin/tEmplate`` and rename it OR remove the directory
9. Customize ``/setup.py`` to your liking. You should pay attention to the
classifiers and the commented parts.
10. Customize requirements.txt.
11. If you are using PyQt4 or PySide, make sure to put your UI code in a ``ui``
submodule. Copy over the ``/QT-ADDONS/resources.py`` file to that
submodule, even if you are not using resources now.
12. Remove the ``/QT-ADDONS/`` directory.
13. If you are using Qt, make sure to create a ``.pro`` file with your sources
and locales.
14. Read the COPYRIGHT section below (or ``LICENSE.PyPT``) and remove
``/LICENSE.PyPT`` and ``/README.PyPT``. If you believe the BSD license presented by the
``/LICENSE`` file is not the license you want, here is a list of files you
should modify:

1. ``/tests.py``
2. Everything in the Python package directory (twice in many cases)
3. Everything in ``/docs``
4. ``/LICENSE``, which is **not** equivalent to ``/docs/LICENSE.rst``

PS. GNU GPL is not a good idea. You can use it, but the world would be
much happier if you did not.

15. Remove ``/.git``, and run the following commands, replacing stuff with ``$``
in front::

git init
git remote add origin git@github.com:$GITUSERNAME/$GITREPO
git flow init #(change version tag prefix to `v`)
git add *
git checkout develop
git commit -sm 'initial commit via @Kwpolska’s Python Project Template'
git checkout master
git merge --ff-only develop
git push -u origin master develop

COPYRIGHT
---------

Python Project Template is licensed under a BSD-like license. You are free to
relicense your code to another open source license. If you want to apply a
commercial (a.k.a. proprietary) license, you must contact me first.

**However, the following files must remain under the BSD license:**

* /.pypt/aursend
* /.pypt/commitlog
* /.pypt/localegen
* /.pypt/README.PyPT
* /.pypt/LICENSE.PyPT
* /docs/CONTRIBUTING.rst
* /CONTRIBUTING.rst
* /release

**This README file MAY NOT be relicensed.**

Copyright © 2013-2015, Chris Warrick.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the author of this software nor the names of
contributors to this software may be used to endorse or promote
products derived from this software without specific prior written
consent.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
117 changes: 117 additions & 0 deletions .pypt/aursend
@@ -0,0 +1,117 @@
#!/usr/bin/python
# -*- encoding: utf-8 -*-
# Kw’s Release Tools/Python Project Template
# AUR Uploader
# Copyright © 2013-2015, Chris Warrick.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the author of this software nor the names of
# contributors to this software may be used to endorse or promote
# products derived from this software without specific prior written
# consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import json
import requests
import getpass
import sys
import tarfile

# This was nicely stolen from PKGBUILDer.
CATEGORIES = ['none', 'none', 'daemons', 'devel', 'editors',
'emulators', 'games', 'gnome', 'i18n', 'kde',
'lib', 'modules', 'multimedia', 'network',
'office', 'science', 'system', 'x11',
'xfce', 'kernels', 'wayland']

AURURL = 'https://aur.archlinux.org/'
SESSION = requests.Session()

if __name__ == '__main__':
if sys.version_info[0] == 2:
input = raw_input

username = input('Username: ')
password = getpass.getpass('Password: ')

r = SESSION.post(AURURL + 'login', data={'user': username,
'passwd': password})
sid = SESSION.cookies['AURSID']

for pkgorder, filename in enumerate(sys.argv[1:]):
thandle = tarfile.open(filename, 'r:gz')
# Warning: this is fragile. However, as part of the PyPT, we know that
# archives built by the release script have a sane order, allowing us
# to drop worthless magic or PKGBUILD parsing.
pkgname = thandle.next().name
thandle.close()

try:
import pkgbuilder.utils
try:
category = pkgbuilder.utils.info(pkgname)[0]._categoryid
except IndexError:
category = None
except ImportError:
# The user does not have PKGBUILDer installed. Because PyPT caters
# to all sorts of audiences and is meant to be portable, I
# copy-pasted PKGBUILDer code down here and used it for the above.
# Note that this uses an info requests, something PKGBUILDer does
# not do since multiinfo requests were implemented upstream.
r = SESSION.get(AURURL + 'rpc.php', params={'type': 'info', 'arg': pkgname})
r.raise_for_status()
pkgdata = json.loads(r.text)
try:
category = pkgdata['results']['CategoryID']
except TypeError:
# The AUR RPC returns an empty list in the 'results' field if
# there is no such package and a dict (aka object) in the
# 'results' field if the package exists.
# Why am I using 'info'?
category = None
# Now that we are done with this procedure, time to upload them.
# But wait: what if the category is `None` Or if the user chose a
# wrong category? ↓ because ERROR is invalid (1-19)
while category not in range(1, len(CATEGORIES)):
catlist = list(enumerate(CATEGORIES[1:], 1))
print('Choose a category for {0}.'.format(pkgname))
formatted = [catlist[i:i + 5] for i in range(0, len(catlist), 5)]
formatted[-1] = formatted[-1] + (5 - len(formatted[-1])) * [('', '')]
# 'multimedia' is 10, and we use this as our width.
for i in formatted:
print('{0[0]:>2}: {0[1]:<10} {1[0]:>2}: {1[1]:<10} {2[0]:>2}'
': {2[1]:<10} {3[0]:>2}: {3[1]:<10} {4[0]:>2}: '
'{4[1]:<10} {5[0]:>2}: {5[1]:<10}'.format(i))

category = input('Category: ')

r = SESSION.post(AURURL + 'submit/',
data={'pkgsubmit': 1, 'token': sid,
'category': category},
files={'pfile': open(filename, 'rb')})
r.raise_for_status()

# Note that I do not perform any sanity checks. There is a reason: I believe
# that PyPT is so awesome and wonderful that it cann— oh wait, stop this
# bullshit. I actually had a little Heisenbug in here and removed a sanity check.

0 comments on commit 79f8d46

Please sign in to comment.