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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
slapos.buildout
Commits
7e825d61
Commit
7e825d61
authored
Feb 12, 2010
by
Gary Poster
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify resulting site.py function
parent
8f1f787f
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
202 additions
and
271 deletions
+202
-271
src/zc/buildout/easy_install.py
src/zc/buildout/easy_install.py
+59
-88
src/zc/buildout/easy_install.txt
src/zc/buildout/easy_install.txt
+125
-166
src/zc/buildout/tests.py
src/zc/buildout/tests.py
+7
-4
z3c.recipe.scripts_/src/z3c/recipe/scripts/README.txt
z3c.recipe.scripts_/src/z3c/recipe/scripts/README.txt
+8
-11
z3c.recipe.scripts_/src/z3c/recipe/scripts/tests.py
z3c.recipe.scripts_/src/z3c/recipe/scripts/tests.py
+3
-2
No files found.
src/zc/buildout/easy_install.py
View file @
7e825d61
...
@@ -1390,69 +1390,66 @@ def _generate_site(dest, working_set, executable, extra_paths=(),
...
@@ -1390,69 +1390,66 @@ def _generate_site(dest, working_set, executable, extra_paths=(),
rpsetup
=
'
\
n
'
.
join
(
rpsetup
=
'
\
n
'
.
join
(
[(
line
and
' %s'
%
(
line
,)
or
line
)
[(
line
and
' %s'
%
(
line
,)
or
line
)
for
line
in
rpsetup
.
split
(
'
\
n
'
)])
for
line
in
rpsetup
.
split
(
'
\
n
'
)])
real_site_path
=
_get_module_file
(
executable
,
'site'
)
namespace_setup
=
''
real_site
=
open
(
real_site_path
,
'r'
)
addsitedir
=
addsitedir_snippet
site
=
open
(
site_path
,
'w'
)
extra_path_snippet
=
add_site_packages_snippet
[
add_site_packages
]
extra_path_snippet_followup
=
add_site_packages_snippet_followup
[
add_site_packages
]
if
add_site_packages
:
if
add_site_packages
:
stdlib
,
site_paths
=
_get_system_paths
(
executable
)
stdlib
,
site_paths
=
_get_system_paths
(
executable
)
extra_path_snippet
=
extra_path_snippet
%
_format_paths
(
path_string
=
''
.
join
([
(
repr
(
p
)
for
p
in
site_paths
),
2
)
path_string
,
(
",
\
n
"
" # These are the underlying Python's site-packages.
\
n
"
" "
),
_format_paths
((
repr
(
p
)
for
p
in
site_paths
),
2
)])
distribution
=
working_set
.
find
(
pkg_resources
.
Requirement
.
parse
(
'setuptools'
))
if
distribution
is
not
None
:
# We need to worry about namespace packages.
namespace_setup
=
namespace_add_site_packages_setup
%
(
distribution
.
location
,)
addsitedir
=
addsitedir_namespace_add_site_packages_snippet
addsitepackages_marker
=
'def addsitepackages('
addsitepackages_marker
=
'def addsitepackages('
enableusersite_marker
=
'ENABLE_USER_SITE = '
enableusersite_marker
=
'ENABLE_USER_SITE = '
successful_rewrite
=
False
successful_rewrite
=
False
real_site_path
=
_get_module_file
(
executable
,
'site'
)
real_site
=
open
(
real_site_path
,
'r'
)
site
=
open
(
site_path
,
'w'
)
try
:
for
line
in
real_site
.
readlines
():
for
line
in
real_site
.
readlines
():
if
line
.
startswith
(
enableusersite_marker
):
if
line
.
startswith
(
enableusersite_marker
):
site
.
write
(
enableusersite_marker
)
site
.
write
(
enableusersite_marker
)
site
.
write
(
'False # buildout does not support user sites.
\
n
'
)
site
.
write
(
'False # buildout does not support user sites.
\
n
'
)
elif
line
.
startswith
(
addsitepackages_marker
):
elif
line
.
startswith
(
addsitepackages_marker
):
site
.
write
(
addsitepackages_script
%
(
site
.
write
(
addsitepackages_script
%
(
extra_path_snippet
,
rpsetup
,
path_string
,
namespace_setup
,
rpsetup
,
path_string
,
addsitedir
))
extra_path_snippet_followup
))
site
.
write
(
line
[
len
(
addsitepackages_marker
):])
site
.
write
(
line
[
len
(
addsitepackages_marker
):])
successful_rewrite
=
True
successful_rewrite
=
True
else
:
else
:
site
.
write
(
line
)
site
.
write
(
line
)
finally
:
site
.
close
()
real_site
.
close
()
if
not
successful_rewrite
:
if
not
successful_rewrite
:
raise
RuntimeError
(
'Buildout did not successfully rewrite site.py'
)
raise
RuntimeError
(
'Buildout did not successfully rewrite site.py'
)
return
site_path
return
site_path
add_site_packages_snippet
=
[
'''
namespace_add_site_packages_setup
=
'''
paths = []'''
,
'''
setuptools_path = %r
paths = [ # These are the underlying Python's site-packages.
sys.path.append(setuptools_path)
%s]
known_paths.add(setuptools_path)
sys.path[0:0] = paths
import pkg_resources'''
known_paths.update([os.path.normcase(os.path.abspath(p)) for p in paths])
try:
import pkg_resources
except ImportError:
# No namespace packages in sys.path; no fixup needed.
pkg_resources = None'''
]
add_site_packages_snippet_followup
=
[
''
,
'''
if pkg_resources is not None:
# There may be namespace packages in sys.path. This is much faster
# than importing pkg_resources after the sys.path has a large number
# of eggs.
for p in sys.path:
pkg_resources.fixup_namespace_packages(p)'''
]
addsitepackages_script
=
'''
\
addsitedir_snippet
=
'''
def addsitepackages(known_paths):%s
for path in paths:
%s paths[0:0] = [ # eggs
addsitedir(path, known_paths)'''
%s
]
addsitedir_namespace_add_site_packages_snippet
=
'''
# Process all dirs. Look for .pth files. If they exist, defer
# processing "import" varieties.
dotpth = os.extsep + "pth"
dotpth = os.extsep + "pth"
deferred = []
for path in paths:
for path in reversed(paths):
# This duplicates addsitedir except for adding the pkg_resources call.
# Duplicating addsitedir.
sitedir, sitedircase = makepath(path)
sitedir, sitedircase = makepath(path)
if not sitedircase in known_paths and os.path.exists(sitedir):
if not sitedircase in known_paths and os.path.exists(sitedir):
sys.path.insert(0, sitedir)
sys.path.append(sitedir)
pkg_resources.working_set.add_entry(sitedir)
known_paths.add(sitedircase)
known_paths.add(sitedircase)
try:
try:
names = os.listdir(sitedir)
names = os.listdir(sitedir)
...
@@ -1461,44 +1458,18 @@ def addsitepackages(known_paths):%s
...
@@ -1461,44 +1458,18 @@ def addsitepackages(known_paths):%s
names = [name for name in names if name.endswith(dotpth)]
names = [name for name in names if name.endswith(dotpth)]
names.sort()
names.sort()
for name in names:
for name in names:
# Duplicating addpackage.
addpackage(sitedir, name, known_paths)'''
fullname = os.path.join(sitedir, name)
try:
addsitepackages_script
=
'''
\
f = open(fullname, "rU")
def addsitepackages(known_paths):
except IOError:
"""Add site packages.
continue
try:
This function is written by buildout. See original_addsitepackages,
for line in f:
below, for the original version."""%s
if line.startswith("#"):
%s paths = [
continue
# Eggs.
if (line.startswith("import ") or
%s
line.startswith("import
\
t
")):
]%s
# This line is supposed to be executed. It
# might be a setuptools namespace package
# installed with a system package manager.
# Defer this so we can process egg namespace
# packages first, or else the eggs with the same
# namespace will be ignored.
deferred.append((sitedir, name, fullname, line))
continue
line = line.rstrip()
dir, dircase = makepath(sitedir, line)
if not dircase in known_paths and os.path.exists(dir):
sys.path.append(dir)
known_paths.add(dircase)
finally:
f.close()%s
# Process "import ..." .pth lines.
for sitedir, name, fullname, line in deferred:
# Note that some lines--such as the one setuptools writes for
# namespace packages--expect some or all of sitedir, name, and
# fullname to be present in the frame locals, as it is in
# ``addpackage``.
try:
exec line
except:
print "Error in %%s" %% (fullname,)
raise
global addsitepackages
global addsitepackages
addsitepackages = original_addsitepackages
addsitepackages = original_addsitepackages
return known_paths
return known_paths
...
...
src/zc/buildout/easy_install.txt
View file @
7e825d61
This diff is collapsed.
Click to expand it.
src/zc/buildout/tests.py
View file @
7e825d61
...
@@ -2890,8 +2890,12 @@ def increment_on_command_line():
...
@@ -2890,8 +2890,12 @@ def increment_on_command_line():
######################################################################
######################################################################
def
make_py_with_system_install
(
make_py
,
sample_eggs
):
def
make_py_with_system_install
(
make_py
,
sample_eggs
):
from
zc.buildout.testing
import
write
,
mkdir
py_path
,
site_packages_path
=
make_py
()
py_path
,
site_packages_path
=
make_py
()
create_sample_namespace_eggs
(
sample_eggs
,
site_packages_path
)
return
py_path
def
create_sample_namespace_eggs
(
dest
,
site_packages_path
=
None
):
from
zc.buildout.testing
import
write
,
mkdir
for
pkg
,
version
in
((
'version'
,
'1.0'
),
(
'version'
,
'1.1'
),
for
pkg
,
version
in
((
'version'
,
'1.0'
),
(
'version'
,
'1.1'
),
(
'fortune'
,
'1.0'
)):
(
'fortune'
,
'1.0'
)):
tmp
=
tempfile
.
mkdtemp
()
tmp
=
tempfile
.
mkdtemp
()
...
@@ -2918,14 +2922,13 @@ def make_py_with_system_install(make_py, sample_eggs):
...
@@ -2918,14 +2922,13 @@ def make_py_with_system_install(make_py, sample_eggs):
" author='bob', url='bob', author_email='bob')
\
n
"
" author='bob', url='bob', author_email='bob')
\
n
"
%
locals
()
%
locals
()
)
)
zc
.
buildout
.
testing
.
sdist
(
tmp
,
sample_eggs
)
zc
.
buildout
.
testing
.
sdist
(
tmp
,
dest
)
if
pkg
==
'version'
and
version
==
'1.1'
:
if
(
site_packages_path
and
pkg
==
'version'
and
version
==
'1.1'
)
:
# We install the 1.1 version in site packages the way a
# We install the 1.1 version in site packages the way a
# system packaging system (debs, rpms) would do it.
# system packaging system (debs, rpms) would do it.
zc
.
buildout
.
testing
.
sys_install
(
tmp
,
site_packages_path
)
zc
.
buildout
.
testing
.
sys_install
(
tmp
,
site_packages_path
)
finally
:
finally
:
shutil
.
rmtree
(
tmp
)
shutil
.
rmtree
(
tmp
)
return
py_path
def
create_sample_eggs
(
test
,
executable
=
sys
.
executable
):
def
create_sample_eggs
(
test
,
executable
=
sys
.
executable
):
write
=
test
.
globs
[
'write'
]
write
=
test
.
globs
[
'write'
]
...
...
z3c.recipe.scripts_/src/z3c/recipe/scripts/README.txt
View file @
7e825d61
...
@@ -168,9 +168,8 @@ provided.
...
@@ -168,9 +168,8 @@ provided.
Here's an example of using the generated interpreter.
Here's an example of using the generated interpreter.
>>> print system(join(sample_buildout, 'bin', 'py') +
>>> print system(join(sample_buildout, 'bin', 'py') +
... ' -c "import sys, pprint; pprint.pprint(sys.path[:3])"')
... ' -c "import sys, pprint; pprint.pprint(sys.path[-2:])"')
['',
['/sample-buildout/eggs/demo-0.2-pyN.N.egg',
'/sample-buildout/eggs/demo-0.2-pyN.N.egg',
'/sample-buildout/eggs/demoneeded-1.2c1-pyN.N.egg']
'/sample-buildout/eggs/demoneeded-1.2c1-pyN.N.egg']
<BLANKLINE>
<BLANKLINE>
...
@@ -241,13 +240,12 @@ Now let's take a look at add-site-packages.
...
@@ -241,13 +240,12 @@ Now let's take a look at add-site-packages.
... ''' -c "import sys, pprint; pprint.pprint(sys.path)"''')
... ''' -c "import sys, pprint; pprint.pprint(sys.path)"''')
... # doctest: +ELLIPSIS
... # doctest: +ELLIPSIS
['',
['',
'/sample-buildout/parts/py',
...,
'/sample-buildout/eggs/demo-0.2-pyN.N.egg',
'/sample-buildout/eggs/demo-0.2-pyN.N.egg',
'/sample-buildout/eggs/demoneeded-1.2c1-pyN.N.egg',
'/sample-buildout/eggs/demoneeded-1.2c1-pyN.N.egg',
'/executable_buildout/eggs/setuptools-0.6c11-pyN.N.egg',
'/executable_buildout/eggs/setuptools-X-pyN.N.egg',
'/executable_buildout/site-packages',
'/executable_buildout/site-packages']
'/sample-buildout/parts/py',
'/executable_buildout/parts/py',
...]
<BLANKLINE>
<BLANKLINE>
Next we will use the exec-sitecustomize option. It simply copies
Next we will use the exec-sitecustomize option. It simply copies
...
@@ -327,9 +325,8 @@ Now let's put it in action.
...
@@ -327,9 +325,8 @@ Now let's put it in action.
Generated interpreter '/sample-buildout/bin/python'.
Generated interpreter '/sample-buildout/bin/python'.
>>> print system(join(sample_buildout, 'bin', 'python') +
>>> print system(join(sample_buildout, 'bin', 'python') +
... ' -c "import sys, pprint; pprint.pprint(sys.path[:3])"')
... ' -c "import sys, pprint; pprint.pprint(sys.path[-2:])"')
['',
['/sample-buildout/eggs/demo-0.2-pyN.N.egg',
'/sample-buildout/eggs/demo-0.2-pyN.N.egg',
'/sample-buildout/eggs/demoneeded-1.2c1-pyN.N.egg']
'/sample-buildout/eggs/demoneeded-1.2c1-pyN.N.egg']
<BLANKLINE>
<BLANKLINE>
>>> print system(join(sample_buildout, 'bin', 'python') +
>>> print system(join(sample_buildout, 'bin', 'python') +
...
...
z3c.recipe.scripts_/src/z3c/recipe/scripts/tests.py
View file @
7e825d61
...
@@ -226,7 +226,7 @@ Let's look at the site.py that was generated:
...
@@ -226,7 +226,7 @@ Let's look at the site.py that was generated:
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
#...
#...
def addsitepackages(known_paths):
def addsitepackages(known_paths):
paths = []
"..."
<BLANKLINE>
<BLANKLINE>
import os
import os
<BLANKLINE>
<BLANKLINE>
...
@@ -234,7 +234,8 @@ Let's look at the site.py that was generated:
...
@@ -234,7 +234,8 @@ Let's look at the site.py that was generated:
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
base = os.path.dirname(base)
base = os.path.dirname(base)
base = os.path.dirname(base)
base = os.path.dirname(base)
paths[0:0] = [ # eggs
paths = [
# Eggs.
'/foo/bar',
'/foo/bar',
join(base, 'spam')
join(base, 'spam')
]...
]...
...
...
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