Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.buildout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.buildout
Commits
83d53da5
Commit
83d53da5
authored
Jun 11, 2012
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checkout: core tests passing w python 3.2
parent
493394b7
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
1857 additions
and
1616 deletions
+1857
-1616
bootstrap/bootstrap.py
bootstrap/bootstrap.py
+3
-3
buildout.cfg
buildout.cfg
+1
-1
dev.py
dev.py
+3
-3
src/zc/buildout/__init__.py
src/zc/buildout/__init__.py
+1
-1
src/zc/buildout/allowhosts.txt
src/zc/buildout/allowhosts.txt
+3
-3
src/zc/buildout/bootstrap.txt
src/zc/buildout/bootstrap.txt
+11
-11
src/zc/buildout/buildout.py
src/zc/buildout/buildout.py
+79
-83
src/zc/buildout/buildout.txt
src/zc/buildout/buildout.txt
+87
-85
src/zc/buildout/configparser.py
src/zc/buildout/configparser.py
+164
-0
src/zc/buildout/debugging.txt
src/zc/buildout/debugging.txt
+3
-3
src/zc/buildout/dependencylinks.txt
src/zc/buildout/dependencylinks.txt
+6
-12
src/zc/buildout/download.py
src/zc/buildout/download.py
+11
-10
src/zc/buildout/download.txt
src/zc/buildout/download.txt
+24
-24
src/zc/buildout/downloadcache.txt
src/zc/buildout/downloadcache.txt
+4
-4
src/zc/buildout/easy_install.py
src/zc/buildout/easy_install.py
+17
-13
src/zc/buildout/easy_install.txt
src/zc/buildout/easy_install.txt
+1162
-1156
src/zc/buildout/extends-cache.txt
src/zc/buildout/extends-cache.txt
+25
-25
src/zc/buildout/isolation.txt
src/zc/buildout/isolation.txt
+6
-5
src/zc/buildout/repeatable.txt
src/zc/buildout/repeatable.txt
+12
-8
src/zc/buildout/rmtree.py
src/zc/buildout/rmtree.py
+3
-2
src/zc/buildout/runsetup.txt
src/zc/buildout/runsetup.txt
+3
-2
src/zc/buildout/setup.txt
src/zc/buildout/setup.txt
+3
-3
src/zc/buildout/testing.py
src/zc/buildout/testing.py
+29
-22
src/zc/buildout/testrecipes.py
src/zc/buildout/testrecipes.py
+3
-2
src/zc/buildout/tests.py
src/zc/buildout/tests.py
+179
-124
src/zc/buildout/update.txt
src/zc/buildout/update.txt
+8
-6
src/zc/buildout/windows.txt
src/zc/buildout/windows.txt
+5
-3
zc.recipe.egg_/src/zc/recipe/egg/custom.py
zc.recipe.egg_/src/zc/recipe/egg/custom.py
+2
-2
No files found.
bootstrap/bootstrap.py
View file @
83d53da5
...
...
@@ -18,7 +18,7 @@ The script accepts buildout command-line options, so you can
use the -c option to specify an alternate configuration file.
"""
import
os
,
shutil
,
sys
,
tempfile
,
urllib
2
import
os
,
shutil
,
sys
,
tempfile
,
urllib
.
request
,
urllib
.
error
,
urllib
.
parse
from
optparse
import
OptionParser
tmpeggs
=
tempfile
.
mkdtemp
()
...
...
@@ -80,9 +80,9 @@ try:
raise
ImportError
except
ImportError
:
ez
=
{}
exec
urllib2
.
urlopen
(
exec
(
urllib
.
request
.
urlopen
(
'http://python-distribute.org/distribute_setup.py'
).
read
()
in
ez
).
read
()
,
ez
)
setup_args
=
dict
(
to_dir
=
tmpeggs
,
download_delay
=
0
,
no_fake
=
True
)
ez
[
'use_setuptools'
](
**
setup_args
)
...
...
buildout.cfg
View file @
83d53da5
...
...
@@ -9,7 +9,7 @@ eggs = zc.buildout
interpreter = py
[test]
recipe = zc.recipe.testrunner
recipe = zc.recipe.testrunner
==1.3.0
eggs =
zc.buildout[test]
zc.recipe.egg
...
...
dev.py
View file @
83d53da5
...
...
@@ -17,7 +17,7 @@ This is different from a normal boostrapping process because the
buildout egg itself is installed as a develop egg.
"""
import
os
,
shutil
,
sys
,
subprocess
,
urllib
2
import
os
,
shutil
,
sys
,
subprocess
,
urllib
.
request
,
urllib
.
error
,
urllib
.
parse
for
d
in
'eggs'
,
'develop-eggs'
,
'bin'
,
'parts'
:
if
not
os
.
path
.
exists
(
d
):
...
...
@@ -57,8 +57,8 @@ else:
######################################################################
# Install distribute
ez
=
{}
exec
urllib2
.
urlopen
(
'http://python-distribute.org/distribute_setup.py'
).
read
()
in
ez
exec
(
urllib
.
request
.
urlopen
(
'http://python-distribute.org/distribute_setup.py'
).
read
()
,
ez
)
ez
[
'use_setuptools'
](
to_dir
=
'eggs'
,
download_delay
=
0
)
import
pkg_resources
...
...
src/zc/buildout/__init__.py
View file @
83d53da5
...
...
@@ -19,4 +19,4 @@ class UserError(Exception):
"""
def
__str__
(
self
):
return
" "
.
join
(
map
(
str
,
self
))
return
" "
.
join
(
map
(
str
,
self
.
args
))
src/zc/buildout/allowhosts.txt
View file @
83d53da5
...
...
@@ -55,7 +55,7 @@ local files::
Now we can run the buildout and make sure all attempts to dist.plone.org fails::
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
Develop: '/sample-buildout/allowdemo'
Installing eggs.
<BLANKLINE>
...
...
@@ -91,7 +91,7 @@ XXX (showcase with a svn:// file)
Now we can run the buildout and make sure all attempts to dist.plone.org fails::
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
Develop: '/sample-buildout/allowdemo'
Installing eggs.
<BLANKLINE>
...
...
@@ -121,7 +121,7 @@ Test for 1.0.5 breakage as in https://bugs.launchpad.net/zc.buildout/+bug/239212
... eggs=zc.buildout
... interpreter=python
... ''')
>>> print
'XX'; print system(buildout
) # doctest: +ELLIPSIS
>>> print
_('XX'; print system(buildout)
) # doctest: +ELLIPSIS
X...
Unused options for buildout: 'foo'.
Installing python.
...
...
src/zc/buildout/bootstrap.txt
View file @
83d53da5
...
...
@@ -20,9 +20,9 @@ Make sure the bootstrap script actually works::
... parts =
... ''')
>>> write('bootstrap.py', open(bootstrap_py).read())
>>> print
'X'; print system(
>>> print
_(
'X'; print system(
... zc.buildout.easy_install._safe_arg(sys.executable)+' '+
... 'bootstrap.py')
; print 'X'
# doctest: +ELLIPSIS
... 'bootstrap.py')
); print_('X')
# doctest: +ELLIPSIS
X...
Creating directory '/sample/bin'.
Creating directory '/sample/parts'.
...
...
@@ -43,7 +43,7 @@ Make sure the bootstrap script actually works::
>>> ls(sample_buildout, 'bin')
- buildout
>>> print
'X'
; ls(sample_buildout, 'eggs') # doctest: +ELLIPSIS
>>> print
_('X')
; ls(sample_buildout, 'eggs') # doctest: +ELLIPSIS
X...
d zc.buildout-...egg
...
...
@@ -52,9 +52,9 @@ Now trying the `--version` option, that let you define a version for
Let's try with an unknown version::
>>> print
'X'; print
system(
>>> print
_('X'); print_(
system(
... zc.buildout.easy_install._safe_arg(sys.executable)+' '+
... 'bootstrap.py --version UNKNOWN')
; print 'X'
# doctest: +ELLIPSIS
... 'bootstrap.py --version UNKNOWN')
); print_('X')
# doctest: +ELLIPSIS
...
X
...
...
...
@@ -63,9 +63,9 @@ Let's try with an unknown version::
Now let's try with `1.1.2`, which happens to exist::
>>> print
'X'; print
system(
>>> print
_('X'); print_(
system(
... zc.buildout.easy_install._safe_arg(sys.executable)+' '+
... 'bootstrap.py --version 1.1.2')
; print 'X'
... 'bootstrap.py --version 1.1.2')
); print_('X')
... # doctest: +ELLIPSIS
X
...
...
...
@@ -78,7 +78,7 @@ Let's make sure the generated `buildout` script uses it::
>>> buildout_script = join(sample_buildout, 'bin', 'buildout')
>>> if sys.platform.startswith('win'):
... buildout_script += '-script.py'
>>> print
open(buildout_script).read(
) # doctest: +ELLIPSIS
>>> print
_(open(buildout_script).read()
) # doctest: +ELLIPSIS
#...
<BLANKLINE>
import sys
...
...
@@ -95,9 +95,9 @@ Let's make sure the generated `buildout` script uses it::
Let's try with `1.2.1`::
>>> print
'X'; print
system(
>>> print
_('X'); print_(
system(
... zc.buildout.easy_install._safe_arg(sys.executable)+' '+
... 'bootstrap.py --version 1.2.1')
; print 'X'
# doctest: +ELLIPSIS
... 'bootstrap.py --version 1.2.1')
); print_('X')
# doctest: +ELLIPSIS
...
X
...
...
...
@@ -107,7 +107,7 @@ Let's try with `1.2.1`::
Let's make sure the generated `buildout` script uses it::
>>> print
open(buildout_script).read(
) # doctest: +ELLIPSIS
>>> print
_(open(buildout_script).read()
) # doctest: +ELLIPSIS
#...
<BLANKLINE>
import sys
...
...
src/zc/buildout/buildout.py
View file @
83d53da5
...
...
@@ -18,10 +18,15 @@
import
zc.buildout.easy_install
no_site
=
zc
.
buildout
.
easy_install
.
no_site
from
rmtree
import
rmtree
from
.
rmtree
import
rmtree
from
hashlib
import
md5
import
ConfigParser
try
:
from
UserDict
import
DictMixin
except
ImportError
:
from
collections
import
MutableMapping
as
DictMixin
import
zc.buildout.configparser
import
copy
import
distutils.errors
import
glob
...
...
@@ -34,10 +39,17 @@ import shutil
import
subprocess
import
sys
import
tempfile
import
UserDict
import
zc.buildout
import
zc.buildout.download
def
_print_options
(
sep
=
' '
,
end
=
'
\
n
'
,
file
=
None
):
return
sep
,
end
,
file
def
print_
(
*
args
,
**
kw
):
sep
,
end
,
file
=
_print_options
(
**
kw
)
if
file
is
None
:
file
=
sys
.
stdout
file
.
write
(
sep
.
join
(
map
(
str
,
args
))
+
end
)
realpath
=
zc
.
buildout
.
easy_install
.
realpath
...
...
@@ -69,20 +81,20 @@ def _annotate(data, note):
return
data
def
_print_annotate
(
data
):
sections
=
data
.
keys
(
)
sections
=
list
(
data
.
keys
()
)
sections
.
sort
()
print
print
"Annotated sections"
print
"="
*
len
(
"Annotated sections"
)
print
_
()
print
_
(
"Annotated sections"
)
print
_
(
"="
*
len
(
"Annotated sections"
)
)
for
section
in
sections
:
print
print
'[%s]'
%
section
keys
=
data
[
section
].
keys
(
)
print
_
()
print
_
(
'[%s]'
%
section
)
keys
=
list
(
data
[
section
].
keys
()
)
keys
.
sort
()
for
key
in
keys
:
value
,
notes
=
data
[
section
][
key
]
keyvalue
=
"%s= %s"
%
(
key
,
value
)
print
keyvalue
print
_
(
keyvalue
)
line
=
' '
for
note
in
notes
.
split
():
if
note
==
'[+]'
:
...
...
@@ -90,9 +102,9 @@ def _print_annotate(data):
elif
note
==
'[-]'
:
line
=
'-= '
else
:
print
line
,
note
print
_
(
line
,
note
)
line
=
' '
print
print
_
()
def
_unannotate_section
(
section
):
...
...
@@ -127,24 +139,7 @@ _buildout_default_options = _annotate_section({
'use-dependency-links'
:
'true'
,
},
'DEFAULT_VALUE'
)
# _buildout_version and _buildout_1_4_default_versions are part of a
# hack specific to zc.buildout 1.4.4. Search for
# _buildout_1_4_default_versions below to see the usage.
_buildout_version
=
pkg_resources
.
working_set
.
find
(
pkg_resources
.
Requirement
.
parse
(
'zc.buildout'
)).
version
_buildout_1_4_default_versions
=
{
# Buildout and recipes that are likely to change to 1.5.0 sooner rather
# than later.
'zc.buildout'
:
_buildout_version
,
# 'zc.recipe.egg': '1.2.2',
'zc.recipe.testrunner'
:
'1.3.0'
,
'z3c.recipe.i18n'
:
'0.7.0'
,
'z3c.recipe.tag:'
:
'0.3.0'
,
'djangorecipe'
:
'0.20'
,
}
class
Buildout
(
UserDict
.
DictMixin
):
class
Buildout
(
DictMixin
):
def
__init__
(
self
,
config_file
,
cloptions
,
user_defaults
=
True
,
windows_restart
=
False
,
...
...
@@ -295,7 +290,7 @@ class Buildout(UserDict.DictMixin):
# of it is to keep from migrating to 1.5 unless explicitly
# requested. This lets 1.4.4 be an "aspirin release" that people can
# use if they are having trouble with the 1.5 releases.
versions
=
_buildout_1_4_default_versions
.
copy
()
versions
=
{}
versions_section
=
options
.
get
(
'versions'
)
if
versions_section
:
versions
.
update
(
dict
(
self
[
versions_section
]))
...
...
@@ -392,7 +387,7 @@ class Buildout(UserDict.DictMixin):
self
[
'buildout'
][
'bin-directory'
])
def
_init_config
(
self
,
config_file
,
args
):
print
'Creating %r.'
%
config_file
print
_
(
'Creating %r.'
%
config_file
)
f
=
open
(
config_file
,
'w'
)
sep
=
re
.
compile
(
r'[\\/]'
)
if
args
:
...
...
@@ -477,11 +472,11 @@ class Buildout(UserDict.DictMixin):
if
self
.
_log_level
<
logging
.
DEBUG
:
sections
=
list
(
self
)
sections
.
sort
()
print
print
'Configuration data:'
print
_
()
print
_
(
'Configuration data:'
)
for
section
in
self
.
_data
:
_save_options
(
section
,
self
[
section
],
sys
.
stdout
)
print
print
_
()
# compute new part recipe signatures
...
...
@@ -628,7 +623,7 @@ class Buildout(UserDict.DictMixin):
installed
=
self
[
'buildout'
][
'installed'
]
f
=
open
(
installed
,
'a'
)
f
.
write
(
'
\
n
[buildout]
\
n
'
)
for
option
,
value
in
buildout_options
.
items
(
):
for
option
,
value
in
list
(
buildout_options
.
items
()
):
_save_option
(
option
,
value
,
f
)
f
.
close
()
...
...
@@ -644,7 +639,7 @@ class Buildout(UserDict.DictMixin):
recipe
,
'zc.buildout.uninstall'
,
entry
,
self
)
self
.
_logger
.
info
(
'Running uninstall recipe.'
)
uninstaller
(
part
,
installed_part_options
[
part
])
except
(
ImportError
,
pkg_resources
.
DistributionNotFound
)
,
v
:
except
(
ImportError
,
pkg_resources
.
DistributionNotFound
):
pass
# remove created files and directories
...
...
@@ -734,17 +729,15 @@ class Buildout(UserDict.DictMixin):
def
_read_installed_part_options
(
self
):
old
=
self
[
'buildout'
][
'installed'
]
if
old
and
os
.
path
.
isfile
(
old
):
parser
=
ConfigParser
.
RawConfigParser
()
parser
.
optionxform
=
lambda
s
:
s
parser
.
read
(
old
)
with
open
(
old
)
as
fp
:
sections
=
zc
.
buildout
.
configparser
.
parse
(
fp
,
old
)
result
=
{}
for
section
in
parser
.
sections
():
options
=
{}
for
option
,
value
in
parser
.
items
(
section
):
for
section
,
options
in
sections
.
items
():
for
option
,
value
in
options
.
items
():
if
'%('
in
value
:
for
k
,
v
in
_spacey_defaults
:
value
=
value
.
replace
(
k
,
v
)
options
[
option
]
=
value
options
[
option
]
=
value
result
[
section
]
=
Options
(
self
,
section
,
options
)
return
result
,
True
...
...
@@ -784,7 +777,7 @@ class Buildout(UserDict.DictMixin):
installed
=
recipe_class
(
self
,
part
,
options
).
install
()
if
installed
is
None
:
installed
=
[]
elif
isinstance
(
installed
,
basestring
):
elif
isinstance
(
installed
,
str
):
installed
=
[
installed
]
base
=
self
.
_buildout_path
(
''
)
installed
=
[
d
.
startswith
(
base
)
and
d
[
len
(
base
):]
or
d
...
...
@@ -799,7 +792,7 @@ class Buildout(UserDict.DictMixin):
f
=
open
(
installed
,
'w'
)
_save_options
(
'buildout'
,
installed_options
[
'buildout'
],
f
)
for
part
in
installed_options
[
'buildout'
][
'parts'
].
split
():
print
>>
f
print
_
(
file
=
f
)
_save_options
(
part
,
installed_options
[
part
],
f
)
f
.
close
()
...
...
@@ -808,7 +801,7 @@ class Buildout(UserDict.DictMixin):
def
_setup_socket_timeout
(
self
):
timeout
=
self
[
'buildout'
][
'socket-timeout'
]
if
timeout
<>
''
:
if
timeout
!=
''
:
try
:
timeout
=
int
(
timeout
)
import
socket
...
...
@@ -901,7 +894,7 @@ class Buildout(UserDict.DictMixin):
return
if
sys
.
platform
==
'win32'
and
not
self
.
__windows_restart
:
args
=
map
(
zc
.
buildout
.
easy_install
.
_safe_arg
,
sys
.
argv
)
args
=
list
(
map
(
zc
.
buildout
.
easy_install
.
_safe_arg
,
sys
.
argv
)
)
args
.
insert
(
1
,
'-W'
)
if
not
__debug__
:
args
.
insert
(
0
,
'-O'
)
...
...
@@ -986,12 +979,12 @@ class Buildout(UserDict.DictMixin):
fd
,
tsetup
=
tempfile
.
mkstemp
()
try
:
os
.
write
(
fd
,
zc
.
buildout
.
easy_install
.
runsetup_template
%
dict
(
os
.
write
(
fd
,
(
zc
.
buildout
.
easy_install
.
runsetup_template
%
dict
(
distribute
=
pkg_resources_loc
,
setupdir
=
os
.
path
.
dirname
(
setup
),
setup
=
setup
,
__file__
=
setup
,
))
))
.
encode
())
args
=
[
sys
.
executable
,
tsetup
]
+
args
if
no_site
:
args
.
insert
(
1
,
'-S'
)
...
...
@@ -1029,11 +1022,14 @@ class Buildout(UserDict.DictMixin):
raise
NotImplementedError
(
'__delitem__'
)
def
keys
(
self
):
return
self
.
_raw
.
keys
(
)
return
list
(
self
.
_raw
.
keys
()
)
def
__iter__
(
self
):
return
iter
(
self
.
_raw
)
def
__len__
(
self
):
return
len
(
self
.
_raw
)
def
_install_and_load
(
spec
,
group
,
entry
,
buildout
):
__doing__
=
'Loading recipe %r.'
,
spec
...
...
@@ -1066,14 +1062,15 @@ def _install_and_load(spec, group, entry, buildout):
return
pkg_resources
.
load_entry_point
(
req
.
project_name
,
group
,
entry
)
except
Exception
,
v
:
except
Exception
:
v
=
sys
.
exc_info
()[
1
]
buildout
.
_logger
.
log
(
1
,
"Could't load %s entry point %s
\
n
from %s:
\
n
%s."
,
group
,
entry
,
spec
,
v
)
raise
class
Options
(
UserDict
.
DictMixin
):
class
Options
(
DictMixin
):
def
__init__
(
self
,
buildout
,
section
,
data
):
self
.
buildout
=
buildout
...
...
@@ -1090,7 +1087,7 @@ class Options(UserDict.DictMixin):
self
.
_raw
=
self
.
_do_extend_raw
(
name
,
self
.
_raw
,
[])
# force substitutions
for
k
,
v
in
self
.
_raw
.
items
(
):
for
k
,
v
in
list
(
self
.
_raw
.
items
()
):
if
'${'
in
v
:
self
.
_dosub
(
k
,
v
)
...
...
@@ -1241,12 +1238,18 @@ class Options(UserDict.DictMixin):
elif
key
in
self
.
_data
:
del
self
.
_data
[
key
]
else
:
raise
KeyError
,
key
raise
KeyError
(
key
)
def
keys
(
self
):
raw
=
self
.
_raw
return
list
(
self
.
_raw
)
+
[
k
for
k
in
self
.
_data
if
k
not
in
raw
]
def
__iter__
(
self
):
return
iter
(
self
.
keys
())
def
__len__
(
self
):
return
len
(
self
.
keys
())
def
copy
(
self
):
result
=
self
.
_raw
.
copy
()
result
.
update
(
self
.
_cooked
)
...
...
@@ -1317,11 +1320,11 @@ def _save_option(option, value, f):
value
=
'%(__buildout_space_n__)s'
+
value
[
2
:]
if
value
.
endswith
(
'
\
n
\
t
'
):
value
=
value
[:
-
2
]
+
'%(__buildout_space_n__)s'
print
>>
f
,
option
,
'='
,
value
print
_
(
option
,
'='
,
value
,
file
=
f
)
def
_save_options
(
section
,
options
,
f
):
print
>>
f
,
'[%s]'
%
section
items
=
options
.
items
(
)
print
_
(
'[%s]'
%
section
,
file
=
f
)
items
=
list
(
options
.
items
()
)
items
.
sort
()
for
option
,
value
in
items
:
_save_option
(
option
,
value
,
f
)
...
...
@@ -1374,25 +1377,17 @@ def _open(base, filename, seen, dl_options, override, downloaded):
root_config_file
=
not
seen
seen
.
append
(
filename
)
result
=
{}
parser
=
ConfigParser
.
RawConfigParser
()
parser
.
optionxform
=
lambda
s
:
s
parser
.
readfp
(
fp
)
result
=
zc
.
buildout
.
configparser
.
parse
(
fp
,
filename
)
fp
.
close
()
if
is_temp
:
fp
.
close
()
os
.
remove
(
path
)
extends
=
None
for
section
in
parser
.
sections
():
options
=
dict
(
parser
.
items
(
section
))
if
section
==
'buildout'
:
extends
=
options
.
pop
(
'extends'
,
extends
)
if
'extended-by'
in
options
:
raise
zc
.
buildout
.
UserError
(
'No-longer supported "extended-by" option found in %s.'
%
filename
)
result
[
section
]
=
options
options
=
result
.
get
(
'buildout'
,
{})
extends
=
options
.
pop
(
'extends'
,
None
)
if
'extended-by'
in
options
:
raise
zc
.
buildout
.
UserError
(
'No-longer supported "extended-by" option found in %s.'
%
filename
)
result
=
_annotate
(
result
,
filename
)
...
...
@@ -1425,11 +1420,11 @@ def _dir_hash(dir):
if
(
not
(
f
.
endswith
(
'pyc'
)
or
f
.
endswith
(
'pyo'
))
and
os
.
path
.
exists
(
os
.
path
.
join
(
dirpath
,
f
)))
]
hash
.
update
(
' '
.
join
(
dirnames
))
hash
.
update
(
' '
.
join
(
filenames
))
hash
.
update
(
' '
.
join
(
dirnames
)
.
encode
()
)
hash
.
update
(
' '
.
join
(
filenames
)
.
encode
()
)
for
name
in
filenames
:
hash
.
update
(
open
(
os
.
path
.
join
(
dirpath
,
name
)).
read
())
_dir_hashes
[
dir
]
=
dir_hash
=
hash
.
digest
().
encode
(
'base64'
).
strip
()
hash
.
update
(
open
(
os
.
path
.
join
(
dirpath
,
name
)
,
'rb'
).
read
())
_dir_hashes
[
dir
]
=
dir_hash
=
hash
.
hexdigest
()
return
dir_hash
def
_dists_sig
(
dists
):
...
...
@@ -1444,7 +1439,7 @@ def _dists_sig(dists):
def
_update_section
(
s1
,
s2
):
s2
=
s2
.
copy
()
# avoid mutating the second argument, which is unexpected
for
k
,
v
in
s2
.
items
(
):
for
k
,
v
in
list
(
s2
.
items
()
):
v2
,
note2
=
v
if
k
.
endswith
(
'+'
):
key
=
k
.
rstrip
(
' +'
)
...
...
@@ -1631,7 +1626,7 @@ Commands:
"""
def
_help
():
print
_usage
print
_
(
_usage
)
sys
.
exit
(
0
)
def
main
(
args
=
None
):
...
...
@@ -1728,7 +1723,8 @@ def main(args=None):
getattr
(
buildout
,
command
)(
args
)
except
SystemExit
:
pass
except
Exception
,
v
:
except
Exception
:
v
=
sys
.
exc_info
()[
1
]
_doing
()
exc_info
=
sys
.
exc_info
()
import
pdb
,
traceback
...
...
@@ -1738,7 +1734,7 @@ def main(args=None):
pdb
.
post_mortem
(
exc_info
[
2
])
else
:
if
isinstance
(
v
,
(
zc
.
buildout
.
UserError
,
distutils
.
errors
.
DistutilsError
,
distutils
.
errors
.
DistutilsError
)
):
_error
(
str
(
v
))
...
...
src/zc/buildout/buildout.txt
View file @
83d53da5
...
...
@@ -284,7 +284,7 @@ buildout:
>>> import os
>>> os.chdir(sample_buildout)
>>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Installing data-dir.
data-dir: Creating directory mystuff
...
...
@@ -333,7 +333,7 @@ we'll see that the directory gets removed and recreated:
... path = mydata
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Uninstalling data-dir.
Installing data-dir.
...
...
@@ -353,7 +353,7 @@ If any of the files or directories created by a recipe are removed,
the part will be reinstalled:
>>> rmdir(sample_buildout, 'mydata')
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Uninstalling data-dir.
Installing data-dir.
...
...
@@ -384,7 +384,7 @@ non-existent directory to create the directory in:
We'll get a user error, not a traceback.
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
data-dir: Cannot create /xxx/mydata. /xxx is not a directory.
While:
...
...
@@ -449,7 +449,7 @@ leave previously created paths in place:
... path = foo bin
... """)
>>> print
system(buildout),
# doctest: +ELLIPSIS
>>> print
_(system(buildout))
# doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes'
Uninstalling data-dir.
Installing data-dir.
...
...
@@ -483,7 +483,7 @@ If we fix the typo:
... path = foo bins
... """)
>>> print
system(buildout),
# doctest: +ELLIPSIS
>>> print
_(system(buildout))
# doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes'
Installing data-dir.
data-dir: Creating directory foo
...
...
@@ -565,7 +565,7 @@ And put back the typo:
When we rerun the buildout:
>>> print
system(buildout),
# doctest: +ELLIPSIS
>>> print
_(system(buildout))
# doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes'
Installing data-dir.
data-dir: Creating directory foo
...
...
@@ -638,7 +638,12 @@ recipe:
..
>>> remove(sample_buildout, 'recipes', 'mkdir.pyc')
>>> for path in (
... join(sample_buildout, 'recipes', 'mkdir.pyc'),
... join(sample_buildout, 'recipes', '__pycache__', 'mkdir.pyc'),
... ):
... if os.path.exists(path):
... remove(path)
We returned by calling created, taking advantage of the fact that it
returns the registered paths. We did this for illustrative purposes.
...
...
@@ -647,7 +652,7 @@ It would be simpler just to return the paths as before.
If we rerun the buildout, again, we'll get the error and no
directories will be created:
>>> print
system(buildout),
# doctest: +ELLIPSIS
>>> print
_(system(buildout))
# doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes'
Installing data-dir.
data-dir: Creating directory foo
...
...
@@ -677,7 +682,7 @@ Now, we'll fix the typo again and we'll get the directories we expect:
... path = foo bins
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Installing data-dir.
data-dir: Creating directory foo
...
...
@@ -724,7 +729,7 @@ all key-value pairs are displayed, sorted alphabetically, along with
the origin of the value (file name or COMPUTED_VALUE, DEFAULT_VALUE,
COMMAND_LINE_VALUE).
>>> print
system(buildout+ ' annotate'),
>>> print
_(system(buildout+ ' annotate'), end='')
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<BLANKLINE>
Annotated sections
...
...
@@ -790,6 +795,7 @@ allow us to see interactions with the buildout:
>>> write(sample_buildout, 'recipes', 'debug.py',
... """
... import sys
... class Debug:
...
... def __init__(self, buildout, name, options):
...
...
@@ -798,10 +804,8 @@ allow us to see interactions with the buildout:
... self.options = options
...
... def install(self):
... items = self.options.items()
... items.sort()
... for option, value in items:
... print option, value
... for option, value in sorted(self.options.items()):
... sys.stdout.write('%s %s\\n' % (option, value))
... return ()
...
... update = install
...
...
@@ -857,7 +861,7 @@ and option name joined by a colon.
Now, if we run the buildout, we'll see the options with the values
substituted.
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Uninstalling data-dir.
Installing data-dir.
...
...
@@ -876,7 +880,7 @@ The buildout system didn't know if this module could effect the mkdir
recipe, so it assumed it could and reinstalled mydata. If we rerun
the buildout:
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Updating data-dir.
Updating debug.
...
...
@@ -915,7 +919,7 @@ _buildout_section_name_ to get the current section name.
... path = mydata
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Updating data-dir.
...
...
@@ -953,7 +957,7 @@ example, we can leave data-dir out of the parts list:
It will still be treated as a part:
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Updating data-dir.
...
...
@@ -992,7 +996,7 @@ the data-dir part after the debug part, it will be included before:
It will still be treated as a part:
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Updating data-dir.
Updating debug.
...
...
@@ -1041,7 +1045,7 @@ of the current section allows sections to be used as macros.
... path = mydata
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Uninstalling data-dir.
...
...
@@ -1132,9 +1136,11 @@ extension that prints out the options.
>>> mkdir(sample_buildout, 'demo')
>>> write(sample_buildout, 'demo', 'demo.py',
... """
... import sys
... def ext(buildout):
... print [part['option'] for name, part in buildout.items() \
... if name.startswith('part')]
... sys.stdout.write(str(
... [part['option'] for name, part in buildout.items()
... if name.startswith('part')])+'\\n')
... """)
>>> write(sample_buildout, 'demo', 'setup.py',
...
...
@@ -1157,13 +1163,9 @@ Set up a buildout configuration for this extension.
... """)
>>> os.chdir(sample_buildout)
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
Develop: '/sample-buildout/demo'
Uninstalling myfiles.
Getting distribution for 'recipes'.
zip_safe flag not set; analyzing archive contents...
Got recipes 0.0.0.
warning: install_lib: 'build/lib' does not exist -- no Python modules to install
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')), end='')
... # doctest: +ELLIPSIS
Develop: '/sample-buildout/demo'...
Verify option values.
...
...
@@ -1175,14 +1177,14 @@ Verify option values.
... extends = extension2.cfg
... """)
>>> print
system(os.path.join('bin', 'buildout')),
>>> print
_(system(os.path.join('bin', 'buildout')), end='')
['a1 a2/na3 a4/na5', 'b1 b2 b3 b4', 'c1 c2/nc3 c4 c5', 'h1 h2']
Develop: '/sample-buildout/demo'
Annotated sections output shows which files are responsible for which
operations.
>>> print
system(os.path.join('bin', 'buildout') + ' annotate'),
>>> print
_(system(os.path.join('bin', 'buildout') + ' annotate'), end='')
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<BLANKLINE>
Annotated sections
...
...
@@ -1258,7 +1260,7 @@ To see how this works, we use an example:
... op = base
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Installing debug.
op buildout
...
...
@@ -1328,7 +1330,7 @@ Here is a more elaborate example.
... name = base
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Installing debug.
...
...
@@ -1390,7 +1392,7 @@ we'll set up a web server with some configuration files.
... """ % dict(url=server_url))
>>> print
system(buildout+ ' -c client.cfg'),
>>> print
_(system(buildout+ ' -c client.cfg'), end='')
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Installing debug.
...
...
@@ -1421,7 +1423,7 @@ buildout.
... name = remote
... """)
>>> print
system(buildout + ' -c ' + server_url + '/remote.cfg'),
>>> print
_(system(buildout + ' -c ' + server_url + '/remote.cfg'), end='')
While:
Initializing.
Error: Missing option: buildout:directory
...
...
@@ -1431,10 +1433,10 @@ containing a configuration file. This won't work for configuration
files loaded from URLs. In this case, the buildout directory would
normally be defined on the command line:
>>> print
system(buildout
>>> print
_(
system(buildout
... + ' -c ' + server_url + '/remote.cfg'
... + ' buildout:directory=' + sample_buildout
... ),
... ),
end='')
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Installing debug.
...
...
@@ -1463,7 +1465,7 @@ delimiter.)
... """)
>>> os.environ['HOME'] = home
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Installing debug.
...
...
@@ -1480,7 +1482,7 @@ delimiter.)
A buildout command-line argument, -U, can be used to suppress reading
user defaults:
>>> print
system(buildout + ' -U'),
>>> print
_(system(buildout + ' -U'), end='')
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Installing debug.
...
...
@@ -1509,7 +1511,7 @@ set the logging level to WARNING
... extends = b1.cfg b2.cfg
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
name base
op1 b1 1
op2 b2 2
...
...
@@ -1534,7 +1536,7 @@ configured in the buildout section. Its value is configured in seconds.
... op = timeout
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Setting socket time out to 5 seconds.
Develop: '/sample-buildout/recipes'
Uninstalling debug.
...
...
@@ -1557,7 +1559,7 @@ timeout of the Python socket module is used.
... op = timeout
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Default socket timeout is used !
Value in configuration is not numeric: [5s].
<BLANKLINE>
...
...
@@ -1594,6 +1596,7 @@ with an uninstall recipe that simulates removing the service.
>>> write(sample_buildout, 'recipes', 'service.py',
... """
... import sys
... class Service:
...
... def __init__(self, buildout, name, options):
...
...
@@ -1602,7 +1605,8 @@ with an uninstall recipe that simulates removing the service.
... self.options = options
...
... def install(self):
... print "chkconfig --add %s" % self.options['script']
... sys.stdout.write("chkconfig --add %s\\n"
... % self.options['script'])
... return ()
...
... def update(self):
...
...
@@ -1610,7 +1614,7 @@ with an uninstall recipe that simulates removing the service.
...
...
... def uninstall_service(name, options):
...
print "chkconfig --del %s" % options['script']
...
sys.stdout.write("chkconfig --del %s\\n" % options['script'])
... """)
To use these recipes we must register them using entry points. Make
...
...
@@ -1649,20 +1653,18 @@ Here's how these recipes could be used in a buildout:
When the buildout is run the service will be installed
>>> print
system(buildout
)
>>> print
_(system(buildout), end=''
)
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Installing service.
chkconfig --add /path/to/script
<BLANKLINE>
The service has been installed. If the buildout is run again with no
changes, the service shouldn't be changed.
>>> print
system(buildout
)
>>> print
_(system(buildout), end=''
)
Develop: '/sample-buildout/recipes'
Updating service.
<BLANKLINE>
Now we change the service part to trigger uninstallation and
re-installation.
...
...
@@ -1678,14 +1680,13 @@ re-installation.
... script = /path/to/a/different/script
... """)
>>> print
system(buildout
)
>>> print
_(system(buildout), end=''
)
Develop: '/sample-buildout/recipes'
Uninstalling service.
Running uninstall recipe.
chkconfig --del /path/to/script
Installing service.
chkconfig --add /path/to/a/different/script
<BLANKLINE>
Now we remove the service part, and add another part.
...
...
@@ -1699,14 +1700,13 @@ Now we remove the service part, and add another part.
... recipe = recipes:debug
... """)
>>> print
system(buildout
)
>>> print
_(system(buildout), end=''
)
Develop: '/sample-buildout/recipes'
Uninstalling service.
Running uninstall recipe.
chkconfig --del /path/to/a/different/script
Installing debug.
recipe recipes:debug
<BLANKLINE>
Uninstall recipes don't have to take care of removing all the files
and directories created by the part. This is still done automatically,
...
...
@@ -1720,11 +1720,12 @@ mkdir recipe introduced earlier.
>>> write(sample_buildout, 'recipes', 'backup.py',
... """
... import os
... import os
, sys
... def backup_directory(name, options):
... path = options['path']
... size = len(os.listdir(path))
... print "backing up directory %s of size %s" % (path, size)
... sys.stdout.write("backing up directory %s of size %s\\n"
... % (path, size))
... """)
It must be registered with the zc.buildout.uninstall entry
...
...
@@ -1766,14 +1767,13 @@ Now we can use it with a mkdir part.
Run the buildout to install the part.
>>> print
system(buildout
)
>>> print
_(system(buildout), end=''
)
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Installing dir.
dir: Creating directory my_directory
Installing debug.
recipe recipes:debug
<BLANKLINE>
Now we remove the part from the configuration file.
...
...
@@ -1790,14 +1790,13 @@ Now we remove the part from the configuration file.
When the buildout is run the part is removed, and the uninstall recipe
is run before the directory is deleted.
>>> print
system(buildout
)
>>> print
_(system(buildout), end=''
)
Develop: '/sample-buildout/recipes'
Uninstalling dir.
Running uninstall recipe.
backing up directory /sample-buildout/my_directory of size 0
Updating debug.
recipe recipes:debug
<BLANKLINE>
Now we will return the registration to normal for the benefit of the
rest of the examples.
...
...
@@ -1895,7 +1894,7 @@ Here's an example:
Note that we used the installed buildout option to specify an
alternate file to store information about installed parts.
>>> print
system(buildout+' -c other.cfg debug:op1=foo -v'),
>>> print
_(system(buildout+' -c other.cfg debug:op1=foo -v'), end='')
Develop: '/sample-buildout/recipes'
Installing debug.
name other
...
...
@@ -1908,7 +1907,7 @@ WARNING.
Options can also be combined in the usual Unix way, as in:
>>> print
system(buildout+' -vcother.cfg debug:op1=foo'),
>>> print
_(system(buildout+' -vcother.cfg debug:op1=foo'), end='')
Develop: '/sample-buildout/recipes'
Updating debug.
name other
...
...
@@ -1949,7 +1948,7 @@ the buildout in the usual way:
... recipe = recipes:debug
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Uninstalling debug.
Installing debug.
...
...
@@ -2033,7 +2032,7 @@ Now we'll update our configuration file:
and run the buildout specifying just d3 and d4:
>>> print
system(buildout+' install d3 d4'),
>>> print
_(system(buildout+' install d3 d4'), end='')
Develop: '/sample-buildout/recipes'
Uninstalling d3.
Installing d3.
...
...
@@ -2104,7 +2103,7 @@ directories are still there.
Now, if we run the buildout without the install command:
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Uninstalling d2.
Uninstalling d1.
...
...
@@ -2161,7 +2160,7 @@ provide alternate locations, and even names for these directories.
... work = os.path.join(alt, 'work'),
... ))
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Creating directory '/sample-alt/scripts'.
Creating directory '/sample-alt/work'.
Creating directory '/sample-alt/basket'.
...
...
@@ -2197,7 +2196,7 @@ You can also specify an alternate buildout directory:
... recipes=os.path.join(sample_buildout, 'recipes'),
... ))
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Creating directory '/sample-alt/bin'.
Creating directory '/sample-alt/parts'.
Creating directory '/sample-alt/eggs'.
...
...
@@ -2249,7 +2248,7 @@ can be a numeric value and that the verbosity can be specified in the
configuration file. Because the verbosity is subtracted from the log
level, we get a final log level of 20, which is the INFO level.
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
INFO Develop: '/sample-buildout/recipes'
Predefined buildout options
...
...
@@ -2267,7 +2266,7 @@ database is shown.
... parts =
... """)
>>> print
system(buildout+' -vv'),
# doctest: +NORMALIZE_WHITESPACE
>>> print
_(system(buildout+' -vv'), end='')
# doctest: +NORMALIZE_WHITESPACE
Installing 'zc.buildout', 'distribute'.
We have a develop egg: zc.buildout 1.0.0.
We have the best distribution that satisfies 'distribute'.
...
...
@@ -2492,9 +2491,9 @@ local buildout scripts.
>>> sample_bootstrapped = tmpdir('sample-bootstrapped')
>>> print
system(buildout
>>> print
_(
system(buildout
... +' -c'+os.path.join(sample_bootstrapped, 'setup.cfg')
... +' init'),
... +' init'),
end='')
Creating '/sample-bootstrapped/setup.cfg'.
Creating directory '/sample-bootstrapped/bin'.
Creating directory '/sample-bootstrapped/parts'.
...
...
@@ -2541,9 +2540,9 @@ if there isn't a configuration file:
>>> sample_bootstrapped2 = tmpdir('sample-bootstrapped2')
>>> print
system(buildout
>>> print
_(
system(buildout
... +' -c'+os.path.join(sample_bootstrapped2, 'setup.cfg')
... +' bootstrap'),
... +' bootstrap'),
end='')
While:
Initializing.
Error: Couldn't open /sample-bootstrapped2/setup.cfg
...
...
@@ -2554,9 +2553,9 @@ if there isn't a configuration file:
... parts =
... """)
>>> print
system(buildout
>>> print
_(
system(buildout
... +' -c'+os.path.join(sample_bootstrapped2, 'setup.cfg')
... +' bootstrap'),
... +' bootstrap'),
end='')
Creating directory '/sample-bootstrapped2/bin'.
Creating directory '/sample-bootstrapped2/parts'.
Creating directory '/sample-bootstrapped2/eggs'.
...
...
@@ -2567,9 +2566,9 @@ Similarly, if there is a configuration file and we use the init
command, we'll get an error that the configuration file already
exists:
>>> print
system(buildout
>>> print
_(
system(buildout
... +' -c'+os.path.join(sample_bootstrapped, 'setup.cfg')
... +' init'),
... +' init'),
end='')
While:
Initializing.
Error: '/sample-bootstrapped/setup.cfg' already exists.
...
...
@@ -2583,7 +2582,7 @@ or paths to use:
>>> cd(sample_bootstrapped)
>>> remove('setup.cfg')
>>> remove('bin', 'buildout')
>>> print
system(buildout + ' -csetup.cfg init demo other ./src'),
>>> print
_(system(buildout + ' -csetup.cfg init demo other ./src'), end='')
Creating '/sample-bootstrapped/setup.cfg'.
Generated script '/sample-bootstrapped/bin/buildout'.
Getting distribution for 'zc.recipe.egg'.
...
...
@@ -2642,7 +2641,7 @@ for us:
>>> cd(sample_bootstrapped)
>>> _ = system(buildout + ' -csetup.cfg buildout:parts=')
>>> remove('setup.cfg')
>>> print
system(buildout + ' -csetup.cfg init demo other ./src'),
>>> print
_(system(buildout + ' -csetup.cfg init demo other ./src'), end='')
Creating '/sample-bootstrapped/setup.cfg'.
Installing py.
Generated script '/sample-bootstrapped/bin/demo'.
...
...
@@ -2692,7 +2691,7 @@ or on the command line:
... recipe = recipes:debug
... """)
>>> print
system(buildout+' buildout:installed=inst.cfg'),
>>> print
_(system(buildout+' buildout:installed=inst.cfg'), end='')
Develop: '/sample-buildout/recipes'
Installing debug.
recipe recipes:debug
...
...
@@ -2714,7 +2713,7 @@ The installation database can be disabled by supplying an empty
buildout installed option:
>>> os.remove('inst.cfg')
>>> print
system(buildout+' buildout:installed='),
>>> print
_(system(buildout+' buildout:installed='), end='')
Develop: '/sample-buildout/recipes'
Installing debug.
recipe recipes:debug
...
...
@@ -2740,7 +2739,7 @@ Note that there will be no installation database if there are no parts:
... parts =
... """)
>>> print
system(buildout+' buildout:installed=inst.cfg'),
>>> print
_(system(buildout+' buildout:installed=inst.cfg'), end='')
>>> ls(sample_buildout)
- b1.cfg
...
...
@@ -2776,10 +2775,11 @@ previous section:
>>> write(sample_bootstrapped, 'demo', 'demo.py',
... """
... import sys
... def ext(buildout):
...
print 'ext', list(buildout
)
...
sys.stdout.write('%s %s\\n' % ('ext', list(buildout))
)
... def unload(buildout):
...
print 'unload', list(buildout
)
...
sys.stdout.write('%s %s\\n' % ('unload', list(buildout))
)
... """)
>>> write(sample_bootstrapped, 'demo', 'setup.py',
...
...
@@ -2809,7 +2809,8 @@ egg to be built:
... """)
>>> os.chdir(sample_bootstrapped)
>>> print system(os.path.join(sample_bootstrapped, 'bin', 'buildout')),
>>> print_(system(os.path.join(sample_bootstrapped, 'bin', 'buildout')),
... end='')
Develop: '/sample-bootstrapped/demo'
Now we can add the extensions option. We were a bit tricky and ran
...
...
@@ -2829,7 +2830,8 @@ the network, we wouldn't need to do anything special.
We see that our extension is loaded and executed:
>>> print system(os.path.join(sample_bootstrapped, 'bin', 'buildout')),
>>> print_(system(os.path.join(sample_bootstrapped, 'bin', 'buildout')),
... end='')
ext ['buildout']
Develop: '/sample-bootstrapped/demo'
unload ['buildout']
src/zc/buildout/configparser.py
0 → 100644
View file @
83d53da5
##############################################################################
#
# Copyright Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
# The following copied from Python 2 config parser because:
# - The py3 configparser isn't backward compatible
# - Both strip option values in undesireable ways
# - dict of dicts is a much simpler api
import
re
class
Error
(
Exception
):
"""Base class for ConfigParser exceptions."""
def
_get_message
(
self
):
"""Getter for 'message'; needed only to override deprecation in
BaseException."""
return
self
.
__message
def
_set_message
(
self
,
value
):
"""Setter for 'message'; needed only to override deprecation in
BaseException."""
self
.
__message
=
value
# BaseException.message has been deprecated since Python 2.6. To prevent
# DeprecationWarning from popping up over this pre-existing attribute, use
# a new property that takes lookup precedence.
message
=
property
(
_get_message
,
_set_message
)
def
__init__
(
self
,
msg
=
''
):
self
.
message
=
msg
Exception
.
__init__
(
self
,
msg
)
def
__repr__
(
self
):
return
self
.
message
class
ParsingError
(
Error
):
"""Raised when a configuration file does not follow legal syntax."""
def
__init__
(
self
,
filename
):
Error
.
__init__
(
self
,
'File contains parsing errors: %s'
%
filename
)
self
.
filename
=
filename
self
.
errors
=
[]
def
append
(
self
,
lineno
,
line
):
self
.
errors
.
append
((
lineno
,
line
))
self
.
message
+=
'
\
n
\
t
[line %2d]: %s'
%
(
lineno
,
line
)
class
MissingSectionHeaderError
(
ParsingError
):
"""Raised when a key-value pair is found before any section header."""
def
__init__
(
self
,
filename
,
lineno
,
line
):
Error
.
__init__
(
self
,
'File contains no section headers.
\
n
file: %s, line: %d
\
n
%r'
%
(
filename
,
lineno
,
line
))
self
.
filename
=
filename
self
.
lineno
=
lineno
self
.
line
=
line
SECTCRE
=
re
.
compile
(
r'\
[
' # [
r'
(
?
P
<
header
>
[
^
]]
+
)
' # very permissive!
r'
\
]
' # ]
)
OPTCRE = re.compile(
r'
(
?
P
<
option
>
[
^
:
=
\
s
][
^
:
=
]
*
)
' # very permissive!
r'
\
s
*
(
?
P
<
vi
>
[:
=
])
\
s
*
' # any number of space/tab,
# followed by separator
# (either : or =), followed
# by any # space/tab
r'
(
?
P
<
value
>
.
*
)
$
' # everything up to eol
)
def parse(fp, fpname):
"""Parse a sectioned setup file.
The sections in setup file contains a title line at the top,
indicated by a name in square brackets (`[]'
),
plus
key
/
value
options
lines
,
indicated
by
`
name
:
value
' format lines.
Continuations are represented by an embedded newline then
leading whitespace. Blank lines, lines beginning with a '
#',
and
just
about
everything
else
are
ignored
.
"""
_sections = {}
cursect = None # None, or a dictionary
optname = None
lineno = 0
e = None # None, or an exception
while True:
line = fp.readline()
if not line:
break
lineno = lineno + 1
# comment or blank line?
if line.strip() == '' or line[0] in '#;':
continue
if line.split(None, 1)[0].lower() == 'rem' and line[0] in "rR":
# no leading whitespace
continue
# continuation line?
if line[0].isspace() and cursect is not None and optname:
value = line.strip()
if value:
cursect[optname] = "%s
\
n
%s" % (cursect[optname], value)
# a section header or option header?
else:
# is it a section header?
mo = SECTCRE.match(line)
if mo:
sectname = mo.group('header')
if sectname in _sections:
cursect = _sections[sectname]
else:
cursect = {}
_sections[sectname] = cursect
# So sections can't start with a continuation line
optname = None
# no section header in the file?
elif cursect is None:
raise MissingSectionHeaderError(fpname, lineno, line)
# an option line?
else:
mo = OPTCRE.match(line)
if mo:
optname, vi, optval = mo.group('option', 'vi', 'value')
# This check is fine because the OPTCRE cannot
# match if it would set optval to None
if optval is not None:
if vi in ('=', ':') and ';' in optval:
# ';' is a comment delimiter only if it follows
# a spacing character
pos = optval.find(';')
if pos != -1 and optval[pos-1].isspace():
optval = optval[:pos]
optval = optval.strip()
# allow empty values
if optval == '""':
optval = ''
optname = optname.rstrip()
cursect[optname] = optval
else:
# a non-fatal parsing error occurred. set up the
# exception but keep going. the exception will be
# raised at the end of the file and will contain a
# list of all bogus lines
if not e:
e = ParsingError(fpname)
e.append(lineno, repr(line))
# if any parsing errors occurred, raise an exception
if e:
raise e
return _sections
src/zc/buildout/debugging.txt
View file @
83d53da5
...
...
@@ -56,7 +56,7 @@ And create a buildout that uses it:
If we run the buildout, we'll get an error:
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Develop: '/sample-buildout/recipes'
Installing data-dir.
While:
...
...
@@ -67,11 +67,11 @@ If we run the buildout, we'll get an error:
If we want to debug the error, we can add the -D option. Here's we'll
supply some input:
>>> print
system(buildout+" -D", """\
>>> print
_(
system(buildout+" -D", """\
... up
... p self.options.keys()
... q
... """),
... """),
end='')
Develop: '/sample-buildout/recipes'
Installing data-dir.
> /zc/buildout/buildout.py(925)__getitem__()
...
...
src/zc/buildout/dependencylinks.txt
View file @
83d53da5
...
...
@@ -54,14 +54,13 @@ Now let's configure the buildout to use the develop egg.
Now we can run the buildout.
>>> print
system(buildout
)
>>> print
_(system(buildout), end=''
)
GET 200 /
GET 200 /demoneeded-1.2c1.zip
Develop: '/sample-buildout/depdemo'
Installing eggs.
Getting distribution for 'demoneeded'.
Got demoneeded 1.2c1.
<BLANKLINE>
Notice that the egg was retrieved from the logging server.
...
...
@@ -83,7 +82,7 @@ buildout to see where the egg comes from this time.
... for egg in glob(join(sample_buildout, 'eggs', 'demoneeded*.egg')):
... remove(sample_buildout, 'eggs', egg)
>>> remove_demoneeded_egg()
>>> print
system(buildout
)
>>> print
_(system(buildout), end=''
)
Develop: '/sample-buildout/depdemo'
Updating eggs.
Couldn't find index page for 'demoneeded' (maybe misspelled?)
...
...
@@ -92,7 +91,6 @@ buildout to see where the egg comes from this time.
Updating eggs.
Getting distribution for 'demoneeded'.
Error: Couldn't find a distribution for 'demoneeded'.
<BLANKLINE>
Now it can't find the dependency since neither the buildout
configuration nor setup specifies where to look.
...
...
@@ -112,12 +110,11 @@ to look for eggs.
... eggs = depdemo
... ''' % link_server)
>>> print
system(buildout
)
>>> print
_(system(buildout), end=''
)
Develop: '/sample-buildout/depdemo'
Installing eggs.
Getting distribution for 'demoneeded'.
Got demoneeded 1.2c1.
<BLANKLINE>
This time the dependency egg was found on the server without logging
configured.
...
...
@@ -134,13 +131,12 @@ specify different places to look for the dependency egg.
... ''' % link_server2)
>>> remove_demoneeded_egg()
>>> print
system(buildout
) #doctest: +ELLIPSIS
>>> print
_(system(buildout), end=''
) #doctest: +ELLIPSIS
GET 200 /...
Develop: '/sample-buildout/depdemo'
Updating eggs.
Getting distribution for 'demoneeded'.
Got demoneeded 1.2c1.
<BLANKLINE>
So when both setuptools and buildout specify places to search for
eggs, the dependency_links takes precedence over find-links.
...
...
@@ -166,12 +162,11 @@ Here is an example of using this option to disable dependency_links.
... ''' % link_server)
>>> remove_demoneeded_egg()
>>> print
system(buildout
)
>>> print
_(system(buildout), end=''
)
Develop: '/sample-buildout/depdemo'
Updating eggs.
Getting distribution for 'demoneeded'.
Got demoneeded 1.2c1.
<BLANKLINE>
Notice that this time the egg isn't downloaded from the logging server.
...
...
@@ -191,10 +186,9 @@ before. The dependency's are looked for first in the logging server.
... eggs = depdemo
... ''' % link_server)
>>> remove_demoneeded_egg()
>>> print
system(buildout
) #doctest: +ELLIPSIS
>>> print
_(system(buildout), end=''
) #doctest: +ELLIPSIS
GET 200 /...
Develop: '/sample-buildout/depdemo'
Updating eggs.
Getting distribution for 'demoneeded'.
Got demoneeded 1.2c1.
<BLANKLINE>
src/zc/buildout/download.py
View file @
83d53da5
...
...
@@ -24,13 +24,13 @@ import os.path
import
re
import
shutil
import
tempfile
import
urllib
import
urlparse
import
urllib
.request
,
urllib
.
parse
,
urllib
.
error
import
url
lib.
parse
import
zc.buildout
class
URLOpener
(
urllib
.
FancyURLopener
):
http_error_default
=
urllib
.
URLopener
.
http_error_default
class
URLOpener
(
urllib
.
request
.
FancyURLopener
):
http_error_default
=
urllib
.
request
.
URLopener
.
http_error_default
class
ChecksumError
(
zc
.
buildout
.
UserError
):
...
...
@@ -157,7 +157,7 @@ class Download(object):
if
re
.
match
(
r"^[A-Za-z]:\\"
,
url
):
url
=
'file:'
+
url
parsed_url
=
urlparse
.
urlparse
(
url
,
'file'
)
parsed_url
=
url
lib
.
parse
.
urlparse
(
url
,
'file'
)
url_scheme
,
_
,
url_path
=
parsed_url
[:
3
]
if
url_scheme
==
'file'
:
self
.
logger
.
debug
(
'Using local resource %s'
%
url
)
...
...
@@ -172,18 +172,19 @@ class Download(object):
"Couldn't download %r in offline mode."
%
url
)
self
.
logger
.
info
(
'Downloading %s'
%
url
)
urllib
.
_urlopener
=
url_opener
urllib
.
request
.
_urlopener
=
url_opener
handle
,
tmp_path
=
tempfile
.
mkstemp
(
prefix
=
'buildout-'
)
try
:
tmp_path
,
headers
=
urllib
.
urlretrieve
(
url
,
tmp_path
)
tmp_path
,
headers
=
urllib
.
request
.
urlretrieve
(
url
,
tmp_path
)
if
not
check_md5sum
(
tmp_path
,
md5sum
):
raise
ChecksumError
(
'MD5 checksum mismatch downloading %r'
%
url
)
except
IOError
,
e
:
except
IOError
:
e
=
sys
.
exc_info
()[
1
]
os
.
remove
(
tmp_path
)
raise
zc
.
buildout
.
UserError
(
"Error downloading extends for URL "
"%s: %r"
%
(
url
,
e
[
1
:
3
]))
except
Exception
,
e
:
except
Exception
:
os
.
remove
(
tmp_path
)
raise
finally
:
...
...
@@ -204,7 +205,7 @@ class Download(object):
else
:
if
re
.
match
(
r"^[A-Za-z]:\\"
,
url
):
url
=
'file:'
+
url
parsed
=
urlparse
.
urlparse
(
url
,
'file'
)
parsed
=
url
lib
.
parse
.
urlparse
(
url
,
'file'
)
url_path
=
parsed
[
2
]
if
parsed
[
0
]
==
'file'
:
...
...
src/zc/buildout/download.txt
View file @
83d53da5
...
...
@@ -28,7 +28,7 @@ without any arguments:
>>> from zc.buildout.download import Download
>>> download = Download()
>>> print
download.cache_dir
>>> print
_(download.cache_dir)
None
Downloading a file is achieved by calling the utility with the URL as an
...
...
@@ -37,7 +37,7 @@ of the file and a boolean value indicating whether this is a temporary file
meant to be cleaned up during the same buildout run:
>>> path, is_temp = download(server_url+'foo.txt')
>>> print
path
>>> print
_(path)
/.../buildout-...
>>> cat(path)
This is a foo text.
...
...
@@ -59,8 +59,8 @@ We are responsible for cleaning up temporary files behind us:
When trying to access a file that doesn't exist, we'll get an exception:
>>> try: download(server_url+'not-there') # doctest: +ELLIPSIS
... except: print
'download error'
... else: print
'woops'
... except: print
_('download error')
... else: print
_('woops')
download error
Downloading a local file doesn't produce a temporary file but simply returns
...
...
@@ -102,7 +102,7 @@ Finally, we can download the file to a specified place in the file system:
>>> target_dir = tmpdir('download-target')
>>> path, is_temp = download(server_url+'foo.txt',
... path=join(target_dir, 'downloaded.txt'))
>>> print
path
>>> print
_(path)
/download-target/downloaded.txt
>>> cat(path)
This is a foo text.
...
...
@@ -136,7 +136,7 @@ attribute upon instantiation:
>>> cache = tmpdir('download-cache')
>>> download = Download(cache=cache)
>>> print
download.cache_dir
>>> print
_(download.cache_dir)
/download-cache/
Simple usage
...
...
@@ -148,7 +148,7 @@ to the cached copy:
>>> ls(cache)
>>> path, is_temp = download(server_url+'foo.txt')
>>> print
path
>>> print
_(path)
/download-cache/foo.txt
>>> cat(path)
This is a foo text.
...
...
@@ -160,7 +160,7 @@ the file on the server to see this:
>>> write(server_data, 'foo.txt', 'The wrong text.')
>>> path, is_temp = download(server_url+'foo.txt')
>>> print
path
>>> print
_(path)
/download-cache/foo.txt
>>> cat(path)
This is a foo text.
...
...
@@ -179,7 +179,7 @@ will result in the cached copy being used:
>>> mkdir(server_data, 'other')
>>> write(server_data, 'other', 'foo.txt', 'The wrong text.')
>>> path, is_temp = download(server_url+'other/foo.txt')
>>> print
path
>>> print
_(path)
/download-cache/foo.txt
>>> cat(path)
This is a foo text.
...
...
@@ -194,7 +194,7 @@ cached copy:
>>> path, is_temp = download(server_url+'foo.txt',
... path=join(target_dir, 'downloaded.txt'))
>>> print
path
>>> print
_(path)
/download-target/downloaded.txt
>>> cat(path)
This is a foo text.
...
...
@@ -208,7 +208,7 @@ False
>>> path, is_temp = download(server_url+'foo.txt',
... path=join(target_dir, 'downloaded.txt'))
>>> print
path
>>> print
_(path)
/download-target/downloaded.txt
>>> cat(path)
This is a foo text.
...
...
@@ -281,7 +281,7 @@ namespaces to use, so the download utility stored files directly inside the
download cache. Let's use a namespace "test" instead:
>>> download = Download(cache=cache, namespace='test')
>>> print
download.cache_dir
>>> print
_(download.cache_dir)
/download-cache/test
The namespace sub-directory hasn't been created yet:
...
...
@@ -292,7 +292,7 @@ Downloading a file now creates the namespace sub-directory and places a copy
of the file inside it:
>>> path, is_temp = download(server_url+'foo.txt')
>>> print
path
>>> print
_(path)
/download-cache/test/foo.txt
>>> ls(cache)
d test
...
...
@@ -311,7 +311,7 @@ different content both on the server and in the cache's root directory:
>>> write(cache, 'foo.txt', 'The wrong text.')
>>> path, is_temp = download(server_url+'foo.txt')
>>> print
path
>>> print
_(path)
/download-cache/test/foo.txt
>>> cat(path)
This is a foo text.
...
...
@@ -332,7 +332,7 @@ be used as the filename in the cache:
>>> download = Download(cache=cache, hash_name=True)
>>> path, is_temp = download(server_url+'foo.txt')
>>> print
path
>>> print
_(path)
/download-cache/09f5793fcdc1716727f72d49519c688d
>>> cat(path)
This is a foo text.
...
...
@@ -362,7 +362,7 @@ file the same, the file will be downloaded again this time and put in the
cache under a different name:
>>> path2, is_temp = download(server_url+'other/foo.txt')
>>> print
path2
>>> print
_(path2)
/download-cache/537b6d73267f8f4447586989af8c470e
>>> path == path2
False
...
...
@@ -390,7 +390,7 @@ down or if we are in offline mode. This mode is only in effect if a download
cache is configured in the first place:
>>> download = Download(cache=cache, fallback=True)
>>> print
download.cache_dir
>>> print
_(download.cache_dir)
/download-cache/
A downloaded file will be cached:
...
...
@@ -408,8 +408,8 @@ If the file cannot be served, the cached copy will be used:
>>> remove(server_data, 'foo.txt')
>>> try: Download()(server_url+'foo.txt') # doctest: +ELLIPSIS
... except: print
'download error'
... else: print
'woops'
... except: print
_('download error')
... else: print
_('woops')
download error
>>> path, is_temp = download(server_url+'foo.txt')
>>> cat(path)
...
...
@@ -426,7 +426,7 @@ using the cache:
>>> offline_download = Download(cache=cache, offline=True, fallback=True)
>>> path, is_temp = offline_download(server_url+'foo.txt')
>>> print
path
>>> print
_(path)
/download-cache/foo.txt
>>> cat(path)
This is a foo text.
...
...
@@ -466,7 +466,7 @@ The location of the download cache is specified by the ``download-cache``
option:
>>> download = Download({'download-cache': cache}, namespace='cmmi')
>>> print
download.cache_dir
>>> print
_(download.cache_dir)
/download-cache/cmmi
If the ``download-cache`` option specifies a relative path, it is understood
...
...
@@ -474,18 +474,18 @@ relative to the current working directory, or to the buildout directory if
that is given:
>>> download = Download({'download-cache': 'relative-cache'})
>>> print
download.cache_dir
>>> print
_(download.cache_dir)
/sample-buildout/relative-cache/
>>> download = Download({'directory': join(sample_buildout, 'root'),
... 'download-cache': 'relative-cache'})
>>> print
download.cache_dir
>>> print
_(download.cache_dir)
/sample-buildout/root/relative-cache/
Keyword parameters take precedence over the corresponding options:
>>> download = Download({'download-cache': cache}, cache=None)
>>> print
download.cache_dir
>>> print
_(download.cache_dir)
None
Whether to assume offline mode can be inferred from either the ``offline`` or
...
...
src/zc/buildout/downloadcache.txt
View file @
83d53da5
...
...
@@ -31,7 +31,7 @@ And set up a buildout that downloads some eggs:
We specified a link server that has some distributions available for
download:
>>> print
get(link_server),
>>> print
_(get(link_server), end='')
<html><body>
<a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br>
<a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
...
...
@@ -59,7 +59,7 @@ We also specified a download cache.
If we run the buildout, we'll see the eggs installed from the link
server as usual:
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
GET 200 /
GET 200 /demo-0.2-py2.4.egg
GET 200 /demoneeded-1.2c1.zip
...
...
@@ -89,7 +89,7 @@ If we remove the installed eggs from eggs directory and re-run the buildout:
... if f.startswith('demo'):
... remove('eggs', f)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
GET 200 /
Updating eggs.
Getting distribution for 'demo==0.2'.
...
...
@@ -132,7 +132,7 @@ install-from-cache option set to true:
... eggs = demo
... ''' % globals())
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Uninstalling eggs.
Installing eggs.
Getting distribution for 'demo'.
...
...
src/zc/buildout/easy_install.py
View file @
83d53da5
...
...
@@ -611,8 +611,9 @@ class Installer:
while
1
:
try
:
ws
.
resolve
(
requirements
)
except
pkg_resources
.
DistributionNotFound
,
err
:
[
requirement
]
=
err
except
pkg_resources
.
DistributionNotFound
:
err
=
sys
.
exc_info
()[
1
]
[
requirement
]
=
err
.
args
requirement
=
self
.
_constrain
(
requirement
)
if
dest
:
logger
.
debug
(
'Getting required %r'
,
str
(
requirement
))
...
...
@@ -623,7 +624,8 @@ class Installer:
for
dist
in
self
.
_get_dist
(
requirement
,
ws
):
ws
.
add
(
dist
)
self
.
_maybe_add_distribute
(
ws
,
dist
)
except
pkg_resources
.
VersionConflict
,
err
:
except
pkg_resources
.
VersionConflict
:
err
=
sys
.
exc_info
()[
1
]
raise
VersionConflict
(
err
,
ws
)
else
:
break
...
...
@@ -813,12 +815,12 @@ def develop(setup, dest,
undo
.
append
(
lambda
:
os
.
remove
(
tsetup
))
undo
.
append
(
lambda
:
os
.
close
(
fd
))
os
.
write
(
fd
,
runsetup_template
%
dict
(
os
.
write
(
fd
,
(
runsetup_template
%
dict
(
distribute
=
distribute_loc
,
setupdir
=
directory
,
setup
=
setup
,
__file__
=
setup
,
))
))
.
encode
())
tmp3
=
tempfile
.
mkdtemp
(
'build'
,
dir
=
dest
)
undo
.
append
(
lambda
:
shutil
.
rmtree
(
tmp3
))
...
...
@@ -871,7 +873,7 @@ def scripts(reqs, working_set, executable, dest=None,
for
p
in
path
:
if
p
not
in
unique_path
:
unique_path
.
append
(
p
)
path
=
map
(
realpath
,
unique_path
)
path
=
list
(
map
(
realpath
,
unique_path
)
)
generated
=
[]
...
...
@@ -1073,7 +1075,7 @@ def _create_script(contents, dest):
logger
.
info
(
"Generated script %r."
,
script
)
try
:
os
.
chmod
(
dest
,
0755
)
os
.
chmod
(
dest
,
0
o
755
)
except
(
AttributeError
,
os
.
error
):
pass
...
...
@@ -1110,8 +1112,7 @@ sys.path[0:0] = [
]
%(initialization)s
%(original_content)s
'''
%(original_content)s'''
def
_pyscript
(
path
,
dest
,
rsetup
):
...
...
@@ -1142,7 +1143,7 @@ def _pyscript(path, dest, rsetup):
if
changed
:
open
(
dest
,
'w'
).
write
(
contents
)
try
:
os
.
chmod
(
dest
,
0755
)
os
.
chmod
(
dest
,
0
o
755
)
except
(
AttributeError
,
os
.
error
):
pass
logger
.
info
(
"Generated interpreter %r."
,
script
)
...
...
@@ -1167,7 +1168,7 @@ if len(sys.argv) > 1:
if _opt == '-i':
_interactive = True
elif _opt == '-c':
exec
_val
exec
(_val)
elif _opt == '-m':
sys.argv[1:] = _args
_args = []
...
...
@@ -1178,7 +1179,9 @@ if len(sys.argv) > 1:
sys.argv[:] = _args
__file__ = _args[0]
del _options, _args
execfile(__file__)
__file__f = open(__file__)
exec(compile(__file__f.read(), __file__, "exec"))
__file__f.close(); del __file__f
if _interactive:
del _interactive
...
...
@@ -1195,7 +1198,8 @@ __file__ = %(__file__)r
os.chdir(%(setupdir)r)
sys.argv[0] = %(setup)r
execfile(%(setup)r)
exec(compile(open(%(setup)r).read(), %(setup)r, 'exec'))
"""
...
...
src/zc/buildout/easy_install.txt
View file @
83d53da5
...
...
@@ -91,7 +91,7 @@ needed to meet the given requirements.
We have a link server that has a number of eggs:
>>> print
get(link_server),
>>> print
_(get(link_server), end='')
<html><body>
<a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br>
<a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
...
...
@@ -107,1216 +107,1222 @@ We have a link server that has a number of eggs:
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
</body></html>
Let's make a directory and install the demo egg to it, using the demo:
Let's make a directory and install the demo egg to it, using the demo:
>>> dest = tmpdir('sample-install')
>>> import zc.buildout.easy_install
>>> ws = zc.buildout.easy_install.install(
... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/')
We requested version 0.2 of the demo distribution to be installed into
the destination server. We specified that we should search for links
on the link server and that we should use the (empty) link server
index directory as a package index.
The working set contains the distributions we retrieved.
>>> for dist in ws:
... print dist
demo 0.2
demoneeded 1.1
We got demoneeded because it was a dependency of demo.
And the actual eggs were added to the eggs directory.
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
If we remove the version restriction on demo, but specify a false
value for newest, no new distributions will be installed:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... newest=False)
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
If we leave off the newest option, we'll get an update for demo:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/')
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.1-py2.4.egg
Note that we didn't get the newest versions available. There were
release candidates for newer versions of both packages. By default,
final releases are preferred. We can change this behavior using the
prefer_final function:
>>> zc.buildout.easy_install.prefer_final(False)
True
The old setting is returned.
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/')
>>> for dist in ws:
... print dist
demo 0.4c1
demoneeded 1.2c1
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demo-0.4c1-py2.4.egg
d demoneeded-1.1-py2.4.egg
d demoneeded-1.2c1-py2.4.egg
Let's put the setting back to the default.
>>> zc.buildout.easy_install.prefer_final(True)
False
We can supply additional distributions. We can also supply
specifications for distributions that would normally be found via
dependencies. We might do this to specify a specific version.
>>> ws = zc.buildout.easy_install.install(
... ['demo', 'other', 'demoneeded==1.0'], dest,
... links=[link_server], index=link_server+'index/')
>>> for dist in ws:
... print dist
demo 0.3
other 1.0
demoneeded 1.0
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demo-0.4c1-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d demoneeded-1.2c1-py2.4.egg
d other-1.0-py2.4.egg
>>> rmdir(dest)
Specifying version information independent of requirements
----------------------------------------------------------
Sometimes it's useful to specify version information independent of
normal requirements specifications. For example, a buildout may need
to lock down a set of versions, without having to put put version
numbers in setup files or part definitions. If a dictionary is passed
to the install function, mapping project names to version numbers,
then the versions numbers will be used.
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... versions = dict(demo='0.2', demoneeded='1.0'))
>>> [d.version for d in ws]
['0.2', '1.0']
In this example, we specified a version for demoneeded, even though we
didn't define a requirement for it. The versions specified apply to
dependencies as well as the specified requirements.
If we specify a version that's incompatible with a requirement, then
we'll get an error:
>>> from zope.testing.loggingsupport import InstalledHandler
>>> handler = InstalledHandler('zc.buildout.easy_install')
>>> import logging
>>> logging.getLogger('zc.buildout.easy_install').propagate = False
>>> ws = zc.buildout.easy_install.install(
... ['demo >0.2'], dest, links=[link_server],
... index=link_server+'index/',
... versions = dict(demo='0.2', demoneeded='1.0'))
Traceback (most recent call last):
...
IncompatibleVersionError: Bad version 0.2
>>> print handler
zc.buildout.easy_install DEBUG
Installing 'demo >0.2'.
zc.buildout.easy_install ERROR
The version, 0.2, is not consistent with the requirement, 'demo>0.2'.
>>> handler.clear()
If no versions are specified, a debugging message will be output
reporting that a version was picked automatically:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... )
>>> print handler
# doctest: +ELLIPSIS
zc.buildout.easy_install DEBUG
Installing 'demo'.
zc.buildout.easy_install INFO
Getting distribution for 'demo'.
zc.buildout.easy_install INFO
Got demo 0.3.
zc.buildout.easy_install DEBUG
Picked: demo = 0.3
zc.buildout.easy_install DEBUG
Getting required 'demoneeded'
zc.buildout.easy_install DEBUG
required by demo 0.3.
zc.buildout.easy_install INFO
Getting distribution for 'demoneeded'.
zc.buildout.easy_install DEBUG
Running easy_install:...
zc.buildout.easy_install INFO
Got demoneeded 1.1.
zc.buildout.easy_install DEBUG
Picked: demoneeded = 1.1
zc.buildout.easy_install DEBUG
Installing 'demo'.
zc.buildout.easy_install DEBUG
We have the best distribution that satisfies 'demo'.
zc.buildout.easy_install DEBUG
Picked: demo = 0.3
zc.buildout.easy_install DEBUG
Getting required 'demoneeded'
zc.buildout.easy_install DEBUG
required by demo 0.3.
zc.buildout.easy_install DEBUG
We have the best distribution that satisfies 'demoneeded'.
zc.buildout.easy_install DEBUG
Picked: demoneeded = 1.1
>>> handler.uninstall()
>>> logging.getLogger('zc.buildout.easy_install').propagate = True
We can request that we get an error if versions are picked:
>>> zc.buildout.easy_install.allow_picked_versions(False)
True
(The old setting is returned.)
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... )
Traceback (most recent call last):
...
UserError: Picked: demo = 0.3
>>> zc.buildout.easy_install.allow_picked_versions(True)
False
The function default_versions can be used to get and set default
version information to be used when no version information is passes.
If called with an argument, it sets the default versions:
>>> zc.buildout.easy_install.default_versions(dict(demoneeded='1'))
... # doctest: +ELLIPSIS
{...}
It always returns the previous default versions. If called without an
argument, it simply returns the default versions without changing
them:
>>> zc.buildout.easy_install.default_versions()
{'demoneeded': '1'}
So with the default versions set, we'll get the requested version even
if the versions option isn't used:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... )
>>> [d.version for d in ws]
['0.3', '1.0']
Of course, we can unset the default versions by passing an empty
dictionary:
>>> zc.buildout.easy_install.default_versions({})
{'demoneeded': '1'}
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... )
>>> [d.version for d in ws]
['0.3', '1.1']
Dependency links
----------------
Setuptools allows metadata that describes where to search for package
dependencies. This option is called dependency_links. Buildout has its
own notion of where to look for dependencies, but it also uses the
setup tools dependency_links information if it's available.
Let's demo this by creating an egg that specifies dependency_links.
To begin, let's create a new egg repository. This repository hold a
newer version of the 'demoneeded' egg than the sample repository does.
>>> repoloc = tmpdir('repo')
>>> from zc.buildout.tests import create_egg
>>> create_egg('demoneeded', '1.2', repoloc)
>>> link_server2 = start_server(repoloc)
Turn on logging on this server so that we can see when eggs are pulled
from it.
>>> get(link_server2 + 'enable_server_logging')
GET 200 /enable_server_logging
''
>>> dest = tmpdir('sample-install')
>>> import zc.buildout.easy_install
>>> ws = zc.buildout.easy_install.install(
... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/')
We requested version 0.2 of the demo distribution to be installed into
the destination server. We specified that we should search for links
on the link server and that we should use the (empty) link server
index directory as a package index.
The working set contains the distributions we retrieved.
>>> for dist in ws:
... print_(dist)
demo 0.2
demoneeded 1.1
We got demoneeded because it was a dependency of demo.
And the actual eggs were added to the eggs directory.
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
If we remove the version restriction on demo, but specify a false
value for newest, no new distributions will be installed:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... newest=False)
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
If we leave off the newest option, we'll get an update for demo:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/')
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.1-py2.4.egg
Note that we didn't get the newest versions available. There were
release candidates for newer versions of both packages. By default,
final releases are preferred. We can change this behavior using the
prefer_final function:
>>> zc.buildout.easy_install.prefer_final(False)
True
The old setting is returned.
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/')
>>> for dist in ws:
... print_(dist)
demo 0.4c1
demoneeded 1.2c1
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demo-0.4c1-py2.4.egg
d demoneeded-1.1-py2.4.egg
d demoneeded-1.2c1-py2.4.egg
Let's put the setting back to the default.
>>> zc.buildout.easy_install.prefer_final(True)
False
We can supply additional distributions. We can also supply
specifications for distributions that would normally be found via
dependencies. We might do this to specify a specific version.
>>> ws = zc.buildout.easy_install.install(
... ['demo', 'other', 'demoneeded==1.0'], dest,
... links=[link_server], index=link_server+'index/')
>>> for dist in ws:
... print_(dist)
demo 0.3
other 1.0
demoneeded 1.0
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demo-0.4c1-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d demoneeded-1.2c1-py2.4.egg
d other-1.0-py2.4.egg
>>> rmdir(dest)
Specifying version information independent of requirements
----------------------------------------------------------
Sometimes it's useful to specify version information independent of
normal requirements specifications. For example, a buildout may need
to lock down a set of versions, without having to put put version
numbers in setup files or part definitions. If a dictionary is passed
to the install function, mapping project names to version numbers,
then the versions numbers will be used.
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... versions = dict(demo='0.2', demoneeded='1.0'))
>>> [d.version for d in ws]
['0.2', '1.0']
In this example, we specified a version for demoneeded, even though we
didn't define a requirement for it. The versions specified apply to
dependencies as well as the specified requirements.
If we specify a version that's incompatible with a requirement, then
we'll get an error:
>>> from zope.testing.loggingsupport import InstalledHandler
>>> handler = InstalledHandler('zc.buildout.easy_install')
>>> import logging
>>> logging.getLogger('zc.buildout.easy_install').propagate = False
>>> ws = zc.buildout.easy_install.install(
... ['demo >0.2'], dest, links=[link_server],
... index=link_server+'index/',
... versions = dict(demo='0.2', demoneeded='1.0'))
Traceback (most recent call last):
...
IncompatibleVersionError: Bad version 0.2
>>> print_(handler)
zc.buildout.easy_install DEBUG
Installing 'demo >0.2'.
zc.buildout.easy_install ERROR
The version, 0.2, is not consistent with the requirement, 'demo>0.2'.
>>> handler.clear()
If no versions are specified, a debugging message will be output
reporting that a version was picked automatically:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... )
>>> print_(handler)
# doctest: +ELLIPSIS
zc.buildout.easy_install DEBUG
Installing 'demo'.
zc.buildout.easy_install INFO
Getting distribution for 'demo'.
zc.buildout.easy_install INFO
Got demo 0.3.
zc.buildout.easy_install DEBUG
Picked: demo = 0.3
zc.buildout.easy_install DEBUG
Getting required 'demoneeded'
zc.buildout.easy_install DEBUG
required by demo 0.3.
zc.buildout.easy_install INFO
Getting distribution for 'demoneeded'.
zc.buildout.easy_install DEBUG
Running easy_install:...
zc.buildout.easy_install INFO
Got demoneeded 1.1.
zc.buildout.easy_install DEBUG
Picked: demoneeded = 1.1
zc.buildout.easy_install DEBUG
Installing 'demo'.
zc.buildout.easy_install DEBUG
We have the best distribution that satisfies 'demo'.
zc.buildout.easy_install DEBUG
Picked: demo = 0.3
zc.buildout.easy_install DEBUG
Getting required 'demoneeded'
zc.buildout.easy_install DEBUG
required by demo 0.3.
zc.buildout.easy_install DEBUG
We have the best distribution that satisfies 'demoneeded'.
zc.buildout.easy_install DEBUG
Picked: demoneeded = 1.1
>>> handler.uninstall()
>>> logging.getLogger('zc.buildout.easy_install').propagate = True
We can request that we get an error if versions are picked:
>>> zc.buildout.easy_install.allow_picked_versions(False)
True
(The old setting is returned.)
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... )
Traceback (most recent call last):
...
UserError: Picked: demo = 0.3
>>> zc.buildout.easy_install.allow_picked_versions(True)
False
The function default_versions can be used to get and set default
version information to be used when no version information is passes.
If called with an argument, it sets the default versions:
>>> zc.buildout.easy_install.default_versions(dict(demoneeded='1'))
... # doctest: +ELLIPSIS
{...}
It always returns the previous default versions. If called without an
argument, it simply returns the default versions without changing
them:
>>> zc.buildout.easy_install.default_versions()
{'demoneeded': '1'}
So with the default versions set, we'll get the requested version even
if the versions option isn't used:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... )
>>> [d.version for d in ws]
['0.3', '1.0']
Of course, we can unset the default versions by passing an empty
dictionary:
>>> zc.buildout.easy_install.default_versions({})
{'demoneeded': '1'}
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... )
>>> [d.version for d in ws]
['0.3', '1.1']
Dependency links
----------------
Setuptools allows metadata that describes where to search for package
dependencies. This option is called dependency_links. Buildout has its
own notion of where to look for dependencies, but it also uses the
setup tools dependency_links information if it's available.
Let's demo this by creating an egg that specifies dependency_links.
To begin, let's create a new egg repository. This repository hold a
newer version of the 'demoneeded' egg than the sample repository does.
>>> repoloc = tmpdir('repo')
>>> from zc.buildout.tests import create_egg
>>> create_egg('demoneeded', '1.2', repoloc)
>>> link_server2 = start_server(repoloc)
Turn on logging on this server so that we can see when eggs are pulled
from it.
>>> get(link_server2 + 'enable_server_logging')
GET 200 /enable_server_logging
''
Now we can create an egg that specifies that its dependencies are
found on this server.
>>> repoloc = tmpdir('repo2')
>>> create_egg('hasdeps', '1.0', repoloc,
... install_requires = "'demoneeded'",
... dependency_links = [link_server2])
Now we can create an egg that specifies that its dependencies are
found on this server.
>>> repoloc = tmpdir('repo2')
>>> create_egg('hasdeps', '1.0', repoloc,
... install_requires = "'demoneeded'",
... dependency_links = [link_server2])
Let's add the egg to another repository.
Let's add the egg to another repository.
>>> link_server3 = start_server(repoloc)
>>> link_server3 = start_server(repoloc)
Now let's install the egg.
Now let's install the egg.
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest,
... links=[link_server3], index=link_server3+'index/')
GET 200 /
GET 200 /demoneeded-1.2-pyN.N.egg
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest,
... links=[link_server3], index=link_server3+'index/')
GET 200 /
GET 200 /demoneeded-1.2-pyN.N.egg
The server logs show that the dependency was retrieved from the server
specified in the dependency_links.
The server logs show that the dependency was retrieved from the server
specified in the dependency_links.
Now let's see what happens if we provide two different ways to retrieve
the dependencies.
Now let's see what happens if we provide two different ways to retrieve
the dependencies.
>>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3])
GET 200 /
GET 200 /demoneeded-1.2-pyN.N.egg
>>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3])
GET 200 /
GET 200 /demoneeded-1.2-pyN.N.egg
Once again the dependency is fetched from the logging server even
though it is also available from the non-logging server. This is
because the version on the logging server is newer and buildout
normally chooses the newest egg available.
Once again the dependency is fetched from the logging server even
though it is also available from the non-logging server. This is
because the version on the logging server is newer and buildout
normally chooses the newest egg available.
If you wish to control where dependencies come from regardless of
dependency_links setup metadata use the 'use_dependency_links' option
to zc.buildout.easy_install.install().
If you wish to control where dependencies come from regardless of
dependency_links setup metadata use the 'use_dependency_links' option
to zc.buildout.easy_install.install().
>>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3],
... use_dependency_links=False)
>>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3],
... use_dependency_links=False)
Notice that this time the dependency egg is not fetched from the
logging server. When you specify not to use dependency_links, eggs
will only be searched for using the links you explicitly provide.
Notice that this time the dependency egg is not fetched from the
logging server. When you specify not to use dependency_links, eggs
will only be searched for using the links you explicitly provide.
Another way to control this option is with the
zc.buildout.easy_install.use_dependency_links() function. This
function sets the default behavior for the zc.buildout.easy_install()
function.
Another way to control this option is with the
zc.buildout.easy_install.use_dependency_links() function. This
function sets the default behavior for the zc.buildout.easy_install()
function.
>>> zc.buildout.easy_install.use_dependency_links(False)
True
>>> zc.buildout.easy_install.use_dependency_links(False)
True
The function returns its previous setting.
The function returns its previous setting.
>>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3])
>>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3])
It can be overridden by passing a keyword argument to the install
function.
It can be overridden by passing a keyword argument to the install
function.
>>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3],
... use_dependency_links=True)
GET 200 /demoneeded-1.2-pyN.N.egg
>>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3],
... use_dependency_links=True)
GET 200 /demoneeded-1.2-pyN.N.egg
To return the dependency_links behavior to normal call the function again.
To return the dependency_links behavior to normal call the function again.
>>> zc.buildout.easy_install.use_dependency_links(True)
False
>>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3])
GET 200 /demoneeded-1.2-pyN.N.egg
>>> zc.buildout.easy_install.use_dependency_links(True)
False
>>> rmdir(example_dest)
>>> example_dest = tmpdir('example-install')
>>> workingset = zc.buildout.easy_install.install(
... ['hasdeps'], example_dest, index=link_server+'index/',
... links=[link_server, link_server3])
GET 200 /demoneeded-1.2-pyN.N.egg
Script generation
-----------------
Script generation
-----------------
The easy_install module provides support for creating scripts from
eggs. It provides a function similar to setuptools except that it
provides facilities for baking a script's path into the script. This
has two advantages:
The easy_install module provides support for creating scripts from
eggs. It provides a function similar to setuptools except that it
provides facilities for baking a script's path into the script. This
has two advantages:
- The eggs to be used by a script are not chosen at run time, making
startup faster and, more importantly, deterministic.
- The eggs to be used by a script are not chosen at run time, making
startup faster and, more importantly, deterministic.
- The script doesn't have to import pkg_resources because the logic
that pkg_resources would execute at run time is executed at
script-creation time.
- The script doesn't have to import pkg_resources because the logic
that pkg_resources would execute at run time is executed at
script-creation time.
The scripts method can be used to generate scripts. Let's create a
destination directory for it to place them in:
>>> import tempfile
>>> bin = tmpdir('bin')
Now, we'll use the scripts method to generate scripts in this directory
from the demo egg:
The scripts method can be used to generate scripts. Let's create a
destination directory for it to place them in:
>>> import tempfile
>>> bin = tmpdir('bin')
Now, we'll use the scripts method to generate scripts in this directory
from the demo egg:
>>> import sys
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin)
>>> import sys
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin)
the three arguments we passed were:
the three arguments we passed were:
1. A sequence of distribution requirements. These are of the same
form as setuptools requirements. Here we passed a single
requirement, for the version 0.1 demo distribution.
2. A working set,
3. The destination directory.
The bin directory now contains a generated script:
>>> ls(bin)
- demo
The return value is a list of the scripts generated:
>>> import os, sys
>>> if sys.platform == 'win32':
... scripts == [os.path.join(bin, 'demo.exe'),
... os.path.join(bin, 'demo-script.py')]
... else:
... scripts == [os.path.join(bin, 'demo')]
True
Note that in Windows, 2 files are generated for each script. A script
file, ending in '-script.py', and an exe file that allows the script
to be invoked directly without having to specify the Python
interpreter and without having to provide a '.py' suffix.
The demo script run the entry point defined in the demo egg:
>>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg',
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main())
Some things to note:
- The demo and demoneeded eggs are added to the beginning of sys.path.
- The module for the script entry point is imported and the entry
point, in this case, 'main', is run.
Rather than requirement strings, you can pass tuples containing 3
strings:
- A script name,
- A module,
- An attribute expression for an entry point within the module.
For example, we could have passed entry point information directly
rather than passing a requirement:
>>> scripts = zc.buildout.easy_install.scripts(
... [('demo', 'eggrecipedemo', 'main')], ws,
... sys.executable, bin)
>>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg',
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main())
Passing entry-point information directly is handy when using eggs (or
distributions) that don't declare their entry points, such as
distributions that aren't based on setuptools.
The interpreter keyword argument can be used to generate a script that can
be used to invoke the Python interactive interpreter with the path set
based on the working set. This generated script can also be used to
run other scripts with the path set on the working set:
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, interpreter='py')
>>> ls(bin)
- demo
- py
>>> if sys.platform == 'win32':
... scripts == [os.path.join(bin, 'demo.exe'),
... os.path.join(bin, 'demo-script.py'),
... os.path.join(bin, 'py.exe'),
... os.path.join(bin, 'py-script.py')]
... else:
... scripts == [os.path.join(bin, 'demo'),
... os.path.join(bin, 'py')]
True
The py script simply runs the Python interactive interpreter with
the path set:
>>> cat(bin, 'py') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
<BLANKLINE>
sys.path[0:0] = [
'/sample-install/demo-0.3-pyN.N.egg',
'/sample-install/demoneeded-1.1-pyN.N.egg',
]
<BLANKLINE>
_interactive = True
if len(sys.argv) > 1:
_options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
_interactive = False
for (_opt, _val) in _options:
if _opt == '-i':
_interactive = True
elif _opt == '-c':
exec _val
elif _opt == '-m':
sys.argv[1:] = _args
_args = []
__import__("runpy").run_module(
_val, {}, "__main__", alter_sys=True)
<BLANKLINE>
if _args:
sys.argv[:] = _args
__file__ = _args[0]
del _options, _args
execfile(__file__)
<BLANKLINE>
if _interactive:
del _interactive
__import__("code").interact(banner="", local=globals())
If invoked with a script name and arguments, it will run that script, instead.
>>> write('ascript', '''
... "demo doc"
... print sys.argv
... print (__name__, __file__, __doc__)
... ''')
>>> print system(join(bin, 'py')+' ascript a b c'),
['ascript', 'a', 'b', 'c']
('__main__', 'ascript', 'demo doc')
For Python 2.5 and higher, you can also use the -m option to run a
module:
>>> print system(join(bin, 'py')+' -m pdb'),
usage: pdb.py scriptfile [arg] ...
>>> print system(join(bin, 'py')+' -m pdb what'),
Error: what does not exist
An additional argument can be passed to define which scripts to install
and to provide script names. The argument is a dictionary mapping
original script names to new script names.
>>> bin = tmpdir('bin2')
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, dict(demo='run'))
>>> if sys.platform == 'win32':
... scripts == [os.path.join(bin, 'run.exe'),
... os.path.join(bin, 'run-script.py')]
... else:
... scripts == [os.path.join(bin, 'run')]
True
>>> ls(bin)
- run
>>> print system(os.path.join(bin, 'run')),
3 1
Including extra paths in scripts
--------------------------------
We can pass a keyword argument, extra paths, to cause additional paths
to be included in the a generated script:
>>> foo = tmpdir('foo')
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, dict(demo='run'),
... extra_paths=[foo])
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg',
'/foo',
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main())
Providing script arguments
--------------------------
An "argument" keyword argument can be used to pass arguments to an
entry point. The value passed is a source string to be placed between the
parentheses in the call:
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, dict(demo='run'),
... arguments='1, 2')
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg',
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main(1, 2))
Passing initialization code
---------------------------
You can also pass script initialization code:
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, dict(demo='run'),
... arguments='1, 2',
... initialization='import os\nos.chdir("foo")')
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg',
]
<BLANKLINE>
import os
os.chdir("foo")
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main(1, 2))
Relative paths
--------------
Sometimes, you want to be able to move a buildout directory around and
have scripts still work without having to rebuild them. We can
control this using the relative_paths option to install. You need
to pass a common base directory of the scripts and eggs:
>>> bo = tmpdir('bo')
>>> ba = tmpdir('ba')
>>> mkdir(bo, 'eggs')
>>> mkdir(bo, 'bin')
>>> mkdir(bo, 'other')
>>> ws = zc.buildout.easy_install.install(
... ['demo'], join(bo, 'eggs'), links=[link_server],
... index=link_server+'index/')
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, join(bo, 'bin'), dict(demo='run'),
... extra_paths=[ba, join(bo, 'bar')],
... interpreter='py',
... relative_paths=bo)
>>> cat(bo, 'bin', 'run')
#!/usr/local/bin/python2.7
<BLANKLINE>
import os
<BLANKLINE>
join = os.path.join
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
base = os.path.dirname(base)
<BLANKLINE>
import sys
sys.path[0:0] = [
join(base, 'eggs/demo-0.3-pyN.N.egg'),
join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
'/ba',
join(base, 'bar'),
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main())
Note that the extra path we specified that was outside the directory
passed as relative_paths wasn't converted to a relative path.
Of course, running the script works:
>>> print system(join(bo, 'bin', 'run')),
3 1
We specified an interpreter and its paths are adjusted too:
>>> cat(bo, 'bin', 'py')
#!/usr/local/bin/python2.7
<BLANKLINE>
import os
<BLANKLINE>
join = os.path.join
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
base = os.path.dirname(base)
<BLANKLINE>
import sys
<BLANKLINE>
sys.path[0:0] = [
join(base, 'eggs/demo-0.3-pyN.N.egg'),
join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
'/ba',
join(base, 'bar'),
]
<BLANKLINE>
_interactive = True
if len(sys.argv) > 1:
_options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
_interactive = False
for (_opt, _val) in _options:
if _opt == '-i':
_interactive = True
elif _opt == '-c':
exec _val
elif _opt == '-m':
sys.argv[1:] = _args
_args = []
__import__("runpy").run_module(
_val, {}, "__main__", alter_sys=True)
<BLANKLINE>
if _args:
sys.argv[:] = _args
__file__ = _args[0]
del _options, _args
execfile(__file__)
<BLANKLINE>
if _interactive:
del _interactive
__import__("code").interact(banner="", local=globals())
Installing distutils-style scripts
----------------------------------
Most python libraries use the console_scripts entry point nowadays. But
several still have a ``scripts=['bin/something']`` in their setup() call.
Buildout also installs those:
>>> distdir = tmpdir('distutilsscriptdir')
>>> distbin = tmpdir('distutilsscriptbin')
>>> ws = zc.buildout.easy_install.install(
... ['other'], distdir,
... links=[link_server], index=link_server+'index/')
>>> scripts = zc.buildout.easy_install.scripts(
... ['other'], ws, sys.executable, distbin)
>>> ls(distbin)
- distutilsscript
It also works for zipped eggs:
>>> distdir2 = tmpdir('distutilsscriptdir2')
>>> distbin2 = tmpdir('distutilsscriptbin2')
>>> ws = zc.buildout.easy_install.install(
... ['du_zipped'], distdir2,
... links=[link_server], index=link_server+'index/')
>>> scripts = zc.buildout.easy_install.scripts(
... ['du_zipped'], ws, sys.executable, distbin2)
>>> ls(distbin2)
- distutilsscript
Distutils copies the script files verbatim, apart from a line at the top that
looks like ``#!/usr/bin/python``, which gets replaced by the actual python
interpreter. Buildout does the same, but additionally also adds the sys.path
like for the console_scripts:
>>> cat(distbin, 'distutilsscript')
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
'/distutilsscriptdir/other-1.0-pyN.N.egg',
]
<BLANKLINE>
<BLANKLINE>
print "distutils!"
Due to the nature of distutils scripts, buildout cannot pass arguments as
there's no specific method to pass them to.
Handling custom build options for extensions provided in source distributions
-----------------------------------------------------------------------------
Sometimes, we need to control how extension modules are built. The
build function provides this level of control. It takes a single
package specification, downloads a source distribution, and builds it
with specified custom build options.
The build function takes 3 positional arguments:
spec
A package specification for a source distribution
dest
A destination directory
build_ext
A dictionary of options to be passed to the distutils build_ext
command when building extensions.
1. A sequence of distribution requirements. These are of the same
form as setuptools requirements. Here we passed a single
requirement, for the version 0.1 demo distribution.
2. A working set,
3. The destination directory.
The bin directory now contains a generated script:
>>> ls(bin)
- demo
The return value is a list of the scripts generated:
>>> import os, sys
>>> if sys.platform == 'win32':
... scripts == [os.path.join(bin, 'demo.exe'),
... os.path.join(bin, 'demo-script.py')]
... else:
... scripts == [os.path.join(bin, 'demo')]
True
Note that in Windows, 2 files are generated for each script. A script
file, ending in '-script.py', and an exe file that allows the script
to be invoked directly without having to specify the Python
interpreter and without having to provide a '.py' suffix.
The demo script run the entry point defined in the demo egg:
>>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg',
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main())
Some things to note:
- The demo and demoneeded eggs are added to the beginning of sys.path.
- The module for the script entry point is imported and the entry
point, in this case, 'main', is run.
Rather than requirement strings, you can pass tuples containing 3
strings:
- A script name,
- A module,
- An attribute expression for an entry point within the module.
For example, we could have passed entry point information directly
rather than passing a requirement:
>>> scripts = zc.buildout.easy_install.scripts(
... [('demo', 'eggrecipedemo', 'main')], ws,
... sys.executable, bin)
>>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg',
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main())
Passing entry-point information directly is handy when using eggs (or
distributions) that don't declare their entry points, such as
distributions that aren't based on setuptools.
The interpreter keyword argument can be used to generate a script that can
be used to invoke the Python interactive interpreter with the path set
based on the working set. This generated script can also be used to
run other scripts with the path set on the working set:
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, interpreter='py')
>>> ls(bin)
- demo
- py
>>> if sys.platform == 'win32':
... scripts == [os.path.join(bin, 'demo.exe'),
... os.path.join(bin, 'demo-script.py'),
... os.path.join(bin, 'py.exe'),
... os.path.join(bin, 'py-script.py')]
... else:
... scripts == [os.path.join(bin, 'demo'),
... os.path.join(bin, 'py')]
True
The py script simply runs the Python interactive interpreter with
the path set:
>>> cat(bin, 'py') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
<BLANKLINE>
sys.path[0:0] = [
'/sample-install/demo-0.3-pyN.N.egg',
'/sample-install/demoneeded-1.1-pyN.N.egg',
]
<BLANKLINE>
_interactive = True
if len(sys.argv) > 1:
_options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
_interactive = False
for (_opt, _val) in _options:
if _opt == '-i':
_interactive = True
elif _opt == '-c':
exec(_val)
elif _opt == '-m':
sys.argv[1:] = _args
_args = []
__import__("runpy").run_module(
_val, {}, "__main__", alter_sys=True)
<BLANKLINE>
if _args:
sys.argv[:] = _args
__file__ = _args[0]
del _options, _args
__file__f = open(__file__)
exec(compile(__file__f.read(), __file__, "exec"))
__file__f.close(); del __file__f
<BLANKLINE>
if _interactive:
del _interactive
__import__("code").interact(banner="", local=globals())
If invoked with a script name and arguments, it will run that script, instead.
>>> write('ascript', r'''
... "demo doc"
... import sys
... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\n')
... print_(sys.argv)
... print_((__name__, __file__, __doc__))
... ''')
>>> print_(system(join(bin, 'py')+' ascript a b c'), end='')
['ascript', 'a', 'b', 'c']
('__main__', 'ascript', 'demo doc')
For Python 2.5 and higher, you can also use the -m option to run a
module:
>>> print_(system(join(bin, 'py')+' -m pdb'), end='') # doctest: +ELLIPSIS
usage: pdb.py ...
>>> print_(system(join(bin, 'py')+' -m pdb what'), end='')
Error: what does not exist
An additional argument can be passed to define which scripts to install
and to provide script names. The argument is a dictionary mapping
original script names to new script names.
>>> bin = tmpdir('bin2')
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, dict(demo='run'))
>>> if sys.platform == 'win32':
... scripts == [os.path.join(bin, 'run.exe'),
... os.path.join(bin, 'run-script.py')]
... else:
... scripts == [os.path.join(bin, 'run')]
True
>>> ls(bin)
- run
>>> print_(system(os.path.join(bin, 'run')), end='')
3 1
Including extra paths in scripts
--------------------------------
We can pass a keyword argument, extra paths, to cause additional paths
to be included in the a generated script:
>>> foo = tmpdir('foo')
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, dict(demo='run'),
... extra_paths=[foo])
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg',
'/foo',
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main())
Providing script arguments
--------------------------
An "argument" keyword argument can be used to pass arguments to an
entry point. The value passed is a source string to be placed between the
parentheses in the call:
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, dict(demo='run'),
... arguments='1, 2')
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg',
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main(1, 2))
Passing initialization code
---------------------------
You can also pass script initialization code:
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, dict(demo='run'),
... arguments='1, 2',
... initialization='import os\nos.chdir("foo")')
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
'/sample-install/demoneeded-1.1-py2.4.egg',
]
<BLANKLINE>
import os
os.chdir("foo")
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main(1, 2))
Relative paths
--------------
Sometimes, you want to be able to move a buildout directory around and
have scripts still work without having to rebuild them. We can
control this using the relative_paths option to install. You need
to pass a common base directory of the scripts and eggs:
>>> bo = tmpdir('bo')
>>> ba = tmpdir('ba')
>>> mkdir(bo, 'eggs')
>>> mkdir(bo, 'bin')
>>> mkdir(bo, 'other')
>>> ws = zc.buildout.easy_install.install(
... ['demo'], join(bo, 'eggs'), links=[link_server],
... index=link_server+'index/')
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, join(bo, 'bin'), dict(demo='run'),
... extra_paths=[ba, join(bo, 'bar')],
... interpreter='py',
... relative_paths=bo)
>>> cat(bo, 'bin', 'run')
#!/usr/local/bin/python2.7
<BLANKLINE>
import os
<BLANKLINE>
join = os.path.join
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
base = os.path.dirname(base)
<BLANKLINE>
import sys
sys.path[0:0] = [
join(base, 'eggs/demo-0.3-pyN.N.egg'),
join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
'/ba',
join(base, 'bar'),
]
<BLANKLINE>
import eggrecipedemo
<BLANKLINE>
if __name__ == '__main__':
sys.exit(eggrecipedemo.main())
Note that the extra path we specified that was outside the directory
passed as relative_paths wasn't converted to a relative path.
Of course, running the script works:
>>> print_(system(join(bo, 'bin', 'run')), end='')
3 1
We specified an interpreter and its paths are adjusted too:
>>> cat(bo, 'bin', 'py')
#!/usr/local/bin/python2.7
<BLANKLINE>
import os
<BLANKLINE>
join = os.path.join
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
base = os.path.dirname(base)
<BLANKLINE>
import sys
<BLANKLINE>
sys.path[0:0] = [
join(base, 'eggs/demo-0.3-pyN.N.egg'),
join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
'/ba',
join(base, 'bar'),
]
<BLANKLINE>
_interactive = True
if len(sys.argv) > 1:
_options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
_interactive = False
for (_opt, _val) in _options:
if _opt == '-i':
_interactive = True
elif _opt == '-c':
exec(_val)
elif _opt == '-m':
sys.argv[1:] = _args
_args = []
__import__("runpy").run_module(
_val, {}, "__main__", alter_sys=True)
<BLANKLINE>
if _args:
sys.argv[:] = _args
__file__ = _args[0]
del _options, _args
__file__f = open(__file__)
exec(compile(__file__f.read(), __file__, "exec"))
__file__f.close(); del __file__f
<BLANKLINE>
if _interactive:
del _interactive
__import__("code").interact(banner="", local=globals())
Installing distutils-style scripts
----------------------------------
Most python libraries use the console_scripts entry point nowadays. But
several still have a ``scripts=['bin/something']`` in their setup() call.
Buildout also installs those:
>>> distdir = tmpdir('distutilsscriptdir')
>>> distbin = tmpdir('distutilsscriptbin')
>>> ws = zc.buildout.easy_install.install(
... ['other'], distdir,
... links=[link_server], index=link_server+'index/')
>>> scripts = zc.buildout.easy_install.scripts(
... ['other'], ws, sys.executable, distbin)
>>> ls(distbin)
- distutilsscript
It also works for zipped eggs:
>>> distdir2 = tmpdir('distutilsscriptdir2')
>>> distbin2 = tmpdir('distutilsscriptbin2')
>>> ws = zc.buildout.easy_install.install(
... ['du_zipped'], distdir2,
... links=[link_server], index=link_server+'index/')
>>> scripts = zc.buildout.easy_install.scripts(
... ['du_zipped'], ws, sys.executable, distbin2)
>>> ls(distbin2)
- distutilsscript
Distutils copies the script files verbatim, apart from a line at the top that
looks like ``#!/usr/bin/python``, which gets replaced by the actual python
interpreter. Buildout does the same, but additionally also adds the sys.path
like for the console_scripts:
>>> cat(distbin, 'distutilsscript')
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
'/distutilsscriptdir/other-1.0-pyN.N.egg',
]
<BLANKLINE>
<BLANKLINE>
import sys; sys.stdout.write("distutils!\n")
Due to the nature of distutils scripts, buildout cannot pass arguments as
there's no specific method to pass them to.
Handling custom build options for extensions provided in source distributions
-----------------------------------------------------------------------------
Sometimes, we need to control how extension modules are built. The
build function provides this level of control. It takes a single
package specification, downloads a source distribution, and builds it
with specified custom build options.
The build function takes 3 positional arguments:
spec
A package specification for a source distribution
dest
A destination directory
build_ext
A dictionary of options to be passed to the distutils build_ext
command when building extensions.
It supports a number of optional keyword arguments:
links
a sequence of URLs, file names, or directories to look for
links to distributions,
index
The URL of an index server, or almost any other valid URL. :)
If not specified, the Python Package Index,
http://pypi.python.org/simple/, is used. You can specify an
alternate index with this option. If you use the links option and
if the links point to the needed distributions, then the index can
be anything and will be largely ignored. In the examples, here,
we'll just point to an empty directory on our link server. This
will make our examples run a little bit faster.
path
A list of additional directories to search for locally-installed
distributions.
newest
A boolean value indicating whether to search for new distributions
when already-installed distributions meet the requirement. When
this is true, the default, and when the destination directory is
not None, then the install function will search for the newest
distributions that satisfy the requirements.
versions
A dictionary mapping project names to version numbers to be used
when selecting distributions. This can be used to specify a set of
distribution versions independent of other requirements.
Our link server included a source distribution that includes a simple
extension, extdemo.c::
#include <Python.h>
#include <extdemo.h>
static PyMethodDef methods[] = {};
PyMODINIT_FUNC
initextdemo(void)
{
PyObject *m;
m = Py_InitModule3("extdemo", methods, "");
#ifdef TWO
PyModule_AddObject(m, "val", PyInt_FromLong(2));
#else
PyModule_AddObject(m, "val", PyInt_FromLong(EXTDEMO));
#endif
}
The extension depends on a system-dependent include file, extdemo.h,
that defines a constant, EXTDEMO, that is exposed by the extension.
We'll add an include directory to our sample buildout and add the
needed include file to it:
>>> mkdir('include')
>>> write('include', 'extdemo.h',
... """
... #define EXTDEMO 42
... """)
Now, we can use the build function to create an egg from the source
distribution:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
['/sample-install/extdemo-1.4-py2.4-unix-i686.egg']
The function returns the list of eggs
Now if we look in our destination directory, we see we have an extdemo egg:
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
Let's update our link server with a new version of extdemo:
>>> update_extdemo()
>>> print_(get(link_server), end='')
<html><body>
<a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br>
<a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
<a href="demo-0.2-py2.4.egg">demo-0.2-py2.4.egg</a><br>
<a href="demo-0.3-py2.4.egg">demo-0.3-py2.4.egg</a><br>
<a href="demo-0.4c1-py2.4.egg">demo-0.4c1-py2.4.egg</a><br>
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
<a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
<a href="du_zipped-1.0-pyN.N.egg">du_zipped-1.0-pyN.N.egg</a><br>
<a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
<a href="extdemo-1.5.zip">extdemo-1.5.zip</a><br>
<a href="index/">index/</a><br>
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
</body></html>
The easy_install caches information about servers to reduce network
access. To see the update, we have to call the clear_index_cache
function to clear the index cache:
>>> zc.buildout.easy_install.clear_index_cache()
If we run build with newest set to False, we won't get an update:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/',
... newest=False)
['/sample-install/extdemo-1.4-py2.4-linux-i686.egg']
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
But if we run it with the default True setting for newest, then we'll
get an updated egg:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
['/sample-install/extdemo-1.5-py2.4-unix-i686.egg']
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
d extdemo-1.5-py2.4-unix-i686.egg
The versions option also influences the versions used. For example,
if we specify a version for extdemo, then that will be used, even
though it isn't the newest. Let's clean out the destination directory
first:
>>> import os
>>> for name in os.listdir(dest):
... remove(dest, name)
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/',
... versions=dict(extdemo='1.4'))
['/sample-install/extdemo-1.4-py2.4-unix-i686.egg']
>>> ls(dest)
d extdemo-1.4-py2.4-unix-i686.egg
Handling custom build options for extensions in develop eggs
------------------------------------------------------------
The develop function is similar to the build function, except that,
rather than building an egg from a source directory containing a
setup.py script.
The develop function takes 2 positional arguments:
setup
The path to a setup script, typically named "setup.py", or a
directory containing a setup.py script.
dest
The directory to install the egg link to
It supports some optional keyword argument:
build_ext
A dictionary of options to be passed to the distutils build_ext
command when building extensions.
We have a local directory containing the extdemo source:
>>> ls(extdemo)
- MANIFEST
- MANIFEST.in
- README
- extdemo.c
- setup.py
Now, we can use the develop function to create a develop egg from the source
distribution:
>>> zc.buildout.easy_install.develop(
... extdemo, dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')})
'/sample-install/extdemo.egg-link'
The name of the egg link created is returned.
Now if we look in our destination directory, we see we have an extdemo
egg link:
>>> ls(dest)
d extdemo-1.4-py2.4-unix-i686.egg
- extdemo.egg-link
And that the source directory contains the compiled extension:
>>> ls(extdemo)
- MANIFEST
- MANIFEST.in
- README
d build
- extdemo.c
d extdemo.egg-info
- extdemo.so
- setup.py
Download cache
--------------
Normally, when distributions are installed, if any processing is
needed, they are downloaded from the internet to a temporary directory
and then installed from there. A download cache can be used to avoid
the download step. This can be useful to reduce network access and to
create source distributions of an entire buildout.
A download cache is specified by calling the download_cache
function. The function always returns the previous setting. If no
argument is passed, then the setting is unchanged. If an argument is
passed, the download cache is set to the given path, which must point
to an existing directory. Passing None clears the cache setting.
To see this work, we'll create a directory and set it as the cache
directory:
>>> cache = tmpdir('cache')
>>> zc.buildout.easy_install.download_cache(cache)
We'll recreate our destination directory:
>>> remove(dest)
>>> dest = tmpdir('sample-install')
We'd like to see what is being fetched from the server, so we'll
enable server logging:
>>> get(link_server+'enable_server_logging')
GET 200 /enable_server_logging
''
It supports a number of optional keyword arguments:
links
a sequence of URLs, file names, or directories to look for
links to distributions,
index
The URL of an index server, or almost any other valid URL. :)
If not specified, the Python Package Index,
http://pypi.python.org/simple/, is used. You can specify an
alternate index with this option. If you use the links option and
if the links point to the needed distributions, then the index can
be anything and will be largely ignored. In the examples, here,
we'll just point to an empty directory on our link server. This
will make our examples run a little bit faster.
path
A list of additional directories to search for locally-installed
distributions.
newest
A boolean value indicating whether to search for new distributions
when already-installed distributions meet the requirement. When
this is true, the default, and when the destination directory is
not None, then the install function will search for the newest
distributions that satisfy the requirements.
versions
A dictionary mapping project names to version numbers to be used
when selecting distributions. This can be used to specify a set of
distribution versions independent of other requirements.
Our link server included a source distribution that includes a simple
extension, extdemo.c::
#include <Python.h>
#include <extdemo.h>
static PyMethodDef methods[] = {};
PyMODINIT_FUNC
initextdemo(void)
{
PyObject *m;
m = Py_InitModule3("extdemo", methods, "");
#ifdef TWO
PyModule_AddObject(m, "val", PyInt_FromLong(2));
#else
PyModule_AddObject(m, "val", PyInt_FromLong(EXTDEMO));
#endif
}
The extension depends on a system-dependent include file, extdemo.h,
that defines a constant, EXTDEMO, that is exposed by the extension.
We'll add an include directory to our sample buildout and add the
needed include file to it:
>>> mkdir('include')
>>> write('include', 'extdemo.h',
... """
... #define EXTDEMO 42
... """)
Now, we can use the build function to create an egg from the source
distribution:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
['/sample-install/extdemo-1.4-py2.4-unix-i686.egg']
The function returns the list of eggs
Now if we look in our destination directory, we see we have an extdemo egg:
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
Let's update our link server with a new version of extdemo:
>>> update_extdemo()
>>> print get(link_server),
<html><body>
<a href="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br>
<a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
<a href="demo-0.2-py2.4.egg">demo-0.2-py2.4.egg</a><br>
<a href="demo-0.3-py2.4.egg">demo-0.3-py2.4.egg</a><br>
<a href="demo-0.4c1-py2.4.egg">demo-0.4c1-py2.4.egg</a><br>
<a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
<a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
<a href="demoneeded-1.2c1.zip">demoneeded-1.2c1.zip</a><br>
<a href="du_zipped-1.0-pyN.N.egg">du_zipped-1.0-pyN.N.egg</a><br>
<a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
<a href="extdemo-1.5.zip">extdemo-1.5.zip</a><br>
<a href="index/">index/</a><br>
<a href="other-1.0-py2.4.egg">other-1.0-py2.4.egg</a><br>
</body></html>
The easy_install caches information about servers to reduce network
access. To see the update, we have to call the clear_index_cache
function to clear the index cache:
>>> zc.buildout.easy_install.clear_index_cache()
If we run build with newest set to False, we won't get an update:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/',
... newest=False)
['/sample-install/extdemo-1.4-py2.4-linux-i686.egg']
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
But if we run it with the default True setting for newest, then we'll
get an updated egg:
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
['/sample-install/extdemo-1.5-py2.4-unix-i686.egg']
>>> ls(dest)
d demo-0.2-py2.4.egg
d demo-0.3-py2.4.egg
d demoneeded-1.0-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.4-py2.4-unix-i686.egg
d extdemo-1.5-py2.4-unix-i686.egg
The versions option also influences the versions used. For example,
if we specify a version for extdemo, then that will be used, even
though it isn't the newest. Let's clean out the destination directory
first:
>>> import os
>>> for name in os.listdir(dest):
... remove(dest, name)
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/',
... versions=dict(extdemo='1.4'))
['/sample-install/extdemo-1.4-py2.4-unix-i686.egg']
>>> ls(dest)
d extdemo-1.4-py2.4-unix-i686.egg
Handling custom build options for extensions in develop eggs
------------------------------------------------------------
The develop function is similar to the build function, except that,
rather than building an egg from a source directory containing a
setup.py script.
The develop function takes 2 positional arguments:
setup
The path to a setup script, typically named "setup.py", or a
directory containing a setup.py script.
dest
The directory to install the egg link to
It supports some optional keyword argument:
build_ext
A dictionary of options to be passed to the distutils build_ext
command when building extensions.
We have a local directory containing the extdemo source:
>>> ls(extdemo)
- MANIFEST
- MANIFEST.in
- README
- extdemo.c
- setup.py
Now, we can use the develop function to create a develop egg from the source
distribution:
>>> zc.buildout.easy_install.develop(
... extdemo, dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')})
'/sample-install/extdemo.egg-link'
The name of the egg link created is returned.
Now if we look in our destination directory, we see we have an extdemo
egg link:
>>> ls(dest)
d extdemo-1.4-py2.4-unix-i686.egg
- extdemo.egg-link
And that the source directory contains the compiled extension:
>>> ls(extdemo)
- MANIFEST
- MANIFEST.in
- README
d build
- extdemo.c
d extdemo.egg-info
- extdemo.so
- setup.py
Download cache
--------------
Normally, when distributions are installed, if any processing is
needed, they are downloaded from the internet to a temporary directory
and then installed from there. A download cache can be used to avoid
the download step. This can be useful to reduce network access and to
create source distributions of an entire buildout.
A download cache is specified by calling the download_cache
function. The function always returns the previous setting. If no
argument is passed, then the setting is unchanged. If an argument is
passed, the download cache is set to the given path, which must point
to an existing directory. Passing None clears the cache setting.
To see this work, we'll create a directory and set it as the cache
directory:
>>> cache = tmpdir('cache')
>>> zc.buildout.easy_install.download_cache(cache)
We'll recreate our destination directory:
>>> remove(dest)
>>> dest = tmpdir('sample-install')
We'd like to see what is being fetched from the server, so we'll
enable server logging:
>>> get(link_server+'enable_server_logging')
GET 200 /enable_server_logging
''
Now, if we install demo, and extdemo:
Now, if we install demo, and extdemo:
>>> ws = zc.buildout.easy_install.install(
... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/')
GET 200 /
GET 404 /index/demo/
GET 200 /index/
GET 200 /demo-0.2-py2.4.egg
GET 404 /index/demoneeded/
GET 200 /demoneeded-1.1.zip
>>> ws = zc.buildout.easy_install.install(
... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/')
GET 200 /
GET 404 /index/demo/
GET 200 /index/
GET 200 /demo-0.2-py2.4.egg
GET 404 /index/demoneeded/
GET 200 /demoneeded-1.1.zip
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
GET 404 /index/extdemo/
GET 200 /extdemo-1.5.zip
['/sample-install/extdemo-1.5-py2.4-linux-i686.egg']
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
GET 404 /index/extdemo/
GET 200 /extdemo-1.5.zip
['/sample-install/extdemo-1.5-py2.4-linux-i686.egg']
Not only will we get eggs in our destination directory:
Not only will we get eggs in our destination directory:
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.5-py2.4-linux-i686.egg
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.5-py2.4-linux-i686.egg
But we'll get distributions in the cache directory:
But we'll get distributions in the cache directory:
>>> ls(cache)
- demo-0.2-py2.4.egg
- demoneeded-1.1.zip
- extdemo-1.5.zip
>>> ls(cache)
- demo-0.2-py2.4.egg
- demoneeded-1.1.zip
- extdemo-1.5.zip
The cache directory contains uninstalled distributions, such as zipped
eggs or source distributions.
The cache directory contains uninstalled distributions, such as zipped
eggs or source distributions.
Let's recreate our destination directory and clear the index cache:
Let's recreate our destination directory and clear the index cache:
>>> remove(dest)
>>> dest = tmpdir('sample-install')
>>> zc.buildout.easy_install.clear_index_cache()
>>> remove(dest)
>>> dest = tmpdir('sample-install')
>>> zc.buildout.easy_install.clear_index_cache()
Now when we install the distributions:
Now when we install the distributions:
>>> ws = zc.buildout.easy_install.install(
... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/')
GET 200 /
GET 404 /index/demo/
GET 200 /index/
GET 404 /index/demoneeded/
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
GET 404 /index/extdemo/
['/sample-install/extdemo-1.5-py2.4-linux-i686.egg']
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.5-py2.4-linux-i686.egg
>>> ws = zc.buildout.easy_install.install(
... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/')
GET 200 /
GET 404 /index/demo/
GET 200 /index/
GET 404 /index/demoneeded/
>>> zc.buildout.easy_install.build(
... 'extdemo', dest,
... {'include-dirs': os.path.join(sample_buildout, 'include')},
... links=[link_server], index=link_server+'index/')
GET 404 /index/extdemo/
['/sample-install/extdemo-1.5-py2.4-linux-i686.egg']
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
d extdemo-1.5-py2.4-linux-i686.egg
Note that we didn't download the distributions from the link server.
Note that we didn't download the distributions from the link server.
If we remove the restriction on demo, we'll download a newer version
from the link server:
If we remove the restriction on demo, we'll download a newer version
from the link server:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest,
... links=[link_server], index=link_server+'index/')
GET 200 /demo-0.3-py2.4.egg
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest,
... links=[link_server], index=link_server+'index/')
GET 200 /demo-0.3-py2.4.egg
Normally, the download cache is the preferred source of downloads, but
not the only one.
Normally, the download cache is the preferred source of downloads, but
not the only one.
Installing solely from a download cache
---------------------------------------
Installing solely from a download cache
---------------------------------------
A download cache can be used as the basis of application source
releases. In an application source release, we want to distribute an
application that can be built without making any network accesses. In
this case, we distribute a download cache and tell the easy_install
module to install from the download cache only, without making network
accesses. The install_from_cache function can be used to signal that
packages should be installed only from the download cache. The
function always returns the previous setting. Calling it with no
arguments returns the current setting without changing it:
A download cache can be used as the basis of application source
releases. In an application source release, we want to distribute an
application that can be built without making any network accesses. In
this case, we distribute a download cache and tell the easy_install
module to install from the download cache only, without making network
accesses. The install_from_cache function can be used to signal that
packages should be installed only from the download cache. The
function always returns the previous setting. Calling it with no
arguments returns the current setting without changing it:
>>> zc.buildout.easy_install.install_from_cache()
False
>>> zc.buildout.easy_install.install_from_cache()
False
Calling it with a boolean value changes the setting and returns the
previous setting:
>>> zc.buildout.easy_install.install_from_cache(True)
False
Calling it with a boolean value changes the setting and returns the
previous setting:
>>> zc.buildout.easy_install.install_from_cache(True)
False
Let's remove demo-0.3-py2.4.egg from the cache, clear the index cache,
recreate the destination directory, and reinstall demo:
>>> for f in os.listdir(cache):
... if f.startswith('demo-0.3-'):
... remove(cache, f)
Let's remove demo-0.3-py2.4.egg from the cache, clear the index cache,
recreate the destination directory, and reinstall demo:
>>> for f in os.listdir(cache):
... if f.startswith('demo-0.3-'):
... remove(cache, f)
>>> zc.buildout.easy_install.clear_index_cache()
>>> remove(dest)
>>> dest = tmpdir('sample-install')
>>> zc.buildout.easy_install.clear_index_cache()
>>> remove(dest)
>>> dest = tmpdir('sample-install')
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest,
... links=[link_server], index=link_server+'index/')
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest,
... links=[link_server], index=link_server+'index/')
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
>>> ls(dest)
d demo-0.2-py2.4.egg
d demoneeded-1.1-py2.4.egg
This time, we didn't download from or even query the link server.
This time, we didn't download from or even query the link server.
.. Disable the download cache:
.. Disable the download cache:
>>> zc.buildout.easy_install.download_cache(None)
'/cache'
>>> zc.buildout.easy_install.download_cache(None)
'/cache'
>>> zc.buildout.easy_install.install_from_cache(False)
True
>>> zc.buildout.easy_install.install_from_cache(False)
True
src/zc/buildout/extends-cache.txt
View file @
83d53da5
...
...
@@ -41,20 +41,20 @@ buildout:
When trying to run this buildout offline, we'll find that we cannot read all
of the required configuration:
>>> print
system(buildout + ' -o'
)
>>> print
_(system(buildout + ' -o')
)
While:
Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
Trying the same online, we can:
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
Unused options for buildout: 'foo'.
As long as we haven't said anything about caching downloaded configuration,
nothing gets cached. Offline mode will still cause the buildout to fail:
>>> print
system(buildout + ' -o'
)
>>> print
_(system(buildout + ' -o')
)
While:
Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
...
...
@@ -73,7 +73,7 @@ being a hash of the complete URL):
... extends-cache = cache
... """ % server_url)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
Unused options for buildout: 'foo'.
>>> cache = join(sample_buildout, 'cache')
...
...
@@ -88,7 +88,7 @@ foo = bar
We can now run buildout offline as it will read base.cfg from the cache:
>>> print
system(buildout + ' -o'
)
>>> print
_(system(buildout + ' -o')
)
Unused options for buildout: 'foo'.
The cache is being used purely as a fall-back in case we are offline or don't
...
...
@@ -104,18 +104,18 @@ base.cfg from the cache:
... bar = baz
... """)
>>> print
system(buildout + ' -o'
)
>>> print
_(system(buildout + ' -o')
)
Unused options for buildout: 'foo'.
In online mode, buildout will download and use the modified version:
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
Unused options for buildout: 'bar'.
Trying offline mode again, the new version will be used as it has been put in
the cache now:
>>> print
system(buildout + ' -o'
)
>>> print
_(system(buildout + ' -o')
)
Unused options for buildout: 'bar'.
Clean up:
...
...
@@ -203,7 +203,7 @@ bases, using different caches:
Buildout will now assemble its configuration from all of these 6 files,
defaults first. The online resources end up in the respective extends caches:
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
Unused options for buildout: 'foo'.
>>> ls('user-cache')
...
...
@@ -249,7 +249,7 @@ Let's rewrite the config files, clean out the caches and re-run buildout:
>>> remove('user-cache', os.listdir('user-cache')[0])
>>> remove('cache', os.listdir('cache')[0])
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
Unused options for buildout: 'foo'.
>>> ls('user-cache')
...
...
@@ -272,7 +272,7 @@ Offline mode and installation from cache
If we run buildout in offline mode now, it will fail because it cannot get at
the remote configuration file needed by the user's defaults:
>>> print
system(buildout + ' -o'
)
>>> print
_(system(buildout + ' -o')
)
While:
Initializing.
Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode.
...
...
@@ -285,7 +285,7 @@ configuration and see when buildout applies this setting in each case:
... extends = fancy_default.cfg
... offline = true
... """)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
While:
Initializing.
Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode.
...
...
@@ -299,7 +299,7 @@ Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode.
... extends = %sbase_default.cfg
... offline = true
... """ % server_url)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
While:
Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
...
...
@@ -313,7 +313,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
... extends = fancy.cfg
... offline = true
... """)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
While:
Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
...
...
@@ -327,7 +327,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
... extends = %sbase.cfg
... offline = true
... """ % server_url)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
Unused options for buildout: 'foo'.
The ``install-from-cache`` option is treated accordingly:
...
...
@@ -337,7 +337,7 @@ The ``install-from-cache`` option is treated accordingly:
... extends = fancy_default.cfg
... install-from-cache = true
... """)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
While:
Initializing.
Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode.
...
...
@@ -351,7 +351,7 @@ Error: Couldn't download 'http://localhost/base_default.cfg' in offline mode.
... extends = %sbase_default.cfg
... install-from-cache = true
... """ % server_url)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
While:
Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
...
...
@@ -365,7 +365,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
... extends = fancy.cfg
... install-from-cache = true
... """)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
While:
Initializing.
Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
...
...
@@ -379,7 +379,7 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
... extends = %sbase.cfg
... install-from-cache = true
... """ % server_url)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
While:
Installing.
Checking for upgrades.
...
...
@@ -406,7 +406,7 @@ is already present locally. If we run buildout in newest mode
... extends-cache = cache
... extends = %sbase.cfg
... """ % server_url)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
>>> ls('cache')
- 5aedc98d7e769290a29d654a591a3a45
>>> cat('cache', os.listdir(cache)[0])
...
...
@@ -420,7 +420,7 @@ A change to ``base.cfg`` is picked up on the next buildout run:
... parts =
... foo = bar
... """)
>>> print
system(buildout + " -n"
)
>>> print
_(system(buildout + " -n")
)
Unused options for buildout: 'foo'.
>>> cat('cache', os.listdir(cache)[0])
[buildout]
...
...
@@ -434,7 +434,7 @@ already present in the extends cache will not be updated:
... [buildout]
... parts =
... """)
>>> print
system(buildout + " -N"
)
>>> print
_(system(buildout + " -N")
)
Unused options for buildout: 'foo'.
>>> cat('cache', os.listdir(cache)[0])
[buildout]
...
...
@@ -463,7 +463,7 @@ used:
... newest = true
... extends = %sbaseA.cfg %sbaseB.cfg
... """ % (server_url, server_url))
>>> print
system(buildout + " -n"
)
>>> print
_(system(buildout + " -n")
)
Unused options for buildout: 'bar' 'foo'.
(XXX We patch download utility's API to produce readable output for the test;
...
...
@@ -472,7 +472,7 @@ a better solution would utilise the logging already done by the utility.)
>>> import zc.buildout
>>> old_download = zc.buildout.download.Download.download
>>> def wrapper_download(self, url, md5sum=None, path=None):
... print
"The URL %s was downloaded." % url
... print
_("The URL %s was downloaded." % url)
... return old_download(url, md5sum, path)
>>> zc.buildout.download.Download.download = wrapper_download
...
...
@@ -499,7 +499,7 @@ UserError is raised if that option is encountered now:
... parts =
... extended-by = foo.cfg
... """)
>>> print
system(buildout
)
>>> print
_(system(buildout)
)
While:
Initializing.
Error: No-longer supported "extended-by" option found in http://localhost/base.cfg.
...
...
src/zc/buildout/isolation.txt
View file @
83d53da5
...
...
@@ -38,7 +38,8 @@ This document tests the 3rd option.
>>> sample_buildout = tmpdir('sample')
>>> cd(sample_buildout)
>>> import sys
>>> print system("%s -S %s init demo" % (sys.executable, bootstrap_py)),
>>> print_(system("%s -S %s init demo" % (sys.executable, bootstrap_py)),
... end='')
... # doctest: +ELLIPSIS
Downloading http://pypi.python.org/packages/source/d/distribute/...
Creating '/sample/buildout.cfg'.
...
...
@@ -78,10 +79,10 @@ The -S option is also used when invoking setup scripts.
>>> write('proj', 'setup.py', """
... from distutils.core import setup
... import sys
... print
'site:', 'site' in sys.modules
... print
_('site:', 'site' in sys.modules)
... setup(name='hassite')
... """)
>>> print
system(join('bin', 'buildout')+' setup proj sdist'
)
>>> print
_(system(join('bin', 'buildout')+' setup proj sdist')
)
... # doctest: +ELLIPSIS
Running setup script 'proj/setup.py'.
site: True
...
...
@@ -95,7 +96,7 @@ The -S option is also used when invoking setup scripts.
... recipe = zc.recipe.egg
... eggs = hassite
... """ % join('proj', 'dist'))
>>> print
system(join('bin', 'buildout'
))
>>> print
_(system(join('bin', 'buildout')
))
... # doctest: +ELLIPSIS
Uninstalling py.
Installing egg.
...
...
@@ -110,7 +111,7 @@ The -S option is also used when invoking setup scripts.
... parts =
... develop = %s
... """ % join('proj'))
>>> print
system(join('bin', 'buildout'
))
>>> print
_(system(join('bin', 'buildout')
))
... # doctest: +ELLIPSIS
Develop: '/sample/proj'
site: True
...
...
src/zc/buildout/repeatable.txt
View file @
83d53da5
...
...
@@ -21,10 +21,12 @@ To see how this works, we'll create two versions of a recipe egg:
>>> mkdir('recipe')
>>> write('recipe', 'recipe.py',
... '''
... import sys
... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\n')
... class Recipe:
... def __init__(*a): pass
... def install(self):
... print
'recipe v1'
... print
_('recipe v1')
... return ()
... update = install
... ''')
...
...
@@ -39,7 +41,7 @@ To see how this works, we'll create two versions of a recipe egg:
>>> write('recipe', 'README', '')
>>> print
system(buildout+' setup recipe bdist_egg'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' setup recipe bdist_egg'))
# doctest: +ELLIPSIS
Running setup script 'recipe/setup.py'.
...
...
...
@@ -47,10 +49,12 @@ To see how this works, we'll create two versions of a recipe egg:
>>> write('recipe', 'recipe.py',
... '''
... import sys
... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\n')
... class Recipe:
... def __init__(*a): pass
... def install(self):
... print
'recipe v2'
... print
_('recipe v2')
... return ()
... update = install
... ''')
...
...
@@ -64,7 +68,7 @@ To see how this works, we'll create two versions of a recipe egg:
... ''')
>>> print
system(buildout+' setup recipe bdist_egg'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' setup recipe bdist_egg'))
# doctest: +ELLIPSIS
Running setup script 'recipe/setup.py'.
...
...
...
@@ -82,7 +86,7 @@ and we'll configure a buildout to use it:
If we run the buildout, it will use version 2:
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Getting distribution for 'spam'.
Got spam 2.
Installing foo.
...
...
@@ -112,7 +116,7 @@ as in the versions option.
Now, if we run the buildout, we'll use version 1 of the spam recipe:
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Getting distribution for 'spam==1'.
Got spam 1.
Uninstalling foo.
...
...
@@ -123,7 +127,7 @@ Running the buildout in verbose mode will help us get information
about versions used. If we run the buildout in verbose mode without
specifying a versions section:
>>> print
system(buildout+' buildout:versions= -v'), # doctest: +ELLIPSIS
>>> print
_(system(buildout+' buildout:versions= -v'), end='')
Installing 'zc.buildout', 'distribute'.
We have a develop egg: zc.buildout 1.0.0.
We have the best distribution that satisfies 'distribute'.
...
...
@@ -145,7 +149,7 @@ that we can fix them in a versions section.
If we run the buildout with the versions section:
>>> print
system(buildout+' -v'), # doctest: +ELLIPSIS
>>> print
_(system(buildout+' -v'), end='')
Installing 'zc.buildout', 'distribute'.
We have a develop egg: zc.buildout 1.0.0.
We have the best distribution that satisfies 'distribute'.
...
...
src/zc/buildout/rmtree.py
View file @
83d53da5
...
...
@@ -42,7 +42,7 @@ def rmtree (path):
and make it unwriteable
>>> os.chmod (foo, 0400)
>>> os.chmod (foo, 0
o
400)
rmtree should be able to remove it:
...
...
@@ -54,7 +54,7 @@ def rmtree (path):
0
"""
def
retry_writeable
(
func
,
path
,
exc
):
os
.
chmod
(
path
,
0600
)
os
.
chmod
(
path
,
0
o
600
)
func
(
path
)
shutil
.
rmtree
(
path
,
onerror
=
retry_writeable
)
...
...
@@ -64,3 +64,4 @@ def test_suite():
if
"__main__"
==
__name__
:
doctest
.
testmod
()
src/zc/buildout/runsetup.txt
View file @
83d53da5
...
...
@@ -17,7 +17,8 @@ commands, like bdist_egg even with packages that don't use setuptools.
To illustrate this, we'll create a package in a sample buildout:
>>> mkdir('hello')
>>> write('hello', 'hello.py', 'print "Hello World!"')
>>> write('hello', 'hello.py',
... 'import sys; sys.stdout.write("Hello World!\n")\n')
>>> write('hello', 'README', 'This is hello')
>>> write('hello', 'setup.py',
... """
...
...
@@ -32,7 +33,7 @@ To illustrate this, we'll create a package in a sample buildout:
We can use the buildout command to generate the hello egg:
>>> print
system(buildout +' setup hello -q bdist_egg'),
>>> print
_(system(buildout +' setup hello -q bdist_egg'), end='')
Running setup script 'hello/setup.py'.
zip_safe flag not set; analyzing archive contents...
...
...
src/zc/buildout/setup.txt
View file @
83d53da5
...
...
@@ -28,14 +28,14 @@ We've created a super simple (stupid) setup script. Note that it
doesn't import setuptools. Let's try running it to create an egg.
We'll use the buildout script from our sample buildout:
>>> print
system(buildout+' setup'),
>>> print
_(system(buildout+' setup'), end='')
... # doctest: +NORMALIZE_WHITESPACE
Error: The setup command requires the path to a setup script or
directory containing a setup script, and its arguments.
Oops, we forgot to give the name of the setup script:
>>> print
system(buildout+' setup setup.py bdist_egg'),
>>> print
_(system(buildout+' setup setup.py bdist_egg'))
... # doctest: +ELLIPSIS
Running setup script 'setup.py'.
...
...
...
@@ -46,6 +46,6 @@ Oops, we forgot to give the name of the setup script:
Note that we can specify a directory name. This is often shorter and
preferred by the lazy :)
>>> print
system(buildout+' setup . bdist_egg'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' setup . bdist_egg'))
# doctest: +ELLIPSIS
Running setup script './setup.py'.
...
src/zc/buildout/testing.py
View file @
83d53da5
...
...
@@ -14,7 +14,7 @@
"""Various test-support utility functions
"""
import
BaseHTTPS
erver
import
http.s
erver
import
errno
import
logging
import
os
...
...
@@ -28,12 +28,14 @@ import sys
import
tempfile
import
threading
import
time
import
urllib
2
import
urllib
.request
,
urllib
.
error
,
urllib
.
parse
import
zc.buildout.buildout
import
zc.buildout.easy_install
from
zc.buildout.rmtree
import
rmtree
print_
=
zc
.
buildout
.
buildout
.
print_
fsync
=
getattr
(
os
,
'fsync'
,
lambda
fileno
:
None
)
is_win32
=
sys
.
platform
==
'win32'
...
...
@@ -47,7 +49,7 @@ def cat(dir, *names):
and
os
.
path
.
exists
(
path
+
'-script.py'
)
):
path
=
path
+
'-script.py'
print
open
(
path
).
read
(),
print
_
(
open
(
path
).
read
(),
end
=
''
)
def
ls
(
dir
,
*
subs
):
if
subs
:
...
...
@@ -56,12 +58,12 @@ def ls(dir, *subs):
names
.
sort
()
for
name
in
names
:
if
os
.
path
.
isdir
(
os
.
path
.
join
(
dir
,
name
)):
print
'd '
,
print
_
(
'd '
,
end
=
' '
)
elif
os
.
path
.
islink
(
os
.
path
.
join
(
dir
,
name
)):
print
'l '
,
print
_
(
'l '
,
end
=
' '
)
else
:
print
'- '
,
print
name
print
_
(
'- '
,
end
=
' '
)
print
_
(
name
)
def
mkdir
(
*
path
):
os
.
mkdir
(
os
.
path
.
join
(
*
path
))
...
...
@@ -96,15 +98,15 @@ def system(command, input=''):
close_fds
=
MUST_CLOSE_FDS
)
i
,
o
,
e
=
(
p
.
stdin
,
p
.
stdout
,
p
.
stderr
)
if
input
:
i
.
write
(
input
)
i
.
write
(
input
.
encode
()
)
i
.
close
()
result
=
o
.
read
()
+
e
.
read
()
o
.
close
()
e
.
close
()
return
result
return
result
.
decode
()
def
get
(
url
):
return
urllib
2
.
urlopen
(
url
).
read
()
return
urllib
.
request
.
urlopen
(
url
).
read
().
decode
()
def
_runsetup
(
setup
,
*
args
):
if
os
.
path
.
isdir
(
setup
):
...
...
@@ -254,6 +256,7 @@ def buildoutSetUp(test):
start_server
=
start_server
,
buildout
=
os
.
path
.
join
(
sample
,
'bin'
,
'buildout'
),
wait_until
=
wait_until
,
print_
=
print_
,
))
zc
.
buildout
.
easy_install
.
prefer_final
(
prefer_final
)
...
...
@@ -262,10 +265,10 @@ def buildoutTearDown(test):
for
f
in
test
.
globs
[
'__tear_downs'
]:
f
()
class
Server
(
BaseHTTPS
erver
.
HTTPServer
):
class
Server
(
http
.
s
erver
.
HTTPServer
):
def
__init__
(
self
,
tree
,
*
args
):
BaseHTTPS
erver
.
HTTPServer
.
__init__
(
self
,
*
args
)
http
.
s
erver
.
HTTPServer
.
__init__
(
self
,
*
args
)
self
.
tree
=
os
.
path
.
abspath
(
tree
)
__run
=
True
...
...
@@ -276,14 +279,14 @@ class Server(BaseHTTPServer.HTTPServer):
def
handle_error
(
self
,
*
_
):
self
.
__run
=
False
class
Handler
(
BaseHTTPS
erver
.
BaseHTTPRequestHandler
):
class
Handler
(
http
.
s
erver
.
BaseHTTPRequestHandler
):
Server
.
__log
=
False
def
__init__
(
self
,
request
,
address
,
server
):
self
.
__server
=
server
self
.
tree
=
server
.
tree
BaseHTTPS
erver
.
BaseHTTPRequestHandler
.
__init__
(
http
.
s
erver
.
BaseHTTPRequestHandler
.
__init__
(
self
,
request
,
address
,
server
)
def
do_GET
(
self
):
...
...
@@ -308,7 +311,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
):
self
.
send_response
(
404
,
'Not Found'
)
#self.send_response(200)
out
=
'<html><body>Not Found</body></html>'
out
=
'<html><body>Not Found</body></html>'
.
encode
()
#out = '\n'.join(self.tree, self.path, path)
self
.
send_header
(
'Content-Length'
,
str
(
len
(
out
)))
self
.
send_header
(
'Content-Type'
,
'text/html'
)
...
...
@@ -326,7 +329,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
name
+=
'/'
out
.
append
(
'<a href="%s">%s</a><br>
\
n
'
%
(
name
,
name
))
out
.
append
(
'</body></html>
\
n
'
)
out
=
''
.
join
(
out
)
out
=
''
.
join
(
out
)
.
encode
()
self
.
send_header
(
'Content-Length'
,
str
(
len
(
out
)))
self
.
send_header
(
'Content-Type'
,
'text/html'
)
else
:
...
...
@@ -346,7 +349,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
def
log_request
(
self
,
code
):
if
self
.
__server
.
__log
:
print
'%s %s %s'
%
(
self
.
command
,
code
,
self
.
path
)
print
_
(
'%s %s %s'
%
(
self
.
command
,
code
,
self
.
path
)
)
def
_run
(
tree
,
port
):
server_address
=
(
'localhost'
,
port
)
...
...
@@ -364,7 +367,7 @@ def get_port():
return
port
finally
:
s
.
close
()
raise
RuntimeError
,
"Can't find port"
raise
RuntimeError
(
"Can't find port"
)
def
_start_server
(
tree
,
name
=
''
):
port
=
get_port
()
...
...
@@ -379,7 +382,7 @@ def start_server(tree):
def
stop_server
(
url
,
thread
=
None
):
try
:
urllib
2
.
urlopen
(
url
+
'__stop__'
)
urllib
.
request
.
urlopen
(
url
+
'__stop__'
)
except
Exception
:
pass
if
thread
is
not
None
:
...
...
@@ -395,7 +398,7 @@ def wait(port, up):
s
.
close
()
if
up
:
break
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
if
e
[
0
]
not
in
(
errno
.
ECONNREFUSED
,
errno
.
ECONNRESET
):
raise
s
.
close
()
...
...
@@ -408,7 +411,7 @@ def wait(port, up):
raise
SystemError
(
"Couln't stop server"
)
def
install
(
project
,
destination
):
if
not
isinstance
(
destination
,
basestring
):
if
not
isinstance
(
destination
,
str
):
destination
=
os
.
path
.
join
(
destination
.
globs
[
'sample_buildout'
],
'eggs'
)
...
...
@@ -428,7 +431,7 @@ def install(project, destination):
).
write
(
dist
.
location
)
def
install_develop
(
project
,
destination
):
if
not
isinstance
(
destination
,
basestring
):
if
not
isinstance
(
destination
,
str
):
destination
=
os
.
path
.
join
(
destination
.
globs
[
'sample_buildout'
],
'develop-eggs'
)
...
...
@@ -462,3 +465,7 @@ normalize_egg_py = (
re
.
compile
(
'-py
\
d[.]
\
d(-
\
S+)?.egg
'
),
'
-
pyN
.
N
.
egg
',
)
normalize_exception_type_for_python_2_and_3 = (
re.compile(r'
^
(
\
w
+
\
.)
*
([
A
-
Z
][
A
-
Za
-
z0
-
9
]
+
Error
:
)
'),
'
\
2
')
src/zc/buildout/testrecipes.py
View file @
83d53da5
from
zc.buildout.buildout
import
print_
class
Debug
:
...
...
@@ -7,10 +8,10 @@ class Debug:
self
.
options
=
options
def
install
(
self
):
items
=
self
.
options
.
items
(
)
items
=
list
(
self
.
options
.
items
()
)
items
.
sort
()
for
option
,
value
in
items
:
print
" %s=%r"
%
(
option
,
value
)
print
_
(
" %s=%r"
%
(
option
,
value
)
)
return
()
update
=
install
src/zc/buildout/tests.py
View file @
83d53da5
...
...
@@ -11,7 +11,9 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from
zc.buildout.buildout
import
print_
from
zope.testing
import
renormalizing
import
doctest
import
os
import
pkg_resources
...
...
@@ -47,7 +49,7 @@ We should be able to deal with setup scripts that aren't setuptools based.
... parts =
... ''')
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo'
>>> ls('develop-eggs')
...
...
@@ -74,7 +76,8 @@ We should be able to deal with setup scripts that aren't setuptools based.
... parts =
... ''')
>>> print system(join('bin', 'buildout')+' -vv'), # doctest: +ELLIPSIS
>>> print_(system(join('bin', 'buildout')+' -vv'), end=' ')
... # doctest: +ELLIPSIS
Installing...
Develop: '/sample-buildout/foo'
...
...
...
@@ -85,7 +88,8 @@ We should be able to deal with setup scripts that aren't setuptools based.
- foo.egg-link
- zc.recipe.egg.egg-link
>>> print system(join('bin', 'buildout')+' -vvv'), # doctest: +ELLIPSIS
>>> print_(system(join('bin', 'buildout')+' -vvv'), end=' ')
... # doctest: +ELLIPSIS
Installing...
Develop: '/sample-buildout/foo'
in: '/sample-buildout/foo'
...
...
@@ -126,7 +130,8 @@ It is an error to create a variable-reference cycle:
... z = ${buildout:x}
... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
While:
Initializing.
...
...
@@ -148,7 +153,8 @@ It is an error to use funny characters in variable refereces:
... x = ${bui$ldout:y}
... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While:
Initializing.
Getting section buildout.
...
...
@@ -165,7 +171,8 @@ It is an error to use funny characters in variable refereces:
... x = ${buildout:y{z}
... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While:
Initializing.
Getting section buildout.
...
...
@@ -184,7 +191,8 @@ and too have too many or too few colons:
... x = ${parts}
... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While:
Initializing.
Getting section buildout.
...
...
@@ -201,7 +209,8 @@ and too have too many or too few colons:
... x = ${buildout:y:z}
... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While:
Initializing.
Getting section buildout.
...
...
@@ -218,7 +227,8 @@ Al parts have to have a section:
... parts = x
... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While:
Installing.
Getting section x.
...
...
@@ -236,7 +246,8 @@ and all parts have to have a specified recipe:
... foo = 1
... ''')
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
>>> print_(system(os.path.join(sample_buildout, 'bin', 'buildout')),
... end=' ')
While:
Installing.
Error: Missing option: x:recipe
...
...
@@ -285,7 +296,7 @@ Now, let's create a buildout that requires y and z:
... samplez
... ''' % globals())
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/sampley'
Develop: '/sample-buildout/samplez'
Installing eggs.
...
...
@@ -318,7 +329,7 @@ if we hadn't required sampley ourselves:
If we use the verbose switch, we can see where requirements are coming from:
>>> print
system(buildout+' -v'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' -v'), end=' ')
# doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'.
We have a develop egg: zc.buildout 1.0.0
We have the best distribution that satisfies 'distribute'.
...
...
@@ -369,7 +380,7 @@ buildout will tell us who's asking for something that we can't find.
... eggs = samplea
... ''')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/sampley'
Develop: '/sample-buildout/samplea'
Develop: '/sample-buildout/sampleb'
...
...
@@ -446,14 +457,14 @@ the comparison with the saved value works correctly.
>>> os.chdir(sample_buildout)
>>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes'
Installing debug.
If we run the buildout again, we shoudn't get a message about
uninstalling anything because the configuration hasn't changed.
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes'
Updating debug.
"""
...
...
@@ -507,7 +518,8 @@ def create_sections_on_command_line():
... x = ${foo:bar}
... ''')
>>> print system(buildout + ' foo:bar=1 -vv'), # doctest: +ELLIPSIS
>>> print_(system(buildout + ' foo:bar=1 -vv'), end=' ')
... # doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'.
...
[foo]
...
...
@@ -518,7 +530,7 @@ def create_sections_on_command_line():
def
test_help
():
"""
>>> print
system(os.path.join(sample_buildout, 'bin', 'buildout')+' -h'),
>>> print
_(system(os.path.join(sample_buildout, 'bin', 'buildout')+' -h'))
... # doctest: +ELLIPSIS
Usage: buildout [options] [assignments] [command [command arguments]]
<BLANKLINE>
...
...
@@ -527,8 +539,8 @@ def test_help():
-h, --help
...
>>> print
system(os.path.join(sample_buildout, 'bin', 'buildout')
... +' --help')
,
>>> print
_(
system(os.path.join(sample_buildout, 'bin', 'buildout')
... +' --help')
)
... # doctest: +ELLIPSIS
Usage: buildout [options] [assignments] [command [command arguments]]
<BLANKLINE>
...
...
@@ -554,8 +566,8 @@ bootstrapping.
... ''')
>>> os.chdir(d)
>>> print
system(os.path.join(sample_buildout, 'bin', 'buildout')
... + ' bootstrap'),
>>> print
_(
system(os.path.join(sample_buildout, 'bin', 'buildout')
... + ' bootstrap'),
end=' ')
Creating directory '/sample-bootstrap/bin'.
Creating directory '/sample-bootstrap/parts'.
Creating directory '/sample-bootstrap/eggs'.
...
...
@@ -581,15 +593,15 @@ def bug_92891_bootstrap_crashes_with_egg_recipe_in_buildout_section():
... ''')
>>> os.chdir(d)
>>> print
system(os.path.join(sample_buildout, 'bin', 'buildout')
... + ' bootstrap'),
>>> print
_(
system(os.path.join(sample_buildout, 'bin', 'buildout')
... + ' bootstrap'),
end=' ')
Creating directory '/sample-bootstrap/bin'.
Creating directory '/sample-bootstrap/parts'.
Creating directory '/sample-bootstrap/eggs'.
Creating directory '/sample-bootstrap/develop-eggs'.
Generated script '/sample-bootstrap/bin/buildout'.
>>> print
system(os.path.join('bin', 'buildout')),
>>> print
_(system(os.path.join('bin', 'buildout')), end=' ')
Unused options for buildout: 'scripts' 'eggs'.
"""
...
...
@@ -613,7 +625,7 @@ Create a develop egg:
... parts =
... """)
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo'
>>> ls('develop-eggs')
...
...
@@ -635,7 +647,7 @@ Create another:
... parts =
... """)
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo'
Develop: '/sample-buildout/bar'
...
...
@@ -652,7 +664,7 @@ Remove one:
... develop = bar
... parts =
... """)
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/bar'
It is gone
...
...
@@ -668,7 +680,7 @@ Remove the other:
... [buildout]
... parts =
... """)
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
All gone
...
...
@@ -713,7 +725,7 @@ a devlop egg, we will also generate a warning.
... parts =
... """)
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo'
Now, if we generate a working set using the egg link, we will get a warning
...
...
@@ -732,7 +744,7 @@ and we will get distribute included in the working set.
... ])]
['foox', 'distribute']
>>> print
handler
>>> print
_(handler)
zc.buildout.easy_install WARNING
Develop distribution: foox 0.0.0
uses namespace packages but the distribution does not require distribute.
...
...
@@ -764,7 +776,7 @@ We do not get a warning, but we do get distribute included in the working set:
... ])]
['foox', 'distribute']
>>> print
handler,
>>> print
_(handler, end=' ')
We get the same behavior if the it is a depedency that uses a
namespace package.
...
...
@@ -785,7 +797,7 @@ namespace package.
... parts =
... """)
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo'
Develop: '/sample-buildout/bar'
...
...
@@ -797,7 +809,7 @@ namespace package.
... ])]
['bar', 'foox', 'distribute']
>>> print
handler,
>>> print
_(handler, end=' ')
zc.buildout.easy_install WARNING
Develop distribution: foox 0.0.0
uses namespace packages but the distribution does not require distribute.
...
...
@@ -854,7 +866,7 @@ existing setup.cfg:
"""
def
uninstall_recipes_used_for_removal
():
"""
r
"""
Uninstall recipes need to be called when a part is removed too:
>>> mkdir("recipes")
...
...
@@ -869,13 +881,15 @@ Uninstall recipes need to be called when a part is removed too:
... ''')
>>> write("recipes", "demo.py",
... '''
... r'''
... import sys
... class Install:
... def __init__(*args): pass
... def install(self):
...
print 'installing'
...
sys.stdout.write('installing\n')
... return ()
... def uninstall(name, options): print 'uninstalling'
... def uninstall(name, options):
... sys.stdout.write('uninstalling\n')
... ''')
>>> write('buildout.cfg', '''
...
...
@@ -886,7 +900,7 @@ Uninstall recipes need to be called when a part is removed too:
... recipe = recipes:demo
... ''')
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipes'
Installing demo.
installing
...
...
@@ -901,7 +915,7 @@ Uninstall recipes need to be called when a part is removed too:
... x = 1
... ''')
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipes'
Uninstalling demo.
Running uninstall recipe.
...
...
@@ -916,7 +930,7 @@ Uninstall recipes need to be called when a part is removed too:
... parts =
... ''')
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipes'
Uninstalling demo.
Running uninstall recipe.
...
...
@@ -931,7 +945,7 @@ def extensions_installed_as_eggs_work_in_offline_mode():
>>> write('demo', 'demo.py',
... """
... def ext(buildout):
... print
'ext', list(buildout
)
... print
_('ext', list(buildout)
)
... """)
>>> write('demo', 'setup.py',
...
...
@@ -956,7 +970,7 @@ def extensions_installed_as_eggs_work_in_offline_mode():
... offline = true
... """)
>>> print
system(join(sample_buildout, 'bin', 'buildout')),
>>> print
_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
ext ['buildout']
...
...
@@ -994,20 +1008,20 @@ changes in .svn or CVS directories.
... ''')
>>> print
system(join(sample_buildout, 'bin', 'buildout')),
>>> print
_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipe'
Installing foo.
>>> mkdir('recipe', '.svn')
>>> mkdir('recipe', 'CVS')
>>> print
system(join(sample_buildout, 'bin', 'buildout')),
>>> print
_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipe'
Updating foo.
>>> write('recipe', '.svn', 'x', '1')
>>> write('recipe', 'CVS', 'x', '1')
>>> print
system(join(sample_buildout, 'bin', 'buildout')),
>>> print
_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipe'
Updating foo.
...
...
@@ -1046,7 +1060,7 @@ because of the missing target file.
... ''')
>>> print
system(join(sample_buildout, 'bin', 'buildout')),
>>> print
_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipe'
Installing foo.
...
...
@@ -1063,7 +1077,7 @@ because of the missing target file.
>>> remove('recipe', 'some-file')
>>> print
system(join(sample_buildout, 'bin', 'buildout')),
>>> print
_(system(join(sample_buildout, 'bin', 'buildout')), end=' ')
Develop: '/sample-buildout/recipe'
Updating foo.
...
...
@@ -1071,7 +1085,7 @@ because of the missing target file.
def
o_option_sets_offline
():
"""
>>> print
system(join(sample_buildout, 'bin', 'buildout')+' -vvo'),
>>> print
_(system(join(sample_buildout, 'bin', 'buildout')+' -vvo'), end=' ')
... # doctest: +ELLIPSIS
<BLANKLINE>
...
...
...
@@ -1080,7 +1094,7 @@ def o_option_sets_offline():
"""
def
recipe_upgrade
():
"""
r
"""
The buildout will upgrade recipes in newest (and non-offline) mode.
...
...
@@ -1088,11 +1102,12 @@ Let's create a recipe egg
>>> mkdir('recipe')
>>> write('recipe', 'recipe.py',
... '''
... r'''
... import sys
... class Recipe:
... def __init__(*a): pass
... def install(self):
...
print 'recipe v1'
...
sys.stdout.write('recipe v1\n')
... return ()
... update = install
... ''')
...
...
@@ -1107,7 +1122,7 @@ Let's create a recipe egg
>>> write('recipe', 'README', '')
>>> print
system(buildout+' setup recipe bdist_egg'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' setup recipe bdist_egg'))
# doctest: +ELLIPSIS
Running setup script 'recipe/setup.py'.
...
...
...
@@ -1125,7 +1140,7 @@ And update our buildout to use it.
... recipe = recipe
... ''' % join('recipe', 'dist'))
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Getting distribution for 'recipe'.
Got recipe 1.
Installing foo.
...
...
@@ -1134,11 +1149,12 @@ And update our buildout to use it.
Now, if we update the recipe egg:
>>> write('recipe', 'recipe.py',
... '''
... r'''
... import sys
... class Recipe:
... def __init__(*a): pass
... def install(self):
...
print 'recipe v2'
...
sys.stdout.write('recipe v2\n')
... return ()
... update = install
... ''')
...
...
@@ -1152,25 +1168,25 @@ Now, if we update the recipe egg:
... ''')
>>> print
system(buildout+' setup recipe bdist_egg'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' setup recipe bdist_egg'))
# doctest: +ELLIPSIS
Running setup script 'recipe/setup.py'.
...
We won't get the update if we specify -N:
>>> print
system(buildout+' -N'),
>>> print
_(system(buildout+' -N'), end=' ')
Updating foo.
recipe v1
or if we use -o:
>>> print
system(buildout+' -o'),
>>> print
_(system(buildout+' -o'), end=' ')
Updating foo.
recipe v1
But we will if we use neither of these:
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Getting distribution for 'recipe'.
Got recipe 2.
Uninstalling foo.
...
...
@@ -1189,7 +1205,7 @@ We can also select a particular recipe version:
... recipe = recipe ==1
... ''' % join('recipe', 'dist'))
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Uninstalling foo.
Installing foo.
recipe v1
...
...
@@ -1238,11 +1254,11 @@ uninstall
... recipe = recipe
... ''')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipe'
Installing foo.
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipe'
Updating foo.
...
...
@@ -1274,7 +1290,7 @@ def log_when_there_are_not_local_distros():
... ['demo==0.2'], dest,
... links=[link_server], index=link_server+'index/')
>>> print
handler
# doctest: +ELLIPSIS
>>> print
_(handler)
# doctest: +ELLIPSIS
zc.buildout.easy_install DEBUG
Installing 'demo==0.2'.
zc.buildout.easy_install DEBUG
...
...
@@ -1320,7 +1336,7 @@ def internal_errors():
... recipe = recipes:mkdir
... ''')
>>> print
system(buildout),
# doctest: +ELLIPSIS
>>> print
_(system(buildout), end=' ')
# doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes'
While:
Installing.
...
...
@@ -1372,7 +1388,7 @@ def whine_about_unused_options():
... z = 1
... """)
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/.'
Unused options for buildout: 'a'.
Installing foo.
...
...
@@ -1440,19 +1456,19 @@ Now let's look at 3 cases:
... recipe = recipes:clean
... ''')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes'
Installing p1.
Installing p2.
Installing p3.
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes'
Updating p1.
Updating p2.
Installing p3.
>>> print
system(buildout+' buildout:parts='),
>>> print
_(system(buildout+' buildout:parts='), end=' ')
Develop: '/sample-buildout/recipes'
Uninstalling p2.
Uninstalling p1.
...
...
@@ -1478,20 +1494,20 @@ Now let's look at 3 cases:
... recipe = recipes:clean
... ''')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes'
Installing p1.
Installing p2.
Installing p3.
Installing p4.
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes'
Updating p1.
Updating p2.
Updating p3.
>>> print
system(buildout+' buildout:parts='),
>>> print
_(system(buildout+' buildout:parts='), end=' ')
Develop: '/sample-buildout/recipes'
Uninstalling p2.
Uninstalling p1.
...
...
@@ -1519,7 +1535,7 @@ Now let's look at 3 cases:
... recipe = recipes:clean
... ''')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes'
Installing p1.
Installing p2.
...
...
@@ -1546,7 +1562,7 @@ Now let's look at 3 cases:
... x = 1
... ''')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes'
Uninstalling p4.
Updating p1.
...
...
@@ -1570,7 +1586,7 @@ Now let's look at 3 cases:
... recipe = recipes:clean
... ''')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/recipes'
Uninstalling p1.
Installing p1.
...
...
@@ -1581,7 +1597,7 @@ Now let's look at 3 cases:
"""
def
install_source_dist_with_bad_py
():
"""
r
"""
>>> mkdir('badegg')
>>> mkdir('badegg', 'badegg')
...
...
@@ -1603,7 +1619,7 @@ def install_source_dist_with_bad_py():
... zip_safe=False)
... ''')
>>> print
system(buildout+' setup badegg sdist'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' setup badegg sdist'), end=' ')
# doctest: +ELLIPSIS
Running setup script 'badegg/setup.py'.
...
...
...
@@ -1625,7 +1641,7 @@ def install_source_dist_with_bad_py():
... scripts = buildout=bo
... ''' % globals())
>>> print
system(buildout);print 'X'
# doctest: +ELLIPSIS
>>> print
_(system(buildout));print_('X')
# doctest: +ELLIPSIS
Installing eggs.
Getting distribution for 'badegg'.
Got badegg 1.
...
...
@@ -1687,7 +1703,7 @@ def bug_105081_Specific_egg_versions_are_ignored_when_newer_eggs_are_around():
... eggs = demo
... ''' % globals())
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Installing x.
Getting distribution for 'demo'.
Got demo 0.4c1.
...
...
@@ -1695,7 +1711,7 @@ def bug_105081_Specific_egg_versions_are_ignored_when_newer_eggs_are_around():
Got demoneeded 1.2c1.
Generated script '/sample-buildout/bin/demo'.
>>> print
system(join('bin', 'demo')),
>>> print
_(system(join('bin', 'demo')), end=' ')
4 2
>>> write('buildout.cfg',
...
...
@@ -1709,14 +1725,14 @@ def bug_105081_Specific_egg_versions_are_ignored_when_newer_eggs_are_around():
... eggs = demo ==0.1
... ''' % globals())
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Uninstalling x.
Installing x.
Getting distribution for 'demo==0.1'.
Got demo 0.1.
Generated script '/sample-buildout/bin/demo'.
>>> print
system(join('bin', 'demo')),
>>> print
_(system(join('bin', 'demo')), end=' ')
1 2
"""
...
...
@@ -1728,8 +1744,8 @@ if sys.version_info > (2, 4):
... p = subprocess.Popen(s, stdin=subprocess.PIPE,
... stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
... p.stdin.close()
... print
p.stdout.read(
)
... print
'Exit:', bool(p.wait(
))
... print
_(p.stdout.read().decode()
)
... print
_('Exit:', bool(p.wait()
))
>>> call(buildout)
<BLANKLINE>
...
...
@@ -1791,20 +1807,20 @@ if sys.version_info > (2, 4):
"""
def
bug_59270_recipes_always_start_in_buildout_dir
():
"""
r
"""
Recipes can rely on running from buildout directory
>>> mkdir('bad_start')
>>> write('bad_recipe.py',
... '''
... import os
...
r
'''
... import os
, sys
... class Bad:
... def __init__(self, *_):
... print os.getcwd()
... def install(self):
...
print os.getcwd(
)
...
sys.stdout.write(os.getcwd()+'\n'
)
... os.chdir('bad_start')
...
print os.getcwd(
)
...
sys.stdout.write(os.getcwd()+'\n'
)
... return ()
... ''')
...
...
@@ -1827,8 +1843,8 @@ def bug_59270_recipes_always_start_in_buildout_dir():
... ''')
>>> os.chdir('bad_start')
>>> print
system(join(sample_buildout, 'bin', 'buildout')
... +' -c '+join(sample_buildout, 'buildout.cfg')),
>>> print
_(
system(join(sample_buildout, 'bin', 'buildout')
... +' -c '+join(sample_buildout, 'buildout.cfg')),
end=' ')
Develop: '/sample-buildout/.'
/sample-buildout
/sample-buildout
...
...
@@ -1857,7 +1873,7 @@ def bug_61890_file_urls_dont_seem_to_work_in_find_dash_links():
>>> for dist in ws:
... print
dist
... print
_(dist)
demo 0.2
demoneeded 1.1
...
...
@@ -1870,7 +1886,7 @@ def bug_61890_file_urls_dont_seem_to_work_in_find_dash_links():
def
bug_75607_buildout_should_not_run_if_it_creates_an_empty_buildout_cfg
():
"""
>>> remove('buildout.cfg')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
While:
Initializing.
Error: Couldn't open /sample-buildout/buildout.cfg
...
...
@@ -1911,7 +1927,7 @@ def dealing_with_extremely_insane_dependencies():
... eggs = pack0
... ''')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/pack0'
Develop: '/sample-buildout/pack1'
Develop: '/sample-buildout/pack2'
...
...
@@ -1927,7 +1943,7 @@ def dealing_with_extremely_insane_dependencies():
However, if we run in verbose mode, we can see why packages were included:
>>> print
system(buildout+' -v'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' -v'), end=' ')
# doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'.
We have a develop egg: zc.buildout 1.0.0
We have the best distribution that satisfies 'distribute'.
...
...
@@ -1992,7 +2008,7 @@ We'll create a wacky buildout extension that is just another name for http:
... },
... )
... ''')
>>> print
system(buildout+' setup '+src+' bdist_egg'),
>>> print
_(system(buildout+' setup '+src+' bdist_egg'), end=' ')
... # doctest: +ELLIPSIS
Running setup ...
creating 'dist/wackyextension-1-...
...
...
@@ -2016,7 +2032,7 @@ Now we'll create a buildout that uses this extension to load other packages:
When we run the buildout. it will load the extension from the dist
directory and then use the wacky extension to load the demo package
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Getting distribution for 'wackyextension'.
Got wackyextension 1.
Installing demo.
...
...
@@ -2038,7 +2054,7 @@ need to make it to the download cache.
... setup(name='foo')
... ''')
>>> print
system(buildout+' setup test bdist_egg'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' setup test bdist_egg'))
# doctest: +ELLIPSIS
Running setup script 'test/setup.py'.
...
...
...
@@ -2098,9 +2114,9 @@ def prefer_final_permutation(existing, available):
)
if
dist
.
extras
:
print
'downloaded'
,
dist
.
version
print
_
(
'downloaded'
,
dist
.
version
)
else
:
print
'had'
,
dist
.
version
print
_
(
'had'
,
dist
.
version
)
sys
.
path_importer_cache
.
clear
()
def
prefer_final
():
...
...
@@ -2217,7 +2233,7 @@ The default is prefer-final = false:
... eggs = demo
... ''' % globals())
>>> print
system(buildout+' -v'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' -v'), end=' ')
# doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'.
...
Picked: demo = 0.4c1
...
...
@@ -2239,7 +2255,7 @@ We get the same behavior if we add prefer-final = false
... eggs = demo
... ''' % globals())
>>> print
system(buildout+' -v'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' -v'), end=' ')
# doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'.
...
Picked: demo = 0.4c1
...
...
@@ -2261,7 +2277,7 @@ distributions:
... eggs = demo
... ''' % globals())
>>> print
system(buildout+' -v'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' -v'), end=' ')
# doctest: +ELLIPSIS
Installing 'zc.buildout', 'distribute'.
...
Picked: demo = 0.3
...
...
@@ -2282,7 +2298,7 @@ We get an error if we specify anything but true or false:
... eggs = demo
... ''' % globals())
>>> print
system(buildout+' -v'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' -v'), end=' ')
# doctest: +ELLIPSIS
While:
Initializing.
Error: Invalid value for prefer-final option: no
...
...
@@ -2312,7 +2328,7 @@ Distribution setup scripts can import modules in the distribution directory:
... parts =
... ''')
>>> print
system(join('bin', 'buildout')),
>>> print
_(system(join('bin', 'buildout')), end=' ')
Develop: '/sample-buildout/foo'
>>> ls('develop-eggs')
...
...
@@ -2353,7 +2369,7 @@ honoring our version specification.
... ''' % pkg_resources.working_set.find(
... pkg_resources.Requirement.parse('distribute')).version)
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Installing foo.
Getting distribution for 'foo==1'.
Got foo 1.
...
...
@@ -2378,13 +2394,13 @@ def pyc_and_pyo_files_have_correct_paths():
>>> _ = system(buildout)
>>> write('t.py',
... '''
... import eggrecipedemo, eggrecipedemoneeded
...
print eggrecipedemo.main.func_code.co_filename
...
print eggrecipedemoneeded.f.func_code.co_filename
...
r
'''
... import eggrecipedemo, eggrecipedemoneeded
, sys
...
sys.stdout.write(eggrecipedemo.main.func_code.co_filename+'\n')
...
sys.stdout.write(eggrecipedemoneeded.f.func_code.co_filename+'\n')
... ''')
>>> print
system(join('bin', 'py')+ ' t.py'),
>>> print
_(system(join('bin', 'py')+ ' t.py'), end=' ')
/sample-buildout/eggs/demo-0.4c1-py2.4.egg/eggrecipedemo.py
/sample-buildout/eggs/demoneeded-1.2c1-py2.4.egg/eggrecipedemoneeded.py
...
...
@@ -2407,7 +2423,7 @@ def dont_mess_with_standard_dirs_with_variable_refs():
... eggs-directory = ${buildout:directory}/develop-eggs
... parts =
... ''' % globals())
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
"""
...
...
@@ -2438,7 +2454,7 @@ def expand_shell_patterns_in_develop_paths():
We can see that both eggs were found:
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/sampley'
Develop: '/sample-buildout/samplez'
Installing eggs.
...
...
@@ -2470,7 +2486,7 @@ def warn_users_when_expanding_shell_patterns_yields_no_results():
We should get one of the eggs, and a warning for the pattern that
did not match anything.
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Develop: '/sample-buildout/samplea'
Couldn't develop '/sample-buildout/grumble*' (not found)
Installing eggs.
...
...
@@ -2525,7 +2541,7 @@ def increment_buildout_options():
... <= p1
... ''')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Installing p1.
foo='1\n2 b'
recipe='zc.buildout:debug'
...
...
@@ -2565,7 +2581,7 @@ def increment_buildout_with_multiple_extended_files_421022():
... x = ${buildout:bar-option} ${buildout:foo-option}
... ''')
>>> print
system(buildout),
>>> print
_(system(buildout), end=' ')
Installing p.
recipe='zc.buildout:debug'
x='bar\nbaz foo\nham'
...
...
@@ -2592,7 +2608,7 @@ def increment_on_command_line():
... <= p1
... ''')
>>> print
system(buildout+' buildout:parts+=p2 p1:foo+=bar'),
>>> print
_(system(buildout+' buildout:parts+=p2 p1:foo+=bar'), end=' ')
Installing p1.
foo='1 a\nb\nbar'
recipe='zc.buildout:debug'
...
...
@@ -2624,7 +2640,11 @@ def create_sample_eggs(test, executable=sys.executable):
)
zc
.
buildout
.
testing
.
sdist
(
tmp
,
dest
)
write
(
tmp
,
'distutilsscript'
,
'#!/usr/bin/python
\
n
print "distutils!"'
)
write
(
tmp
,
'distutilsscript'
,
'#!/usr/bin/python
\
n
'
'import sys; sys.stdout.write("distutils!
\
\
n")
\
n
'
)
write
(
tmp
,
'setup.py'
,
"from setuptools import setup
\
n
"
...
...
@@ -2649,9 +2669,12 @@ def create_sample_eggs(test, executable=sys.executable):
for
i
in
(
1
,
2
,
3
,
4
):
write
(
tmp
,
'eggrecipedemo.py'
,
'import eggrecipedemoneeded
\
n
'
'import eggrecipedemoneeded, sys
\
n
'
'def print_(*a):
\
n
'
' sys.stdout.write(" ".join(map(str, a))+"
\
\
n")
\
n
'
'x=%s
\
n
'
'def main(): print x, eggrecipedemoneeded.y
\
n
'
'def main():
\
n
'
' print_(x, eggrecipedemoneeded.y)
\
n
'
%
i
)
c1
=
i
==
4
and
'c1'
or
''
write
(
...
...
@@ -2679,7 +2702,7 @@ def create_sample_eggs(test, executable=sys.executable):
finally
:
shutil
.
rmtree
(
tmp
)
extdemo_c
=
"""
extdemo_c
2
=
"""
#include <Python.h>
#include <extdemo.h>
...
...
@@ -2698,12 +2721,43 @@ initextdemo(void)
}
"""
extdemo_setup_py
=
"""
import os
extdemo_c3
=
"""
#include <Python.h>
#include <extdemo.h>
static PyMethodDef methods[] = {{NULL}};
#define MOD_DEF(ob, name, doc, methods)
\
static struct PyModuleDef moduledef = {
\
PyModuleDef_HEAD_INIT, name, doc, -1, methods, };
\
ob = PyModule_Create(&moduledef);
#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
MOD_INIT(extdemo)
{
PyObject *m;
MOD_DEF(m, "extdemo", "", methods);
#ifdef TWO
PyModule_AddObject(m, "val", PyLong_FromLong(2));
#else
PyModule_AddObject(m, "val", PyLong_FromLong(EXTDEMO));
#endif
return m;
}
"""
extdemo_c
=
sys
.
version_info
[
0
]
<
3
and
extdemo_c2
or
extdemo_c3
extdemo_setup_py
=
r"""
import os, sys
from distutils.core import setup, Extension
if os.environ.get('test-variable'):
print
"Have environment test-variable:", os.environ['test-variable']
print
("Have environment test-variable: %%s" %% os.environ['test-variable'])
setup(name = "extdemo", version = "%s", url="http://www.zope.org",
author="Demo", author_email="demo@demo.com",
...
...
@@ -2712,7 +2766,6 @@ setup(name = "extdemo", version = "%s", url="http://www.zope.org",
"""
def
add_source_dist
(
test
,
version
=
1.4
):
if
'extdemo'
not
in
test
.
globs
:
test
.
globs
[
'extdemo'
]
=
test
.
globs
[
'tmpdir'
](
'extdemo'
)
...
...
@@ -2968,6 +3021,7 @@ def test_suite():
zc.buildout.testing.normalize_endings,
zc.buildout.testing.normalize_script,
zc.buildout.testing.normalize_egg_py,
zc.buildout.testing.normalize_exception_type_for_python_2_and_3,
normalize_bang,
normalize_S,
(re.compile('
extdemo
[.]
pyd
'), '
extdemo
.
so
'),
...
...
@@ -3076,3 +3130,4 @@ def test_suite():
))
return unittest.TestSuite(test_suite)
src/zc/buildout/update.txt
View file @
83d53da5
...
...
@@ -34,6 +34,8 @@ zc.buildout used:
>>> write(sample_buildout, 'showversions', 'showversions.py',
... """
... import pkg_resources
... import sys
... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\n')
...
... class Recipe:
...
...
...
@@ -43,7 +45,7 @@ zc.buildout used:
... def install(self):
... for project in 'zc.buildout', 'distribute':
... req = pkg_resources.Requirement.parse(project)
... print
project, pkg_resources.working_set.find(req).version
... print
_(project, pkg_resources.working_set.find(req).version)
... return ()
... update = install
... """)
...
...
@@ -63,7 +65,7 @@ zc.buildout used:
Now if we run the buildout, the buildout will upgrade itself to the
new versions found in new releases:
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Getting distribution for 'distribute'.
Got distribute 99.99.
Upgraded:
...
...
@@ -111,7 +113,7 @@ will install earlier versions of these packages:
Now we can see that we actually "upgrade" to an earlier version.
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Upgraded:
distribute version 0.6;
restarting.
...
...
@@ -138,7 +140,7 @@ We won't upgrade in offline mode:
... recipe = showversions
... """ % dict(new_releases=new_releases))
>>> print
system(buildout+' -o'),
>>> print
_(system(buildout+' -o'), ed='')
Develop: '/sample-buildout/showversions'
Updating show-versions.
zc.buildout 1.0.0
...
...
@@ -146,7 +148,7 @@ We won't upgrade in offline mode:
Or in non-newest mode:
>>> print
system(buildout+' -N'),
>>> print
_(system(buildout+' -N'), end='')
Develop: '/sample-buildout/showversions'
Updating show-versions.
zc.buildout 1.0.0
...
...
@@ -166,7 +168,7 @@ directory:
... """ % dict(new_releases=new_releases))
>>> cd(sample_buildout2)
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Creating directory '/sample_buildout2/bin'.
Creating directory '/sample_buildout2/parts'.
Creating directory '/sample_buildout2/eggs'.
...
...
src/zc/buildout/windows.txt
View file @
83d53da5
...
...
@@ -14,6 +14,8 @@ can't delete.
>>> write('recipe', 'recipe.py',
... '''
... import os
... import sys
... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\n')
... class Recipe:
... def __init__(self, buildout, name, options):
... self.location = os.path.join(
...
...
@@ -21,7 +23,7 @@ can't delete.
... name)
...
... def install(self):
... print
"can't remove read only files"
... print
_("can't remove read only files")
... if not os.path.exists (self.location):
... os.makedirs (self.location)
...
...
...
@@ -43,7 +45,7 @@ can't delete.
>>> write('recipe', 'README', '')
>>> print
system(buildout+' setup recipe bdist_egg'),
# doctest: +ELLIPSIS
>>> print
_(system(buildout+' setup recipe bdist_egg'))
# doctest: +ELLIPSIS
Running setup script 'recipe/setup.py'.
...
...
...
@@ -59,7 +61,7 @@ and we'll configure a buildout to use it:
... recipe = spam
... ''' % join('recipe', 'dist'))
>>> print
system(buildout),
>>> print
_(system(buildout), end='')
Getting distribution for 'spam'.
Got spam 1.
Installing foo.
...
...
zc.recipe.egg_/src/zc/recipe/egg/custom.py
View file @
83d53da5
...
...
@@ -61,7 +61,7 @@ class Custom(Base):
self
.
environment
=
buildout
[
environment_section
]
else
:
self
.
environment
=
{}
environment_data
=
self
.
environment
.
items
(
)
environment_data
=
list
(
self
.
environment
.
items
()
)
environment_data
.
sort
()
options
[
'_environment-data'
]
=
repr
(
environment_data
)
...
...
@@ -98,7 +98,7 @@ class Custom(Base):
def
_set_environment
(
self
):
self
.
_saved_environment
=
{}
for
key
,
value
in
self
.
environment
.
items
(
):
for
key
,
value
in
list
(
self
.
environment
.
items
()
):
if
key
in
os
.
environ
:
self
.
_saved_environment
[
key
]
=
os
.
environ
[
key
]
# Interpolate value with variables from environment. Maybe there
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment