Skip to content

Commit 24c6e24

Browse files
authored
Merge pull request asottile-archive#5 from asottile/dont_link
Don't link in libpython / libpypy
2 parents c0110c1 + f03b69a commit 24c6e24

8 files changed

+31
-122
lines changed

Diff for: .pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- repo: https://github.com/pre-commit/pre-commit-hooks.git
2-
sha: 97b88d9610bcc03982ddac33caba98bb2b751f5f
2+
sha: v0.7.0
33
hooks:
44
- id: trailing-whitespace
55
- id: end-of-file-fixer
@@ -10,7 +10,7 @@
1010
- id: requirements-txt-fixer
1111
- id: flake8
1212
- repo: https://github.com/asottile/reorder_python_imports.git
13-
sha: 50e0be95e292cac913cc3c6fd44b3d6b51d104c5
13+
sha: v0.3.1
1414
hooks:
1515
- id: reorder-python-imports
1616
- repo: local

Diff for: .travis.yml

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
language: python
2-
env:
3-
- TOXENV=py27 GO=1.5
4-
- TOXENV=py27 GO=1.6
5-
- TOXENV=py34 GO=1.6
6-
- TOXENV=py35 GO=1.6
7-
- TOXENV=pypy GO=1.6
2+
sudo: false
3+
matrix:
4+
include:
5+
- env: TOXENV=py27 GO=1.6
6+
- env: TOXENV=py27 GO=1.7
7+
- env: TOXENV=py35 GO=1.7
8+
python: 3.5
9+
- env: TOXENV=py36 GO=1.7
10+
python: 3.6
11+
- env: TOXENV=pypy GO=1.7
12+
python: pypy
813
install:
914
- eval "$(gimme $GO)"
1015
- pip install coveralls tox
11-
script:
12-
- tox
13-
after_success:
14-
- coveralls
15-
sudo: false
16+
script: tox
17+
after_success: coveralls
1618
cache:
1719
directories:
1820
- $HOME/.cache/pip
1921
- $HOME/.pre-commit
20-
addons:
21-
apt:
22-
sources:
23-
- deadsnakes
24-
packages:
25-
- python3.4-dev
26-
- python3.5-dev

Diff for: Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ all: venv test
77
venv: .venv.touch
88
tox -e venv $(REBUILD_FLAG)
99

10-
.PHONY: tests test
11-
tests: test
10+
.PHONY: test
1211
test: .venv.touch
1312
tox $(REBUILD_FLAG)
1413

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

1918
.PHONY: clean
2019
clean:
21-
find . -name '*.pyc' -delete
20+
find -name '*.pyc' -delete
2221
rm -rf .tox
2322
rm -rf ./venv-*
2423
rm -f .venv.touch

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ A setuptools extension for building cpython extensions written in golang.
88

99
## Requirements
1010

11-
This requires golang >= 1.5. It is currently tested against 1.5 and 1.6.
11+
This requires golang >= 1.5. It is currently tested against 1.6 and 1.7.
1212

13-
This requires python >= 2.7. It is currently tested against 2.7, 3.4, 3.5,
13+
This requires python >= 2.7. It is currently tested against 2.7, 3.5, 3.6,
1414
and pypy.
1515

1616
It is incompatible with pypy3 (for now) due to a lack of c-api.

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
'Programming Language :: Python :: 2',
1717
'Programming Language :: Python :: 2.7',
1818
'Programming Language :: Python :: 3',
19-
'Programming Language :: Python :: 3.4',
2019
'Programming Language :: Python :: 3.5',
20+
'Programming Language :: Python :: 3.6',
2121
'Programming Language :: Python :: Implementation :: CPython',
2222
'Programming Language :: Python :: Implementation :: PyPy',
2323
],

Diff for: setuptools_golang.py

+10-55
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import unicode_literals
33

44
import contextlib
5-
import distutils.sysconfig
65
import os
76
import pipes
87
import shutil
@@ -13,50 +12,11 @@
1312
from setuptools.command.build_ext import build_ext as _build_ext
1413

1514

16-
PYPY = '__pypy__' in sys.builtin_module_names
17-
18-
1915
def _get_cflags(compiler):
2016
return ' '.join('-I{}'.format(p) for p in compiler.include_dirs)
2117

2218

23-
def _get_ldflags_pypy():
24-
if PYPY: # pragma: no cover (pypy only)
25-
return '-L{} -lpypy-c'.format(
26-
os.path.dirname(os.path.realpath(sys.executable)),
27-
)
28-
else:
29-
return None
30-
31-
32-
def _get_ldflags_pkg_config():
33-
try:
34-
return subprocess.check_output((
35-
'pkg-config', '--libs',
36-
'python-{}.{}'.format(*sys.version_info[:2]),
37-
)).decode('UTF-8').strip()
38-
except (subprocess.CalledProcessError, OSError):
39-
return None
40-
41-
42-
def _get_ldflags_bldlibrary():
43-
return distutils.sysconfig.get_config_var('BLDLIBRARY')
44-
45-
46-
def _get_ldflags():
47-
for func in (
48-
_get_ldflags_pypy,
49-
_get_ldflags_pkg_config,
50-
_get_ldflags_bldlibrary,
51-
):
52-
ret = func()
53-
if ret is not None:
54-
return ret
55-
else:
56-
raise AssertionError('Could not determine ldflags!')
57-
58-
59-
def _print_cmd(env, cmd):
19+
def _check_call(cmd, cwd, env):
6020
envparts = [
6121
'{}={}'.format(k, pipes.quote(v))
6222
for k, v in sorted(tuple(env.items()))
@@ -65,6 +25,7 @@ def _print_cmd(env, cmd):
6525
'$ {}'.format(' '.join(envparts + [pipes.quote(p) for p in cmd])),
6626
file=sys.stderr,
6727
)
28+
subprocess.check_call(cmd, cwd=cwd, env=dict(os.environ, **env))
6829

6930

7031
@contextlib.contextmanager
@@ -106,25 +67,19 @@ def _raise_error(msg):
10667
shutil.copytree('.', root_path)
10768
pkg_path = os.path.join(root_path, main_dir)
10869

109-
env = {
110-
'GOPATH': tempdir,
111-
'CGO_CFLAGS': _get_cflags(self.compiler),
112-
'CGO_LDFLAGS': _get_ldflags(),
113-
}
114-
cmd_get = ('go', 'get')
115-
_print_cmd(env, cmd_get)
116-
subprocess.check_call(
117-
cmd_get, cwd=pkg_path, env=dict(os.environ, **env),
118-
)
70+
env = {'GOPATH': tempdir}
71+
cmd_get = ('go', 'get', '-d')
72+
_check_call(cmd_get, cwd=pkg_path, env=env)
11973

74+
env.update({
75+
'CGO_CFLAGS': _get_cflags(self.compiler),
76+
'CGO_LDFLAGS': '-Wl,--unresolved-symbols=ignore-all',
77+
})
12078
cmd_build = (
12179
'go', 'build', '-buildmode=c-shared',
12280
'-o', os.path.abspath(self.get_ext_fullpath(ext.name)),
12381
)
124-
_print_cmd(env, cmd_build)
125-
subprocess.check_call(
126-
cmd_build, cwd=pkg_path, env=dict(os.environ, **env),
127-
)
82+
_check_call(cmd_build, cwd=pkg_path, env=env)
12883

12984
return build_extension
13085

Diff for: setuptools_golang_test.py

-29
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
import setuptools_golang
1212

1313

14-
xfailif_pypy = pytest.mark.xfail(
15-
setuptools_golang.PYPY, reason='pypy is a special snowflake',
16-
)
17-
18-
1914
@pytest.fixture(autouse=True, scope='session')
2015
def enable_coverage_subprocesses():
2116
here = os.path.dirname(os.path.abspath(__file__))
@@ -56,30 +51,6 @@ def test_sets_cmdclass():
5651
assert dist.cmdclass['build_ext']
5752

5853

59-
GET_LDFLAGS = (
60-
'import distutils.spawn;'
61-
"print(bool(distutils.spawn.find_executable('pkg-config')));"
62-
'import setuptools_golang;'
63-
'print(setuptools_golang._get_ldflags());'
64-
)
65-
66-
67-
@xfailif_pypy
68-
def test_from_pkg_config():
69-
output = run_output(sys.executable, '-c', GET_LDFLAGS)
70-
assert output.startswith('True\n')
71-
assert '-lpython' in output
72-
73-
74-
@xfailif_pypy
75-
def test_no_pkg_config():
76-
# Blank PATH so we don't have pkg-config
77-
env = dict(os.environ, PATH='')
78-
output = run_output(sys.executable, '-c', GET_LDFLAGS, env=env)
79-
assert output.startswith('False\n')
80-
assert '-lpython' in output
81-
82-
8354
@pytest.yield_fixture(scope='session')
8455
def venv(tmpdir_factory):
8556
"""A shared virtualenv fixture, be careful not to install two of the same

Diff for: tox.ini

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
project = setuptools-golang
33
# These should match the travis env list
4-
envlist = py27,py34,py35,pypy
4+
envlist = py27,py35,py36,pypy
55

66
[testenv]
77
deps = -rrequirements-dev.txt
@@ -15,17 +15,6 @@ commands =
1515
pre-commit install -f --install-hooks
1616
pre-commit run --all-files
1717

18-
[testenv:pypy]
19-
deps = {[testenv]deps}
20-
passenv = {[testenv]passenv}
21-
setenv = {[testenv]setenv}
22-
commands =
23-
coverage erase
24-
coverage run -m pytest {posargs:setuptools_golang_test.py}
25-
coverage combine
26-
# Omit --fail-under for pypy
27-
coverage report --show-missing
28-
2918
[testenv:venv]
3019
envdir = venv-{[tox]project}
3120
commands =

0 commit comments

Comments
 (0)