diff --git a/pytest.ini b/pytest.ini index c3b723fe29c8..ac65e77b201a 100644 --- a/pytest.ini +++ b/pytest.ini @@ -13,7 +13,6 @@ pep8ignore = tools/boilerplate.py E501 setup.py E402 setupext.py E301 E302 E501 - setup_external_compile.py E302 E711 versioneer.py ALL # External file. tools/gh_api.py ALL # External file. diff --git a/setup_external_compile.py b/setup_external_compile.py deleted file mode 100644 index c7a59515c9f0..000000000000 --- a/setup_external_compile.py +++ /dev/null @@ -1,71 +0,0 @@ -# This file is copied from https://github.com/jbmohler/matplotlib-winbuild -# Only the needed functions were kept. -""" -This file extracts and builds library dependencies libpng, zlib, & freetype2 on -MS Windows. It also extract tcl/tk for the header files. - -There are four possible build targets -- one for each permutation of VS 2008, -2010 and 32/64 bit. This builds the configuration that matches the Python -install that is executing. - -For Python 2.6, 2.7, 3.2: - -- VS 2008, 32 bit -- Windows SDK v7.0 -- VS 2008, 64 bit -- Windows SDK v7.0 - -For Python 3.3, 3.4: - -- VS 2010, 32 bit -- Windows SDK v7.1 -- VS 2010, 64 bit -- Windows SDK v7.1 -""" - -import sys -import platform -import os -import glob -import shutil -import zipfile -import tarfile -import distutils.msvc9compiler as msvc - -def fixproj(project_file, bit_target): - """ - :param bit_target: one of 'Win32' or 'x64' - """ - with open(project_file, 'r') as fd: - content = '\n'.join(line.strip() for line in fd if line.strip()) - content = content.replace('Win32', bit_target).replace('x64', bit_target) - with open(project_file, 'w') as fd: - fd.write(content) - -def tar_extract(tar_file, target): - with tarfile.open(tar_file, 'r:gz') as tgz: - tgz.extractall(target) - -def zip_extract(zip_file, target): - with zipfile.ZipFile(zip_file) as zf: - zf.extractall(target) - -# Configuration selection & declaration: -DEPSSRC = os.path.join(os.path.dirname(os.path.normpath(__file__)), - 'deps_source') -DEPSBUILD = os.path.join(os.path.dirname(os.path.normpath(__file__)), 'build') -X64 = platform.architecture()[0] == '64bit' -PYVER = sys.version_info[:2] -VS2010 = PYVER >= (3, 3) -# If not VS2010, then use VS2008 - -VCVARSALL = None - -def prepare_build_cmd(build_cmd, **kwargs): - global VCVARSALL - if VCVARSALL == None: - candidate = msvc.find_vcvarsall(10.0 if VS2010 else 9.0) - if candidate == None: - raise RuntimeError('Microsoft VS {} required' - .format('2010' if VS2010 else '2008')) - else: - VCVARSALL = candidate - - return build_cmd.format( - vcvarsall=VCVARSALL, xXX='x64' if X64 else 'x86', **kwargs) diff --git a/setupext.py b/setupext.py index e57f1d9b0333..82c8fb14d1ce 100644 --- a/setupext.py +++ b/setupext.py @@ -14,6 +14,7 @@ import shutil import subprocess import sys +import tarfile import textwrap import urllib.request import warnings @@ -1045,6 +1046,8 @@ def add_flags(self, ext): ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system')) def do_custom_build(self): + from pathlib import Path + # We're using a system freetype if not options.get('local_freetype'): return @@ -1058,7 +1061,7 @@ def do_custom_build(self): else: libfreetype = 'libfreetype.a' - if os.path.isfile(os.path.join(src_path, 'objs', '.libs', libfreetype)): + if Path(src_path, "objs", ".libs", libfreetype).is_file(): return tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION) @@ -1097,21 +1100,20 @@ def do_custom_build(self): tarball_url = url_fmt.format( version=LOCAL_FREETYPE_VERSION, tarball=tarball) - print("Downloading {0}".format(tarball_url)) + print("Downloading {}".format(tarball_url)) try: urllib.request.urlretrieve(tarball_url, tarball_path) - except IOError: # URLError (a subclass) on Py3. - print("Failed to download {0}".format(tarball_url)) + except IOError: + print("Failed to download {}".format(tarball_url)) else: if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH: print("Invalid hash.") else: break else: - raise IOError("Failed to download freetype. " - "You can download the file by " - "alternative means and copy it " - " to '{0}'".format(tarball_path)) + raise IOError("Failed to download freetype; you can " + "download the file by alternative means and " + "copy it to '{}'".format(tarball_path)) os.makedirs(tarball_cache_dir, exist_ok=True) try: shutil.copy(tarball_path, tarball_cache_path) @@ -1122,55 +1124,55 @@ def do_custom_build(self): if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH: raise IOError( - "{0} does not match expected hash.".format(tarball)) + "{} does not match expected hash".format(tarball)) + + print("Building {}".format(tarball)) + with tarfile.open(tarball_path, "r:gz") as tgz: + tgz.extractall("build") - print("Building {0}".format(tarball)) if sys.platform != 'win32': # compilation on all other platforms than windows - cflags = 'CFLAGS="{0} -fPIC" '.format(os.environ.get('CFLAGS', '')) - - subprocess.check_call( - ['tar', 'zxf', tarball], cwd='build') - subprocess.check_call( - [cflags + './configure --with-zlib=no --with-bzip2=no ' - '--with-png=no --with-harfbuzz=no'], shell=True, cwd=src_path) + env={**os.environ, + "CFLAGS": "{} -fPIC".format(os.environ.get("CFLAGS", ""))} subprocess.check_call( - [cflags + 'make'], shell=True, cwd=src_path) + ["./configure", "--with-zlib=no", "--with-bzip2=no", + "--with-png=no", "--with-harfbuzz=no"], + env=env, cwd=src_path) + subprocess.check_call(["make"], env=env, cwd=src_path) else: # compilation on windows - FREETYPE_BUILD_CMD = """\ -call "%ProgramFiles%\\Microsoft SDKs\\Windows\\v7.0\\Bin\\SetEnv.Cmd" /Release /{xXX} /xp + FREETYPE_BUILD_CMD = r""" +call "%ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" ^ + /Release /{xXX} /xp call "{vcvarsall}" {xXX} -set MSBUILD=C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe -rd /S /Q %FREETYPE%\\objs -%MSBUILD% %FREETYPE%\\builds\\windows\\{vc20xx}\\freetype.sln /t:Clean;Build /p:Configuration="{config}";Platform={WinXX} -echo Build completed, moving result" -:: move to the "normal" path for the unix builds... -mkdir %FREETYPE%\\objs\\.libs -:: REMINDER: fix when changing the version -copy %FREETYPE%\\objs\\{vc20xx}\\{xXX}\\freetype261.lib %FREETYPE%\\objs\\.libs\\libfreetype.lib -if errorlevel 1 ( - rem This is a py27 version, which has a different location for the lib file :-/ - copy %FREETYPE%\\objs\\win32\\{vc20xx}\\freetype261.lib %FREETYPE%\\objs\\.libs\\libfreetype.lib -) +set MSBUILD=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe +%MSBUILD% "builds\windows\{vc20xx}\freetype.sln" ^ + /t:Clean;Build /p:Configuration="{config}";Platform={WinXX} """ - from setup_external_compile import fixproj, prepare_build_cmd, VS2010, X64, tar_extract - # Note: freetype has no build profile for 2014, so we don't bother... - vc = 'vc2010' if VS2010 else 'vc2008' - WinXX = 'x64' if X64 else 'Win32' - tar_extract(tarball_path, "build") - # This is only false for py2.7, even on py3.5... - if not VS2010: - fixproj(os.path.join(src_path, 'builds', 'windows', vc, 'freetype.sln'), WinXX) - fixproj(os.path.join(src_path, 'builds', 'windows', vc, 'freetype.vcproj'), WinXX) - - cmdfile = os.path.join("build", 'build_freetype.cmd') - with open(cmdfile, 'w') as cmd: - cmd.write(prepare_build_cmd(FREETYPE_BUILD_CMD, vc20xx=vc, WinXX=WinXX, - config='Release' if VS2010 else 'LIB Release')) - - os.environ['FREETYPE'] = src_path - subprocess.check_call([cmdfile], shell=True) + import distutils.msvc9compiler as msvc + # FreeType 2.6.1 has no build profile for 2014. + vcvarsall = msvc.find_vcvarsall(10.0) + if vcvarsall is None: + raise RuntimeError("Microsoft VS 2010 required") + X64 = sys.maxsize > 2 ** 32 + vc20xx = "vc2010" + WinXX="x64" if X64 else "Win32" + xXX="x64" if X64 else "x86" + cmd_file = Path("build", "build_freetype.cmd") + cmd_file.write_text(FREETYPE_BUILD_CMD.format( + vcvarsall=msvc.find_vcvarsall(10.0), + vc20xx=vc20xx, WinXX=WinXX, xXX=xXX, config="Release")) + shutil.rmtree(str(Path(src_path, "objs")), ignore_errors=True) + subprocess.check_call(cmdfile, shell=True, cwd=src_path) + # Move to the corresponding Unix build path. + Path(src_path, "objs/.libs").mkdir() + # Be robust against change of FreeType version. + lib_path, = (Path(src_path, "objs", vc20xx, xXX).glob() + .glob("freetype*.lib")) + shutil.copy2( + str(lib_path), + str(Path(src_path, "objs", ".libs", "libfreetype.lib")) + ) class FT2Font(SetupPackage): pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy