Created
February 3, 2026 15:30
-
-
Save Markus92/04a5040dd25f9f5b236f70145e0a0b4c to your computer and use it in GitHub Desktop.
Spack package for python2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright 2013-2022 Lawrence Livermore National Security, LLC and other | |
| # Spack Project Developers. See the top-level COPYRIGHT file for details. | |
| # | |
| # SPDX-License-Identifier: (Apache-2.0 OR MIT) | |
| import glob | |
| import json | |
| import os | |
| import platform | |
| import re | |
| import subprocess | |
| import sys | |
| from shutil import copy | |
| from typing import Dict, List | |
| from spack.build_environment import dso_suffix, stat_suffix | |
| from spack_repo.builtin.build_systems.generic import Package | |
| from spack.package import * | |
| from spack.util.environment import is_system_path | |
| from spack.util.prefix import Prefix | |
| is_windows = sys.platform == "win32" | |
| class Python2(Package): | |
| """The Python programming language.""" | |
| homepage = "https://www.python.org/" | |
| url = "https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz" | |
| list_url = "https://www.python.org/ftp/python/" | |
| list_depth = 1 | |
| maintainers = ["Markus92"] | |
| phases = ["configure", "build", "install"] | |
| depends_on("c", type="build") | |
| depends_on("cxx", type="build") | |
| #: phase | |
| install_targets = ["install"] | |
| build_targets = [] # type: List[str] | |
| version( | |
| "2.7.18", | |
| sha256="da3080e3b488f648a3d7a4560ddee895284c3380b11d6de75edb986526b9a814", | |
| deprecated=False, # Technically it is deprecated, but not for our purposes | |
| ) | |
| extendable = True | |
| # Variants to avoid cyclical dependencies for concretizer | |
| variant("libxml2", default=True, description="Use a gettext library build with libxml2") | |
| variant( | |
| "debug", default=False, description="debug build with extra checks (this is high overhead)" | |
| ) | |
| # --enable-shared is known to cause problems for some users on macOS | |
| # This is a problem for Python 2.7 only, not Python3 | |
| # See http://bugs.python.org/issue29846 | |
| variant("shared", default=True, description="Enable shared libraries") | |
| # From https://docs.python.org/2/c-api/unicode.html: Python's default | |
| # builds use a 16-bit type for Py_UNICODE and store Unicode values | |
| # internally as UCS2. It is also possible to build a UCS4 version of Python | |
| # (most recent Linux distributions come with UCS4 builds of Python). These | |
| # builds then use a 32-bit type for Py_UNICODE and store Unicode data | |
| # internally as UCS4. Note that UCS2 and UCS4 Python builds are not binary | |
| # compatible. | |
| # Needs to be True for RHEL 7 compatibility | |
| variant("ucs4", default=True, description="Enable UCS4 (wide) unicode strings") | |
| variant("pic", default=True, description="Produce position-independent code (for shared libs)") | |
| variant( | |
| "optimizations", | |
| default=False, | |
| description="Enable expensive build-time optimizations, if available", | |
| ) | |
| # Optional Python modules | |
| variant("readline", default=not is_windows, description="Build readline module") | |
| variant("ssl", default=True, description="Build ssl module") | |
| variant("sqlite3", default=True, description="Build sqlite3 module") | |
| variant("dbm", default=True, description="Build dbm module") | |
| variant("nis", default=False, description="Build nis module") | |
| variant("zlib", default=True, description="Build zlib module") | |
| variant("bz2", default=True, description="Build bz2 module") | |
| variant("lzma", default=True, description="Build lzma module", when="@3.3:") | |
| variant("pyexpat", default=True, description="Build pyexpat module") | |
| variant("ctypes", default=True, description="Build ctypes module") | |
| variant("tkinter", default=False, description="Build tkinter module") | |
| variant("uuid", default=True, description="Build uuid module") | |
| variant("tix", default=False, description="Build Tix module") | |
| if not is_windows: | |
| depends_on("gmake", type="build") | |
| depends_on("pkgconfig@0.9.0:", type="build") | |
| depends_on("gettext +libxml2", when="+libxml2") | |
| depends_on("gettext ~libxml2", when="~libxml2") | |
| # Optional dependencies | |
| # See detect_modules() in setup.py for details | |
| depends_on("readline", when="+readline") | |
| depends_on("ncurses", when="+readline") | |
| depends_on("openssl", when="+ssl") | |
| # https://raw.githubusercontent.com/python/cpython/84471935ed2f62b8c5758fd544c7d37076fe0fa5/Misc/NEWS | |
| # https://docs.python.org/3.5/whatsnew/changelog.html#python-3-5-4rc1 | |
| depends_on("openssl@:1.0.2z", when="@:2.7.13,3.0.0:3.5.2+ssl") | |
| depends_on( | |
| "openssl@1.0.2:", when="@3.7:+ssl" | |
| ) # https://docs.python.org/3/whatsnew/3.7.html#build-changes | |
| depends_on("gdbm", when="+dbm") # alternatively ndbm or berkeley-db | |
| depends_on("libnsl", when="+nis") | |
| depends_on("zlib@1.1.3:", when="+zlib") | |
| depends_on("bzip2", when="+bz2") | |
| depends_on("xz", when="@3.3:+lzma") | |
| depends_on("expat", when="+pyexpat") | |
| depends_on("libffi", when="+ctypes") | |
| depends_on("tk", when="+tkinter") | |
| depends_on("tcl", when="+tkinter") | |
| depends_on("uuid", when="+uuid") | |
| depends_on("tix", when="+tix") | |
| # Python needs to be patched to build extensions w/ mixed C/C++ code: | |
| # https://github.com/NixOS/nixpkgs/pull/19585/files | |
| # https://bugs.python.org/issue1222585 | |
| # | |
| # NOTE: This patch puts Spack's default Python installation out of | |
| # sync with standard Python installs. If you're using such an | |
| # installation as an external and encountering build issues with mixed | |
| # C/C++ modules, consider installing a Spack-managed Python with | |
| # this patch instead. For more information, see: | |
| # https://github.com/spack/spack/pull/16856 | |
| patch("python-2.7.17+-distutils-C++.patch", when="@2.7.17:2.7.18") | |
| patch("python-2.7.17+-distutils-C++-fixup.patch", when="@2.7.17:2.7.18") | |
| # Not included, but could be useful for slightly older Python 2.7 versions | |
| # patch("python-2.7.8-distutils-C++.patch", when="@2.7.8:2.7.16") | |
| # Ensure that distutils chooses correct compiler option for RPATH on cray: | |
| patch("cray-rpath-2.3.patch", when="@2.3:3.0.1 platform=cray") | |
| # Ensure that distutils chooses correct compiler option for RPATH on fj: | |
| patch("fj-rpath-2.3.patch", when="@2.3:3.0.1 %fj") | |
| # CPython tries to build an Objective-C file with GCC's C frontend | |
| # https://github.com/spack/spack/pull/16222 | |
| # https://github.com/python/cpython/pull/13306 | |
| conflicts( | |
| "%gcc platform=darwin", | |
| msg="CPython does not compile with GCC on macOS yet, use clang. " | |
| "See: https://github.com/python/cpython/pull/13306", | |
| ) | |
| # For more information refer to this bug report: | |
| # https://bugs.python.org/issue29712 | |
| conflicts( | |
| "@:2.8 +shared", | |
| when="+optimizations", | |
| msg="+optimizations is incompatible with +shared in python@2.X", | |
| ) | |
| conflicts("+tix", when="~tkinter", msg="python+tix requires python+tix+tkinter") | |
| conflicts("%nvhpc") | |
| conflicts( | |
| "@:2.7", | |
| when="platform=darwin target=aarch64:", | |
| msg="Python 2.7 is too old for Apple Silicon", | |
| ) | |
| # Used to cache various attributes that are expensive to compute | |
| _config_vars = {} # type: Dict[str, Dict[str, str]] | |
| # An in-source build with --enable-optimizations fails for python@3.X | |
| build_directory = "spack-build" | |
| executables = [r"^python[\d.]*[mw]?$"] | |
| @classmethod | |
| def determine_version(cls, exe): | |
| # Newer versions of Python support `--version`, | |
| # but older versions only support `-V` | |
| # Python 2 sends to STDERR, while Python 3 sends to STDOUT | |
| # Output looks like: | |
| # Python 3.7.7 | |
| # On pre-production Ubuntu, this is also possible: | |
| # Python 3.10.2+ | |
| output = Executable(exe)("-V", output=str, error=str) | |
| match = re.search(r"Python\s+([A-Za-z0-9_.-]+)", output) | |
| return match.group(1) if match else None | |
| @classmethod | |
| def determine_variants(cls, exes, version_str): | |
| python = Executable(exes[0]) | |
| variants = "" | |
| for exe in exes: | |
| if os.path.basename(exe) == "python": | |
| variants += "+pythoncmd" | |
| break | |
| else: | |
| variants += "~pythoncmd" | |
| for module in ["readline", "sqlite3", "dbm", "nis", "zlib", "bz2", "ctypes", "uuid"]: | |
| try: | |
| python("-c", "import " + module, error=os.devnull) | |
| variants += "+" + module | |
| except ProcessError: | |
| variants += "~" + module | |
| # Some variants enable multiple modules | |
| try: | |
| python("-c", "import ssl", error=os.devnull) | |
| python("-c", "import hashlib", error=os.devnull) | |
| variants += "+ssl" | |
| except ProcessError: | |
| variants += "~ssl" | |
| try: | |
| python("-c", "import xml.parsers.expat", error=os.devnull) | |
| python("-c", "import xml.etree.ElementTree", error=os.devnull) | |
| variants += "+pyexpat" | |
| except ProcessError: | |
| variants += "~pyexpat" | |
| # Some modules are version-dependent | |
| if Version(version_str) >= Version("3"): | |
| try: | |
| python("-c", "import tkinter", error=os.devnull) | |
| variants += "+tkinter" | |
| except ProcessError: | |
| variants += "~tkinter" | |
| try: | |
| python("-c", "import tkinter.tix", error=os.devnull) | |
| variants += "+tix" | |
| except ProcessError: | |
| variants += "~tix" | |
| else: | |
| try: | |
| python("-c", "import Tkinter", error=os.devnull) | |
| variants += "+tkinter" | |
| except ProcessError: | |
| variants += "~tkinter" | |
| try: | |
| python("-c", "import Tix", error=os.devnull) | |
| variants += "+tix" | |
| except ProcessError: | |
| variants += "~tix" | |
| return variants | |
| def url_for_version(self, version): | |
| url = "https://www.python.org/ftp/python/{0}/Python-{1}.tgz" | |
| return url.format(re.split("[a-z]", str(version))[0], version) | |
| # TODO: Ideally, these patches would be applied as separate '@run_before' | |
| # functions enabled via '@when', but these two decorators don't work | |
| # when used together. See: https://github.com/spack/spack/issues/12736 | |
| def patch(self): | |
| # NOTE: Python's default installation procedure makes it possible for a | |
| # user's local configurations to change the Spack installation. In | |
| # order to prevent this behavior for a full installation, we must | |
| # modify the installation script so that it ignores user files. | |
| if self.spec.satisfies("@2.7:2.8,3.4:"): | |
| ff = FileFilter("Makefile.pre.in") | |
| ff.filter( | |
| r"^(.*)setup\.py(.*)((build)|(install))(.*)$", r"\1setup.py\2 --no-user-cfg \3\6" | |
| ) | |
| # NOTE: Older versions of Python do not support the '--with-openssl' | |
| # configuration option, so the installation's module setup file needs | |
| # to be modified directly in order to point to the correct SSL path. | |
| # See: https://stackoverflow.com/a/5939170 | |
| if self.spec.satisfies("@:3.6+ssl"): | |
| ff = FileFilter(join_path("Modules", "Setup.dist")) | |
| ff.filter(r"^#(((SSL=)|(_ssl))(.*))$", r"\1") | |
| ff.filter(r"^#((.*)(\$\(SSL\))(.*))$", r"\1") | |
| ff.filter(r"^SSL=(.*)$", r"SSL={0}".format(self.spec["openssl"].prefix)) | |
| # Because Python uses compiler system paths during install, it's | |
| # possible to pick up a system OpenSSL when building 'python~ssl'. | |
| # To avoid this scenario, we disable the 'ssl' module with patching. | |
| elif self.spec.satisfies("@:3.6~ssl"): | |
| ff = FileFilter("setup.py") | |
| ff.filter(r"^(\s+(ssl_((incs)|(libs)))\s+=\s+)(.*)$", r"\1 None and \6") | |
| ff.filter(r"^(\s+(opensslv_h)\s+=\s+)(.*)$", r"\1 None and \3") | |
| def setup_build_environment(self, env): | |
| spec = self.spec | |
| # TODO: The '--no-user-cfg' option for Python installation is only in | |
| # Python v2.7 and v3.4+ (see https://bugs.python.org/issue1180) and | |
| # adding support for ignoring user configuration will require | |
| # significant changes to this package for other Python versions. | |
| if not spec.satisfies("@2.7:2.8,3.4:"): | |
| tty.warn( | |
| ( | |
| "Python v{0} may not install properly if Python " | |
| "user configurations are present." | |
| ).format(self.version) | |
| ) | |
| # TODO: Python has incomplete support for Python modules with mixed | |
| # C/C++ source, and patches are required to enable building for these | |
| # modules. All Python versions without a viable patch are installed | |
| # with a warning message about this potentially erroneous behavior. | |
| if not spec.satisfies("@2.7.8:2.7.18,3.6.8,3.7.2:"): | |
| tty.warn( | |
| ( | |
| 'Python v{0} does not have the C++ "distutils" patch; ' | |
| "errors may occur when installing Python modules w/ " | |
| "mixed C/C++ source files." | |
| ).format(self.version) | |
| ) | |
| env.unset("PYTHONPATH") | |
| env.unset("PYTHONHOME") | |
| # avoid build error on fugaku | |
| if spec.satisfies("@3.10.0 arch=linux-rhel8-a64fx"): | |
| if spec.satisfies("%gcc") or spec.satisfies("%fj"): | |
| env.unset("LC_ALL") | |
| def flag_handler(self, name, flags): | |
| # python 3.8 requires -fwrapv when compiled with intel | |
| if self.spec.satisfies("@3.8: %intel"): | |
| if name == "cflags": | |
| flags.append("-fwrapv") | |
| # Fix for following issues for python with aocc%3.2.0: | |
| # https://github.com/spack/spack/issues/29115 | |
| # https://github.com/spack/spack/pull/28708 | |
| if self.spec.satisfies("%aocc@3.2.0"): | |
| if name == "cflags": | |
| flags.extend(["-mllvm", "-disable-indvar-simplify=true"]) | |
| # allow flags to be passed through compiler wrapper | |
| return (flags, None, None) | |
| @property | |
| def plat_arch(self): | |
| """ | |
| String referencing platform architecture | |
| filtered through Python's Windows build file | |
| architecture support map | |
| Note: This function really only makes | |
| sense to use on Windows, could be overridden to | |
| cross compile however. | |
| """ | |
| arch_map = {"AMD64": "x64", "x86": "Win32", "IA64": "Win32", "EM64T": "Win32"} | |
| arch = platform.machine() | |
| if arch in arch_map: | |
| arch = arch_map[arch] | |
| return arch | |
| @property | |
| def win_build_params(self): | |
| """ | |
| Arguments must be passed to the Python build batch script | |
| in order to configure it to spec and system. | |
| A number of these toggle optional MSBuild Projects | |
| directly corresponding to the python support of the same | |
| name. | |
| """ | |
| args = [] | |
| args.append("-p %s" % self.plat_arch) | |
| if self.spec.satisfies("+debug"): | |
| args.append("-d") | |
| if self.spec.satisfies("~ctypes"): | |
| args.append("--no-ctypes") | |
| if self.spec.satisfies("~ssl"): | |
| args.append("--no-ssl") | |
| if self.spec.satisfies("~tkinter"): | |
| args.append("--no-tkinter") | |
| return args | |
| def win_installer(self, prefix): | |
| """ | |
| Python on Windows does not export an install target | |
| so we must handcraft one here. This structure | |
| directly mimics the install tree of the Python | |
| Installer on Windows. | |
| Parameters: | |
| prefix (str): Install prefix for package | |
| """ | |
| proj_root = self.stage.source_path | |
| pcbuild_root = os.path.join(proj_root, "PCbuild") | |
| build_root = os.path.join(pcbuild_root, platform.machine().lower()) | |
| include_dir = os.path.join(proj_root, "Include") | |
| copy_tree(include_dir, prefix.include) | |
| doc_dir = os.path.join(proj_root, "Doc") | |
| copy_tree(doc_dir, prefix.Doc) | |
| tools_dir = os.path.join(proj_root, "Tools") | |
| copy_tree(tools_dir, prefix.Tools) | |
| lib_dir = os.path.join(proj_root, "Lib") | |
| copy_tree(lib_dir, prefix.Lib) | |
| pyconfig = os.path.join(proj_root, "PC", "pyconfig.h") | |
| copy(pyconfig, prefix.include) | |
| shared_libraries = [] | |
| shared_libraries.extend(glob.glob("%s\\*.exe" % build_root)) | |
| shared_libraries.extend(glob.glob("%s\\*.dll" % build_root)) | |
| shared_libraries.extend(glob.glob("%s\\*.pyd" % build_root)) | |
| os.makedirs(prefix.DLLs) | |
| for lib in shared_libraries: | |
| file_name = os.path.basename(lib) | |
| if ( | |
| file_name.endswith(".exe") | |
| or (file_name.endswith(".dll") and "python" in file_name) | |
| or "vcruntime" in file_name | |
| ): | |
| copy(lib, prefix) | |
| else: | |
| copy(lib, prefix.DLLs) | |
| static_libraries = glob.glob("%s\\*.lib") | |
| for lib in static_libraries: | |
| copy(lib, prefix.libs) | |
| def configure_args(self): | |
| spec = self.spec | |
| config_args = [] | |
| cflags = [] | |
| # setup.py needs to be able to read the CPPFLAGS and LDFLAGS | |
| # as it scans for the library and headers to build | |
| link_deps = spec.dependencies(deptype="link") | |
| if link_deps: | |
| # Header files are often included assuming they reside in a | |
| # subdirectory of prefix.include, e.g. #include <openssl/ssl.h>, | |
| # which is why we don't use HeaderList here. The header files of | |
| # libffi reside in prefix.lib but the configure script of Python | |
| # finds them using pkg-config. | |
| cppflags = " ".join("-I" + spec[dep.name].prefix.include for dep in link_deps) | |
| # Currently, the only way to get SpecBuildInterface wrappers of the | |
| # dependencies (which we need to get their 'libs') is to get them | |
| # using spec.__getitem__. | |
| ldflags = " ".join(spec[dep.name].libs.search_flags for dep in link_deps) | |
| config_args.extend(["CPPFLAGS=" + cppflags, "LDFLAGS=" + ldflags]) | |
| # https://docs.python.org/3/whatsnew/3.7.html#build-changes | |
| if spec.satisfies("@:3.6"): | |
| config_args.append("--with-threads") | |
| if spec.satisfies("@2.7.13:2.8,3.5.3:") and "+optimizations" in spec: | |
| config_args.append("--enable-optimizations") | |
| config_args.append("--with-lto") | |
| config_args.append("--with-computed-gotos") | |
| if spec.satisfies("%gcc platform=darwin"): | |
| config_args.append("--disable-toolbox-glue") | |
| if spec.satisfies("%intel") and spec.satisfies( | |
| "@2.7.12:2.8,3.5.2:3.7"): | |
| config_args.append("--with-icc={0}".format(spack_cc)) | |
| if "+debug" in spec: | |
| config_args.append("--with-pydebug") | |
| else: | |
| config_args.append("--without-pydebug") | |
| if "+shared" in spec: | |
| config_args.append("--enable-shared") | |
| else: | |
| config_args.append("--disable-shared") | |
| if "+ucs4" in spec: | |
| if spec.satisfies("@:2.7"): | |
| config_args.append("--enable-unicode=ucs4") | |
| elif spec.satisfies("@3.0:3.2"): | |
| config_args.append("--with-wide-unicode") | |
| elif spec.satisfies("@3.3:"): | |
| # https://docs.python.org/3.3/whatsnew/3.3.html#functionality | |
| raise ValueError("+ucs4 variant not compatible with Python 3.3 and beyond") | |
| if spec.satisfies("@2.7.9:2,3.4:"): | |
| config_args.append("--without-ensurepip") | |
| if "+pic" in spec: | |
| cflags.append(self["c"].pic_flag) | |
| if "+ssl" in spec: | |
| if spec.satisfies("@3.7:"): | |
| config_args.append("--with-openssl={0}".format(spec["openssl"].prefix)) | |
| if "+dbm" in spec: | |
| # Default order is ndbm:gdbm:bdb | |
| config_args.append("--with-dbmliborder=gdbm") | |
| else: | |
| config_args.append("--with-dbmliborder=") | |
| if "+pyexpat" in spec: | |
| config_args.append("--with-system-expat") | |
| else: | |
| config_args.append("--without-system-expat") | |
| if "+ctypes" in spec: | |
| config_args.append("--with-system-ffi") | |
| else: | |
| config_args.append("--without-system-ffi") | |
| if "+tkinter" in spec: | |
| config_args.extend( | |
| [ | |
| "--with-tcltk-includes=-I{0} -I{1}".format( | |
| spec["tcl"].prefix.include, spec["tk"].prefix.include | |
| ), | |
| "--with-tcltk-libs={0} {1}".format( | |
| spec["tcl"].libs.ld_flags, spec["tk"].libs.ld_flags | |
| ), | |
| ] | |
| ) | |
| # https://docs.python.org/3.8/library/sqlite3.html#f1 | |
| if spec.satisfies("@3.2: +sqlite3 ^sqlite+dynamic_extensions"): | |
| config_args.append("--enable-loadable-sqlite-extensions") | |
| if spec.satisfies("%oneapi"): | |
| cflags.append("-fp-model=strict") | |
| if cflags: | |
| config_args.append("CFLAGS={0}".format(" ".join(cflags))) | |
| return config_args | |
| def configure(self, spec, prefix): | |
| """Runs configure with the arguments specified in | |
| :meth:`~spack.build_systems.autotools.AutotoolsPackage.configure_args` | |
| and an appropriately set prefix. | |
| """ | |
| with working_dir(self.stage.source_path, create=True): | |
| if is_windows: | |
| pass | |
| else: | |
| options = getattr(self, "configure_flag_args", []) | |
| options += ["--prefix={0}".format(prefix)] | |
| options += self.configure_args() | |
| configure(*options) | |
| def build(self, spec, prefix): | |
| """Makes the build targets specified by | |
| :py:attr:``~.AutotoolsPackage.build_targets`` | |
| """ | |
| # Windows builds use a batch script to drive | |
| # configure and build in one step | |
| with working_dir(self.stage.source_path): | |
| if is_windows: | |
| pcbuild_root = os.path.join(self.stage.source_path, "PCbuild") | |
| builder_cmd = os.path.join(pcbuild_root, "build.bat") | |
| try: | |
| subprocess.check_output( # novermin | |
| " ".join([builder_cmd] + self.win_build_params), stderr=subprocess.STDOUT | |
| ) | |
| except subprocess.CalledProcessError as e: | |
| raise ProcessError( | |
| "Process exited with status %d" % e.returncode, | |
| long_message=e.output.decode("utf-8"), | |
| ) | |
| else: | |
| # See https://autotools.io/automake/silent.html | |
| params = ["V=1"] | |
| params += self.build_targets | |
| make(*params) | |
| def install(self, spec, prefix): | |
| """Makes the install targets specified by | |
| :py:attr:``~.AutotoolsPackage.install_targets`` | |
| """ | |
| with working_dir(self.stage.source_path): | |
| if is_windows: | |
| self.win_installer(prefix) | |
| else: | |
| make(*self.install_targets) | |
| @run_after("install") | |
| def filter_compilers(self): | |
| """Run after install to tell the configuration files and Makefiles | |
| to use the compilers that Spack built the package with. | |
| If this isn't done, they'll have CC and CXX set to Spack's generic | |
| cc and c++. We want them to be bound to whatever compiler | |
| they were built with.""" | |
| if is_windows: | |
| return | |
| kwargs = {"ignore_absent": True, "backup": False, "string": True} | |
| filenames = [self.get_sysconfigdata_name(), self.config_vars["makefile_filename"]] | |
| filter_file(spack_cc, self["c"].cc, *filenames, **kwargs) | |
| if spack_cxx: | |
| filter_file(spack_cxx, self["cxx"].cxx, *filenames, **kwargs) | |
| @run_after("install") | |
| def symlink(self): | |
| if is_windows: | |
| return | |
| spec = self.spec | |
| prefix = self.prefix | |
| # TODO: | |
| # On OpenSuse 13, python uses <prefix>/lib64/python2.7/lib-dynload/*.so | |
| # instead of <prefix>/lib/python2.7/lib-dynload/*.so. Oddly enough the | |
| # result is that Python can not find modules like cPickle. A workaround | |
| # for now is to symlink to `lib`: | |
| src = os.path.join(prefix.lib64, "python{0}".format(self.version.up_to(2)), "lib-dynload") | |
| dst = os.path.join(prefix.lib, "python{0}".format(self.version.up_to(2)), "lib-dynload") | |
| if os.path.isdir(src) and not os.path.isdir(dst): | |
| mkdirp(dst) | |
| for f in os.listdir(src): | |
| os.symlink(os.path.join(src, f), os.path.join(dst, f)) | |
| @run_after("install") | |
| def install_python_gdb(self): | |
| # https://devguide.python.org/gdb/ | |
| src = os.path.join("Tools", "gdb", "libpython.py") | |
| if os.path.exists(src): | |
| install(src, self.command.path + "-gdb.py") | |
| @run_after("install") | |
| @on_package_attributes(run_tests=True) | |
| def import_tests(self): | |
| """Test that basic Python functionality works.""" | |
| spec = self.spec | |
| with working_dir("spack-test", create=True): | |
| # Ensure that readline module works | |
| if "+readline" in spec: | |
| self.command("-c", "import readline") | |
| # Ensure that ssl module works | |
| if "+ssl" in spec: | |
| self.command("-c", "import ssl") | |
| self.command("-c", "import hashlib") | |
| # Ensure that sqlite3 module works | |
| if "+sqlite3" in spec: | |
| self.command("-c", "import sqlite3") | |
| # Ensure that dbm module works | |
| if "+dbm" in spec: | |
| self.command("-c", "import dbm") | |
| # Ensure that nis module works | |
| if "+nis" in spec: | |
| self.command("-c", "import nis") | |
| # Ensure that zlib module works | |
| if "+zlib" in spec: | |
| self.command("-c", "import zlib") | |
| # Ensure that bz2 module works | |
| if "+bz2" in spec: | |
| self.command("-c", "import bz2") | |
| # Ensure that lzma module works | |
| if spec.satisfies("@3.3:"): | |
| if "+lzma" in spec: | |
| self.command("-c", "import lzma") | |
| # Ensure that pyexpat module works | |
| if "+pyexpat" in spec: | |
| self.command("-c", "import xml.parsers.expat") | |
| self.command("-c", "import xml.etree.ElementTree") | |
| # Ensure that ctypes module works | |
| if "+ctypes" in spec: | |
| self.command("-c", "import ctypes") | |
| # Ensure that tkinter module works | |
| # https://wiki.python.org/moin/TkInter | |
| if "+tkinter" in spec: | |
| # Only works if ForwardX11Trusted is enabled, i.e. `ssh -Y` | |
| if "DISPLAY" in env: | |
| if spec.satisfies("@3:"): | |
| self.command("-c", "import tkinter; tkinter._test()") | |
| else: | |
| self.command("-c", "import Tkinter; Tkinter._test()") | |
| else: | |
| if spec.satisfies("@3:"): | |
| self.command("-c", "import tkinter") | |
| else: | |
| self.command("-c", "import Tkinter") | |
| # Ensure that uuid module works | |
| if "+uuid" in spec: | |
| self.command("-c", "import uuid") | |
| # Ensure that tix module works | |
| if "+tix" in spec: | |
| if spec.satisfies("@3:"): | |
| self.command("-c", "import tkinter.tix") | |
| else: | |
| self.command("-c", "import Tix") | |
| # ======================================================================== | |
| # Set up environment to make install easy for python extensions. | |
| # ======================================================================== | |
| @property | |
| def command(self): | |
| """Returns the Python command, which may vary depending | |
| on the version of Python and how it was installed. | |
| In general, Python 2 comes with ``python`` and ``python2`` commands, | |
| while Python 3 only comes with a ``python3`` command. However, some | |
| package managers will symlink ``python`` to ``python3``, while others | |
| may contain ``python3.6``, ``python3.5``, and ``python3.4`` in the | |
| same directory. | |
| Returns: | |
| Executable: the Python command | |
| """ | |
| # We need to be careful here. If the user is using an externally | |
| # installed python, several different commands could be located | |
| # in the same directory. Be as specific as possible. Search for: | |
| # | |
| # * python3.6 | |
| # * python3 | |
| # * python | |
| # | |
| # in that order if using python@3.6.5, for example. | |
| version = self.spec.version | |
| for ver in [version.up_to(2), version.up_to(1), ""]: | |
| if not is_windows: | |
| path = os.path.join(self.prefix.bin, "python{0}".format(ver)) | |
| else: | |
| path = os.path.join(self.prefix, "python{0}.exe".format(ver)) | |
| if os.path.exists(path): | |
| return Executable(path) | |
| else: | |
| msg = "Unable to locate {0} command in {1}" | |
| raise RuntimeError(msg.format(self.name, self.prefix.bin)) | |
| def print_string(self, string): | |
| """Returns the appropriate print string depending on the | |
| version of Python. | |
| Examples: | |
| * Python 2 | |
| .. code-block:: python | |
| >>> self.print_string('sys.prefix') | |
| 'print sys.prefix' | |
| * Python 3 | |
| .. code-block:: python | |
| >>> self.print_string('sys.prefix') | |
| 'print(sys.prefix)' | |
| """ | |
| if self.spec.satisfies("@:2"): | |
| return "print {0}".format(string) | |
| else: | |
| return "print({0})".format(string) | |
| @property | |
| def config_vars(self): | |
| """Return a set of variable definitions associated with a Python installation. | |
| Wrapper around various ``sysconfig`` functions. To see these variables on the | |
| command line, run: | |
| .. code-block:: console | |
| $ python -m sysconfig | |
| Returns: | |
| dict: variable definitions | |
| """ | |
| cmd = """ | |
| import json | |
| from sysconfig import ( | |
| get_config_vars, | |
| get_config_h_filename, | |
| get_makefile_filename, | |
| get_paths, | |
| ) | |
| config = get_config_vars() | |
| config['config_h_filename'] = get_config_h_filename() | |
| config['makefile_filename'] = get_makefile_filename() | |
| config.update(get_paths()) | |
| %s | |
| """ % self.print_string( | |
| "json.dumps(config)" | |
| ) | |
| dag_hash = self.spec.dag_hash() | |
| lib_prefix = "lib" if not is_windows else "" | |
| if dag_hash not in self._config_vars: | |
| # Default config vars | |
| version = self.version.up_to(2) | |
| if is_windows: | |
| version = str(version).split(".")[0] | |
| config = { | |
| # get_config_vars | |
| "BINDIR": self.prefix.bin, | |
| "CC": "cc", | |
| "CONFINCLUDEPY": self.prefix.include.join("python{}").format(version), | |
| "CXX": "c++", | |
| "INCLUDEPY": self.prefix.include.join("python{}").format(version), | |
| "LIBDEST": self.prefix.lib.join("python{}").format(version), | |
| "LIBDIR": self.prefix.lib, | |
| "LIBPL": self.prefix.lib.join("python{0}") | |
| .join("config-{0}-{1}") | |
| .format(version, sys.platform), | |
| "LDLIBRARY": "{}python{}.{}".format(lib_prefix, version, dso_suffix), | |
| "LIBRARY": "{}python{}.{}".format(lib_prefix, version, stat_suffix), | |
| "LDSHARED": "cc", | |
| "LDCXXSHARED": "c++", | |
| "PYTHONFRAMEWORKPREFIX": "/System/Library/Frameworks", | |
| "base": self.prefix, | |
| "installed_base": self.prefix, | |
| "installed_platbase": self.prefix, | |
| "platbase": self.prefix, | |
| "prefix": self.prefix, | |
| # get_config_h_filename | |
| "config_h_filename": self.prefix.include.join("python{}") | |
| .join("pyconfig.h") | |
| .format(version), | |
| # get_makefile_filename | |
| "makefile_filename": self.prefix.lib.join("python{0}") | |
| .join("config-{0}-{1}") | |
| .Makefile.format(version, sys.platform), | |
| # get_paths | |
| "data": self.prefix, | |
| "include": self.prefix.include.join("python{}".format(version)), | |
| "platinclude": self.prefix.include64.join("python{}".format(version)), | |
| "platlib": self.prefix.lib64.join("python{}".format(version)).join( | |
| "site-packages" | |
| ), | |
| "platstdlib": self.prefix.lib64.join("python{}".format(version)), | |
| "purelib": self.prefix.lib.join("python{}".format(version)).join("site-packages"), | |
| "scripts": self.prefix.bin, | |
| "stdlib": self.prefix.lib.join("python{}".format(version)), | |
| } | |
| try: | |
| config.update(json.loads(self.command("-c", cmd, output=str))) | |
| except (ProcessError, RuntimeError): | |
| pass | |
| self._config_vars[dag_hash] = config | |
| return self._config_vars[dag_hash] | |
| def get_sysconfigdata_name(self): | |
| """Return the full path name of the sysconfigdata file.""" | |
| libdest = self.config_vars["LIBDEST"] | |
| filename = "_sysconfigdata.py" | |
| if self.spec.satisfies("@3.6:"): | |
| # Python 3.6.0 renamed the sys config file | |
| cmd = "from sysconfig import _get_sysconfigdata_name; " | |
| cmd += self.print_string("_get_sysconfigdata_name()") | |
| filename = self.command("-c", cmd, output=str).strip() | |
| filename += ".py" | |
| return join_path(libdest, filename) | |
| @property | |
| def home(self): | |
| """Most of the time, ``PYTHONHOME`` is simply | |
| ``spec['python'].prefix``. However, if the user is using an | |
| externally installed python, it may be symlinked. For example, | |
| Homebrew installs python in ``/usr/local/Cellar/python/2.7.12_2`` | |
| and symlinks it to ``/usr/local``. Users may not know the actual | |
| installation directory and add ``/usr/local`` to their | |
| ``packages.yaml`` unknowingly. Query the python executable to | |
| determine exactly where it is installed. | |
| """ | |
| return Prefix(self.config_vars["base"]) | |
| def find_library(self, library): | |
| # Spack installs libraries into lib, except on openSUSE where it installs them | |
| # into lib64. If the user is using an externally installed package, it may be | |
| # in either lib or lib64, so we need to ask Python where its LIBDIR is. | |
| libdir = self.config_vars["LIBDIR"] | |
| # In Ubuntu 16.04.6 and python 2.7.12 from the system, lib could be in LBPL | |
| # https://mail.python.org/pipermail/python-dev/2013-April/125733.html | |
| libpl = self.config_vars["LIBPL"] | |
| # The system Python installation on macOS and Homebrew installations | |
| # install libraries into a Frameworks directory | |
| frameworkprefix = self.config_vars["PYTHONFRAMEWORKPREFIX"] | |
| # Get the active Xcode environment's Framework location. | |
| macos_developerdir = os.environ.get("DEVELOPER_DIR") | |
| if macos_developerdir and os.path.exists(macos_developerdir): | |
| macos_developerdir = os.path.join(macos_developerdir, "Library", "Frameworks") | |
| else: | |
| macos_developerdir = "" | |
| # Windows libraries are installed directly to BINDIR | |
| win_bin_dir = self.config_vars["BINDIR"] | |
| win_root_dir = self.config_vars["prefix"] | |
| directories = [ | |
| libdir, | |
| libpl, | |
| frameworkprefix, | |
| macos_developerdir, | |
| win_bin_dir, | |
| win_root_dir, | |
| ] | |
| # The Python shipped with Xcode command line tools isn't in any of these locations | |
| for subdir in ["lib", "lib64"]: | |
| directories.append(os.path.join(self.config_vars["base"], subdir)) | |
| directories = dedupe(directories) | |
| for directory in directories: | |
| path = os.path.join(directory, library) | |
| if os.path.exists(path): | |
| return LibraryList(path) | |
| @property | |
| def libs(self): | |
| py_version = self.version.up_to(2) | |
| if is_windows: | |
| py_version = str(py_version).replace(".", "") | |
| lib_prefix = "lib" if not is_windows else "" | |
| # The values of LDLIBRARY and LIBRARY aren't reliable. Intel Python uses a | |
| # static binary but installs shared libraries, so sysconfig reports | |
| # libpythonX.Y.a but only libpythonX.Y.so exists. So we add our own paths, too. | |
| # With framework python on macOS, self.config_vars["LDLIBRARY"] can point | |
| # to a library that is not linkable because it does not have the required | |
| # suffix of a shared library (it is called "Python" without extention). | |
| # The linker then falls back to libPython.tbd in the default macOS | |
| # software tree, which security settings prohibit to link against | |
| # (your binary is not an allowed client of /path/to/libPython.tbd). | |
| # To avoid this, we replace the entry in config_vars with a default value. | |
| file_extension_shared = os.path.splitext(self.config_vars["LDLIBRARY"])[-1] | |
| if file_extension_shared == "": | |
| shared_libs = [] | |
| else: | |
| shared_libs = [self.config_vars["LDLIBRARY"]] | |
| shared_libs += [ | |
| "{}python{}.{}".format(lib_prefix, py_version, dso_suffix), | |
| ] | |
| # Like LDLIBRARY for Python on Mac OS, LIBRARY may refer to an un-linkable object | |
| file_extension_static = os.path.splitext(self.config_vars["LIBRARY"])[-1] | |
| if file_extension_static == "": | |
| static_libs = [] | |
| else: | |
| static_libs = [self.config_vars["LIBRARY"]] | |
| static_libs += [ | |
| "{}python{}.{}".format(lib_prefix, py_version, stat_suffix), | |
| ] | |
| # The +shared variant isn't reliable, as `spack external find` currently can't | |
| # detect it. If +shared, prefer the shared libraries, but check for static if | |
| # those aren't found. Vice versa for ~shared. | |
| if "+shared" in self.spec: | |
| candidates = shared_libs + static_libs | |
| else: | |
| candidates = static_libs + shared_libs | |
| candidates = dedupe(candidates) | |
| for candidate in candidates: | |
| lib = self.find_library(candidate) | |
| if lib: | |
| return lib | |
| raise spack.error.NoLibrariesError( | |
| "Unable to find {} libraries with the following names:".format(self.name), | |
| "\n".join(candidates), | |
| ) | |
| @property | |
| def headers(self): | |
| # Locations where pyconfig.h could be | |
| # This varies by system, especially on macOS where the command line tools are | |
| # installed in a very different directory from the system python interpreter. | |
| py_version = str(self.version.up_to(2)) | |
| candidates = [ | |
| os.path.dirname(self.config_vars["config_h_filename"]), | |
| self.config_vars["INCLUDEPY"], | |
| self.config_vars["CONFINCLUDEPY"], | |
| os.path.join(self.config_vars["base"], "include", py_version), | |
| os.path.join(self.config_vars["base"], "Headers"), | |
| ] | |
| candidates = list(dedupe(candidates)) | |
| for directory in candidates: | |
| headers = find_headers("pyconfig", directory) | |
| if headers: | |
| config_h = headers[0] | |
| break | |
| else: | |
| raise spack.error.NoHeadersError( | |
| "Unable to locate {} headers in any of these locations:".format(self.name), | |
| "\n".join(candidates), | |
| ) | |
| headers.directories = [os.path.dirname(config_h)] | |
| return headers | |
| # https://docs.python.org/3/library/sysconfig.html#installation-paths | |
| # https://discuss.python.org/t/understanding-site-packages-directories/12959 | |
| # https://github.com/pypa/pip/blob/22.1/src/pip/_internal/locations/__init__.py | |
| # https://github.com/pypa/installer/pull/103 | |
| # NOTE: XCode Python's sysconfing module was incorrectly patched, and hard-codes | |
| # everything to be installed in /Library/Python. Therefore, we need to use a | |
| # fallback in the following methods. For more information, see: | |
| # https://github.com/pypa/pip/blob/22.1/src/pip/_internal/locations/__init__.py#L486 | |
| @property | |
| def platlib(self): | |
| """Directory for site-specific, platform-specific files. | |
| Exact directory depends on platform/OS/Python version. Examples include: | |
| * ``lib/pythonX.Y/site-packages`` on most POSIX systems | |
| * ``lib64/pythonX.Y/site-packages`` on RHEL/CentOS/Fedora with system Python | |
| * ``lib/pythonX/dist-packages`` on Debian/Ubuntu with system Python | |
| * ``lib/python/site-packages`` on macOS with framework Python | |
| * ``Lib/site-packages`` on Windows | |
| Returns: | |
| str: platform-specific site-packages directory | |
| """ | |
| prefix = self.config_vars["platbase"] + os.sep | |
| path = self.config_vars["platlib"] | |
| if path.startswith(prefix): | |
| return path.replace(prefix, "") | |
| return os.path.join("lib64", "python{}".format(self.version.up_to(2)), "site-packages") | |
| @property | |
| def purelib(self): | |
| """Directory for site-specific, non-platform-specific files. | |
| Exact directory depends on platform/OS/Python version. Examples include: | |
| * ``lib/pythonX.Y/site-packages`` on most POSIX systems | |
| * ``lib/pythonX/dist-packages`` on Debian/Ubuntu with system Python | |
| * ``lib/python/site-packages`` on macOS with framework Python | |
| * ``Lib/site-packages`` on Windows | |
| Returns: | |
| str: platform-independent site-packages directory | |
| """ | |
| prefix = self.config_vars["base"] + os.sep | |
| path = self.config_vars["purelib"] | |
| if path.startswith(prefix): | |
| return path.replace(prefix, "") | |
| return os.path.join("lib", "python{}".format(self.version.up_to(2)), "site-packages") | |
| @property | |
| def include(self): | |
| """Directory for non-platform-specific header files. | |
| Exact directory depends on platform/Python version/ABI flags. Examples include: | |
| * ``include/pythonX.Y`` on most POSIX systems | |
| * ``include/pythonX.Yd`` for debug builds | |
| * ``include/pythonX.Ym`` for malloc builds | |
| * ``include/pythonX.Yu`` for wide unicode builds | |
| * ``include`` on macOS with framework Python | |
| * ``Include`` on Windows | |
| Returns: | |
| str: platform-independent header file directory | |
| """ | |
| prefix = self.config_vars["installed_base"] + os.sep | |
| path = self.config_vars["include"] | |
| if path.startswith(prefix): | |
| return path.replace(prefix, "") | |
| return os.path.join("include", "python{}".format(self.version.up_to(2))) | |
| def setup_run_environment(self, env): | |
| env.prepend_path("CPATH", os.pathsep.join(self.spec["python2"].headers.directories)) | |
| def setup_dependent_build_environment(self, env, dependent_spec): | |
| """Set PYTHONPATH to include the site-packages directory for the | |
| extension and any other python extensions it depends on. | |
| """ | |
| # If we set PYTHONHOME, we must also ensure that the corresponding | |
| # python is found in the build environment. This to prevent cases | |
| # where a system provided python is run against the standard libraries | |
| # of a Spack built python. See issue #7128 | |
| env.set("PYTHONHOME", self.home) | |
| path = os.path.dirname(self.command.path) | |
| if not is_system_path(path): | |
| env.prepend_path("PATH", path) | |
| # Add installation prefix to PYTHONPATH, needed to run import tests | |
| prefixes = set() | |
| if dependent_spec.package.extends(self.spec): | |
| prefixes.add(dependent_spec.prefix) | |
| # Add direct build/run/test dependencies to PYTHONPATH, | |
| # needed to build the package and to run import tests | |
| for direct_dep in dependent_spec.dependencies(deptype=("build", "run", "test")): | |
| if direct_dep.package.extends(self.spec): | |
| prefixes.add(direct_dep.prefix) | |
| # Add recursive run dependencies of all direct dependencies, | |
| # needed by direct dependencies at run-time | |
| for indirect_dep in direct_dep.traverse(deptype="run"): | |
| if indirect_dep.package.extends(self.spec): | |
| prefixes.add(indirect_dep.prefix) | |
| for prefix in prefixes: | |
| # Packages may be installed in platform-specific or platform-independent | |
| # site-packages directories | |
| for directory in {self.platlib, self.purelib}: | |
| env.prepend_path("PYTHONPATH", os.path.join(prefix, directory)) | |
| # We need to make sure that the extensions are compiled and linked with | |
| # the Spack wrapper. Paths to the executables that are used for these | |
| # operations are normally taken from the sysconfigdata file, which we | |
| # modify after the installation (see method filter compilers). The | |
| # modified file contains paths to the real compilers, not the wrappers. | |
| # The values in the file, however, can be overridden with environment | |
| # variables. The first variable, CC (CXX), which is used for | |
| # compilation, is set by Spack for the dependent package by default. | |
| # That is not 100% correct because the value for CC (CXX) in the | |
| # sysconfigdata file often contains additional compiler flags (e.g. | |
| # -pthread), which we lose by simply setting CC (CXX) to the path to the | |
| # Spack wrapper. Moreover, the user might try to build an extension with | |
| # a compiler that is different from the one that was used to build | |
| # Python itself, which might have unexpected side effects. However, the | |
| # experience shows that none of the above is a real issue and we will | |
| # not try to change the default behaviour. Given that, we will simply | |
| # try to modify LDSHARED (LDCXXSHARED), the second variable, which is | |
| # used for linking, in a consistent manner. | |
| for compile_var, link_var in [("CC", "LDSHARED"), ("CXX", "LDCXXSHARED")]: | |
| # First, we get the values from the sysconfigdata: | |
| config_compile = self.config_vars[compile_var] | |
| config_link = self.config_vars[link_var] | |
| # The dependent environment will have the compilation command set to | |
| # the following: | |
| new_compile = join_path( | |
| spack.paths.build_env_path, | |
| dependent_spec.package.compiler.link_paths[compile_var.lower()], | |
| ) | |
| # Normally, the link command starts with the compilation command: | |
| if config_link.startswith(config_compile): | |
| new_link = new_compile + config_link[len(config_compile) :] | |
| else: | |
| # Otherwise, we try to replace the compiler command if it | |
| # appears "in the middle" of the link command; to avoid | |
| # mistaking some substring of a path for the compiler (e.g. to | |
| # avoid replacing "gcc" in "-L/path/to/gcc/"), we require that | |
| # the compiler command be surrounded by spaces. Note this may | |
| # leave "config_link" unchanged if the compilation command does | |
| # not appear in the link command at all, for example if "ld" is | |
| # invoked directly (no change would be required in that case | |
| # because Spack arranges for the Spack ld wrapper to be the | |
| # first instance of "ld" in PATH). | |
| new_link = config_link.replace( | |
| " {0} ".format(config_compile), " {0} ".format(new_compile) | |
| ) | |
| # There is logic in the sysconfig module that is sensitive to the | |
| # fact that LDSHARED is set in the environment, therefore we export | |
| # the variable only if the new value is different from what we got | |
| # from the sysconfigdata file: | |
| if config_link != new_link and not is_windows: | |
| env.set(link_var, new_link) | |
| def setup_dependent_run_environment(self, env, dependent_spec): | |
| """Set PYTHONPATH to include the site-packages directory for the | |
| extension and any other python extensions it depends on. | |
| """ | |
| for d in dependent_spec.traverse(deptype=("run"), root=True): | |
| if d.package.extends(self.spec): | |
| # Packages may be installed in platform-specific or platform-independent | |
| # site-packages directories | |
| for directory in {self.platlib, self.purelib}: | |
| env.prepend_path("PYTHONPATH", os.path.join(d.prefix, directory)) | |
| def setup_dependent_package(self, module, dependent_spec): | |
| """Called before python modules' install() methods.""" | |
| module.python = self.command | |
| module.python_include = join_path(dependent_spec.prefix, self.include) | |
| module.python_platlib = join_path(dependent_spec.prefix, self.platlib) | |
| module.python_purelib = join_path(dependent_spec.prefix, self.purelib) | |
| # Make the site packages directory for extensions | |
| if dependent_spec.package.is_extension: | |
| mkdirp(module.python_platlib) | |
| mkdirp(module.python_purelib) | |
| def add_files_to_view(self, view, merge_map, skip_if_exists=True): | |
| """Make the view a virtual environment if it isn't one already. | |
| If `python-venv` is linked into the view, it will already be a virtual | |
| environment. If not, then this is an older python that doesn't use the | |
| python-venv support, or we may be using python packages that | |
| use ``depends_on("python")`` but not ``extends("python")``. | |
| We used to copy the python interpreter in, but we can get the same effect in a | |
| simpler way by adding a ``pyvenv.cfg`` to the environment. | |
| """ | |
| super().add_files_to_view(view, merge_map, skip_if_exists=skip_if_exists) | |
| # location of python inside the view, where we will put the venv config | |
| projection = view.get_projection_for_spec(self.spec) | |
| pyvenv_cfg = os.path.join(projection, "pyvenv.cfg") | |
| if os.path.lexists(pyvenv_cfg): | |
| return | |
| # don't put a pyvenv.cfg in a copy view | |
| if view.link_type == "copy": | |
| return | |
| with open(pyvenv_cfg, "w") as cfg_file: | |
| cfg_file.write(make_pyvenv_cfg(self, projection)) | |
| def test(self): | |
| # do not use self.command because we are also testing the run env | |
| exe = self.spec["python2"].command.name | |
| # test hello world | |
| msg = "hello world!" | |
| reason = "test: running {0}".format(msg) | |
| options = ["-c", 'print("{0}")'.format(msg)] | |
| self.run_test(exe, options=options, expected=[msg], installed=True, purpose=reason) | |
| # checks import works and executable comes from the spec prefix | |
| reason = "test: checking import and executable" | |
| print_str = self.print_string("sys.executable") | |
| options = ["-c", "import sys; {0}".format(print_str)] | |
| self.run_test( | |
| exe, options=options, expected=[self.spec.prefix], installed=True, purpose=reason | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment