Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Don't link in libpython / libpypy #5

Merged
merged 3 commits into from
Jan 31, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- repo: https://github.com/pre-commit/pre-commit-hooks.git
sha: 97b88d9610bcc03982ddac33caba98bb2b751f5f
sha: v0.7.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -10,7 +10,7 @@
- id: requirements-txt-fixer
- id: flake8
- repo: https://github.com/asottile/reorder_python_imports.git
sha: 50e0be95e292cac913cc3c6fd44b3d6b51d104c5
sha: v0.3.1
hooks:
- id: reorder-python-imports
- repo: local
Expand Down
31 changes: 13 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
language: python
env:
- TOXENV=py27 GO=1.5
- TOXENV=py27 GO=1.6
- TOXENV=py34 GO=1.6
- TOXENV=py35 GO=1.6
- TOXENV=pypy GO=1.6
sudo: false
matrix:
include:
- env: TOXENV=py27 GO=1.6
- env: TOXENV=py27 GO=1.7
- env: TOXENV=py35 GO=1.7
python: 3.5
- env: TOXENV=py36 GO=1.7
python: 3.6
- env: TOXENV=pypy GO=1.7
python: pypy
install:
- eval "$(gimme $GO)"
- pip install coveralls tox
script:
- tox
after_success:
- coveralls
sudo: false
script: tox
after_success: coveralls
cache:
directories:
- $HOME/.cache/pip
- $HOME/.pre-commit
addons:
apt:
sources:
- deadsnakes
packages:
- python3.4-dev
- python3.5-dev
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ all: venv test
venv: .venv.touch
tox -e venv $(REBUILD_FLAG)

.PHONY: tests test
tests: test
.PHONY: test
test: .venv.touch
tox $(REBUILD_FLAG)

Expand All @@ -18,7 +17,7 @@ test: .venv.touch

.PHONY: clean
clean:
find . -name '*.pyc' -delete
find -name '*.pyc' -delete
rm -rf .tox
rm -rf ./venv-*
rm -f .venv.touch
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ A setuptools extension for building cpython extensions written in golang.

## Requirements

This requires golang >= 1.5. It is currently tested against 1.5 and 1.6.
This requires golang >= 1.5. It is currently tested against 1.6 and 1.7.

This requires python >= 2.7. It is currently tested against 2.7, 3.4, 3.5,
This requires python >= 2.7. It is currently tested against 2.7, 3.5, 3.6,
and pypy.

It is incompatible with pypy3 (for now) due to a lack of c-api.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
Expand Down
65 changes: 10 additions & 55 deletions setuptools_golang.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import unicode_literals

import contextlib
import distutils.sysconfig
import os
import pipes
import shutil
Expand All @@ -13,50 +12,11 @@
from setuptools.command.build_ext import build_ext as _build_ext


PYPY = '__pypy__' in sys.builtin_module_names


def _get_cflags(compiler):
return ' '.join('-I{}'.format(p) for p in compiler.include_dirs)


def _get_ldflags_pypy():
if PYPY: # pragma: no cover (pypy only)
return '-L{} -lpypy-c'.format(
os.path.dirname(os.path.realpath(sys.executable)),
)
else:
return None


def _get_ldflags_pkg_config():
try:
return subprocess.check_output((
'pkg-config', '--libs',
'python-{}.{}'.format(*sys.version_info[:2]),
)).decode('UTF-8').strip()
except (subprocess.CalledProcessError, OSError):
return None


def _get_ldflags_bldlibrary():
return distutils.sysconfig.get_config_var('BLDLIBRARY')


def _get_ldflags():
for func in (
_get_ldflags_pypy,
_get_ldflags_pkg_config,
_get_ldflags_bldlibrary,
):
ret = func()
if ret is not None:
return ret
else:
raise AssertionError('Could not determine ldflags!')


def _print_cmd(env, cmd):
def _check_call(cmd, cwd, env):
envparts = [
'{}={}'.format(k, pipes.quote(v))
for k, v in sorted(tuple(env.items()))
Expand All @@ -65,6 +25,7 @@ def _print_cmd(env, cmd):
'$ {}'.format(' '.join(envparts + [pipes.quote(p) for p in cmd])),
file=sys.stderr,
)
subprocess.check_call(cmd, cwd=cwd, env=dict(os.environ, **env))


@contextlib.contextmanager
Expand Down Expand Up @@ -106,25 +67,19 @@ def _raise_error(msg):
shutil.copytree('.', root_path)
pkg_path = os.path.join(root_path, main_dir)

env = {
'GOPATH': tempdir,
'CGO_CFLAGS': _get_cflags(self.compiler),
'CGO_LDFLAGS': _get_ldflags(),
}
cmd_get = ('go', 'get')
_print_cmd(env, cmd_get)
subprocess.check_call(
cmd_get, cwd=pkg_path, env=dict(os.environ, **env),
)
env = {'GOPATH': tempdir}
cmd_get = ('go', 'get', '-d')
_check_call(cmd_get, cwd=pkg_path, env=env)

env.update({
'CGO_CFLAGS': _get_cflags(self.compiler),
'CGO_LDFLAGS': '-Wl,--unresolved-symbols=ignore-all',
})
cmd_build = (
'go', 'build', '-buildmode=c-shared',
'-o', os.path.abspath(self.get_ext_fullpath(ext.name)),
)
_print_cmd(env, cmd_build)
subprocess.check_call(
cmd_build, cwd=pkg_path, env=dict(os.environ, **env),
)
_check_call(cmd_build, cwd=pkg_path, env=env)

return build_extension

Expand Down
29 changes: 0 additions & 29 deletions setuptools_golang_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
import setuptools_golang


xfailif_pypy = pytest.mark.xfail(
setuptools_golang.PYPY, reason='pypy is a special snowflake',
)


@pytest.fixture(autouse=True, scope='session')
def enable_coverage_subprocesses():
here = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -56,30 +51,6 @@ def test_sets_cmdclass():
assert dist.cmdclass['build_ext']


GET_LDFLAGS = (
'import distutils.spawn;'
"print(bool(distutils.spawn.find_executable('pkg-config')));"
'import setuptools_golang;'
'print(setuptools_golang._get_ldflags());'
)


@xfailif_pypy
def test_from_pkg_config():
output = run_output(sys.executable, '-c', GET_LDFLAGS)
assert output.startswith('True\n')
assert '-lpython' in output


@xfailif_pypy
def test_no_pkg_config():
# Blank PATH so we don't have pkg-config
env = dict(os.environ, PATH='')
output = run_output(sys.executable, '-c', GET_LDFLAGS, env=env)
assert output.startswith('False\n')
assert '-lpython' in output


@pytest.yield_fixture(scope='session')
def venv(tmpdir_factory):
"""A shared virtualenv fixture, be careful not to install two of the same
Expand Down
13 changes: 1 addition & 12 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
project = setuptools-golang
# These should match the travis env list
envlist = py27,py34,py35,pypy
envlist = py27,py35,py36,pypy

[testenv]
deps = -rrequirements-dev.txt
Expand All @@ -15,17 +15,6 @@ commands =
pre-commit install -f --install-hooks
pre-commit run --all-files

[testenv:pypy]
deps = {[testenv]deps}
passenv = {[testenv]passenv}
setenv = {[testenv]setenv}
commands =
coverage erase
coverage run -m pytest {posargs:setuptools_golang_test.py}
coverage combine
# Omit --fail-under for pypy
coverage report --show-missing

[testenv:venv]
envdir = venv-{[tox]project}
commands =
Expand Down