Skip to content

Commit

Permalink
Merge python3-setup-6539-2. Make setup.py install on Python 3.
Browse files Browse the repository at this point in the history
Author: itamar
Reviewer: exarkun, hynek
Fixes: twisted#6539

setup.py install and pip install now work on Python 3.3.


git-svn-id: svn://svn.twistedmatrix.com/svn/Twisted/trunk@41379 bbbe8e31-12d6-0310-92fd-ac37d47ddeeb
  • Loading branch information
itamarst committed Jan 21, 2014
1 parent 15db086 commit 4ece689
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
try:
# Load setuptools, to build a specific source package
import setuptools
# Tell Twisted not to enforce zope.interface requirement on import, since
# we're going to have to import twisted.python.dist and can rely on
# setuptools to install dependencies.
setuptools._TWISTED_NO_CHECK_REQUIREMENTS = True
except ImportError:
pass

Expand All @@ -25,6 +29,12 @@ def main(args):
if os.path.exists('twisted'):
sys.path.insert(0, '.')

# On Python 3, use setup3.py until Python 3 port is done:
if sys.version_info[0] > 2:
import setup3
setup3.main()
return

setup_args = {}

if 'setuptools' in sys.modules:
Expand All @@ -39,7 +49,6 @@ def main(args):
""")
else:
setup_args['install_requires'] = requirements
setuptools._TWISTED_NO_CHECK_REQUIREMENTS = True
setup_args['include_package_data'] = True
setup_args['zip_safe'] = False

Expand Down
29 changes: 22 additions & 7 deletions setup3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import division, absolute_import

import sys

from distutils.command.sdist import sdist

# A list of modules that have been ported, e.g. "twisted.python.versions"; a
# package name (e.g. "twisted.python") indicates the corresponding __init__.py
Expand Down Expand Up @@ -249,18 +249,33 @@



if __name__ == "__main__":
sys.path.insert(0, '.')
class DisabledSdist(sdist):
"""
A version of the sdist command that does nothing.
"""
def run(self):
sys.stderr.write(
"The sdist command only works with Python 2 at the moment.\n")
sys.exit(1)



from distutils.core import setup
def main():
try:
from setuptools import setup
except ImportError:
from distutils.core import setup

from twisted.python.dist import STATIC_PACKAGE_METADATA

args = STATIC_PACKAGE_METADATA.copy()
args['install_requires'] = ["zope.interface >= 4.0.2"]
args['classifiers'] = ["Programming Language :: Python :: 3.3"]
args['py_modules'] = modules + testModules + almostModules

if 'sdist' in sys.argv:
args['data_files'] = [('admin', ['admin/run-python3-tests'])]
args['cmdclass'] = {'sdist': DisabledSdist}

setup(**args)


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions twisted/python/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
classifiers=[
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
],
)

Expand Down
20 changes: 20 additions & 0 deletions twisted/python/test/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,26 @@ def test_coreProjectLayout(self):
self.assertExtractedStructure(outputFile, outStructure)


def test_setup3(self):
"""
setup3.py is included in the release tarball.
"""
structure = {
"setup3.py": "install python 3 version",
"bin": {"twistd": "TWISTD"},
"twisted": {
"web": {
"__init__.py": "import WEB",
"topfiles": {"setup.py": "import WEBINSTALL",
"README": "WEB!"}}},
"doc": {"web": {"howto": {"index.html": "hello"}}},
}

self.createStructure(self.rootDir, structure)
outputFile = self.builder.buildTwisted("13.2.0")
self.assertExtractedStructure(outputFile, structure)



class BuildAllTarballsTest(DistributionBuilderTestBase):
"""
Expand Down
1 change: 1 addition & 0 deletions twisted/topfiles/6539.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"setup.py install" and "pip install" now work on Python 3.3, installing the subset of Twisted that has been ported to Python 3.

0 comments on commit 4ece689

Please sign in to comment.