Skip to content

Commit

Permalink
Merge pull request #1632 from minrk/undistutils
Browse files Browse the repository at this point in the history
Remove use of distutils
  • Loading branch information
minrk authored Nov 5, 2021
2 parents 4b8f43c + df94062 commit 18268f8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 107 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ jobs:
sudo apt-get -y remove libzmq5 || true # workaround https://github.com/actions/virtual-environments/issues/3317
sudo apt-get -y install libzmq3-dev libsodium-dev
- name: set $ZMQ_PREFIX
if: matrix.zmq
run: |
echo "ZMQ_PREFIX=${{ matrix.zmq }}" >> "$GITHUB_ENV"
- name: install libzmq-dev
if: matrix.zmq == 'head'
run: |
Expand All @@ -154,7 +159,7 @@ jobs:
- name: build pyzmq
run: |
pip install -v -e . --global-option=--zmq=${{ matrix.zmq }}
pip install -v -e .
- name: import zmq
run: |
Expand Down
22 changes: 8 additions & 14 deletions buildutils/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
# the file COPYING.BSD, distributed as part of this software.
# -----------------------------------------------------------------------------

import copy
import shutil
import sys
import os
import logging
import platform
from distutils import ccompiler
from distutils.sysconfig import customize_compiler

from .misc import get_compiler, get_output_error
from .msg import info
Expand All @@ -30,9 +29,8 @@
# -----------------------------------------------------------------------------


def test_compilation(cfile, compiler=None, **compiler_attrs):
def test_compilation(cfile, compiler, **compiler_attrs):
"""Test simple compilation with given settings"""
cc = get_compiler(compiler, **compiler_attrs)

efile, ext = os.path.splitext(cfile)

Expand All @@ -58,12 +56,12 @@ def test_compilation(cfile, compiler=None, **compiler_attrs):
extra_link = compiler_attrs.get('extra_link_args', [])
lpreargs.extend(extra_link)

objs = cc.compile([cfile], extra_preargs=cpreargs, extra_postargs=extra)
cc.link_executable(objs, efile, extra_preargs=lpreargs)
objs = compiler.compile([cfile], extra_preargs=cpreargs, extra_postargs=extra)
compiler.link_executable(objs, efile, extra_preargs=lpreargs)
return efile


def compile_and_forget(basedir, src, compiler=None, **compiler_attrs):
def compile_and_forget(basedir, src, compiler, **compiler_attrs):
"""Make sure src compiles and links successfully.
The resulting binary is deleted without being run.
Expand All @@ -73,13 +71,12 @@ def compile_and_forget(basedir, src, compiler=None, **compiler_attrs):
cfile = pjoin(basedir, os.path.basename(src))
shutil.copy(src, cfile)
try:
cc = get_compiler(compiler, **compiler_attrs)
efile = test_compilation(cfile, compiler=cc, **compiler_attrs)
efile = test_compilation(cfile, compiler=compiler, **compiler_attrs)
finally:
shutil.rmtree(basedir)


def detect_zmq(basedir, compiler=None, **compiler_attrs):
def detect_zmq(basedir, compiler, **compiler_attrs):
"""Compile, link & execute a test program, in empty directory `basedir`.
The C compiler will be updated with any keywords given via setattr.
Expand Down Expand Up @@ -111,14 +108,11 @@ def detect_zmq(basedir, compiler=None, **compiler_attrs):

# check if we need to link against Realtime Extensions library
if sys.platform.startswith('linux'):
cc = ccompiler.new_compiler(compiler=compiler)
customize_compiler(cc)
cc.output_dir = basedir
info("Checking for timer_create")
info(
"** Errors about missing timer_create are a normal part of this process **"
)
if not cc.has_function('timer_create'):
if not compiler.has_function('timer_create'):
compiler_attrs['libraries'].append('rt')
info(
"** The above error about timer_create is normal and not a problem! **"
Expand Down
22 changes: 5 additions & 17 deletions buildutils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
# Copyright (c) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.

import copy
import os
import sys
import logging
from distutils import ccompiler
from distutils.sysconfig import customize_compiler
from pipes import quote
from pprint import pprint
from subprocess import Popen, PIPE
Expand Down Expand Up @@ -36,13 +35,7 @@ def customize_mingw(cc):

def get_compiler(compiler, **compiler_attrs):
"""get and customize a compiler"""
if compiler is None or isinstance(compiler, str):
cc = ccompiler.new_compiler(compiler=compiler)
customize_compiler(cc)
if cc.compiler_type == 'mingw32':
customize_mingw(cc)
else:
cc = compiler
cc = copy.deepcopy(compiler)

for name, val in compiler_attrs.items():
setattr(cc, name, val)
Expand All @@ -67,24 +60,19 @@ def get_output_error(cmd, **kwargs):
return result.returncode, so, se


def locate_vcredist_dir():
def locate_vcredist_dir(plat):
"""Locate vcredist directory and add it to $PATH
Adding it to $PATH is required to run
executables that link libzmq to find e.g. msvcp140.dll
"""
from setuptools import msvc

try:
from setuptools._distutils.util import get_platform
except ImportError:
from distutils.util import get_platform

vcvars = msvc.msvc14_get_vc_env(get_platform())
vcvars = msvc.msvc14_get_vc_env(plat)
try:
vcruntime = vcvars["py_vcruntime_redist"]
except KeyError:
warn(f"platform={get_platform()}, vcvars=")
warn(f"platform={plat}, vcvars=")
pprint(vcvars, stream=sys.stderr)

warn(
Expand Down
Loading

0 comments on commit 18268f8

Please sign in to comment.