Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Remove the sys.exit(1) when setup.py is run on PY3. #13

Merged
merged 3 commits into from
Aug 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions python3_redirect/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""When installed as subprocess32, this sets up a redirect to subprocess."""

import subprocess
import sys
if sys.version_info[:2] < (3,3):
raise ImportError('Ancient Python 3 versions are not supported.')
# Doing this could crash some older Python interpreters due to the module
# reference going away before the import is complete?
sys.modules['subprocess32'] = subprocess
42 changes: 27 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
#!/usr/bin/python
#!/usr/bin/env python2

import os
import sys
from distutils.core import setup, Extension


def main():
if sys.version_info[0] != 2:
sys.stderr.write('This backport is for Python 2.x only.\n')
sys.exit(1)

ext = Extension('_posixsubprocess', ['_posixsubprocess.c'],
depends=['_posixsubprocess_helpers.c'])
if os.name == 'posix':
ext_modules = [ext]
else:
ext_modules = []
ext_modules = []
py_modules = []
packages = []
package_dir = {}
if sys.version_info[0] == 2: # PY2
py_modules.append('subprocess32')
if os.name == 'posix':
ext = Extension('_posixsubprocess', ['_posixsubprocess.c'],
depends=['_posixsubprocess_helpers.c'])
ext_modules.append(ext)
else: # PY3
# Install a redirect that makes subprocess32 == subprocess on import.
packages.append('subprocess32')
package_dir['subprocess32'] = 'python3_redirect'
sys.stderr.write('subprocess32 == subprocess on Python 3.\n')

setup(
name='subprocess32',
version='3.2.7',
version='3.2.8.dev',
description='A backport of the subprocess module from Python 3.2/3.3 for use on 2.x.',
long_description="""
long_description="""\
This is a backport of the subprocess standard library module from
Python 3.2 & 3.3 for use on Python 2.

It includes bugfixes and some new features. On POSIX systems it is
guaranteed to be reliable when used in threaded applications.
It includes timeout support from Python 3.3 but otherwise matches
3.2's API. It has not been tested on Windows.""",
3.2's API.

It has not been tested by the author on Windows.

On Python 3, it merely redirects the subprocess32 name to subprocess.""",
license='PSF license',

maintainer='Gregory P. Smith',
maintainer_email='greg@krypto.org',
url='https://github.com/google/python-subprocess32',

ext_modules=ext_modules,
py_modules=['subprocess32'],
py_modules=py_modules,
packages=packages,
package_dir=package_dir,

classifiers=[
'Intended Audience :: Developers',
Expand Down
26 changes: 18 additions & 8 deletions test
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#!/bin/bash
#!/bin/bash -ex

# This is for my own convenience, edit it for your own environment.

PYTHON=../Python-2.4.6/python
$PYTHON setup.py build || exit 1
LANG=C PYTHONPATH=./build/lib.linux-x86_64-2.4 $PYTHON test_subprocess32.py || exit 1
PYTHON=python3
"$PYTHON" -V
"$PYTHON" setup.py build
# Merely test that it imports. Under Python 3, setup.py should've installed a
# redirection hack making subprocess32 == subprocess. We cd in order to avoid
# attempting to import the local subprocess32.py file.
(cd build && PYTHONPATH=lib "$PYTHON" -c \
"import subprocess as s, subprocess32 as s32; assert s is s32, (s, s32)")

PYTHON=python2
$PYTHON setup.py build || exit 1
PYTHON="../Python-2.4.6/python"
"$PYTHON" -V
"$PYTHON" setup.py build
LANG=C PYTHONPATH=build/lib.linux-x86_64-2.4 "$PYTHON" test_subprocess32.py

export PYTHONPATH=./build/lib.linux-x86_64-2.7
exec $PYTHON test_subprocess32.py
PYTHON=python2
"$PYTHON" -V
"$PYTHON" setup.py build
export PYTHONPATH=build/lib.linux-x86_64-2.7
exec "$PYTHON" test_subprocess32.py