diff --git a/recipes/cpython/all/conandata.yml b/recipes/cpython/all/conandata.yml index f9fd51067c8b3..80e01a0b76111 100644 --- a/recipes/cpython/all/conandata.yml +++ b/recipes/cpython/all/conandata.yml @@ -8,65 +8,58 @@ sources: "3.8.12": url: "https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tgz" sha256: "316aa33f3b7707d041e73f246efedb297a70898c4b91f127f66dc8d80c596f1a" - "3.7.12": - url: "https://www.python.org/ftp/python/3.7.12/Python-3.7.12.tgz" - sha256: "33b4daaf831be19219659466d12645f87ecec6eb21d4d9f9711018a7b66cce46" - "2.7.18": - url: "https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz" - sha256: "da3080e3b488f648a3d7a4560ddee895284c3380b11d6de75edb986526b9a814" patches: "3.10.0": - - patch_file: "patches/3.10.0-0001-msvc.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.9.7-0002-_msi-vcxproj.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.10.0-0003-_ctypes-ffi.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.10.0-0004-setup.py-pass-CFLAGS-CPPFLAGS.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.10.0-0005-disable-macos-tcltk.patch" - base_path: "source_subfolder" + - patch_file: "patches/3.10/3.10.0-0001-msvc.patch" + patch_description: "Version specific patches to MSVC projects to allow injection of dependencies" + patch_type: "conan" + - patch_file: "patches/3.9/3.9.7-0002-_msi-vcxproj.patch" + patch_description: "Fix ARM/ARM64 mismatch in project file" + patch_type: "bugfix" + - patch_file: "patches/3.10/3.10.0-0003-_ctypes-ffi.patch" + patch_description: "Remove duplicate libffi symbols and support shared libffi" + patch_type: "portability" + - patch_file: "patches/3.10/3.10.0-0004-setup.py-pass-CFLAGS-CPPFLAGS.patch" + patch_description: "Pass C and CPP flags from configure script to setup.py" + patch_type: "bugfix" + - patch_file: "patches/3.10/3.10.0-0005-disable-macos-tcltk.patch" + patch_description: "Unconditionally enable tcl/tk on Mac" + patch_type: "conan" - patch_file: "patches/3.x-0001-relocatable-python-config.patch" - base_path: "source_subfolder" + patch_description: "Allow package to be relocatable" + patch_type: "conan" "3.9.7": - - patch_file: "patches/3.9.7-0001-msvc.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.9.7-0002-_msi-vcxproj.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.9.7-0003-_ctypes-ffi.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.9.7-0004-setup.py-pass-CFLAGS-CPPFLAGS.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.9.7-0005-disable-macos-tcltk.patch" - base_path: "source_subfolder" + - patch_file: "patches/3.9/3.9.7-0001-msvc.patch" + patch_description: "Version specific patches to MSVC projects to allow injection of dependencies" + patch_type: "conan" + - patch_file: "patches/3.9/3.9.7-0002-_msi-vcxproj.patch" + patch_description: "Fix ARM/ARM64 mismatch in project file" + patch_type: "bugfix" + - patch_file: "patches/3.9/3.9.7-0003-_ctypes-ffi.patch" + patch_description: "Remove duplicate libffi symbols and support shared libffi" + patch_type: "portability" + - patch_file: "patches/3.9/3.9.7-0004-setup.py-pass-CFLAGS-CPPFLAGS.patch" + patch_description: "Pass C and CPP flags from configure script to setup.py" + patch_type: "bugfix" + - patch_file: "patches/3.9/3.9.7-0005-disable-macos-tcltk.patch" + patch_description: "Unconditionally enable tcl/tk on Mac" + patch_type: "conan" - patch_file: "patches/3.x-0001-relocatable-python-config.patch" - base_path: "source_subfolder" + patch_description: "Allow package to be relocatable" + patch_type: "conan" "3.8.12": - - patch_file: "patches/3.8.12-0001-msvc.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.8.12-0002-_ctypes-ffi.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.8.12-0003-setup.py-pass-CFLAGS-CPPFLAGS.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.8.12-0004-disable-macos-tcltk.patch" - base_path: "source_subfolder" + - patch_file: "patches/3.8/3.8.12-0001-msvc.patch" + patch_description: "Version specific patches to MSVC projects to allow injection of dependencies" + patch_type: "conan" + - patch_file: "patches/3.8/3.8.12-0002-_ctypes-ffi.patch" + patch_description: "Remove duplicate libffi symbols and support shared libffi" + patch_type: "portability" + - patch_file: "patches/3.8/3.8.12-0003-setup.py-pass-CFLAGS-CPPFLAGS.patch" + patch_description: "Pass C and CPP flags from configure script to setup.py" + patch_type: "bugfix" + - patch_file: "patches/3.8/3.8.12-0004-disable-macos-tcltk.patch" + patch_description: "Unconditionally enable tcl/tk on Mac" + patch_type: "conan" - patch_file: "patches/3.x-0001-relocatable-python-config.patch" - base_path: "source_subfolder" - "3.7.12": - - patch_file: "patches/3.7.9-0001-msvc.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.7.9-0002-setup.py-pass-CFLAGS-CPPFLAGS.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.7.9-0003-disable-macos-tcltk.patch" - base_path: "source_subfolder" - - patch_file: "patches/3.x-0001-relocatable-python-config.patch" - base_path: "source_subfolder" - "2.7.18": - - patch_file: "patches/2.7.18-0001-msvc.patch" - base_path: "source_subfolder" - - patch_file: "patches/2.7.18-0002-add-support-msvc-14.patch" - base_path: "source_subfolder" - - patch_file: "patches/2.7.18-0003-msvc-fix-static.patch" - base_path: "source_subfolder" - - patch_file: "patches/2.7.18-0004-disable-macos-tcltk.patch" - base_path: "source_subfolder" + patch_description: "Allow package to be relocatable" + patch_type: "conan" diff --git a/recipes/cpython/all/conanfile.py b/recipes/cpython/all/conanfile.py index 4fa1d1da6334e..160fe6920a426 100644 --- a/recipes/cpython/all/conanfile.py +++ b/recipes/cpython/all/conanfile.py @@ -1,21 +1,29 @@ -from conans import AutoToolsBuildEnvironment, ConanFile, MSBuild, tools -from conans.errors import ConanInvalidConfiguration -from io import StringIO import os import re import textwrap -required_conan_version = ">=1.33.0" +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration, ConanException +from conan.tools.apple import is_apple_os, fix_apple_shared_install_name +from conan.tools.env import VirtualRunEnv +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, mkdir, replace_in_file, rm, rmdir, unzip +from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps +from conan.tools.layout import basic_layout +from conan.tools.microsoft import MSBuildDeps, MSBuildToolchain, MSBuild, is_msvc, is_msvc_static_runtime, msvc_runtime_flag, msvs_toolset +from conan.tools.scm import Version + +required_conan_version = ">=1.58.0" class CPythonConan(ConanFile): name = "cpython" + description = "Python is a programming language that lets you work quickly and integrate systems more effectively." + license = "Python-2.0" url = "https://github.com/conan-io/conan-center-index" homepage = "https://www.python.org" - description = "Python is a programming language that lets you work quickly and integrate systems more effectively." topics = ("python", "cpython", "language", "script") - license = ("Python-2.0",) - exports_sources = "patches/**" + + package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { "shared": [True, False], @@ -30,11 +38,6 @@ class CPythonConan(ConanFile): "with_sqlite3": [True, False], "with_tkinter": [True, False], "with_curses": [True, False], - - # Python 2 options - "unicode": ["ucs2", "ucs4"], - "with_bsddb": [True, False], - # Python 3 options "with_lzma": [True, False], # options that don't change package id @@ -53,168 +56,132 @@ class CPythonConan(ConanFile): "with_sqlite3": True, "with_tkinter": True, "with_curses": True, - - # Python 2 options - "unicode": "ucs2", - "with_bsddb": False, # True, # FIXME: libdb package missing (#5309/#5392) - # Python 3 options "with_lzma": True, # options that don't change package id "env_vars": True, } - - _autotools = None - - @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _version_number_only(self): - return re.match(r"^([0-9.]+)", self.version).group(1) - - @property - def _version_tuple(self): - return tuple(self._version_number_only.split(".")) + short_paths = True @property def _supports_modules(self): - return self.settings.compiler != "Visual Studio" or self.options.shared + return not is_msvc(self) or self.options.shared @property def _version_suffix(self): - if self.settings.compiler == "Visual Studio": - joiner = "" - else: - joiner = "." - return joiner.join(self._version_tuple[:2]) - - @property - def _is_py3(self): - return tools.Version(self._version_number_only).major == "3" + v = Version(self.version) + joiner = "" if is_msvc(self) else "." + return f"{v.major}{joiner}{v.minor}" - @property - def _is_py2(self): - return tools.Version(self._version_number_only).major == "2" + def export_sources(self): + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": del self.options.fPIC - if self.settings.compiler == "Visual Studio": + if is_msvc(self): del self.options.lto del self.options.docstrings del self.options.pymalloc del self.options.with_curses del self.options.with_gdbm del self.options.with_nis - if self._is_py2: - # Python 2.xx does not support following options - del self.options.with_lzma - elif self._is_py3: - # Python 3.xx does not support following options - del self.options.with_bsddb - del self.options.unicode - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + self.settings.compiler.rm_safe("libcxx") + self.settings.compiler.rm_safe("cppstd") def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") if not self._supports_modules: - del self.options.with_bz2 - del self.options.with_sqlite3 - del self.options.with_tkinter - - del self.options.with_bsddb - del self.options.with_lzma - if self.settings.compiler == "Visual Studio": - # The msbuild generator only works with Visual Studio - self.generators.append("MSBuildDeps") - - def validate(self): - if self.options.shared: - if self.settings.compiler == "Visual Studio" and "MT" in self.settings.compiler.runtime: - raise ConanInvalidConfiguration("cpython does not support MT(d) runtime when building a shared cpython library") - if self.settings.compiler == "Visual Studio": - if self.options.optimizations: - raise ConanInvalidConfiguration("This recipe does not support optimized MSVC cpython builds (yet)") - # FIXME: should probably throw when cross building - # FIXME: optimizations for Visual Studio, before building the final `build_type`: - # 1. build the MSVC PGInstrument build_type, - # 2. run the instrumented binaries, (PGInstrument should have created a `python.bat` file in the PCbuild folder) - # 3. build the MSVC PGUpdate build_type - if self.settings.build_type == "Debug" and "d" not in self.settings.compiler.runtime: - raise ConanInvalidConfiguration("Building debug cpython requires a debug runtime (Debug cpython requires _CrtReportMode symbol, which only debug runtimes define)") - if self._is_py2: - if self.settings.compiler.version >= tools.Version("14"): - self.output.warn("Visual Studio versions 14 and higher were never officially supported by the CPython developers") - if str(self.settings.arch) not in self._msvc_archs: - raise ConanInvalidConfiguration("Visual Studio does not support this architecture") - - if not self.options.shared and tools.Version(self._version_number_only) >= "3.10": - raise ConanInvalidConfiguration("Static msvc build disabled (>=3.10) due to \"AttributeError: module 'sys' has no attribute 'winver'\"") - - if self.options.get_safe("with_curses", False) and not self.options["ncurses"].with_widec: - raise ConanInvalidConfiguration("cpython requires ncurses with wide character support") - - def package_id(self): - del self.info.options.env_vars - - def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) + self.options.rm_safe("with_bz2") + self.options.rm_safe("with_sqlite3") + self.options.rm_safe("with_tkinter") + self.options.rm_safe("with_lzma") - @property - def _with_libffi(self): - # cpython 3.7.x on MSVC uses an ancient libffi 2.00-beta (which is not available at cci, and is API/ABI incompatible with current 3.2+) - return self._supports_modules \ - and (self.settings.compiler != "Visual Studio" or tools.Version(self._version_number_only) >= "3.8") + def layout(self): + basic_layout(self, src_folder="src") def requirements(self): - self.requires("zlib/1.2.11") + self.requires("zlib/[>=1.2.11 <2]") if self._supports_modules: - self.requires("openssl/1.1.1l") - self.requires("expat/2.4.1") - if self._with_libffi: - self.requires("libffi/3.2.1") - if tools.Version(self._version_number_only) < "3.8": - self.requires("mpdecimal/2.4.2") - elif tools.Version(self._version_number_only) < "3.10": + self.requires("openssl/[>=1.1 <4]") + self.requires("expat/2.6.0") + self.requires("libffi/3.4.4") + if Version(self.version) < "3.10" or is_apple_os(self): + # FIXME: mpdecimal > 2.5.0 on MacOS causes the _decimal module to not be importable self.requires("mpdecimal/2.5.0") else: - self.requires("mpdecimal/2.5.0") # FIXME: no 2.5.1 to troubleshoot apple + self.requires("mpdecimal/2.5.1") if self.settings.os != "Windows": - if not tools.is_apple_os(self.settings.os): - self.requires("libuuid/1.0.3") - self.requires("libxcrypt/4.4.25") + if not is_apple_os(self): + self.requires("util-linux-libuuid/2.39.2") + # If crypt.h is detected, it is included in the public headers. + self.requires("libxcrypt/4.4.36", transitive_headers=True, transitive_libs=True) if self.options.get_safe("with_bz2"): self.requires("bzip2/1.0.8") if self.options.get_safe("with_gdbm", False): - self.requires("gdbm/1.19") + self.requires("gdbm/1.23") if self.options.get_safe("with_nis", False): # TODO: Add nis when available. raise ConanInvalidConfiguration("nis is not available on CCI (yet)") if self.options.get_safe("with_sqlite3"): - self.requires("sqlite3/3.36.0") + self.requires("sqlite3/3.45.0") if self.options.get_safe("with_tkinter"): self.requires("tk/8.6.10") if self.options.get_safe("with_curses", False): - self.requires("ncurses/6.2") - if self.options.get_safe("with_bsddb", False): - self.requires("libdb/5.3.28") + # Used in a public header + # https://github.com/python/cpython/blob/v3.10.13/Include/py_curses.h#L34 + self.requires("ncurses/6.4", transitive_headers=True, transitive_libs=True) if self.options.get_safe("with_lzma", False): - self.requires("xz_utils/5.2.5") + self.requires("xz_utils/5.6.1") + + def package_id(self): + del self.info.options.env_vars + + def validate(self): + if self.options.shared: + if is_msvc_static_runtime(self): + raise ConanInvalidConfiguration( + "cpython does not support MT(d) runtime when building a shared cpython library" + ) + if is_msvc(self): + if self.options.optimizations: + raise ConanInvalidConfiguration( + "This recipe does not support optimized MSVC cpython builds (yet)" + ) + # FIXME: should probably throw when cross building + # FIXME: optimizations for Visual Studio, before building the final `build_type`: + # 1. build the MSVC PGInstrument build_type, + # 2. run the instrumented binaries, (PGInstrument should have created a `python.bat` file in the PCbuild folder) + # 3. build the MSVC PGUpdate build_type + if self.settings.build_type == "Debug" and "d" not in msvc_runtime_flag(self): + raise ConanInvalidConfiguration( + "Building debug cpython requires a debug runtime (Debug cpython requires _CrtReportMode" + " symbol, which only debug runtimes define)" + ) + if str(self.settings.arch) not in self._msvc_archs: + raise ConanInvalidConfiguration("Visual Studio does not support this architecture") + if not self.options.shared and Version(self.version) >= "3.10": + raise ConanInvalidConfiguration("Static msvc build disabled (>=3.10) due to \"AttributeError: module 'sys' has no attribute 'winver'\"") + + if self.options.get_safe("with_curses", False) and not self.dependencies["ncurses"].options.with_widec: + raise ConanInvalidConfiguration("cpython requires ncurses with wide character support") + + if self._supports_modules: + if Version(self.version) >= "3.9.0": + if self.dependencies["mpdecimal"].ref.version < Version("2.5.0"): + raise ConanInvalidConfiguration("cpython 3.9.0 (and newer) requires (at least) mpdecimal 2.5.0") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) - def _configure_autotools(self): - if self._autotools: - return self._autotools - self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) - self._autotools.libs = [] + def _generate_autotools(self): + tc = AutotoolsToolchain(self, prefix=self.package_folder) + # Not necessary, just cleans up the output + tc.update_configure_args({"--enable-static": None, "--disable-static": None}) yes_no = lambda v: "yes" if v else "no" - conf_args = [ - "--enable-shared={}".format(yes_no(self.options.shared)), + tc.configure_args += [ "--with-doc-strings={}".format(yes_no(self.options.docstrings)), "--with-pymalloc={}".format(yes_no(self.options.pymalloc)), "--with-system-expat", @@ -222,117 +189,157 @@ def _configure_autotools(self): "--enable-optimizations={}".format(yes_no(self.options.optimizations)), "--with-lto={}".format(yes_no(self.options.lto)), "--with-pydebug={}".format(yes_no(self.settings.build_type == "Debug")), + "--with-system-libmpdec", + "--with-openssl={}".format(self.dependencies["openssl"].package_folder), ] - if self._is_py2: - conf_args.extend([ - "--enable-unicode={}".format(yes_no(self.options.unicode)), - ]) - if self._is_py3: - conf_args.extend([ - "--with-system-libmpdec", - "--with-openssl={}".format(self.deps_cpp_info["openssl"].rootpath), - "--enable-loadable-sqlite-extensions={}".format(yes_no(not self.options["sqlite3"].omit_load_extension)), - ]) - if self.settings.compiler == "intel": - conf_args.extend(["--with-icc"]) - if tools.get_env("CC") or self.settings.compiler != "gcc": - conf_args.append("--without-gcc") + if Version(self.version) >= "3.10": + tc.configure_args.append("--disable-test-modules") + if self.options.get_safe("with_sqlite3"): + tc.configure_args.append("--enable-loadable-sqlite-extensions={}".format( + yes_no(not self.dependencies["sqlite3"].options.omit_load_extension) + )) if self.options.with_tkinter: tcltk_includes = [] tcltk_libs = [] # FIXME: collect using some conan util (https://github.com/conan-io/conan/issues/7656) for dep in ("tcl", "tk", "zlib"): - tcltk_includes += ["-I{}".format(d) for d in self.deps_cpp_info[dep].include_paths] - tcltk_libs += ["-l{}".format(lib) for lib in self.deps_cpp_info[dep].libs] - if self.settings.os == "Linux" and not self.options["tk"].shared: + cpp_info = self.dependencies[dep].cpp_info.aggregated_components() + tcltk_includes += [f"-I{d}" for d in cpp_info.includedirs] + tcltk_libs += [f"-L{lib}" for lib in cpp_info.libdirs] + tcltk_libs += [f"-l{lib}" for lib in cpp_info.libs] + if self.settings.os in ["Linux", "FreeBSD"] and not self.dependencies["tk"].options.shared: # FIXME: use info from xorg.components (x11, xscrnsaver) - tcltk_libs.extend(["-l{}".format(lib) for lib in ("X11", "Xss")]) - conf_args.extend([ + tcltk_libs.extend([f"-l{lib}" for lib in ("X11", "Xss")]) + tc.configure_args += [ "--with-tcltk-includes={}".format(" ".join(tcltk_includes)), "--with-tcltk-libs={}".format(" ".join(tcltk_libs)), - ]) - if self.settings.os in ("Linux", "FreeBSD"): - # Building _testembed fails due to missing pthread/rt symbols - self._autotools.link_flags.append("-lpthread") - - build = None - if tools.cross_building(self) and not tools.cross_building(self, skip_x64_x86=True): - # Building from x86_64 to x86 is not a "real" cross build, so set build == host - build = tools.get_gnu_triplet(str(self.settings.os), str(self.settings.arch), str(self.settings.compiler)) - self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder, build=build) - return self._autotools + ] + if not is_apple_os(self): + tc.extra_ldflags.append('-Wl,--as-needed') + + tc.generate() + + deps = AutotoolsDeps(self) + deps.generate() + + def generate(self): + VirtualRunEnv(self).generate(scope="build") + + if is_msvc(self): + # The msbuild generator only works with Visual Studio + deps = MSBuildDeps(self) + deps.generate() + # The toolchain.props is not injected yet, but it also generates VCVars + toolchain = MSBuildToolchain(self) + toolchain.properties["IncludeExternals"] = "true" + toolchain.generate() + else: + self._generate_autotools() def _patch_sources(self): - for patch in self.conan_data.get("patches",{}).get(self.version, []): - tools.patch(**patch) - if self._is_py3 and tools.Version(self._version_number_only) < "3.10": - tools.replace_in_file(os.path.join(self._source_subfolder, "setup.py"), - ":libmpdec.so.2", "mpdec") - if self.settings.compiler == "Visual Studio": + apply_conandata_patches(self) + setup_py = os.path.join(self.source_folder, "setup.py") + if Version(self.version) < "3.10": + replace_in_file(self, setup_py, ":libmpdec.so.2", "mpdec") + if is_msvc(self): runtime_library = { "MT": "MultiThreaded", "MTd": "MultiThreadedDebug", "MD": "MultiThreadedDLL", "MDd": "MultiThreadedDebugDLL", - }[str(self.settings.compiler.runtime)] + }[msvc_runtime_flag(self)] self.output.info("Patching runtime") - tools.replace_in_file(os.path.join(self._source_subfolder, "PCbuild", "pyproject.props"), - "MultiThreadedDLL", runtime_library) - tools.replace_in_file(os.path.join(self._source_subfolder, "PCbuild", "pyproject.props"), - "MultiThreadedDebugDLL", runtime_library) + replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "pyproject.props"), + "MultiThreadedDLL", runtime_library) + replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "pyproject.props"), + "MultiThreadedDebugDLL", runtime_library) # Remove vendored packages - tools.rmdir(os.path.join(self._source_subfolder, "Modules", "_decimal", "libmpdec")) - tools.rmdir(os.path.join(self._source_subfolder, "Modules", "expat")) + rmdir(self, os.path.join(self.source_folder, "Modules", "_decimal", "libmpdec")) + rmdir(self, os.path.join(self.source_folder, "Modules", "expat")) if self.options.get_safe("with_curses", False): # FIXME: this will link to ALL libraries of ncurses. Only need to link to ncurses(w) (+ eventually tinfo) - tools.replace_in_file(os.path.join(self._source_subfolder, "setup.py"), - "curses_libs = ", - "curses_libs = {} #".format(repr(self.deps_cpp_info["ncurses"].libs + self.deps_cpp_info["ncurses"].system_libs))) + ncurses_info = self.dependencies["ncurses"].cpp_info.aggregated_components() + replace_in_file(self, setup_py, + "curses_libs = ", + "curses_libs = {} #".format(repr(ncurses_info.libs + ncurses_info.system_libs))) + + if self._supports_modules: + openssl = self.dependencies["openssl"].cpp_info.aggregated_components() + zlib = self.dependencies["zlib"].cpp_info.aggregated_components() + replace_in_file(self, setup_py, + "openssl_includes = ", + f"openssl_includes = {openssl.includedirs + zlib.includedirs} #") + replace_in_file(self, setup_py, + "openssl_libdirs = ", + f"openssl_libdirs = {openssl.libdirs + zlib.libdirs} #") + replace_in_file(self, setup_py, + "openssl_libs = ", + f"openssl_libs = {openssl.libs + zlib.libs} #") # Enable static MSVC cpython if not self.options.shared: - tools.replace_in_file(os.path.join(self._source_subfolder, "PCbuild", "pythoncore.vcxproj"), - "","Py_NO_BUILD_SHARED;") - tools.replace_in_file(os.path.join(self._source_subfolder, "PCbuild", "pythoncore.vcxproj"), - "Py_ENABLE_SHARED", "Py_NO_ENABLE_SHARED") - tools.replace_in_file(os.path.join(self._source_subfolder, "PCbuild", "pythoncore.vcxproj"), - "DynamicLibrary", "StaticLibrary") - - tools.replace_in_file(os.path.join(self._source_subfolder, "PCbuild", "python.vcxproj"), - "", "shlwapi.lib;ws2_32.lib;pathcch.lib;version.lib;%(AdditionalDependencies)") - tools.replace_in_file(os.path.join(self._source_subfolder, "PCbuild", "python.vcxproj"), - "", "Py_NO_ENABLE_SHARED;") - - tools.replace_in_file(os.path.join(self._source_subfolder, "PCbuild", "pythonw.vcxproj"), - "", "shlwapi.lib;ws2_32.lib;pathcch.lib;version.lib;%(AdditionalDependencies)") - tools.replace_in_file(os.path.join(self._source_subfolder, "PCbuild", "pythonw.vcxproj"), - "", "Py_NO_ENABLE_SHARED;%(PreprocessorDefinitions)") - - def _upgrade_single_project_file(self, project_file): - """ - `devenv /upgrade ` will upgrade *ALL* projects referenced by the project. - By temporarily moving the solution project, only one project is upgraded - This is needed for static cpython or for disabled optional dependencies (e.g. tkinter=False) - Restore it afterwards because it is needed to build some targets. - """ - tools.rename(os.path.join(self._source_subfolder, "PCbuild", "pcbuild.sln"), - os.path.join(self._source_subfolder, "PCbuild", "pcbuild.sln.bak")) - tools.rename(os.path.join(self._source_subfolder, "PCbuild", "pcbuild.proj"), - os.path.join(self._source_subfolder, "PCbuild", "pcbuild.proj.bak")) - with tools.vcvars(self.settings): - self.run("devenv \"{}\" /upgrade".format(project_file), run_environment=True) - tools.rename(os.path.join(self._source_subfolder, "PCbuild", "pcbuild.sln.bak"), - os.path.join(self._source_subfolder, "PCbuild", "pcbuild.sln")) - tools.rename(os.path.join(self._source_subfolder, "PCbuild", "pcbuild.proj.bak"), - os.path.join(self._source_subfolder, "PCbuild", "pcbuild.proj")) + replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "pythoncore.vcxproj"), + "", + "Py_NO_BUILD_SHARED;") + replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "pythoncore.vcxproj"), + "Py_ENABLE_SHARED", + "Py_NO_ENABLE_SHARED") + replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "pythoncore.vcxproj"), + "DynamicLibrary", + "StaticLibrary") + + replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "python.vcxproj"), + "", + "shlwapi.lib;ws2_32.lib;pathcch.lib;version.lib;%(AdditionalDependencies)") + replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "python.vcxproj"), + "", + "Py_NO_ENABLE_SHARED;") + + replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "pythonw.vcxproj"), + "", + "shlwapi.lib;ws2_32.lib;pathcch.lib;version.lib;%(AdditionalDependencies)") + replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "pythonw.vcxproj"), + "", + "Py_NO_ENABLE_SHARED;%(PreprocessorDefinitions)") + + # Don't import projects that we aren't pulling + deps = [ + # Option suffix, base file name, conan props suffix + ("sqlite3", "_sqlite3", "sqlite3"), + ("tkinter", "_tkinter", "tk"), + ("bz2", "_bz2", "bzip2"), + ("lzma", "_lzma", "xz_utils"), + ] + for opt, fname, propname in deps: + full_file = os.path.join(self.source_folder, "PCbuild", f"{fname}.vcxproj") + if not self.options.get_safe(f"with_{opt}", default=True): + replace_in_file(self, full_file, f'', "") + + # Fix props path for dependencies we are pulling + PCBuild = os.path.join(self.source_folder, "PCbuild") + for filename in os.listdir(PCBuild): + if filename.endswith(".vcxproj"): + replace_in_file(self, os.path.join(PCBuild, filename), "CONAN_REPLACE_HERE", self.generators_folder, strict=False) + + conantoolchain_props = os.path.join(self.generators_folder, MSBuildToolchain.filename) + replace_in_file( + self, os.path.join(self.source_folder, "PCbuild", "pythoncore.vcxproj"), + '', + f'', + ) + + for project in ["python", "pythonw"]: + replace_in_file(self, os.path.join(self.source_folder, "PCbuild", f"{project}.vcxproj"), + '', + f'') @property def _solution_projects(self): if self.options.shared: - solution_path = os.path.join(self._source_subfolder, "PCbuild", "pcbuild.sln") - projects = set(m.group(1) for m in re.finditer("\"([^\"]+)\\.vcxproj\"", open(solution_path).read())) + solution_path = os.path.join(self.source_folder, "PCbuild", "pcbuild.sln") + projects = set(m.group(1) for m in re.finditer('"([^"]+)\\.vcxproj"', open(solution_path).read())) def project_build(name): if os.path.basename(name) in self._msvc_discarded_projects: @@ -341,39 +348,31 @@ def project_build(name): return False return True - def sort_importance(key): - importance = ( - "pythoncore", # The python library MUST be built first. All modules and executables depend on it - "python", # Build the python executable next (for convenience, when debugging) - ) - try: - return importance.index(key) - except ValueError: - return len(importance) - - projects = sorted((p for p in projects if project_build(p)), key=sort_importance) + projects = list(filter(project_build, projects)) return projects else: - return "pythoncore", "python", "pythonw" + return ["pythoncore", "python", "pythonw"] @property def _msvc_discarded_projects(self): - discarded = {"python_uwp", "pythonw_uwp"} + discarded = { + "python_uwp", + "pythonw_uwp", + "_freeze_importlib", + "sqlite3", + "bdist_wininst", + "liblzma", + "openssl", + "xxlimited", + } if not self.options.with_bz2: discarded.add("bz2") if not self.options.with_sqlite3: discarded.add("_sqlite3") if not self.options.with_tkinter: discarded.add("_tkinter") - if self._is_py2: - # Python 2 Visual Studio projects NOT to build - discarded = discarded.union({"bdist_wininst", "libeay", "ssleay", "sqlite3", "tcl", "tk", "tix"}) - if not self.options.with_bsddb: - discarded.add("_bsddb") - elif self._is_py3: - discarded = discarded.union({"bdist_wininst", "liblzma", "openssl", "sqlite3", "xxlimited"}) - if not self.options.with_lzma: - discarded.add("_lzma") + if not self.options.with_lzma: + discarded.add("_lzma") return discarded @property @@ -381,50 +380,31 @@ def _msvc_archs(self): archs = { "x86": "Win32", "x86_64": "x64", + "armv7": "ARM", + "armv8_32": "ARM", + "armv8": "ARM64", } - if tools.Version(self._version_number_only) >= "3.8": - archs.update({ - "armv7": "ARM", - "armv8_32": "ARM", - "armv8": "ARM64", - }) return archs def _msvc_build(self): msbuild = MSBuild(self) - msbuild_properties = { - "IncludeExternals": "true", - } + msbuild.platform = self._msvc_archs[str(self.settings.arch)] + projects = self._solution_projects - self.output.info("Building {} Visual Studio projects: {}".format(len(projects), projects)) + self.output.info(f"Building {len(projects)} Visual Studio projects: {projects}") - with tools.no_op(): - for project_i, project in enumerate(projects, 1): - self.output.info("[{}/{}] Building project '{}'...".format(project_i, len(projects), project)) - project_file = os.path.join(self._source_subfolder, "PCbuild", project + ".vcxproj") - self._upgrade_single_project_file(project_file) - msbuild.build(project_file, upgrade_project=False, build_type="Debug" if self.settings.build_type == "Debug" else "Release", - platforms=self._msvc_archs, properties=msbuild_properties) + sln = os.path.join(self.source_folder, "PCbuild", "pcbuild.sln") + # FIXME: Solution files do not pick up the toolset automatically. + cmd = msbuild.command(sln, targets=projects) + self.run(f"{cmd} /p:PlatformToolset={msvs_toolset(self)}") def build(self): - # FIXME: these checks belong in validate, but the versions of dependencies are not available there yet - if self._supports_modules: - if tools.Version(self._version_number_only) < "3.8.0": - if tools.Version(self.deps_cpp_info["mpdecimal"].version) >= "2.5.0": - raise ConanInvalidConfiguration("cpython versions lesser then 3.8.0 require a mpdecimal lesser then 2.5.0") - elif tools.Version(self._version_number_only) >= "3.9.0": - if tools.Version(self.deps_cpp_info["mpdecimal"].version) < "2.5.0": - raise ConanInvalidConfiguration("cpython 3.9.0 (and newer) requires (at least) mpdecimal 2.5.0") - - if self._with_libffi: - if tools.Version(self.deps_cpp_info["libffi"].version) >= "3.3" and self.settings.compiler == "Visual Studio" and "d" in str(self.settings.compiler.runtime): - raise ConanInvalidConfiguration("libffi versions >= 3.3 cause 'read access violations' when using a debug runtime (MTd/MDd)") - self._patch_sources() - if self.settings.compiler == "Visual Studio": + if is_msvc(self): self._msvc_build() else: - autotools = self._configure_autotools() + autotools = Autotools(self) + autotools.configure() autotools.make() @property @@ -432,44 +412,40 @@ def _msvc_artifacts_path(self): build_subdir_lut = { "x86_64": "amd64", "x86": "win32", + "armv7": "arm32", + "armv8_32": "arm32", + "armv8": "arm64", } - if tools.Version(self._version_number_only) >= "3.8": - build_subdir_lut.update({ - "armv7": "arm32", - "armv8_32": "arm32", - "armv8": "arm64", - }) - return os.path.join(self._source_subfolder, "PCbuild", build_subdir_lut[str(self.settings.arch)]) + return os.path.join(self.source_folder, "PCbuild", build_subdir_lut[str(self.settings.arch)]) @property def _msvc_install_subprefix(self): return "bin" def _copy_essential_dlls(self): - if self.settings.compiler == "Visual Studio": + if is_msvc(self): # Until MSVC builds support cross building, copy dll's of essential (shared) dependencies to python binary location. # These dll's are required when running the layout tool using the newly built python executable. dest_path = os.path.join(self.build_folder, self._msvc_artifacts_path) - if self._with_libffi: - for bin_path in self.deps_cpp_info["libffi"].bin_paths: - self.copy("*.dll", src=bin_path, dst=dest_path) - for bin_path in self.deps_cpp_info["expat"].bin_paths: - self.copy("*.dll", src=bin_path, dst=dest_path) - for bin_path in self.deps_cpp_info["zlib"].bin_paths: - self.copy("*.dll", src=bin_path, dst=dest_path) + for bin_path in self.dependencies["libffi"].cpp_info.bindirs: + copy(self, "*.dll", src=bin_path, dst=dest_path) + for bin_path in self.dependencies["expat"].cpp_info.bindirs: + copy(self, "*.dll", src=bin_path, dst=dest_path) + for bin_path in self.dependencies["zlib"].cpp_info.bindirs: + copy(self, "*.dll", src=bin_path, dst=dest_path) def _msvc_package_layout(self): self._copy_essential_dlls() install_prefix = os.path.join(self.package_folder, self._msvc_install_subprefix) - tools.mkdir(install_prefix) + mkdir(self, install_prefix) build_path = self._msvc_artifacts_path infix = "_d" if self.settings.build_type == "Debug" else "" # FIXME: if cross building, use a build python executable here - python_built = os.path.join(build_path, "python{}.exe".format(infix)) + python_built = os.path.join(build_path, f"python{infix}.exe") layout_args = [ - os.path.join(self._source_subfolder, "PC", "layout", "main.py"), + os.path.join(self.source_folder, "PC", "layout", "main.py"), "-v", - "-s", self._source_subfolder, + "-s", self.source_folder, "-b", build_path, "--copy", install_prefix, "-p", @@ -481,16 +457,12 @@ def _msvc_package_layout(self): layout_args.append("--include-tcltk") if self.settings.build_type == "Debug": layout_args.append("-d") - python_args = " ".join("\"{}\"".format(a) for a in layout_args) - self.run("{} {}".format(python_built, python_args), run_environment=True) + python_args = " ".join(f'"{a}"' for a in layout_args) + self.run(f"{python_built} {python_args}") - tools.rmdir(os.path.join(self.package_folder, "bin", "tcl")) + rmdir(self, os.path.join(self.package_folder, "bin", "tcl")) - for file in os.listdir(install_prefix): - if re.match("vcruntime.*", file): - os.unlink(os.path.join(install_prefix, file)) - continue - os.unlink(os.path.join(install_prefix, "LICENSE.txt")) + rm(self, "LICENSE.txt", install_prefix) for file in os.listdir(os.path.join(install_prefix, "libs")): if not re.match("python.*", file): os.unlink(os.path.join(install_prefix, "libs", file)) @@ -498,45 +470,61 @@ def _msvc_package_layout(self): def _msvc_package_copy(self): build_path = self._msvc_artifacts_path infix = "_d" if self.settings.build_type == "Debug" else "" - self.copy("*.exe", src=build_path, dst=os.path.join(self.package_folder, self._msvc_install_subprefix)) - self.copy("*.dll", src=build_path, dst=os.path.join(self.package_folder, self._msvc_install_subprefix)) - self.copy("*.pyd", src=build_path, dst=os.path.join(self.package_folder, self._msvc_install_subprefix, "DLLs")) - self.copy("python{}{}.lib".format(self._version_suffix, infix), src=build_path, dst=os.path.join(self.package_folder, self._msvc_install_subprefix, "libs")) - self.copy("*", src=os.path.join(self._source_subfolder, "Include"), dst=os.path.join(self.package_folder, self._msvc_install_subprefix, "include")) - self.copy("pyconfig.h", src=os.path.join(self._source_subfolder, "PC"), dst=os.path.join(self.package_folder, self._msvc_install_subprefix, "include")) - self.copy("*.py", src=os.path.join(self._source_subfolder, "lib"), dst=os.path.join(self.package_folder, self._msvc_install_subprefix, "Lib")) - tools.rmdir(os.path.join(self.package_folder, self._msvc_install_subprefix, "Lib", "test")) + copy(self, "*.exe", + src=build_path, + dst=os.path.join(self.package_folder, self._msvc_install_subprefix)) + copy(self, "*.dll", + src=build_path, + dst=os.path.join(self.package_folder, self._msvc_install_subprefix)) + copy(self, "*.pyd", + src=build_path, + dst=os.path.join(self.package_folder, self._msvc_install_subprefix, "DLLs")) + copy(self, f"python{self._version_suffix}{infix}.lib", + src=build_path, + dst=os.path.join(self.package_folder, self._msvc_install_subprefix, "libs")) + copy(self, "*", + src=os.path.join(self.source_folder, "Include"), + dst=os.path.join(self.package_folder, self._msvc_install_subprefix, "include")) + copy(self, "pyconfig.h", + src=os.path.join(self.source_folder, "PC"), + dst=os.path.join(self.package_folder, self._msvc_install_subprefix, "include")) + copy(self, "*.py", + src=os.path.join(self.source_folder, "lib"), + dst=os.path.join(self.package_folder, self._msvc_install_subprefix, "Lib")) + rmdir(self, os.path.join(self.package_folder, self._msvc_install_subprefix, "Lib", "test")) packages = {} get_name_version = lambda fn: fn.split(".", 2)[:2] - whldir = os.path.join(self._source_subfolder, "Lib", "ensurepip", "_bundled") + whldir = os.path.join(self.source_folder, "Lib", "ensurepip", "_bundled") for fn in filter(lambda n: n.endswith(".whl"), os.listdir(whldir)): name, version = get_name_version(fn) add = True if name in packages: pname, pversion = get_name_version(packages[name]) - add = tools.Version(version) > tools.Version(pversion) + add = Version(version) > Version(pversion) if add: packages[name] = fn for fname in packages.values(): - tools.unzip(filename=os.path.join(whldir, fname), destination=os.path.join(self.package_folder, "bin", "Lib", "site-packages")) + unzip(self, filename=os.path.join(whldir, fname), + destination=os.path.join(self.package_folder, "bin", "Lib", "site-packages")) - self.run("{} -c \"import compileall; compileall.compile_dir('{}')\"".format(os.path.join(build_path, self._cpython_interpreter_name), os.path.join(self.package_folder, self._msvc_install_subprefix, "Lib").replace("\\", "/")), - run_environment=True) + interpreter_path = os.path.join(build_path, self._cpython_interpreter_name) + lib_dir_path = os.path.join(self.package_folder, self._msvc_install_subprefix, "Lib").replace("\\", "/") + self.run(f"{interpreter_path} -c \"import compileall; compileall.compile_dir('{lib_dir_path}')\"") def package(self): - self.copy("LICENSE", src=self._source_subfolder, dst="licenses") - if self.settings.compiler == "Visual Studio": - if self._is_py2 or not self.options.shared: - self._msvc_package_copy() - else: + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + if is_msvc(self): + if self.options.shared: self._msvc_package_layout() - tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "vcruntime*") + else: + self._msvc_package_copy() + rm(self, "vcruntime*", os.path.join(self.package_folder, "bin"), recursive=True) else: - autotools = self._configure_autotools() - autotools.install() - tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) - tools.rmdir(os.path.join(self.package_folder, "share")) + autotools = Autotools(self) + autotools.install(args=["DESTDIR="]) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "share")) # Rewrite shebangs of python scripts for filename in os.listdir(os.path.join(self.package_folder, "bin")): @@ -550,23 +538,23 @@ def package(self): if not(firstline.startswith(b"#!") and b"/python" in firstline and b"/bin/sh" not in firstline): continue text = fn.read() - self.output.info("Rewriting shebang of {}".format(filename)) + self.output.info(f"Rewriting shebang of {filename}") with open(filepath, "wb") as fn: - fn.write(textwrap.dedent("""\ + fn.write(textwrap.dedent(f"""\ #!/bin/sh ''':' __file__="$0" while [ -L "$__file__" ]; do __file__="$(dirname "$__file__")/$(readlink "$__file__")" done - exec "$(dirname "$__file__")/python{}" "$0" "$@" + exec "$(dirname "$__file__")/python{self._version_suffix}" "$0" "$@" ''' - """.format(self._version_suffix)).encode()) + """).encode()) fn.write(text) if not os.path.exists(self._cpython_symlink): - os.symlink("python{}".format(self._version_suffix), self._cpython_symlink) - self._fix_install_name() + os.symlink(f"python{self._version_suffix}", self._cpython_symlink) + fix_apple_shared_install_name(self) @property def _cpython_symlink(self): @@ -577,14 +565,12 @@ def _cpython_symlink(self): @property def _cpython_interpreter_name(self): - if self.settings.compiler == "Visual Studio": - suffix = "" - else: - suffix = self._version_suffix - python = "python{}".format(suffix) - if self.settings.compiler == "Visual Studio": + python = "python" + if is_msvc(self): if self.settings.build_type == "Debug": python += "_d" + else: + python += self._version_suffix if self.settings.os == "Windows": python += ".exe" return python @@ -596,80 +582,71 @@ def _cpython_interpreter_path(self): @property def _abi_suffix(self): res = "" - if self._is_py3: - if self.settings.build_type == "Debug": - res += "d" - if tools.Version(self._version_number_only) < "3.8": - if self.options.get_safe("pymalloc", False): - res += "m" + if self.settings.build_type == "Debug": + res += "d" return res @property def _lib_name(self): - if self.settings.compiler == "Visual Studio": + if is_msvc(self): if self.settings.build_type == "Debug": lib_ext = "_d" else: lib_ext = "" else: - lib_ext = self._abi_suffix + (".dll.a" if self.options.shared and self.settings.os == "Windows" else "") - return "python{}{}".format(self._version_suffix, lib_ext) - - def _fix_install_name(self): - if tools.is_apple_os(self.settings.os) and self.options.shared: - buffer = StringIO() - python = os.path.join(self.package_folder, "bin", "python") - self.run('otool -L "%s"' % python, output=buffer) - lines = buffer.getvalue().strip().split('\n')[1:] - for line in lines: - library = line.split()[0] - if library.startswith(self.package_folder): - new = library.replace(self.package_folder, "@executable_path/..") - self.output.info("patching {}, replace {} with {}".format(python, library, new)) - self.run("install_name_tool -change {} {} {}".format(library, new, python)) + lib_ext = self._abi_suffix + ( + ".dll.a" if self.options.shared and self.settings.os == "Windows" else "" + ) + return f"python{self._version_suffix}{lib_ext}" def package_info(self): # FIXME: conan components Python::Interpreter component, need a target type # self.cpp_info.names["cmake_find_package"] = "Python" # self.cpp_info.names["cmake_find_package_multi"] = "Python" - # FIXME: conan components need to generate multiple .pc files (python2, python-27) - py_version = tools.Version(self._version_number_only) + py_version = Version(self.version) # python component: "Build a C extension for Python" - if self.settings.compiler == "Visual Studio": + if is_msvc(self): self.cpp_info.components["python"].includedirs = [os.path.join(self._msvc_install_subprefix, "include")] libdir = os.path.join(self._msvc_install_subprefix, "libs") else: - self.cpp_info.components["python"].includedirs.append(os.path.join("include", "python{}{}".format(self._version_suffix, self._abi_suffix))) + self.cpp_info.components["python"].includedirs.append( + os.path.join("include", f"python{self._version_suffix}{self._abi_suffix}") + ) libdir = "lib" if self.options.shared: self.cpp_info.components["python"].defines.append("Py_ENABLE_SHARED") else: self.cpp_info.components["python"].defines.append("Py_NO_ENABLE_SHARED") - if self.settings.os == "Linux": + if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.components["python"].system_libs.extend(["dl", "m", "pthread", "util"]) elif self.settings.os == "Windows": - self.cpp_info.components["python"].system_libs.extend(["pathcch", "shlwapi", "version", "ws2_32"]) + self.cpp_info.components["python"].system_libs.extend( + ["pathcch", "shlwapi", "version", "ws2_32"] + ) self.cpp_info.components["python"].requires = ["zlib::zlib"] if self.settings.os != "Windows": self.cpp_info.components["python"].requires.append("libxcrypt::libxcrypt") - self.cpp_info.components["python"].names["pkg_config"] = "python-{}.{}".format(py_version.major, py_version.minor) + self.cpp_info.components["python"].set_property( + "pkg_config_name", f"python-{py_version.major}.{py_version.minor}" + ) + self.cpp_info.components["python"].set_property( + "pkg_config_aliases", f"python{py_version.major}" + ) self.cpp_info.components["python"].libdirs = [] - self.cpp_info.components["_python_copy"].names["pkg_config"] = "python{}".format(py_version.major) - self.cpp_info.components["_python_copy"].requires = ["python"] - self.cpp_info.components["_python_copy"].libdirs = [] - # embed component: "Embed Python into an application" self.cpp_info.components["embed"].libs = [self._lib_name] self.cpp_info.components["embed"].libdirs = [libdir] - self.cpp_info.components["embed"].names["pkg_config"] = "python-{}.{}-embed".format(py_version.major, py_version.minor) + self.cpp_info.components["embed"].includedirs = [] + self.cpp_info.components["embed"].set_property( + "pkg_config_name", f"python-{py_version.major}.{py_version.minor}-embed" + ) + self.cpp_info.components["embed"].set_property( + "pkg_config_aliases", f"python{py_version.major}-embed" + ) self.cpp_info.components["embed"].requires = ["python"] - self.cpp_info.components["_embed_copy"].requires = ["embed"] - self.cpp_info.components["_embed_copy"].names["pkg_config"] = ["python{}-embed".format(py_version.major)] - self.cpp_info.components["_embed_copy"].libdirs = [] - if self._supports_modules: # hidden components: the C extensions of python are built as dynamically loaded shared libraries. # C extensions or applications with an embedded Python should not need to link to them.. @@ -677,12 +654,11 @@ def package_info(self): "openssl::openssl", "expat::expat", "mpdecimal::mpdecimal", + "libffi::libffi", ] - if self._with_libffi: - self.cpp_info.components["_hidden"].requires.append("libffi::libffi") if self.settings.os != "Windows": - if not tools.is_apple_os(self.settings.os): - self.cpp_info.components["_hidden"].requires.append("libuuid::libuuid") + if not is_apple_os(self): + self.cpp_info.components["_hidden"].requires.append("util-linux-libuuid::util-linux-libuuid") self.cpp_info.components["_hidden"].requires.append("libxcrypt::libxcrypt") if self.options.with_bz2: self.cpp_info.components["_hidden"].requires.append("bzip2::bzip2") @@ -692,47 +668,68 @@ def package_info(self): self.cpp_info.components["_hidden"].requires.append("sqlite3::sqlite3") if self.options.get_safe("with_curses", False): self.cpp_info.components["_hidden"].requires.append("ncurses::ncurses") - if self.options.get_safe("with_bsddb"): - self.cpp_info.components["_hidden"].requires.append("libdb::libdb") if self.options.get_safe("with_lzma"): self.cpp_info.components["_hidden"].requires.append("xz_utils::xz_utils") if self.options.get_safe("with_tkinter"): self.cpp_info.components["_hidden"].requires.append("tk::tk") + self.cpp_info.components["_hidden"].includedirs = [] self.cpp_info.components["_hidden"].libdirs = [] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["_hidden"].system_libs.append("nsl") if self.options.env_vars: bindir = os.path.join(self.package_folder, "bin") - self.output.info("Appending PATH environment variable: {}".format(bindir)) + self.runenv_info.append_path("PATH", bindir) + self.buildenv_info.append_path("PATH", bindir) + + # TODO remove once Conan 1.x is no longer supported + self.output.info(f"Appending PATH environment variable: {bindir}") self.env_info.PATH.append(bindir) python = self._cpython_interpreter_path + self.conf_info.define("user.cpython:python", python) self.user_info.python = python if self.options.env_vars: - self.output.info("Setting PYTHON environment variable: {}".format(python)) + self.runenv_info.append_path("PYTHON", python) + self.buildenv_info.append_path("PYTHON", python) + + # TODO remove once Conan 1.x is no longer supported + self.output.info(f"Appending PYTHON environment variable: {python}") self.env_info.PYTHON = python - if self.settings.compiler == "Visual Studio": + if is_msvc(self): pythonhome = os.path.join(self.package_folder, "bin") - elif tools.is_apple_os(self.settings.os): - pythonhome = self.package_folder else: - version = tools.Version(self._version_number_only) - pythonhome = os.path.join(self.package_folder, "lib", "python{}.{}".format(version.major, version.minor)) + pythonhome = self.package_folder + self.conf_info.define("user.cpython:pythonhome", pythonhome) self.user_info.pythonhome = pythonhome - pythonhome_required = self.settings.compiler == "Visual Studio" or tools.is_apple_os(self.settings.os) + pythonhome_required = is_msvc(self) or is_apple_os(self) + self.conf_info.define("user.cpython:module_requires_pythonhome", pythonhome_required) self.user_info.module_requires_pythonhome = pythonhome_required - if self.settings.compiler == "Visual Studio": + if is_msvc(self): if self.options.env_vars: - self.output.info("Setting PYTHONHOME environment variable: {}".format(pythonhome)) + # FIXME: On Windows, defining this breaks the packaged Python executable, but fixes + # separately built executables with an embedded interpreter trying to run standard Python + # modules. However, NOT defining this reverses the situation, normal Python executables + #work, but embedded interpreters break. + # The docs at https://python.readthedocs.io/en/latest/using/cmdline.html#envvar-PYTHONHOME + # seem to not be accurate to Windows (https://discuss.python.org/t/the-document-on-pythonhome-might-be-wrong/19614/5) + #self.runenv_info.append_path("PYTHONHOME", pythonhome) + #self.buildenv_info.append_path("PYTHONHOME", pythonhome) + + # TODO remove once Conan 1.x is no longer supported + self.output.info(f"Setting PYTHONHOME environment variable: {pythonhome}") self.env_info.PYTHONHOME = pythonhome - if self._is_py2: - python_root = "" - else: - python_root = self.package_folder - if self.options.env_vars: - self.output.info("Setting PYTHON_ROOT environment variable: {}".format(python_root)) - self.env_info.PYTHON_ROOT = python_root + python_root = self.package_folder + if self.options.env_vars: + self.runenv_info.append_path("PYTHON_ROOT", python_root) + self.buildenv_info.append_path("PYTHON_ROOT", python_root) + + # TODO remove once Conan 1.x is no longer supported + self.output.info(f"Setting PYTHON_ROOT environment variable: {python_root}") + self.env_info.PYTHON_ROOT = python_root + self.conf_info.define("user.cpython:python_root", python_root) self.user_info.python_root = python_root diff --git a/recipes/cpython/all/patches/2.7.18-0001-msvc.patch b/recipes/cpython/all/patches/2.7.18-0001-msvc.patch deleted file mode 100644 index 2c101049df531..0000000000000 --- a/recipes/cpython/all/patches/2.7.18-0001-msvc.patch +++ /dev/null @@ -1,278 +0,0 @@ ---- PCbuild/_bsddb.vcxproj -+++ PCbuild/_bsddb.vcxproj -@@ -46,7 +46,7 @@ - NotSet - - -- -+ - - .pyd - -@@ -75,7 +75,7 @@ - - - -- -+ - - - ---- PCbuild/_hashlib.vcxproj -+++ PCbuild/_hashlib.vcxproj -@@ -45,7 +45,7 @@ - DynamicLibrary - NotSet - -- -+ - - .pyd - -@@ -64,7 +64,7 @@ - $(opensslIncludeDir);%(AdditionalIncludeDirectories) - - -- ws2_32.lib;$(OutDir)libeay$(PyDebugExt).lib;$(OutDir)ssleay$(PyDebugExt).lib;%(AdditionalDependencies) -+ ws2_32.lib;%(AdditionalDependencies) - - - -@@ -75,14 +75,14 @@ - {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} - false - -- -+ - - - ---- PCbuild/_sqlite3.vcxproj -+++ PCbuild/_sqlite3.vcxproj -@@ -45,7 +45,7 @@ - DynamicLibrary - NotSet - -- -+ - - .pyd - -@@ -96,10 +96,10 @@ - {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} - false - -- -+ - - - ---- PCbuild/_ssl.vcxproj -+++ PCbuild/_ssl.vcxproj -@@ -45,7 +45,7 @@ - DynamicLibrary - NotSet - -- -+ - - .pyd - -@@ -64,7 +64,7 @@ - $(opensslIncludeDir);%(AdditionalIncludeDirectories) - - -- ws2_32.lib;crypt32.lib;$(OutDir)libeay$(PyDebugExt).lib;$(OutDir)ssleay$(PyDebugExt).lib;%(AdditionalDependencies) -+ ws2_32.lib;crypt32.lib;%(AdditionalDependencies) - - - -@@ -75,14 +75,14 @@ - {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} - false - -- -+ - - {86937f53-c189-40ef-8ce8-8759d8e7d480} - false ---- PCbuild/bz2.vcxproj -+++ PCbuild/bz2.vcxproj -@@ -47,7 +47,7 @@ - NotSet - - -- -+ - - .pyd - -@@ -72,13 +72,13 @@ - - - -- -+ - - - ---- PCbuild/_elementtree.vcxproj -+++ PCbuild/_elementtree.vcxproj -@@ -45,7 +45,7 @@ - DynamicLibrary - NotSet - -- -+ - - .pyd - -@@ -61,15 +61,15 @@ - - - -- ..\Modules\expat;%(AdditionalIncludeDirectories) -- _CRT_SECURE_NO_WARNINGS;USE_PYEXPAT_CAPI;XML_STATIC;%(PreprocessorDefinitions) -+ %(AdditionalIncludeDirectories) -+ _CRT_SECURE_NO_WARNINGS;USE_PYEXPAT_CAPI;%(PreprocessorDefinitions) - - - 0x1D100000 - - - -- -+ - - - -- -+ - - - ---- PCbuild/pyexpat.vcxproj -+++ PCbuild/pyexpat.vcxproj -@@ -45,7 +45,7 @@ - DynamicLibrary - NotSet - -- -+ - - .pyd - -@@ -58,19 +58,19 @@ - - - -- $(PySourcePath)Modules\expat;%(AdditionalIncludeDirectories) -- _CRT_SECURE_NO_WARNINGS;PYEXPAT_EXPORTS;XML_STATIC;%(PreprocessorDefinitions) -+ %(AdditionalIncludeDirectories) -+ _CRT_SECURE_NO_WARNINGS;PYEXPAT_EXPORTS;%(PreprocessorDefinitions) - - - -- -- -+ - - - -- -+ - - - ---- PCbuild/_tkinter.vcxproj -+++ PCbuild/_tkinter.vcxproj -@@ -45,7 +45,7 @@ - DynamicLibrary - NotSet - -- -+ - - .pyd - -@@ -61,11 +61,11 @@ - - - -- $(tcltkDir)include;%(AdditionalIncludeDirectories) -+ %(AdditionalIncludeDirectories) - WITH_APPINIT;%(PreprocessorDefinitions) - - -- $(tcltkLib);%(AdditionalDependencies) -+ %(AdditionalDependencies) - - - -@@ -77,12 +77,12 @@ - {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} - false - -- -+ - - - diff --git a/recipes/cpython/all/patches/2.7.18-0002-add-support-msvc-14.patch b/recipes/cpython/all/patches/2.7.18-0002-add-support-msvc-14.patch deleted file mode 100644 index 6034410d3d265..0000000000000 --- a/recipes/cpython/all/patches/2.7.18-0002-add-support-msvc-14.patch +++ /dev/null @@ -1,59 +0,0 @@ -Patches from https://bugs.python.org/issue30742 - ---- Modules/posixmodule.c -+++ Modules/posixmodule.c -@@ -563,7 +563,10 @@ typedef struct { - char osfile; - } my_ioinfo; - -+#if _MSC_VER < 1900 // MSVS2013 and lower (https://bugs.python.org/issue30742) - extern __declspec(dllimport) char * __pioinfo[]; -+#endif -+ - #define IOINFO_L2E 5 - #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E) - #define IOINFO_ARRAYS 64 -@@ -575,6 +578,7 @@ extern __declspec(dllimport) char * __pioinfo[]; - int - _PyVerify_fd(int fd) - { -+#if _MSC_VER < 1900 // MSVS2013 and lower (https://bugs.python.org/issue30742) - const int i1 = fd >> IOINFO_L2E; - const int i2 = fd & ((1 << IOINFO_L2E) - 1); - -@@ -607,6 +611,13 @@ _PyVerify_fd(int fd) - fail: - errno = EBADF; - return 0; -+#else -+ //a call to _get_osfhandle with invalid fd sets errno to EBADF -+ if (_get_osfhandle(fd) == INVALID_HANDLE_VALUE) -+ return 0; -+ else -+ return 1; -+#endif - } - - /* the special case of checking dup2. The target fd must be in a sensible range */ ---- Modules/timemodule.c -+++ Modules/timemodule.c -@@ -803,7 +803,18 @@ inittimezone(PyObject *m) { - - And I'm lazy and hate C so nyer. - */ --#if defined(HAVE_TZNAME) && !defined(__GLIBC__) && !defined(__CYGWIN__) -+#if defined(HAVE_TZNAME) && (_MSC_VER >= 1900) //MSVS2015+ (https://bugs.python.org/issue30742) -+ tzset(); -+ PyModule_AddIntConstant(m, "timezone", _timezone); -+#ifdef HAVE_ALTZONE -+ PyModule_AddIntConstant(m, "altzone", altzone); -+#else -+ PyModule_AddIntConstant(m, "altzone", _timezone - 3600); -+#endif -+ PyModule_AddIntConstant(m, "daylight", _daylight); -+ PyModule_AddObject(m, "tzname", -+ Py_BuildValue("(zz)", _tzname[0], _tzname[1])); -+#elif defined(HAVE_TZNAME) && !defined(__GLIBC__) && !defined(__CYGWIN__) - tzset(); - #ifdef PYOS_OS2 - PyModule_AddIntConstant(m, "timezone", _timezone); diff --git a/recipes/cpython/all/patches/2.7.18-0003-msvc-fix-static.patch b/recipes/cpython/all/patches/2.7.18-0003-msvc-fix-static.patch deleted file mode 100644 index 9eb079402733d..0000000000000 --- a/recipes/cpython/all/patches/2.7.18-0003-msvc-fix-static.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- PC/dl_nt.c -+++ PC/dl_nt.c -@@ -107,5 +107,7 @@ - } - return TRUE; - } -- -+#else -+ULONG_PTR _Py_ActivateActCtx() { return 0; } -+void _Py_DeactivateActCtx(ULONG_PTR cookie) {} - #endif /* Py_ENABLE_SHARED */ diff --git a/recipes/cpython/all/patches/2.7.18-0004-disable-macos-tcltk.patch b/recipes/cpython/all/patches/2.7.18-0004-disable-macos-tcltk.patch deleted file mode 100644 index 5c61acd74bd5c..0000000000000 --- a/recipes/cpython/all/patches/2.7.18-0004-disable-macos-tcltk.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- setup.py -+++ setup.py -@@ -1928,9 +1928,9 @@ - # Rather than complicate the code below, detecting and building - # AquaTk is a separate method. Only one Tkinter will be built on - # Darwin - either AquaTk, if it is found, or X11 based Tk. -- if (host_platform == 'darwin' and -- self.detect_tkinter_darwin(inc_dirs, lib_dirs)): -- return -+ #if (host_platform == 'darwin' and -+ # self.detect_tkinter_darwin(inc_dirs, lib_dirs)): -+ # return - - # Assume we haven't found any of the libraries or include files - # The versions with dots are used on Unix, and the versions without diff --git a/recipes/cpython/all/patches/3.10.0-0001-msvc.patch b/recipes/cpython/all/patches/3.10/3.10.0-0001-msvc.patch similarity index 94% rename from recipes/cpython/all/patches/3.10.0-0001-msvc.patch rename to recipes/cpython/all/patches/3.10/3.10.0-0001-msvc.patch index e9b1faf061f3b..9884e12e53f1e 100644 --- a/recipes/cpython/all/patches/3.10.0-0001-msvc.patch +++ b/recipes/cpython/all/patches/3.10/3.10.0-0001-msvc.patch @@ -26,7 +26,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -59,7 +59,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -88,7 +88,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -146,7 +146,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -180,7 +180,7 @@ +++ PCbuild/_sqlite3.vcxproj @@ -74,1 +74,1 @@ - -+ ++ @@ -129,4 +129,4 @@ - + ---- PCbuild/_freeze_importlib.vcxproj -+++ PCbuild/_freeze_importlib.vcxproj -@@ -110,1 +110,1 @@ -- -+ --> ---- PCbuild/_bz2.vcxproj -+++ PCbuild/_bz2.vcxproj -@@ -39,7 +39,7 @@ - bz2 - Win32Proj - -- -+ - - - DynamicLibrary -@@ -69,17 +69,17 @@ - - - -- -+ - - -- -- -+ - - - ---- PCbuild/_decimal.vcxproj -+++ PCbuild/_decimal.vcxproj -@@ -39,7 +39,7 @@ - _decimal - Win32Proj - -- -+ - - - DynamicLibrary -@@ -64,11 +64,11 @@ - _CRT_SECURE_NO_WARNINGS;MASM;%(PreprocessorDefinitions) - CONFIG_32;PPRO;%(PreprocessorDefinitions) - CONFIG_64;%(PreprocessorDefinitions) -- ..\Modules\_decimal;..\Modules\_decimal\libmpdec;%(AdditionalIncludeDirectories) -+ ..\Modules\_decimal;%(AdditionalIncludeDirectories) - - - -- -+ - - - -- -+ - - -- -+ - - - ---- PCbuild/_elementtree.vcxproj -+++ PCbuild/_elementtree.vcxproj -@@ -39,7 +39,7 @@ - _elementtree - Win32Proj - -- -+ - - - DynamicLibrary -@@ -65,8 +65,8 @@ -- _CRT_SECURE_NO_WARNINGS;USE_PYEXPAT_CAPI;XML_STATIC;%(PreprocessorDefinitions) -+ _CRT_SECURE_NO_WARNINGS;USE_PYEXPAT_CAPI;%(PreprocessorDefinitions) - - - -- -+ - - - -- -+ - - - ---- PCbuild/_lzma.vcxproj -+++ PCbuild/_lzma.vcxproj -@@ -39,7 +39,7 @@ - lzma - Win32Proj - -- -+ - - - DynamicLibrary -@@ -62,10 +62,10 @@ - - - $(lzmaDir)src/liblzma/api;%(AdditionalIncludeDirectories) -- WIN32;_FILE_OFFSET_BITS=64;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;LZMA_API_STATIC;%(PreprocessorDefinitions) -+ $(ConanPreprocessorDefinitions);WIN32;_FILE_OFFSET_BITS=64;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;LZMA_API_STATIC;%(PreprocessorDefinitions) - - -- $(OutDir)liblzma$(PyDebugExt).lib;%(AdditionalDependencies) -+ %(AdditionalDependencies) - - - -@@ -79,10 +79,10 @@ - {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} - false - -- -+ - - - ---- PCbuild/_sqlite3.vcxproj -+++ PCbuild/_sqlite3.vcxproj -@@ -39,7 +39,7 @@ - _sqlite3 - Win32Proj - -- -+ - - - DynamicLibrary -@@ -95,10 +95,10 @@ - {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} - false - -- -+ - - - ---- PCbuild/openssl.vcxproj -+++ PCbuild/openssl.vcxproj -@@ -74,6 +74,6 @@ nmake - - - -- -+ - - - ---- PCbuild/pyexpat.vcxproj -+++ PCbuild/pyexpat.vcxproj -@@ -39,7 +39,7 @@ - {D06B6426-4762-44CC-8BAD-D79052507F2F} - pyexpat - -- -+ - - - DynamicLibrary -@@ -58,19 +58,19 @@ - - - -- $(PySourcePath)Modules\expat;%(AdditionalIncludeDirectories) -- _CRT_SECURE_NO_WARNINGS;PYEXPAT_EXPORTS;HAVE_EXPAT_H;XML_STATIC;%(PreprocessorDefinitions) -+ %(AdditionalIncludeDirectories) -+ _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - -- -- -+ - - - -- -+ - - - ---- PCbuild/pythoncore.vcxproj -+++ PCbuild/pythoncore.vcxproj -@@ -38,7 +38,7 @@ - {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} - pythoncore - -- -+ - - - DynamicLibrary -@@ -215,7 +215,7 @@ - - - -- -+ - - - -@@ -409,7 +409,7 @@ - - - -- -+ - - - ---- PCbuild/_hashlib.vcxproj -+++ PCbuild/_hashlib.vcxproj -@@ -39,7 +39,7 @@ - _hashlib - Win32Proj - -- -+ - - - DynamicLibrary -@@ -54,7 +54,7 @@ - - - -- -+ - - - ---- PCbuild/_ssl.vcxproj -+++ PCbuild/_ssl.vcxproj -@@ -39,7 +39,7 @@ - _ssl - Win32Proj - -- -+ - - - DynamicLibrary -@@ -54,7 +54,7 @@ - - - -- -+ - - - -@@ -67,9 +67,9 @@ - - - -- -+ - - - ---- PCbuild/_tkinter.vcxproj -+++ PCbuild/_tkinter.vcxproj -@@ -45,7 +45,7 @@ - DynamicLibrary - NotSet - -- -+ - - .pyd - -@@ -61,12 +61,12 @@ - - - -- $(tcltkDir)include;%(AdditionalIncludeDirectories) -+ %(AdditionalIncludeDirectories) - WITH_APPINIT;%(PreprocessorDefinitions) -- Py_TCLTK_DIR="$(tcltkDir.TrimEnd('\').Replace('\', '\\'))";%(PreprocessorDefinitions) -+ - - -- $(tcltkLib);%(AdditionalDependencies) -+ %(AdditionalDependencies) - - - -@@ -76,10 +76,10 @@ - - - -- -+ - - - {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} ---- PCbuild/pcbuild.sln -+++ PCbuild/pcbuild.sln -@@ -9,9 +9,6 @@ - EndProjectSection - EndProject - Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "python", "python.vcxproj", "{B11D750F-CD1F-4A96-85CE-E69A5C5259F9}" -- ProjectSection(ProjectDependencies) = postProject -- {0E9791DB-593A-465F-98BC-681011311618} = {0E9791DB-593A-465F-98BC-681011311618} -- EndProjectSection - EndProject - Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythoncore", "pythoncore.vcxproj", "{CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26}" - EndProject diff --git a/recipes/cpython/all/patches/3.7.9-0002-setup.py-pass-CFLAGS-CPPFLAGS.patch b/recipes/cpython/all/patches/3.7.9-0002-setup.py-pass-CFLAGS-CPPFLAGS.patch deleted file mode 100644 index 92e44c8ea6ee5..0000000000000 --- a/recipes/cpython/all/patches/3.7.9-0002-setup.py-pass-CFLAGS-CPPFLAGS.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- Makefile.pre.in -+++ Makefile.pre.in -@@ -618,10 +618,10 @@ - *\ -s*|s*) quiet="-q";; \ - *) quiet="";; \ - esac; \ -- echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ -+ echo "$(RUNSHARED) CC='$(CC) $(CONFIGURE_CFLAGS) $(CONFIGURE_CPPFLAGS)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ - _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ - $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build"; \ -- $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ -+ $(RUNSHARED) CC='$(CC) $(CONFIGURE_CFLAGS) $(CONFIGURE_CPPFLAGS)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ - _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ - $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build - diff --git a/recipes/cpython/all/patches/3.7.9-0003-disable-macos-tcltk.patch b/recipes/cpython/all/patches/3.7.9-0003-disable-macos-tcltk.patch deleted file mode 100644 index f5ffba2f61232..0000000000000 --- a/recipes/cpython/all/patches/3.7.9-0003-disable-macos-tcltk.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- setup.py -+++ setup.py -@@ -1829,9 +1829,9 @@ - # Rather than complicate the code below, detecting and building - # AquaTk is a separate method. Only one Tkinter will be built on - # Darwin - either AquaTk, if it is found, or X11 based Tk. -- if (host_platform == 'darwin' and -- self.detect_tkinter_darwin(inc_dirs, lib_dirs)): -- return -+ #if (host_platform == 'darwin' and -+ # self.detect_tkinter_darwin(inc_dirs, lib_dirs)): -+ # return - - # Assume we haven't found any of the libraries or include files - # The versions with dots are used on Unix, and the versions without diff --git a/recipes/cpython/all/patches/3.8.12-0001-msvc.patch b/recipes/cpython/all/patches/3.8/3.8.12-0001-msvc.patch similarity index 95% rename from recipes/cpython/all/patches/3.8.12-0001-msvc.patch rename to recipes/cpython/all/patches/3.8/3.8.12-0001-msvc.patch index 4e390810d2dde..3e4f2d86c5335 100644 --- a/recipes/cpython/all/patches/3.8.12-0001-msvc.patch +++ b/recipes/cpython/all/patches/3.8/3.8.12-0001-msvc.patch @@ -26,7 +26,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -59,7 +59,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -88,7 +88,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -145,7 +145,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -182,7 +182,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -206,7 +206,7 @@ pythoncore - -+ ++ DynamicLibrary @@ -253,7 +253,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -273,7 +273,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -305,7 +305,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -349,7 +349,7 @@ pyexpat - -+ ++ DynamicLibrary @@ -384,7 +384,7 @@ NotSet - -+ ++ .pyd diff --git a/recipes/cpython/all/patches/3.8.12-0002-_ctypes-ffi.patch b/recipes/cpython/all/patches/3.8/3.8.12-0002-_ctypes-ffi.patch similarity index 100% rename from recipes/cpython/all/patches/3.8.12-0002-_ctypes-ffi.patch rename to recipes/cpython/all/patches/3.8/3.8.12-0002-_ctypes-ffi.patch diff --git a/recipes/cpython/all/patches/3.8.12-0003-setup.py-pass-CFLAGS-CPPFLAGS.patch b/recipes/cpython/all/patches/3.8/3.8.12-0003-setup.py-pass-CFLAGS-CPPFLAGS.patch similarity index 100% rename from recipes/cpython/all/patches/3.8.12-0003-setup.py-pass-CFLAGS-CPPFLAGS.patch rename to recipes/cpython/all/patches/3.8/3.8.12-0003-setup.py-pass-CFLAGS-CPPFLAGS.patch diff --git a/recipes/cpython/all/patches/3.8.12-0004-disable-macos-tcltk.patch b/recipes/cpython/all/patches/3.8/3.8.12-0004-disable-macos-tcltk.patch similarity index 100% rename from recipes/cpython/all/patches/3.8.12-0004-disable-macos-tcltk.patch rename to recipes/cpython/all/patches/3.8/3.8.12-0004-disable-macos-tcltk.patch diff --git a/recipes/cpython/all/patches/3.9.7-0001-msvc.patch b/recipes/cpython/all/patches/3.9/3.9.7-0001-msvc.patch similarity index 95% rename from recipes/cpython/all/patches/3.9.7-0001-msvc.patch rename to recipes/cpython/all/patches/3.9/3.9.7-0001-msvc.patch index fac9247123880..0c65a84205152 100644 --- a/recipes/cpython/all/patches/3.9.7-0001-msvc.patch +++ b/recipes/cpython/all/patches/3.9/3.9.7-0001-msvc.patch @@ -26,7 +26,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -59,7 +59,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -88,7 +88,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -146,7 +146,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -183,7 +183,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -207,7 +207,7 @@ pythoncore - -+ ++ DynamicLibrary @@ -254,7 +254,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -274,7 +274,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -306,7 +306,7 @@ Win32Proj - -+ ++ DynamicLibrary @@ -350,7 +350,7 @@ pyexpat - -+ ++ DynamicLibrary @@ -387,7 +387,7 @@ NotSet - -+ ++ .pyd diff --git a/recipes/cpython/all/patches/3.9.7-0002-_msi-vcxproj.patch b/recipes/cpython/all/patches/3.9/3.9.7-0002-_msi-vcxproj.patch similarity index 100% rename from recipes/cpython/all/patches/3.9.7-0002-_msi-vcxproj.patch rename to recipes/cpython/all/patches/3.9/3.9.7-0002-_msi-vcxproj.patch diff --git a/recipes/cpython/all/patches/3.9.7-0003-_ctypes-ffi.patch b/recipes/cpython/all/patches/3.9/3.9.7-0003-_ctypes-ffi.patch similarity index 100% rename from recipes/cpython/all/patches/3.9.7-0003-_ctypes-ffi.patch rename to recipes/cpython/all/patches/3.9/3.9.7-0003-_ctypes-ffi.patch diff --git a/recipes/cpython/all/patches/3.9.7-0004-setup.py-pass-CFLAGS-CPPFLAGS.patch b/recipes/cpython/all/patches/3.9/3.9.7-0004-setup.py-pass-CFLAGS-CPPFLAGS.patch similarity index 100% rename from recipes/cpython/all/patches/3.9.7-0004-setup.py-pass-CFLAGS-CPPFLAGS.patch rename to recipes/cpython/all/patches/3.9/3.9.7-0004-setup.py-pass-CFLAGS-CPPFLAGS.patch diff --git a/recipes/cpython/all/patches/3.9.7-0005-disable-macos-tcltk.patch b/recipes/cpython/all/patches/3.9/3.9.7-0005-disable-macos-tcltk.patch similarity index 100% rename from recipes/cpython/all/patches/3.9.7-0005-disable-macos-tcltk.patch rename to recipes/cpython/all/patches/3.9/3.9.7-0005-disable-macos-tcltk.patch diff --git a/recipes/cpython/all/test_package/CMakeLists.txt b/recipes/cpython/all/test_package/CMakeLists.txt index 525329324757f..0d333d99af1e3 100644 --- a/recipes/cpython/all/test_package/CMakeLists.txt +++ b/recipes/cpython/all/test_package/CMakeLists.txt @@ -1,15 +1,19 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) project(test_package C) -include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") -conan_basic_setup() +find_package(cpython REQUIRED CONFIG) -set(CACHE PY_VERSION_MAJOR "" CACHE STRING "MAJOR version of python") -set(CACHE PY_VERSION_MAJOR_MINOR "" CACHE STRING "MAJOR.MINOR version of python") -set(CACHE PY_VERSION "" CACHE STRING "Required version of python") -set(CACHE PY_VERSION_SUFFIX "" CACHE STRING "Suffix of python") +# FIXME: We can't modify CMake's FindPython to link dependencies pulled by +# Conan, so here we just include them globally. This is mainly necessary for +# MacOS missing crypt.h, which is available at configure time (in the main recipe) +# but otherwise not at build time (in consumer packages). +link_libraries(cpython::python) -set(Python_ADDITIONAL_VERSIONS ${PY_VERSION}${PY_VERSION_SUFFIX} ${PY_VERSION_MAJOR_MINOR}${PY_VERSION_SUFFIX} ${PY_VERSION_MAJOR}${PY_VERSION_SUFFIX} ${PY_VERSION} ${PY_VERSION_MAJOR_MINOR} ${PY_VERSION_MAJOR}) +set(PY_VERSION_MAJOR_MINOR "" CACHE STRING "MAJOR.MINOR version of python") +set(PY_VERSION "" CACHE STRING "Required version of python") +set(PY_VERSION_SUFFIX "" CACHE STRING "Suffix of python") + +set(Python_ADDITIONAL_VERSIONS ${PY_VERSION}${PY_VERSION_SUFFIX} ${PY_VERSION_MAJOR_MINOR}${PY_VERSION_SUFFIX} 3${PY_VERSION_SUFFIX} ${PY_VERSION} ${PY_VERSION_MAJOR_MINOR} 3) message("Using Python_ADDITIONAL_VERSIONS: ${Python_ADDITIONAL_VERSIONS}") find_package(PythonInterp REQUIRED) @@ -22,7 +26,6 @@ endif() message(STATUS "FindPythonInterp:") message(STATUS "PYTHON_VERSION_STRING: ${PYTHON_VERSION_STRING}") -message(STATUS "PYTHON_VERSION_MAJOR: ${PYTHON_VERSION_MAJOR}") message(STATUS "PYTHON_VERSION_MINOR: ${PYTHON_VERSION_MINOR}") message(STATUS "PYTHON_VERSION_PATCH: ${PYTHON_VERSION_PATCH}") message(STATUS "=============================================") @@ -45,8 +48,8 @@ if(PYTHON_VERSION_STRING) endif() if(PYTHONLIBS_VERSION_STRING) - if(NOT PYTHONLIBS_VERSION_STRING STREQUAL "${PY_FULL_VERSION}") - message("PYTHONLIBS_VERSION_STRING does not match PY_FULL_VERSION") + if(NOT PYTHONLIBS_VERSION_STRING STREQUAL "${PY_VERSION}") + message("PYTHONLIBS_VERSION_STRING does not match PY_VERSION") message(FATAL_ERROR "CMake detected wrong cpython version") endif() endif() @@ -54,7 +57,7 @@ endif() option(BUILD_MODULE "Build python module") if(BUILD_MODULE) - add_library(spam MODULE "py${PY_VERSION_MAJOR}/test_module.c") + add_library(spam MODULE "test_module.c") target_include_directories(spam PRIVATE ${PYTHON_INCLUDE_DIRS} @@ -64,37 +67,29 @@ if(BUILD_MODULE) ) set_property(TARGET spam PROPERTY PREFIX "") if(MSVC) - if(CONAN_SETTINGS_BUILD_TYPE STREQUAL "Debug") - set(SUFFIX "_d.pyd") - else() - set(SUFFIX ".pyd") - endif() - set_property(TARGET spam PROPERTY SUFFIX "${SUFFIX}") + set_target_properties(spam PROPERTIES + DEBUG_POSTFIX "_d" + SUFFIX ".pyd" + ) endif() option(USE_FINDPYTHON_X "Use new-style FindPythonX module") - if(USE_FINDPYTHON_X AND NOT (CMAKE_VERSION VERSION_LESS "3.16")) - # Require CMake 3.16 because this version introduces Python${PY_VERSION_MAJOR}_FIND_ABI - find_package(Python${PY_VERSION_MAJOR} REQUIRED COMPONENTS Interpreter Development) - message("Python${PY_VERSION_MAJOR}_EXECUTABLE: ${Python${PY_VERSION_MAJOR}_EXECUTABLE}") - message("Python${PY_VERSION_MAJOR}_INTERPRETER_ID: ${Python${PY_VERSION_MAJOR}_INTERPRETER_ID}") - message("Python${PY_VERSION_MAJOR}_VERSION: ${Python${PY_VERSION_MAJOR}_VERSION}") - message("Python${PY_VERSION_MAJOR}_INCLUDE_DIRS: ${Python${PY_VERSION_MAJOR}_INCLUDE_DIRS}") - message("Python${PY_VERSION_MAJOR}_LIBRARIES: ${Python${PY_VERSION_MAJOR}_LIBRARIES}") - if(NOT Python${PY_VERSION_MAJOR}_VERSION STREQUAL "${PY_VERSION}") + if(USE_FINDPYTHON_X AND NOT CMAKE_VERSION VERSION_LESS "3.16") + # Require CMake 3.16 because this version introduces Python3_FIND_ABI + find_package(Python3 REQUIRED COMPONENTS Interpreter Development) + message("Python3_EXECUTABLE: ${Python3_EXECUTABLE}") + message("Python3_INTERPRETER_ID: ${Python3_INTERPRETER_ID}") + message("Python3_VERSION: ${Python3_VERSION}") + message("Python3_INCLUDE_DIRS: ${Python3_INCLUDE_DIRS}") + message("Python3_LIBRARIES: ${Python3_LIBRARIES}") + if(NOT Python3_VERSION STREQUAL "${PY_VERSION}") message("Python_ADDITIONAL_VERSIONS does not match PY_VERSION") message(FATAL_ERROR "CMake detected wrong cpython version") endif() - if(PY_VERSION_MAJOR STREQUAL "2") - python2_add_library(spam2 "py${PY_VERSION_MAJOR}/test_module.c") - elseif(PY_VERSION_MAJOR STREQUAL "3") - python3_add_library(spam2 "py${PY_VERSION_MAJOR}/test_module.c") - else() - message(FATAL_ERROR "Unknown PY_VERSION_MAJOR") - endif() + python3_add_library(spam2 "test_module.c") endif() endif() -add_executable(${PROJECT_NAME} "py${PY_VERSION_MAJOR}/test_package.c") -target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) +add_executable(${PROJECT_NAME} "test_package.c") +target_link_libraries(${PROJECT_NAME} PRIVATE cpython::embed) diff --git a/recipes/cpython/all/test_package/conanfile.py b/recipes/cpython/all/test_package/conanfile.py index 8abc18e4492c5..bca7c7fcfd3b7 100644 --- a/recipes/cpython/all/test_package/conanfile.py +++ b/recipes/cpython/all/test_package/conanfile.py @@ -1,192 +1,193 @@ -from conans import AutoToolsBuildEnvironment, ConanFile, CMake, tools, RunEnvironment -from conans.errors import ConanException -from io import StringIO import os -import re -import shutil - +from io import StringIO -class CmakePython3Abi(object): - def __init__(self, debug, pymalloc, unicode): - self.debug, self.pymalloc, self.unicode = debug, pymalloc, unicode +from conan import ConanFile, conan_version +from conan.errors import ConanException +from conan.tools.apple import is_apple_os +from conan.tools.build import can_run +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.env import Environment, VirtualRunEnv +from conan.tools.gnu import AutotoolsDeps +from conan.tools.microsoft import is_msvc, VCVars +from conan.tools.scm import Version - _cmake_lut = { - None: "ANY", - True: "ON", - False: "OFF", - } +conan2 = conan_version.major >= 2 - @property - def suffix(self): - return "{}{}{}".format( - "d" if self.debug else "", - "m" if self.pymalloc else "", - "u" if self.unicode else "", - ) +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + test_type = "explicit" - @property - def cmake_arg(self): - return ";".join(self._cmake_lut[a] for a in (self.debug, self.pymalloc, self.unicode)) + def requirements(self): + self.requires(self.tested_reference_str) + def build_requirements(self): + # The main recipe does not require CMake, but we test with it. + # The interesting problem that arises here is if you have CMake installed + # with your global pip, then it will fail to run in this test package. + # To avoid that, just add a requirement on CMake. + self.tool_requires("cmake/[>=3.15 <4]") -class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + def layout(self): + cmake_layout(self) @property - def _py_version(self): - return re.match(r"^([0-9.]+)", self.deps_cpp_info["cpython"].version).group(1) + def _python(self): + if conan2: + return self.dependencies["cpython"].conf_info.get("user.cpython:python", check_type=str) + else: + return self.deps_user_info["cpython"].python - @property - def _pymalloc(self): - return bool("pymalloc" in self.options["cpython"] and self.options["cpython"].pymalloc) + def _cpython_option(self, name): + if conan2: + return self.dependencies["cpython"].options.get_safe(name, False) + else: + try: + return getattr(self.options["cpython"], name, False) + except ConanException: + return False @property - def _cmake_abi(self): - if self._py_version < tools.Version("3.8"): - return CmakePython3Abi( - debug=self.settings.build_type == "Debug", - pymalloc=self._pymalloc, - unicode=False, - ) + def _py_version(self): + if conan2: + return Version(self.dependencies["cpython"].ref.version) else: - return CmakePython3Abi( - debug=self.settings.build_type == "Debug", - pymalloc=False, - unicode=False, - ) + return Version(self.deps_cpp_info["cpython"].version) @property def _cmake_try_FindPythonX(self): - if self.settings.compiler == "Visual Studio" and self.settings.build_type == "Debug": - return False - return True + return not is_msvc(self) or self.settings.build_type != "Debug" @property def _supports_modules(self): - return self.settings.compiler != "Visual Studio" or self.options["cpython"].shared + return not is_msvc(self) or self._cpython_option("shared") + + def generate(self): + tc = CMakeToolchain(self) + version = self._py_version + tc.cache_variables["BUILD_MODULE"] = self._supports_modules + tc.cache_variables["PY_VERSION_MAJOR_MINOR"] = f"{version.major}.{version.minor}" + tc.cache_variables["PY_VERSION"] = str(self._py_version) + tc.cache_variables["PY_VERSION_SUFFIX"] = "d" if self.settings.build_type == "Debug" else "" + tc.cache_variables["PYTHON_EXECUTABLE"] = self._python + tc.cache_variables["USE_FINDPYTHON_X"] = self._cmake_try_FindPythonX + tc.cache_variables["Python3_EXECUTABLE"] = self._python + tc.cache_variables["Python3_ROOT_DIR"] = self.dependencies["cpython"].package_folder + tc.cache_variables["Python3_USE_STATIC_LIBS"] = not self.dependencies["cpython"].options.shared + tc.cache_variables["Python3_FIND_FRAMEWORK"] = "NEVER" + tc.cache_variables["Python3_FIND_REGISTRY"] = "NEVER" + tc.cache_variables["Python3_FIND_IMPLEMENTATIONS"] = "CPython" + tc.cache_variables["Python3_FIND_STRATEGY"] = "LOCATION" + tc.generate() + + deps = CMakeDeps(self) + deps.generate() - def build(self): - if not tools.cross_building(self, skip_x64_x86=True): - command = "{} --version".format(self.deps_user_info["cpython"].python) - buffer = StringIO() - self.run(command, output=buffer, ignore_errors=True, run_environment=True) - self.output.info("output: %s" % buffer.getvalue()) - self.run(command, run_environment=True) + try: + # CMakeToolchain might generate VCVars, but we need it + # unconditionally for the setuptools build. + VCVars(self).generate() + except ConanException: + pass + # The build also needs access to the run environment to run the python executable + VirtualRunEnv(self).generate(scope="run") + VirtualRunEnv(self).generate(scope="build") + # Just for the distutils build + AutotoolsDeps(self).generate(scope="build") + + def build(self): cmake = CMake(self) - py_major = self.deps_cpp_info["cpython"].version.split(".")[0] - cmake.definitions["BUILD_MODULE"] = self._supports_modules - cmake.definitions["PY_VERSION_MAJOR"] = py_major - cmake.definitions["PY_VERSION_MAJOR_MINOR"] = ".".join(self._py_version.split(".")[:2]) - cmake.definitions["PY_FULL_VERSION"] = self.deps_cpp_info["cpython"].version - cmake.definitions["PY_VERSION"] = self._py_version - cmake.definitions["PY_VERSION_SUFFIX"] = self._cmake_abi.suffix - cmake.definitions["PYTHON_EXECUTABLE"] = self.deps_user_info["cpython"].python - cmake.definitions["USE_FINDPYTHON_X".format(py_major)] = self._cmake_try_FindPythonX - cmake.definitions["Python{}_EXECUTABLE".format(py_major)] = self.deps_user_info["cpython"].python - cmake.definitions["Python{}_ROOT_DIR".format(py_major)] = self.deps_cpp_info["cpython"].rootpath - cmake.definitions["Python{}_USE_STATIC_LIBS".format(py_major)] = not self.options["cpython"].shared - cmake.definitions["Python{}_FIND_FRAMEWORK".format(py_major)] = "NEVER" - cmake.definitions["Python{}_FIND_REGISTRY".format(py_major)] = "NEVER" - cmake.definitions["Python{}_FIND_IMPLEMENTATIONS".format(py_major)] = "CPython" - cmake.definitions["Python{}_FIND_STRATEGY".format(py_major)] = "LOCATION" - - if self.settings.compiler != "Visual Studio": - if tools.Version(self._py_version) < tools.Version("3.8"): - cmake.definitions["Python{}_FIND_ABI".format(py_major)] = self._cmake_abi.cmake_arg - - with tools.environment_append(RunEnvironment(self).vars): - cmake.configure() + cmake.configure() cmake.build() - if not tools.cross_building(self, skip_x64_x86=True): - if self._supports_modules: - with tools.vcvars(self.settings) if self.settings.compiler == "Visual Studio" else tools.no_op(): - modsrcfolder = "py2" if tools.Version(self.deps_cpp_info["cpython"].version).major < "3" else "py3" - tools.mkdir(os.path.join(self.build_folder, modsrcfolder)) - for fn in os.listdir(os.path.join(self.source_folder, modsrcfolder)): - shutil.copy(os.path.join(self.source_folder, modsrcfolder, fn), os.path.join(self.build_folder, modsrcfolder, fn)) - shutil.copy(os.path.join(self.source_folder, "setup.py"), os.path.join(self.build_folder, "setup.py")) - env = { - "DISTUTILS_USE_SDK": "1", - "MSSdk": "1" - } - env.update(**AutoToolsBuildEnvironment(self).vars) - with tools.environment_append(env): - setup_args = [ - "{}/setup.py".format(self.source_folder), - # "conan", - # "--install-folder", self.build_folder, - "build", - "--build-base", self.build_folder, - "--build-platlib", os.path.join(self.build_folder, "lib_setuptools"), - ] - if self.settings.build_type == "Debug": - setup_args.append("--debug") - self.run("{} {}".format(self.deps_user_info["cpython"].python, " ".join("\"{}\"".format(a) for a in setup_args)), run_environment=True) + if can_run(self) and self._supports_modules: + os.environ["DISTUTILS_USE_SDK"] = "1" + os.environ["MSSdk"] = "1" + setup_args = [ + os.path.join(self.source_folder, "setup.py"), + "build", + "--build-base", self.build_folder, + "--build-platlib", os.path.join(self.build_folder, "lib_setuptools"), + # Bandaid fix: setuptools places temporary files in a subdirectory of the build folder where the + # entirety of the absolute path up to this folder is appended (with seemingly no way to stop this), + # essentially doubling the path length. This may run into Windows max path lengths, so we give ourselves + # a little bit of wiggle room by making this directory name as short as possible. One of the directory + # names goes from (for example) "temp.win-amd64-3.10-pydebug" to "t", saving us roughly 25 characters. + "--build-temp", "t", + ] + if self.settings.build_type == "Debug": + setup_args.append("--debug") + args = " ".join(f'"{a}"' for a in setup_args) + self.run(f"{self._python} {args}") def _test_module(self, module, should_work): try: - self.run("{} {}/test_package.py -b {} -t {} ".format( - self.deps_user_info["cpython"].python, self.source_folder, self.build_folder, module), run_environment=True) - works = True - except ConanException as e: - works = False - exception = e - if should_work == works: - self.output.info("Result of test was expected.") - else: - if works: - raise ConanException("Module '{}' works, but should not have worked".format(module)) - else: - self.output.warn("Module '{}' does not work, but should have worked".format(module)) - raise exception - - def _cpython_option(self, name): - try: - return getattr(self.options["cpython"], name, False) + self.run(f"{self._python} {self.source_folder}/test_package.py -b {self.build_folder} -t {module}", env="conanrun") except ConanException: - return False + if should_work: + self.output.warning(f"Module '{module}' does not work, but should have worked") + raise + self.output.info("Module failed as expected") + return + if not should_work: + raise ConanException(f"Module '{module}' works, but should not have worked") + self.output.info("Module worked as expected") def test(self): - if not tools.cross_building(self, skip_x64_x86=True): - self.run("{} -c \"print('hello world')\"".format(self.deps_user_info["cpython"].python), run_environment=True) + if can_run(self): + self.run(f"{self._python} --version", env="conanrun") + + self.run(f"{self._python} -c \"print('hello world')\"", env="conanrun") buffer = StringIO() - self.run("{} -c \"import sys; print('.'.join(str(s) for s in sys.version_info[:3]))\"".format(self.deps_user_info["cpython"].python), run_environment=True, output=buffer) + self.run(f"{self._python} -c \"import sys; print('.'.join(str(s) for s in sys.version_info[:3]))\"", buffer, env="conanrun") self.output.info(buffer.getvalue()) version_detected = buffer.getvalue().splitlines()[-1].strip() if self._py_version != version_detected: - raise ConanException("python reported wrong version. Expected {exp}. Got {res}.".format(exp=self._py_version, res=version_detected)) + raise ConanException( + f"python reported wrong version. Expected {self._py_version}. Got {version_detected}." + ) if self._supports_modules: self._test_module("gdbm", self._cpython_option("with_gdbm")) self._test_module("bz2", self._cpython_option("with_bz2")) - self._test_module("bsddb", self._cpython_option("with_bsddb")) self._test_module("lzma", self._cpython_option("with_lzma")) self._test_module("tkinter", self._cpython_option("with_tkinter")) - with tools.environment_append({"TERM": "ansi"}): - self._test_module("curses", self._cpython_option("with_curses")) - + os.environ["TERM"] = "ansi" + self._test_module("curses", self._cpython_option("with_curses")) self._test_module("expat", True) - self._test_module("sqlite3", True) + self._test_module("sqlite3", self._cpython_option("with_sqlite3")) self._test_module("decimal", True) self._test_module("ctypes", True) - - if tools.is_apple_os(self.settings.os) and not self.options["cpython"].shared: - self.output.info("Not testing the module, because these seem not to work on apple when cpython is built as a static library") + env = Environment() + if self.settings.os != "Windows": + env.define_path("OPENSSL_CONF", os.path.join(os.sep, "dev", "null")) + with env.vars(self).apply(): + self._test_module("ssl", True) + + if is_apple_os(self) and not self._cpython_option("shared"): + self.output.info( + "Not testing the module, because these seem not to work on apple when cpython is built as" + " a static library" + ) # FIXME: find out why cpython on apple does not allow to use modules linked against a static python else: if self._supports_modules: - with tools.environment_append({"PYTHONPATH": [os.path.join(self.build_folder, "lib")]}): - self.output.info("Testing module (spam) using cmake built module") - self._test_module("spam", True) + os.environ["PYTHONPATH"] = os.path.join(self.build_folder, self.cpp.build.libdirs[0]) + self.output.info("Testing module (spam) using cmake built module") + self._test_module("spam", True) + + os.environ["PYTHONPATH"] = os.path.join(self.build_folder, "lib_setuptools") + self.output.info("Testing module (spam) using setup.py built module") + self._test_module("spam", True) - with tools.environment_append({"PYTHONPATH": [os.path.join(self.build_folder, "lib_setuptools")]}): - self.output.info("Testing module (spam) using setup.py built module") - self._test_module("spam", True) + del os.environ["PYTHONPATH"] - # MSVC builds need PYTHONHOME set. - with tools.environment_append({"PYTHONHOME": self.deps_user_info["cpython"].pythonhome}) if self.deps_user_info["cpython"].module_requires_pythonhome == "True" else tools.no_op(): - self.run(os.path.join("bin", "test_package"), run_environment=True) + # MSVC builds need PYTHONHOME set. Linux and Mac don't require it to be set if tested after building, + # but if the package is relocated then it needs to be set. + if conan2: + os.environ["PYTHONHOME"] = self.dependencies["cpython"].conf_info.get("user.cpython:pythonhome", check_type=str) + else: + os.environ["PYTHONHOME"] = self.deps_user_info["cpython"].pythonhome + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/cpython/all/test_package/py2/test_module.c b/recipes/cpython/all/test_package/py2/test_module.c deleted file mode 100644 index 9c5af39ab391b..0000000000000 --- a/recipes/cpython/all/test_package/py2/test_module.c +++ /dev/null @@ -1,42 +0,0 @@ -#include - -#include - -static PyObject *SpamError; - -static PyObject * -spam_system(PyObject *self, PyObject *args) -{ - const char *command; - int sts; - - if (!PyArg_ParseTuple(args, "s", &command)) - return NULL; - sts = system(command); - if (sts < 0) { - PyErr_SetString(SpamError, "System command failed"); - return NULL; - } - return PyLong_FromLong(sts); -} - -const char spam_doc[] = "This is an example spam doc."; - -static PyMethodDef SpamMethods[] = { - {"system", spam_system, METH_VARARGS, "Execute a shell command."}, - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - -PyMODINIT_FUNC -initspam(void) -{ - PyObject *m; - - m = Py_InitModule("spam", SpamMethods); - if (m == NULL) - return; - PyModule_AddStringConstant(m, "__doc__", spam_doc); - SpamError = PyErr_NewException("spam.error", NULL, NULL); - Py_INCREF(SpamError); - PyModule_AddObject(m, "error", SpamError); -} diff --git a/recipes/cpython/all/test_package/py2/test_package.c b/recipes/cpython/all/test_package/py2/test_package.c deleted file mode 100644 index 5e5d839b5a6a1..0000000000000 --- a/recipes/cpython/all/test_package/py2/test_package.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -int -main(int argc, char *argv[]) -{ - Py_SetProgramName(argv[0]); /* optional but recommended */ - Py_Initialize(); - PyRun_SimpleString("from time import time,ctime\n" - "print 'Today is',ctime(time())\n"); - Py_Finalize(); - return 0; -} diff --git a/recipes/cpython/all/test_package/setup.py b/recipes/cpython/all/test_package/setup.py index cd1754cef8131..2cf4febef6264 100644 --- a/recipes/cpython/all/test_package/setup.py +++ b/recipes/cpython/all/test_package/setup.py @@ -1,5 +1,4 @@ import os -import sys # Hack to work around Python 3.8+ secure dll loading: # see https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew @@ -8,24 +7,14 @@ if os.path.isdir(directory): os.add_dll_directory(directory) -PY2 = (2, 0) <= sys.version_info < (3, 0) -PY3 = (3, 0) <= sys.version_info < (4, 0) - -if PY2: - subdir = "py2" - from distutils.core import setup, Extension -elif PY3: - subdir = "py3" - from setuptools import setup, Extension -else: - raise Exception +from setuptools import setup, Extension +script_dir = os.path.dirname(os.path.realpath(__file__)) setup( name="test_package", version="1.0", - use_2to3=True, ext_modules=[ - Extension("spam", [os.path.join(subdir, "test_module.c")]), + Extension("spam", [os.path.join(script_dir, "test_module.c")]), ], ) diff --git a/recipes/cpython/all/test_package/py3/test_module.c b/recipes/cpython/all/test_package/test_module.c similarity index 100% rename from recipes/cpython/all/test_package/py3/test_module.c rename to recipes/cpython/all/test_package/test_module.c diff --git a/recipes/cpython/all/test_package/py3/test_package.c b/recipes/cpython/all/test_package/test_package.c similarity index 100% rename from recipes/cpython/all/test_package/py3/test_package.c rename to recipes/cpython/all/test_package/test_package.c diff --git a/recipes/cpython/all/test_package/test_package.py b/recipes/cpython/all/test_package/test_package.py index f77d2837c6376..bed43fac74c62 100644 --- a/recipes/cpython/all/test_package/test_package.py +++ b/recipes/cpython/all/test_package/test_package.py @@ -14,12 +14,13 @@ def add_test(fn): global ALL_TESTS - name = fn.__name__[fn.__name__.find("_")+1:] + name = fn.__name__[fn.__name__.find("_") + 1 :] def inner_fn(): print("testing {}".format(name)) sys.stdout.flush() fn() + ALL_TESTS[name] = inner_fn return fn @@ -30,13 +31,13 @@ def test_expat(): # 3 handler functions def start_element(name, attrs): - print('Start element:', name, attrs) + print("Start element:", name, attrs) def end_element(name): - print('End element:', name) + print("End element:", name) def char_data(data): - print('Character data:', repr(data)) + print("Character data:", repr(data)) p = xml.parsers.expat.ParserCreate() @@ -44,18 +45,18 @@ def char_data(data): p.EndElementHandler = end_element p.CharacterDataHandler = char_data - p.Parse(""" + p.Parse( + """ Text goes here More text - """, 1) + """, + 1, + ) @add_test def test_gdbm(): - if sys.version_info < (3, 0): - import gdbm - else: - import dbm.gnu as gdbm + import dbm.gnu as gdbm dbfile = "gdbm.db" @@ -85,10 +86,8 @@ def test_spam(): if "This is an example spam doc." not in spam.__doc__: raise Exception("spam.__doc__ does not contain the expected text") - cmd = { - "Windows": "dir", - }.get(platform.system(), "ls") - print("About to run spam.system(\"{}\")".format(cmd)) + cmd = {"Windows": "dir"}.get(platform.system(), "ls") + print('About to run spam.system("{}")'.format(cmd)) sys.stdout.flush() spam.system(cmd) @@ -103,24 +102,6 @@ def test_bz2(): raise Exception("bz2.compress returned no data") -@add_test -def test_bsddb(): - import bsddb - - db = bsddb.btopen("bsddb.db", "c") - db["key1"] = "value1" - db["key2"] = "value2" - db.close() - - db = bsddb.btopen("bsddb.db", "r") - if len(db) != 2: - raise Exception("Wrong length") - if db["key1"] != "value1": - raise Exception("value1 incorrect {}".format(db["key1"])) - if db["key2"] != "value2": - raise Exception("value2 incorrect {}".format(db["key2"])) - - @add_test def test_lzma(): import lzma @@ -133,6 +114,7 @@ def test_lzma(): @add_test def test_sqlite3(): import sqlite3 + conn = sqlite3.connect("sqlite3.db") c = conn.cursor() @@ -141,16 +123,16 @@ def test_sqlite3(): c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)") conn.commit() - t = ('RHAT',) - c.execute('SELECT * FROM stocks WHERE symbol=?', t) + t = ("RHAT",) + c.execute("SELECT * FROM stocks WHERE symbol=?", t) # Larger example that inserts many records at a time purchases = [ - ('2006-03-28', 'BUY', 'IBM', 1000, 45.00), - ('2006-04-05', 'BUY', 'MSFT', 1000, 72.00), - ('2006-04-06', 'SELL', 'IBM', 500, 53.00), + ("2006-03-28", "BUY", "IBM", 1000, 45.00), + ("2006-04-05", "BUY", "MSFT", 1000, 72.00), + ("2006-04-06", "SELL", "IBM", 500, 53.00), ] - c.executemany('INSERT INTO stocks VALUES (?,?,?,?,?)', purchases) + c.executemany("INSERT INTO stocks VALUES (?,?,?,?,?)", purchases) conn.commit() conn.close() conn = sqlite3.connect("sqlite3.db") @@ -161,15 +143,15 @@ def test_sqlite3(): raise Exception("Need 4 stocks") print(data) conn.close() + # Remove the file so subsequent tests don't fail + os.remove("sqlite3.db") @add_test def test_decimal(): - if sys.version_info >= (3, ): - # Check whether the _decimal package was built successfully - import _decimal as decimal - else: - import decimal + # Check whether the _decimal package was built successfully + import _decimal as decimal + decimal.getcontext().prec = 6 print("1/7 =", decimal.Decimal(1) / decimal.Decimal(7)) decimal.getcontext().prec = 40 @@ -199,6 +181,14 @@ def test_tkinter(): print("tk version: {}".format(_tkinter.TK_VERSION)) +@add_test +def test_ssl(): + import ssl + + default_context = ssl.create_default_context() + print("default_context.options={}".format(default_context.options)) + + def main(): parser = argparse.ArgumentParser() parser.add_argument("-b", dest="build_folder", help="build_folder", required=True) diff --git a/recipes/cpython/all/test_v1_package/CMakeLists.txt b/recipes/cpython/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..6014dcdd6efcb --- /dev/null +++ b/recipes/cpython/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,96 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package C) + +include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") +conan_basic_setup() + +set(CACHE PY_VERSION_MAJOR "" CACHE STRING "MAJOR version of python") +set(CACHE PY_VERSION_MAJOR_MINOR "" CACHE STRING "MAJOR.MINOR version of python") +set(CACHE PY_VERSION "" CACHE STRING "Required version of python") +set(CACHE PY_VERSION_SUFFIX "" CACHE STRING "Suffix of python") + +set(Python_ADDITIONAL_VERSIONS ${PY_VERSION}${PY_VERSION_SUFFIX} ${PY_VERSION_MAJOR_MINOR}${PY_VERSION_SUFFIX} 3${PY_VERSION_SUFFIX} ${PY_VERSION} ${PY_VERSION_MAJOR_MINOR} 3) +message("Using Python_ADDITIONAL_VERSIONS: ${Python_ADDITIONAL_VERSIONS}") + +find_package(PythonInterp REQUIRED) +find_package(PythonLibs REQUIRED) + +string(FIND "${PYTHON_EXECUTABLE}" "${CONAN_CPYTHON_ROOT}" ROOT_SUBPOS) +if(ROOT_SUBPOS EQUAL -1) + message(FATAL_ERROR "found wrong python interpreter: ${PYTHON_EXECUTABLE}") +endif() + +message(STATUS "FindPythonInterp:") +message(STATUS "PYTHON_VERSION_STRING: ${PYTHON_VERSION_STRING}") +message(STATUS "PYTHON_VERSION_MAJOR: ${PYTHON_VERSION_MAJOR}") +message(STATUS "PYTHON_VERSION_MINOR: ${PYTHON_VERSION_MINOR}") +message(STATUS "PYTHON_VERSION_PATCH: ${PYTHON_VERSION_PATCH}") +message(STATUS "=============================================") +message(STATUS "FindPythonLibs:") +message(STATUS "PYTHON_LIBRARIES: ${PYTHON_LIBRARIES}") +message(STATUS "PYTHON_INCLUDE_PATH: ${PYTHON_INCLUDE_PATH} (deprecated)") +message(STATUS "PYTHON_INCLUDE_DIRS: ${PYTHON_INCLUDE_DIRS}") +message(STATUS "PYTHON_DEBUG_LIBRARIES: ${PYTHON_DEBUG_LIBRARIES} (deprecated)") +message(STATUS "PYTHONLIBS_VERSION_STRING: ${PYTHONLIBS_VERSION_STRING}") + +if(NOT PYTHON_VERSION_STRING AND NOT PYTHONLIBS_VERSION_STRING) + message(FATAL_ERROR "Version of python interpreter and libraries not found") +endif() + +if(PYTHON_VERSION_STRING) + if(NOT PYTHON_VERSION_STRING VERSION_EQUAL "${PY_VERSION}") + message("PYTHON_VERSION_STRING does not match PY_VERSION") + message(FATAL_ERROR "CMake detected wrong cpython version") + endif() +endif() + +if(PYTHONLIBS_VERSION_STRING) + if(NOT PYTHONLIBS_VERSION_STRING STREQUAL "${PY_FULL_VERSION}") + message("PYTHONLIBS_VERSION_STRING does not match PY_FULL_VERSION") + message(FATAL_ERROR "CMake detected wrong cpython version") + endif() +endif() + +option(BUILD_MODULE "Build python module") + +set(SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../test_package") + +if(BUILD_MODULE) + add_library(spam MODULE "${SOURCE_DIR}/test_module.c") + target_include_directories(spam + PRIVATE + ${PYTHON_INCLUDE_DIRS} + ) + target_link_libraries(spam PRIVATE + ${PYTHON_LIBRARIES} + ) + set_property(TARGET spam PROPERTY PREFIX "") + if(MSVC) + if(CONAN_SETTINGS_BUILD_TYPE STREQUAL "Debug") + set(SUFFIX "_d.pyd") + else() + set(SUFFIX ".pyd") + endif() + set_property(TARGET spam PROPERTY SUFFIX "${SUFFIX}") + endif() + + option(USE_FINDPYTHON_X "Use new-style FindPythonX module") + if(USE_FINDPYTHON_X AND NOT (CMAKE_VERSION VERSION_LESS "3.16")) + # Require CMake 3.16 because this version introduces Python3_FIND_ABI + find_package(Python3 REQUIRED COMPONENTS Interpreter Development) + message("Python3_EXECUTABLE: ${Python3_EXECUTABLE}") + message("Python3_INTERPRETER_ID: ${Python3_INTERPRETER_ID}") + message("Python3_VERSION: ${Python3_VERSION}") + message("Python3_INCLUDE_DIRS: ${Python3_INCLUDE_DIRS}") + message("Python3_LIBRARIES: ${Python3_LIBRARIES}") + if(NOT Python3_VERSION STREQUAL "${PY_VERSION}") + message("Python_ADDITIONAL_VERSIONS does not match PY_VERSION") + message(FATAL_ERROR "CMake detected wrong cpython version") + endif() + + python3_add_library(spam2 "${SOURCE_DIR}/test_module.c") + endif() +endif() + +add_executable(${PROJECT_NAME} "${SOURCE_DIR}/test_package.c") +target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) diff --git a/recipes/cpython/all/test_v1_package/conanfile.py b/recipes/cpython/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..b79e5742735f3 --- /dev/null +++ b/recipes/cpython/all/test_v1_package/conanfile.py @@ -0,0 +1,154 @@ +from conans import AutoToolsBuildEnvironment, ConanFile, CMake, tools, RunEnvironment +from conans.errors import ConanException +from conan.tools.env import VirtualRunEnv +from io import StringIO +import os +import re + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + @property + def _py_version(self): + return re.match(r"^([0-9.]+)", self.deps_cpp_info["cpython"].version).group(1) + + @property + def _cmake_try_FindPythonX(self): + if self.settings.compiler == "Visual Studio" and self.settings.build_type == "Debug": + return False + return True + + @property + def _supports_modules(self): + return self.settings.compiler != "Visual Studio" or self.options["cpython"].shared + + def generate(self): + # The build also needs access to the run environment to run the python executable + VirtualRunEnv(self).generate(scope="run") + VirtualRunEnv(self).generate(scope="build") + + def build_requirements(self): + # The main recipe does not require CMake, but we test with it. + # The interesting problem that arises here is if you have CMake installed + # with your global pip, then it will fail to run in this test package. + # To avoid that, just add a requirement on CMake. + self.tool_requires("cmake/[>=3.15 <4]") + + def build(self): + if not tools.cross_building(self, skip_x64_x86=True): + command = "{} --version".format(self.deps_user_info["cpython"].python) + buffer = StringIO() + self.run(command, output=buffer, ignore_errors=True, run_environment=True) + self.output.info("output: %s" % buffer.getvalue()) + self.run(command, run_environment=True) + + cmake = CMake(self) + cmake.definitions["BUILD_MODULE"] = self._supports_modules + cmake.definitions["PY_VERSION_MAJOR_MINOR"] = ".".join(self._py_version.split(".")[:2]) + cmake.definitions["PY_FULL_VERSION"] = self.deps_cpp_info["cpython"].version + cmake.definitions["PY_VERSION"] = self._py_version + cmake.definitions["PY_VERSION_SUFFIX"] = "d" if self.settings.build_type == "Debug" else "" + cmake.definitions["PYTHON_EXECUTABLE"] = self.deps_user_info["cpython"].python + cmake.definitions["USE_FINDPYTHON_X"] = self._cmake_try_FindPythonX + cmake.definitions["Python3_EXECUTABLE"] = self.deps_user_info["cpython"].python + cmake.definitions["Python3_ROOT_DIR"] = self.deps_cpp_info["cpython"].rootpath + cmake.definitions["Python3_USE_STATIC_LIBS"] = not self.options["cpython"].shared + cmake.definitions["Python3_FIND_FRAMEWORK"] = "NEVER" + cmake.definitions["Python3_FIND_REGISTRY"] = "NEVER" + cmake.definitions["Python3_FIND_IMPLEMENTATIONS"] = "CPython" + cmake.definitions["Python3_FIND_STRATEGY"] = "LOCATION" + + with tools.environment_append(RunEnvironment(self).vars): + cmake.configure() + cmake.build() + + if not tools.cross_building(self, skip_x64_x86=True): + if self._supports_modules: + with tools.vcvars(self.settings) if self.settings.compiler == "Visual Studio" else tools.no_op(): + env = { + "DISTUTILS_USE_SDK": "1", + "MSSdk": "1" + } + env.update(**AutoToolsBuildEnvironment(self).vars) + with tools.environment_append(env): + setup_args = [ + os.path.join(self.source_folder, "..", "test_package", "setup.py"), + "build", + "--build-base", self.build_folder, + "--build-platlib", os.path.join(self.build_folder, "lib_setuptools"), + # Bandaid fix: setuptools places temporary files in a subdirectory of the build folder where the + # entirety of the absolute path up to this folder is appended (with seemingly no way to stop this), + # essentially doubling the path length. This may run into Windows max path lengths, so we give ourselves + # a little bit of wiggle room by making this directory name as short as possible. One of the directory + # names goes from (for example) "temp.win-amd64-3.10-pydebug" to "t", saving us roughly 25 characters. + "--build-temp", "t", + ] + if self.settings.build_type == "Debug": + setup_args.append("--debug") + self.run("{} {}".format(self.deps_user_info["cpython"].python, " ".join("\"{}\"".format(a) for a in setup_args)), run_environment=True) + + def _test_module(self, module, should_work): + try: + self.run("{} {}/../test_package/test_package.py -b {} -t {} ".format( + self.deps_user_info["cpython"].python, self.source_folder, self.build_folder, module), run_environment=True) + works = True + except ConanException as e: + works = False + exception = e + if should_work == works: + self.output.info("Result of test was expected.") + else: + if works: + raise ConanException("Module '{}' works, but should not have worked".format(module)) + else: + self.output.warn("Module '{}' does not work, but should have worked".format(module)) + raise exception + + def _cpython_option(self, name): + try: + return getattr(self.options["cpython"], name, False) + except ConanException: + return False + + def test(self): + if not tools.cross_building(self, skip_x64_x86=True): + self.run("{} -c \"print('hello world')\"".format(self.deps_user_info["cpython"].python), run_environment=True) + + buffer = StringIO() + self.run("{} -c \"import sys; print('.'.join(str(s) for s in sys.version_info[:3]))\"".format(self.deps_user_info["cpython"].python), run_environment=True, output=buffer) + self.output.info(buffer.getvalue()) + version_detected = buffer.getvalue().splitlines()[-1].strip() + if self._py_version != version_detected: + raise ConanException("python reported wrong version. Expected {exp}. Got {res}.".format(exp=self._py_version, res=version_detected)) + + if self._supports_modules: + self._test_module("gdbm", self._cpython_option("with_gdbm")) + self._test_module("bz2", self._cpython_option("with_bz2")) + self._test_module("lzma", self._cpython_option("with_lzma")) + self._test_module("tkinter", self._cpython_option("with_tkinter")) + with tools.environment_append({"TERM": "ansi"}): + self._test_module("curses", self._cpython_option("with_curses")) + + self._test_module("expat", True) + self._test_module("sqlite3", True) + self._test_module("decimal", True) + self._test_module("ctypes", True) + + if tools.is_apple_os(self.settings.os) and not self.options["cpython"].shared: + self.output.info("Not testing the module, because these seem not to work on apple when cpython is built as a static library") + # FIXME: find out why cpython on apple does not allow to use modules linked against a static python + else: + if self._supports_modules: + with tools.environment_append({"PYTHONPATH": [os.path.join(self.build_folder, "lib")]}): + self.output.info("Testing module (spam) using cmake built module") + self._test_module("spam", True) + + with tools.environment_append({"PYTHONPATH": [os.path.join(self.build_folder, "lib_setuptools")]}): + self.output.info("Testing module (spam) using setup.py built module") + self._test_module("spam", True) + + # MSVC builds need PYTHONHOME set. Linux and Mac don't require it to be set if tested after building, + # but if the package is relocated then it needs to be set. + with tools.environment_append({"PYTHONHOME": self.deps_user_info["cpython"].pythonhome}): + self.run(os.path.join("bin", "test_package"), run_environment=True) diff --git a/recipes/cpython/config.yml b/recipes/cpython/config.yml index e3abf3ec8acb2..cce5cc26948d6 100644 --- a/recipes/cpython/config.yml +++ b/recipes/cpython/config.yml @@ -5,7 +5,3 @@ versions: folder: "all" "3.8.12": folder: "all" - "3.7.12": - folder: "all" - "2.7.18": - folder: "all"