Skip to content

Commit

Permalink
Convert dist to use package-py
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Sep 12, 2010
1 parent 59bccc3 commit 93f0d0a
Show file tree
Hide file tree
Showing 11 changed files with 420 additions and 91 deletions.
3 changes: 3 additions & 0 deletions CHANGES.yaml
@@ -0,0 +1,3 @@
- version: 0.0.1
date: Sat Sep 11 21:03:16 PDT 2010
changes: Initial version.
28 changes: 28 additions & 0 deletions LICENSE
@@ -0,0 +1,28 @@
Copyright (c) 2010, Ingy dot Net
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.

THIS SOFTWARE IS PROVIDED BY Ingy dot Net 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 Ingy dot Net 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.

The views and conclusions contained in the software and documentation
are those of the authors and should not be interpreted as representing
official policies, either expressed or implied, of Ingy dot Net.
6 changes: 6 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,6 @@
include CHANGES.yaml
include LICENSE
include Makefile
include README.rst
include package/*
include tests/*
167 changes: 159 additions & 8 deletions Makefile
@@ -1,22 +1,173 @@
.PHONY: default build test devtest install register sdist clean upload run
#-----------------------------------------------------------------------------#
#
# Greetings!
#
# This Makefile was generated by `package`, the Python package package
# package. If you don't know what that means, that's OK. This Makefile is
# mostly for the "author" of this package. If you are not the author you can
# ignore this file, or you can use it to call the setup.py commands that you
# are used to:
#
# * make build
# * make test
# * sudo make install
#
# If you are the module author, you can run `make help` to see all the
# commands that are available to you.
#
# This Makefile currently assumes that, if you are the package author, you are
# on some kind of Unix based system.
#
# For more information on the Python package package package, `package`, visit
# the Python Package Index here:
#
# http://pypi.python.org/pypi/package/
#
# Cheers!
#
#-----------------------------------------------------------------------------#

.PHONY: \
help \
setup \
info \
build \
test \
tests \
devtest \
install \
register \
sdist \
clean \
purge \
upload \


# This variable is hardcoded into the Makefile by initial setup.
# If you move package-py, you need to change this.
PACKAGE_BASE = ../package-py

PYTHON = python


YOUR_PACKAGE = your-package/__init__.py

LAYOUT_FILES = \
setup.py \
README.rst \
LICENSE \
CHANGES.yaml \
MANIFEST.in \

PACKAGE_FILES = \
info.yaml \
__init__.py \
errors.py \
unittest.py \

TESTS_FILES = \
test_import.py \


SETUP_TARGETS = \
Makefile \
$(YOUR_PACKAGE) \
$(LAYOUT_FILES) \
$(PACKAGE_FILES) \
$(TESTS_FILES) \

UPGRADE_TARGETS = \
Makefile \
setup.py \
MANIFEST.in \
__init__.py \
errors.py \
unittest.py \

ALL_TESTS = $(shell echo tests/*.py)
ALL_DEV_TESTS = $(shell echo dev-tests/*.py)

default: build
#-----------------------------------------------------------------------------#
# package-py targets
#-----------------------------------------------------------------------------#
help::
@echo "This is the package (Python package package package) Makefile."
@echo ""
@echo "With this Makefile, you can use the following targets:"
@echo ""
@echo "* setup - Set up a new project with default (package-py) files"
@echo "* info - Update package.info from package/info.yaml"
@echo "* upgrade - Pull in updated files from package-py"
@echo ""
@echo "These targets are simply run by your setup.py:"
@echo ""
@echo "* build - Compile the Python modules"
@echo "* test - Run the unittests"
@echo "* devtest - Run the "developer only" tests"
@echo "* register - Register this package to PyPi"
@echo "* sdist - Create a dist bundle file"
@echo "* upload - Create the dist bundle and upload it to PyPi"
@echo "* clean - Remove the various generated files"

# This rule is disabled after initial setup.
setup:: _setup $(SETUP_TARGETS) _fixup _next

_setup::
@if [ -e "package/base" ]; then echo "Don't `make setup` here!!!"; exit 1; fi
@if [ -e "package" ]; then echo "Can't setup if 'package' directory exists."; exit 1; else mkdir package; fi
@if [ ! -e "tests" ]; then mkdir tests; fi

info::
$(PYTHON) $(PACKAGE_BASE)/bin/make_package_info.py

upgrade:: _upgrade $(UPGRADE_TARGETS) _fixup info

_upgrade::
@if [ -e "Makefile.mk" ]; then echo "Don't `make upgrade` here!!!"; exit 1; fi
@if [ "$(MAKEFILE_LIST:%=%)" == "Makefile" ]; then echo 'run instead: make -f $(PACKAGE_BASE)/Makefile.mk upgrade'; exit 1; fi

_fixup::
$(PYTHON) $(PACKAGE_BASE)/bin/fix_makefile.py "$(PACKAGE_BASE)"

_next::
@cat $(PACKAGE_BASE)/help/next.txt

Makefile::
cp $(PACKAGE_BASE)/$@.mk $@

$(YOUR_PACKAGE)::
mkdir your-package
cp $(PACKAGE_BASE)/layout/$@ $@

$(PACKAGE_FILES)::
cp $(PACKAGE_BASE)/layout/package/$@ package/$@

$(LAYOUT_FILES)::
if [ ! -e $@ ]; then cp $(PACKAGE_BASE)/layout/$@ $@; fi

$(TESTS_FILES)::
if [ ! -e tests/$@ ]; then cp $(PACKAGE_BASE)/layout/tests/$@ tests/$@; fi


#-----------------------------------------------------------------------------#
# setup.py targets
#-----------------------------------------------------------------------------#
register:: info

build test devtest install register sdist clean::
python setup.py $@
$(PYTHON) setup.py $@

upload:: clean register
python setup.py sdist $@
$(PYTHON) setup.py sdist $@

tests:: $(ALL_TESTS)

$(ALL_TESTS) $(ALL_DEV_TESTS): run
@python -c 'print " Running test: $@ ".center(70, "-") + "\n"'
@PYTHONPATH=. python $@
$(ALL_TESTS) $(ALL_DEV_TESTS):
@$(PYTHON) -c 'print " Running test: $@ ".center(70, "-") + "\n"'
@PYTHONPATH=. $(PYTHON) $@

clean::
find . -name '*.pyc' | xargs rm
rm -fr build dist MANIFEST
rm -fr build dist MANIFEST *.egg-info

purge:: clean
73 changes: 73 additions & 0 deletions package/__init__.py
@@ -0,0 +1,73 @@
"""\
package - The Python package package package
"""

import os, sys, glob
from distutils.core import Command

__version__ = '0.0.9'

has_setuptools = False

from package.errors import *

try:
from setuptools import setup as real_setup
has_setuptools = True
except ImportError, err:
try:
from distutils.core import setup as real_setup
except ImportError, err:
die(ENOSETUP)

class setup():
def __init__(self):
args = self.get_args()
self.check_args(args)
real_setup(**args)

def get_args(self):
try:
import package.info
except ImportError, err:
die(ENOINFO)

args = package.info.get()
args['cmdclass'] = {
'test': Test,
'devtest': DevTest,
}
return args

def check_args(self, args):
if args.get('install_requires') and 'install' in sys.argv:
if not has_setuptools:
die(ENOSETUPTOOLS)


class Test(Command):
user_options = []
test_dir = 'tests'

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
build_cmd = self.get_finalized_command('build')
build_cmd.run()
sys.path.insert(0, build_cmd.build_lib)
sys.path.insert(0, self.test_dir)
def exit(code):
pass
sys.exit = exit

for test in glob.glob(self.test_dir + '/test_*.py'):
name = test[test.index('/') + 1: test.rindex('.')]
module = __import__(name)
module.main(module=module, argv=[''])

class DevTest(Test):
test_dir = 'dev-tests'
68 changes: 68 additions & 0 deletions package/errors.py
@@ -0,0 +1,68 @@
"""\
This module provides package management support stuff.
"""

import sys

ENONAME = """
The 'name' entry is required in your `info.yaml` file.
"""

ENOSETUP = """
For some bizarre reason, I cannot locate your Python 'setuptools' or
'distutils' packages. Paint me pathetic, but I just cannot go on at this
point.
"""

ENOINFO = """
I can't find the 'package.info' module. If you are the author of this package,
please run this command:
make package-info
If you are simply some dude installing this Python package, please contact the
author about the missing 'package.info' module.
"""

ENOYAML = """
You need to install pyyaml to use the package-py framework as a package author.
"""

ENOHOMEINFO = """
You need to have a file called $HOME/.package-py/info.yaml. This is where you
put the default info that applies to all your packages.
Just copy ./package/info.yaml to that name and edit it.
"""

ENOLOCALINFO = """
Strange. I can't find the file called ./package/info.yaml. Did you delete it?
"""

ELOCALINFONOTSET = """
It seems like you haven't edited the ./package/info.yaml file yet. You need to
put all the pertinent information in there in order to proceed.
"""

ENOSETUPTOOLS = """
The package you are trying to install depends on an installation feature that
requires the 'setuptools' Python module, but you do not have that module
installed. You will need to install 'setuptools' before proceeding with this
install.
You can find setuptools here:
http://pypi.python.org/pypi/setuptools/
"""

def die(msg):
sys.stderr.write(msg)
sys.exit(1)
22 changes: 22 additions & 0 deletions package/info.py
@@ -0,0 +1,22 @@
def get():
info = {}
info.update(
{ 'author': 'Ingy dot Net',
'author_email': 'ingy@ingy.net',
'classifiers': [ 'Development Status :: 2 - Pre-Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python',
'Topic :: Software Development',
'Topic :: System :: Software Distribution'],
'description': 'TestML -- An Acmeist Unit Testing Framework',
'install_requires': ['pyyaml'],
'long_description': 'The Python implementation of TestML.\n',
'name': 'testml',
'packages': ['testml', 'testml.parser', 'testml.runner'],
'scripts': [],
'url': 'http://www.testml.org/',
'version': '0.1'}
)
return info

0 comments on commit 93f0d0a

Please sign in to comment.