diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 21342d0..26efa14 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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 diff --git a/.travis.yml b/.travis.yml index b8f1bd7..f2e3337 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Makefile b/Makefile index b38b1ae..a27d50a 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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 diff --git a/README.md b/README.md index 05d2295..912b57d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/setup.py b/setup.py index 74dfb3b..ce5cc51 100644 --- a/setup.py +++ b/setup.py @@ -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', ], diff --git a/setuptools_golang.py b/setuptools_golang.py index da7624d..56fb29e 100644 --- a/setuptools_golang.py +++ b/setuptools_golang.py @@ -2,7 +2,6 @@ from __future__ import unicode_literals import contextlib -import distutils.sysconfig import os import pipes import shutil @@ -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())) @@ -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 @@ -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 diff --git a/setuptools_golang_test.py b/setuptools_golang_test.py index 2cdb7b5..5e8dbe2 100644 --- a/setuptools_golang_test.py +++ b/setuptools_golang_test.py @@ -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__)) @@ -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 diff --git a/tox.ini b/tox.ini index 2f00e4e..1d3428e 100644 --- a/tox.ini +++ b/tox.ini @@ -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 @@ -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 =