Merge lp://staging/~gary/zc.buildout/python-support-8-support-subprocess into lp://staging/zc.buildout

Proposed by Gary Poster
Status: Needs review
Proposed branch: lp://staging/~gary/zc.buildout/python-support-8-support-subprocess
Merge into: lp://staging/zc.buildout
Prerequisite: lp://staging/~gary/zc.buildout/python-support-7
Diff against target: 644 lines (+324/-65) (has conflicts)
8 files modified
bootstrap/bootstrap.py (+33/-10)
buildout.cfg (+3/-3)
dev.py (+43/-3)
src/zc/buildout/buildout.py (+40/-19)
src/zc/buildout/easy_install.py (+26/-8)
src/zc/buildout/easy_install.txt (+11/-1)
src/zc/buildout/tests.py (+149/-5)
src/zc/buildout/update.txt (+19/-16)
Text conflict in CHANGES.txt
Text conflict in src/zc/buildout/buildout.py
Text conflict in src/zc/buildout/buildout.txt
Text conflict in src/zc/buildout/easy_install.py
Text conflict in src/zc/buildout/tests.py
To merge this branch: bzr merge lp://staging/~gary/zc.buildout/python-support-8-support-subprocess
Reviewer Review Type Date Requested Status
Francis J. Lacoste (community) Approve
Review via email: mp+21732@code.staging.launchpad.net

Description of the change

This branch does two things.

1) It makes it simple to start Python processes from scripts started with the new recipe: PYTHONPATH is set so that everything works by default.

2) It makes bootstrap.py (and dev.py) yet more robust in the face of system Pythons.

#1 affects #2.

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :
Revision history for this message
Francis J. Lacoste (flacoste) wrote :
Download full text (4.1 KiB)

> === modified file 'bootstrap/bootstrap.py'
> +# In order to be more robust in the face of system Pythons, we want to run
> +# with site-packages loaded. This is somewhat tricky, in particular because

With or without? It seems that you want to run with it, but remove any all
namespace from it? Anyway the comment could be clearer given the
non-obviousness of the code.

> +# Python 2.6's distutils imports site, so starting with the -S flag is not
> +# sufficient.
> +if 'site' in sys.modules:
> + # We will restart with python -S.
> + args = sys.argv[:]
> + args[0:0] = [sys.executable, '-S']
> + args = map(quote, args)
> + os.execv(sys.executable, args)
> +clean_path = sys.path[:]
> +import site
> +sys.path[:] = clean_path
> +for k, v in sys.modules.items():
> + if (hasattr(v, '__path__') and
> + len(v.__path__)==1 and
> + not os.path.exists(os.path.join(v.__path__[0],'__init__.py'))):
> + # This is a namespace package. Remove it.
> + sys.modules.pop(k)
> +

> === modified file 'dev.py'
> +# In order to be more robust in the face of system Pythons, we want to run
> +# with site-packages loaded. This is somewhat tricky, in particular because
> +# Python 2.6's distutils imports site, so starting with the -S flag is not
> +# sufficient.

Since this is copy and paste from the other location, my other comment applies
here also.

> +if 'site' in sys.modules:
> + # We will restart with python -S.
> + args = sys.argv[:]
> + args[0:0] = [sys.executable, '-S']
> + args = map(quote, args)
> + os.execv(sys.executable, args)
> +clean_path = sys.path[:]
> +import site
> +sys.path[:] = clean_path
> +for k, v in sys.modules.items():
> + if (hasattr(v, '__path__') and
> + len(v.__path__)==1 and
> + not os.path.exists(os.path.join(v.__path__[0],'__init__.py'))):
> + # This is a namespace package. Remove it.
> + sys.modules.pop(k)
> +
> is_jython = sys.platform.startswith('java')

> === modified file 'src/zc/buildout/buildout.py'

> - args.insert(0, zc.buildout.easy_install._safe_arg (sys.executable))
> -
> + args.insert(0, zc.buildout.easy_install._safe_arg(sys.executable))
> + env = os.environ.copy()
> + env['PYTHONPATH'] = partsdir
> if is_jython:
> - sys.exit(subprocess.Popen([sys.executable] + list(args)).wait())
> + sys.exit(
> + subprocess.Popen(
> + [sys.executable] + list(args), env=env).wait())
> else:
> - sys.exit(os.spawnv(os.P_WAIT, sys.executable, args))
> + sys.exit(os.spawnve(os.P_WAIT, sys.executable, args, env))
>

The intent here is to run the script with only partsdir in the path?

> === modified file 'src/zc/buildout/easy_install.py'
> --- src/zc/buildout/easy_install.py 2010-03-19 16:04:20 +0000
> +++ src/zc/buildout/easy_install.py 2010-03-19 16:04:20 +0000
> @@ -99,6 +99,7 @@
> "print repr([os.path.normpath(p) for p in sys.path if p])"])
> # Windows needs some (as yet to be determined) part of the real env.
> env = os.environ.copy()
> + env.pop('PYTHONPATH', None)

Care to explain w...

Read more...

review: Needs Information
564. By Gary Poster

add explanatory comments; extend test to show that scripts honor explicit PYTHONPATH

Revision history for this message
Gary Poster (gary) wrote :

Good call on all comments. In the new revision, I answered your questions in the new code comments, and added a test as you described.

(Yes, we want to run without site-packages loaded.)

Revision history for this message
Francis J. Lacoste (flacoste) wrote :

All good!

review: Approve

Unmerged revisions

564. By Gary Poster

add explanatory comments; extend test to show that scripts honor explicit PYTHONPATH

563. By Gary Poster

fix intermittent test failure in update.txt

562. By Gary Poster

fixes for bootstrap and a system Python; changes based on learning what would be necessary to be able to develop buildout with a system Python (zc.recipe.testing would also need to use sitepackage_safe_scripts)

561. By Gary Poster

set up PYTHONPATH for scripts too, so subprocesses are good to go by default.

560. By Gary Poster

merge from gary-6 <- gary-5

559. By Gary Poster

with these changes, I can build zc.buildout and run its tests successfully with my system Python. To make it fully robust, zc.recipe.test probably would need to use sitepackage_safe_scripts, but this works for now.

558. By Gary Poster

add test for recent fix for buildout

557. By Gary Poster

make the buildout script itself safe for a Python with site packages.

556. By Gary Poster

merge from gary-5 <- gary-4

555. By Gary Poster

merge from gary-5 <- gary-4

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to all changes: