Skip to content

Commit

Permalink
test suite fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bubenkoff committed Mar 17, 2015
1 parent a6e9bf4 commit 66f475b
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 212 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,7 +2,8 @@
.idea
/*.sublime-workspace
.codeintel

/.env
/.eggs
# C extensions
*.so

Expand Down
6 changes: 6 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,12 @@
Changelog
=========

0.3.0 (2015-03-17)
------------------

- Support recent pip (ridha)


0.2.0 (2014-02-06)
------------------

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Expand Up @@ -3,3 +3,4 @@ Contributors

Anatoly Bubenkov <bubenkoff@gmail.com>, Author

Abdul Kader Maliyakkal <ridha@github.com>, Contributor
20 changes: 20 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,20 @@
Copyright (c) Anatoly Bubenkov and others

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 changes: 11 additions & 0 deletions Makefile
@@ -0,0 +1,11 @@
# create virtual environment
.env:
virtualenv .env

# install all needed for development
develop: .env
.env/bin/pip install -e . -r requirements-testing.txt tox

# clean the development envrironment
clean:
-rm -rf .env
150 changes: 149 additions & 1 deletion README.rst
Expand Up @@ -12,5 +12,153 @@ and buildout for same project independently
:target: https://coveralls.io/r/collective/collective.recipe.pip


See `Doc tests <https://github.com/collective/collective.recipe.pip/blob/master/collective/recipe/pip/README.rst>`_.
Overview
========

This recipe allows to parse pip configuration files (usually named requirements.txt) into just list of the eggs to use
in other parts of the buildout.

The recipe mirrors the parsed eggs list into its section, so that e.g.
``${pip:eggs}`` will give the list of parsed eggs.

The list of eggs which come from urls (eg from github) are also exported to the urls param:
``${pip:urls}`` will give the list of parsed egg urls.


For now single option of the recipe is ``configs`` - list of config files to parse.

The config files are parsed during the initialization of the ``Recipe`` instance,
i.e. after ``buildout.cfg`` is read but before any recipe is installed or updated.


Example usage: Use an environment variable
==========================================

Let's create test config files

>>> write('requirements.txt',
... """
... some.egg
... -e http://some.package.git.url#egg=develop.egg
... --use-wheel
... http://sourceforge.net/projects/pychecker/files/latest/download?source=files#egg=pychecker==0.8.19
... fabric>=0.9b1
... # some comment
... xlrd # reading excel worksheets
... html5lib==0.95
... """)

>>> write('requirements-included.txt',
... """
... some.included.egg
... """)

>>> write('requirements-included2.txt',
... """
... some.included.egg2
... """)

>>> mkdir('file.package')
>>> write('file.package/setup.py',
... """
... from setuptools import setup
... setup(name='file.package')
... """)

>>> write('requirements2.txt',
... """
... -r requirements-included.txt
... --requirement requirements-included2.txt
... some2.egg
... django>=1.3,<1.4
... django-extensions #django extension requirements (not mandatory, but useful on dev)
... -e http://some2.package.git.url#egg=develop2.egg
... -e file.package
... --extra-index-url=http://some.index.url
... -f http://git.fabfile.org
... """)


We'll start by creating a buildout that uses the recipe::

>>> write('buildout.cfg',
... r"""
... [buildout]
... parts = pip print
...
... [some-section]
... eggs = ${pip:eggs}
...
... [pip]
... recipe = collective.recipe.pip
... configs = requirements.txt
... requirements2.txt
... versions = versions
...
... [versions]
...
... [print]
... recipe = mr.scripty
... install =
... ... print(self.buildout['some-section']['eggs'])
... ... print('\n[versions]')
... ... print('\n'.join(i + ' = ' + k for i, k in sorted(self.buildout['versions'].items())))
... ... print('\n[urls]')
... ... print(self.buildout['pip']['urls'])
... ... print('# done')
... ... return []
... """)

The `mr.scripty` recipe is used to print out the value of the ${some-section:some-option}
option.

Running the buildout gives us::

>>> import sys
>>> sys.stdout.write('start\n' + system(buildout))
start...
Installing pip.
Installing print.
develop.egg
develop2.egg
django-extensions
django>=1.3,<1.4
fabric>=0.9b1
html5lib==0.95
pychecker==0.8.19
some.egg
some.included.egg
some.included.egg2
some2.egg
xlrd
[versions]
django = >=1.3,<1.4
fabric = >=0.9b1
html5lib = 0.95
pychecker = 0.8.19
zc.buildout = ...
zc.recipe.egg = ...
[urls]
/sample-buildout/file.package
git+http://some.package.git.url#egg=develop.egg
git+http://some2.package.git.url#egg=develop2.egg
http://sourceforge.net/projects/pychecker/files/latest/download?source=files#egg=pychecker==0.8.19
...


Contact
-------

If you have questions, bug reports, suggestions, etc. please create an issue on
the `GitHub project page <http://github.com/collective/collective.recipe.pip>`_.


License
-------

This software is licensed under the `MIT license <http://en.wikipedia.org/wiki/MIT_License>`_

See `License file <https://github.com/collective/collective.recipe.pip/blob/master/LICENSE.txt>`_


© 2013 Anatoly Bubenkov and others.
83 changes: 51 additions & 32 deletions bootstrap.py
Expand Up @@ -35,7 +35,7 @@
Simply run this script in a directory containing a buildout.cfg, using the
Python that you want bin/buildout to use.
Note that by using --find-links to point to local resources, you can keep
Note that by using --find-links to point to local resources, you can keep
this script from going over the network.
'''

Expand All @@ -56,39 +56,54 @@
"file to be used."))
parser.add_option("-f", "--find-links",
help=("Specify a URL to search for buildout releases"))
parser.add_option("--allow-site-packages",
action="store_true", default=False,
help=("Let bootstrap.py use existing site packages"))
parser.add_option("--setuptools-version",
help="use a specific setuptools version")


options, args = parser.parse_args()

######################################################################
# load/install setuptools

to_reload = False
try:
import pkg_resources
import setuptools
if options.allow_site_packages:
import setuptools
import pkg_resources
from urllib.request import urlopen
except ImportError:
ez = {}

try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen

# XXX use a more permanent ez_setup.py URL when available.
exec(urlopen('https://bitbucket.org/pypa/setuptools/raw/0.7.2/ez_setup.py'
).read(), ez)
setup_args = dict(to_dir=tmpeggs, download_delay=0)
ez['use_setuptools'](**setup_args)

if to_reload:
reload(pkg_resources)
import pkg_resources
# This does not (always?) update the default working set. We will
# do it.
for path in sys.path:
if path not in pkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)
from urllib2 import urlopen

ez = {}
exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)

if not options.allow_site_packages:
# ez_setup imports site, which adds site packages
# this will remove them from the path to ensure that incompatible versions
# of setuptools are not in the path
import site
# inside a virtualenv, there is no 'getsitepackages'.
# We can't remove these reliably
if hasattr(site, 'getsitepackages'):
for sitepackage_path in site.getsitepackages():
sys.path[:] = [x for x in sys.path if sitepackage_path not in x]

setup_args = dict(to_dir=tmpeggs, download_delay=0)

if options.setuptools_version is not None:
setup_args['version'] = options.setuptools_version

ez['use_setuptools'](**setup_args)
import setuptools
import pkg_resources

# This does not (always?) update the default working set. We will
# do it.
for path in sys.path:
if path not in pkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)

######################################################################
# Install buildout
Expand Down Expand Up @@ -119,10 +134,15 @@
_final_parts = '*final-', '*final'

def _final_version(parsed_version):
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
return False
return True
try:
return not parsed_version.is_prerelease
except AttributeError:
# Older setuptools
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
return False
return True

index = setuptools.package_index.PackageIndex(
search_path=[setuptools_path])
if find_links:
Expand All @@ -149,8 +169,7 @@ def _final_version(parsed_version):
import subprocess
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
raise Exception(
"Failed to execute command:\n%s",
repr(cmd)[1:-1])
"Failed to execute command:\n%s" % repr(cmd)[1:-1])

######################################################################
# Import and run buildout
Expand All @@ -167,4 +186,4 @@ def _final_version(parsed_version):
args[0:0] = ['-c', options.config_file]

zc.buildout.buildout.main(args)
shutil.rmtree(tmpeggs)
shutil.rmtree(tmpeggs)

0 comments on commit 66f475b

Please sign in to comment.