Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some structure for package installation #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
formula/COMMIT_INFO.txt export-subst
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/
doc/_build/
*.pyc
dist/
30 changes: 30 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2005-2011, nipy developers
All rights reserved.

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

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

* 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.

* Neither the name of the nipy developers nor the names of any
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

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.
7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include AUTHOR COPYING Makefile* MANIFEST.in setup* README.*
include Changelog TODO
recursive-include doc *
# put this stuff back into setup.py (package_data) once I'm enlightened
# enough to accomplish this herculean task
recursive-include formula/data *
include formula/COMMIT_INFO.txt
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
PYTHON = python
COVERAGE_REPORT=coverage

clean:
$(MAKE) -C doc clean
-rm -rf build
-rm *-stamp

distclean: clean
-rm MANIFEST
-rm $(COVERAGE_REPORT)
@find . -name '*.py[co]' \
-o -name '*.a' \
-o -name '*,cover' \
-o -name '.coverage' \
-o -iname '*~' \
-o -iname '*.kcache' \
-o -iname '*.pstats' \
-o -iname '*.prof' \
-o -iname '#*#' | xargs -L10 rm -f

# Print out info for possible install methods
check-version-info:
$(PYTHON) -c 'from nisext.testers import info_from_here; info_from_here("formula")'

# Run tests from installed code
installed-tests:
$(PYTHON) -c 'from nisext.testers import tests_installed; tests_installed("formula")'

# Run tests from installed code
sdist-tests:
$(PYTHON) -c 'from nisext.testers import sdist_tests; sdist_tests("formula")'

bdist-egg-tests:
$(PYTHON) -c 'from nisext.testers import bdist_egg_tests; bdist_egg_tests("formula")'

source-release: distclean
python -m compileall .
make distclean
python setup.py sdist --formats=gztar,zip
46 changes: 46 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
=======
Formula
=======

This package contains an implementation of symbolic statistical models in
Python.

The implementation is of a full algebra of factors and numerical variables in
statistical models.

It has some similarities to model formulae in R, but differs in that the rules
for the creation of design matrices are more completely defined by the model
algebra.

An earlier version of this package is in nipy_.

Mailing Lists
=============

Please see the developer's list here::

http://mail.scipy.org/mailman/listinfo/nipy-devel

Code
====

You can find our sources and single-click downloads:

* `Main repository`_ on Github.
* Documentation_ for all releases and current development tree.
* Download as a tar/zip file the `current trunk`_.
* Downloads of all `available releases`_.

.. _nipy: http://nipy.org
.. _main repository: http://github.com/jonathan-taylor/formula
.. _documentation: http://github.com/jonathan-taylor/formula
.. _current trunk: http://github.com/jonathan-taylor/formula/archives/master
.. _available releases: http://github.com/jonathan-taylor/formula/downloads

License
=======

formula is licensed under the terms of the BSD license. Please the COPYING file
in the formula distribution.

.. vim:syntax=rst
6 changes: 6 additions & 0 deletions formula/COMMIT_INFO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This is an ini file that may contain information about the code state
[commit hash]
# The line below may contain a valid hash if it has been substituted during 'git archive'
archive_subst_hash=$Format:%h$
# This line may be modified by the install process
install_hash=
7 changes: 7 additions & 0 deletions formula/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Init for formula
import os

from .info import __version__, long_description as __doc__

from .pkg_info import get_pkg_info as _get_pkg_info
get_info = lambda : _get_pkg_info(os.path.dirname(__file__))
88 changes: 62 additions & 26 deletions formula/info.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
""" This file contains defines parameters for nipy that we use to fill
settings in setup.py, the nipy top-level docstring, and for building the
docs. In setup.py in particular, we exec this file, so it cannot import nipy
""" This file contains defines parameters for formula that we use to fill
settings in setup.py, the formula top-level docstring, and for building the
docs. In setup.py in particular, we exec this file, so it cannot import formula
"""

# nipy version information. An empty _version_extra corresponds to a
# formula version information. An empty _version_extra corresponds to a
# full release. '.dev' as a _version_extra string means this is a development
# version
_version_major = 0
_version_minor = 0
_version_micro = 1
_version_minor = 1
_version_micro = 0
_version_extra = '.dev'
# _version_extra = ''

# Format expected by setup.py and doc/source/conf.py: string of form "X.Y.Z"
__version__ = "%s.%s.%s%s" % (_version_major,
Expand All @@ -25,45 +26,80 @@
"Programming Language :: Python",
"Topic :: Scientific/Engineering"]

description = 'A package to build design matrices for regression models'
description = 'Symbolic statistical formulae'

# Note: this long_description is actually a copy/paste from the top-level
# README.txt, so that it shows up nicely on PyPI. So please remember to edit
# it only in one place and sync it correctly.
long_description = \
"""
long_description = """
=======
Formula
=======

Formula is a python project for building
design matrices for regression models.
This package contains an implementation of symbolic statistical models in
Python.

The implementation is of a full algebra of factors and numerical variables in
statistical models.

It has some similarities to model formulae in R, but differs in that the rules
for the creation of design matrices are more completely defined by the model
algebra.

An earlier version of this package is in nipy_.

Mailing Lists
=============

Please see the developer's list here::

http://mail.scipy.org/mailman/listinfo/nipy-devel

Code
====

You can find our sources and single-click downloads:

* `Main repository`_ on Github.
* Documentation_ for all releases and current development tree.
* Download as a tar/zip file the `current trunk`_.
* Downloads of all `available releases`_.

.. _nipy: http://nipy.org
.. _main repository: http://github.com/jonathan-taylor/formula
.. _documentation: http://github.com/jonathan-taylor/formula
.. _current trunk: http://github.com/jonathan-taylor/formula/archives/master
.. _available releases: http://github.com/jonathan-taylor/formula/downloads

License
=======

formula is licensed under the terms of the BSD license. Please the COPYING file
in the formula distribution.
"""

# versions for dependencies
NUMPY_MIN_VERSION='1.2'
SYMPY_MIN_VERSION='0.7.0'

# Main setup parameters
NAME = 'formula'
MAINTAINER = "formula developers"
MAINTAINER_EMAIL = ""
MAINTAINER = "Jonathan Taylor"
MAINTAINER_EMAIL = "[email protected]"
DESCRIPTION = description
LONG_DESCRIPTION = long_description
URL = ""
DOWNLOAD_URL = ""
URL = "http://github.com/jonathan-taylor/formula"
DOWNLOAD_URL = "http://github.com/jonathan-taylor/formula/downloads"
LICENSE = "BSD license"
CLASSIFIERS = CLASSIFIERS
AUTHOR = "formula developers"
AUTHOR_EMAIL = ""
AUTHOR = "Jonathan Taylor"
AUTHOR_EMAIL = "[email protected]"
PLATFORMS = "OS Independent"
MAJOR = _version_major
MINOR = _version_minor
MICRO = _version_micro
ISRELEASE = _version_extra == ''
VERSION = __version__
REQUIRES = ["numpy", "sympy"]
STATUS = 'alpha'

# versions
NUMPY_MIN_VERSION='1.3'
SYMPY_MIN_VERSION = '0.6.7'



PROVIDES = ["formula"]
REQUIRES = ["numpy (>=%s)" % NUMPY_MIN_VERSION,
"sympy (>=%s)" % SYMPY_MIN_VERSION]
83 changes: 83 additions & 0 deletions formula/pkg_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import os
import sys
import subprocess
from ConfigParser import ConfigParser

COMMIT_INFO_FNAME = 'COMMIT_INFO.txt'

def pkg_commit_hash(pkg_path):
''' Get short form of commit hash given directory `pkg_path`

There should be a file called 'COMMIT_INFO.txt' in `pkg_path`. This is a
file in INI file format, with at least one section: ``commit hash``, and two
variables ``archive_subst_hash`` and ``install_hash``. The first has a
substitution pattern in it which may have been filled by the execution of
``git archive`` if this is an archive generated that way. The second is
filled in by the installation, if the installation is from a git archive.

We get the commit hash from (in order of preference):

* A substituted value in ``archive_subst_hash``
* A written commit hash value in ``install_hash`
* git's output, if we are in a git repository

If all these fail, we return a not-found placeholder tuple

Parameters
----------
pkg_path : str
directory containing package

Returns
-------
hash_from : str
Where we got the hash from - description
hash_str : str
short form of hash
'''
# Try and get commit from written commit text file
pth = os.path.join(pkg_path, COMMIT_INFO_FNAME)
if not os.path.isfile(pth):
raise IOError('Missing commit info file %s' % pth)
cfg_parser = ConfigParser()
cfg_parser.read(pth)
archive_subst = cfg_parser.get('commit hash', 'archive_subst_hash')
if not archive_subst.startswith('$Format'): # it has been substituted
return 'archive substitution', archive_subst
install_subst = cfg_parser.get('commit hash', 'install_hash')
if install_subst != '':
return 'installation', install_subst
# maybe we are in a repository
proc = subprocess.Popen('git rev-parse --short HEAD',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=pkg_path, shell=True)
repo_commit, _ = proc.communicate()
if repo_commit:
return 'repository', repo_commit.strip()
return '(none found)', '<not found>'


def get_pkg_info(pkg_path):
''' Return dict describing the context of this package

Parameters
----------
pkg_path : str
path containing __init__.py for package

Returns
-------
context : dict
with named parameters of interest
'''
src, hsh = pkg_commit_hash(pkg_path)
import numpy
return dict(
pkg_path=pkg_path,
commit_source=src,
commit_hash=hsh,
sys_version=sys.version,
sys_executable=sys.executable,
sys_platform=sys.platform,
np_version=numpy.__version__)
1 change: 1 addition & 0 deletions formula/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Make tests a package
28 changes: 28 additions & 0 deletions nisext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# init for sext package
""" Setuptools extensions that can be shared across projects

Typical use for these routines is as a git subtree merge

For example::

# Add a remote pointing to repository
git remote add nisext git://github.com/nipy/nisext.git
git fetch nisext
# Label nisext history as merged
git merge -s ours --no-commit nisext/master
# Read nisext contents as nisext subdirectory
git read-tree --prefix=nisext/ -u nisext/master
git commit -m "Merge nisext project as subtree"

Then you would typically add a makefile target like::

# Update nisext subtree from remote
update-nisext:
git fetch nisext
git merge --squash -s subtree --no-commit nisext/master

and commit when you have changes you want. This allows you to keep the nisext
tree updated from the upstream repository, but the tree will be there and ready
for someone without this machinery or remote.
"""

Loading