Skip to content

Commit

Permalink
Remove custom my_build_ext and stop trying to build extensions at tes…
Browse files Browse the repository at this point in the history
…t time.

Building the extensions and getting them in the right place is the job of tox.

This includes a temporary minor regression in that the test extensions are now also packaged in the binary distributions. This will be resolved with #189 and #184.

Removes some (maybe all, didnt check yet) uses of distutils so partly addresses #185.

Fixes #187
  • Loading branch information
jamadden committed Nov 11, 2020
1 parent ede3fa5 commit fbcc055
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 160 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- (Packaging) Require setuptools to build from source.
- (Packaging) Stop asking setuptools to build both .tar.gz and .zip
sdists. PyPI has standardized on .tar.gz for all platforms.
- (Packaging) Stop using a custom distutils command to build
extensions. distutils is deprecated.
- (Documentation) Publish the change log to https://greenlet.readthedocs.io
- Drop support for Python 2.4, 2.5, 2.6, 3.0, 3.1, 3.2 and 3.4.
The project metadata now includes the ``python_requires`` data to
Expand Down
60 changes: 0 additions & 60 deletions my_build_ext.py

This file was deleted.

50 changes: 12 additions & 38 deletions run-tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#! /usr/bin/env python
from __future__ import print_function

import sys
import os
import struct
import unittest

import sys, os, getopt, struct, unittest
from distutils.spawn import spawn

build = True
verbosity = 2
build_base = None
here = os.path.dirname(os.path.abspath(__file__))
os.chdir(here)

Expand All @@ -15,49 +17,21 @@ def bits():
"""
return struct.calcsize("P") * 8

# -- parse options
try:
opts, args = getopt.getopt(sys.argv[1:], "nqb:")
if args:
raise getopt.GetoptError("too many arguments")
except getopt.GetoptError:
sys.exit("run-tests.py: error: %s" % sys.exc_info()[1])

for o, a in opts:
if o == "-q":
verbosity = 0
elif o == "-n":
build = False
elif o == "-b":
build_base = a

# -- build greenlet
if build:
if verbosity == 0:
cmd = [sys.executable, "setup.py", "-q", "build_ext", "-q", "-i"]
else:
cmd = [sys.executable, "setup.py", "build_ext", "-i"]

spawn(cmd, search_path=0)


# -- find greenlet but skip the one in "."
if not build:
oldpath = sys.path[:]
sys.path.remove(here)
oldpath = sys.path[:]
sys.path.remove(here)

import greenlet

if not build:
sys.path[:] = oldpath

sys.stdout.write("python %s (%s bit) using greenlet %s from %s\n" %
(sys.version.split()[0], bits(), greenlet.__version__, greenlet.__file__))
sys.stdout.flush()
sys.path[:] = oldpath

print("python %s (%s bit) using greenlet %s from %s\n" %
(sys.version.split()[0], bits(), greenlet.__version__, greenlet.__file__))

# -- run tests
from tests import test_collector
result = unittest.TextTestRunner(verbosity=verbosity).run(test_collector(build_base))
result = unittest.TextTestRunner(verbosity=verbosity).run(test_collector())
if result.failures or result.errors:
sys.exit(1)
39 changes: 28 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
from setuptools import setup
from setuptools import Extension

# XXX: This uses distutils directly and is probably
# unnecessary with setuptools.
from my_build_ext import build_ext

# workaround segfaults on openbsd and RHEL 3 / CentOS 3 . see
# https://bitbucket.org/ambroff/greenlet/issue/11/segfault-on-openbsd-i386
# https://github.com/python-greenlet/greenlet/issues/4
Expand Down Expand Up @@ -53,12 +49,34 @@ def _find_platform_headers():
else:
extra_compile_args = []

ext_modules = [Extension(
name='greenlet',
sources=['greenlet.c'],
extra_objects=extra_objects,
extra_compile_args=extra_compile_args,
depends=['greenlet.h', 'slp_platformselect.h'] + _find_platform_headers())]
ext_modules = [
Extension(
name='greenlet',
sources=['greenlet.c'],
extra_objects=extra_objects,
extra_compile_args=extra_compile_args,
depends=['greenlet.h', 'slp_platformselect.h'] + _find_platform_headers()
),
# Test extensions.
# XXX: We used to try hard to not include these in built
# distributions. That's really not important, at least not once we have a clean
# layout with the test directory nested inside a greenlet directory.
# See https://github.com/python-greenlet/greenlet/issues/184 and 189
Extension(
'_test_extension',
[os.path.join('tests', '_test_extension.c')],
include_dirs=[os.path.curdir]
),
]

if os.environ.get('GREENLET_TEST_CPP', 'yes').lower() not in ('0', 'no', 'false'):
ext_modules.append(
Extension(
'_test_extension_cpp',
[os.path.join('tests', '_test_extension_cpp.cpp')],
language="c++",
include_dirs=[os.path.curdir]),
)

setup(
name="greenlet",
Expand All @@ -75,7 +93,6 @@ def _find_platform_headers():
platforms=['any'],
headers=headers,
ext_modules=ext_modules,
cmdclass=dict(build_ext=build_ext),
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
Expand Down
48 changes: 3 additions & 45 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,14 @@
import os
import glob
import unittest
from distutils.core import setup, Extension

TEST_EXTENSIONS = [
Extension('_test_extension',
[os.path.join('tests', '_test_extension.c')],
include_dirs=[os.path.curdir]),
]

if os.environ.get('GREENLET_TEST_CPP', 'yes').lower() not in ('0', 'no', 'false'):
TEST_EXTENSIONS_CPP = [
Extension('_test_extension_cpp',
[os.path.join('tests', '_test_extension_cpp.cpp')],
language="c++",
include_dirs=[os.path.curdir]),
]
else:
TEST_EXTENSIONS_CPP = []


def test_collector(build_base=None):
def test_collector():
"""Collect all tests under the tests directory and return a
unittest.TestSuite
"""
build_test_extensions(build_base)
tests_dir = os.path.realpath(os.path.dirname(__file__))
test_module_list = [
'tests.%s' % os.path.splitext(os.path.basename(t))[0]
for t in glob.glob(os.path.join(tests_dir, 'test_*.py'))]
if not TEST_EXTENSIONS_CPP:
test_module_list.remove('tests.test_cpp')
for t in glob.glob(os.path.join(tests_dir, 'test_*.py'))
]
return unittest.TestLoader().loadTestsFromNames(test_module_list)


def build_test_extensions(build_base=None):
"""Because distutils sucks, it just copies the entire contents of the build
results dir (e.g. build/lib.linux-i686-2.6) during installation. That means
that we can't put any files there that we don't want to distribute.
To deal with it, this code will compile test extensions in a separate
directory, prepending it to sys.path afterwards. This way testing with
multiple Python release and pydebug versions works and test extensions
are not distributed.
"""
if build_base is None:
build_base = os.path.join('build', 'tests')
from my_build_ext import build_ext
setup(
options={
'build': {'build_base': build_base},
},
cmdclass=dict(build_ext=build_ext),
script_args=['-q', 'build_ext', '-q'],
ext_modules=TEST_EXTENSIONS + TEST_EXTENSIONS_CPP)
11 changes: 5 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[tox]
envlist =
py27,py35,py36,py37,py38,py39,docs

[testenv]
commands={envpython} run-tests.py -nq
commands=python run-tests.py
sitepackages=False

[testenv:x-py27]
commands=/usr/bin/arch -i386 {envpython} run-tests.py -qn
/usr/bin/arch -x86_64 {envpython} run-tests.py -qn
basepython=/usr/bin/python2.7


[testenv:docs]
# usedevelop to save rebuilding the extension
Expand Down

0 comments on commit fbcc055

Please sign in to comment.