diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/__init__.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..742a46e975b380e9de885430c23bc0ed7ba17966 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/__init__.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/_log.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/_log.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d879b93c422765b714cc29a4d31eeda31db47208 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/_log.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/_macos_compat.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/_macos_compat.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5470143a427c7360a3cd6a4be866aaad9b0ea9db Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/_macos_compat.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/_modified.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/_modified.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..11afe999298b777109c2e52f07146bc927036c18 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/_modified.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1f643be960dc3c82e267d0d3aaaacadffa5e14b2 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..532be1bf11d0e1ab4df942da4ee85dc391070ec4 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2cf9b792aad5c942b18fb8ca37403e03dd3c1bb4 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/cmd.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/cmd.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..425fc81d0ace384788922ac0470ca94d26af1ffe Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/cmd.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/core.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/core.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9167898955327c5f19a200a7374a52afa87db77b Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/core.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bcb358d1b93dfb190106ade5d0468d86dacf2aac Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/debug.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/debug.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c19954b8dbf2907fc3a00117b8d2852afa7c2c5f Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/debug.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/dep_util.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/dep_util.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f257f4b9089e742202c57a22c3785d2e15922323 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/dep_util.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/dir_util.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/dir_util.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b1834d5ccf4b89cc73c4001d2420f2b9374cd36a Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/dir_util.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/dist.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/dist.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8ef3ea76aaa89895815cf91b51c132b6e5e37b23 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/dist.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/errors.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/errors.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d2fac2013ffa98265cabd2bd9e011493286fe33a Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/errors.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/extension.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/extension.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b34d294ebbfdb31c65fc3ac9597027feb96b88fd Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/extension.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/fancy_getopt.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/fancy_getopt.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..af2679e420283406511b71b35afa4bc7ecfaea87 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/fancy_getopt.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/file_util.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/file_util.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..92ee454c02c2394cddae3dfd6d7526f76d58e50c Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/file_util.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/filelist.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/filelist.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1177339e1e292c5105cfef583a91ef63fb064514 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/filelist.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/log.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/log.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..527f0b1f473674c2a7928b85d428b4a19a4ff4df Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/log.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/spawn.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/spawn.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d314b6589dfa9b8260ccfa539096a39f6b73f492 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/spawn.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/sysconfig.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/sysconfig.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e7b9e42c4886ae7d0db7195a8f8ab5ebf9e643be Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/sysconfig.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/text_file.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/text_file.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0771539867d7ae37a91b7578606be7ff52093502 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/text_file.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/unixccompiler.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/unixccompiler.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8638bfd7b3f4519a03ecfa0ce78daaa70d44f022 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/unixccompiler.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/util.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/util.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2a23abd9e8483a8c7212aebb23cb9344ad22f326 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/util.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/version.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/version.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5b77a2754ba1ffacf91cd45aad218972a8799504 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/version.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..81b84fce05d49aaf248a20be084727ffbb822fa3 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/__pycache__/zosccompiler.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/__pycache__/zosccompiler.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bc0a53fb056b2b91fab2341cc150693d0e3fd70f Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/__pycache__/zosccompiler.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__init__.py b/python/Lib/site-packages/setuptools/_distutils/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..5a8ab061009f1cd87a53ce51eff3bc9e9a632273 --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/__init__.py @@ -0,0 +1,42 @@ +""" +Test suite for distutils. + +Tests for the command classes in the distutils.command package are +included in distutils.tests as well, instead of using a separate +distutils.command.tests package, since command identification is done +by import rather than matching pre-defined names. +""" + +import shutil +from collections.abc import Sequence + + +def missing_compiler_executable(cmd_names: Sequence[str] = []): # pragma: no cover + """Check if the compiler components used to build the interpreter exist. + + Check for the existence of the compiler executables whose names are listed + in 'cmd_names' or all the compiler executables when 'cmd_names' is empty + and return the first missing executable or None when none is found + missing. + + """ + from distutils import ccompiler, errors, sysconfig + + compiler = ccompiler.new_compiler() + sysconfig.customize_compiler(compiler) + if compiler.compiler_type == "msvc": + # MSVC has no executables, so check whether initialization succeeds + try: + compiler.initialize() + except errors.DistutilsPlatformError: + return "msvc" + for name in compiler.executables: + if cmd_names and name not in cmd_names: + continue + cmd = getattr(compiler, name) + if cmd_names: + assert cmd is not None, f"the '{name}' executable is not configured" + elif not cmd: + continue + if shutil.which(cmd[0]) is None: + return cmd[0] diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/support.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/support.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9dcb90786c3b297d5d3f8705e5ce53fa832fbc7a Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/support.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_archive_util.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_archive_util.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7914116a1652ce59aea6fdf21a980c1018bedd96 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_archive_util.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..669b899d76ddb8443292ebd460f637aae9e11358 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist_dumb.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist_dumb.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a81d9b504310f9122bb7784c1ec92ef4093f6a66 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist_dumb.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist_rpm.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist_rpm.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9c624e2dd98e171c95df705bf2889853dd3070b1 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_bdist_rpm.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..55e1e893bd56ba1ada4c0dddbaa9dc465c9b41e6 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_clib.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_clib.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..828af3f78a9fa6b54abf4e0023f94a0fd6a51ca3 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_clib.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_ext.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_ext.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6163e14df3c39accf0bf8ecef3596c50d6b9ab24 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_ext.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_py.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_py.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..34437c4ee40b2c7392de7cbac2a4170b9c180b16 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_py.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_scripts.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_scripts.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c0c619703f0fcc49c18af2fb158c1b02eedc3af6 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_build_scripts.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_check.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_check.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..32ad73fac3cca12039a63ad19e31ca580d26a781 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_check.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_clean.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_clean.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5e73c3ad7df37cf8bde45d98a6dcf639f430b03f Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_clean.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_cmd.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_cmd.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8557b8be739ec24c9b7f3ea5698efccc8a2fa87e Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_cmd.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_config_cmd.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_config_cmd.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..94d8f4482e36b99a57118761e00bd495f8324838 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_config_cmd.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_core.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_core.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5aec902e691a3c413d52f2c7082e5630fd8c58e1 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_core.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_dir_util.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_dir_util.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ae844cb729fbccb72562aeedff8a453540d3e525 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_dir_util.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_dist.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_dist.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..597b484c3043466e812b66e2887176543852858d Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_dist.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_extension.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_extension.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e9c2a006855ab4d0763eaaa9c65e0c62694b3e0b Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_extension.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_file_util.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_file_util.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0aa2b7ddf8e63896ba9c5e9e1195e54df1634d04 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_file_util.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_filelist.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_filelist.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a761ea7a12361ced24a46b2e274aacfa54afe2a7 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_filelist.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..87c7f32feee25b29182d6d847afec97180d48298 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_data.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_data.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3e3d3706fb6328517e34f62e86b99d9adb40ee24 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_data.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_headers.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_headers.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2bb1f13095337362d187c82da5bd963978e06c30 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_headers.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_lib.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_lib.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8993bfe39a6bdb8c6fc1c0f310cce65447a737a0 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_lib.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_scripts.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_scripts.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..35c2403e49e179b2d64b4cc38a835d6e42a4311a Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_install_scripts.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_log.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_log.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4548252c8cb50472c8c550134c7081cba184a8e4 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_log.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_modified.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_modified.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8774c4223033e2875ae642e72b5f9d746251e2c3 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_modified.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_sdist.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_sdist.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e1491b05770660176093f2feecc210a1bccb8507 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_sdist.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_spawn.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_spawn.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1a0fc8f211a2961bd3d6d86f3dbf03ea83d439ce Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_spawn.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_sysconfig.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_sysconfig.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c265f79a24c3030f9f76f03a16d0ed17d0ebb7f4 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_sysconfig.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_text_file.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_text_file.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5e79a599f47bc4d277e0656ca3f6a00bfde1288f Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_text_file.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_util.cpython-313.pyc b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_util.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..feebee86c6b6c1f899ed67b028619073ca85ddc7 Binary files /dev/null and b/python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_util.cpython-313.pyc differ diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/compat/__init__.py b/python/Lib/site-packages/setuptools/_distutils/tests/compat/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/compat/py39.py b/python/Lib/site-packages/setuptools/_distutils/tests/compat/py39.py new file mode 100644 index 0000000000000000000000000000000000000000..aca3939a0cea90dd0a90d7f36fcf83a5167cbfc4 --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/compat/py39.py @@ -0,0 +1,40 @@ +import sys + +if sys.version_info >= (3, 10): + from test.support.import_helper import ( + CleanImport as CleanImport, + ) + from test.support.import_helper import ( + DirsOnSysPath as DirsOnSysPath, + ) + from test.support.os_helper import ( + EnvironmentVarGuard as EnvironmentVarGuard, + ) + from test.support.os_helper import ( + rmtree as rmtree, + ) + from test.support.os_helper import ( + skip_unless_symlink as skip_unless_symlink, + ) + from test.support.os_helper import ( + unlink as unlink, + ) +else: + from test.support import ( + CleanImport as CleanImport, + ) + from test.support import ( + DirsOnSysPath as DirsOnSysPath, + ) + from test.support import ( + EnvironmentVarGuard as EnvironmentVarGuard, + ) + from test.support import ( + rmtree as rmtree, + ) + from test.support import ( + skip_unless_symlink as skip_unless_symlink, + ) + from test.support import ( + unlink as unlink, + ) diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_install_lib.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_install_lib.py new file mode 100644 index 0000000000000000000000000000000000000000..f685a579560ea70bceea221de0e54485975ce180 --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/test_install_lib.py @@ -0,0 +1,110 @@ +"""Tests for distutils.command.install_data.""" + +import importlib.util +import os +import sys +from distutils.command.install_lib import install_lib +from distutils.errors import DistutilsOptionError +from distutils.extension import Extension +from distutils.tests import support + +import pytest + + +@support.combine_markers +@pytest.mark.usefixtures('save_env') +class TestInstallLib( + support.TempdirManager, +): + def test_finalize_options(self): + dist = self.create_dist()[1] + cmd = install_lib(dist) + + cmd.finalize_options() + assert cmd.compile == 1 + assert cmd.optimize == 0 + + # optimize must be 0, 1, or 2 + cmd.optimize = 'foo' + with pytest.raises(DistutilsOptionError): + cmd.finalize_options() + cmd.optimize = '4' + with pytest.raises(DistutilsOptionError): + cmd.finalize_options() + + cmd.optimize = '2' + cmd.finalize_options() + assert cmd.optimize == 2 + + @pytest.mark.skipif('sys.dont_write_bytecode') + def test_byte_compile(self): + project_dir, dist = self.create_dist() + os.chdir(project_dir) + cmd = install_lib(dist) + cmd.compile = cmd.optimize = 1 + + f = os.path.join(project_dir, 'foo.py') + self.write_file(f, '# python file') + cmd.byte_compile([f]) + pyc_file = importlib.util.cache_from_source('foo.py', optimization='') + pyc_opt_file = importlib.util.cache_from_source( + 'foo.py', optimization=cmd.optimize + ) + assert os.path.exists(pyc_file) + assert os.path.exists(pyc_opt_file) + + def test_get_outputs(self): + project_dir, dist = self.create_dist() + os.chdir(project_dir) + os.mkdir('spam') + cmd = install_lib(dist) + + # setting up a dist environment + cmd.compile = cmd.optimize = 1 + cmd.install_dir = self.mkdtemp() + f = os.path.join(project_dir, 'spam', '__init__.py') + self.write_file(f, '# python package') + cmd.distribution.ext_modules = [Extension('foo', ['xxx'])] + cmd.distribution.packages = ['spam'] + cmd.distribution.script_name = 'setup.py' + + # get_outputs should return 4 elements: spam/__init__.py and .pyc, + # foo.import-tag-abiflags.so / foo.pyd + outputs = cmd.get_outputs() + assert len(outputs) == 4, outputs + + def test_get_inputs(self): + project_dir, dist = self.create_dist() + os.chdir(project_dir) + os.mkdir('spam') + cmd = install_lib(dist) + + # setting up a dist environment + cmd.compile = cmd.optimize = 1 + cmd.install_dir = self.mkdtemp() + f = os.path.join(project_dir, 'spam', '__init__.py') + self.write_file(f, '# python package') + cmd.distribution.ext_modules = [Extension('foo', ['xxx'])] + cmd.distribution.packages = ['spam'] + cmd.distribution.script_name = 'setup.py' + + # get_inputs should return 2 elements: spam/__init__.py and + # foo.import-tag-abiflags.so / foo.pyd + inputs = cmd.get_inputs() + assert len(inputs) == 2, inputs + + def test_dont_write_bytecode(self, caplog): + # makes sure byte_compile is not used + dist = self.create_dist()[1] + cmd = install_lib(dist) + cmd.compile = True + cmd.optimize = 1 + + old_dont_write_bytecode = sys.dont_write_bytecode + sys.dont_write_bytecode = True + try: + cmd.byte_compile([]) + finally: + sys.dont_write_bytecode = old_dont_write_bytecode + + assert 'byte-compiling is disabled' in caplog.messages[0] diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_install_scripts.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_install_scripts.py new file mode 100644 index 0000000000000000000000000000000000000000..868b1c22521f23a5dd398e4636c94330d4c238ac --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/test_install_scripts.py @@ -0,0 +1,52 @@ +"""Tests for distutils.command.install_scripts.""" + +import os +from distutils.command.install_scripts import install_scripts +from distutils.core import Distribution +from distutils.tests import support + +from . import test_build_scripts + + +class TestInstallScripts(support.TempdirManager): + def test_default_settings(self): + dist = Distribution() + dist.command_obj["build"] = support.DummyCommand(build_scripts="/foo/bar") + dist.command_obj["install"] = support.DummyCommand( + install_scripts="/splat/funk", + force=True, + skip_build=True, + ) + cmd = install_scripts(dist) + assert not cmd.force + assert not cmd.skip_build + assert cmd.build_dir is None + assert cmd.install_dir is None + + cmd.finalize_options() + + assert cmd.force + assert cmd.skip_build + assert cmd.build_dir == "/foo/bar" + assert cmd.install_dir == "/splat/funk" + + def test_installation(self): + source = self.mkdtemp() + + expected = test_build_scripts.TestBuildScripts.write_sample_scripts(source) + + target = self.mkdtemp() + dist = Distribution() + dist.command_obj["build"] = support.DummyCommand(build_scripts=source) + dist.command_obj["install"] = support.DummyCommand( + install_scripts=target, + force=True, + skip_build=True, + ) + cmd = install_scripts(dist) + cmd.finalize_options() + cmd.run() + + installed = os.listdir(target) + for name in expected: + assert name in installed diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_log.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_log.py new file mode 100644 index 0000000000000000000000000000000000000000..d67779fc9fa0f58a010929d5a456890c6dde3376 --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/test_log.py @@ -0,0 +1,12 @@ +"""Tests for distutils.log""" + +import logging +from distutils._log import log + + +class TestLog: + def test_non_ascii(self, caplog): + caplog.set_level(logging.DEBUG) + log.debug('Dεbug\tMėssãge') + log.fatal('Fαtal\tÈrrōr') + assert caplog.messages == ['Dεbug\tMėssãge', 'Fαtal\tÈrrōr'] diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_modified.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_modified.py new file mode 100644 index 0000000000000000000000000000000000000000..e35cec2d6f1a8d27619e33c253f0a83f0f72a75d --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/test_modified.py @@ -0,0 +1,126 @@ +"""Tests for distutils._modified.""" + +import os +import types +from distutils._modified import newer, newer_group, newer_pairwise, newer_pairwise_group +from distutils.errors import DistutilsFileError +from distutils.tests import support + +import pytest + + +class TestDepUtil(support.TempdirManager): + def test_newer(self): + tmpdir = self.mkdtemp() + new_file = os.path.join(tmpdir, 'new') + old_file = os.path.abspath(__file__) + + # Raise DistutilsFileError if 'new_file' does not exist. + with pytest.raises(DistutilsFileError): + newer(new_file, old_file) + + # Return true if 'new_file' exists and is more recently modified than + # 'old_file', or if 'new_file' exists and 'old_file' doesn't. + self.write_file(new_file) + assert newer(new_file, 'I_dont_exist') + assert newer(new_file, old_file) + + # Return false if both exist and 'old_file' is the same age or younger + # than 'new_file'. + assert not newer(old_file, new_file) + + def _setup_1234(self): + tmpdir = self.mkdtemp() + sources = os.path.join(tmpdir, 'sources') + targets = os.path.join(tmpdir, 'targets') + os.mkdir(sources) + os.mkdir(targets) + one = os.path.join(sources, 'one') + two = os.path.join(sources, 'two') + three = os.path.abspath(__file__) # I am the old file + four = os.path.join(targets, 'four') + self.write_file(one) + self.write_file(two) + self.write_file(four) + return one, two, three, four + + def test_newer_pairwise(self): + one, two, three, four = self._setup_1234() + + assert newer_pairwise([one, two], [three, four]) == ([one], [three]) + + def test_newer_pairwise_mismatch(self): + one, two, three, four = self._setup_1234() + + with pytest.raises(ValueError): + newer_pairwise([one], [three, four]) + + with pytest.raises(ValueError): + newer_pairwise([one, two], [three]) + + def test_newer_pairwise_empty(self): + assert newer_pairwise([], []) == ([], []) + + def test_newer_pairwise_fresh(self): + one, two, three, four = self._setup_1234() + + assert newer_pairwise([one, three], [two, four]) == ([], []) + + def test_newer_group(self): + tmpdir = self.mkdtemp() + sources = os.path.join(tmpdir, 'sources') + os.mkdir(sources) + one = os.path.join(sources, 'one') + two = os.path.join(sources, 'two') + three = os.path.join(sources, 'three') + old_file = os.path.abspath(__file__) + + # return true if 'old_file' is out-of-date with respect to any file + # listed in 'sources'. + self.write_file(one) + self.write_file(two) + self.write_file(three) + assert newer_group([one, two, three], old_file) + assert not newer_group([one, two, old_file], three) + + # missing handling + os.remove(one) + with pytest.raises(OSError): + newer_group([one, two, old_file], three) + + assert not newer_group([one, two, old_file], three, missing='ignore') + + assert newer_group([one, two, old_file], three, missing='newer') + + +@pytest.fixture +def groups_target(tmp_path): + """ + Set up some older sources, a target, and newer sources. + + Returns a simple namespace with these values. + """ + filenames = ['older.c', 'older.h', 'target.o', 'newer.c', 'newer.h'] + paths = [tmp_path / name for name in filenames] + + for mtime, path in enumerate(paths): + path.write_text('', encoding='utf-8') + + # make sure modification times are sequential + os.utime(path, (mtime, mtime)) + + return types.SimpleNamespace(older=paths[:2], target=paths[2], newer=paths[3:]) + + +def test_newer_pairwise_group(groups_target): + older = newer_pairwise_group([groups_target.older], [groups_target.target]) + newer = newer_pairwise_group([groups_target.newer], [groups_target.target]) + assert older == ([], []) + assert newer == ([groups_target.newer], [groups_target.target]) + + +def test_newer_group_no_sources_no_target(tmp_path): + """ + Consider no sources and no target "newer". + """ + assert newer_group([], str(tmp_path / 'does-not-exist')) diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_sdist.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_sdist.py new file mode 100644 index 0000000000000000000000000000000000000000..6b1a376b262162aa7c8d3d989709c05b38563d6c --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/test_sdist.py @@ -0,0 +1,470 @@ +"""Tests for distutils.command.sdist.""" + +import os +import pathlib +import shutil # noqa: F401 +import tarfile +import zipfile +from distutils.archive_util import ARCHIVE_FORMATS +from distutils.command.sdist import sdist, show_formats +from distutils.core import Distribution +from distutils.errors import DistutilsOptionError +from distutils.filelist import FileList +from os.path import join +from textwrap import dedent + +import jaraco.path +import path +import pytest +from more_itertools import ilen + +from . import support +from .unix_compat import grp, pwd, require_uid_0, require_unix_id + +SETUP_PY = """ +from distutils.core import setup +import somecode + +setup(name='fake') +""" + +MANIFEST = """\ +# file GENERATED by distutils, do NOT edit +README +buildout.cfg +inroot.txt +setup.py +data%(sep)sdata.dt +scripts%(sep)sscript.py +some%(sep)sfile.txt +some%(sep)sother_file.txt +somecode%(sep)s__init__.py +somecode%(sep)sdoc.dat +somecode%(sep)sdoc.txt +""" + + +@pytest.fixture(autouse=True) +def project_dir(request, distutils_managed_tempdir): + self = request.instance + self.tmp_dir = self.mkdtemp() + jaraco.path.build( + { + 'somecode': { + '__init__.py': '#', + }, + 'README': 'xxx', + 'setup.py': SETUP_PY, + }, + self.tmp_dir, + ) + with path.Path(self.tmp_dir): + yield + + +def clean_lines(filepath): + with pathlib.Path(filepath).open(encoding='utf-8') as f: + yield from filter(None, map(str.strip, f)) + + +class TestSDist(support.TempdirManager): + def get_cmd(self, metadata=None): + """Returns a cmd""" + if metadata is None: + metadata = { + 'name': 'ns.fake--pkg', + 'version': '1.0', + 'url': 'xxx', + 'author': 'xxx', + 'author_email': 'xxx', + } + dist = Distribution(metadata) + dist.script_name = 'setup.py' + dist.packages = ['somecode'] + dist.include_package_data = True + cmd = sdist(dist) + cmd.dist_dir = 'dist' + return dist, cmd + + @pytest.mark.usefixtures('needs_zlib') + def test_prune_file_list(self): + # this test creates a project with some VCS dirs and an NFS rename + # file, then launches sdist to check they get pruned on all systems + + # creating VCS directories with some files in them + os.mkdir(join(self.tmp_dir, 'somecode', '.svn')) + self.write_file((self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx') + + os.mkdir(join(self.tmp_dir, 'somecode', '.hg')) + self.write_file((self.tmp_dir, 'somecode', '.hg', 'ok'), 'xxx') + + os.mkdir(join(self.tmp_dir, 'somecode', '.git')) + self.write_file((self.tmp_dir, 'somecode', '.git', 'ok'), 'xxx') + + self.write_file((self.tmp_dir, 'somecode', '.nfs0001'), 'xxx') + + # now building a sdist + dist, cmd = self.get_cmd() + + # zip is available universally + # (tar might not be installed under win32) + cmd.formats = ['zip'] + + cmd.ensure_finalized() + cmd.run() + + # now let's check what we have + dist_folder = join(self.tmp_dir, 'dist') + files = os.listdir(dist_folder) + assert files == ['ns_fake_pkg-1.0.zip'] + + zip_file = zipfile.ZipFile(join(dist_folder, 'ns_fake_pkg-1.0.zip')) + try: + content = zip_file.namelist() + finally: + zip_file.close() + + # making sure everything has been pruned correctly + expected = [ + '', + 'PKG-INFO', + 'README', + 'setup.py', + 'somecode/', + 'somecode/__init__.py', + ] + assert sorted(content) == ['ns_fake_pkg-1.0/' + x for x in expected] + + @pytest.mark.usefixtures('needs_zlib') + @pytest.mark.skipif("not shutil.which('tar')") + @pytest.mark.skipif("not shutil.which('gzip')") + def test_make_distribution(self): + # now building a sdist + dist, cmd = self.get_cmd() + + # creating a gztar then a tar + cmd.formats = ['gztar', 'tar'] + cmd.ensure_finalized() + cmd.run() + + # making sure we have two files + dist_folder = join(self.tmp_dir, 'dist') + result = os.listdir(dist_folder) + result.sort() + assert result == ['ns_fake_pkg-1.0.tar', 'ns_fake_pkg-1.0.tar.gz'] + + os.remove(join(dist_folder, 'ns_fake_pkg-1.0.tar')) + os.remove(join(dist_folder, 'ns_fake_pkg-1.0.tar.gz')) + + # now trying a tar then a gztar + cmd.formats = ['tar', 'gztar'] + + cmd.ensure_finalized() + cmd.run() + + result = os.listdir(dist_folder) + result.sort() + assert result == ['ns_fake_pkg-1.0.tar', 'ns_fake_pkg-1.0.tar.gz'] + + @pytest.mark.usefixtures('needs_zlib') + def test_add_defaults(self): + # https://bugs.python.org/issue2279 + + # add_default should also include + # data_files and package_data + dist, cmd = self.get_cmd() + + # filling data_files by pointing files + # in package_data + dist.package_data = {'': ['*.cfg', '*.dat'], 'somecode': ['*.txt']} + self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#') + self.write_file((self.tmp_dir, 'somecode', 'doc.dat'), '#') + + # adding some data in data_files + data_dir = join(self.tmp_dir, 'data') + os.mkdir(data_dir) + self.write_file((data_dir, 'data.dt'), '#') + some_dir = join(self.tmp_dir, 'some') + os.mkdir(some_dir) + # make sure VCS directories are pruned (#14004) + hg_dir = join(self.tmp_dir, '.hg') + os.mkdir(hg_dir) + self.write_file((hg_dir, 'last-message.txt'), '#') + # a buggy regex used to prevent this from working on windows (#6884) + self.write_file((self.tmp_dir, 'buildout.cfg'), '#') + self.write_file((self.tmp_dir, 'inroot.txt'), '#') + self.write_file((some_dir, 'file.txt'), '#') + self.write_file((some_dir, 'other_file.txt'), '#') + + dist.data_files = [ + ('data', ['data/data.dt', 'buildout.cfg', 'inroot.txt', 'notexisting']), + 'some/file.txt', + 'some/other_file.txt', + ] + + # adding a script + script_dir = join(self.tmp_dir, 'scripts') + os.mkdir(script_dir) + self.write_file((script_dir, 'script.py'), '#') + dist.scripts = [join('scripts', 'script.py')] + + cmd.formats = ['zip'] + cmd.use_defaults = True + + cmd.ensure_finalized() + cmd.run() + + # now let's check what we have + dist_folder = join(self.tmp_dir, 'dist') + files = os.listdir(dist_folder) + assert files == ['ns_fake_pkg-1.0.zip'] + + zip_file = zipfile.ZipFile(join(dist_folder, 'ns_fake_pkg-1.0.zip')) + try: + content = zip_file.namelist() + finally: + zip_file.close() + + # making sure everything was added + expected = [ + '', + 'PKG-INFO', + 'README', + 'buildout.cfg', + 'data/', + 'data/data.dt', + 'inroot.txt', + 'scripts/', + 'scripts/script.py', + 'setup.py', + 'some/', + 'some/file.txt', + 'some/other_file.txt', + 'somecode/', + 'somecode/__init__.py', + 'somecode/doc.dat', + 'somecode/doc.txt', + ] + assert sorted(content) == ['ns_fake_pkg-1.0/' + x for x in expected] + + # checking the MANIFEST + manifest = pathlib.Path(self.tmp_dir, 'MANIFEST').read_text(encoding='utf-8') + assert manifest == MANIFEST % {'sep': os.sep} + + @staticmethod + def warnings(messages, prefix='warning: '): + return [msg for msg in messages if msg.startswith(prefix)] + + @pytest.mark.usefixtures('needs_zlib') + def test_metadata_check_option(self, caplog): + # testing the `medata-check` option + dist, cmd = self.get_cmd(metadata={}) + + # this should raise some warnings ! + # with the `check` subcommand + cmd.ensure_finalized() + cmd.run() + assert len(self.warnings(caplog.messages, 'warning: check: ')) == 1 + + # trying with a complete set of metadata + caplog.clear() + dist, cmd = self.get_cmd() + cmd.ensure_finalized() + cmd.metadata_check = False + cmd.run() + assert len(self.warnings(caplog.messages, 'warning: check: ')) == 0 + + def test_show_formats(self, capsys): + show_formats() + + # the output should be a header line + one line per format + num_formats = len(ARCHIVE_FORMATS.keys()) + output = [ + line + for line in capsys.readouterr().out.split('\n') + if line.strip().startswith('--formats=') + ] + assert len(output) == num_formats + + def test_finalize_options(self): + dist, cmd = self.get_cmd() + cmd.finalize_options() + + # default options set by finalize + assert cmd.manifest == 'MANIFEST' + assert cmd.template == 'MANIFEST.in' + assert cmd.dist_dir == 'dist' + + # formats has to be a string splitable on (' ', ',') or + # a stringlist + cmd.formats = 1 + with pytest.raises(DistutilsOptionError): + cmd.finalize_options() + cmd.formats = ['zip'] + cmd.finalize_options() + + # formats has to be known + cmd.formats = 'supazipa' + with pytest.raises(DistutilsOptionError): + cmd.finalize_options() + + # the following tests make sure there is a nice error message instead + # of a traceback when parsing an invalid manifest template + + def _check_template(self, content, caplog): + dist, cmd = self.get_cmd() + os.chdir(self.tmp_dir) + self.write_file('MANIFEST.in', content) + cmd.ensure_finalized() + cmd.filelist = FileList() + cmd.read_template() + assert len(self.warnings(caplog.messages)) == 1 + + def test_invalid_template_unknown_command(self, caplog): + self._check_template('taunt knights *', caplog) + + def test_invalid_template_wrong_arguments(self, caplog): + # this manifest command takes one argument + self._check_template('prune', caplog) + + @pytest.mark.skipif("platform.system() != 'Windows'") + def test_invalid_template_wrong_path(self, caplog): + # on Windows, trailing slashes are not allowed + # this used to crash instead of raising a warning: #8286 + self._check_template('include examples/', caplog) + + @pytest.mark.usefixtures('needs_zlib') + def test_get_file_list(self): + # make sure MANIFEST is recalculated + dist, cmd = self.get_cmd() + + # filling data_files by pointing files in package_data + dist.package_data = {'somecode': ['*.txt']} + self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#') + cmd.formats = ['gztar'] + cmd.ensure_finalized() + cmd.run() + + assert ilen(clean_lines(cmd.manifest)) == 5 + + # adding a file + self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#') + + # make sure build_py is reinitialized, like a fresh run + build_py = dist.get_command_obj('build_py') + build_py.finalized = False + build_py.ensure_finalized() + + cmd.run() + + manifest2 = list(clean_lines(cmd.manifest)) + + # do we have the new file in MANIFEST ? + assert len(manifest2) == 6 + assert 'doc2.txt' in manifest2[-1] + + @pytest.mark.usefixtures('needs_zlib') + def test_manifest_marker(self): + # check that autogenerated MANIFESTs have a marker + dist, cmd = self.get_cmd() + cmd.ensure_finalized() + cmd.run() + + assert ( + next(clean_lines(cmd.manifest)) + == '# file GENERATED by distutils, do NOT edit' + ) + + @pytest.mark.usefixtures('needs_zlib') + def test_manifest_comments(self): + # make sure comments don't cause exceptions or wrong includes + contents = dedent( + """\ + # bad.py + #bad.py + good.py + """ + ) + dist, cmd = self.get_cmd() + cmd.ensure_finalized() + self.write_file((self.tmp_dir, cmd.manifest), contents) + self.write_file((self.tmp_dir, 'good.py'), '# pick me!') + self.write_file((self.tmp_dir, 'bad.py'), "# don't pick me!") + self.write_file((self.tmp_dir, '#bad.py'), "# don't pick me!") + cmd.run() + assert cmd.filelist.files == ['good.py'] + + @pytest.mark.usefixtures('needs_zlib') + def test_manual_manifest(self): + # check that a MANIFEST without a marker is left alone + dist, cmd = self.get_cmd() + cmd.formats = ['gztar'] + cmd.ensure_finalized() + self.write_file((self.tmp_dir, cmd.manifest), 'README.manual') + self.write_file( + (self.tmp_dir, 'README.manual'), + 'This project maintains its MANIFEST file itself.', + ) + cmd.run() + assert cmd.filelist.files == ['README.manual'] + + assert list(clean_lines(cmd.manifest)) == ['README.manual'] + + archive_name = join(self.tmp_dir, 'dist', 'ns_fake_pkg-1.0.tar.gz') + archive = tarfile.open(archive_name) + try: + filenames = [tarinfo.name for tarinfo in archive] + finally: + archive.close() + assert sorted(filenames) == [ + 'ns_fake_pkg-1.0', + 'ns_fake_pkg-1.0/PKG-INFO', + 'ns_fake_pkg-1.0/README.manual', + ] + + @pytest.mark.usefixtures('needs_zlib') + @require_unix_id + @require_uid_0 + @pytest.mark.skipif("not shutil.which('tar')") + @pytest.mark.skipif("not shutil.which('gzip')") + def test_make_distribution_owner_group(self): + # now building a sdist + dist, cmd = self.get_cmd() + + # creating a gztar and specifying the owner+group + cmd.formats = ['gztar'] + cmd.owner = pwd.getpwuid(0)[0] + cmd.group = grp.getgrgid(0)[0] + cmd.ensure_finalized() + cmd.run() + + # making sure we have the good rights + archive_name = join(self.tmp_dir, 'dist', 'ns_fake_pkg-1.0.tar.gz') + archive = tarfile.open(archive_name) + try: + for member in archive.getmembers(): + assert member.uid == 0 + assert member.gid == 0 + finally: + archive.close() + + # building a sdist again + dist, cmd = self.get_cmd() + + # creating a gztar + cmd.formats = ['gztar'] + cmd.ensure_finalized() + cmd.run() + + # making sure we have the good rights + archive_name = join(self.tmp_dir, 'dist', 'ns_fake_pkg-1.0.tar.gz') + archive = tarfile.open(archive_name) + + # note that we are not testing the group ownership here + # because, depending on the platforms and the container + # rights (see #7408) + try: + for member in archive.getmembers(): + assert member.uid == os.getuid() + finally: + archive.close() diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_spawn.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_spawn.py new file mode 100644 index 0000000000000000000000000000000000000000..3b9fc926f6ffc41673630fbf5775e6f4ad638b18 --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/test_spawn.py @@ -0,0 +1,141 @@ +"""Tests for distutils.spawn.""" + +import os +import stat +import sys +import unittest.mock as mock +from distutils.errors import DistutilsExecError +from distutils.spawn import find_executable, spawn +from distutils.tests import support + +import path +import pytest +from test.support import unix_shell + +from .compat import py39 as os_helper + + +class TestSpawn(support.TempdirManager): + @pytest.mark.skipif("os.name not in ('nt', 'posix')") + def test_spawn(self): + tmpdir = self.mkdtemp() + + # creating something executable + # through the shell that returns 1 + if sys.platform != 'win32': + exe = os.path.join(tmpdir, 'foo.sh') + self.write_file(exe, f'#!{unix_shell}\nexit 1') + else: + exe = os.path.join(tmpdir, 'foo.bat') + self.write_file(exe, 'exit 1') + + os.chmod(exe, 0o777) + with pytest.raises(DistutilsExecError): + spawn([exe]) + + # now something that works + if sys.platform != 'win32': + exe = os.path.join(tmpdir, 'foo.sh') + self.write_file(exe, f'#!{unix_shell}\nexit 0') + else: + exe = os.path.join(tmpdir, 'foo.bat') + self.write_file(exe, 'exit 0') + + os.chmod(exe, 0o777) + spawn([exe]) # should work without any error + + def test_find_executable(self, tmp_path): + program_path = self._make_executable(tmp_path, '.exe') + program = program_path.name + program_noeext = program_path.with_suffix('').name + filename = str(program_path) + tmp_dir = path.Path(tmp_path) + + # test path parameter + rv = find_executable(program, path=tmp_dir) + assert rv == filename + + if sys.platform == 'win32': + # test without ".exe" extension + rv = find_executable(program_noeext, path=tmp_dir) + assert rv == filename + + # test find in the current directory + with tmp_dir: + rv = find_executable(program) + assert rv == program + + # test non-existent program + dont_exist_program = "dontexist_" + program + rv = find_executable(dont_exist_program, path=tmp_dir) + assert rv is None + + # PATH='': no match, except in the current directory + with os_helper.EnvironmentVarGuard() as env: + env['PATH'] = '' + with ( + mock.patch( + 'distutils.spawn.os.confstr', return_value=tmp_dir, create=True + ), + mock.patch('distutils.spawn.os.defpath', tmp_dir), + ): + rv = find_executable(program) + assert rv is None + + # look in current directory + with tmp_dir: + rv = find_executable(program) + assert rv == program + + # PATH=':': explicitly looks in the current directory + with os_helper.EnvironmentVarGuard() as env: + env['PATH'] = os.pathsep + with ( + mock.patch('distutils.spawn.os.confstr', return_value='', create=True), + mock.patch('distutils.spawn.os.defpath', ''), + ): + rv = find_executable(program) + assert rv is None + + # look in current directory + with tmp_dir: + rv = find_executable(program) + assert rv == program + + # missing PATH: test os.confstr("CS_PATH") and os.defpath + with os_helper.EnvironmentVarGuard() as env: + env.pop('PATH', None) + + # without confstr + with ( + mock.patch( + 'distutils.spawn.os.confstr', side_effect=ValueError, create=True + ), + mock.patch('distutils.spawn.os.defpath', tmp_dir), + ): + rv = find_executable(program) + assert rv == filename + + # with confstr + with ( + mock.patch( + 'distutils.spawn.os.confstr', return_value=tmp_dir, create=True + ), + mock.patch('distutils.spawn.os.defpath', ''), + ): + rv = find_executable(program) + assert rv == filename + + @staticmethod + def _make_executable(tmp_path, ext): + # Give the temporary program a suffix regardless of platform. + # It's needed on Windows and not harmful on others. + program = tmp_path.joinpath('program').with_suffix(ext) + program.write_text("", encoding='utf-8') + program.chmod(stat.S_IXUSR) + return program + + def test_spawn_missing_exe(self): + with pytest.raises(DistutilsExecError) as ctx: + spawn(['does-not-exist']) + assert "command 'does-not-exist' failed" in str(ctx.value) diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_sysconfig.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_sysconfig.py new file mode 100644 index 0000000000000000000000000000000000000000..43d77c23fad426be237b9f91a6d98d7c36233d84 --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/test_sysconfig.py @@ -0,0 +1,319 @@ +"""Tests for distutils.sysconfig.""" + +import contextlib +import distutils +import os +import pathlib +import subprocess +import sys +from distutils import sysconfig +from distutils.ccompiler import new_compiler # noqa: F401 +from distutils.unixccompiler import UnixCCompiler + +import jaraco.envs +import path +import pytest +from jaraco.text import trim +from test.support import swap_item + + +def _gen_makefile(root, contents): + jaraco.path.build({'Makefile': trim(contents)}, root) + return root / 'Makefile' + + +@pytest.mark.usefixtures('save_env') +class TestSysconfig: + def test_get_config_h_filename(self): + config_h = sysconfig.get_config_h_filename() + assert os.path.isfile(config_h) + + @pytest.mark.skipif("platform.system() == 'Windows'") + @pytest.mark.skipif("sys.implementation.name != 'cpython'") + def test_get_makefile_filename(self): + makefile = sysconfig.get_makefile_filename() + assert os.path.isfile(makefile) + + def test_get_python_lib(self, tmp_path): + assert sysconfig.get_python_lib() != sysconfig.get_python_lib(prefix=tmp_path) + + def test_get_config_vars(self): + cvars = sysconfig.get_config_vars() + assert isinstance(cvars, dict) + assert cvars + + @pytest.mark.skipif('sysconfig.IS_PYPY') + @pytest.mark.skipif('sysconfig.python_build') + @pytest.mark.xfail('platform.system() == "Windows"') + def test_srcdir_simple(self): + # See #15364. + srcdir = pathlib.Path(sysconfig.get_config_var('srcdir')) + + assert srcdir.absolute() + assert srcdir.is_dir() + + makefile = pathlib.Path(sysconfig.get_makefile_filename()) + assert makefile.parent.samefile(srcdir) + + @pytest.mark.skipif('sysconfig.IS_PYPY') + @pytest.mark.skipif('not sysconfig.python_build') + def test_srcdir_python_build(self): + # See #15364. + srcdir = pathlib.Path(sysconfig.get_config_var('srcdir')) + + # The python executable has not been installed so srcdir + # should be a full source checkout. + Python_h = srcdir.joinpath('Include', 'Python.h') + assert Python_h.is_file() + assert sysconfig._is_python_source_dir(srcdir) + assert sysconfig._is_python_source_dir(str(srcdir)) + + def test_srcdir_independent_of_cwd(self): + """ + srcdir should be independent of the current working directory + """ + # See #15364. + srcdir = sysconfig.get_config_var('srcdir') + with path.Path('..'): + srcdir2 = sysconfig.get_config_var('srcdir') + assert srcdir == srcdir2 + + def customize_compiler(self): + # make sure AR gets caught + class compiler: + compiler_type = 'unix' + executables = UnixCCompiler.executables + + def __init__(self): + self.exes = {} + + def set_executables(self, **kw): + for k, v in kw.items(): + self.exes[k] = v + + sysconfig_vars = { + 'AR': 'sc_ar', + 'CC': 'sc_cc', + 'CXX': 'sc_cxx', + 'ARFLAGS': '--sc-arflags', + 'CFLAGS': '--sc-cflags', + 'CCSHARED': '--sc-ccshared', + 'LDSHARED': 'sc_ldshared', + 'SHLIB_SUFFIX': 'sc_shutil_suffix', + } + + comp = compiler() + with contextlib.ExitStack() as cm: + for key, value in sysconfig_vars.items(): + cm.enter_context(swap_item(sysconfig._config_vars, key, value)) + sysconfig.customize_compiler(comp) + + return comp + + @pytest.mark.skipif("not isinstance(new_compiler(), UnixCCompiler)") + @pytest.mark.usefixtures('disable_macos_customization') + def test_customize_compiler(self): + # Make sure that sysconfig._config_vars is initialized + sysconfig.get_config_vars() + + os.environ['AR'] = 'env_ar' + os.environ['CC'] = 'env_cc' + os.environ['CPP'] = 'env_cpp' + os.environ['CXX'] = 'env_cxx --env-cxx-flags' + os.environ['LDSHARED'] = 'env_ldshared' + os.environ['LDFLAGS'] = '--env-ldflags' + os.environ['ARFLAGS'] = '--env-arflags' + os.environ['CFLAGS'] = '--env-cflags' + os.environ['CPPFLAGS'] = '--env-cppflags' + os.environ['RANLIB'] = 'env_ranlib' + + comp = self.customize_compiler() + assert comp.exes['archiver'] == 'env_ar --env-arflags' + assert comp.exes['preprocessor'] == 'env_cpp --env-cppflags' + assert comp.exes['compiler'] == 'env_cc --env-cflags --env-cppflags' + assert comp.exes['compiler_so'] == ( + 'env_cc --env-cflags --env-cppflags --sc-ccshared' + ) + assert ( + comp.exes['compiler_cxx'] + == 'env_cxx --env-cxx-flags --sc-cflags --env-cppflags' + ) + assert comp.exes['linker_exe'] == 'env_cc' + assert comp.exes['linker_so'] == ( + 'env_ldshared --env-ldflags --env-cflags --env-cppflags' + ) + assert comp.shared_lib_extension == 'sc_shutil_suffix' + + if sys.platform == "darwin": + assert comp.exes['ranlib'] == 'env_ranlib' + else: + assert 'ranlib' not in comp.exes + + del os.environ['AR'] + del os.environ['CC'] + del os.environ['CPP'] + del os.environ['CXX'] + del os.environ['LDSHARED'] + del os.environ['LDFLAGS'] + del os.environ['ARFLAGS'] + del os.environ['CFLAGS'] + del os.environ['CPPFLAGS'] + del os.environ['RANLIB'] + + comp = self.customize_compiler() + assert comp.exes['archiver'] == 'sc_ar --sc-arflags' + assert comp.exes['preprocessor'] == 'sc_cc -E' + assert comp.exes['compiler'] == 'sc_cc --sc-cflags' + assert comp.exes['compiler_so'] == 'sc_cc --sc-cflags --sc-ccshared' + assert comp.exes['compiler_cxx'] == 'sc_cxx --sc-cflags' + assert comp.exes['linker_exe'] == 'sc_cc' + assert comp.exes['linker_so'] == 'sc_ldshared' + assert comp.shared_lib_extension == 'sc_shutil_suffix' + assert 'ranlib' not in comp.exes + + def test_parse_makefile_base(self, tmp_path): + makefile = _gen_makefile( + tmp_path, + """ + CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB' + VAR=$OTHER + OTHER=foo + """, + ) + d = sysconfig.parse_makefile(makefile) + assert d == {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'", 'OTHER': 'foo'} + + def test_parse_makefile_literal_dollar(self, tmp_path): + makefile = _gen_makefile( + tmp_path, + """ + CONFIG_ARGS= '--arg1=optarg1' 'ENV=\\$$LIB' + VAR=$OTHER + OTHER=foo + """, + ) + d = sysconfig.parse_makefile(makefile) + assert d == {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'", 'OTHER': 'foo'} + + def test_sysconfig_module(self): + import sysconfig as global_sysconfig + + assert global_sysconfig.get_config_var('CFLAGS') == sysconfig.get_config_var( + 'CFLAGS' + ) + assert global_sysconfig.get_config_var('LDFLAGS') == sysconfig.get_config_var( + 'LDFLAGS' + ) + + # On macOS, binary installers support extension module building on + # various levels of the operating system with differing Xcode + # configurations, requiring customization of some of the + # compiler configuration directives to suit the environment on + # the installed machine. Some of these customizations may require + # running external programs and are thus deferred until needed by + # the first extension module build. Only + # the Distutils version of sysconfig is used for extension module + # builds, which happens earlier in the Distutils tests. This may + # cause the following tests to fail since no tests have caused + # the global version of sysconfig to call the customization yet. + # The solution for now is to simply skip this test in this case. + # The longer-term solution is to only have one version of sysconfig. + @pytest.mark.skipif("sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER')") + def test_sysconfig_compiler_vars(self): + import sysconfig as global_sysconfig + + if sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'): + pytest.skip('compiler flags customized') + assert global_sysconfig.get_config_var('LDSHARED') == sysconfig.get_config_var( + 'LDSHARED' + ) + assert global_sysconfig.get_config_var('CC') == sysconfig.get_config_var('CC') + + @pytest.mark.skipif("not sysconfig.get_config_var('EXT_SUFFIX')") + def test_SO_deprecation(self): + with pytest.warns(DeprecationWarning): + sysconfig.get_config_var('SO') + + def test_customize_compiler_before_get_config_vars(self, tmp_path): + # Issue #21923: test that a Distribution compiler + # instance can be called without an explicit call to + # get_config_vars(). + jaraco.path.build( + { + 'file': trim(""" + from distutils.core import Distribution + config = Distribution().get_command_obj('config') + # try_compile may pass or it may fail if no compiler + # is found but it should not raise an exception. + rc = config.try_compile('int x;') + """) + }, + tmp_path, + ) + p = subprocess.Popen( + [sys.executable, tmp_path / 'file'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + universal_newlines=True, + encoding='utf-8', + ) + outs, errs = p.communicate() + assert 0 == p.returncode, "Subprocess failed: " + outs + + def test_parse_config_h(self): + config_h = sysconfig.get_config_h_filename() + input = {} + with open(config_h, encoding="utf-8") as f: + result = sysconfig.parse_config_h(f, g=input) + assert input is result + with open(config_h, encoding="utf-8") as f: + result = sysconfig.parse_config_h(f) + assert isinstance(result, dict) + + @pytest.mark.skipif("platform.system() != 'Windows'") + @pytest.mark.skipif("sys.implementation.name != 'cpython'") + def test_win_ext_suffix(self): + assert sysconfig.get_config_var("EXT_SUFFIX").endswith(".pyd") + assert sysconfig.get_config_var("EXT_SUFFIX") != ".pyd" + + @pytest.mark.skipif("platform.system() != 'Windows'") + @pytest.mark.skipif("sys.implementation.name != 'cpython'") + @pytest.mark.skipif( + '\\PCbuild\\'.casefold() not in sys.executable.casefold(), + reason='Need sys.executable to be in a source tree', + ) + def test_win_build_venv_from_source_tree(self, tmp_path): + """Ensure distutils.sysconfig detects venvs from source tree builds.""" + env = jaraco.envs.VEnv() + env.create_opts = env.clean_opts + env.root = tmp_path + env.ensure_env() + cmd = [ + env.exe(), + "-c", + "import distutils.sysconfig; print(distutils.sysconfig.python_build)", + ] + distutils_path = os.path.dirname(os.path.dirname(distutils.__file__)) + out = subprocess.check_output( + cmd, env={**os.environ, "PYTHONPATH": distutils_path} + ) + assert out == "True" + + def test_get_python_inc_missing_config_dir(self, monkeypatch): + """ + In portable Python installations, the sysconfig will be broken, + pointing to the directories where the installation was built and + not where it currently is. In this case, ensure that the missing + directory isn't used for get_python_inc. + + See pypa/distutils#178. + """ + + def override(name): + if name == 'INCLUDEPY': + return '/does-not-exist' + return sysconfig.get_config_var(name) + + monkeypatch.setattr(sysconfig, 'get_config_var', override) + + assert os.path.exists(sysconfig.get_python_inc()) diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_text_file.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_text_file.py new file mode 100644 index 0000000000000000000000000000000000000000..f51115656135cd3f348a45d4a14f97eeee47fb98 --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/test_text_file.py @@ -0,0 +1,127 @@ +"""Tests for distutils.text_file.""" + +from distutils.tests import support +from distutils.text_file import TextFile + +import jaraco.path +import path + +TEST_DATA = """# test file + +line 3 \\ +# intervening comment + continues on next line +""" + + +class TestTextFile(support.TempdirManager): + def test_class(self): + # old tests moved from text_file.__main__ + # so they are really called by the buildbots + + # result 1: no fancy options + result1 = [ + '# test file\n', + '\n', + 'line 3 \\\n', + '# intervening comment\n', + ' continues on next line\n', + ] + + # result 2: just strip comments + result2 = ["\n", "line 3 \\\n", " continues on next line\n"] + + # result 3: just strip blank lines + result3 = [ + "# test file\n", + "line 3 \\\n", + "# intervening comment\n", + " continues on next line\n", + ] + + # result 4: default, strip comments, blank lines, + # and trailing whitespace + result4 = ["line 3 \\", " continues on next line"] + + # result 5: strip comments and blanks, plus join lines (but don't + # "collapse" joined lines + result5 = ["line 3 continues on next line"] + + # result 6: strip comments and blanks, plus join lines (and + # "collapse" joined lines + result6 = ["line 3 continues on next line"] + + def test_input(count, description, file, expected_result): + result = file.readlines() + assert result == expected_result + + tmp_path = path.Path(self.mkdtemp()) + filename = tmp_path / 'test.txt' + jaraco.path.build({filename.name: TEST_DATA}, tmp_path) + + in_file = TextFile( + filename, + strip_comments=False, + skip_blanks=False, + lstrip_ws=False, + rstrip_ws=False, + ) + try: + test_input(1, "no processing", in_file, result1) + finally: + in_file.close() + + in_file = TextFile( + filename, + strip_comments=True, + skip_blanks=False, + lstrip_ws=False, + rstrip_ws=False, + ) + try: + test_input(2, "strip comments", in_file, result2) + finally: + in_file.close() + + in_file = TextFile( + filename, + strip_comments=False, + skip_blanks=True, + lstrip_ws=False, + rstrip_ws=False, + ) + try: + test_input(3, "strip blanks", in_file, result3) + finally: + in_file.close() + + in_file = TextFile(filename) + try: + test_input(4, "default processing", in_file, result4) + finally: + in_file.close() + + in_file = TextFile( + filename, + strip_comments=True, + skip_blanks=True, + join_lines=True, + rstrip_ws=True, + ) + try: + test_input(5, "join lines without collapsing", in_file, result5) + finally: + in_file.close() + + in_file = TextFile( + filename, + strip_comments=True, + skip_blanks=True, + join_lines=True, + rstrip_ws=True, + collapse_join=True, + ) + try: + test_input(6, "join lines with collapsing", in_file, result6) + finally: + in_file.close() diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_util.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_util.py new file mode 100644 index 0000000000000000000000000000000000000000..00c9743ed0a2664039060ef149d30f165bf2f465 --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/test_util.py @@ -0,0 +1,243 @@ +"""Tests for distutils.util.""" + +import email +import email.generator +import email.policy +import io +import os +import pathlib +import sys +import sysconfig as stdlib_sysconfig +import unittest.mock as mock +from copy import copy +from distutils import sysconfig, util +from distutils.errors import DistutilsByteCompileError, DistutilsPlatformError +from distutils.util import ( + byte_compile, + change_root, + check_environ, + convert_path, + get_host_platform, + get_platform, + grok_environment_error, + rfc822_escape, + split_quoted, + strtobool, +) + +import pytest + + +@pytest.fixture(autouse=True) +def environment(monkeypatch): + monkeypatch.setattr(os, 'name', os.name) + monkeypatch.setattr(sys, 'platform', sys.platform) + monkeypatch.setattr(sys, 'version', sys.version) + monkeypatch.setattr(os, 'sep', os.sep) + monkeypatch.setattr(os.path, 'join', os.path.join) + monkeypatch.setattr(os.path, 'isabs', os.path.isabs) + monkeypatch.setattr(os.path, 'splitdrive', os.path.splitdrive) + monkeypatch.setattr(sysconfig, '_config_vars', copy(sysconfig._config_vars)) + + +@pytest.mark.usefixtures('save_env') +class TestUtil: + def test_get_host_platform(self): + with mock.patch('os.name', 'nt'): + with mock.patch('sys.version', '... [... (ARM64)]'): + assert get_host_platform() == 'win-arm64' + with mock.patch('sys.version', '... [... (ARM)]'): + assert get_host_platform() == 'win-arm32' + + with mock.patch('sys.version_info', (3, 9, 0, 'final', 0)): + assert get_host_platform() == stdlib_sysconfig.get_platform() + + def test_get_platform(self): + with mock.patch('os.name', 'nt'): + with mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'x86'}): + assert get_platform() == 'win32' + with mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'x64'}): + assert get_platform() == 'win-amd64' + with mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm'}): + assert get_platform() == 'win-arm32' + with mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm64'}): + assert get_platform() == 'win-arm64' + + def test_convert_path(self): + expected = os.sep.join(('', 'home', 'to', 'my', 'stuff')) + assert convert_path('/home/to/my/stuff') == expected + assert convert_path(pathlib.Path('/home/to/my/stuff')) == expected + assert convert_path('.') == os.curdir + + def test_change_root(self): + # linux/mac + os.name = 'posix' + + def _isabs(path): + return path[0] == '/' + + os.path.isabs = _isabs + + def _join(*path): + return '/'.join(path) + + os.path.join = _join + + assert change_root('/root', '/old/its/here') == '/root/old/its/here' + assert change_root('/root', 'its/here') == '/root/its/here' + + # windows + os.name = 'nt' + os.sep = '\\' + + def _isabs(path): + return path.startswith('c:\\') + + os.path.isabs = _isabs + + def _splitdrive(path): + if path.startswith('c:'): + return ('', path.replace('c:', '')) + return ('', path) + + os.path.splitdrive = _splitdrive + + def _join(*path): + return '\\'.join(path) + + os.path.join = _join + + assert ( + change_root('c:\\root', 'c:\\old\\its\\here') == 'c:\\root\\old\\its\\here' + ) + assert change_root('c:\\root', 'its\\here') == 'c:\\root\\its\\here' + + # BugsBunny os (it's a great os) + os.name = 'BugsBunny' + with pytest.raises(DistutilsPlatformError): + change_root('c:\\root', 'its\\here') + + # XXX platforms to be covered: mac + + def test_check_environ(self): + util.check_environ.cache_clear() + os.environ.pop('HOME', None) + + check_environ() + + assert os.environ['PLAT'] == get_platform() + + @pytest.mark.skipif("os.name != 'posix'") + def test_check_environ_getpwuid(self): + util.check_environ.cache_clear() + os.environ.pop('HOME', None) + + import pwd + + # only set pw_dir field, other fields are not used + result = pwd.struct_passwd(( + None, + None, + None, + None, + None, + '/home/distutils', + None, + )) + with mock.patch.object(pwd, 'getpwuid', return_value=result): + check_environ() + assert os.environ['HOME'] == '/home/distutils' + + util.check_environ.cache_clear() + os.environ.pop('HOME', None) + + # bpo-10496: Catch pwd.getpwuid() error + with mock.patch.object(pwd, 'getpwuid', side_effect=KeyError): + check_environ() + assert 'HOME' not in os.environ + + def test_split_quoted(self): + assert split_quoted('""one"" "two" \'three\' \\four') == [ + 'one', + 'two', + 'three', + 'four', + ] + + def test_strtobool(self): + yes = ('y', 'Y', 'yes', 'True', 't', 'true', 'True', 'On', 'on', '1') + no = ('n', 'no', 'f', 'false', 'off', '0', 'Off', 'No', 'N') + + for y in yes: + assert strtobool(y) + + for n in no: + assert not strtobool(n) + + indent = 8 * ' ' + + @pytest.mark.parametrize( + "given,wanted", + [ + # 0x0b, 0x0c, ..., etc are also considered a line break by Python + ("hello\x0b\nworld\n", f"hello\x0b{indent}\n{indent}world\n{indent}"), + ("hello\x1eworld", f"hello\x1e{indent}world"), + ("", ""), + ( + "I am a\npoor\nlonesome\nheader\n", + f"I am a\n{indent}poor\n{indent}lonesome\n{indent}header\n{indent}", + ), + ], + ) + def test_rfc822_escape(self, given, wanted): + """ + We want to ensure a multi-line header parses correctly. + + For interoperability, the escaped value should also "round-trip" over + `email.generator.Generator.flatten` and `email.message_from_*` + (see pypa/setuptools#4033). + + The main issue is that internally `email.policy.EmailPolicy` uses + `splitlines` which will split on some control chars. If all the new lines + are not prefixed with spaces, the parser will interrupt reading + the current header and produce an incomplete value, while + incorrectly interpreting the rest of the headers as part of the payload. + """ + res = rfc822_escape(given) + + policy = email.policy.EmailPolicy( + utf8=True, + mangle_from_=False, + max_line_length=0, + ) + with io.StringIO() as buffer: + raw = f"header: {res}\nother-header: 42\n\npayload\n" + orig = email.message_from_string(raw) + email.generator.Generator(buffer, policy=policy).flatten(orig) + buffer.seek(0) + regen = email.message_from_file(buffer) + + for msg in (orig, regen): + assert msg.get_payload() == "payload\n" + assert msg["other-header"] == "42" + # Generator may replace control chars with `\n` + assert set(msg["header"].splitlines()) == set(res.splitlines()) + + assert res == wanted + + def test_dont_write_bytecode(self): + # makes sure byte_compile raise a DistutilsError + # if sys.dont_write_bytecode is True + old_dont_write_bytecode = sys.dont_write_bytecode + sys.dont_write_bytecode = True + try: + with pytest.raises(DistutilsByteCompileError): + byte_compile([]) + finally: + sys.dont_write_bytecode = old_dont_write_bytecode + + def test_grok_environment_error(self): + # test obsolete function to ensure backward compat (#4931) + exc = OSError("Unable to find batch file") + msg = grok_environment_error(exc) + assert msg == "error: Unable to find batch file" diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_version.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_version.py new file mode 100644 index 0000000000000000000000000000000000000000..b68f0977249aa23aafbf31cf74a0e4127f777d05 --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/test_version.py @@ -0,0 +1,80 @@ +"""Tests for distutils.version.""" + +import distutils +from distutils.version import LooseVersion, StrictVersion + +import pytest + + +@pytest.fixture(autouse=True) +def suppress_deprecation(): + with distutils.version.suppress_known_deprecation(): + yield + + +class TestVersion: + def test_prerelease(self): + version = StrictVersion('1.2.3a1') + assert version.version == (1, 2, 3) + assert version.prerelease == ('a', 1) + assert str(version) == '1.2.3a1' + + version = StrictVersion('1.2.0') + assert str(version) == '1.2' + + def test_cmp_strict(self): + versions = ( + ('1.5.1', '1.5.2b2', -1), + ('161', '3.10a', ValueError), + ('8.02', '8.02', 0), + ('3.4j', '1996.07.12', ValueError), + ('3.2.pl0', '3.1.1.6', ValueError), + ('2g6', '11g', ValueError), + ('0.9', '2.2', -1), + ('1.2.1', '1.2', 1), + ('1.1', '1.2.2', -1), + ('1.2', '1.1', 1), + ('1.2.1', '1.2.2', -1), + ('1.2.2', '1.2', 1), + ('1.2', '1.2.2', -1), + ('0.4.0', '0.4', 0), + ('1.13++', '5.5.kw', ValueError), + ) + + for v1, v2, wanted in versions: + try: + res = StrictVersion(v1)._cmp(StrictVersion(v2)) + except ValueError: + if wanted is ValueError: + continue + else: + raise AssertionError(f"cmp({v1}, {v2}) shouldn't raise ValueError") + assert res == wanted, f'cmp({v1}, {v2}) should be {wanted}, got {res}' + res = StrictVersion(v1)._cmp(v2) + assert res == wanted, f'cmp({v1}, {v2}) should be {wanted}, got {res}' + res = StrictVersion(v1)._cmp(object()) + assert res is NotImplemented, ( + f'cmp({v1}, {v2}) should be NotImplemented, got {res}' + ) + + def test_cmp(self): + versions = ( + ('1.5.1', '1.5.2b2', -1), + ('161', '3.10a', 1), + ('8.02', '8.02', 0), + ('3.4j', '1996.07.12', -1), + ('3.2.pl0', '3.1.1.6', 1), + ('2g6', '11g', -1), + ('0.960923', '2.2beta29', -1), + ('1.13++', '5.5.kw', -1), + ) + + for v1, v2, wanted in versions: + res = LooseVersion(v1)._cmp(LooseVersion(v2)) + assert res == wanted, f'cmp({v1}, {v2}) should be {wanted}, got {res}' + res = LooseVersion(v1)._cmp(v2) + assert res == wanted, f'cmp({v1}, {v2}) should be {wanted}, got {res}' + res = LooseVersion(v1)._cmp(object()) + assert res is NotImplemented, ( + f'cmp({v1}, {v2}) should be NotImplemented, got {res}' + ) diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/test_versionpredicate.py b/python/Lib/site-packages/setuptools/_distutils/tests/test_versionpredicate.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/python/Lib/site-packages/setuptools/_distutils/tests/unix_compat.py b/python/Lib/site-packages/setuptools/_distutils/tests/unix_compat.py new file mode 100644 index 0000000000000000000000000000000000000000..a5d9ee45ccc639794d29ba0a5fd24f781ee5ecf5 --- /dev/null +++ b/python/Lib/site-packages/setuptools/_distutils/tests/unix_compat.py @@ -0,0 +1,17 @@ +import sys + +try: + import grp + import pwd +except ImportError: + grp = pwd = None + +import pytest + +UNIX_ID_SUPPORT = grp and pwd +UID_0_SUPPORT = UNIX_ID_SUPPORT and sys.platform != "cygwin" + +require_unix_id = pytest.mark.skipif( + not UNIX_ID_SUPPORT, reason="Requires grp and pwd support" +) +require_uid_0 = pytest.mark.skipif(not UID_0_SUPPORT, reason="Requires UID 0 support")