Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/__init__.py +23 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/bdist_rpm.py +597 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/build_py.py +404 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/build_scripts.py +150 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/check.py +152 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/install_data.py +94 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/install_scripts.py +59 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/__init__.py +42 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/support.py +134 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_archive_util.py +342 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_bdist.py +47 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_bdist_dumb.py +78 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_bdist_rpm.py +127 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_build.py +49 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_build_clib.py +134 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_build_ext.py +628 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_build_py.py +196 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_build_scripts.py +96 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_check.py +204 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_clean.py +45 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_cmd.py +107 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_config_cmd.py +87 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_core.py +130 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_dir_util.py +139 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_dist.py +552 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_extension.py +117 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_file_util.py +95 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_filelist.py +337 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_install.py +245 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_install_data.py +74 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_install_headers.py +33 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_install_lib.py +110 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_install_scripts.py +52 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_log.py +12 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_modified.py +126 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_sdist.py +470 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_spawn.py +141 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_sysconfig.py +319 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_text_file.py +127 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_util.py +236 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_version.py +80 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_versionpredicate.py +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/unix_compat.py +17 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/backports/tarfile/__init__.py +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/backports/tarfile/__main__.py +5 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/backports/tarfile/compat/__init__.py +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/backports/tarfile/compat/py38.py +24 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/licenses/LICENSE +73 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/importlib_metadata/compat/__init__.py +0 -0
- data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/importlib_metadata/compat/py311.py +22 -0
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/__init__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command
|
| 2 |
+
|
| 3 |
+
Package containing implementation of all the standard Distutils
|
| 4 |
+
commands."""
|
| 5 |
+
|
| 6 |
+
__all__ = [
|
| 7 |
+
'build',
|
| 8 |
+
'build_py',
|
| 9 |
+
'build_ext',
|
| 10 |
+
'build_clib',
|
| 11 |
+
'build_scripts',
|
| 12 |
+
'clean',
|
| 13 |
+
'install',
|
| 14 |
+
'install_lib',
|
| 15 |
+
'install_headers',
|
| 16 |
+
'install_scripts',
|
| 17 |
+
'install_data',
|
| 18 |
+
'sdist',
|
| 19 |
+
'bdist',
|
| 20 |
+
'bdist_dumb',
|
| 21 |
+
'bdist_rpm',
|
| 22 |
+
'check',
|
| 23 |
+
]
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/bdist_rpm.py
ADDED
|
@@ -0,0 +1,597 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.bdist_rpm
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'bdist_rpm' command (create RPM source and binary
|
| 4 |
+
distributions)."""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import subprocess
|
| 8 |
+
import sys
|
| 9 |
+
from distutils._log import log
|
| 10 |
+
from typing import ClassVar
|
| 11 |
+
|
| 12 |
+
from ..core import Command
|
| 13 |
+
from ..debug import DEBUG
|
| 14 |
+
from ..errors import (
|
| 15 |
+
DistutilsExecError,
|
| 16 |
+
DistutilsFileError,
|
| 17 |
+
DistutilsOptionError,
|
| 18 |
+
DistutilsPlatformError,
|
| 19 |
+
)
|
| 20 |
+
from ..file_util import write_file
|
| 21 |
+
from ..sysconfig import get_python_version
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class bdist_rpm(Command):
|
| 25 |
+
description = "create an RPM distribution"
|
| 26 |
+
|
| 27 |
+
user_options = [
|
| 28 |
+
('bdist-base=', None, "base directory for creating built distributions"),
|
| 29 |
+
(
|
| 30 |
+
'rpm-base=',
|
| 31 |
+
None,
|
| 32 |
+
"base directory for creating RPMs (defaults to \"rpm\" under "
|
| 33 |
+
"--bdist-base; must be specified for RPM 2)",
|
| 34 |
+
),
|
| 35 |
+
(
|
| 36 |
+
'dist-dir=',
|
| 37 |
+
'd',
|
| 38 |
+
"directory to put final RPM files in (and .spec files if --spec-only)",
|
| 39 |
+
),
|
| 40 |
+
(
|
| 41 |
+
'python=',
|
| 42 |
+
None,
|
| 43 |
+
"path to Python interpreter to hard-code in the .spec file "
|
| 44 |
+
"[default: \"python\"]",
|
| 45 |
+
),
|
| 46 |
+
(
|
| 47 |
+
'fix-python',
|
| 48 |
+
None,
|
| 49 |
+
"hard-code the exact path to the current Python interpreter in "
|
| 50 |
+
"the .spec file",
|
| 51 |
+
),
|
| 52 |
+
('spec-only', None, "only regenerate spec file"),
|
| 53 |
+
('source-only', None, "only generate source RPM"),
|
| 54 |
+
('binary-only', None, "only generate binary RPM"),
|
| 55 |
+
('use-bzip2', None, "use bzip2 instead of gzip to create source distribution"),
|
| 56 |
+
# More meta-data: too RPM-specific to put in the setup script,
|
| 57 |
+
# but needs to go in the .spec file -- so we make these options
|
| 58 |
+
# to "bdist_rpm". The idea is that packagers would put this
|
| 59 |
+
# info in setup.cfg, although they are of course free to
|
| 60 |
+
# supply it on the command line.
|
| 61 |
+
(
|
| 62 |
+
'distribution-name=',
|
| 63 |
+
None,
|
| 64 |
+
"name of the (Linux) distribution to which this "
|
| 65 |
+
"RPM applies (*not* the name of the module distribution!)",
|
| 66 |
+
),
|
| 67 |
+
('group=', None, "package classification [default: \"Development/Libraries\"]"),
|
| 68 |
+
('release=', None, "RPM release number"),
|
| 69 |
+
('serial=', None, "RPM serial number"),
|
| 70 |
+
(
|
| 71 |
+
'vendor=',
|
| 72 |
+
None,
|
| 73 |
+
"RPM \"vendor\" (eg. \"Joe Blow <joe@example.com>\") "
|
| 74 |
+
"[default: maintainer or author from setup script]",
|
| 75 |
+
),
|
| 76 |
+
(
|
| 77 |
+
'packager=',
|
| 78 |
+
None,
|
| 79 |
+
"RPM packager (eg. \"Jane Doe <jane@example.net>\") [default: vendor]",
|
| 80 |
+
),
|
| 81 |
+
('doc-files=', None, "list of documentation files (space or comma-separated)"),
|
| 82 |
+
('changelog=', None, "RPM changelog"),
|
| 83 |
+
('icon=', None, "name of icon file"),
|
| 84 |
+
('provides=', None, "capabilities provided by this package"),
|
| 85 |
+
('requires=', None, "capabilities required by this package"),
|
| 86 |
+
('conflicts=', None, "capabilities which conflict with this package"),
|
| 87 |
+
('build-requires=', None, "capabilities required to build this package"),
|
| 88 |
+
('obsoletes=', None, "capabilities made obsolete by this package"),
|
| 89 |
+
('no-autoreq', None, "do not automatically calculate dependencies"),
|
| 90 |
+
# Actions to take when building RPM
|
| 91 |
+
('keep-temp', 'k', "don't clean up RPM build directory"),
|
| 92 |
+
('no-keep-temp', None, "clean up RPM build directory [default]"),
|
| 93 |
+
(
|
| 94 |
+
'use-rpm-opt-flags',
|
| 95 |
+
None,
|
| 96 |
+
"compile with RPM_OPT_FLAGS when building from source RPM",
|
| 97 |
+
),
|
| 98 |
+
('no-rpm-opt-flags', None, "do not pass any RPM CFLAGS to compiler"),
|
| 99 |
+
('rpm3-mode', None, "RPM 3 compatibility mode (default)"),
|
| 100 |
+
('rpm2-mode', None, "RPM 2 compatibility mode"),
|
| 101 |
+
# Add the hooks necessary for specifying custom scripts
|
| 102 |
+
('prep-script=', None, "Specify a script for the PREP phase of RPM building"),
|
| 103 |
+
('build-script=', None, "Specify a script for the BUILD phase of RPM building"),
|
| 104 |
+
(
|
| 105 |
+
'pre-install=',
|
| 106 |
+
None,
|
| 107 |
+
"Specify a script for the pre-INSTALL phase of RPM building",
|
| 108 |
+
),
|
| 109 |
+
(
|
| 110 |
+
'install-script=',
|
| 111 |
+
None,
|
| 112 |
+
"Specify a script for the INSTALL phase of RPM building",
|
| 113 |
+
),
|
| 114 |
+
(
|
| 115 |
+
'post-install=',
|
| 116 |
+
None,
|
| 117 |
+
"Specify a script for the post-INSTALL phase of RPM building",
|
| 118 |
+
),
|
| 119 |
+
(
|
| 120 |
+
'pre-uninstall=',
|
| 121 |
+
None,
|
| 122 |
+
"Specify a script for the pre-UNINSTALL phase of RPM building",
|
| 123 |
+
),
|
| 124 |
+
(
|
| 125 |
+
'post-uninstall=',
|
| 126 |
+
None,
|
| 127 |
+
"Specify a script for the post-UNINSTALL phase of RPM building",
|
| 128 |
+
),
|
| 129 |
+
('clean-script=', None, "Specify a script for the CLEAN phase of RPM building"),
|
| 130 |
+
(
|
| 131 |
+
'verify-script=',
|
| 132 |
+
None,
|
| 133 |
+
"Specify a script for the VERIFY phase of the RPM build",
|
| 134 |
+
),
|
| 135 |
+
# Allow a packager to explicitly force an architecture
|
| 136 |
+
('force-arch=', None, "Force an architecture onto the RPM build process"),
|
| 137 |
+
('quiet', 'q', "Run the INSTALL phase of RPM building in quiet mode"),
|
| 138 |
+
]
|
| 139 |
+
|
| 140 |
+
boolean_options: ClassVar[list[str]] = [
|
| 141 |
+
'keep-temp',
|
| 142 |
+
'use-rpm-opt-flags',
|
| 143 |
+
'rpm3-mode',
|
| 144 |
+
'no-autoreq',
|
| 145 |
+
'quiet',
|
| 146 |
+
]
|
| 147 |
+
|
| 148 |
+
negative_opt: ClassVar[dict[str, str]] = {
|
| 149 |
+
'no-keep-temp': 'keep-temp',
|
| 150 |
+
'no-rpm-opt-flags': 'use-rpm-opt-flags',
|
| 151 |
+
'rpm2-mode': 'rpm3-mode',
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
def initialize_options(self):
|
| 155 |
+
self.bdist_base = None
|
| 156 |
+
self.rpm_base = None
|
| 157 |
+
self.dist_dir = None
|
| 158 |
+
self.python = None
|
| 159 |
+
self.fix_python = None
|
| 160 |
+
self.spec_only = None
|
| 161 |
+
self.binary_only = None
|
| 162 |
+
self.source_only = None
|
| 163 |
+
self.use_bzip2 = None
|
| 164 |
+
|
| 165 |
+
self.distribution_name = None
|
| 166 |
+
self.group = None
|
| 167 |
+
self.release = None
|
| 168 |
+
self.serial = None
|
| 169 |
+
self.vendor = None
|
| 170 |
+
self.packager = None
|
| 171 |
+
self.doc_files = None
|
| 172 |
+
self.changelog = None
|
| 173 |
+
self.icon = None
|
| 174 |
+
|
| 175 |
+
self.prep_script = None
|
| 176 |
+
self.build_script = None
|
| 177 |
+
self.install_script = None
|
| 178 |
+
self.clean_script = None
|
| 179 |
+
self.verify_script = None
|
| 180 |
+
self.pre_install = None
|
| 181 |
+
self.post_install = None
|
| 182 |
+
self.pre_uninstall = None
|
| 183 |
+
self.post_uninstall = None
|
| 184 |
+
self.prep = None
|
| 185 |
+
self.provides = None
|
| 186 |
+
self.requires = None
|
| 187 |
+
self.conflicts = None
|
| 188 |
+
self.build_requires = None
|
| 189 |
+
self.obsoletes = None
|
| 190 |
+
|
| 191 |
+
self.keep_temp = False
|
| 192 |
+
self.use_rpm_opt_flags = True
|
| 193 |
+
self.rpm3_mode = True
|
| 194 |
+
self.no_autoreq = False
|
| 195 |
+
|
| 196 |
+
self.force_arch = None
|
| 197 |
+
self.quiet = False
|
| 198 |
+
|
| 199 |
+
def finalize_options(self) -> None:
|
| 200 |
+
self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
|
| 201 |
+
if self.rpm_base is None:
|
| 202 |
+
if not self.rpm3_mode:
|
| 203 |
+
raise DistutilsOptionError("you must specify --rpm-base in RPM 2 mode")
|
| 204 |
+
self.rpm_base = os.path.join(self.bdist_base, "rpm")
|
| 205 |
+
|
| 206 |
+
if self.python is None:
|
| 207 |
+
if self.fix_python:
|
| 208 |
+
self.python = sys.executable
|
| 209 |
+
else:
|
| 210 |
+
self.python = "python3"
|
| 211 |
+
elif self.fix_python:
|
| 212 |
+
raise DistutilsOptionError(
|
| 213 |
+
"--python and --fix-python are mutually exclusive options"
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
if os.name != 'posix':
|
| 217 |
+
raise DistutilsPlatformError(
|
| 218 |
+
f"don't know how to create RPM distributions on platform {os.name}"
|
| 219 |
+
)
|
| 220 |
+
if self.binary_only and self.source_only:
|
| 221 |
+
raise DistutilsOptionError(
|
| 222 |
+
"cannot supply both '--source-only' and '--binary-only'"
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
# don't pass CFLAGS to pure python distributions
|
| 226 |
+
if not self.distribution.has_ext_modules():
|
| 227 |
+
self.use_rpm_opt_flags = False
|
| 228 |
+
|
| 229 |
+
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
|
| 230 |
+
self.finalize_package_data()
|
| 231 |
+
|
| 232 |
+
def finalize_package_data(self) -> None:
|
| 233 |
+
self.ensure_string('group', "Development/Libraries")
|
| 234 |
+
self.ensure_string(
|
| 235 |
+
'vendor',
|
| 236 |
+
f"{self.distribution.get_contact()} <{self.distribution.get_contact_email()}>",
|
| 237 |
+
)
|
| 238 |
+
self.ensure_string('packager')
|
| 239 |
+
self.ensure_string_list('doc_files')
|
| 240 |
+
if isinstance(self.doc_files, list):
|
| 241 |
+
for readme in ('README', 'README.txt'):
|
| 242 |
+
if os.path.exists(readme) and readme not in self.doc_files:
|
| 243 |
+
self.doc_files.append(readme)
|
| 244 |
+
|
| 245 |
+
self.ensure_string('release', "1")
|
| 246 |
+
self.ensure_string('serial') # should it be an int?
|
| 247 |
+
|
| 248 |
+
self.ensure_string('distribution_name')
|
| 249 |
+
|
| 250 |
+
self.ensure_string('changelog')
|
| 251 |
+
# Format changelog correctly
|
| 252 |
+
self.changelog = self._format_changelog(self.changelog)
|
| 253 |
+
|
| 254 |
+
self.ensure_filename('icon')
|
| 255 |
+
|
| 256 |
+
self.ensure_filename('prep_script')
|
| 257 |
+
self.ensure_filename('build_script')
|
| 258 |
+
self.ensure_filename('install_script')
|
| 259 |
+
self.ensure_filename('clean_script')
|
| 260 |
+
self.ensure_filename('verify_script')
|
| 261 |
+
self.ensure_filename('pre_install')
|
| 262 |
+
self.ensure_filename('post_install')
|
| 263 |
+
self.ensure_filename('pre_uninstall')
|
| 264 |
+
self.ensure_filename('post_uninstall')
|
| 265 |
+
|
| 266 |
+
# XXX don't forget we punted on summaries and descriptions -- they
|
| 267 |
+
# should be handled here eventually!
|
| 268 |
+
|
| 269 |
+
# Now *this* is some meta-data that belongs in the setup script...
|
| 270 |
+
self.ensure_string_list('provides')
|
| 271 |
+
self.ensure_string_list('requires')
|
| 272 |
+
self.ensure_string_list('conflicts')
|
| 273 |
+
self.ensure_string_list('build_requires')
|
| 274 |
+
self.ensure_string_list('obsoletes')
|
| 275 |
+
|
| 276 |
+
self.ensure_string('force_arch')
|
| 277 |
+
|
| 278 |
+
def run(self) -> None: # noqa: C901
|
| 279 |
+
if DEBUG:
|
| 280 |
+
print("before _get_package_data():")
|
| 281 |
+
print("vendor =", self.vendor)
|
| 282 |
+
print("packager =", self.packager)
|
| 283 |
+
print("doc_files =", self.doc_files)
|
| 284 |
+
print("changelog =", self.changelog)
|
| 285 |
+
|
| 286 |
+
# make directories
|
| 287 |
+
if self.spec_only:
|
| 288 |
+
spec_dir = self.dist_dir
|
| 289 |
+
self.mkpath(spec_dir)
|
| 290 |
+
else:
|
| 291 |
+
rpm_dir = {}
|
| 292 |
+
for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
|
| 293 |
+
rpm_dir[d] = os.path.join(self.rpm_base, d)
|
| 294 |
+
self.mkpath(rpm_dir[d])
|
| 295 |
+
spec_dir = rpm_dir['SPECS']
|
| 296 |
+
|
| 297 |
+
# Spec file goes into 'dist_dir' if '--spec-only specified',
|
| 298 |
+
# build/rpm.<plat> otherwise.
|
| 299 |
+
spec_path = os.path.join(spec_dir, f"{self.distribution.get_name()}.spec")
|
| 300 |
+
self.execute(
|
| 301 |
+
write_file, (spec_path, self._make_spec_file()), f"writing '{spec_path}'"
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
if self.spec_only: # stop if requested
|
| 305 |
+
return
|
| 306 |
+
|
| 307 |
+
# Make a source distribution and copy to SOURCES directory with
|
| 308 |
+
# optional icon.
|
| 309 |
+
saved_dist_files = self.distribution.dist_files[:]
|
| 310 |
+
sdist = self.reinitialize_command('sdist')
|
| 311 |
+
if self.use_bzip2:
|
| 312 |
+
sdist.formats = ['bztar']
|
| 313 |
+
else:
|
| 314 |
+
sdist.formats = ['gztar']
|
| 315 |
+
self.run_command('sdist')
|
| 316 |
+
self.distribution.dist_files = saved_dist_files
|
| 317 |
+
|
| 318 |
+
source = sdist.get_archive_files()[0]
|
| 319 |
+
source_dir = rpm_dir['SOURCES']
|
| 320 |
+
self.copy_file(source, source_dir)
|
| 321 |
+
|
| 322 |
+
if self.icon:
|
| 323 |
+
if os.path.exists(self.icon):
|
| 324 |
+
self.copy_file(self.icon, source_dir)
|
| 325 |
+
else:
|
| 326 |
+
raise DistutilsFileError(f"icon file '{self.icon}' does not exist")
|
| 327 |
+
|
| 328 |
+
# build package
|
| 329 |
+
log.info("building RPMs")
|
| 330 |
+
rpm_cmd = ['rpmbuild']
|
| 331 |
+
|
| 332 |
+
if self.source_only: # what kind of RPMs?
|
| 333 |
+
rpm_cmd.append('-bs')
|
| 334 |
+
elif self.binary_only:
|
| 335 |
+
rpm_cmd.append('-bb')
|
| 336 |
+
else:
|
| 337 |
+
rpm_cmd.append('-ba')
|
| 338 |
+
rpm_cmd.extend(['--define', f'__python {self.python}'])
|
| 339 |
+
if self.rpm3_mode:
|
| 340 |
+
rpm_cmd.extend(['--define', f'_topdir {os.path.abspath(self.rpm_base)}'])
|
| 341 |
+
if not self.keep_temp:
|
| 342 |
+
rpm_cmd.append('--clean')
|
| 343 |
+
|
| 344 |
+
if self.quiet:
|
| 345 |
+
rpm_cmd.append('--quiet')
|
| 346 |
+
|
| 347 |
+
rpm_cmd.append(spec_path)
|
| 348 |
+
# Determine the binary rpm names that should be built out of this spec
|
| 349 |
+
# file
|
| 350 |
+
# Note that some of these may not be really built (if the file
|
| 351 |
+
# list is empty)
|
| 352 |
+
nvr_string = "%{name}-%{version}-%{release}"
|
| 353 |
+
src_rpm = nvr_string + ".src.rpm"
|
| 354 |
+
non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
|
| 355 |
+
q_cmd = rf"rpm -q --qf '{src_rpm} {non_src_rpm}\n' --specfile '{spec_path}'"
|
| 356 |
+
|
| 357 |
+
out = os.popen(q_cmd)
|
| 358 |
+
try:
|
| 359 |
+
binary_rpms = []
|
| 360 |
+
source_rpm = None
|
| 361 |
+
while True:
|
| 362 |
+
line = out.readline()
|
| 363 |
+
if not line:
|
| 364 |
+
break
|
| 365 |
+
ell = line.strip().split()
|
| 366 |
+
assert len(ell) == 2
|
| 367 |
+
binary_rpms.append(ell[1])
|
| 368 |
+
# The source rpm is named after the first entry in the spec file
|
| 369 |
+
if source_rpm is None:
|
| 370 |
+
source_rpm = ell[0]
|
| 371 |
+
|
| 372 |
+
status = out.close()
|
| 373 |
+
if status:
|
| 374 |
+
raise DistutilsExecError(f"Failed to execute: {q_cmd!r}")
|
| 375 |
+
|
| 376 |
+
finally:
|
| 377 |
+
out.close()
|
| 378 |
+
|
| 379 |
+
self.spawn(rpm_cmd)
|
| 380 |
+
|
| 381 |
+
if self.distribution.has_ext_modules():
|
| 382 |
+
pyversion = get_python_version()
|
| 383 |
+
else:
|
| 384 |
+
pyversion = 'any'
|
| 385 |
+
|
| 386 |
+
if not self.binary_only:
|
| 387 |
+
srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
|
| 388 |
+
assert os.path.exists(srpm)
|
| 389 |
+
self.move_file(srpm, self.dist_dir)
|
| 390 |
+
filename = os.path.join(self.dist_dir, source_rpm)
|
| 391 |
+
self.distribution.dist_files.append(('bdist_rpm', pyversion, filename))
|
| 392 |
+
|
| 393 |
+
if not self.source_only:
|
| 394 |
+
for rpm in binary_rpms:
|
| 395 |
+
rpm = os.path.join(rpm_dir['RPMS'], rpm)
|
| 396 |
+
if os.path.exists(rpm):
|
| 397 |
+
self.move_file(rpm, self.dist_dir)
|
| 398 |
+
filename = os.path.join(self.dist_dir, os.path.basename(rpm))
|
| 399 |
+
self.distribution.dist_files.append((
|
| 400 |
+
'bdist_rpm',
|
| 401 |
+
pyversion,
|
| 402 |
+
filename,
|
| 403 |
+
))
|
| 404 |
+
|
| 405 |
+
def _dist_path(self, path):
|
| 406 |
+
return os.path.join(self.dist_dir, os.path.basename(path))
|
| 407 |
+
|
| 408 |
+
def _make_spec_file(self): # noqa: C901
|
| 409 |
+
"""Generate the text of an RPM spec file and return it as a
|
| 410 |
+
list of strings (one per line).
|
| 411 |
+
"""
|
| 412 |
+
# definitions and headers
|
| 413 |
+
spec_file = [
|
| 414 |
+
'%define name ' + self.distribution.get_name(),
|
| 415 |
+
'%define version ' + self.distribution.get_version().replace('-', '_'),
|
| 416 |
+
'%define unmangled_version ' + self.distribution.get_version(),
|
| 417 |
+
'%define release ' + self.release.replace('-', '_'),
|
| 418 |
+
'',
|
| 419 |
+
'Summary: ' + (self.distribution.get_description() or "UNKNOWN"),
|
| 420 |
+
]
|
| 421 |
+
|
| 422 |
+
# Workaround for #14443 which affects some RPM based systems such as
|
| 423 |
+
# RHEL6 (and probably derivatives)
|
| 424 |
+
vendor_hook = subprocess.getoutput('rpm --eval %{__os_install_post}')
|
| 425 |
+
# Generate a potential replacement value for __os_install_post (whilst
|
| 426 |
+
# normalizing the whitespace to simplify the test for whether the
|
| 427 |
+
# invocation of brp-python-bytecompile passes in __python):
|
| 428 |
+
vendor_hook = '\n'.join([
|
| 429 |
+
f' {line.strip()} \\' for line in vendor_hook.splitlines()
|
| 430 |
+
])
|
| 431 |
+
problem = "brp-python-bytecompile \\\n"
|
| 432 |
+
fixed = "brp-python-bytecompile %{__python} \\\n"
|
| 433 |
+
fixed_hook = vendor_hook.replace(problem, fixed)
|
| 434 |
+
if fixed_hook != vendor_hook:
|
| 435 |
+
spec_file.append('# Workaround for https://bugs.python.org/issue14443')
|
| 436 |
+
spec_file.append('%define __os_install_post ' + fixed_hook + '\n')
|
| 437 |
+
|
| 438 |
+
# put locale summaries into spec file
|
| 439 |
+
# XXX not supported for now (hard to put a dictionary
|
| 440 |
+
# in a config file -- arg!)
|
| 441 |
+
# for locale in self.summaries.keys():
|
| 442 |
+
# spec_file.append('Summary(%s): %s' % (locale,
|
| 443 |
+
# self.summaries[locale]))
|
| 444 |
+
|
| 445 |
+
spec_file.extend([
|
| 446 |
+
'Name: %{name}',
|
| 447 |
+
'Version: %{version}',
|
| 448 |
+
'Release: %{release}',
|
| 449 |
+
])
|
| 450 |
+
|
| 451 |
+
# XXX yuck! this filename is available from the "sdist" command,
|
| 452 |
+
# but only after it has run: and we create the spec file before
|
| 453 |
+
# running "sdist", in case of --spec-only.
|
| 454 |
+
if self.use_bzip2:
|
| 455 |
+
spec_file.append('Source0: %{name}-%{unmangled_version}.tar.bz2')
|
| 456 |
+
else:
|
| 457 |
+
spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz')
|
| 458 |
+
|
| 459 |
+
spec_file.extend([
|
| 460 |
+
'License: ' + (self.distribution.get_license() or "UNKNOWN"),
|
| 461 |
+
'Group: ' + self.group,
|
| 462 |
+
'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot',
|
| 463 |
+
'Prefix: %{_prefix}',
|
| 464 |
+
])
|
| 465 |
+
|
| 466 |
+
if not self.force_arch:
|
| 467 |
+
# noarch if no extension modules
|
| 468 |
+
if not self.distribution.has_ext_modules():
|
| 469 |
+
spec_file.append('BuildArch: noarch')
|
| 470 |
+
else:
|
| 471 |
+
spec_file.append(f'BuildArch: {self.force_arch}')
|
| 472 |
+
|
| 473 |
+
for field in (
|
| 474 |
+
'Vendor',
|
| 475 |
+
'Packager',
|
| 476 |
+
'Provides',
|
| 477 |
+
'Requires',
|
| 478 |
+
'Conflicts',
|
| 479 |
+
'Obsoletes',
|
| 480 |
+
):
|
| 481 |
+
val = getattr(self, field.lower())
|
| 482 |
+
if isinstance(val, list):
|
| 483 |
+
spec_file.append('{}: {}'.format(field, ' '.join(val)))
|
| 484 |
+
elif val is not None:
|
| 485 |
+
spec_file.append(f'{field}: {val}')
|
| 486 |
+
|
| 487 |
+
if self.distribution.get_url():
|
| 488 |
+
spec_file.append('Url: ' + self.distribution.get_url())
|
| 489 |
+
|
| 490 |
+
if self.distribution_name:
|
| 491 |
+
spec_file.append('Distribution: ' + self.distribution_name)
|
| 492 |
+
|
| 493 |
+
if self.build_requires:
|
| 494 |
+
spec_file.append('BuildRequires: ' + ' '.join(self.build_requires))
|
| 495 |
+
|
| 496 |
+
if self.icon:
|
| 497 |
+
spec_file.append('Icon: ' + os.path.basename(self.icon))
|
| 498 |
+
|
| 499 |
+
if self.no_autoreq:
|
| 500 |
+
spec_file.append('AutoReq: 0')
|
| 501 |
+
|
| 502 |
+
spec_file.extend([
|
| 503 |
+
'',
|
| 504 |
+
'%description',
|
| 505 |
+
self.distribution.get_long_description() or "",
|
| 506 |
+
])
|
| 507 |
+
|
| 508 |
+
# put locale descriptions into spec file
|
| 509 |
+
# XXX again, suppressed because config file syntax doesn't
|
| 510 |
+
# easily support this ;-(
|
| 511 |
+
# for locale in self.descriptions.keys():
|
| 512 |
+
# spec_file.extend([
|
| 513 |
+
# '',
|
| 514 |
+
# '%description -l ' + locale,
|
| 515 |
+
# self.descriptions[locale],
|
| 516 |
+
# ])
|
| 517 |
+
|
| 518 |
+
# rpm scripts
|
| 519 |
+
# figure out default build script
|
| 520 |
+
def_setup_call = f"{self.python} {os.path.basename(sys.argv[0])}"
|
| 521 |
+
def_build = f"{def_setup_call} build"
|
| 522 |
+
if self.use_rpm_opt_flags:
|
| 523 |
+
def_build = 'env CFLAGS="$RPM_OPT_FLAGS" ' + def_build
|
| 524 |
+
|
| 525 |
+
# insert contents of files
|
| 526 |
+
|
| 527 |
+
# XXX this is kind of misleading: user-supplied options are files
|
| 528 |
+
# that we open and interpolate into the spec file, but the defaults
|
| 529 |
+
# are just text that we drop in as-is. Hmmm.
|
| 530 |
+
|
| 531 |
+
install_cmd = f'{def_setup_call} install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES'
|
| 532 |
+
|
| 533 |
+
script_options = [
|
| 534 |
+
('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"),
|
| 535 |
+
('build', 'build_script', def_build),
|
| 536 |
+
('install', 'install_script', install_cmd),
|
| 537 |
+
('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"),
|
| 538 |
+
('verifyscript', 'verify_script', None),
|
| 539 |
+
('pre', 'pre_install', None),
|
| 540 |
+
('post', 'post_install', None),
|
| 541 |
+
('preun', 'pre_uninstall', None),
|
| 542 |
+
('postun', 'post_uninstall', None),
|
| 543 |
+
]
|
| 544 |
+
|
| 545 |
+
for rpm_opt, attr, default in script_options:
|
| 546 |
+
# Insert contents of file referred to, if no file is referred to
|
| 547 |
+
# use 'default' as contents of script
|
| 548 |
+
val = getattr(self, attr)
|
| 549 |
+
if val or default:
|
| 550 |
+
spec_file.extend([
|
| 551 |
+
'',
|
| 552 |
+
'%' + rpm_opt,
|
| 553 |
+
])
|
| 554 |
+
if val:
|
| 555 |
+
with open(val) as f:
|
| 556 |
+
spec_file.extend(f.read().split('\n'))
|
| 557 |
+
else:
|
| 558 |
+
spec_file.append(default)
|
| 559 |
+
|
| 560 |
+
# files section
|
| 561 |
+
spec_file.extend([
|
| 562 |
+
'',
|
| 563 |
+
'%files -f INSTALLED_FILES',
|
| 564 |
+
'%defattr(-,root,root)',
|
| 565 |
+
])
|
| 566 |
+
|
| 567 |
+
if self.doc_files:
|
| 568 |
+
spec_file.append('%doc ' + ' '.join(self.doc_files))
|
| 569 |
+
|
| 570 |
+
if self.changelog:
|
| 571 |
+
spec_file.extend([
|
| 572 |
+
'',
|
| 573 |
+
'%changelog',
|
| 574 |
+
])
|
| 575 |
+
spec_file.extend(self.changelog)
|
| 576 |
+
|
| 577 |
+
return spec_file
|
| 578 |
+
|
| 579 |
+
def _format_changelog(self, changelog):
|
| 580 |
+
"""Format the changelog correctly and convert it to a list of strings"""
|
| 581 |
+
if not changelog:
|
| 582 |
+
return changelog
|
| 583 |
+
new_changelog = []
|
| 584 |
+
for line in changelog.strip().split('\n'):
|
| 585 |
+
line = line.strip()
|
| 586 |
+
if line[0] == '*':
|
| 587 |
+
new_changelog.extend(['', line])
|
| 588 |
+
elif line[0] == '-':
|
| 589 |
+
new_changelog.append(line)
|
| 590 |
+
else:
|
| 591 |
+
new_changelog.append(' ' + line)
|
| 592 |
+
|
| 593 |
+
# strip trailing newline inserted by first changelog entry
|
| 594 |
+
if not new_changelog[0]:
|
| 595 |
+
del new_changelog[0]
|
| 596 |
+
|
| 597 |
+
return new_changelog
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/build_py.py
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.build_py
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'build_py' command."""
|
| 4 |
+
|
| 5 |
+
import glob
|
| 6 |
+
import importlib.util
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
from distutils._log import log
|
| 10 |
+
from typing import ClassVar
|
| 11 |
+
|
| 12 |
+
from ..core import Command
|
| 13 |
+
from ..errors import DistutilsFileError, DistutilsOptionError
|
| 14 |
+
from ..util import convert_path
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class build_py(Command):
|
| 18 |
+
description = "\"build\" pure Python modules (copy to build directory)"
|
| 19 |
+
|
| 20 |
+
user_options = [
|
| 21 |
+
('build-lib=', 'd', "directory to \"build\" (copy) to"),
|
| 22 |
+
('compile', 'c', "compile .py to .pyc"),
|
| 23 |
+
('no-compile', None, "don't compile .py files [default]"),
|
| 24 |
+
(
|
| 25 |
+
'optimize=',
|
| 26 |
+
'O',
|
| 27 |
+
"also compile with optimization: -O1 for \"python -O\", "
|
| 28 |
+
"-O2 for \"python -OO\", and -O0 to disable [default: -O0]",
|
| 29 |
+
),
|
| 30 |
+
('force', 'f', "forcibly build everything (ignore file timestamps)"),
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
boolean_options: ClassVar[list[str]] = ['compile', 'force']
|
| 34 |
+
negative_opt: ClassVar[dict[str, str]] = {'no-compile': 'compile'}
|
| 35 |
+
|
| 36 |
+
def initialize_options(self):
|
| 37 |
+
self.build_lib = None
|
| 38 |
+
self.py_modules = None
|
| 39 |
+
self.package = None
|
| 40 |
+
self.package_data = None
|
| 41 |
+
self.package_dir = None
|
| 42 |
+
self.compile = False
|
| 43 |
+
self.optimize = 0
|
| 44 |
+
self.force = None
|
| 45 |
+
|
| 46 |
+
def finalize_options(self) -> None:
|
| 47 |
+
self.set_undefined_options(
|
| 48 |
+
'build', ('build_lib', 'build_lib'), ('force', 'force')
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# Get the distribution options that are aliases for build_py
|
| 52 |
+
# options -- list of packages and list of modules.
|
| 53 |
+
self.packages = self.distribution.packages
|
| 54 |
+
self.py_modules = self.distribution.py_modules
|
| 55 |
+
self.package_data = self.distribution.package_data
|
| 56 |
+
self.package_dir = {}
|
| 57 |
+
if self.distribution.package_dir:
|
| 58 |
+
for name, path in self.distribution.package_dir.items():
|
| 59 |
+
self.package_dir[name] = convert_path(path)
|
| 60 |
+
self.data_files = self.get_data_files()
|
| 61 |
+
|
| 62 |
+
# Ick, copied straight from install_lib.py (fancy_getopt needs a
|
| 63 |
+
# type system! Hell, *everything* needs a type system!!!)
|
| 64 |
+
if not isinstance(self.optimize, int):
|
| 65 |
+
try:
|
| 66 |
+
self.optimize = int(self.optimize)
|
| 67 |
+
assert 0 <= self.optimize <= 2
|
| 68 |
+
except (ValueError, AssertionError):
|
| 69 |
+
raise DistutilsOptionError("optimize must be 0, 1, or 2")
|
| 70 |
+
|
| 71 |
+
def run(self) -> None:
|
| 72 |
+
# XXX copy_file by default preserves atime and mtime. IMHO this is
|
| 73 |
+
# the right thing to do, but perhaps it should be an option -- in
|
| 74 |
+
# particular, a site administrator might want installed files to
|
| 75 |
+
# reflect the time of installation rather than the last
|
| 76 |
+
# modification time before the installed release.
|
| 77 |
+
|
| 78 |
+
# XXX copy_file by default preserves mode, which appears to be the
|
| 79 |
+
# wrong thing to do: if a file is read-only in the working
|
| 80 |
+
# directory, we want it to be installed read/write so that the next
|
| 81 |
+
# installation of the same module distribution can overwrite it
|
| 82 |
+
# without problems. (This might be a Unix-specific issue.) Thus
|
| 83 |
+
# we turn off 'preserve_mode' when copying to the build directory,
|
| 84 |
+
# since the build directory is supposed to be exactly what the
|
| 85 |
+
# installation will look like (ie. we preserve mode when
|
| 86 |
+
# installing).
|
| 87 |
+
|
| 88 |
+
# Two options control which modules will be installed: 'packages'
|
| 89 |
+
# and 'py_modules'. The former lets us work with whole packages, not
|
| 90 |
+
# specifying individual modules at all; the latter is for
|
| 91 |
+
# specifying modules one-at-a-time.
|
| 92 |
+
|
| 93 |
+
if self.py_modules:
|
| 94 |
+
self.build_modules()
|
| 95 |
+
if self.packages:
|
| 96 |
+
self.build_packages()
|
| 97 |
+
self.build_package_data()
|
| 98 |
+
|
| 99 |
+
self.byte_compile(self.get_outputs(include_bytecode=False))
|
| 100 |
+
|
| 101 |
+
def get_data_files(self):
|
| 102 |
+
"""Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
|
| 103 |
+
data = []
|
| 104 |
+
if not self.packages:
|
| 105 |
+
return data
|
| 106 |
+
for package in self.packages:
|
| 107 |
+
# Locate package source directory
|
| 108 |
+
src_dir = self.get_package_dir(package)
|
| 109 |
+
|
| 110 |
+
# Compute package build directory
|
| 111 |
+
build_dir = os.path.join(*([self.build_lib] + package.split('.')))
|
| 112 |
+
|
| 113 |
+
# Length of path to strip from found files
|
| 114 |
+
plen = 0
|
| 115 |
+
if src_dir:
|
| 116 |
+
plen = len(src_dir) + 1
|
| 117 |
+
|
| 118 |
+
# Strip directory from globbed filenames
|
| 119 |
+
filenames = [file[plen:] for file in self.find_data_files(package, src_dir)]
|
| 120 |
+
data.append((package, src_dir, build_dir, filenames))
|
| 121 |
+
return data
|
| 122 |
+
|
| 123 |
+
def find_data_files(self, package, src_dir):
|
| 124 |
+
"""Return filenames for package's data files in 'src_dir'"""
|
| 125 |
+
globs = self.package_data.get('', []) + self.package_data.get(package, [])
|
| 126 |
+
files = []
|
| 127 |
+
for pattern in globs:
|
| 128 |
+
# Each pattern has to be converted to a platform-specific path
|
| 129 |
+
filelist = glob.glob(
|
| 130 |
+
os.path.join(glob.escape(src_dir), convert_path(pattern))
|
| 131 |
+
)
|
| 132 |
+
# Files that match more than one pattern are only added once
|
| 133 |
+
files.extend([
|
| 134 |
+
fn for fn in filelist if fn not in files and os.path.isfile(fn)
|
| 135 |
+
])
|
| 136 |
+
return files
|
| 137 |
+
|
| 138 |
+
def build_package_data(self) -> None:
|
| 139 |
+
"""Copy data files into build directory"""
|
| 140 |
+
for _package, src_dir, build_dir, filenames in self.data_files:
|
| 141 |
+
for filename in filenames:
|
| 142 |
+
target = os.path.join(build_dir, filename)
|
| 143 |
+
self.mkpath(os.path.dirname(target))
|
| 144 |
+
self.copy_file(
|
| 145 |
+
os.path.join(src_dir, filename), target, preserve_mode=False
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
def get_package_dir(self, package):
|
| 149 |
+
"""Return the directory, relative to the top of the source
|
| 150 |
+
distribution, where package 'package' should be found
|
| 151 |
+
(at least according to the 'package_dir' option, if any)."""
|
| 152 |
+
path = package.split('.')
|
| 153 |
+
|
| 154 |
+
if not self.package_dir:
|
| 155 |
+
if path:
|
| 156 |
+
return os.path.join(*path)
|
| 157 |
+
else:
|
| 158 |
+
return ''
|
| 159 |
+
else:
|
| 160 |
+
tail = []
|
| 161 |
+
while path:
|
| 162 |
+
try:
|
| 163 |
+
pdir = self.package_dir['.'.join(path)]
|
| 164 |
+
except KeyError:
|
| 165 |
+
tail.insert(0, path[-1])
|
| 166 |
+
del path[-1]
|
| 167 |
+
else:
|
| 168 |
+
tail.insert(0, pdir)
|
| 169 |
+
return os.path.join(*tail)
|
| 170 |
+
else:
|
| 171 |
+
# Oops, got all the way through 'path' without finding a
|
| 172 |
+
# match in package_dir. If package_dir defines a directory
|
| 173 |
+
# for the root (nameless) package, then fallback on it;
|
| 174 |
+
# otherwise, we might as well have not consulted
|
| 175 |
+
# package_dir at all, as we just use the directory implied
|
| 176 |
+
# by 'tail' (which should be the same as the original value
|
| 177 |
+
# of 'path' at this point).
|
| 178 |
+
pdir = self.package_dir.get('')
|
| 179 |
+
if pdir is not None:
|
| 180 |
+
tail.insert(0, pdir)
|
| 181 |
+
|
| 182 |
+
if tail:
|
| 183 |
+
return os.path.join(*tail)
|
| 184 |
+
else:
|
| 185 |
+
return ''
|
| 186 |
+
|
| 187 |
+
def check_package(self, package, package_dir):
|
| 188 |
+
# Empty dir name means current directory, which we can probably
|
| 189 |
+
# assume exists. Also, os.path.exists and isdir don't know about
|
| 190 |
+
# my "empty string means current dir" convention, so we have to
|
| 191 |
+
# circumvent them.
|
| 192 |
+
if package_dir != "":
|
| 193 |
+
if not os.path.exists(package_dir):
|
| 194 |
+
raise DistutilsFileError(
|
| 195 |
+
f"package directory '{package_dir}' does not exist"
|
| 196 |
+
)
|
| 197 |
+
if not os.path.isdir(package_dir):
|
| 198 |
+
raise DistutilsFileError(
|
| 199 |
+
f"supposed package directory '{package_dir}' exists, "
|
| 200 |
+
"but is not a directory"
|
| 201 |
+
)
|
| 202 |
+
|
| 203 |
+
# Directories without __init__.py are namespace packages (PEP 420).
|
| 204 |
+
if package:
|
| 205 |
+
init_py = os.path.join(package_dir, "__init__.py")
|
| 206 |
+
if os.path.isfile(init_py):
|
| 207 |
+
return init_py
|
| 208 |
+
|
| 209 |
+
# Either not in a package at all (__init__.py not expected), or
|
| 210 |
+
# __init__.py doesn't exist -- so don't return the filename.
|
| 211 |
+
return None
|
| 212 |
+
|
| 213 |
+
def check_module(self, module, module_file):
|
| 214 |
+
if not os.path.isfile(module_file):
|
| 215 |
+
log.warning("file %s (for module %s) not found", module_file, module)
|
| 216 |
+
return False
|
| 217 |
+
else:
|
| 218 |
+
return True
|
| 219 |
+
|
| 220 |
+
def find_package_modules(self, package, package_dir):
|
| 221 |
+
self.check_package(package, package_dir)
|
| 222 |
+
module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py"))
|
| 223 |
+
modules = []
|
| 224 |
+
setup_script = os.path.abspath(self.distribution.script_name)
|
| 225 |
+
|
| 226 |
+
for f in module_files:
|
| 227 |
+
abs_f = os.path.abspath(f)
|
| 228 |
+
if abs_f != setup_script:
|
| 229 |
+
module = os.path.splitext(os.path.basename(f))[0]
|
| 230 |
+
modules.append((package, module, f))
|
| 231 |
+
else:
|
| 232 |
+
self.debug_print(f"excluding {setup_script}")
|
| 233 |
+
return modules
|
| 234 |
+
|
| 235 |
+
def find_modules(self):
|
| 236 |
+
"""Finds individually-specified Python modules, ie. those listed by
|
| 237 |
+
module name in 'self.py_modules'. Returns a list of tuples (package,
|
| 238 |
+
module_base, filename): 'package' is a tuple of the path through
|
| 239 |
+
package-space to the module; 'module_base' is the bare (no
|
| 240 |
+
packages, no dots) module name, and 'filename' is the path to the
|
| 241 |
+
".py" file (relative to the distribution root) that implements the
|
| 242 |
+
module.
|
| 243 |
+
"""
|
| 244 |
+
# Map package names to tuples of useful info about the package:
|
| 245 |
+
# (package_dir, checked)
|
| 246 |
+
# package_dir - the directory where we'll find source files for
|
| 247 |
+
# this package
|
| 248 |
+
# checked - true if we have checked that the package directory
|
| 249 |
+
# is valid (exists, contains __init__.py, ... ?)
|
| 250 |
+
packages = {}
|
| 251 |
+
|
| 252 |
+
# List of (package, module, filename) tuples to return
|
| 253 |
+
modules = []
|
| 254 |
+
|
| 255 |
+
# We treat modules-in-packages almost the same as toplevel modules,
|
| 256 |
+
# just the "package" for a toplevel is empty (either an empty
|
| 257 |
+
# string or empty list, depending on context). Differences:
|
| 258 |
+
# - don't check for __init__.py in directory for empty package
|
| 259 |
+
for module in self.py_modules:
|
| 260 |
+
path = module.split('.')
|
| 261 |
+
package = '.'.join(path[0:-1])
|
| 262 |
+
module_base = path[-1]
|
| 263 |
+
|
| 264 |
+
try:
|
| 265 |
+
(package_dir, checked) = packages[package]
|
| 266 |
+
except KeyError:
|
| 267 |
+
package_dir = self.get_package_dir(package)
|
| 268 |
+
checked = False
|
| 269 |
+
|
| 270 |
+
if not checked:
|
| 271 |
+
init_py = self.check_package(package, package_dir)
|
| 272 |
+
packages[package] = (package_dir, 1)
|
| 273 |
+
if init_py:
|
| 274 |
+
modules.append((package, "__init__", init_py))
|
| 275 |
+
|
| 276 |
+
# XXX perhaps we should also check for just .pyc files
|
| 277 |
+
# (so greedy closed-source bastards can distribute Python
|
| 278 |
+
# modules too)
|
| 279 |
+
module_file = os.path.join(package_dir, module_base + ".py")
|
| 280 |
+
if not self.check_module(module, module_file):
|
| 281 |
+
continue
|
| 282 |
+
|
| 283 |
+
modules.append((package, module_base, module_file))
|
| 284 |
+
|
| 285 |
+
return modules
|
| 286 |
+
|
| 287 |
+
def find_all_modules(self):
|
| 288 |
+
"""Compute the list of all modules that will be built, whether
|
| 289 |
+
they are specified one-module-at-a-time ('self.py_modules') or
|
| 290 |
+
by whole packages ('self.packages'). Return a list of tuples
|
| 291 |
+
(package, module, module_file), just like 'find_modules()' and
|
| 292 |
+
'find_package_modules()' do."""
|
| 293 |
+
modules = []
|
| 294 |
+
if self.py_modules:
|
| 295 |
+
modules.extend(self.find_modules())
|
| 296 |
+
if self.packages:
|
| 297 |
+
for package in self.packages:
|
| 298 |
+
package_dir = self.get_package_dir(package)
|
| 299 |
+
m = self.find_package_modules(package, package_dir)
|
| 300 |
+
modules.extend(m)
|
| 301 |
+
return modules
|
| 302 |
+
|
| 303 |
+
def get_source_files(self):
|
| 304 |
+
return [module[-1] for module in self.find_all_modules()]
|
| 305 |
+
|
| 306 |
+
def get_module_outfile(self, build_dir, package, module):
|
| 307 |
+
outfile_path = [build_dir] + list(package) + [module + ".py"]
|
| 308 |
+
return os.path.join(*outfile_path)
|
| 309 |
+
|
| 310 |
+
def get_outputs(self, include_bytecode: bool = True) -> list[str]:
|
| 311 |
+
modules = self.find_all_modules()
|
| 312 |
+
outputs = []
|
| 313 |
+
for package, module, _module_file in modules:
|
| 314 |
+
package = package.split('.')
|
| 315 |
+
filename = self.get_module_outfile(self.build_lib, package, module)
|
| 316 |
+
outputs.append(filename)
|
| 317 |
+
if include_bytecode:
|
| 318 |
+
if self.compile:
|
| 319 |
+
outputs.append(
|
| 320 |
+
importlib.util.cache_from_source(filename, optimization='')
|
| 321 |
+
)
|
| 322 |
+
if self.optimize > 0:
|
| 323 |
+
outputs.append(
|
| 324 |
+
importlib.util.cache_from_source(
|
| 325 |
+
filename, optimization=self.optimize
|
| 326 |
+
)
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
+
outputs += [
|
| 330 |
+
os.path.join(build_dir, filename)
|
| 331 |
+
for package, src_dir, build_dir, filenames in self.data_files
|
| 332 |
+
for filename in filenames
|
| 333 |
+
]
|
| 334 |
+
|
| 335 |
+
return outputs
|
| 336 |
+
|
| 337 |
+
def build_module(self, module, module_file, package):
|
| 338 |
+
if isinstance(package, str):
|
| 339 |
+
package = package.split('.')
|
| 340 |
+
elif not isinstance(package, (list, tuple)):
|
| 341 |
+
raise TypeError(
|
| 342 |
+
"'package' must be a string (dot-separated), list, or tuple"
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
# Now put the module source file into the "build" area -- this is
|
| 346 |
+
# easy, we just copy it somewhere under self.build_lib (the build
|
| 347 |
+
# directory for Python source).
|
| 348 |
+
outfile = self.get_module_outfile(self.build_lib, package, module)
|
| 349 |
+
dir = os.path.dirname(outfile)
|
| 350 |
+
self.mkpath(dir)
|
| 351 |
+
return self.copy_file(module_file, outfile, preserve_mode=False)
|
| 352 |
+
|
| 353 |
+
def build_modules(self) -> None:
|
| 354 |
+
modules = self.find_modules()
|
| 355 |
+
for package, module, module_file in modules:
|
| 356 |
+
# Now "build" the module -- ie. copy the source file to
|
| 357 |
+
# self.build_lib (the build directory for Python source).
|
| 358 |
+
# (Actually, it gets copied to the directory for this package
|
| 359 |
+
# under self.build_lib.)
|
| 360 |
+
self.build_module(module, module_file, package)
|
| 361 |
+
|
| 362 |
+
def build_packages(self) -> None:
|
| 363 |
+
for package in self.packages:
|
| 364 |
+
# Get list of (package, module, module_file) tuples based on
|
| 365 |
+
# scanning the package directory. 'package' is only included
|
| 366 |
+
# in the tuple so that 'find_modules()' and
|
| 367 |
+
# 'find_package_tuples()' have a consistent interface; it's
|
| 368 |
+
# ignored here (apart from a sanity check). Also, 'module' is
|
| 369 |
+
# the *unqualified* module name (ie. no dots, no package -- we
|
| 370 |
+
# already know its package!), and 'module_file' is the path to
|
| 371 |
+
# the .py file, relative to the current directory
|
| 372 |
+
# (ie. including 'package_dir').
|
| 373 |
+
package_dir = self.get_package_dir(package)
|
| 374 |
+
modules = self.find_package_modules(package, package_dir)
|
| 375 |
+
|
| 376 |
+
# Now loop over the modules we found, "building" each one (just
|
| 377 |
+
# copy it to self.build_lib).
|
| 378 |
+
for package_, module, module_file in modules:
|
| 379 |
+
assert package == package_
|
| 380 |
+
self.build_module(module, module_file, package)
|
| 381 |
+
|
| 382 |
+
def byte_compile(self, files) -> None:
|
| 383 |
+
if sys.dont_write_bytecode:
|
| 384 |
+
self.warn('byte-compiling is disabled, skipping.')
|
| 385 |
+
return
|
| 386 |
+
|
| 387 |
+
from ..util import byte_compile
|
| 388 |
+
|
| 389 |
+
prefix = self.build_lib
|
| 390 |
+
if prefix[-1] != os.sep:
|
| 391 |
+
prefix = prefix + os.sep
|
| 392 |
+
|
| 393 |
+
# XXX this code is essentially the same as the 'byte_compile()
|
| 394 |
+
# method of the "install_lib" command, except for the determination
|
| 395 |
+
# of the 'prefix' string. Hmmm.
|
| 396 |
+
if self.compile:
|
| 397 |
+
byte_compile(files, optimize=0, force=self.force, prefix=prefix)
|
| 398 |
+
if self.optimize > 0:
|
| 399 |
+
byte_compile(
|
| 400 |
+
files,
|
| 401 |
+
optimize=self.optimize,
|
| 402 |
+
force=self.force,
|
| 403 |
+
prefix=prefix,
|
| 404 |
+
)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/build_scripts.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.build_scripts
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'build_scripts' command."""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import re
|
| 7 |
+
import tokenize
|
| 8 |
+
from distutils._log import log
|
| 9 |
+
from stat import ST_MODE
|
| 10 |
+
from typing import ClassVar
|
| 11 |
+
|
| 12 |
+
from .._modified import newer
|
| 13 |
+
from ..core import Command
|
| 14 |
+
from ..util import convert_path
|
| 15 |
+
|
| 16 |
+
shebang_pattern = re.compile('^#!.*python[0-9.]*([ \t].*)?$')
|
| 17 |
+
"""
|
| 18 |
+
Pattern matching a Python interpreter indicated in first line of a script.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
# for Setuptools compatibility
|
| 22 |
+
first_line_re = shebang_pattern
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class build_scripts(Command):
|
| 26 |
+
description = "\"build\" scripts (copy and fixup #! line)"
|
| 27 |
+
|
| 28 |
+
user_options: ClassVar[list[tuple[str, str, str]]] = [
|
| 29 |
+
('build-dir=', 'd', "directory to \"build\" (copy) to"),
|
| 30 |
+
('force', 'f', "forcibly build everything (ignore file timestamps"),
|
| 31 |
+
('executable=', 'e', "specify final destination interpreter path"),
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
boolean_options: ClassVar[list[str]] = ['force']
|
| 35 |
+
|
| 36 |
+
def initialize_options(self):
|
| 37 |
+
self.build_dir = None
|
| 38 |
+
self.scripts = None
|
| 39 |
+
self.force = None
|
| 40 |
+
self.executable = None
|
| 41 |
+
|
| 42 |
+
def finalize_options(self):
|
| 43 |
+
self.set_undefined_options(
|
| 44 |
+
'build',
|
| 45 |
+
('build_scripts', 'build_dir'),
|
| 46 |
+
('force', 'force'),
|
| 47 |
+
('executable', 'executable'),
|
| 48 |
+
)
|
| 49 |
+
self.scripts = self.distribution.scripts
|
| 50 |
+
|
| 51 |
+
def get_source_files(self):
|
| 52 |
+
return self.scripts
|
| 53 |
+
|
| 54 |
+
def run(self):
|
| 55 |
+
if not self.scripts:
|
| 56 |
+
return
|
| 57 |
+
self.copy_scripts()
|
| 58 |
+
|
| 59 |
+
def copy_scripts(self):
|
| 60 |
+
"""
|
| 61 |
+
Copy each script listed in ``self.scripts``.
|
| 62 |
+
|
| 63 |
+
If a script is marked as a Python script (first line matches
|
| 64 |
+
'shebang_pattern', i.e. starts with ``#!`` and contains
|
| 65 |
+
"python"), then adjust in the copy the first line to refer to
|
| 66 |
+
the current Python interpreter.
|
| 67 |
+
"""
|
| 68 |
+
self.mkpath(self.build_dir)
|
| 69 |
+
outfiles = []
|
| 70 |
+
updated_files = []
|
| 71 |
+
for script in self.scripts:
|
| 72 |
+
self._copy_script(script, outfiles, updated_files)
|
| 73 |
+
|
| 74 |
+
self._change_modes(outfiles)
|
| 75 |
+
|
| 76 |
+
return outfiles, updated_files
|
| 77 |
+
|
| 78 |
+
def _copy_script(self, script, outfiles, updated_files):
|
| 79 |
+
shebang_match = None
|
| 80 |
+
script = convert_path(script)
|
| 81 |
+
outfile = os.path.join(self.build_dir, os.path.basename(script))
|
| 82 |
+
outfiles.append(outfile)
|
| 83 |
+
|
| 84 |
+
if not self.force and not newer(script, outfile):
|
| 85 |
+
log.debug("not copying %s (up-to-date)", script)
|
| 86 |
+
return
|
| 87 |
+
|
| 88 |
+
# Always open the file, but ignore failures in dry-run mode
|
| 89 |
+
# in order to attempt to copy directly.
|
| 90 |
+
f = tokenize.open(script)
|
| 91 |
+
|
| 92 |
+
first_line = f.readline()
|
| 93 |
+
if not first_line:
|
| 94 |
+
self.warn(f"{script} is an empty file (skipping)")
|
| 95 |
+
return
|
| 96 |
+
|
| 97 |
+
shebang_match = shebang_pattern.match(first_line)
|
| 98 |
+
|
| 99 |
+
updated_files.append(outfile)
|
| 100 |
+
if shebang_match:
|
| 101 |
+
log.info("copying and adjusting %s -> %s", script, self.build_dir)
|
| 102 |
+
post_interp = shebang_match.group(1) or ''
|
| 103 |
+
shebang = "#!" + self.executable + post_interp + "\n"
|
| 104 |
+
self._validate_shebang(shebang, f.encoding)
|
| 105 |
+
with open(outfile, "w", encoding=f.encoding) as outf:
|
| 106 |
+
outf.write(shebang)
|
| 107 |
+
outf.writelines(f.readlines())
|
| 108 |
+
if f:
|
| 109 |
+
f.close()
|
| 110 |
+
else:
|
| 111 |
+
if f:
|
| 112 |
+
f.close()
|
| 113 |
+
self.copy_file(script, outfile)
|
| 114 |
+
|
| 115 |
+
def _change_modes(self, outfiles):
|
| 116 |
+
if os.name != 'posix':
|
| 117 |
+
return
|
| 118 |
+
|
| 119 |
+
for file in outfiles:
|
| 120 |
+
self._change_mode(file)
|
| 121 |
+
|
| 122 |
+
def _change_mode(self, file):
|
| 123 |
+
oldmode = os.stat(file)[ST_MODE] & 0o7777
|
| 124 |
+
newmode = (oldmode | 0o555) & 0o7777
|
| 125 |
+
if newmode != oldmode:
|
| 126 |
+
log.info("changing mode of %s from %o to %o", file, oldmode, newmode)
|
| 127 |
+
os.chmod(file, newmode)
|
| 128 |
+
|
| 129 |
+
@staticmethod
|
| 130 |
+
def _validate_shebang(shebang, encoding):
|
| 131 |
+
# Python parser starts to read a script using UTF-8 until
|
| 132 |
+
# it gets a #coding:xxx cookie. The shebang has to be the
|
| 133 |
+
# first line of a file, the #coding:xxx cookie cannot be
|
| 134 |
+
# written before. So the shebang has to be encodable to
|
| 135 |
+
# UTF-8.
|
| 136 |
+
try:
|
| 137 |
+
shebang.encode('utf-8')
|
| 138 |
+
except UnicodeEncodeError:
|
| 139 |
+
raise ValueError(f"The shebang ({shebang!r}) is not encodable to utf-8")
|
| 140 |
+
|
| 141 |
+
# If the script is encoded to a custom encoding (use a
|
| 142 |
+
# #coding:xxx cookie), the shebang has to be encodable to
|
| 143 |
+
# the script encoding too.
|
| 144 |
+
try:
|
| 145 |
+
shebang.encode(encoding)
|
| 146 |
+
except UnicodeEncodeError:
|
| 147 |
+
raise ValueError(
|
| 148 |
+
f"The shebang ({shebang!r}) is not encodable "
|
| 149 |
+
f"to the script encoding ({encoding})"
|
| 150 |
+
)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/check.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.check
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'check' command.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import contextlib
|
| 7 |
+
from typing import ClassVar
|
| 8 |
+
|
| 9 |
+
from ..core import Command
|
| 10 |
+
from ..errors import DistutilsSetupError
|
| 11 |
+
|
| 12 |
+
with contextlib.suppress(ImportError):
|
| 13 |
+
import docutils.frontend
|
| 14 |
+
import docutils.nodes
|
| 15 |
+
import docutils.parsers.rst
|
| 16 |
+
import docutils.utils
|
| 17 |
+
|
| 18 |
+
class SilentReporter(docutils.utils.Reporter):
|
| 19 |
+
def __init__(
|
| 20 |
+
self,
|
| 21 |
+
source,
|
| 22 |
+
report_level,
|
| 23 |
+
halt_level,
|
| 24 |
+
stream=None,
|
| 25 |
+
debug=False,
|
| 26 |
+
encoding='ascii',
|
| 27 |
+
error_handler='replace',
|
| 28 |
+
):
|
| 29 |
+
self.messages = []
|
| 30 |
+
super().__init__(
|
| 31 |
+
source, report_level, halt_level, stream, debug, encoding, error_handler
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
def system_message(self, level, message, *children, **kwargs):
|
| 35 |
+
self.messages.append((level, message, children, kwargs))
|
| 36 |
+
return docutils.nodes.system_message(
|
| 37 |
+
message, *children, level=level, type=self.levels[level], **kwargs
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class check(Command):
|
| 42 |
+
"""This command checks the meta-data of the package."""
|
| 43 |
+
|
| 44 |
+
description = "perform some checks on the package"
|
| 45 |
+
user_options: ClassVar[list[tuple[str, str, str]]] = [
|
| 46 |
+
('metadata', 'm', 'Verify meta-data'),
|
| 47 |
+
(
|
| 48 |
+
'restructuredtext',
|
| 49 |
+
'r',
|
| 50 |
+
'Checks if long string meta-data syntax are reStructuredText-compliant',
|
| 51 |
+
),
|
| 52 |
+
('strict', 's', 'Will exit with an error if a check fails'),
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
boolean_options: ClassVar[list[str]] = ['metadata', 'restructuredtext', 'strict']
|
| 56 |
+
|
| 57 |
+
def initialize_options(self):
|
| 58 |
+
"""Sets default values for options."""
|
| 59 |
+
self.restructuredtext = False
|
| 60 |
+
self.metadata = 1
|
| 61 |
+
self.strict = False
|
| 62 |
+
self._warnings = 0
|
| 63 |
+
|
| 64 |
+
def finalize_options(self):
|
| 65 |
+
pass
|
| 66 |
+
|
| 67 |
+
def warn(self, msg):
|
| 68 |
+
"""Counts the number of warnings that occurs."""
|
| 69 |
+
self._warnings += 1
|
| 70 |
+
return Command.warn(self, msg)
|
| 71 |
+
|
| 72 |
+
def run(self):
|
| 73 |
+
"""Runs the command."""
|
| 74 |
+
# perform the various tests
|
| 75 |
+
if self.metadata:
|
| 76 |
+
self.check_metadata()
|
| 77 |
+
if self.restructuredtext:
|
| 78 |
+
if 'docutils' in globals():
|
| 79 |
+
try:
|
| 80 |
+
self.check_restructuredtext()
|
| 81 |
+
except TypeError as exc:
|
| 82 |
+
raise DistutilsSetupError(str(exc))
|
| 83 |
+
elif self.strict:
|
| 84 |
+
raise DistutilsSetupError('The docutils package is needed.')
|
| 85 |
+
|
| 86 |
+
# let's raise an error in strict mode, if we have at least
|
| 87 |
+
# one warning
|
| 88 |
+
if self.strict and self._warnings > 0:
|
| 89 |
+
raise DistutilsSetupError('Please correct your package.')
|
| 90 |
+
|
| 91 |
+
def check_metadata(self):
|
| 92 |
+
"""Ensures that all required elements of meta-data are supplied.
|
| 93 |
+
|
| 94 |
+
Required fields:
|
| 95 |
+
name, version
|
| 96 |
+
|
| 97 |
+
Warns if any are missing.
|
| 98 |
+
"""
|
| 99 |
+
metadata = self.distribution.metadata
|
| 100 |
+
|
| 101 |
+
missing = [
|
| 102 |
+
attr for attr in ('name', 'version') if not getattr(metadata, attr, None)
|
| 103 |
+
]
|
| 104 |
+
|
| 105 |
+
if missing:
|
| 106 |
+
self.warn("missing required meta-data: {}".format(', '.join(missing)))
|
| 107 |
+
|
| 108 |
+
def check_restructuredtext(self):
|
| 109 |
+
"""Checks if the long string fields are reST-compliant."""
|
| 110 |
+
data = self.distribution.get_long_description()
|
| 111 |
+
for warning in self._check_rst_data(data):
|
| 112 |
+
line = warning[-1].get('line')
|
| 113 |
+
if line is None:
|
| 114 |
+
warning = warning[1]
|
| 115 |
+
else:
|
| 116 |
+
warning = f'{warning[1]} (line {line})'
|
| 117 |
+
self.warn(warning)
|
| 118 |
+
|
| 119 |
+
def _check_rst_data(self, data):
|
| 120 |
+
"""Returns warnings when the provided data doesn't compile."""
|
| 121 |
+
# the include and csv_table directives need this to be a path
|
| 122 |
+
source_path = self.distribution.script_name or 'setup.py'
|
| 123 |
+
parser = docutils.parsers.rst.Parser()
|
| 124 |
+
settings = docutils.frontend.OptionParser(
|
| 125 |
+
components=(docutils.parsers.rst.Parser,)
|
| 126 |
+
).get_default_values()
|
| 127 |
+
settings.tab_width = 4
|
| 128 |
+
settings.pep_references = None
|
| 129 |
+
settings.rfc_references = None
|
| 130 |
+
reporter = SilentReporter(
|
| 131 |
+
source_path,
|
| 132 |
+
settings.report_level,
|
| 133 |
+
settings.halt_level,
|
| 134 |
+
stream=settings.warning_stream,
|
| 135 |
+
debug=settings.debug,
|
| 136 |
+
encoding=settings.error_encoding,
|
| 137 |
+
error_handler=settings.error_encoding_error_handler,
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
document = docutils.nodes.document(settings, reporter, source=source_path)
|
| 141 |
+
document.note_source(source_path, -1)
|
| 142 |
+
try:
|
| 143 |
+
parser.parse(data, document)
|
| 144 |
+
except (AttributeError, TypeError) as e:
|
| 145 |
+
reporter.messages.append((
|
| 146 |
+
-1,
|
| 147 |
+
f'Could not finish the parsing: {e}.',
|
| 148 |
+
'',
|
| 149 |
+
{},
|
| 150 |
+
))
|
| 151 |
+
|
| 152 |
+
return reporter.messages
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/install_data.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.install_data
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'install_data' command, for installing
|
| 4 |
+
platform-independent data files."""
|
| 5 |
+
|
| 6 |
+
# contributed by Bastian Kleineidam
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import functools
|
| 11 |
+
import os
|
| 12 |
+
from collections.abc import Iterable
|
| 13 |
+
from typing import ClassVar
|
| 14 |
+
|
| 15 |
+
from ..core import Command
|
| 16 |
+
from ..util import change_root, convert_path
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class install_data(Command):
|
| 20 |
+
description = "install data files"
|
| 21 |
+
|
| 22 |
+
user_options = [
|
| 23 |
+
(
|
| 24 |
+
'install-dir=',
|
| 25 |
+
'd',
|
| 26 |
+
"base directory for installing data files [default: installation base dir]",
|
| 27 |
+
),
|
| 28 |
+
('root=', None, "install everything relative to this alternate root directory"),
|
| 29 |
+
('force', 'f', "force installation (overwrite existing files)"),
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
boolean_options: ClassVar[list[str]] = ['force']
|
| 33 |
+
|
| 34 |
+
def initialize_options(self):
|
| 35 |
+
self.install_dir = None
|
| 36 |
+
self.outfiles = []
|
| 37 |
+
self.root = None
|
| 38 |
+
self.force = False
|
| 39 |
+
self.data_files = self.distribution.data_files
|
| 40 |
+
self.warn_dir = True
|
| 41 |
+
|
| 42 |
+
def finalize_options(self) -> None:
|
| 43 |
+
self.set_undefined_options(
|
| 44 |
+
'install',
|
| 45 |
+
('install_data', 'install_dir'),
|
| 46 |
+
('root', 'root'),
|
| 47 |
+
('force', 'force'),
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
def run(self) -> None:
|
| 51 |
+
self.mkpath(self.install_dir)
|
| 52 |
+
for f in self.data_files:
|
| 53 |
+
self._copy(f)
|
| 54 |
+
|
| 55 |
+
@functools.singledispatchmethod
|
| 56 |
+
def _copy(self, f: tuple[str | os.PathLike, Iterable[str | os.PathLike]]):
|
| 57 |
+
# it's a tuple with path to install to and a list of files
|
| 58 |
+
dir = convert_path(f[0])
|
| 59 |
+
if not os.path.isabs(dir):
|
| 60 |
+
dir = os.path.join(self.install_dir, dir)
|
| 61 |
+
elif self.root:
|
| 62 |
+
dir = change_root(self.root, dir)
|
| 63 |
+
self.mkpath(dir)
|
| 64 |
+
|
| 65 |
+
if f[1] == []:
|
| 66 |
+
# If there are no files listed, the user must be
|
| 67 |
+
# trying to create an empty directory, so add the
|
| 68 |
+
# directory to the list of output files.
|
| 69 |
+
self.outfiles.append(dir)
|
| 70 |
+
else:
|
| 71 |
+
# Copy files, adding them to the list of output files.
|
| 72 |
+
for data in f[1]:
|
| 73 |
+
data = convert_path(data)
|
| 74 |
+
(out, _) = self.copy_file(data, dir)
|
| 75 |
+
self.outfiles.append(out)
|
| 76 |
+
|
| 77 |
+
@_copy.register(str)
|
| 78 |
+
@_copy.register(os.PathLike)
|
| 79 |
+
def _(self, f: str | os.PathLike):
|
| 80 |
+
# it's a simple file, so copy it
|
| 81 |
+
f = convert_path(f)
|
| 82 |
+
if self.warn_dir:
|
| 83 |
+
self.warn(
|
| 84 |
+
"setup script did not provide a directory for "
|
| 85 |
+
f"'{f}' -- installing right in '{self.install_dir}'"
|
| 86 |
+
)
|
| 87 |
+
(out, _) = self.copy_file(f, self.install_dir)
|
| 88 |
+
self.outfiles.append(out)
|
| 89 |
+
|
| 90 |
+
def get_inputs(self):
|
| 91 |
+
return self.data_files or []
|
| 92 |
+
|
| 93 |
+
def get_outputs(self):
|
| 94 |
+
return self.outfiles
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/command/install_scripts.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.command.install_scripts
|
| 2 |
+
|
| 3 |
+
Implements the Distutils 'install_scripts' command, for installing
|
| 4 |
+
Python scripts."""
|
| 5 |
+
|
| 6 |
+
# contributed by Bastian Kleineidam
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
from distutils._log import log
|
| 10 |
+
from stat import ST_MODE
|
| 11 |
+
from typing import ClassVar
|
| 12 |
+
|
| 13 |
+
from ..core import Command
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class install_scripts(Command):
|
| 17 |
+
description = "install scripts (Python or otherwise)"
|
| 18 |
+
|
| 19 |
+
user_options = [
|
| 20 |
+
('install-dir=', 'd', "directory to install scripts to"),
|
| 21 |
+
('build-dir=', 'b', "build directory (where to install from)"),
|
| 22 |
+
('force', 'f', "force installation (overwrite existing files)"),
|
| 23 |
+
('skip-build', None, "skip the build steps"),
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
boolean_options: ClassVar[list[str]] = ['force', 'skip-build']
|
| 27 |
+
|
| 28 |
+
def initialize_options(self):
|
| 29 |
+
self.install_dir = None
|
| 30 |
+
self.force = False
|
| 31 |
+
self.build_dir = None
|
| 32 |
+
self.skip_build = None
|
| 33 |
+
|
| 34 |
+
def finalize_options(self) -> None:
|
| 35 |
+
self.set_undefined_options('build', ('build_scripts', 'build_dir'))
|
| 36 |
+
self.set_undefined_options(
|
| 37 |
+
'install',
|
| 38 |
+
('install_scripts', 'install_dir'),
|
| 39 |
+
('force', 'force'),
|
| 40 |
+
('skip_build', 'skip_build'),
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
def run(self) -> None:
|
| 44 |
+
if not self.skip_build:
|
| 45 |
+
self.run_command('build_scripts')
|
| 46 |
+
self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
|
| 47 |
+
if os.name == 'posix':
|
| 48 |
+
# Set the executable bits (owner, group, and world) on
|
| 49 |
+
# all the scripts we just installed.
|
| 50 |
+
for file in self.get_outputs():
|
| 51 |
+
mode = ((os.stat(file)[ST_MODE]) | 0o555) & 0o7777
|
| 52 |
+
log.info("changing mode of %s to %o", file, mode)
|
| 53 |
+
os.chmod(file, mode)
|
| 54 |
+
|
| 55 |
+
def get_inputs(self):
|
| 56 |
+
return self.distribution.scripts or []
|
| 57 |
+
|
| 58 |
+
def get_outputs(self):
|
| 59 |
+
return self.outfiles or []
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/__init__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Test suite for distutils.
|
| 3 |
+
|
| 4 |
+
Tests for the command classes in the distutils.command package are
|
| 5 |
+
included in distutils.tests as well, instead of using a separate
|
| 6 |
+
distutils.command.tests package, since command identification is done
|
| 7 |
+
by import rather than matching pre-defined names.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import shutil
|
| 11 |
+
from collections.abc import Sequence
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def missing_compiler_executable(cmd_names: Sequence[str] = []): # pragma: no cover
|
| 15 |
+
"""Check if the compiler components used to build the interpreter exist.
|
| 16 |
+
|
| 17 |
+
Check for the existence of the compiler executables whose names are listed
|
| 18 |
+
in 'cmd_names' or all the compiler executables when 'cmd_names' is empty
|
| 19 |
+
and return the first missing executable or None when none is found
|
| 20 |
+
missing.
|
| 21 |
+
|
| 22 |
+
"""
|
| 23 |
+
from distutils import ccompiler, errors, sysconfig
|
| 24 |
+
|
| 25 |
+
compiler = ccompiler.new_compiler()
|
| 26 |
+
sysconfig.customize_compiler(compiler)
|
| 27 |
+
if compiler.compiler_type == "msvc":
|
| 28 |
+
# MSVC has no executables, so check whether initialization succeeds
|
| 29 |
+
try:
|
| 30 |
+
compiler.initialize()
|
| 31 |
+
except errors.DistutilsPlatformError:
|
| 32 |
+
return "msvc"
|
| 33 |
+
for name in compiler.executables:
|
| 34 |
+
if cmd_names and name not in cmd_names:
|
| 35 |
+
continue
|
| 36 |
+
cmd = getattr(compiler, name)
|
| 37 |
+
if cmd_names:
|
| 38 |
+
assert cmd is not None, f"the '{name}' executable is not configured"
|
| 39 |
+
elif not cmd:
|
| 40 |
+
continue
|
| 41 |
+
if shutil.which(cmd[0]) is None:
|
| 42 |
+
return cmd[0]
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/support.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Support code for distutils test cases."""
|
| 2 |
+
|
| 3 |
+
import itertools
|
| 4 |
+
import os
|
| 5 |
+
import pathlib
|
| 6 |
+
import shutil
|
| 7 |
+
import sys
|
| 8 |
+
import sysconfig
|
| 9 |
+
import tempfile
|
| 10 |
+
from distutils.core import Distribution
|
| 11 |
+
|
| 12 |
+
import pytest
|
| 13 |
+
from more_itertools import always_iterable
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@pytest.mark.usefixtures('distutils_managed_tempdir')
|
| 17 |
+
class TempdirManager:
|
| 18 |
+
"""
|
| 19 |
+
Mix-in class that handles temporary directories for test cases.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
def mkdtemp(self):
|
| 23 |
+
"""Create a temporary directory that will be cleaned up.
|
| 24 |
+
|
| 25 |
+
Returns the path of the directory.
|
| 26 |
+
"""
|
| 27 |
+
d = tempfile.mkdtemp()
|
| 28 |
+
self.tempdirs.append(d)
|
| 29 |
+
return d
|
| 30 |
+
|
| 31 |
+
def write_file(self, path, content='xxx'):
|
| 32 |
+
"""Writes a file in the given path.
|
| 33 |
+
|
| 34 |
+
path can be a string or a sequence.
|
| 35 |
+
"""
|
| 36 |
+
pathlib.Path(*always_iterable(path)).write_text(content, encoding='utf-8')
|
| 37 |
+
|
| 38 |
+
def create_dist(self, pkg_name='foo', **kw):
|
| 39 |
+
"""Will generate a test environment.
|
| 40 |
+
|
| 41 |
+
This function creates:
|
| 42 |
+
- a Distribution instance using keywords
|
| 43 |
+
- a temporary directory with a package structure
|
| 44 |
+
|
| 45 |
+
It returns the package directory and the distribution
|
| 46 |
+
instance.
|
| 47 |
+
"""
|
| 48 |
+
tmp_dir = self.mkdtemp()
|
| 49 |
+
pkg_dir = os.path.join(tmp_dir, pkg_name)
|
| 50 |
+
os.mkdir(pkg_dir)
|
| 51 |
+
dist = Distribution(attrs=kw)
|
| 52 |
+
|
| 53 |
+
return pkg_dir, dist
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class DummyCommand:
|
| 57 |
+
"""Class to store options for retrieval via set_undefined_options()."""
|
| 58 |
+
|
| 59 |
+
def __init__(self, **kwargs):
|
| 60 |
+
vars(self).update(kwargs)
|
| 61 |
+
|
| 62 |
+
def ensure_finalized(self):
|
| 63 |
+
pass
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def copy_xxmodule_c(directory):
|
| 67 |
+
"""Helper for tests that need the xxmodule.c source file.
|
| 68 |
+
|
| 69 |
+
Example use:
|
| 70 |
+
|
| 71 |
+
def test_compile(self):
|
| 72 |
+
copy_xxmodule_c(self.tmpdir)
|
| 73 |
+
self.assertIn('xxmodule.c', os.listdir(self.tmpdir))
|
| 74 |
+
|
| 75 |
+
If the source file can be found, it will be copied to *directory*. If not,
|
| 76 |
+
the test will be skipped. Errors during copy are not caught.
|
| 77 |
+
"""
|
| 78 |
+
shutil.copy(_get_xxmodule_path(), os.path.join(directory, 'xxmodule.c'))
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _get_xxmodule_path():
|
| 82 |
+
source_name = 'xxmodule.c' if sys.version_info > (3, 9) else 'xxmodule-3.8.c'
|
| 83 |
+
return os.path.join(os.path.dirname(__file__), source_name)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def fixup_build_ext(cmd):
|
| 87 |
+
"""Function needed to make build_ext tests pass.
|
| 88 |
+
|
| 89 |
+
When Python was built with --enable-shared on Unix, -L. is not enough to
|
| 90 |
+
find libpython<blah>.so, because regrtest runs in a tempdir, not in the
|
| 91 |
+
source directory where the .so lives.
|
| 92 |
+
|
| 93 |
+
When Python was built with in debug mode on Windows, build_ext commands
|
| 94 |
+
need their debug attribute set, and it is not done automatically for
|
| 95 |
+
some reason.
|
| 96 |
+
|
| 97 |
+
This function handles both of these things. Example use:
|
| 98 |
+
|
| 99 |
+
cmd = build_ext(dist)
|
| 100 |
+
support.fixup_build_ext(cmd)
|
| 101 |
+
cmd.ensure_finalized()
|
| 102 |
+
|
| 103 |
+
Unlike most other Unix platforms, Mac OS X embeds absolute paths
|
| 104 |
+
to shared libraries into executables, so the fixup is not needed there.
|
| 105 |
+
"""
|
| 106 |
+
if os.name == 'nt':
|
| 107 |
+
cmd.debug = sys.executable.endswith('_d.exe')
|
| 108 |
+
elif sysconfig.get_config_var('Py_ENABLE_SHARED'):
|
| 109 |
+
# To further add to the shared builds fun on Unix, we can't just add
|
| 110 |
+
# library_dirs to the Extension() instance because that doesn't get
|
| 111 |
+
# plumbed through to the final compiler command.
|
| 112 |
+
runshared = sysconfig.get_config_var('RUNSHARED')
|
| 113 |
+
if runshared is None:
|
| 114 |
+
cmd.library_dirs = ['.']
|
| 115 |
+
else:
|
| 116 |
+
if sys.platform == 'darwin':
|
| 117 |
+
cmd.library_dirs = []
|
| 118 |
+
else:
|
| 119 |
+
name, equals, value = runshared.partition('=')
|
| 120 |
+
cmd.library_dirs = [d for d in value.split(os.pathsep) if d]
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def combine_markers(cls):
|
| 124 |
+
"""
|
| 125 |
+
pytest will honor markers as found on the class, but when
|
| 126 |
+
markers are on multiple subclasses, only one appears. Use
|
| 127 |
+
this decorator to combine those markers.
|
| 128 |
+
"""
|
| 129 |
+
cls.pytestmark = [
|
| 130 |
+
mark
|
| 131 |
+
for base in itertools.chain([cls], cls.__bases__)
|
| 132 |
+
for mark in getattr(base, 'pytestmark', [])
|
| 133 |
+
]
|
| 134 |
+
return cls
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_archive_util.py
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.archive_util."""
|
| 2 |
+
|
| 3 |
+
import functools
|
| 4 |
+
import operator
|
| 5 |
+
import os
|
| 6 |
+
import pathlib
|
| 7 |
+
import sys
|
| 8 |
+
import tarfile
|
| 9 |
+
from distutils import archive_util
|
| 10 |
+
from distutils.archive_util import (
|
| 11 |
+
ARCHIVE_FORMATS,
|
| 12 |
+
check_archive_formats,
|
| 13 |
+
make_archive,
|
| 14 |
+
make_tarball,
|
| 15 |
+
make_zipfile,
|
| 16 |
+
)
|
| 17 |
+
from distutils.spawn import spawn
|
| 18 |
+
from distutils.tests import support
|
| 19 |
+
from os.path import splitdrive
|
| 20 |
+
|
| 21 |
+
import path
|
| 22 |
+
import pytest
|
| 23 |
+
from test.support import patch
|
| 24 |
+
|
| 25 |
+
from .unix_compat import UID_0_SUPPORT, grp, pwd, require_uid_0, require_unix_id
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def can_fs_encode(filename):
|
| 29 |
+
"""
|
| 30 |
+
Return True if the filename can be saved in the file system.
|
| 31 |
+
"""
|
| 32 |
+
if os.path.supports_unicode_filenames:
|
| 33 |
+
return True
|
| 34 |
+
try:
|
| 35 |
+
filename.encode(sys.getfilesystemencoding())
|
| 36 |
+
except UnicodeEncodeError:
|
| 37 |
+
return False
|
| 38 |
+
return True
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def all_equal(values):
|
| 42 |
+
return functools.reduce(operator.eq, values)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def same_drive(*paths):
|
| 46 |
+
return all_equal(pathlib.Path(path).drive for path in paths)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class ArchiveUtilTestCase(support.TempdirManager):
|
| 50 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 51 |
+
def test_make_tarball(self, name='archive'):
|
| 52 |
+
# creating something to tar
|
| 53 |
+
tmpdir = self._create_files()
|
| 54 |
+
self._make_tarball(tmpdir, name, '.tar.gz')
|
| 55 |
+
# trying an uncompressed one
|
| 56 |
+
self._make_tarball(tmpdir, name, '.tar', compress=None)
|
| 57 |
+
|
| 58 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 59 |
+
def test_make_tarball_gzip(self):
|
| 60 |
+
tmpdir = self._create_files()
|
| 61 |
+
self._make_tarball(tmpdir, 'archive', '.tar.gz', compress='gzip')
|
| 62 |
+
|
| 63 |
+
def test_make_tarball_bzip2(self):
|
| 64 |
+
pytest.importorskip('bz2')
|
| 65 |
+
tmpdir = self._create_files()
|
| 66 |
+
self._make_tarball(tmpdir, 'archive', '.tar.bz2', compress='bzip2')
|
| 67 |
+
|
| 68 |
+
def test_make_tarball_xz(self):
|
| 69 |
+
pytest.importorskip('lzma')
|
| 70 |
+
tmpdir = self._create_files()
|
| 71 |
+
self._make_tarball(tmpdir, 'archive', '.tar.xz', compress='xz')
|
| 72 |
+
|
| 73 |
+
@pytest.mark.skipif("not can_fs_encode('årchiv')")
|
| 74 |
+
def test_make_tarball_latin1(self):
|
| 75 |
+
"""
|
| 76 |
+
Mirror test_make_tarball, except filename contains latin characters.
|
| 77 |
+
"""
|
| 78 |
+
self.test_make_tarball('årchiv') # note this isn't a real word
|
| 79 |
+
|
| 80 |
+
@pytest.mark.skipif("not can_fs_encode('のアーカイブ')")
|
| 81 |
+
def test_make_tarball_extended(self):
|
| 82 |
+
"""
|
| 83 |
+
Mirror test_make_tarball, except filename contains extended
|
| 84 |
+
characters outside the latin charset.
|
| 85 |
+
"""
|
| 86 |
+
self.test_make_tarball('のアーカイブ') # japanese for archive
|
| 87 |
+
|
| 88 |
+
def _make_tarball(self, tmpdir, target_name, suffix, **kwargs):
|
| 89 |
+
tmpdir2 = self.mkdtemp()
|
| 90 |
+
if same_drive(tmpdir, tmpdir2):
|
| 91 |
+
pytest.skip("source and target should be on same drive")
|
| 92 |
+
|
| 93 |
+
base_name = os.path.join(tmpdir2, target_name)
|
| 94 |
+
|
| 95 |
+
# working with relative paths to avoid tar warnings
|
| 96 |
+
with path.Path(tmpdir):
|
| 97 |
+
make_tarball(splitdrive(base_name)[1], 'dist', **kwargs)
|
| 98 |
+
|
| 99 |
+
# check if the compressed tarball was created
|
| 100 |
+
tarball = base_name + suffix
|
| 101 |
+
assert os.path.exists(tarball)
|
| 102 |
+
assert self._tarinfo(tarball) == self._created_files
|
| 103 |
+
|
| 104 |
+
def _tarinfo(self, path):
|
| 105 |
+
tar = tarfile.open(path)
|
| 106 |
+
try:
|
| 107 |
+
names = tar.getnames()
|
| 108 |
+
names.sort()
|
| 109 |
+
return names
|
| 110 |
+
finally:
|
| 111 |
+
tar.close()
|
| 112 |
+
|
| 113 |
+
_zip_created_files = [
|
| 114 |
+
'dist/',
|
| 115 |
+
'dist/file1',
|
| 116 |
+
'dist/file2',
|
| 117 |
+
'dist/sub/',
|
| 118 |
+
'dist/sub/file3',
|
| 119 |
+
'dist/sub2/',
|
| 120 |
+
]
|
| 121 |
+
_created_files = [p.rstrip('/') for p in _zip_created_files]
|
| 122 |
+
|
| 123 |
+
def _create_files(self):
|
| 124 |
+
# creating something to tar
|
| 125 |
+
tmpdir = self.mkdtemp()
|
| 126 |
+
dist = os.path.join(tmpdir, 'dist')
|
| 127 |
+
os.mkdir(dist)
|
| 128 |
+
self.write_file([dist, 'file1'], 'xxx')
|
| 129 |
+
self.write_file([dist, 'file2'], 'xxx')
|
| 130 |
+
os.mkdir(os.path.join(dist, 'sub'))
|
| 131 |
+
self.write_file([dist, 'sub', 'file3'], 'xxx')
|
| 132 |
+
os.mkdir(os.path.join(dist, 'sub2'))
|
| 133 |
+
return tmpdir
|
| 134 |
+
|
| 135 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 136 |
+
@pytest.mark.skipif("not (shutil.which('tar') and shutil.which('gzip'))")
|
| 137 |
+
def test_tarfile_vs_tar(self):
|
| 138 |
+
tmpdir = self._create_files()
|
| 139 |
+
tmpdir2 = self.mkdtemp()
|
| 140 |
+
base_name = os.path.join(tmpdir2, 'archive')
|
| 141 |
+
old_dir = os.getcwd()
|
| 142 |
+
os.chdir(tmpdir)
|
| 143 |
+
try:
|
| 144 |
+
make_tarball(base_name, 'dist')
|
| 145 |
+
finally:
|
| 146 |
+
os.chdir(old_dir)
|
| 147 |
+
|
| 148 |
+
# check if the compressed tarball was created
|
| 149 |
+
tarball = base_name + '.tar.gz'
|
| 150 |
+
assert os.path.exists(tarball)
|
| 151 |
+
|
| 152 |
+
# now create another tarball using `tar`
|
| 153 |
+
tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
|
| 154 |
+
tar_cmd = ['tar', '-cf', 'archive2.tar', 'dist']
|
| 155 |
+
gzip_cmd = ['gzip', '-f', '-9', 'archive2.tar']
|
| 156 |
+
old_dir = os.getcwd()
|
| 157 |
+
os.chdir(tmpdir)
|
| 158 |
+
try:
|
| 159 |
+
spawn(tar_cmd)
|
| 160 |
+
spawn(gzip_cmd)
|
| 161 |
+
finally:
|
| 162 |
+
os.chdir(old_dir)
|
| 163 |
+
|
| 164 |
+
assert os.path.exists(tarball2)
|
| 165 |
+
# let's compare both tarballs
|
| 166 |
+
assert self._tarinfo(tarball) == self._created_files
|
| 167 |
+
assert self._tarinfo(tarball2) == self._created_files
|
| 168 |
+
|
| 169 |
+
# trying an uncompressed one
|
| 170 |
+
base_name = os.path.join(tmpdir2, 'archive')
|
| 171 |
+
old_dir = os.getcwd()
|
| 172 |
+
os.chdir(tmpdir)
|
| 173 |
+
try:
|
| 174 |
+
make_tarball(base_name, 'dist', compress=None)
|
| 175 |
+
finally:
|
| 176 |
+
os.chdir(old_dir)
|
| 177 |
+
tarball = base_name + '.tar'
|
| 178 |
+
assert os.path.exists(tarball)
|
| 179 |
+
|
| 180 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 181 |
+
def test_make_zipfile(self):
|
| 182 |
+
zipfile = pytest.importorskip('zipfile')
|
| 183 |
+
# creating something to tar
|
| 184 |
+
tmpdir = self._create_files()
|
| 185 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 186 |
+
with path.Path(tmpdir):
|
| 187 |
+
make_zipfile(base_name, 'dist')
|
| 188 |
+
|
| 189 |
+
# check if the compressed tarball was created
|
| 190 |
+
tarball = base_name + '.zip'
|
| 191 |
+
assert os.path.exists(tarball)
|
| 192 |
+
with zipfile.ZipFile(tarball) as zf:
|
| 193 |
+
assert sorted(zf.namelist()) == self._zip_created_files
|
| 194 |
+
|
| 195 |
+
def test_make_zipfile_no_zlib(self):
|
| 196 |
+
zipfile = pytest.importorskip('zipfile')
|
| 197 |
+
patch(self, archive_util.zipfile, 'zlib', None) # force zlib ImportError
|
| 198 |
+
|
| 199 |
+
called = []
|
| 200 |
+
zipfile_class = zipfile.ZipFile
|
| 201 |
+
|
| 202 |
+
def fake_zipfile(*a, **kw):
|
| 203 |
+
if kw.get('compression', None) == zipfile.ZIP_STORED:
|
| 204 |
+
called.append((a, kw))
|
| 205 |
+
return zipfile_class(*a, **kw)
|
| 206 |
+
|
| 207 |
+
patch(self, archive_util.zipfile, 'ZipFile', fake_zipfile)
|
| 208 |
+
|
| 209 |
+
# create something to tar and compress
|
| 210 |
+
tmpdir = self._create_files()
|
| 211 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 212 |
+
with path.Path(tmpdir):
|
| 213 |
+
make_zipfile(base_name, 'dist')
|
| 214 |
+
|
| 215 |
+
tarball = base_name + '.zip'
|
| 216 |
+
assert called == [((tarball, "w"), {'compression': zipfile.ZIP_STORED})]
|
| 217 |
+
assert os.path.exists(tarball)
|
| 218 |
+
with zipfile.ZipFile(tarball) as zf:
|
| 219 |
+
assert sorted(zf.namelist()) == self._zip_created_files
|
| 220 |
+
|
| 221 |
+
def test_check_archive_formats(self):
|
| 222 |
+
assert check_archive_formats(['gztar', 'xxx', 'zip']) == 'xxx'
|
| 223 |
+
assert (
|
| 224 |
+
check_archive_formats(['gztar', 'bztar', 'xztar', 'ztar', 'tar', 'zip'])
|
| 225 |
+
is None
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
def test_make_archive(self):
|
| 229 |
+
tmpdir = self.mkdtemp()
|
| 230 |
+
base_name = os.path.join(tmpdir, 'archive')
|
| 231 |
+
with pytest.raises(ValueError):
|
| 232 |
+
make_archive(base_name, 'xxx')
|
| 233 |
+
|
| 234 |
+
def test_make_archive_cwd(self):
|
| 235 |
+
current_dir = os.getcwd()
|
| 236 |
+
|
| 237 |
+
def _breaks(*args, **kw):
|
| 238 |
+
raise RuntimeError()
|
| 239 |
+
|
| 240 |
+
ARCHIVE_FORMATS['xxx'] = (_breaks, [], 'xxx file')
|
| 241 |
+
try:
|
| 242 |
+
try:
|
| 243 |
+
make_archive('xxx', 'xxx', root_dir=self.mkdtemp())
|
| 244 |
+
except Exception:
|
| 245 |
+
pass
|
| 246 |
+
assert os.getcwd() == current_dir
|
| 247 |
+
finally:
|
| 248 |
+
ARCHIVE_FORMATS.pop('xxx')
|
| 249 |
+
|
| 250 |
+
def test_make_archive_tar(self):
|
| 251 |
+
base_dir = self._create_files()
|
| 252 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 253 |
+
res = make_archive(base_name, 'tar', base_dir, 'dist')
|
| 254 |
+
assert os.path.exists(res)
|
| 255 |
+
assert os.path.basename(res) == 'archive.tar'
|
| 256 |
+
assert self._tarinfo(res) == self._created_files
|
| 257 |
+
|
| 258 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 259 |
+
def test_make_archive_gztar(self):
|
| 260 |
+
base_dir = self._create_files()
|
| 261 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 262 |
+
res = make_archive(base_name, 'gztar', base_dir, 'dist')
|
| 263 |
+
assert os.path.exists(res)
|
| 264 |
+
assert os.path.basename(res) == 'archive.tar.gz'
|
| 265 |
+
assert self._tarinfo(res) == self._created_files
|
| 266 |
+
|
| 267 |
+
def test_make_archive_bztar(self):
|
| 268 |
+
pytest.importorskip('bz2')
|
| 269 |
+
base_dir = self._create_files()
|
| 270 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 271 |
+
res = make_archive(base_name, 'bztar', base_dir, 'dist')
|
| 272 |
+
assert os.path.exists(res)
|
| 273 |
+
assert os.path.basename(res) == 'archive.tar.bz2'
|
| 274 |
+
assert self._tarinfo(res) == self._created_files
|
| 275 |
+
|
| 276 |
+
def test_make_archive_xztar(self):
|
| 277 |
+
pytest.importorskip('lzma')
|
| 278 |
+
base_dir = self._create_files()
|
| 279 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 280 |
+
res = make_archive(base_name, 'xztar', base_dir, 'dist')
|
| 281 |
+
assert os.path.exists(res)
|
| 282 |
+
assert os.path.basename(res) == 'archive.tar.xz'
|
| 283 |
+
assert self._tarinfo(res) == self._created_files
|
| 284 |
+
|
| 285 |
+
def test_make_archive_owner_group(self):
|
| 286 |
+
# testing make_archive with owner and group, with various combinations
|
| 287 |
+
# this works even if there's not gid/uid support
|
| 288 |
+
if UID_0_SUPPORT:
|
| 289 |
+
group = grp.getgrgid(0)[0]
|
| 290 |
+
owner = pwd.getpwuid(0)[0]
|
| 291 |
+
else:
|
| 292 |
+
group = owner = 'root'
|
| 293 |
+
|
| 294 |
+
base_dir = self._create_files()
|
| 295 |
+
root_dir = self.mkdtemp()
|
| 296 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 297 |
+
res = make_archive(
|
| 298 |
+
base_name, 'zip', root_dir, base_dir, owner=owner, group=group
|
| 299 |
+
)
|
| 300 |
+
assert os.path.exists(res)
|
| 301 |
+
|
| 302 |
+
res = make_archive(base_name, 'zip', root_dir, base_dir)
|
| 303 |
+
assert os.path.exists(res)
|
| 304 |
+
|
| 305 |
+
res = make_archive(
|
| 306 |
+
base_name, 'tar', root_dir, base_dir, owner=owner, group=group
|
| 307 |
+
)
|
| 308 |
+
assert os.path.exists(res)
|
| 309 |
+
|
| 310 |
+
res = make_archive(
|
| 311 |
+
base_name, 'tar', root_dir, base_dir, owner='kjhkjhkjg', group='oihohoh'
|
| 312 |
+
)
|
| 313 |
+
assert os.path.exists(res)
|
| 314 |
+
|
| 315 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 316 |
+
@require_unix_id
|
| 317 |
+
@require_uid_0
|
| 318 |
+
def test_tarfile_root_owner(self):
|
| 319 |
+
tmpdir = self._create_files()
|
| 320 |
+
base_name = os.path.join(self.mkdtemp(), 'archive')
|
| 321 |
+
old_dir = os.getcwd()
|
| 322 |
+
os.chdir(tmpdir)
|
| 323 |
+
group = grp.getgrgid(0)[0]
|
| 324 |
+
owner = pwd.getpwuid(0)[0]
|
| 325 |
+
try:
|
| 326 |
+
archive_name = make_tarball(
|
| 327 |
+
base_name, 'dist', compress=None, owner=owner, group=group
|
| 328 |
+
)
|
| 329 |
+
finally:
|
| 330 |
+
os.chdir(old_dir)
|
| 331 |
+
|
| 332 |
+
# check if the compressed tarball was created
|
| 333 |
+
assert os.path.exists(archive_name)
|
| 334 |
+
|
| 335 |
+
# now checks the rights
|
| 336 |
+
archive = tarfile.open(archive_name)
|
| 337 |
+
try:
|
| 338 |
+
for member in archive.getmembers():
|
| 339 |
+
assert member.uid == 0
|
| 340 |
+
assert member.gid == 0
|
| 341 |
+
finally:
|
| 342 |
+
archive.close()
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_bdist.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.bdist."""
|
| 2 |
+
|
| 3 |
+
from distutils.command.bdist import bdist
|
| 4 |
+
from distutils.tests import support
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestBuild(support.TempdirManager):
|
| 8 |
+
def test_formats(self):
|
| 9 |
+
# let's create a command and make sure
|
| 10 |
+
# we can set the format
|
| 11 |
+
dist = self.create_dist()[1]
|
| 12 |
+
cmd = bdist(dist)
|
| 13 |
+
cmd.formats = ['gztar']
|
| 14 |
+
cmd.ensure_finalized()
|
| 15 |
+
assert cmd.formats == ['gztar']
|
| 16 |
+
|
| 17 |
+
# what formats does bdist offer?
|
| 18 |
+
formats = [
|
| 19 |
+
'bztar',
|
| 20 |
+
'gztar',
|
| 21 |
+
'rpm',
|
| 22 |
+
'tar',
|
| 23 |
+
'xztar',
|
| 24 |
+
'zip',
|
| 25 |
+
'ztar',
|
| 26 |
+
]
|
| 27 |
+
found = sorted(cmd.format_commands)
|
| 28 |
+
assert found == formats
|
| 29 |
+
|
| 30 |
+
def test_skip_build(self):
|
| 31 |
+
# bug #10946: bdist --skip-build should trickle down to subcommands
|
| 32 |
+
dist = self.create_dist()[1]
|
| 33 |
+
cmd = bdist(dist)
|
| 34 |
+
cmd.skip_build = True
|
| 35 |
+
cmd.ensure_finalized()
|
| 36 |
+
dist.command_obj['bdist'] = cmd
|
| 37 |
+
|
| 38 |
+
names = [
|
| 39 |
+
'bdist_dumb',
|
| 40 |
+
] # bdist_rpm does not support --skip-build
|
| 41 |
+
|
| 42 |
+
for name in names:
|
| 43 |
+
subcmd = cmd.get_finalized_command(name)
|
| 44 |
+
if getattr(subcmd, '_unsupported', False):
|
| 45 |
+
# command is not supported on this build
|
| 46 |
+
continue
|
| 47 |
+
assert subcmd.skip_build, f'{name} should take --skip-build from bdist'
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_bdist_dumb.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.bdist_dumb."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import zipfile
|
| 6 |
+
from distutils.command.bdist_dumb import bdist_dumb
|
| 7 |
+
from distutils.core import Distribution
|
| 8 |
+
from distutils.tests import support
|
| 9 |
+
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
SETUP_PY = """\
|
| 13 |
+
from distutils.core import setup
|
| 14 |
+
import foo
|
| 15 |
+
|
| 16 |
+
setup(name='foo', version='0.1', py_modules=['foo'],
|
| 17 |
+
url='xxx', author='xxx', author_email='xxx')
|
| 18 |
+
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@support.combine_markers
|
| 23 |
+
@pytest.mark.usefixtures('save_env')
|
| 24 |
+
@pytest.mark.usefixtures('save_argv')
|
| 25 |
+
@pytest.mark.usefixtures('save_cwd')
|
| 26 |
+
class TestBuildDumb(
|
| 27 |
+
support.TempdirManager,
|
| 28 |
+
):
|
| 29 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 30 |
+
def test_simple_built(self):
|
| 31 |
+
# let's create a simple package
|
| 32 |
+
tmp_dir = self.mkdtemp()
|
| 33 |
+
pkg_dir = os.path.join(tmp_dir, 'foo')
|
| 34 |
+
os.mkdir(pkg_dir)
|
| 35 |
+
self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
|
| 36 |
+
self.write_file((pkg_dir, 'foo.py'), '#')
|
| 37 |
+
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
|
| 38 |
+
self.write_file((pkg_dir, 'README'), '')
|
| 39 |
+
|
| 40 |
+
dist = Distribution({
|
| 41 |
+
'name': 'foo',
|
| 42 |
+
'version': '0.1',
|
| 43 |
+
'py_modules': ['foo'],
|
| 44 |
+
'url': 'xxx',
|
| 45 |
+
'author': 'xxx',
|
| 46 |
+
'author_email': 'xxx',
|
| 47 |
+
})
|
| 48 |
+
dist.script_name = 'setup.py'
|
| 49 |
+
os.chdir(pkg_dir)
|
| 50 |
+
|
| 51 |
+
sys.argv = ['setup.py']
|
| 52 |
+
cmd = bdist_dumb(dist)
|
| 53 |
+
|
| 54 |
+
# so the output is the same no matter
|
| 55 |
+
# what is the platform
|
| 56 |
+
cmd.format = 'zip'
|
| 57 |
+
|
| 58 |
+
cmd.ensure_finalized()
|
| 59 |
+
cmd.run()
|
| 60 |
+
|
| 61 |
+
# see what we have
|
| 62 |
+
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
| 63 |
+
base = f"{dist.get_fullname()}.{cmd.plat_name}.zip"
|
| 64 |
+
|
| 65 |
+
assert dist_created == [base]
|
| 66 |
+
|
| 67 |
+
# now let's check what we have in the zip file
|
| 68 |
+
fp = zipfile.ZipFile(os.path.join('dist', base))
|
| 69 |
+
try:
|
| 70 |
+
contents = fp.namelist()
|
| 71 |
+
finally:
|
| 72 |
+
fp.close()
|
| 73 |
+
|
| 74 |
+
contents = sorted(filter(None, map(os.path.basename, contents)))
|
| 75 |
+
wanted = ['foo-0.1-py{}.{}.egg-info'.format(*sys.version_info[:2]), 'foo.py']
|
| 76 |
+
if not sys.dont_write_bytecode:
|
| 77 |
+
wanted.append(f'foo.{sys.implementation.cache_tag}.pyc')
|
| 78 |
+
assert contents == sorted(wanted)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_bdist_rpm.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.bdist_rpm."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import shutil # noqa: F401
|
| 5 |
+
import sys
|
| 6 |
+
from distutils.command.bdist_rpm import bdist_rpm
|
| 7 |
+
from distutils.core import Distribution
|
| 8 |
+
from distutils.tests import support
|
| 9 |
+
|
| 10 |
+
import pytest
|
| 11 |
+
from test.support import requires_zlib
|
| 12 |
+
|
| 13 |
+
SETUP_PY = """\
|
| 14 |
+
from distutils.core import setup
|
| 15 |
+
import foo
|
| 16 |
+
|
| 17 |
+
setup(name='foo', version='0.1', py_modules=['foo'],
|
| 18 |
+
url='xxx', author='xxx', author_email='xxx')
|
| 19 |
+
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@pytest.fixture(autouse=True)
|
| 24 |
+
def sys_executable_encodable():
|
| 25 |
+
try:
|
| 26 |
+
sys.executable.encode('UTF-8')
|
| 27 |
+
except UnicodeEncodeError:
|
| 28 |
+
pytest.skip("sys.executable is not encodable to UTF-8")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
mac_woes = pytest.mark.skipif(
|
| 32 |
+
"not sys.platform.startswith('linux')",
|
| 33 |
+
reason='spurious sdtout/stderr output under macOS',
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@pytest.mark.usefixtures('save_env')
|
| 38 |
+
@pytest.mark.usefixtures('save_argv')
|
| 39 |
+
@pytest.mark.usefixtures('save_cwd')
|
| 40 |
+
class TestBuildRpm(
|
| 41 |
+
support.TempdirManager,
|
| 42 |
+
):
|
| 43 |
+
@mac_woes
|
| 44 |
+
@requires_zlib()
|
| 45 |
+
@pytest.mark.skipif("not shutil.which('rpm')")
|
| 46 |
+
@pytest.mark.skipif("not shutil.which('rpmbuild')")
|
| 47 |
+
def test_quiet(self):
|
| 48 |
+
# let's create a package
|
| 49 |
+
tmp_dir = self.mkdtemp()
|
| 50 |
+
os.environ['HOME'] = tmp_dir # to confine dir '.rpmdb' creation
|
| 51 |
+
pkg_dir = os.path.join(tmp_dir, 'foo')
|
| 52 |
+
os.mkdir(pkg_dir)
|
| 53 |
+
self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
|
| 54 |
+
self.write_file((pkg_dir, 'foo.py'), '#')
|
| 55 |
+
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
|
| 56 |
+
self.write_file((pkg_dir, 'README'), '')
|
| 57 |
+
|
| 58 |
+
dist = Distribution({
|
| 59 |
+
'name': 'foo',
|
| 60 |
+
'version': '0.1',
|
| 61 |
+
'py_modules': ['foo'],
|
| 62 |
+
'url': 'xxx',
|
| 63 |
+
'author': 'xxx',
|
| 64 |
+
'author_email': 'xxx',
|
| 65 |
+
})
|
| 66 |
+
dist.script_name = 'setup.py'
|
| 67 |
+
os.chdir(pkg_dir)
|
| 68 |
+
|
| 69 |
+
sys.argv = ['setup.py']
|
| 70 |
+
cmd = bdist_rpm(dist)
|
| 71 |
+
cmd.fix_python = True
|
| 72 |
+
|
| 73 |
+
# running in quiet mode
|
| 74 |
+
cmd.quiet = True
|
| 75 |
+
cmd.ensure_finalized()
|
| 76 |
+
cmd.run()
|
| 77 |
+
|
| 78 |
+
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
| 79 |
+
assert 'foo-0.1-1.noarch.rpm' in dist_created
|
| 80 |
+
|
| 81 |
+
# bug #2945: upload ignores bdist_rpm files
|
| 82 |
+
assert ('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm') in dist.dist_files
|
| 83 |
+
assert ('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm') in dist.dist_files
|
| 84 |
+
|
| 85 |
+
@mac_woes
|
| 86 |
+
@requires_zlib()
|
| 87 |
+
# https://bugs.python.org/issue1533164
|
| 88 |
+
@pytest.mark.skipif("not shutil.which('rpm')")
|
| 89 |
+
@pytest.mark.skipif("not shutil.which('rpmbuild')")
|
| 90 |
+
def test_no_optimize_flag(self):
|
| 91 |
+
# let's create a package that breaks bdist_rpm
|
| 92 |
+
tmp_dir = self.mkdtemp()
|
| 93 |
+
os.environ['HOME'] = tmp_dir # to confine dir '.rpmdb' creation
|
| 94 |
+
pkg_dir = os.path.join(tmp_dir, 'foo')
|
| 95 |
+
os.mkdir(pkg_dir)
|
| 96 |
+
self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
|
| 97 |
+
self.write_file((pkg_dir, 'foo.py'), '#')
|
| 98 |
+
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
|
| 99 |
+
self.write_file((pkg_dir, 'README'), '')
|
| 100 |
+
|
| 101 |
+
dist = Distribution({
|
| 102 |
+
'name': 'foo',
|
| 103 |
+
'version': '0.1',
|
| 104 |
+
'py_modules': ['foo'],
|
| 105 |
+
'url': 'xxx',
|
| 106 |
+
'author': 'xxx',
|
| 107 |
+
'author_email': 'xxx',
|
| 108 |
+
})
|
| 109 |
+
dist.script_name = 'setup.py'
|
| 110 |
+
os.chdir(pkg_dir)
|
| 111 |
+
|
| 112 |
+
sys.argv = ['setup.py']
|
| 113 |
+
cmd = bdist_rpm(dist)
|
| 114 |
+
cmd.fix_python = True
|
| 115 |
+
|
| 116 |
+
cmd.quiet = True
|
| 117 |
+
cmd.ensure_finalized()
|
| 118 |
+
cmd.run()
|
| 119 |
+
|
| 120 |
+
dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
|
| 121 |
+
assert 'foo-0.1-1.noarch.rpm' in dist_created
|
| 122 |
+
|
| 123 |
+
# bug #2945: upload ignores bdist_rpm files
|
| 124 |
+
assert ('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm') in dist.dist_files
|
| 125 |
+
assert ('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm') in dist.dist_files
|
| 126 |
+
|
| 127 |
+
os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_build.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.build."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from distutils.command.build import build
|
| 6 |
+
from distutils.tests import support
|
| 7 |
+
from sysconfig import get_config_var, get_platform
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TestBuild(support.TempdirManager):
|
| 11 |
+
def test_finalize_options(self):
|
| 12 |
+
pkg_dir, dist = self.create_dist()
|
| 13 |
+
cmd = build(dist)
|
| 14 |
+
cmd.finalize_options()
|
| 15 |
+
|
| 16 |
+
# if not specified, plat_name gets the current platform
|
| 17 |
+
assert cmd.plat_name == get_platform()
|
| 18 |
+
|
| 19 |
+
# build_purelib is build + lib
|
| 20 |
+
wanted = os.path.join(cmd.build_base, 'lib')
|
| 21 |
+
assert cmd.build_purelib == wanted
|
| 22 |
+
|
| 23 |
+
# build_platlib is 'build/lib.platform-cache_tag[-pydebug]'
|
| 24 |
+
# examples:
|
| 25 |
+
# build/lib.macosx-10.3-i386-cpython39
|
| 26 |
+
plat_spec = f'.{cmd.plat_name}-{sys.implementation.cache_tag}'
|
| 27 |
+
if get_config_var('Py_GIL_DISABLED'):
|
| 28 |
+
plat_spec += 't'
|
| 29 |
+
if hasattr(sys, 'gettotalrefcount'):
|
| 30 |
+
assert cmd.build_platlib.endswith('-pydebug')
|
| 31 |
+
plat_spec += '-pydebug'
|
| 32 |
+
wanted = os.path.join(cmd.build_base, 'lib' + plat_spec)
|
| 33 |
+
assert cmd.build_platlib == wanted
|
| 34 |
+
|
| 35 |
+
# by default, build_lib = build_purelib
|
| 36 |
+
assert cmd.build_lib == cmd.build_purelib
|
| 37 |
+
|
| 38 |
+
# build_temp is build/temp.<plat>
|
| 39 |
+
wanted = os.path.join(cmd.build_base, 'temp' + plat_spec)
|
| 40 |
+
assert cmd.build_temp == wanted
|
| 41 |
+
|
| 42 |
+
# build_scripts is build/scripts-x.x
|
| 43 |
+
wanted = os.path.join(
|
| 44 |
+
cmd.build_base, f'scripts-{sys.version_info.major}.{sys.version_info.minor}'
|
| 45 |
+
)
|
| 46 |
+
assert cmd.build_scripts == wanted
|
| 47 |
+
|
| 48 |
+
# executable is os.path.normpath(sys.executable)
|
| 49 |
+
assert cmd.executable == os.path.normpath(sys.executable)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_build_clib.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.build_clib."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from distutils.command.build_clib import build_clib
|
| 5 |
+
from distutils.errors import DistutilsSetupError
|
| 6 |
+
from distutils.tests import missing_compiler_executable, support
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TestBuildCLib(support.TempdirManager):
|
| 12 |
+
def test_check_library_dist(self):
|
| 13 |
+
pkg_dir, dist = self.create_dist()
|
| 14 |
+
cmd = build_clib(dist)
|
| 15 |
+
|
| 16 |
+
# 'libraries' option must be a list
|
| 17 |
+
with pytest.raises(DistutilsSetupError):
|
| 18 |
+
cmd.check_library_list('foo')
|
| 19 |
+
|
| 20 |
+
# each element of 'libraries' must a 2-tuple
|
| 21 |
+
with pytest.raises(DistutilsSetupError):
|
| 22 |
+
cmd.check_library_list(['foo1', 'foo2'])
|
| 23 |
+
|
| 24 |
+
# first element of each tuple in 'libraries'
|
| 25 |
+
# must be a string (the library name)
|
| 26 |
+
with pytest.raises(DistutilsSetupError):
|
| 27 |
+
cmd.check_library_list([(1, 'foo1'), ('name', 'foo2')])
|
| 28 |
+
|
| 29 |
+
# library name may not contain directory separators
|
| 30 |
+
with pytest.raises(DistutilsSetupError):
|
| 31 |
+
cmd.check_library_list(
|
| 32 |
+
[('name', 'foo1'), ('another/name', 'foo2')],
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# second element of each tuple must be a dictionary (build info)
|
| 36 |
+
with pytest.raises(DistutilsSetupError):
|
| 37 |
+
cmd.check_library_list(
|
| 38 |
+
[('name', {}), ('another', 'foo2')],
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# those work
|
| 42 |
+
libs = [('name', {}), ('name', {'ok': 'good'})]
|
| 43 |
+
cmd.check_library_list(libs)
|
| 44 |
+
|
| 45 |
+
def test_get_source_files(self):
|
| 46 |
+
pkg_dir, dist = self.create_dist()
|
| 47 |
+
cmd = build_clib(dist)
|
| 48 |
+
|
| 49 |
+
# "in 'libraries' option 'sources' must be present and must be
|
| 50 |
+
# a list of source filenames
|
| 51 |
+
cmd.libraries = [('name', {})]
|
| 52 |
+
with pytest.raises(DistutilsSetupError):
|
| 53 |
+
cmd.get_source_files()
|
| 54 |
+
|
| 55 |
+
cmd.libraries = [('name', {'sources': 1})]
|
| 56 |
+
with pytest.raises(DistutilsSetupError):
|
| 57 |
+
cmd.get_source_files()
|
| 58 |
+
|
| 59 |
+
cmd.libraries = [('name', {'sources': ['a', 'b']})]
|
| 60 |
+
assert cmd.get_source_files() == ['a', 'b']
|
| 61 |
+
|
| 62 |
+
cmd.libraries = [('name', {'sources': ('a', 'b')})]
|
| 63 |
+
assert cmd.get_source_files() == ['a', 'b']
|
| 64 |
+
|
| 65 |
+
cmd.libraries = [
|
| 66 |
+
('name', {'sources': ('a', 'b')}),
|
| 67 |
+
('name2', {'sources': ['c', 'd']}),
|
| 68 |
+
]
|
| 69 |
+
assert cmd.get_source_files() == ['a', 'b', 'c', 'd']
|
| 70 |
+
|
| 71 |
+
def test_build_libraries(self):
|
| 72 |
+
pkg_dir, dist = self.create_dist()
|
| 73 |
+
cmd = build_clib(dist)
|
| 74 |
+
|
| 75 |
+
class FakeCompiler:
|
| 76 |
+
def compile(*args, **kw):
|
| 77 |
+
pass
|
| 78 |
+
|
| 79 |
+
create_static_lib = compile
|
| 80 |
+
|
| 81 |
+
cmd.compiler = FakeCompiler()
|
| 82 |
+
|
| 83 |
+
# build_libraries is also doing a bit of typo checking
|
| 84 |
+
lib = [('name', {'sources': 'notvalid'})]
|
| 85 |
+
with pytest.raises(DistutilsSetupError):
|
| 86 |
+
cmd.build_libraries(lib)
|
| 87 |
+
|
| 88 |
+
lib = [('name', {'sources': list()})]
|
| 89 |
+
cmd.build_libraries(lib)
|
| 90 |
+
|
| 91 |
+
lib = [('name', {'sources': tuple()})]
|
| 92 |
+
cmd.build_libraries(lib)
|
| 93 |
+
|
| 94 |
+
def test_finalize_options(self):
|
| 95 |
+
pkg_dir, dist = self.create_dist()
|
| 96 |
+
cmd = build_clib(dist)
|
| 97 |
+
|
| 98 |
+
cmd.include_dirs = 'one-dir'
|
| 99 |
+
cmd.finalize_options()
|
| 100 |
+
assert cmd.include_dirs == ['one-dir']
|
| 101 |
+
|
| 102 |
+
cmd.include_dirs = None
|
| 103 |
+
cmd.finalize_options()
|
| 104 |
+
assert cmd.include_dirs == []
|
| 105 |
+
|
| 106 |
+
cmd.distribution.libraries = 'WONTWORK'
|
| 107 |
+
with pytest.raises(DistutilsSetupError):
|
| 108 |
+
cmd.finalize_options()
|
| 109 |
+
|
| 110 |
+
@pytest.mark.skipif('platform.system() == "Windows"')
|
| 111 |
+
def test_run(self):
|
| 112 |
+
pkg_dir, dist = self.create_dist()
|
| 113 |
+
cmd = build_clib(dist)
|
| 114 |
+
|
| 115 |
+
foo_c = os.path.join(pkg_dir, 'foo.c')
|
| 116 |
+
self.write_file(foo_c, 'int main(void) { return 1;}\n')
|
| 117 |
+
cmd.libraries = [('foo', {'sources': [foo_c]})]
|
| 118 |
+
|
| 119 |
+
build_temp = os.path.join(pkg_dir, 'build')
|
| 120 |
+
os.mkdir(build_temp)
|
| 121 |
+
cmd.build_temp = build_temp
|
| 122 |
+
cmd.build_clib = build_temp
|
| 123 |
+
|
| 124 |
+
# Before we run the command, we want to make sure
|
| 125 |
+
# all commands are present on the system.
|
| 126 |
+
ccmd = missing_compiler_executable()
|
| 127 |
+
if ccmd is not None:
|
| 128 |
+
self.skipTest(f'The {ccmd!r} command is not found')
|
| 129 |
+
|
| 130 |
+
# this should work
|
| 131 |
+
cmd.run()
|
| 132 |
+
|
| 133 |
+
# let's check the result
|
| 134 |
+
assert 'libfoo.a' in os.listdir(build_temp)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_build_ext.py
ADDED
|
@@ -0,0 +1,628 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import contextlib
|
| 2 |
+
import glob
|
| 3 |
+
import importlib
|
| 4 |
+
import os.path
|
| 5 |
+
import platform
|
| 6 |
+
import re
|
| 7 |
+
import shutil
|
| 8 |
+
import site
|
| 9 |
+
import subprocess
|
| 10 |
+
import sys
|
| 11 |
+
import tempfile
|
| 12 |
+
import textwrap
|
| 13 |
+
import time
|
| 14 |
+
from distutils import sysconfig
|
| 15 |
+
from distutils.command.build_ext import build_ext
|
| 16 |
+
from distutils.core import Distribution
|
| 17 |
+
from distutils.errors import (
|
| 18 |
+
CompileError,
|
| 19 |
+
DistutilsPlatformError,
|
| 20 |
+
DistutilsSetupError,
|
| 21 |
+
UnknownFileError,
|
| 22 |
+
)
|
| 23 |
+
from distutils.extension import Extension
|
| 24 |
+
from distutils.tests import missing_compiler_executable
|
| 25 |
+
from distutils.tests.support import TempdirManager, copy_xxmodule_c, fixup_build_ext
|
| 26 |
+
from io import StringIO
|
| 27 |
+
|
| 28 |
+
import jaraco.path
|
| 29 |
+
import path
|
| 30 |
+
import pytest
|
| 31 |
+
from test import support
|
| 32 |
+
|
| 33 |
+
from .compat import py39 as import_helper
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@pytest.fixture()
|
| 37 |
+
def user_site_dir(request):
|
| 38 |
+
self = request.instance
|
| 39 |
+
self.tmp_dir = self.mkdtemp()
|
| 40 |
+
self.tmp_path = path.Path(self.tmp_dir)
|
| 41 |
+
from distutils.command import build_ext
|
| 42 |
+
|
| 43 |
+
orig_user_base = site.USER_BASE
|
| 44 |
+
|
| 45 |
+
site.USER_BASE = self.mkdtemp()
|
| 46 |
+
build_ext.USER_BASE = site.USER_BASE
|
| 47 |
+
|
| 48 |
+
# bpo-30132: On Windows, a .pdb file may be created in the current
|
| 49 |
+
# working directory. Create a temporary working directory to cleanup
|
| 50 |
+
# everything at the end of the test.
|
| 51 |
+
with self.tmp_path:
|
| 52 |
+
yield
|
| 53 |
+
|
| 54 |
+
site.USER_BASE = orig_user_base
|
| 55 |
+
build_ext.USER_BASE = orig_user_base
|
| 56 |
+
|
| 57 |
+
if sys.platform == 'cygwin':
|
| 58 |
+
time.sleep(1)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@contextlib.contextmanager
|
| 62 |
+
def safe_extension_import(name, path):
|
| 63 |
+
with import_helper.CleanImport(name):
|
| 64 |
+
with extension_redirect(name, path) as new_path:
|
| 65 |
+
with import_helper.DirsOnSysPath(new_path):
|
| 66 |
+
yield
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
@contextlib.contextmanager
|
| 70 |
+
def extension_redirect(mod, path):
|
| 71 |
+
"""
|
| 72 |
+
Tests will fail to tear down an extension module if it's been imported.
|
| 73 |
+
|
| 74 |
+
Before importing, copy the file to a temporary directory that won't
|
| 75 |
+
be cleaned up. Yield the new path.
|
| 76 |
+
"""
|
| 77 |
+
if platform.system() != "Windows" and sys.platform != "cygwin":
|
| 78 |
+
yield path
|
| 79 |
+
return
|
| 80 |
+
with import_helper.DirsOnSysPath(path):
|
| 81 |
+
spec = importlib.util.find_spec(mod)
|
| 82 |
+
filename = os.path.basename(spec.origin)
|
| 83 |
+
trash_dir = tempfile.mkdtemp(prefix='deleteme')
|
| 84 |
+
dest = os.path.join(trash_dir, os.path.basename(filename))
|
| 85 |
+
shutil.copy(spec.origin, dest)
|
| 86 |
+
yield trash_dir
|
| 87 |
+
# TODO: can the file be scheduled for deletion?
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
@pytest.mark.usefixtures('user_site_dir')
|
| 91 |
+
class TestBuildExt(TempdirManager):
|
| 92 |
+
def build_ext(self, *args, **kwargs):
|
| 93 |
+
return build_ext(*args, **kwargs)
|
| 94 |
+
|
| 95 |
+
@pytest.mark.parametrize("copy_so", [False])
|
| 96 |
+
def test_build_ext(self, copy_so):
|
| 97 |
+
missing_compiler_executable()
|
| 98 |
+
copy_xxmodule_c(self.tmp_dir)
|
| 99 |
+
xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
|
| 100 |
+
xx_ext = Extension('xx', [xx_c])
|
| 101 |
+
if sys.platform != "win32":
|
| 102 |
+
if not copy_so:
|
| 103 |
+
xx_ext = Extension(
|
| 104 |
+
'xx',
|
| 105 |
+
[xx_c],
|
| 106 |
+
library_dirs=['/usr/lib'],
|
| 107 |
+
libraries=['z'],
|
| 108 |
+
runtime_library_dirs=['/usr/lib'],
|
| 109 |
+
)
|
| 110 |
+
elif sys.platform == 'linux':
|
| 111 |
+
libz_so = {
|
| 112 |
+
os.path.realpath(name) for name in glob.iglob('/usr/lib*/libz.so*')
|
| 113 |
+
}
|
| 114 |
+
libz_so = sorted(libz_so, key=lambda lib_path: len(lib_path))
|
| 115 |
+
shutil.copyfile(libz_so[-1], '/tmp/libxx_z.so')
|
| 116 |
+
|
| 117 |
+
xx_ext = Extension(
|
| 118 |
+
'xx',
|
| 119 |
+
[xx_c],
|
| 120 |
+
library_dirs=['/tmp'],
|
| 121 |
+
libraries=['xx_z'],
|
| 122 |
+
runtime_library_dirs=['/tmp'],
|
| 123 |
+
)
|
| 124 |
+
dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
|
| 125 |
+
dist.package_dir = self.tmp_dir
|
| 126 |
+
cmd = self.build_ext(dist)
|
| 127 |
+
fixup_build_ext(cmd)
|
| 128 |
+
cmd.build_lib = self.tmp_dir
|
| 129 |
+
cmd.build_temp = self.tmp_dir
|
| 130 |
+
|
| 131 |
+
old_stdout = sys.stdout
|
| 132 |
+
if not support.verbose:
|
| 133 |
+
# silence compiler output
|
| 134 |
+
sys.stdout = StringIO()
|
| 135 |
+
try:
|
| 136 |
+
cmd.ensure_finalized()
|
| 137 |
+
cmd.run()
|
| 138 |
+
finally:
|
| 139 |
+
sys.stdout = old_stdout
|
| 140 |
+
|
| 141 |
+
with safe_extension_import('xx', self.tmp_dir):
|
| 142 |
+
self._test_xx(copy_so)
|
| 143 |
+
|
| 144 |
+
if sys.platform == 'linux' and copy_so:
|
| 145 |
+
os.unlink('/tmp/libxx_z.so')
|
| 146 |
+
|
| 147 |
+
@staticmethod
|
| 148 |
+
def _test_xx(copy_so):
|
| 149 |
+
import xx # type: ignore[import-not-found] # Module generated for tests
|
| 150 |
+
|
| 151 |
+
for attr in ('error', 'foo', 'new', 'roj'):
|
| 152 |
+
assert hasattr(xx, attr)
|
| 153 |
+
|
| 154 |
+
assert xx.foo(2, 5) == 7
|
| 155 |
+
assert xx.foo(13, 15) == 28
|
| 156 |
+
assert xx.new().demo() is None
|
| 157 |
+
if support.HAVE_DOCSTRINGS:
|
| 158 |
+
doc = 'This is a template module just for instruction.'
|
| 159 |
+
assert xx.__doc__ == doc
|
| 160 |
+
assert isinstance(xx.Null(), xx.Null)
|
| 161 |
+
assert isinstance(xx.Str(), xx.Str)
|
| 162 |
+
|
| 163 |
+
if sys.platform == 'linux':
|
| 164 |
+
so_headers = subprocess.check_output(
|
| 165 |
+
["readelf", "-d", xx.__file__], universal_newlines=True
|
| 166 |
+
)
|
| 167 |
+
import pprint
|
| 168 |
+
|
| 169 |
+
pprint.pprint(so_headers)
|
| 170 |
+
rpaths = [
|
| 171 |
+
rpath
|
| 172 |
+
for line in so_headers.split("\n")
|
| 173 |
+
if "RPATH" in line or "RUNPATH" in line
|
| 174 |
+
for rpath in line.split()[2][1:-1].split(":")
|
| 175 |
+
]
|
| 176 |
+
if not copy_so:
|
| 177 |
+
pprint.pprint(rpaths)
|
| 178 |
+
# Linked against a library in /usr/lib{,64}
|
| 179 |
+
assert "/usr/lib" not in rpaths and "/usr/lib64" not in rpaths
|
| 180 |
+
else:
|
| 181 |
+
# Linked against a library in /tmp
|
| 182 |
+
assert "/tmp" in rpaths
|
| 183 |
+
# The import is the real test here
|
| 184 |
+
|
| 185 |
+
def test_solaris_enable_shared(self):
|
| 186 |
+
dist = Distribution({'name': 'xx'})
|
| 187 |
+
cmd = self.build_ext(dist)
|
| 188 |
+
old = sys.platform
|
| 189 |
+
|
| 190 |
+
sys.platform = 'sunos' # fooling finalize_options
|
| 191 |
+
from distutils.sysconfig import _config_vars
|
| 192 |
+
|
| 193 |
+
old_var = _config_vars.get('Py_ENABLE_SHARED')
|
| 194 |
+
_config_vars['Py_ENABLE_SHARED'] = True
|
| 195 |
+
try:
|
| 196 |
+
cmd.ensure_finalized()
|
| 197 |
+
finally:
|
| 198 |
+
sys.platform = old
|
| 199 |
+
if old_var is None:
|
| 200 |
+
del _config_vars['Py_ENABLE_SHARED']
|
| 201 |
+
else:
|
| 202 |
+
_config_vars['Py_ENABLE_SHARED'] = old_var
|
| 203 |
+
|
| 204 |
+
# make sure we get some library dirs under solaris
|
| 205 |
+
assert len(cmd.library_dirs) > 0
|
| 206 |
+
|
| 207 |
+
def test_user_site(self):
|
| 208 |
+
import site
|
| 209 |
+
|
| 210 |
+
dist = Distribution({'name': 'xx'})
|
| 211 |
+
cmd = self.build_ext(dist)
|
| 212 |
+
|
| 213 |
+
# making sure the user option is there
|
| 214 |
+
options = [name for name, short, label in cmd.user_options]
|
| 215 |
+
assert 'user' in options
|
| 216 |
+
|
| 217 |
+
# setting a value
|
| 218 |
+
cmd.user = True
|
| 219 |
+
|
| 220 |
+
# setting user based lib and include
|
| 221 |
+
lib = os.path.join(site.USER_BASE, 'lib')
|
| 222 |
+
incl = os.path.join(site.USER_BASE, 'include')
|
| 223 |
+
os.mkdir(lib)
|
| 224 |
+
os.mkdir(incl)
|
| 225 |
+
|
| 226 |
+
# let's run finalize
|
| 227 |
+
cmd.ensure_finalized()
|
| 228 |
+
|
| 229 |
+
# see if include_dirs and library_dirs
|
| 230 |
+
# were set
|
| 231 |
+
assert lib in cmd.library_dirs
|
| 232 |
+
assert lib in cmd.rpath
|
| 233 |
+
assert incl in cmd.include_dirs
|
| 234 |
+
|
| 235 |
+
def test_optional_extension(self):
|
| 236 |
+
# this extension will fail, but let's ignore this failure
|
| 237 |
+
# with the optional argument.
|
| 238 |
+
modules = [Extension('foo', ['xxx'], optional=False)]
|
| 239 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 240 |
+
cmd = self.build_ext(dist)
|
| 241 |
+
cmd.ensure_finalized()
|
| 242 |
+
with pytest.raises((UnknownFileError, CompileError)):
|
| 243 |
+
cmd.run() # should raise an error
|
| 244 |
+
|
| 245 |
+
modules = [Extension('foo', ['xxx'], optional=True)]
|
| 246 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 247 |
+
cmd = self.build_ext(dist)
|
| 248 |
+
cmd.ensure_finalized()
|
| 249 |
+
cmd.run() # should pass
|
| 250 |
+
|
| 251 |
+
def test_finalize_options(self):
|
| 252 |
+
# Make sure Python's include directories (for Python.h, pyconfig.h,
|
| 253 |
+
# etc.) are in the include search path.
|
| 254 |
+
modules = [Extension('foo', ['xxx'], optional=False)]
|
| 255 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 256 |
+
cmd = self.build_ext(dist)
|
| 257 |
+
cmd.finalize_options()
|
| 258 |
+
|
| 259 |
+
py_include = sysconfig.get_python_inc()
|
| 260 |
+
for p in py_include.split(os.path.pathsep):
|
| 261 |
+
assert p in cmd.include_dirs
|
| 262 |
+
|
| 263 |
+
plat_py_include = sysconfig.get_python_inc(plat_specific=True)
|
| 264 |
+
for p in plat_py_include.split(os.path.pathsep):
|
| 265 |
+
assert p in cmd.include_dirs
|
| 266 |
+
|
| 267 |
+
# make sure cmd.libraries is turned into a list
|
| 268 |
+
# if it's a string
|
| 269 |
+
cmd = self.build_ext(dist)
|
| 270 |
+
cmd.libraries = 'my_lib, other_lib lastlib'
|
| 271 |
+
cmd.finalize_options()
|
| 272 |
+
assert cmd.libraries == ['my_lib', 'other_lib', 'lastlib']
|
| 273 |
+
|
| 274 |
+
# make sure cmd.library_dirs is turned into a list
|
| 275 |
+
# if it's a string
|
| 276 |
+
cmd = self.build_ext(dist)
|
| 277 |
+
cmd.library_dirs = f'my_lib_dir{os.pathsep}other_lib_dir'
|
| 278 |
+
cmd.finalize_options()
|
| 279 |
+
assert 'my_lib_dir' in cmd.library_dirs
|
| 280 |
+
assert 'other_lib_dir' in cmd.library_dirs
|
| 281 |
+
|
| 282 |
+
# make sure rpath is turned into a list
|
| 283 |
+
# if it's a string
|
| 284 |
+
cmd = self.build_ext(dist)
|
| 285 |
+
cmd.rpath = f'one{os.pathsep}two'
|
| 286 |
+
cmd.finalize_options()
|
| 287 |
+
assert cmd.rpath == ['one', 'two']
|
| 288 |
+
|
| 289 |
+
# make sure cmd.link_objects is turned into a list
|
| 290 |
+
# if it's a string
|
| 291 |
+
cmd = build_ext(dist)
|
| 292 |
+
cmd.link_objects = 'one two,three'
|
| 293 |
+
cmd.finalize_options()
|
| 294 |
+
assert cmd.link_objects == ['one', 'two', 'three']
|
| 295 |
+
|
| 296 |
+
# XXX more tests to perform for win32
|
| 297 |
+
|
| 298 |
+
# make sure define is turned into 2-tuples
|
| 299 |
+
# strings if they are ','-separated strings
|
| 300 |
+
cmd = self.build_ext(dist)
|
| 301 |
+
cmd.define = 'one,two'
|
| 302 |
+
cmd.finalize_options()
|
| 303 |
+
assert cmd.define == [('one', '1'), ('two', '1')]
|
| 304 |
+
|
| 305 |
+
# make sure undef is turned into a list of
|
| 306 |
+
# strings if they are ','-separated strings
|
| 307 |
+
cmd = self.build_ext(dist)
|
| 308 |
+
cmd.undef = 'one,two'
|
| 309 |
+
cmd.finalize_options()
|
| 310 |
+
assert cmd.undef == ['one', 'two']
|
| 311 |
+
|
| 312 |
+
# make sure swig_opts is turned into a list
|
| 313 |
+
cmd = self.build_ext(dist)
|
| 314 |
+
cmd.swig_opts = None
|
| 315 |
+
cmd.finalize_options()
|
| 316 |
+
assert cmd.swig_opts == []
|
| 317 |
+
|
| 318 |
+
cmd = self.build_ext(dist)
|
| 319 |
+
cmd.swig_opts = '1 2'
|
| 320 |
+
cmd.finalize_options()
|
| 321 |
+
assert cmd.swig_opts == ['1', '2']
|
| 322 |
+
|
| 323 |
+
def test_check_extensions_list(self):
|
| 324 |
+
dist = Distribution()
|
| 325 |
+
cmd = self.build_ext(dist)
|
| 326 |
+
cmd.finalize_options()
|
| 327 |
+
|
| 328 |
+
# 'extensions' option must be a list of Extension instances
|
| 329 |
+
with pytest.raises(DistutilsSetupError):
|
| 330 |
+
cmd.check_extensions_list('foo')
|
| 331 |
+
|
| 332 |
+
# each element of 'ext_modules' option must be an
|
| 333 |
+
# Extension instance or 2-tuple
|
| 334 |
+
exts = [('bar', 'foo', 'bar'), 'foo']
|
| 335 |
+
with pytest.raises(DistutilsSetupError):
|
| 336 |
+
cmd.check_extensions_list(exts)
|
| 337 |
+
|
| 338 |
+
# first element of each tuple in 'ext_modules'
|
| 339 |
+
# must be the extension name (a string) and match
|
| 340 |
+
# a python dotted-separated name
|
| 341 |
+
exts = [('foo-bar', '')]
|
| 342 |
+
with pytest.raises(DistutilsSetupError):
|
| 343 |
+
cmd.check_extensions_list(exts)
|
| 344 |
+
|
| 345 |
+
# second element of each tuple in 'ext_modules'
|
| 346 |
+
# must be a dictionary (build info)
|
| 347 |
+
exts = [('foo.bar', '')]
|
| 348 |
+
with pytest.raises(DistutilsSetupError):
|
| 349 |
+
cmd.check_extensions_list(exts)
|
| 350 |
+
|
| 351 |
+
# ok this one should pass
|
| 352 |
+
exts = [('foo.bar', {'sources': [''], 'libraries': 'foo', 'some': 'bar'})]
|
| 353 |
+
cmd.check_extensions_list(exts)
|
| 354 |
+
ext = exts[0]
|
| 355 |
+
assert isinstance(ext, Extension)
|
| 356 |
+
|
| 357 |
+
# check_extensions_list adds in ext the values passed
|
| 358 |
+
# when they are in ('include_dirs', 'library_dirs', 'libraries'
|
| 359 |
+
# 'extra_objects', 'extra_compile_args', 'extra_link_args')
|
| 360 |
+
assert ext.libraries == 'foo'
|
| 361 |
+
assert not hasattr(ext, 'some')
|
| 362 |
+
|
| 363 |
+
# 'macros' element of build info dict must be 1- or 2-tuple
|
| 364 |
+
exts = [
|
| 365 |
+
(
|
| 366 |
+
'foo.bar',
|
| 367 |
+
{
|
| 368 |
+
'sources': [''],
|
| 369 |
+
'libraries': 'foo',
|
| 370 |
+
'some': 'bar',
|
| 371 |
+
'macros': [('1', '2', '3'), 'foo'],
|
| 372 |
+
},
|
| 373 |
+
)
|
| 374 |
+
]
|
| 375 |
+
with pytest.raises(DistutilsSetupError):
|
| 376 |
+
cmd.check_extensions_list(exts)
|
| 377 |
+
|
| 378 |
+
exts[0][1]['macros'] = [('1', '2'), ('3',)]
|
| 379 |
+
cmd.check_extensions_list(exts)
|
| 380 |
+
assert exts[0].undef_macros == ['3']
|
| 381 |
+
assert exts[0].define_macros == [('1', '2')]
|
| 382 |
+
|
| 383 |
+
def test_get_source_files(self):
|
| 384 |
+
modules = [Extension('foo', ['xxx'], optional=False)]
|
| 385 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 386 |
+
cmd = self.build_ext(dist)
|
| 387 |
+
cmd.ensure_finalized()
|
| 388 |
+
assert cmd.get_source_files() == ['xxx']
|
| 389 |
+
|
| 390 |
+
def test_unicode_module_names(self):
|
| 391 |
+
modules = [
|
| 392 |
+
Extension('foo', ['aaa'], optional=False),
|
| 393 |
+
Extension('föö', ['uuu'], optional=False),
|
| 394 |
+
]
|
| 395 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 396 |
+
cmd = self.build_ext(dist)
|
| 397 |
+
cmd.ensure_finalized()
|
| 398 |
+
assert re.search(r'foo(_d)?\..*', cmd.get_ext_filename(modules[0].name))
|
| 399 |
+
assert re.search(r'föö(_d)?\..*', cmd.get_ext_filename(modules[1].name))
|
| 400 |
+
assert cmd.get_export_symbols(modules[0]) == ['PyInit_foo']
|
| 401 |
+
assert cmd.get_export_symbols(modules[1]) == ['PyInitU_f_1gaa']
|
| 402 |
+
|
| 403 |
+
def test_export_symbols__init__(self):
|
| 404 |
+
# https://github.com/python/cpython/issues/80074
|
| 405 |
+
# https://github.com/pypa/setuptools/issues/4826
|
| 406 |
+
modules = [
|
| 407 |
+
Extension('foo.__init__', ['aaa']),
|
| 408 |
+
Extension('föö.__init__', ['uuu']),
|
| 409 |
+
]
|
| 410 |
+
dist = Distribution({'name': 'xx', 'ext_modules': modules})
|
| 411 |
+
cmd = self.build_ext(dist)
|
| 412 |
+
cmd.ensure_finalized()
|
| 413 |
+
assert cmd.get_export_symbols(modules[0]) == ['PyInit_foo']
|
| 414 |
+
assert cmd.get_export_symbols(modules[1]) == ['PyInitU_f_1gaa']
|
| 415 |
+
|
| 416 |
+
def test_compiler_option(self):
|
| 417 |
+
# cmd.compiler is an option and
|
| 418 |
+
# should not be overridden by a compiler instance
|
| 419 |
+
# when the command is run
|
| 420 |
+
dist = Distribution()
|
| 421 |
+
cmd = self.build_ext(dist)
|
| 422 |
+
cmd.compiler = 'unix'
|
| 423 |
+
cmd.ensure_finalized()
|
| 424 |
+
cmd.run()
|
| 425 |
+
assert cmd.compiler == 'unix'
|
| 426 |
+
|
| 427 |
+
def test_get_outputs(self):
|
| 428 |
+
missing_compiler_executable()
|
| 429 |
+
tmp_dir = self.mkdtemp()
|
| 430 |
+
c_file = os.path.join(tmp_dir, 'foo.c')
|
| 431 |
+
self.write_file(c_file, 'void PyInit_foo(void) {}\n')
|
| 432 |
+
ext = Extension('foo', [c_file], optional=False)
|
| 433 |
+
dist = Distribution({'name': 'xx', 'ext_modules': [ext]})
|
| 434 |
+
cmd = self.build_ext(dist)
|
| 435 |
+
fixup_build_ext(cmd)
|
| 436 |
+
cmd.ensure_finalized()
|
| 437 |
+
assert len(cmd.get_outputs()) == 1
|
| 438 |
+
|
| 439 |
+
cmd.build_lib = os.path.join(self.tmp_dir, 'build')
|
| 440 |
+
cmd.build_temp = os.path.join(self.tmp_dir, 'tempt')
|
| 441 |
+
|
| 442 |
+
# issue #5977 : distutils build_ext.get_outputs
|
| 443 |
+
# returns wrong result with --inplace
|
| 444 |
+
other_tmp_dir = os.path.realpath(self.mkdtemp())
|
| 445 |
+
old_wd = os.getcwd()
|
| 446 |
+
os.chdir(other_tmp_dir)
|
| 447 |
+
try:
|
| 448 |
+
cmd.inplace = True
|
| 449 |
+
cmd.run()
|
| 450 |
+
so_file = cmd.get_outputs()[0]
|
| 451 |
+
finally:
|
| 452 |
+
os.chdir(old_wd)
|
| 453 |
+
assert os.path.exists(so_file)
|
| 454 |
+
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
|
| 455 |
+
assert so_file.endswith(ext_suffix)
|
| 456 |
+
so_dir = os.path.dirname(so_file)
|
| 457 |
+
assert so_dir == other_tmp_dir
|
| 458 |
+
|
| 459 |
+
cmd.inplace = False
|
| 460 |
+
cmd.compiler = None
|
| 461 |
+
cmd.run()
|
| 462 |
+
so_file = cmd.get_outputs()[0]
|
| 463 |
+
assert os.path.exists(so_file)
|
| 464 |
+
assert so_file.endswith(ext_suffix)
|
| 465 |
+
so_dir = os.path.dirname(so_file)
|
| 466 |
+
assert so_dir == cmd.build_lib
|
| 467 |
+
|
| 468 |
+
# inplace = False, cmd.package = 'bar'
|
| 469 |
+
build_py = cmd.get_finalized_command('build_py')
|
| 470 |
+
build_py.package_dir = {'': 'bar'}
|
| 471 |
+
path = cmd.get_ext_fullpath('foo')
|
| 472 |
+
# checking that the last directory is the build_dir
|
| 473 |
+
path = os.path.split(path)[0]
|
| 474 |
+
assert path == cmd.build_lib
|
| 475 |
+
|
| 476 |
+
# inplace = True, cmd.package = 'bar'
|
| 477 |
+
cmd.inplace = True
|
| 478 |
+
other_tmp_dir = os.path.realpath(self.mkdtemp())
|
| 479 |
+
old_wd = os.getcwd()
|
| 480 |
+
os.chdir(other_tmp_dir)
|
| 481 |
+
try:
|
| 482 |
+
path = cmd.get_ext_fullpath('foo')
|
| 483 |
+
finally:
|
| 484 |
+
os.chdir(old_wd)
|
| 485 |
+
# checking that the last directory is bar
|
| 486 |
+
path = os.path.split(path)[0]
|
| 487 |
+
lastdir = os.path.split(path)[-1]
|
| 488 |
+
assert lastdir == 'bar'
|
| 489 |
+
|
| 490 |
+
def test_ext_fullpath(self):
|
| 491 |
+
ext = sysconfig.get_config_var('EXT_SUFFIX')
|
| 492 |
+
# building lxml.etree inplace
|
| 493 |
+
# etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
|
| 494 |
+
# etree_ext = Extension('lxml.etree', [etree_c])
|
| 495 |
+
# dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
|
| 496 |
+
dist = Distribution()
|
| 497 |
+
cmd = self.build_ext(dist)
|
| 498 |
+
cmd.inplace = True
|
| 499 |
+
cmd.distribution.package_dir = {'': 'src'}
|
| 500 |
+
cmd.distribution.packages = ['lxml', 'lxml.html']
|
| 501 |
+
curdir = os.getcwd()
|
| 502 |
+
wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
|
| 503 |
+
path = cmd.get_ext_fullpath('lxml.etree')
|
| 504 |
+
assert wanted == path
|
| 505 |
+
|
| 506 |
+
# building lxml.etree not inplace
|
| 507 |
+
cmd.inplace = False
|
| 508 |
+
cmd.build_lib = os.path.join(curdir, 'tmpdir')
|
| 509 |
+
wanted = os.path.join(curdir, 'tmpdir', 'lxml', 'etree' + ext)
|
| 510 |
+
path = cmd.get_ext_fullpath('lxml.etree')
|
| 511 |
+
assert wanted == path
|
| 512 |
+
|
| 513 |
+
# building twisted.runner.portmap not inplace
|
| 514 |
+
build_py = cmd.get_finalized_command('build_py')
|
| 515 |
+
build_py.package_dir = {}
|
| 516 |
+
cmd.distribution.packages = ['twisted', 'twisted.runner.portmap']
|
| 517 |
+
path = cmd.get_ext_fullpath('twisted.runner.portmap')
|
| 518 |
+
wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner', 'portmap' + ext)
|
| 519 |
+
assert wanted == path
|
| 520 |
+
|
| 521 |
+
# building twisted.runner.portmap inplace
|
| 522 |
+
cmd.inplace = True
|
| 523 |
+
path = cmd.get_ext_fullpath('twisted.runner.portmap')
|
| 524 |
+
wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext)
|
| 525 |
+
assert wanted == path
|
| 526 |
+
|
| 527 |
+
@pytest.mark.skipif('platform.system() != "Darwin"')
|
| 528 |
+
@pytest.mark.usefixtures('save_env')
|
| 529 |
+
def test_deployment_target_default(self):
|
| 530 |
+
# Issue 9516: Test that, in the absence of the environment variable,
|
| 531 |
+
# an extension module is compiled with the same deployment target as
|
| 532 |
+
# the interpreter.
|
| 533 |
+
self._try_compile_deployment_target('==', None)
|
| 534 |
+
|
| 535 |
+
@pytest.mark.skipif('platform.system() != "Darwin"')
|
| 536 |
+
@pytest.mark.usefixtures('save_env')
|
| 537 |
+
def test_deployment_target_too_low(self):
|
| 538 |
+
# Issue 9516: Test that an extension module is not allowed to be
|
| 539 |
+
# compiled with a deployment target less than that of the interpreter.
|
| 540 |
+
with pytest.raises(DistutilsPlatformError):
|
| 541 |
+
self._try_compile_deployment_target('>', '10.1')
|
| 542 |
+
|
| 543 |
+
@pytest.mark.skipif('platform.system() != "Darwin"')
|
| 544 |
+
@pytest.mark.usefixtures('save_env')
|
| 545 |
+
def test_deployment_target_higher_ok(self): # pragma: no cover
|
| 546 |
+
# Issue 9516: Test that an extension module can be compiled with a
|
| 547 |
+
# deployment target higher than that of the interpreter: the ext
|
| 548 |
+
# module may depend on some newer OS feature.
|
| 549 |
+
deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
|
| 550 |
+
if deptarget:
|
| 551 |
+
# increment the minor version number (i.e. 10.6 -> 10.7)
|
| 552 |
+
deptarget = [int(x) for x in deptarget.split('.')]
|
| 553 |
+
deptarget[-1] += 1
|
| 554 |
+
deptarget = '.'.join(str(i) for i in deptarget)
|
| 555 |
+
self._try_compile_deployment_target('<', deptarget)
|
| 556 |
+
|
| 557 |
+
def _try_compile_deployment_target(self, operator, target): # pragma: no cover
|
| 558 |
+
if target is None:
|
| 559 |
+
if os.environ.get('MACOSX_DEPLOYMENT_TARGET'):
|
| 560 |
+
del os.environ['MACOSX_DEPLOYMENT_TARGET']
|
| 561 |
+
else:
|
| 562 |
+
os.environ['MACOSX_DEPLOYMENT_TARGET'] = target
|
| 563 |
+
|
| 564 |
+
jaraco.path.build(
|
| 565 |
+
{
|
| 566 |
+
'deptargetmodule.c': textwrap.dedent(f"""\
|
| 567 |
+
#include <AvailabilityMacros.h>
|
| 568 |
+
|
| 569 |
+
int dummy;
|
| 570 |
+
|
| 571 |
+
#if TARGET {operator} MAC_OS_X_VERSION_MIN_REQUIRED
|
| 572 |
+
#else
|
| 573 |
+
#error "Unexpected target"
|
| 574 |
+
#endif
|
| 575 |
+
|
| 576 |
+
"""),
|
| 577 |
+
},
|
| 578 |
+
self.tmp_path,
|
| 579 |
+
)
|
| 580 |
+
|
| 581 |
+
# get the deployment target that the interpreter was built with
|
| 582 |
+
target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
|
| 583 |
+
target = tuple(map(int, target.split('.')[0:2]))
|
| 584 |
+
# format the target value as defined in the Apple
|
| 585 |
+
# Availability Macros. We can't use the macro names since
|
| 586 |
+
# at least one value we test with will not exist yet.
|
| 587 |
+
if target[:2] < (10, 10):
|
| 588 |
+
# for 10.1 through 10.9.x -> "10n0"
|
| 589 |
+
tmpl = '{:02}{:01}0'
|
| 590 |
+
else:
|
| 591 |
+
# for 10.10 and beyond -> "10nn00"
|
| 592 |
+
if len(target) >= 2:
|
| 593 |
+
tmpl = '{:02}{:02}00'
|
| 594 |
+
else:
|
| 595 |
+
# 11 and later can have no minor version (11 instead of 11.0)
|
| 596 |
+
tmpl = '{:02}0000'
|
| 597 |
+
target = tmpl.format(*target)
|
| 598 |
+
deptarget_ext = Extension(
|
| 599 |
+
'deptarget',
|
| 600 |
+
[self.tmp_path / 'deptargetmodule.c'],
|
| 601 |
+
extra_compile_args=[f'-DTARGET={target}'],
|
| 602 |
+
)
|
| 603 |
+
dist = Distribution({'name': 'deptarget', 'ext_modules': [deptarget_ext]})
|
| 604 |
+
dist.package_dir = self.tmp_dir
|
| 605 |
+
cmd = self.build_ext(dist)
|
| 606 |
+
cmd.build_lib = self.tmp_dir
|
| 607 |
+
cmd.build_temp = self.tmp_dir
|
| 608 |
+
|
| 609 |
+
try:
|
| 610 |
+
old_stdout = sys.stdout
|
| 611 |
+
if not support.verbose:
|
| 612 |
+
# silence compiler output
|
| 613 |
+
sys.stdout = StringIO()
|
| 614 |
+
try:
|
| 615 |
+
cmd.ensure_finalized()
|
| 616 |
+
cmd.run()
|
| 617 |
+
finally:
|
| 618 |
+
sys.stdout = old_stdout
|
| 619 |
+
|
| 620 |
+
except CompileError:
|
| 621 |
+
self.fail("Wrong deployment target during compilation")
|
| 622 |
+
|
| 623 |
+
|
| 624 |
+
class TestParallelBuildExt(TestBuildExt):
|
| 625 |
+
def build_ext(self, *args, **kwargs):
|
| 626 |
+
build_ext = super().build_ext(*args, **kwargs)
|
| 627 |
+
build_ext.parallel = True
|
| 628 |
+
return build_ext
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_build_py.py
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.build_py."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from distutils.command.build_py import build_py
|
| 6 |
+
from distutils.core import Distribution
|
| 7 |
+
from distutils.errors import DistutilsFileError
|
| 8 |
+
from distutils.tests import support
|
| 9 |
+
|
| 10 |
+
import jaraco.path
|
| 11 |
+
import pytest
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@support.combine_markers
|
| 15 |
+
class TestBuildPy(support.TempdirManager):
|
| 16 |
+
def test_package_data(self):
|
| 17 |
+
sources = self.mkdtemp()
|
| 18 |
+
jaraco.path.build(
|
| 19 |
+
{
|
| 20 |
+
'__init__.py': "# Pretend this is a package.",
|
| 21 |
+
'README.txt': 'Info about this package',
|
| 22 |
+
},
|
| 23 |
+
sources,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
destination = self.mkdtemp()
|
| 27 |
+
|
| 28 |
+
dist = Distribution({"packages": ["pkg"], "package_dir": {"pkg": sources}})
|
| 29 |
+
# script_name need not exist, it just need to be initialized
|
| 30 |
+
dist.script_name = os.path.join(sources, "setup.py")
|
| 31 |
+
dist.command_obj["build"] = support.DummyCommand(
|
| 32 |
+
force=False, build_lib=destination
|
| 33 |
+
)
|
| 34 |
+
dist.packages = ["pkg"]
|
| 35 |
+
dist.package_data = {"pkg": ["README.txt"]}
|
| 36 |
+
dist.package_dir = {"pkg": sources}
|
| 37 |
+
|
| 38 |
+
cmd = build_py(dist)
|
| 39 |
+
cmd.compile = True
|
| 40 |
+
cmd.ensure_finalized()
|
| 41 |
+
assert cmd.package_data == dist.package_data
|
| 42 |
+
|
| 43 |
+
cmd.run()
|
| 44 |
+
|
| 45 |
+
# This makes sure the list of outputs includes byte-compiled
|
| 46 |
+
# files for Python modules but not for package data files
|
| 47 |
+
# (there shouldn't *be* byte-code files for those!).
|
| 48 |
+
assert len(cmd.get_outputs()) == 3
|
| 49 |
+
pkgdest = os.path.join(destination, "pkg")
|
| 50 |
+
files = os.listdir(pkgdest)
|
| 51 |
+
pycache_dir = os.path.join(pkgdest, "__pycache__")
|
| 52 |
+
assert "__init__.py" in files
|
| 53 |
+
assert "README.txt" in files
|
| 54 |
+
if sys.dont_write_bytecode:
|
| 55 |
+
assert not os.path.exists(pycache_dir)
|
| 56 |
+
else:
|
| 57 |
+
pyc_files = os.listdir(pycache_dir)
|
| 58 |
+
assert f"__init__.{sys.implementation.cache_tag}.pyc" in pyc_files
|
| 59 |
+
|
| 60 |
+
def test_empty_package_dir(self):
|
| 61 |
+
# See bugs #1668596/#1720897
|
| 62 |
+
sources = self.mkdtemp()
|
| 63 |
+
jaraco.path.build({'__init__.py': '', 'doc': {'testfile': ''}}, sources)
|
| 64 |
+
|
| 65 |
+
os.chdir(sources)
|
| 66 |
+
dist = Distribution({
|
| 67 |
+
"packages": ["pkg"],
|
| 68 |
+
"package_dir": {"pkg": ""},
|
| 69 |
+
"package_data": {"pkg": ["doc/*"]},
|
| 70 |
+
})
|
| 71 |
+
# script_name need not exist, it just need to be initialized
|
| 72 |
+
dist.script_name = os.path.join(sources, "setup.py")
|
| 73 |
+
dist.script_args = ["build"]
|
| 74 |
+
dist.parse_command_line()
|
| 75 |
+
|
| 76 |
+
try:
|
| 77 |
+
dist.run_commands()
|
| 78 |
+
except DistutilsFileError:
|
| 79 |
+
self.fail("failed package_data test when package_dir is ''")
|
| 80 |
+
|
| 81 |
+
@pytest.mark.skipif('sys.dont_write_bytecode')
|
| 82 |
+
def test_byte_compile(self):
|
| 83 |
+
project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
|
| 84 |
+
os.chdir(project_dir)
|
| 85 |
+
self.write_file('boiledeggs.py', 'import antigravity')
|
| 86 |
+
cmd = build_py(dist)
|
| 87 |
+
cmd.compile = True
|
| 88 |
+
cmd.build_lib = 'here'
|
| 89 |
+
cmd.finalize_options()
|
| 90 |
+
cmd.run()
|
| 91 |
+
|
| 92 |
+
found = os.listdir(cmd.build_lib)
|
| 93 |
+
assert sorted(found) == ['__pycache__', 'boiledeggs.py']
|
| 94 |
+
found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
|
| 95 |
+
assert found == [f'boiledeggs.{sys.implementation.cache_tag}.pyc']
|
| 96 |
+
|
| 97 |
+
@pytest.mark.skipif('sys.dont_write_bytecode')
|
| 98 |
+
def test_byte_compile_optimized(self):
|
| 99 |
+
project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
|
| 100 |
+
os.chdir(project_dir)
|
| 101 |
+
self.write_file('boiledeggs.py', 'import antigravity')
|
| 102 |
+
cmd = build_py(dist)
|
| 103 |
+
cmd.compile = False
|
| 104 |
+
cmd.optimize = 1
|
| 105 |
+
cmd.build_lib = 'here'
|
| 106 |
+
cmd.finalize_options()
|
| 107 |
+
cmd.run()
|
| 108 |
+
|
| 109 |
+
found = os.listdir(cmd.build_lib)
|
| 110 |
+
assert sorted(found) == ['__pycache__', 'boiledeggs.py']
|
| 111 |
+
found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
|
| 112 |
+
expect = f'boiledeggs.{sys.implementation.cache_tag}.opt-1.pyc'
|
| 113 |
+
assert sorted(found) == [expect]
|
| 114 |
+
|
| 115 |
+
def test_dir_in_package_data(self):
|
| 116 |
+
"""
|
| 117 |
+
A directory in package_data should not be added to the filelist.
|
| 118 |
+
"""
|
| 119 |
+
# See bug 19286
|
| 120 |
+
sources = self.mkdtemp()
|
| 121 |
+
jaraco.path.build(
|
| 122 |
+
{
|
| 123 |
+
'pkg': {
|
| 124 |
+
'__init__.py': '',
|
| 125 |
+
'doc': {
|
| 126 |
+
'testfile': '',
|
| 127 |
+
# create a directory that could be incorrectly detected as a file
|
| 128 |
+
'otherdir': {},
|
| 129 |
+
},
|
| 130 |
+
}
|
| 131 |
+
},
|
| 132 |
+
sources,
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
os.chdir(sources)
|
| 136 |
+
dist = Distribution({"packages": ["pkg"], "package_data": {"pkg": ["doc/*"]}})
|
| 137 |
+
# script_name need not exist, it just need to be initialized
|
| 138 |
+
dist.script_name = os.path.join(sources, "setup.py")
|
| 139 |
+
dist.script_args = ["build"]
|
| 140 |
+
dist.parse_command_line()
|
| 141 |
+
|
| 142 |
+
try:
|
| 143 |
+
dist.run_commands()
|
| 144 |
+
except DistutilsFileError:
|
| 145 |
+
self.fail("failed package_data when data dir includes a dir")
|
| 146 |
+
|
| 147 |
+
def test_dont_write_bytecode(self, caplog):
|
| 148 |
+
# makes sure byte_compile is not used
|
| 149 |
+
dist = self.create_dist()[1]
|
| 150 |
+
cmd = build_py(dist)
|
| 151 |
+
cmd.compile = True
|
| 152 |
+
cmd.optimize = 1
|
| 153 |
+
|
| 154 |
+
old_dont_write_bytecode = sys.dont_write_bytecode
|
| 155 |
+
sys.dont_write_bytecode = True
|
| 156 |
+
try:
|
| 157 |
+
cmd.byte_compile([])
|
| 158 |
+
finally:
|
| 159 |
+
sys.dont_write_bytecode = old_dont_write_bytecode
|
| 160 |
+
|
| 161 |
+
assert 'byte-compiling is disabled' in caplog.records[0].message
|
| 162 |
+
|
| 163 |
+
def test_namespace_package_does_not_warn(self, caplog):
|
| 164 |
+
"""
|
| 165 |
+
Originally distutils implementation did not account for PEP 420
|
| 166 |
+
and included warns for package directories that did not contain
|
| 167 |
+
``__init__.py`` files.
|
| 168 |
+
After the acceptance of PEP 420, these warnings don't make more sense
|
| 169 |
+
so we want to ensure there are not displayed to not confuse the users.
|
| 170 |
+
"""
|
| 171 |
+
# Create a fake project structure with a package namespace:
|
| 172 |
+
tmp = self.mkdtemp()
|
| 173 |
+
jaraco.path.build({'ns': {'pkg': {'module.py': ''}}}, tmp)
|
| 174 |
+
os.chdir(tmp)
|
| 175 |
+
|
| 176 |
+
# Configure the package:
|
| 177 |
+
attrs = {
|
| 178 |
+
"name": "ns.pkg",
|
| 179 |
+
"packages": ["ns", "ns.pkg"],
|
| 180 |
+
"script_name": "setup.py",
|
| 181 |
+
}
|
| 182 |
+
dist = Distribution(attrs)
|
| 183 |
+
|
| 184 |
+
# Run code paths that would trigger the trap:
|
| 185 |
+
cmd = dist.get_command_obj("build_py")
|
| 186 |
+
cmd.finalize_options()
|
| 187 |
+
modules = cmd.find_all_modules()
|
| 188 |
+
assert len(modules) == 1
|
| 189 |
+
module_path = modules[0][-1]
|
| 190 |
+
assert module_path.replace(os.sep, "/") == "ns/pkg/module.py"
|
| 191 |
+
|
| 192 |
+
cmd.run()
|
| 193 |
+
|
| 194 |
+
assert not any(
|
| 195 |
+
"package init file" in msg and "not found" in msg for msg in caplog.messages
|
| 196 |
+
)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_build_scripts.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.build_scripts."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import textwrap
|
| 5 |
+
from distutils import sysconfig
|
| 6 |
+
from distutils.command.build_scripts import build_scripts
|
| 7 |
+
from distutils.core import Distribution
|
| 8 |
+
from distutils.tests import support
|
| 9 |
+
|
| 10 |
+
import jaraco.path
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class TestBuildScripts(support.TempdirManager):
|
| 14 |
+
def test_default_settings(self):
|
| 15 |
+
cmd = self.get_build_scripts_cmd("/foo/bar", [])
|
| 16 |
+
assert not cmd.force
|
| 17 |
+
assert cmd.build_dir is None
|
| 18 |
+
|
| 19 |
+
cmd.finalize_options()
|
| 20 |
+
|
| 21 |
+
assert cmd.force
|
| 22 |
+
assert cmd.build_dir == "/foo/bar"
|
| 23 |
+
|
| 24 |
+
def test_build(self):
|
| 25 |
+
source = self.mkdtemp()
|
| 26 |
+
target = self.mkdtemp()
|
| 27 |
+
expected = self.write_sample_scripts(source)
|
| 28 |
+
|
| 29 |
+
cmd = self.get_build_scripts_cmd(
|
| 30 |
+
target, [os.path.join(source, fn) for fn in expected]
|
| 31 |
+
)
|
| 32 |
+
cmd.finalize_options()
|
| 33 |
+
cmd.run()
|
| 34 |
+
|
| 35 |
+
built = os.listdir(target)
|
| 36 |
+
for name in expected:
|
| 37 |
+
assert name in built
|
| 38 |
+
|
| 39 |
+
def get_build_scripts_cmd(self, target, scripts):
|
| 40 |
+
import sys
|
| 41 |
+
|
| 42 |
+
dist = Distribution()
|
| 43 |
+
dist.scripts = scripts
|
| 44 |
+
dist.command_obj["build"] = support.DummyCommand(
|
| 45 |
+
build_scripts=target, force=True, executable=sys.executable
|
| 46 |
+
)
|
| 47 |
+
return build_scripts(dist)
|
| 48 |
+
|
| 49 |
+
@staticmethod
|
| 50 |
+
def write_sample_scripts(dir):
|
| 51 |
+
spec = {
|
| 52 |
+
'script1.py': textwrap.dedent("""
|
| 53 |
+
#! /usr/bin/env python2.3
|
| 54 |
+
# bogus script w/ Python sh-bang
|
| 55 |
+
pass
|
| 56 |
+
""").lstrip(),
|
| 57 |
+
'script2.py': textwrap.dedent("""
|
| 58 |
+
#!/usr/bin/python
|
| 59 |
+
# bogus script w/ Python sh-bang
|
| 60 |
+
pass
|
| 61 |
+
""").lstrip(),
|
| 62 |
+
'shell.sh': textwrap.dedent("""
|
| 63 |
+
#!/bin/sh
|
| 64 |
+
# bogus shell script w/ sh-bang
|
| 65 |
+
exit 0
|
| 66 |
+
""").lstrip(),
|
| 67 |
+
}
|
| 68 |
+
jaraco.path.build(spec, dir)
|
| 69 |
+
return list(spec)
|
| 70 |
+
|
| 71 |
+
def test_version_int(self):
|
| 72 |
+
source = self.mkdtemp()
|
| 73 |
+
target = self.mkdtemp()
|
| 74 |
+
expected = self.write_sample_scripts(source)
|
| 75 |
+
|
| 76 |
+
cmd = self.get_build_scripts_cmd(
|
| 77 |
+
target, [os.path.join(source, fn) for fn in expected]
|
| 78 |
+
)
|
| 79 |
+
cmd.finalize_options()
|
| 80 |
+
|
| 81 |
+
# https://bugs.python.org/issue4524
|
| 82 |
+
#
|
| 83 |
+
# On linux-g++-32 with command line `./configure --enable-ipv6
|
| 84 |
+
# --with-suffix=3`, python is compiled okay but the build scripts
|
| 85 |
+
# failed when writing the name of the executable
|
| 86 |
+
old = sysconfig.get_config_vars().get('VERSION')
|
| 87 |
+
sysconfig._config_vars['VERSION'] = 4
|
| 88 |
+
try:
|
| 89 |
+
cmd.run()
|
| 90 |
+
finally:
|
| 91 |
+
if old is not None:
|
| 92 |
+
sysconfig._config_vars['VERSION'] = old
|
| 93 |
+
|
| 94 |
+
built = os.listdir(target)
|
| 95 |
+
for name in expected:
|
| 96 |
+
assert name in built
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_check.py
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.check."""
|
| 2 |
+
|
| 3 |
+
import distutils.command.check as _check
|
| 4 |
+
import importlib
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
import textwrap
|
| 8 |
+
from distutils.errors import DistutilsSetupError
|
| 9 |
+
from distutils.tests import support
|
| 10 |
+
|
| 11 |
+
import pytest
|
| 12 |
+
|
| 13 |
+
HERE = os.path.dirname(__file__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@pytest.fixture
|
| 17 |
+
def hide_pygments(monkeypatch, request):
|
| 18 |
+
"""
|
| 19 |
+
Clear docutils and hide the presence of pygments.
|
| 20 |
+
"""
|
| 21 |
+
clear_docutils(monkeypatch)
|
| 22 |
+
monkeypatch.setitem(sys.modules, 'pygments', None)
|
| 23 |
+
reload_check()
|
| 24 |
+
# restore 'check' to its normal state after monkeypatch is undone
|
| 25 |
+
request.addfinalizer(reload_check)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def clear_docutils(monkeypatch):
|
| 29 |
+
docutils_names = [
|
| 30 |
+
name for name in sys.modules if name.partition('.')[0] == 'docutils'
|
| 31 |
+
]
|
| 32 |
+
for name in docutils_names:
|
| 33 |
+
monkeypatch.delitem(sys.modules, name)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def reload_check():
|
| 37 |
+
"""
|
| 38 |
+
Reload the 'check' command module to reflect the import state.
|
| 39 |
+
"""
|
| 40 |
+
importlib.reload(_check)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@support.combine_markers
|
| 44 |
+
class TestCheck(support.TempdirManager):
|
| 45 |
+
def _run(self, metadata=None, cwd=None, **options):
|
| 46 |
+
if metadata is None:
|
| 47 |
+
metadata = {}
|
| 48 |
+
if cwd is not None:
|
| 49 |
+
old_dir = os.getcwd()
|
| 50 |
+
os.chdir(cwd)
|
| 51 |
+
pkg_info, dist = self.create_dist(**metadata)
|
| 52 |
+
cmd = _check.check(dist)
|
| 53 |
+
cmd.initialize_options()
|
| 54 |
+
for name, value in options.items():
|
| 55 |
+
setattr(cmd, name, value)
|
| 56 |
+
cmd.ensure_finalized()
|
| 57 |
+
cmd.run()
|
| 58 |
+
if cwd is not None:
|
| 59 |
+
os.chdir(old_dir)
|
| 60 |
+
return cmd
|
| 61 |
+
|
| 62 |
+
def test_check_metadata(self):
|
| 63 |
+
# let's run the command with no metadata at all
|
| 64 |
+
# by default, check is checking the metadata
|
| 65 |
+
# should have some warnings
|
| 66 |
+
cmd = self._run()
|
| 67 |
+
assert cmd._warnings == 1
|
| 68 |
+
|
| 69 |
+
# now let's add the required fields
|
| 70 |
+
# and run it again, to make sure we don't get
|
| 71 |
+
# any warning anymore
|
| 72 |
+
metadata = {
|
| 73 |
+
'url': 'xxx',
|
| 74 |
+
'author': 'xxx',
|
| 75 |
+
'author_email': 'xxx',
|
| 76 |
+
'name': 'xxx',
|
| 77 |
+
'version': 'xxx',
|
| 78 |
+
}
|
| 79 |
+
cmd = self._run(metadata)
|
| 80 |
+
assert cmd._warnings == 0
|
| 81 |
+
|
| 82 |
+
# now with the strict mode, we should
|
| 83 |
+
# get an error if there are missing metadata
|
| 84 |
+
with pytest.raises(DistutilsSetupError):
|
| 85 |
+
self._run({}, **{'strict': 1})
|
| 86 |
+
|
| 87 |
+
# and of course, no error when all metadata are present
|
| 88 |
+
cmd = self._run(metadata, strict=True)
|
| 89 |
+
assert cmd._warnings == 0
|
| 90 |
+
|
| 91 |
+
# now a test with non-ASCII characters
|
| 92 |
+
metadata = {
|
| 93 |
+
'url': 'xxx',
|
| 94 |
+
'author': '\u00c9ric',
|
| 95 |
+
'author_email': 'xxx',
|
| 96 |
+
'name': 'xxx',
|
| 97 |
+
'version': 'xxx',
|
| 98 |
+
'description': 'Something about esszet \u00df',
|
| 99 |
+
'long_description': 'More things about esszet \u00df',
|
| 100 |
+
}
|
| 101 |
+
cmd = self._run(metadata)
|
| 102 |
+
assert cmd._warnings == 0
|
| 103 |
+
|
| 104 |
+
def test_check_author_maintainer(self):
|
| 105 |
+
for kind in ("author", "maintainer"):
|
| 106 |
+
# ensure no warning when author_email or maintainer_email is given
|
| 107 |
+
# (the spec allows these fields to take the form "Name <email>")
|
| 108 |
+
metadata = {
|
| 109 |
+
'url': 'xxx',
|
| 110 |
+
kind + '_email': 'Name <name@email.com>',
|
| 111 |
+
'name': 'xxx',
|
| 112 |
+
'version': 'xxx',
|
| 113 |
+
}
|
| 114 |
+
cmd = self._run(metadata)
|
| 115 |
+
assert cmd._warnings == 0
|
| 116 |
+
|
| 117 |
+
# the check should not warn if only email is given
|
| 118 |
+
metadata[kind + '_email'] = 'name@email.com'
|
| 119 |
+
cmd = self._run(metadata)
|
| 120 |
+
assert cmd._warnings == 0
|
| 121 |
+
|
| 122 |
+
# the check should not warn if only the name is given
|
| 123 |
+
metadata[kind] = "Name"
|
| 124 |
+
del metadata[kind + '_email']
|
| 125 |
+
cmd = self._run(metadata)
|
| 126 |
+
assert cmd._warnings == 0
|
| 127 |
+
|
| 128 |
+
def test_check_document(self):
|
| 129 |
+
pkg_info, dist = self.create_dist()
|
| 130 |
+
cmd = _check.check(dist)
|
| 131 |
+
|
| 132 |
+
# let's see if it detects broken rest
|
| 133 |
+
broken_rest = 'title\n===\n\ntest'
|
| 134 |
+
msgs = cmd._check_rst_data(broken_rest)
|
| 135 |
+
assert len(msgs) == 1
|
| 136 |
+
|
| 137 |
+
# and non-broken rest
|
| 138 |
+
rest = 'title\n=====\n\ntest'
|
| 139 |
+
msgs = cmd._check_rst_data(rest)
|
| 140 |
+
assert len(msgs) == 0
|
| 141 |
+
|
| 142 |
+
def test_check_restructuredtext(self):
|
| 143 |
+
# let's see if it detects broken rest in long_description
|
| 144 |
+
broken_rest = 'title\n===\n\ntest'
|
| 145 |
+
pkg_info, dist = self.create_dist(long_description=broken_rest)
|
| 146 |
+
cmd = _check.check(dist)
|
| 147 |
+
cmd.check_restructuredtext()
|
| 148 |
+
assert cmd._warnings == 1
|
| 149 |
+
|
| 150 |
+
# let's see if we have an error with strict=True
|
| 151 |
+
metadata = {
|
| 152 |
+
'url': 'xxx',
|
| 153 |
+
'author': 'xxx',
|
| 154 |
+
'author_email': 'xxx',
|
| 155 |
+
'name': 'xxx',
|
| 156 |
+
'version': 'xxx',
|
| 157 |
+
'long_description': broken_rest,
|
| 158 |
+
}
|
| 159 |
+
with pytest.raises(DistutilsSetupError):
|
| 160 |
+
self._run(metadata, **{'strict': 1, 'restructuredtext': 1})
|
| 161 |
+
|
| 162 |
+
# and non-broken rest, including a non-ASCII character to test #12114
|
| 163 |
+
metadata['long_description'] = 'title\n=====\n\ntest \u00df'
|
| 164 |
+
cmd = self._run(metadata, strict=True, restructuredtext=True)
|
| 165 |
+
assert cmd._warnings == 0
|
| 166 |
+
|
| 167 |
+
# check that includes work to test #31292
|
| 168 |
+
metadata['long_description'] = 'title\n=====\n\n.. include:: includetest.rst'
|
| 169 |
+
cmd = self._run(metadata, cwd=HERE, strict=True, restructuredtext=True)
|
| 170 |
+
assert cmd._warnings == 0
|
| 171 |
+
|
| 172 |
+
code_examples = [
|
| 173 |
+
textwrap.dedent(
|
| 174 |
+
f"""
|
| 175 |
+
Here's some code:
|
| 176 |
+
|
| 177 |
+
.. {directive}:: python
|
| 178 |
+
|
| 179 |
+
def foo():
|
| 180 |
+
pass
|
| 181 |
+
"""
|
| 182 |
+
).lstrip()
|
| 183 |
+
for directive in ['code', 'code-block']
|
| 184 |
+
]
|
| 185 |
+
|
| 186 |
+
def check_rst_data(self, descr):
|
| 187 |
+
pkg_info, dist = self.create_dist(long_description=descr)
|
| 188 |
+
cmd = _check.check(dist)
|
| 189 |
+
cmd.check_restructuredtext()
|
| 190 |
+
return cmd._check_rst_data(descr)
|
| 191 |
+
|
| 192 |
+
@pytest.mark.parametrize('descr', code_examples)
|
| 193 |
+
def test_check_rst_with_syntax_highlight_pygments(self, descr):
|
| 194 |
+
assert self.check_rst_data(descr) == []
|
| 195 |
+
|
| 196 |
+
@pytest.mark.parametrize('descr', code_examples)
|
| 197 |
+
def test_check_rst_with_syntax_highlight_no_pygments(self, descr, hide_pygments):
|
| 198 |
+
(msg,) = self.check_rst_data(descr)
|
| 199 |
+
_, exc, _, _ = msg
|
| 200 |
+
assert str(exc) == 'Cannot analyze code. Pygments package not found.'
|
| 201 |
+
|
| 202 |
+
def test_check_all(self):
|
| 203 |
+
with pytest.raises(DistutilsSetupError):
|
| 204 |
+
self._run({}, **{'strict': 1, 'restructuredtext': 1})
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_clean.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.clean."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from distutils.command.clean import clean
|
| 5 |
+
from distutils.tests import support
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestClean(support.TempdirManager):
|
| 9 |
+
def test_simple_run(self):
|
| 10 |
+
pkg_dir, dist = self.create_dist()
|
| 11 |
+
cmd = clean(dist)
|
| 12 |
+
|
| 13 |
+
# let's add some elements clean should remove
|
| 14 |
+
dirs = [
|
| 15 |
+
(d, os.path.join(pkg_dir, d))
|
| 16 |
+
for d in (
|
| 17 |
+
'build_temp',
|
| 18 |
+
'build_lib',
|
| 19 |
+
'bdist_base',
|
| 20 |
+
'build_scripts',
|
| 21 |
+
'build_base',
|
| 22 |
+
)
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
for name, path in dirs:
|
| 26 |
+
os.mkdir(path)
|
| 27 |
+
setattr(cmd, name, path)
|
| 28 |
+
if name == 'build_base':
|
| 29 |
+
continue
|
| 30 |
+
for f in ('one', 'two', 'three'):
|
| 31 |
+
self.write_file(os.path.join(path, f))
|
| 32 |
+
|
| 33 |
+
# let's run the command
|
| 34 |
+
cmd.all = 1
|
| 35 |
+
cmd.ensure_finalized()
|
| 36 |
+
cmd.run()
|
| 37 |
+
|
| 38 |
+
# make sure the files where removed
|
| 39 |
+
for _name, path in dirs:
|
| 40 |
+
assert not os.path.exists(path), f'{path} was not removed'
|
| 41 |
+
|
| 42 |
+
# let's run the command again (should spit warnings but succeed)
|
| 43 |
+
cmd.all = 1
|
| 44 |
+
cmd.ensure_finalized()
|
| 45 |
+
cmd.run()
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_cmd.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.cmd."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from distutils import debug
|
| 5 |
+
from distutils.cmd import Command
|
| 6 |
+
from distutils.dist import Distribution
|
| 7 |
+
from distutils.errors import DistutilsOptionError
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class MyCmd(Command):
|
| 13 |
+
def initialize_options(self):
|
| 14 |
+
pass
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@pytest.fixture
|
| 18 |
+
def cmd(request):
|
| 19 |
+
return MyCmd(Distribution())
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class TestCommand:
|
| 23 |
+
def test_ensure_string_list(self, cmd):
|
| 24 |
+
cmd.not_string_list = ['one', 2, 'three']
|
| 25 |
+
cmd.yes_string_list = ['one', 'two', 'three']
|
| 26 |
+
cmd.not_string_list2 = object()
|
| 27 |
+
cmd.yes_string_list2 = 'ok'
|
| 28 |
+
cmd.ensure_string_list('yes_string_list')
|
| 29 |
+
cmd.ensure_string_list('yes_string_list2')
|
| 30 |
+
|
| 31 |
+
with pytest.raises(DistutilsOptionError):
|
| 32 |
+
cmd.ensure_string_list('not_string_list')
|
| 33 |
+
|
| 34 |
+
with pytest.raises(DistutilsOptionError):
|
| 35 |
+
cmd.ensure_string_list('not_string_list2')
|
| 36 |
+
|
| 37 |
+
cmd.option1 = 'ok,dok'
|
| 38 |
+
cmd.ensure_string_list('option1')
|
| 39 |
+
assert cmd.option1 == ['ok', 'dok']
|
| 40 |
+
|
| 41 |
+
cmd.option2 = ['xxx', 'www']
|
| 42 |
+
cmd.ensure_string_list('option2')
|
| 43 |
+
|
| 44 |
+
cmd.option3 = ['ok', 2]
|
| 45 |
+
with pytest.raises(DistutilsOptionError):
|
| 46 |
+
cmd.ensure_string_list('option3')
|
| 47 |
+
|
| 48 |
+
def test_make_file(self, cmd):
|
| 49 |
+
# making sure it raises when infiles is not a string or a list/tuple
|
| 50 |
+
with pytest.raises(TypeError):
|
| 51 |
+
cmd.make_file(infiles=True, outfile='', func='func', args=())
|
| 52 |
+
|
| 53 |
+
# making sure execute gets called properly
|
| 54 |
+
def _execute(func, args, exec_msg, level):
|
| 55 |
+
assert exec_msg == 'generating out from in'
|
| 56 |
+
|
| 57 |
+
cmd.force = True
|
| 58 |
+
cmd.execute = _execute
|
| 59 |
+
cmd.make_file(infiles='in', outfile='out', func='func', args=())
|
| 60 |
+
|
| 61 |
+
def test_dump_options(self, cmd):
|
| 62 |
+
msgs = []
|
| 63 |
+
|
| 64 |
+
def _announce(msg, level):
|
| 65 |
+
msgs.append(msg)
|
| 66 |
+
|
| 67 |
+
cmd.announce = _announce
|
| 68 |
+
cmd.option1 = 1
|
| 69 |
+
cmd.option2 = 1
|
| 70 |
+
cmd.user_options = [('option1', '', ''), ('option2', '', '')]
|
| 71 |
+
cmd.dump_options()
|
| 72 |
+
|
| 73 |
+
wanted = ["command options for 'MyCmd':", ' option1 = 1', ' option2 = 1']
|
| 74 |
+
assert msgs == wanted
|
| 75 |
+
|
| 76 |
+
def test_ensure_string(self, cmd):
|
| 77 |
+
cmd.option1 = 'ok'
|
| 78 |
+
cmd.ensure_string('option1')
|
| 79 |
+
|
| 80 |
+
cmd.option2 = None
|
| 81 |
+
cmd.ensure_string('option2', 'xxx')
|
| 82 |
+
assert hasattr(cmd, 'option2')
|
| 83 |
+
|
| 84 |
+
cmd.option3 = 1
|
| 85 |
+
with pytest.raises(DistutilsOptionError):
|
| 86 |
+
cmd.ensure_string('option3')
|
| 87 |
+
|
| 88 |
+
def test_ensure_filename(self, cmd):
|
| 89 |
+
cmd.option1 = __file__
|
| 90 |
+
cmd.ensure_filename('option1')
|
| 91 |
+
cmd.option2 = 'xxx'
|
| 92 |
+
with pytest.raises(DistutilsOptionError):
|
| 93 |
+
cmd.ensure_filename('option2')
|
| 94 |
+
|
| 95 |
+
def test_ensure_dirname(self, cmd):
|
| 96 |
+
cmd.option1 = os.path.dirname(__file__) or os.curdir
|
| 97 |
+
cmd.ensure_dirname('option1')
|
| 98 |
+
cmd.option2 = 'xxx'
|
| 99 |
+
with pytest.raises(DistutilsOptionError):
|
| 100 |
+
cmd.ensure_dirname('option2')
|
| 101 |
+
|
| 102 |
+
def test_debug_print(self, cmd, capsys, monkeypatch):
|
| 103 |
+
cmd.debug_print('xxx')
|
| 104 |
+
assert capsys.readouterr().out == ''
|
| 105 |
+
monkeypatch.setattr(debug, 'DEBUG', True)
|
| 106 |
+
cmd.debug_print('xxx')
|
| 107 |
+
assert capsys.readouterr().out == 'xxx\n'
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_config_cmd.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.config."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from distutils._log import log
|
| 6 |
+
from distutils.command.config import config, dump_file
|
| 7 |
+
from distutils.tests import missing_compiler_executable, support
|
| 8 |
+
|
| 9 |
+
import more_itertools
|
| 10 |
+
import path
|
| 11 |
+
import pytest
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@pytest.fixture(autouse=True)
|
| 15 |
+
def info_log(request, monkeypatch):
|
| 16 |
+
self = request.instance
|
| 17 |
+
self._logs = []
|
| 18 |
+
monkeypatch.setattr(log, 'info', self._info)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@support.combine_markers
|
| 22 |
+
class TestConfig(support.TempdirManager):
|
| 23 |
+
def _info(self, msg, *args):
|
| 24 |
+
for line in msg.splitlines():
|
| 25 |
+
self._logs.append(line)
|
| 26 |
+
|
| 27 |
+
def test_dump_file(self):
|
| 28 |
+
this_file = path.Path(__file__).with_suffix('.py')
|
| 29 |
+
with this_file.open(encoding='utf-8') as f:
|
| 30 |
+
numlines = more_itertools.ilen(f)
|
| 31 |
+
|
| 32 |
+
dump_file(this_file, 'I am the header')
|
| 33 |
+
assert len(self._logs) == numlines + 1
|
| 34 |
+
|
| 35 |
+
@pytest.mark.skipif('platform.system() == "Windows"')
|
| 36 |
+
def test_search_cpp(self):
|
| 37 |
+
cmd = missing_compiler_executable(['preprocessor'])
|
| 38 |
+
if cmd is not None:
|
| 39 |
+
self.skipTest(f'The {cmd!r} command is not found')
|
| 40 |
+
pkg_dir, dist = self.create_dist()
|
| 41 |
+
cmd = config(dist)
|
| 42 |
+
cmd._check_compiler()
|
| 43 |
+
compiler = cmd.compiler
|
| 44 |
+
if sys.platform[:3] == "aix" and "xlc" in compiler.preprocessor[0].lower():
|
| 45 |
+
self.skipTest(
|
| 46 |
+
'xlc: The -E option overrides the -P, -o, and -qsyntaxonly options'
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# simple pattern searches
|
| 50 |
+
match = cmd.search_cpp(pattern='xxx', body='/* xxx */')
|
| 51 |
+
assert match == 0
|
| 52 |
+
|
| 53 |
+
match = cmd.search_cpp(pattern='_configtest', body='/* xxx */')
|
| 54 |
+
assert match == 1
|
| 55 |
+
|
| 56 |
+
def test_finalize_options(self):
|
| 57 |
+
# finalize_options does a bit of transformation
|
| 58 |
+
# on options
|
| 59 |
+
pkg_dir, dist = self.create_dist()
|
| 60 |
+
cmd = config(dist)
|
| 61 |
+
cmd.include_dirs = f'one{os.pathsep}two'
|
| 62 |
+
cmd.libraries = 'one'
|
| 63 |
+
cmd.library_dirs = f'three{os.pathsep}four'
|
| 64 |
+
cmd.ensure_finalized()
|
| 65 |
+
|
| 66 |
+
assert cmd.include_dirs == ['one', 'two']
|
| 67 |
+
assert cmd.libraries == ['one']
|
| 68 |
+
assert cmd.library_dirs == ['three', 'four']
|
| 69 |
+
|
| 70 |
+
def test_clean(self):
|
| 71 |
+
# _clean removes files
|
| 72 |
+
tmp_dir = self.mkdtemp()
|
| 73 |
+
f1 = os.path.join(tmp_dir, 'one')
|
| 74 |
+
f2 = os.path.join(tmp_dir, 'two')
|
| 75 |
+
|
| 76 |
+
self.write_file(f1, 'xxx')
|
| 77 |
+
self.write_file(f2, 'xxx')
|
| 78 |
+
|
| 79 |
+
for f in (f1, f2):
|
| 80 |
+
assert os.path.exists(f)
|
| 81 |
+
|
| 82 |
+
pkg_dir, dist = self.create_dist()
|
| 83 |
+
cmd = config(dist)
|
| 84 |
+
cmd._clean(f1, f2)
|
| 85 |
+
|
| 86 |
+
for f in (f1, f2):
|
| 87 |
+
assert not os.path.exists(f)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_core.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.core."""
|
| 2 |
+
|
| 3 |
+
import distutils.core
|
| 4 |
+
import io
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
from distutils.dist import Distribution
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
# setup script that uses __file__
|
| 12 |
+
setup_using___file__ = """\
|
| 13 |
+
|
| 14 |
+
__file__
|
| 15 |
+
|
| 16 |
+
from distutils.core import setup
|
| 17 |
+
setup()
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
setup_prints_cwd = """\
|
| 21 |
+
|
| 22 |
+
import os
|
| 23 |
+
print(os.getcwd())
|
| 24 |
+
|
| 25 |
+
from distutils.core import setup
|
| 26 |
+
setup()
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
setup_does_nothing = """\
|
| 30 |
+
from distutils.core import setup
|
| 31 |
+
setup()
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
setup_defines_subclass = """\
|
| 36 |
+
from distutils.core import setup
|
| 37 |
+
from distutils.command.install import install as _install
|
| 38 |
+
|
| 39 |
+
class install(_install):
|
| 40 |
+
sub_commands = _install.sub_commands + ['cmd']
|
| 41 |
+
|
| 42 |
+
setup(cmdclass={'install': install})
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
setup_within_if_main = """\
|
| 46 |
+
from distutils.core import setup
|
| 47 |
+
|
| 48 |
+
def main():
|
| 49 |
+
return setup(name="setup_within_if_main")
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
main()
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
@pytest.fixture(autouse=True)
|
| 57 |
+
def save_stdout(monkeypatch):
|
| 58 |
+
monkeypatch.setattr(sys, 'stdout', sys.stdout)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@pytest.fixture
|
| 62 |
+
def temp_file(tmp_path):
|
| 63 |
+
return tmp_path / 'file'
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@pytest.mark.usefixtures('save_env')
|
| 67 |
+
@pytest.mark.usefixtures('save_argv')
|
| 68 |
+
class TestCore:
|
| 69 |
+
def test_run_setup_provides_file(self, temp_file):
|
| 70 |
+
# Make sure the script can use __file__; if that's missing, the test
|
| 71 |
+
# setup.py script will raise NameError.
|
| 72 |
+
temp_file.write_text(setup_using___file__, encoding='utf-8')
|
| 73 |
+
distutils.core.run_setup(temp_file)
|
| 74 |
+
|
| 75 |
+
def test_run_setup_preserves_sys_argv(self, temp_file):
|
| 76 |
+
# Make sure run_setup does not clobber sys.argv
|
| 77 |
+
argv_copy = sys.argv.copy()
|
| 78 |
+
temp_file.write_text(setup_does_nothing, encoding='utf-8')
|
| 79 |
+
distutils.core.run_setup(temp_file)
|
| 80 |
+
assert sys.argv == argv_copy
|
| 81 |
+
|
| 82 |
+
def test_run_setup_defines_subclass(self, temp_file):
|
| 83 |
+
# Make sure the script can use __file__; if that's missing, the test
|
| 84 |
+
# setup.py script will raise NameError.
|
| 85 |
+
temp_file.write_text(setup_defines_subclass, encoding='utf-8')
|
| 86 |
+
dist = distutils.core.run_setup(temp_file)
|
| 87 |
+
install = dist.get_command_obj('install')
|
| 88 |
+
assert 'cmd' in install.sub_commands
|
| 89 |
+
|
| 90 |
+
def test_run_setup_uses_current_dir(self, tmp_path):
|
| 91 |
+
"""
|
| 92 |
+
Test that the setup script is run with the current directory
|
| 93 |
+
as its own current directory.
|
| 94 |
+
"""
|
| 95 |
+
sys.stdout = io.StringIO()
|
| 96 |
+
cwd = os.getcwd()
|
| 97 |
+
|
| 98 |
+
# Create a directory and write the setup.py file there:
|
| 99 |
+
setup_py = tmp_path / 'setup.py'
|
| 100 |
+
setup_py.write_text(setup_prints_cwd, encoding='utf-8')
|
| 101 |
+
distutils.core.run_setup(setup_py)
|
| 102 |
+
|
| 103 |
+
output = sys.stdout.getvalue()
|
| 104 |
+
if output.endswith("\n"):
|
| 105 |
+
output = output[:-1]
|
| 106 |
+
assert cwd == output
|
| 107 |
+
|
| 108 |
+
def test_run_setup_within_if_main(self, temp_file):
|
| 109 |
+
temp_file.write_text(setup_within_if_main, encoding='utf-8')
|
| 110 |
+
dist = distutils.core.run_setup(temp_file, stop_after="config")
|
| 111 |
+
assert isinstance(dist, Distribution)
|
| 112 |
+
assert dist.get_name() == "setup_within_if_main"
|
| 113 |
+
|
| 114 |
+
def test_run_commands(self, temp_file):
|
| 115 |
+
sys.argv = ['setup.py', 'build']
|
| 116 |
+
temp_file.write_text(setup_within_if_main, encoding='utf-8')
|
| 117 |
+
dist = distutils.core.run_setup(temp_file, stop_after="commandline")
|
| 118 |
+
assert 'build' not in dist.have_run
|
| 119 |
+
distutils.core.run_commands(dist)
|
| 120 |
+
assert 'build' in dist.have_run
|
| 121 |
+
|
| 122 |
+
def test_debug_mode(self, capsys, monkeypatch):
|
| 123 |
+
# this covers the code called when DEBUG is set
|
| 124 |
+
sys.argv = ['setup.py', '--name']
|
| 125 |
+
distutils.core.setup(name='bar')
|
| 126 |
+
assert capsys.readouterr().out == 'bar\n'
|
| 127 |
+
monkeypatch.setattr(distutils.core, 'DEBUG', True)
|
| 128 |
+
distutils.core.setup(name='bar')
|
| 129 |
+
wanted = "options (after parsing config files):\n"
|
| 130 |
+
assert capsys.readouterr().out.startswith(wanted)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_dir_util.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.dir_util."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
import stat
|
| 6 |
+
import sys
|
| 7 |
+
import unittest.mock as mock
|
| 8 |
+
from distutils import dir_util, errors
|
| 9 |
+
from distutils.dir_util import (
|
| 10 |
+
copy_tree,
|
| 11 |
+
create_tree,
|
| 12 |
+
ensure_relative,
|
| 13 |
+
mkpath,
|
| 14 |
+
remove_tree,
|
| 15 |
+
)
|
| 16 |
+
from distutils.tests import support
|
| 17 |
+
|
| 18 |
+
import jaraco.path
|
| 19 |
+
import path
|
| 20 |
+
import pytest
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@pytest.fixture(autouse=True)
|
| 24 |
+
def stuff(request, monkeypatch, distutils_managed_tempdir):
|
| 25 |
+
self = request.instance
|
| 26 |
+
tmp_dir = self.mkdtemp()
|
| 27 |
+
self.root_target = os.path.join(tmp_dir, 'deep')
|
| 28 |
+
self.target = os.path.join(self.root_target, 'here')
|
| 29 |
+
self.target2 = os.path.join(tmp_dir, 'deep2')
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class TestDirUtil(support.TempdirManager):
|
| 33 |
+
def test_mkpath_remove_tree_verbosity(self, caplog):
|
| 34 |
+
mkpath(self.target, verbose=False)
|
| 35 |
+
assert not caplog.records
|
| 36 |
+
remove_tree(self.root_target, verbose=False)
|
| 37 |
+
|
| 38 |
+
mkpath(self.target, verbose=True)
|
| 39 |
+
wanted = [f'creating {self.target}']
|
| 40 |
+
assert caplog.messages == wanted
|
| 41 |
+
caplog.clear()
|
| 42 |
+
|
| 43 |
+
remove_tree(self.root_target, verbose=True)
|
| 44 |
+
wanted = [f"removing '{self.root_target}' (and everything under it)"]
|
| 45 |
+
assert caplog.messages == wanted
|
| 46 |
+
|
| 47 |
+
@pytest.mark.skipif("platform.system() == 'Windows'")
|
| 48 |
+
def test_mkpath_with_custom_mode(self):
|
| 49 |
+
# Get and set the current umask value for testing mode bits.
|
| 50 |
+
umask = os.umask(0o002)
|
| 51 |
+
os.umask(umask)
|
| 52 |
+
mkpath(self.target, 0o700)
|
| 53 |
+
assert stat.S_IMODE(os.stat(self.target).st_mode) == 0o700 & ~umask
|
| 54 |
+
mkpath(self.target2, 0o555)
|
| 55 |
+
assert stat.S_IMODE(os.stat(self.target2).st_mode) == 0o555 & ~umask
|
| 56 |
+
|
| 57 |
+
def test_create_tree_verbosity(self, caplog):
|
| 58 |
+
create_tree(self.root_target, ['one', 'two', 'three'], verbose=False)
|
| 59 |
+
assert caplog.messages == []
|
| 60 |
+
remove_tree(self.root_target, verbose=False)
|
| 61 |
+
|
| 62 |
+
wanted = [f'creating {self.root_target}']
|
| 63 |
+
create_tree(self.root_target, ['one', 'two', 'three'], verbose=True)
|
| 64 |
+
assert caplog.messages == wanted
|
| 65 |
+
|
| 66 |
+
remove_tree(self.root_target, verbose=False)
|
| 67 |
+
|
| 68 |
+
def test_copy_tree_verbosity(self, caplog):
|
| 69 |
+
mkpath(self.target, verbose=False)
|
| 70 |
+
|
| 71 |
+
copy_tree(self.target, self.target2, verbose=False)
|
| 72 |
+
assert caplog.messages == []
|
| 73 |
+
|
| 74 |
+
remove_tree(self.root_target, verbose=False)
|
| 75 |
+
|
| 76 |
+
mkpath(self.target, verbose=False)
|
| 77 |
+
a_file = path.Path(self.target) / 'ok.txt'
|
| 78 |
+
jaraco.path.build({'ok.txt': 'some content'}, self.target)
|
| 79 |
+
|
| 80 |
+
wanted = [f'copying {a_file} -> {self.target2}']
|
| 81 |
+
copy_tree(self.target, self.target2, verbose=True)
|
| 82 |
+
assert caplog.messages == wanted
|
| 83 |
+
|
| 84 |
+
remove_tree(self.root_target, verbose=False)
|
| 85 |
+
remove_tree(self.target2, verbose=False)
|
| 86 |
+
|
| 87 |
+
def test_copy_tree_skips_nfs_temp_files(self):
|
| 88 |
+
mkpath(self.target, verbose=False)
|
| 89 |
+
|
| 90 |
+
jaraco.path.build({'ok.txt': 'some content', '.nfs123abc': ''}, self.target)
|
| 91 |
+
|
| 92 |
+
copy_tree(self.target, self.target2)
|
| 93 |
+
assert os.listdir(self.target2) == ['ok.txt']
|
| 94 |
+
|
| 95 |
+
remove_tree(self.root_target, verbose=False)
|
| 96 |
+
remove_tree(self.target2, verbose=False)
|
| 97 |
+
|
| 98 |
+
def test_ensure_relative(self):
|
| 99 |
+
if os.sep == '/':
|
| 100 |
+
assert ensure_relative('/home/foo') == 'home/foo'
|
| 101 |
+
assert ensure_relative('some/path') == 'some/path'
|
| 102 |
+
else: # \\
|
| 103 |
+
assert ensure_relative('c:\\home\\foo') == 'c:home\\foo'
|
| 104 |
+
assert ensure_relative('home\\foo') == 'home\\foo'
|
| 105 |
+
|
| 106 |
+
def test_copy_tree_exception_in_listdir(self):
|
| 107 |
+
"""
|
| 108 |
+
An exception in listdir should raise a DistutilsFileError
|
| 109 |
+
"""
|
| 110 |
+
with (
|
| 111 |
+
mock.patch("os.listdir", side_effect=OSError()),
|
| 112 |
+
pytest.raises(errors.DistutilsFileError),
|
| 113 |
+
):
|
| 114 |
+
src = self.tempdirs[-1]
|
| 115 |
+
dir_util.copy_tree(src, None)
|
| 116 |
+
|
| 117 |
+
def test_mkpath_exception_uncached(self, monkeypatch, tmp_path):
|
| 118 |
+
"""
|
| 119 |
+
Caching should not remember failed attempts.
|
| 120 |
+
|
| 121 |
+
pypa/distutils#304
|
| 122 |
+
"""
|
| 123 |
+
|
| 124 |
+
class FailPath(pathlib.Path):
|
| 125 |
+
def mkdir(self, *args, **kwargs):
|
| 126 |
+
raise OSError("Failed to create directory")
|
| 127 |
+
|
| 128 |
+
if sys.version_info < (3, 12):
|
| 129 |
+
_flavour = pathlib.Path()._flavour
|
| 130 |
+
|
| 131 |
+
target = tmp_path / 'foodir'
|
| 132 |
+
|
| 133 |
+
with pytest.raises(errors.DistutilsFileError):
|
| 134 |
+
mkpath(FailPath(target))
|
| 135 |
+
|
| 136 |
+
assert not target.exists()
|
| 137 |
+
|
| 138 |
+
mkpath(target)
|
| 139 |
+
assert target.exists()
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_dist.py
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.dist."""
|
| 2 |
+
|
| 3 |
+
import email
|
| 4 |
+
import email.generator
|
| 5 |
+
import email.policy
|
| 6 |
+
import functools
|
| 7 |
+
import io
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
import textwrap
|
| 11 |
+
import unittest.mock as mock
|
| 12 |
+
import warnings
|
| 13 |
+
from distutils.cmd import Command
|
| 14 |
+
from distutils.dist import Distribution, fix_help_options
|
| 15 |
+
from distutils.tests import support
|
| 16 |
+
from typing import ClassVar
|
| 17 |
+
|
| 18 |
+
import jaraco.path
|
| 19 |
+
import pytest
|
| 20 |
+
|
| 21 |
+
pydistutils_cfg = '.' * (os.name == 'posix') + 'pydistutils.cfg'
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class test_dist(Command):
|
| 25 |
+
"""Sample distutils extension command."""
|
| 26 |
+
|
| 27 |
+
user_options: ClassVar[list[tuple[str, str, str]]] = [
|
| 28 |
+
("sample-option=", "S", "help text"),
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
def initialize_options(self):
|
| 32 |
+
self.sample_option = None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class TestDistribution(Distribution):
|
| 36 |
+
"""Distribution subclasses that avoids the default search for
|
| 37 |
+
configuration files.
|
| 38 |
+
|
| 39 |
+
The ._config_files attribute must be set before
|
| 40 |
+
.parse_config_files() is called.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
def find_config_files(self):
|
| 44 |
+
return self._config_files
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
@pytest.fixture
|
| 48 |
+
def clear_argv():
|
| 49 |
+
del sys.argv[1:]
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@support.combine_markers
|
| 53 |
+
@pytest.mark.usefixtures('save_env')
|
| 54 |
+
@pytest.mark.usefixtures('save_argv')
|
| 55 |
+
class TestDistributionBehavior(support.TempdirManager):
|
| 56 |
+
def create_distribution(self, configfiles=()):
|
| 57 |
+
d = TestDistribution()
|
| 58 |
+
d._config_files = configfiles
|
| 59 |
+
d.parse_config_files()
|
| 60 |
+
d.parse_command_line()
|
| 61 |
+
return d
|
| 62 |
+
|
| 63 |
+
def test_command_packages_unspecified(self, clear_argv):
|
| 64 |
+
sys.argv.append("build")
|
| 65 |
+
d = self.create_distribution()
|
| 66 |
+
assert d.get_command_packages() == ["distutils.command"]
|
| 67 |
+
|
| 68 |
+
def test_command_packages_cmdline(self, clear_argv):
|
| 69 |
+
from distutils.tests.test_dist import test_dist
|
| 70 |
+
|
| 71 |
+
sys.argv.extend([
|
| 72 |
+
"--command-packages",
|
| 73 |
+
"foo.bar,distutils.tests",
|
| 74 |
+
"test_dist",
|
| 75 |
+
"-Ssometext",
|
| 76 |
+
])
|
| 77 |
+
d = self.create_distribution()
|
| 78 |
+
# let's actually try to load our test command:
|
| 79 |
+
assert d.get_command_packages() == [
|
| 80 |
+
"distutils.command",
|
| 81 |
+
"foo.bar",
|
| 82 |
+
"distutils.tests",
|
| 83 |
+
]
|
| 84 |
+
cmd = d.get_command_obj("test_dist")
|
| 85 |
+
assert isinstance(cmd, test_dist)
|
| 86 |
+
assert cmd.sample_option == "sometext"
|
| 87 |
+
|
| 88 |
+
@pytest.mark.skipif(
|
| 89 |
+
'distutils' not in Distribution.parse_config_files.__module__,
|
| 90 |
+
reason='Cannot test when virtualenv has monkey-patched Distribution',
|
| 91 |
+
)
|
| 92 |
+
def test_venv_install_options(self, tmp_path, clear_argv):
|
| 93 |
+
sys.argv.append("install")
|
| 94 |
+
file = str(tmp_path / 'file')
|
| 95 |
+
|
| 96 |
+
fakepath = '/somedir'
|
| 97 |
+
|
| 98 |
+
jaraco.path.build({
|
| 99 |
+
file: f"""
|
| 100 |
+
[install]
|
| 101 |
+
install-base = {fakepath}
|
| 102 |
+
install-platbase = {fakepath}
|
| 103 |
+
install-lib = {fakepath}
|
| 104 |
+
install-platlib = {fakepath}
|
| 105 |
+
install-purelib = {fakepath}
|
| 106 |
+
install-headers = {fakepath}
|
| 107 |
+
install-scripts = {fakepath}
|
| 108 |
+
install-data = {fakepath}
|
| 109 |
+
prefix = {fakepath}
|
| 110 |
+
exec-prefix = {fakepath}
|
| 111 |
+
home = {fakepath}
|
| 112 |
+
user = {fakepath}
|
| 113 |
+
root = {fakepath}
|
| 114 |
+
""",
|
| 115 |
+
})
|
| 116 |
+
|
| 117 |
+
# Base case: Not in a Virtual Environment
|
| 118 |
+
with mock.patch.multiple(sys, prefix='/a', base_prefix='/a'):
|
| 119 |
+
d = self.create_distribution([file])
|
| 120 |
+
|
| 121 |
+
option_tuple = (file, fakepath)
|
| 122 |
+
|
| 123 |
+
result_dict = {
|
| 124 |
+
'install_base': option_tuple,
|
| 125 |
+
'install_platbase': option_tuple,
|
| 126 |
+
'install_lib': option_tuple,
|
| 127 |
+
'install_platlib': option_tuple,
|
| 128 |
+
'install_purelib': option_tuple,
|
| 129 |
+
'install_headers': option_tuple,
|
| 130 |
+
'install_scripts': option_tuple,
|
| 131 |
+
'install_data': option_tuple,
|
| 132 |
+
'prefix': option_tuple,
|
| 133 |
+
'exec_prefix': option_tuple,
|
| 134 |
+
'home': option_tuple,
|
| 135 |
+
'user': option_tuple,
|
| 136 |
+
'root': option_tuple,
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
assert sorted(d.command_options.get('install').keys()) == sorted(
|
| 140 |
+
result_dict.keys()
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
for key, value in d.command_options.get('install').items():
|
| 144 |
+
assert value == result_dict[key]
|
| 145 |
+
|
| 146 |
+
# Test case: In a Virtual Environment
|
| 147 |
+
with mock.patch.multiple(sys, prefix='/a', base_prefix='/b'):
|
| 148 |
+
d = self.create_distribution([file])
|
| 149 |
+
|
| 150 |
+
for key in result_dict.keys():
|
| 151 |
+
assert key not in d.command_options.get('install', {})
|
| 152 |
+
|
| 153 |
+
def test_command_packages_configfile(self, tmp_path, clear_argv):
|
| 154 |
+
sys.argv.append("build")
|
| 155 |
+
file = str(tmp_path / "file")
|
| 156 |
+
jaraco.path.build({
|
| 157 |
+
file: """
|
| 158 |
+
[global]
|
| 159 |
+
command_packages = foo.bar, splat
|
| 160 |
+
""",
|
| 161 |
+
})
|
| 162 |
+
|
| 163 |
+
d = self.create_distribution([file])
|
| 164 |
+
assert d.get_command_packages() == ["distutils.command", "foo.bar", "splat"]
|
| 165 |
+
|
| 166 |
+
# ensure command line overrides config:
|
| 167 |
+
sys.argv[1:] = ["--command-packages", "spork", "build"]
|
| 168 |
+
d = self.create_distribution([file])
|
| 169 |
+
assert d.get_command_packages() == ["distutils.command", "spork"]
|
| 170 |
+
|
| 171 |
+
# Setting --command-packages to '' should cause the default to
|
| 172 |
+
# be used even if a config file specified something else:
|
| 173 |
+
sys.argv[1:] = ["--command-packages", "", "build"]
|
| 174 |
+
d = self.create_distribution([file])
|
| 175 |
+
assert d.get_command_packages() == ["distutils.command"]
|
| 176 |
+
|
| 177 |
+
def test_empty_options(self, request):
|
| 178 |
+
# an empty options dictionary should not stay in the
|
| 179 |
+
# list of attributes
|
| 180 |
+
|
| 181 |
+
# catching warnings
|
| 182 |
+
warns = []
|
| 183 |
+
|
| 184 |
+
def _warn(msg):
|
| 185 |
+
warns.append(msg)
|
| 186 |
+
|
| 187 |
+
request.addfinalizer(
|
| 188 |
+
functools.partial(setattr, warnings, 'warn', warnings.warn)
|
| 189 |
+
)
|
| 190 |
+
warnings.warn = _warn
|
| 191 |
+
dist = Distribution(
|
| 192 |
+
attrs={
|
| 193 |
+
'author': 'xxx',
|
| 194 |
+
'name': 'xxx',
|
| 195 |
+
'version': 'xxx',
|
| 196 |
+
'url': 'xxxx',
|
| 197 |
+
'options': {},
|
| 198 |
+
}
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
assert len(warns) == 0
|
| 202 |
+
assert 'options' not in dir(dist)
|
| 203 |
+
|
| 204 |
+
def test_finalize_options(self):
|
| 205 |
+
attrs = {'keywords': 'one,two', 'platforms': 'one,two'}
|
| 206 |
+
|
| 207 |
+
dist = Distribution(attrs=attrs)
|
| 208 |
+
dist.finalize_options()
|
| 209 |
+
|
| 210 |
+
# finalize_option splits platforms and keywords
|
| 211 |
+
assert dist.metadata.platforms == ['one', 'two']
|
| 212 |
+
assert dist.metadata.keywords == ['one', 'two']
|
| 213 |
+
|
| 214 |
+
attrs = {'keywords': 'foo bar', 'platforms': 'foo bar'}
|
| 215 |
+
dist = Distribution(attrs=attrs)
|
| 216 |
+
dist.finalize_options()
|
| 217 |
+
assert dist.metadata.platforms == ['foo bar']
|
| 218 |
+
assert dist.metadata.keywords == ['foo bar']
|
| 219 |
+
|
| 220 |
+
def test_get_command_packages(self):
|
| 221 |
+
dist = Distribution()
|
| 222 |
+
assert dist.command_packages is None
|
| 223 |
+
cmds = dist.get_command_packages()
|
| 224 |
+
assert cmds == ['distutils.command']
|
| 225 |
+
assert dist.command_packages == ['distutils.command']
|
| 226 |
+
|
| 227 |
+
dist.command_packages = 'one,two'
|
| 228 |
+
cmds = dist.get_command_packages()
|
| 229 |
+
assert cmds == ['distutils.command', 'one', 'two']
|
| 230 |
+
|
| 231 |
+
def test_announce(self):
|
| 232 |
+
# make sure the level is known
|
| 233 |
+
dist = Distribution()
|
| 234 |
+
with pytest.raises(TypeError):
|
| 235 |
+
dist.announce('ok', level='ok2')
|
| 236 |
+
|
| 237 |
+
def test_find_config_files_disable(self, temp_home):
|
| 238 |
+
# Ticket #1180: Allow user to disable their home config file.
|
| 239 |
+
jaraco.path.build({pydistutils_cfg: '[distutils]\n'}, temp_home)
|
| 240 |
+
|
| 241 |
+
d = Distribution()
|
| 242 |
+
all_files = d.find_config_files()
|
| 243 |
+
|
| 244 |
+
d = Distribution(attrs={'script_args': ['--no-user-cfg']})
|
| 245 |
+
files = d.find_config_files()
|
| 246 |
+
|
| 247 |
+
# make sure --no-user-cfg disables the user cfg file
|
| 248 |
+
assert len(all_files) - 1 == len(files)
|
| 249 |
+
|
| 250 |
+
def test_script_args_list_coercion(self):
|
| 251 |
+
d = Distribution(attrs={'script_args': ('build', '--no-user-cfg')})
|
| 252 |
+
|
| 253 |
+
# make sure script_args is a list even if it started as a different iterable
|
| 254 |
+
assert d.script_args == ['build', '--no-user-cfg']
|
| 255 |
+
|
| 256 |
+
@pytest.mark.skipif(
|
| 257 |
+
'platform.system() == "Windows"',
|
| 258 |
+
reason='Windows does not honor chmod 000',
|
| 259 |
+
)
|
| 260 |
+
def test_find_config_files_permission_error(self, fake_home):
|
| 261 |
+
"""
|
| 262 |
+
Finding config files should not fail when directory is inaccessible.
|
| 263 |
+
"""
|
| 264 |
+
fake_home.joinpath(pydistutils_cfg).write_text('', encoding='utf-8')
|
| 265 |
+
fake_home.chmod(0o000)
|
| 266 |
+
Distribution().find_config_files()
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
@pytest.mark.usefixtures('save_env')
|
| 270 |
+
@pytest.mark.usefixtures('save_argv')
|
| 271 |
+
class TestMetadata(support.TempdirManager):
|
| 272 |
+
def format_metadata(self, dist):
|
| 273 |
+
sio = io.StringIO()
|
| 274 |
+
dist.metadata.write_pkg_file(sio)
|
| 275 |
+
return sio.getvalue()
|
| 276 |
+
|
| 277 |
+
def test_simple_metadata(self):
|
| 278 |
+
attrs = {"name": "package", "version": "1.0"}
|
| 279 |
+
dist = Distribution(attrs)
|
| 280 |
+
meta = self.format_metadata(dist)
|
| 281 |
+
assert "Metadata-Version: 1.0" in meta
|
| 282 |
+
assert "provides:" not in meta.lower()
|
| 283 |
+
assert "requires:" not in meta.lower()
|
| 284 |
+
assert "obsoletes:" not in meta.lower()
|
| 285 |
+
|
| 286 |
+
def test_provides(self):
|
| 287 |
+
attrs = {
|
| 288 |
+
"name": "package",
|
| 289 |
+
"version": "1.0",
|
| 290 |
+
"provides": ["package", "package.sub"],
|
| 291 |
+
}
|
| 292 |
+
dist = Distribution(attrs)
|
| 293 |
+
assert dist.metadata.get_provides() == ["package", "package.sub"]
|
| 294 |
+
assert dist.get_provides() == ["package", "package.sub"]
|
| 295 |
+
meta = self.format_metadata(dist)
|
| 296 |
+
assert "Metadata-Version: 1.1" in meta
|
| 297 |
+
assert "requires:" not in meta.lower()
|
| 298 |
+
assert "obsoletes:" not in meta.lower()
|
| 299 |
+
|
| 300 |
+
def test_provides_illegal(self):
|
| 301 |
+
with pytest.raises(ValueError):
|
| 302 |
+
Distribution(
|
| 303 |
+
{"name": "package", "version": "1.0", "provides": ["my.pkg (splat)"]},
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
def test_requires(self):
|
| 307 |
+
attrs = {
|
| 308 |
+
"name": "package",
|
| 309 |
+
"version": "1.0",
|
| 310 |
+
"requires": ["other", "another (==1.0)"],
|
| 311 |
+
}
|
| 312 |
+
dist = Distribution(attrs)
|
| 313 |
+
assert dist.metadata.get_requires() == ["other", "another (==1.0)"]
|
| 314 |
+
assert dist.get_requires() == ["other", "another (==1.0)"]
|
| 315 |
+
meta = self.format_metadata(dist)
|
| 316 |
+
assert "Metadata-Version: 1.1" in meta
|
| 317 |
+
assert "provides:" not in meta.lower()
|
| 318 |
+
assert "Requires: other" in meta
|
| 319 |
+
assert "Requires: another (==1.0)" in meta
|
| 320 |
+
assert "obsoletes:" not in meta.lower()
|
| 321 |
+
|
| 322 |
+
def test_requires_illegal(self):
|
| 323 |
+
with pytest.raises(ValueError):
|
| 324 |
+
Distribution(
|
| 325 |
+
{"name": "package", "version": "1.0", "requires": ["my.pkg (splat)"]},
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
def test_requires_to_list(self):
|
| 329 |
+
attrs = {"name": "package", "requires": iter(["other"])}
|
| 330 |
+
dist = Distribution(attrs)
|
| 331 |
+
assert isinstance(dist.metadata.requires, list)
|
| 332 |
+
|
| 333 |
+
def test_obsoletes(self):
|
| 334 |
+
attrs = {
|
| 335 |
+
"name": "package",
|
| 336 |
+
"version": "1.0",
|
| 337 |
+
"obsoletes": ["other", "another (<1.0)"],
|
| 338 |
+
}
|
| 339 |
+
dist = Distribution(attrs)
|
| 340 |
+
assert dist.metadata.get_obsoletes() == ["other", "another (<1.0)"]
|
| 341 |
+
assert dist.get_obsoletes() == ["other", "another (<1.0)"]
|
| 342 |
+
meta = self.format_metadata(dist)
|
| 343 |
+
assert "Metadata-Version: 1.1" in meta
|
| 344 |
+
assert "provides:" not in meta.lower()
|
| 345 |
+
assert "requires:" not in meta.lower()
|
| 346 |
+
assert "Obsoletes: other" in meta
|
| 347 |
+
assert "Obsoletes: another (<1.0)" in meta
|
| 348 |
+
|
| 349 |
+
def test_obsoletes_illegal(self):
|
| 350 |
+
with pytest.raises(ValueError):
|
| 351 |
+
Distribution(
|
| 352 |
+
{"name": "package", "version": "1.0", "obsoletes": ["my.pkg (splat)"]},
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
def test_obsoletes_to_list(self):
|
| 356 |
+
attrs = {"name": "package", "obsoletes": iter(["other"])}
|
| 357 |
+
dist = Distribution(attrs)
|
| 358 |
+
assert isinstance(dist.metadata.obsoletes, list)
|
| 359 |
+
|
| 360 |
+
def test_classifier(self):
|
| 361 |
+
attrs = {
|
| 362 |
+
'name': 'Boa',
|
| 363 |
+
'version': '3.0',
|
| 364 |
+
'classifiers': ['Programming Language :: Python :: 3'],
|
| 365 |
+
}
|
| 366 |
+
dist = Distribution(attrs)
|
| 367 |
+
assert dist.get_classifiers() == ['Programming Language :: Python :: 3']
|
| 368 |
+
meta = self.format_metadata(dist)
|
| 369 |
+
assert 'Metadata-Version: 1.1' in meta
|
| 370 |
+
|
| 371 |
+
def test_classifier_invalid_type(self, caplog):
|
| 372 |
+
attrs = {
|
| 373 |
+
'name': 'Boa',
|
| 374 |
+
'version': '3.0',
|
| 375 |
+
'classifiers': ('Programming Language :: Python :: 3',),
|
| 376 |
+
}
|
| 377 |
+
d = Distribution(attrs)
|
| 378 |
+
# should have warning about passing a non-list
|
| 379 |
+
assert 'should be a list' in caplog.messages[0]
|
| 380 |
+
# should be converted to a list
|
| 381 |
+
assert isinstance(d.metadata.classifiers, list)
|
| 382 |
+
assert d.metadata.classifiers == list(attrs['classifiers'])
|
| 383 |
+
|
| 384 |
+
def test_keywords(self):
|
| 385 |
+
attrs = {
|
| 386 |
+
'name': 'Monty',
|
| 387 |
+
'version': '1.0',
|
| 388 |
+
'keywords': ['spam', 'eggs', 'life of brian'],
|
| 389 |
+
}
|
| 390 |
+
dist = Distribution(attrs)
|
| 391 |
+
assert dist.get_keywords() == ['spam', 'eggs', 'life of brian']
|
| 392 |
+
|
| 393 |
+
def test_keywords_invalid_type(self, caplog):
|
| 394 |
+
attrs = {
|
| 395 |
+
'name': 'Monty',
|
| 396 |
+
'version': '1.0',
|
| 397 |
+
'keywords': ('spam', 'eggs', 'life of brian'),
|
| 398 |
+
}
|
| 399 |
+
d = Distribution(attrs)
|
| 400 |
+
# should have warning about passing a non-list
|
| 401 |
+
assert 'should be a list' in caplog.messages[0]
|
| 402 |
+
# should be converted to a list
|
| 403 |
+
assert isinstance(d.metadata.keywords, list)
|
| 404 |
+
assert d.metadata.keywords == list(attrs['keywords'])
|
| 405 |
+
|
| 406 |
+
def test_platforms(self):
|
| 407 |
+
attrs = {
|
| 408 |
+
'name': 'Monty',
|
| 409 |
+
'version': '1.0',
|
| 410 |
+
'platforms': ['GNU/Linux', 'Some Evil Platform'],
|
| 411 |
+
}
|
| 412 |
+
dist = Distribution(attrs)
|
| 413 |
+
assert dist.get_platforms() == ['GNU/Linux', 'Some Evil Platform']
|
| 414 |
+
|
| 415 |
+
def test_platforms_invalid_types(self, caplog):
|
| 416 |
+
attrs = {
|
| 417 |
+
'name': 'Monty',
|
| 418 |
+
'version': '1.0',
|
| 419 |
+
'platforms': ('GNU/Linux', 'Some Evil Platform'),
|
| 420 |
+
}
|
| 421 |
+
d = Distribution(attrs)
|
| 422 |
+
# should have warning about passing a non-list
|
| 423 |
+
assert 'should be a list' in caplog.messages[0]
|
| 424 |
+
# should be converted to a list
|
| 425 |
+
assert isinstance(d.metadata.platforms, list)
|
| 426 |
+
assert d.metadata.platforms == list(attrs['platforms'])
|
| 427 |
+
|
| 428 |
+
def test_download_url(self):
|
| 429 |
+
attrs = {
|
| 430 |
+
'name': 'Boa',
|
| 431 |
+
'version': '3.0',
|
| 432 |
+
'download_url': 'http://example.org/boa',
|
| 433 |
+
}
|
| 434 |
+
dist = Distribution(attrs)
|
| 435 |
+
meta = self.format_metadata(dist)
|
| 436 |
+
assert 'Metadata-Version: 1.1' in meta
|
| 437 |
+
|
| 438 |
+
def test_long_description(self):
|
| 439 |
+
long_desc = textwrap.dedent(
|
| 440 |
+
"""\
|
| 441 |
+
example::
|
| 442 |
+
We start here
|
| 443 |
+
and continue here
|
| 444 |
+
and end here."""
|
| 445 |
+
)
|
| 446 |
+
attrs = {"name": "package", "version": "1.0", "long_description": long_desc}
|
| 447 |
+
|
| 448 |
+
dist = Distribution(attrs)
|
| 449 |
+
meta = self.format_metadata(dist)
|
| 450 |
+
meta = meta.replace('\n' + 8 * ' ', '\n')
|
| 451 |
+
assert long_desc in meta
|
| 452 |
+
|
| 453 |
+
def test_custom_pydistutils(self, temp_home):
|
| 454 |
+
"""
|
| 455 |
+
pydistutils.cfg is found
|
| 456 |
+
"""
|
| 457 |
+
jaraco.path.build({pydistutils_cfg: ''}, temp_home)
|
| 458 |
+
config_path = temp_home / pydistutils_cfg
|
| 459 |
+
|
| 460 |
+
assert str(config_path) in Distribution().find_config_files()
|
| 461 |
+
|
| 462 |
+
def test_extra_pydistutils(self, monkeypatch, tmp_path):
|
| 463 |
+
jaraco.path.build({'overrides.cfg': ''}, tmp_path)
|
| 464 |
+
filename = tmp_path / 'overrides.cfg'
|
| 465 |
+
monkeypatch.setenv('DIST_EXTRA_CONFIG', str(filename))
|
| 466 |
+
assert str(filename) in Distribution().find_config_files()
|
| 467 |
+
|
| 468 |
+
def test_fix_help_options(self):
|
| 469 |
+
help_tuples = [('a', 'b', 'c', 'd'), (1, 2, 3, 4)]
|
| 470 |
+
fancy_options = fix_help_options(help_tuples)
|
| 471 |
+
assert fancy_options[0] == ('a', 'b', 'c')
|
| 472 |
+
assert fancy_options[1] == (1, 2, 3)
|
| 473 |
+
|
| 474 |
+
def test_show_help(self, request, capsys):
|
| 475 |
+
# smoke test, just makes sure some help is displayed
|
| 476 |
+
dist = Distribution()
|
| 477 |
+
sys.argv = []
|
| 478 |
+
dist.help = True
|
| 479 |
+
dist.script_name = 'setup.py'
|
| 480 |
+
dist.parse_command_line()
|
| 481 |
+
|
| 482 |
+
output = [
|
| 483 |
+
line for line in capsys.readouterr().out.split('\n') if line.strip() != ''
|
| 484 |
+
]
|
| 485 |
+
assert output
|
| 486 |
+
|
| 487 |
+
def test_read_metadata(self):
|
| 488 |
+
attrs = {
|
| 489 |
+
"name": "package",
|
| 490 |
+
"version": "1.0",
|
| 491 |
+
"long_description": "desc",
|
| 492 |
+
"description": "xxx",
|
| 493 |
+
"download_url": "http://example.com",
|
| 494 |
+
"keywords": ['one', 'two'],
|
| 495 |
+
"requires": ['foo'],
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
dist = Distribution(attrs)
|
| 499 |
+
metadata = dist.metadata
|
| 500 |
+
|
| 501 |
+
# write it then reloads it
|
| 502 |
+
PKG_INFO = io.StringIO()
|
| 503 |
+
metadata.write_pkg_file(PKG_INFO)
|
| 504 |
+
PKG_INFO.seek(0)
|
| 505 |
+
metadata.read_pkg_file(PKG_INFO)
|
| 506 |
+
|
| 507 |
+
assert metadata.name == "package"
|
| 508 |
+
assert metadata.version == "1.0"
|
| 509 |
+
assert metadata.description == "xxx"
|
| 510 |
+
assert metadata.download_url == 'http://example.com'
|
| 511 |
+
assert metadata.keywords == ['one', 'two']
|
| 512 |
+
assert metadata.platforms is None
|
| 513 |
+
assert metadata.obsoletes is None
|
| 514 |
+
assert metadata.requires == ['foo']
|
| 515 |
+
|
| 516 |
+
def test_round_trip_through_email_generator(self):
|
| 517 |
+
"""
|
| 518 |
+
In pypa/setuptools#4033, it was shown that once PKG-INFO is
|
| 519 |
+
re-generated using ``email.generator.Generator``, some control
|
| 520 |
+
characters might cause problems.
|
| 521 |
+
"""
|
| 522 |
+
# Given a PKG-INFO file ...
|
| 523 |
+
attrs = {
|
| 524 |
+
"name": "package",
|
| 525 |
+
"version": "1.0",
|
| 526 |
+
"long_description": "hello\x0b\nworld\n",
|
| 527 |
+
}
|
| 528 |
+
dist = Distribution(attrs)
|
| 529 |
+
metadata = dist.metadata
|
| 530 |
+
|
| 531 |
+
with io.StringIO() as buffer:
|
| 532 |
+
metadata.write_pkg_file(buffer)
|
| 533 |
+
msg = buffer.getvalue()
|
| 534 |
+
|
| 535 |
+
# ... when it is read and re-written using stdlib's email library,
|
| 536 |
+
orig = email.message_from_string(msg)
|
| 537 |
+
policy = email.policy.EmailPolicy(
|
| 538 |
+
utf8=True,
|
| 539 |
+
mangle_from_=False,
|
| 540 |
+
max_line_length=0,
|
| 541 |
+
)
|
| 542 |
+
with io.StringIO() as buffer:
|
| 543 |
+
email.generator.Generator(buffer, policy=policy).flatten(orig)
|
| 544 |
+
|
| 545 |
+
buffer.seek(0)
|
| 546 |
+
regen = email.message_from_file(buffer)
|
| 547 |
+
|
| 548 |
+
# ... then it should be the same as the original
|
| 549 |
+
# (except for the specific line break characters)
|
| 550 |
+
orig_desc = set(orig["Description"].splitlines())
|
| 551 |
+
regen_desc = set(regen["Description"].splitlines())
|
| 552 |
+
assert regen_desc == orig_desc
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_extension.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.extension."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
import warnings
|
| 6 |
+
from distutils.extension import Extension, read_setup_file
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
from test.support.warnings_helper import check_warnings
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class TestExtension:
|
| 13 |
+
def test_read_setup_file(self):
|
| 14 |
+
# trying to read a Setup file
|
| 15 |
+
# (sample extracted from the PyGame project)
|
| 16 |
+
setup = os.path.join(os.path.dirname(__file__), 'Setup.sample')
|
| 17 |
+
|
| 18 |
+
exts = read_setup_file(setup)
|
| 19 |
+
names = [ext.name for ext in exts]
|
| 20 |
+
names.sort()
|
| 21 |
+
|
| 22 |
+
# here are the extensions read_setup_file should have created
|
| 23 |
+
# out of the file
|
| 24 |
+
wanted = [
|
| 25 |
+
'_arraysurfarray',
|
| 26 |
+
'_camera',
|
| 27 |
+
'_numericsndarray',
|
| 28 |
+
'_numericsurfarray',
|
| 29 |
+
'base',
|
| 30 |
+
'bufferproxy',
|
| 31 |
+
'cdrom',
|
| 32 |
+
'color',
|
| 33 |
+
'constants',
|
| 34 |
+
'display',
|
| 35 |
+
'draw',
|
| 36 |
+
'event',
|
| 37 |
+
'fastevent',
|
| 38 |
+
'font',
|
| 39 |
+
'gfxdraw',
|
| 40 |
+
'image',
|
| 41 |
+
'imageext',
|
| 42 |
+
'joystick',
|
| 43 |
+
'key',
|
| 44 |
+
'mask',
|
| 45 |
+
'mixer',
|
| 46 |
+
'mixer_music',
|
| 47 |
+
'mouse',
|
| 48 |
+
'movie',
|
| 49 |
+
'overlay',
|
| 50 |
+
'pixelarray',
|
| 51 |
+
'pypm',
|
| 52 |
+
'rect',
|
| 53 |
+
'rwobject',
|
| 54 |
+
'scrap',
|
| 55 |
+
'surface',
|
| 56 |
+
'surflock',
|
| 57 |
+
'time',
|
| 58 |
+
'transform',
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
assert names == wanted
|
| 62 |
+
|
| 63 |
+
def test_extension_init(self):
|
| 64 |
+
# the first argument, which is the name, must be a string
|
| 65 |
+
with pytest.raises(TypeError):
|
| 66 |
+
Extension(1, [])
|
| 67 |
+
ext = Extension('name', [])
|
| 68 |
+
assert ext.name == 'name'
|
| 69 |
+
|
| 70 |
+
# the second argument, which is the list of files, must
|
| 71 |
+
# be an iterable of strings or PathLike objects, and not a string
|
| 72 |
+
with pytest.raises(TypeError):
|
| 73 |
+
Extension('name', 'file')
|
| 74 |
+
with pytest.raises(TypeError):
|
| 75 |
+
Extension('name', ['file', 1])
|
| 76 |
+
ext = Extension('name', ['file1', 'file2'])
|
| 77 |
+
assert ext.sources == ['file1', 'file2']
|
| 78 |
+
ext = Extension('name', [pathlib.Path('file1'), pathlib.Path('file2')])
|
| 79 |
+
assert ext.sources == ['file1', 'file2']
|
| 80 |
+
|
| 81 |
+
# any non-string iterable of strings or PathLike objects should work
|
| 82 |
+
ext = Extension('name', ('file1', 'file2')) # tuple
|
| 83 |
+
assert ext.sources == ['file1', 'file2']
|
| 84 |
+
ext = Extension('name', {'file1', 'file2'}) # set
|
| 85 |
+
assert sorted(ext.sources) == ['file1', 'file2']
|
| 86 |
+
ext = Extension('name', iter(['file1', 'file2'])) # iterator
|
| 87 |
+
assert ext.sources == ['file1', 'file2']
|
| 88 |
+
ext = Extension('name', [pathlib.Path('file1'), 'file2']) # mixed types
|
| 89 |
+
assert ext.sources == ['file1', 'file2']
|
| 90 |
+
|
| 91 |
+
# others arguments have defaults
|
| 92 |
+
for attr in (
|
| 93 |
+
'include_dirs',
|
| 94 |
+
'define_macros',
|
| 95 |
+
'undef_macros',
|
| 96 |
+
'library_dirs',
|
| 97 |
+
'libraries',
|
| 98 |
+
'runtime_library_dirs',
|
| 99 |
+
'extra_objects',
|
| 100 |
+
'extra_compile_args',
|
| 101 |
+
'extra_link_args',
|
| 102 |
+
'export_symbols',
|
| 103 |
+
'swig_opts',
|
| 104 |
+
'depends',
|
| 105 |
+
):
|
| 106 |
+
assert getattr(ext, attr) == []
|
| 107 |
+
|
| 108 |
+
assert ext.language is None
|
| 109 |
+
assert ext.optional is None
|
| 110 |
+
|
| 111 |
+
# if there are unknown keyword options, warn about them
|
| 112 |
+
with check_warnings() as w:
|
| 113 |
+
warnings.simplefilter('always')
|
| 114 |
+
ext = Extension('name', ['file1', 'file2'], chic=True)
|
| 115 |
+
|
| 116 |
+
assert len(w.warnings) == 1
|
| 117 |
+
assert str(w.warnings[0].message) == "Unknown Extension options: 'chic'"
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_file_util.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.file_util."""
|
| 2 |
+
|
| 3 |
+
import errno
|
| 4 |
+
import os
|
| 5 |
+
import unittest.mock as mock
|
| 6 |
+
from distutils.errors import DistutilsFileError
|
| 7 |
+
from distutils.file_util import copy_file, move_file
|
| 8 |
+
|
| 9 |
+
import jaraco.path
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@pytest.fixture(autouse=True)
|
| 14 |
+
def stuff(request, tmp_path):
|
| 15 |
+
self = request.instance
|
| 16 |
+
self.source = tmp_path / 'f1'
|
| 17 |
+
self.target = tmp_path / 'f2'
|
| 18 |
+
self.target_dir = tmp_path / 'd1'
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class TestFileUtil:
|
| 22 |
+
def test_move_file_verbosity(self, caplog):
|
| 23 |
+
jaraco.path.build({self.source: 'some content'})
|
| 24 |
+
|
| 25 |
+
move_file(self.source, self.target, verbose=False)
|
| 26 |
+
assert not caplog.messages
|
| 27 |
+
|
| 28 |
+
# back to original state
|
| 29 |
+
move_file(self.target, self.source, verbose=False)
|
| 30 |
+
|
| 31 |
+
move_file(self.source, self.target, verbose=True)
|
| 32 |
+
wanted = [f'moving {self.source} -> {self.target}']
|
| 33 |
+
assert caplog.messages == wanted
|
| 34 |
+
|
| 35 |
+
# back to original state
|
| 36 |
+
move_file(self.target, self.source, verbose=False)
|
| 37 |
+
|
| 38 |
+
caplog.clear()
|
| 39 |
+
# now the target is a dir
|
| 40 |
+
os.mkdir(self.target_dir)
|
| 41 |
+
move_file(self.source, self.target_dir, verbose=True)
|
| 42 |
+
wanted = [f'moving {self.source} -> {self.target_dir}']
|
| 43 |
+
assert caplog.messages == wanted
|
| 44 |
+
|
| 45 |
+
def test_move_file_exception_unpacking_rename(self):
|
| 46 |
+
# see issue 22182
|
| 47 |
+
with (
|
| 48 |
+
mock.patch("os.rename", side_effect=OSError("wrong", 1)),
|
| 49 |
+
pytest.raises(DistutilsFileError),
|
| 50 |
+
):
|
| 51 |
+
jaraco.path.build({self.source: 'spam eggs'})
|
| 52 |
+
move_file(self.source, self.target, verbose=False)
|
| 53 |
+
|
| 54 |
+
def test_move_file_exception_unpacking_unlink(self):
|
| 55 |
+
# see issue 22182
|
| 56 |
+
with (
|
| 57 |
+
mock.patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")),
|
| 58 |
+
mock.patch("os.unlink", side_effect=OSError("wrong", 1)),
|
| 59 |
+
pytest.raises(DistutilsFileError),
|
| 60 |
+
):
|
| 61 |
+
jaraco.path.build({self.source: 'spam eggs'})
|
| 62 |
+
move_file(self.source, self.target, verbose=False)
|
| 63 |
+
|
| 64 |
+
def test_copy_file_hard_link(self):
|
| 65 |
+
jaraco.path.build({self.source: 'some content'})
|
| 66 |
+
# Check first that copy_file() will not fall back on copying the file
|
| 67 |
+
# instead of creating the hard link.
|
| 68 |
+
try:
|
| 69 |
+
os.link(self.source, self.target)
|
| 70 |
+
except OSError as e:
|
| 71 |
+
self.skipTest(f'os.link: {e}')
|
| 72 |
+
else:
|
| 73 |
+
self.target.unlink()
|
| 74 |
+
st = os.stat(self.source)
|
| 75 |
+
copy_file(self.source, self.target, link='hard')
|
| 76 |
+
st2 = os.stat(self.source)
|
| 77 |
+
st3 = os.stat(self.target)
|
| 78 |
+
assert os.path.samestat(st, st2), (st, st2)
|
| 79 |
+
assert os.path.samestat(st2, st3), (st2, st3)
|
| 80 |
+
assert self.source.read_text(encoding='utf-8') == 'some content'
|
| 81 |
+
|
| 82 |
+
def test_copy_file_hard_link_failure(self):
|
| 83 |
+
# If hard linking fails, copy_file() falls back on copying file
|
| 84 |
+
# (some special filesystems don't support hard linking even under
|
| 85 |
+
# Unix, see issue #8876).
|
| 86 |
+
jaraco.path.build({self.source: 'some content'})
|
| 87 |
+
st = os.stat(self.source)
|
| 88 |
+
with mock.patch("os.link", side_effect=OSError(0, "linking unsupported")):
|
| 89 |
+
copy_file(self.source, self.target, link='hard')
|
| 90 |
+
st2 = os.stat(self.source)
|
| 91 |
+
st3 = os.stat(self.target)
|
| 92 |
+
assert os.path.samestat(st, st2), (st, st2)
|
| 93 |
+
assert not os.path.samestat(st2, st3), (st2, st3)
|
| 94 |
+
for fn in (self.source, self.target):
|
| 95 |
+
assert fn.read_text(encoding='utf-8') == 'some content'
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_filelist.py
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.filelist."""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
from distutils import debug, filelist
|
| 8 |
+
from distutils.errors import DistutilsTemplateError
|
| 9 |
+
from distutils.filelist import FileList, glob_to_re, translate_pattern
|
| 10 |
+
|
| 11 |
+
import jaraco.path
|
| 12 |
+
import pytest
|
| 13 |
+
|
| 14 |
+
from .compat import py39 as os_helper
|
| 15 |
+
|
| 16 |
+
MANIFEST_IN = """\
|
| 17 |
+
include ok
|
| 18 |
+
include xo
|
| 19 |
+
exclude xo
|
| 20 |
+
include foo.tmp
|
| 21 |
+
include buildout.cfg
|
| 22 |
+
global-include *.x
|
| 23 |
+
global-include *.txt
|
| 24 |
+
global-exclude *.tmp
|
| 25 |
+
recursive-include f *.oo
|
| 26 |
+
recursive-exclude global *.x
|
| 27 |
+
graft dir
|
| 28 |
+
prune dir3
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def make_local_path(s):
|
| 33 |
+
"""Converts '/' in a string to os.sep"""
|
| 34 |
+
return s.replace('/', os.sep)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class TestFileList:
|
| 38 |
+
def assertNoWarnings(self, caplog):
|
| 39 |
+
warnings = [rec for rec in caplog.records if rec.levelno == logging.WARNING]
|
| 40 |
+
assert not warnings
|
| 41 |
+
caplog.clear()
|
| 42 |
+
|
| 43 |
+
def assertWarnings(self, caplog):
|
| 44 |
+
warnings = [rec for rec in caplog.records if rec.levelno == logging.WARNING]
|
| 45 |
+
assert warnings
|
| 46 |
+
caplog.clear()
|
| 47 |
+
|
| 48 |
+
def test_glob_to_re(self):
|
| 49 |
+
sep = re.escape(os.sep)
|
| 50 |
+
# https://docs.python.org/3/whatsnew/3.14.html#re
|
| 51 |
+
end_of_str_metachar = r"\z" if sys.version_info >= (3, 14) else r"\Z"
|
| 52 |
+
|
| 53 |
+
for glob, regex in (
|
| 54 |
+
# simple cases
|
| 55 |
+
('foo*', r'(?s:foo[^%(sep)s]*)%(eos)s'),
|
| 56 |
+
('foo?', r'(?s:foo[^%(sep)s])%(eos)s'),
|
| 57 |
+
('foo??', r'(?s:foo[^%(sep)s][^%(sep)s])%(eos)s'),
|
| 58 |
+
# special cases
|
| 59 |
+
(r'foo\\*', r'(?s:foo\\\\[^%(sep)s]*)%(eos)s'),
|
| 60 |
+
(r'foo\\\*', r'(?s:foo\\\\\\[^%(sep)s]*)%(eos)s'),
|
| 61 |
+
('foo????', r'(?s:foo[^%(sep)s][^%(sep)s][^%(sep)s][^%(sep)s])%(eos)s'),
|
| 62 |
+
(r'foo\\??', r'(?s:foo\\\\[^%(sep)s][^%(sep)s])%(eos)s'),
|
| 63 |
+
):
|
| 64 |
+
regex = regex % {'sep': sep, 'eos': end_of_str_metachar}
|
| 65 |
+
assert glob_to_re(glob) == regex
|
| 66 |
+
|
| 67 |
+
def test_process_template_line(self):
|
| 68 |
+
# testing all MANIFEST.in template patterns
|
| 69 |
+
file_list = FileList()
|
| 70 |
+
mlp = make_local_path
|
| 71 |
+
|
| 72 |
+
# simulated file list
|
| 73 |
+
file_list.allfiles = [
|
| 74 |
+
'foo.tmp',
|
| 75 |
+
'ok',
|
| 76 |
+
'xo',
|
| 77 |
+
'four.txt',
|
| 78 |
+
'buildout.cfg',
|
| 79 |
+
# filelist does not filter out VCS directories,
|
| 80 |
+
# it's sdist that does
|
| 81 |
+
mlp('.hg/last-message.txt'),
|
| 82 |
+
mlp('global/one.txt'),
|
| 83 |
+
mlp('global/two.txt'),
|
| 84 |
+
mlp('global/files.x'),
|
| 85 |
+
mlp('global/here.tmp'),
|
| 86 |
+
mlp('f/o/f.oo'),
|
| 87 |
+
mlp('dir/graft-one'),
|
| 88 |
+
mlp('dir/dir2/graft2'),
|
| 89 |
+
mlp('dir3/ok'),
|
| 90 |
+
mlp('dir3/sub/ok.txt'),
|
| 91 |
+
]
|
| 92 |
+
|
| 93 |
+
for line in MANIFEST_IN.split('\n'):
|
| 94 |
+
if line.strip() == '':
|
| 95 |
+
continue
|
| 96 |
+
file_list.process_template_line(line)
|
| 97 |
+
|
| 98 |
+
wanted = [
|
| 99 |
+
'ok',
|
| 100 |
+
'buildout.cfg',
|
| 101 |
+
'four.txt',
|
| 102 |
+
mlp('.hg/last-message.txt'),
|
| 103 |
+
mlp('global/one.txt'),
|
| 104 |
+
mlp('global/two.txt'),
|
| 105 |
+
mlp('f/o/f.oo'),
|
| 106 |
+
mlp('dir/graft-one'),
|
| 107 |
+
mlp('dir/dir2/graft2'),
|
| 108 |
+
]
|
| 109 |
+
|
| 110 |
+
assert file_list.files == wanted
|
| 111 |
+
|
| 112 |
+
def test_debug_print(self, capsys, monkeypatch):
|
| 113 |
+
file_list = FileList()
|
| 114 |
+
file_list.debug_print('xxx')
|
| 115 |
+
assert capsys.readouterr().out == ''
|
| 116 |
+
|
| 117 |
+
monkeypatch.setattr(debug, 'DEBUG', True)
|
| 118 |
+
file_list.debug_print('xxx')
|
| 119 |
+
assert capsys.readouterr().out == 'xxx\n'
|
| 120 |
+
|
| 121 |
+
def test_set_allfiles(self):
|
| 122 |
+
file_list = FileList()
|
| 123 |
+
files = ['a', 'b', 'c']
|
| 124 |
+
file_list.set_allfiles(files)
|
| 125 |
+
assert file_list.allfiles == files
|
| 126 |
+
|
| 127 |
+
def test_remove_duplicates(self):
|
| 128 |
+
file_list = FileList()
|
| 129 |
+
file_list.files = ['a', 'b', 'a', 'g', 'c', 'g']
|
| 130 |
+
# files must be sorted beforehand (sdist does it)
|
| 131 |
+
file_list.sort()
|
| 132 |
+
file_list.remove_duplicates()
|
| 133 |
+
assert file_list.files == ['a', 'b', 'c', 'g']
|
| 134 |
+
|
| 135 |
+
def test_translate_pattern(self):
|
| 136 |
+
# not regex
|
| 137 |
+
assert hasattr(translate_pattern('a', anchor=True, is_regex=False), 'search')
|
| 138 |
+
|
| 139 |
+
# is a regex
|
| 140 |
+
regex = re.compile('a')
|
| 141 |
+
assert translate_pattern(regex, anchor=True, is_regex=True) == regex
|
| 142 |
+
|
| 143 |
+
# plain string flagged as regex
|
| 144 |
+
assert hasattr(translate_pattern('a', anchor=True, is_regex=True), 'search')
|
| 145 |
+
|
| 146 |
+
# glob support
|
| 147 |
+
assert translate_pattern('*.py', anchor=True, is_regex=False).search(
|
| 148 |
+
'filelist.py'
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
def test_exclude_pattern(self):
|
| 152 |
+
# return False if no match
|
| 153 |
+
file_list = FileList()
|
| 154 |
+
assert not file_list.exclude_pattern('*.py')
|
| 155 |
+
|
| 156 |
+
# return True if files match
|
| 157 |
+
file_list = FileList()
|
| 158 |
+
file_list.files = ['a.py', 'b.py']
|
| 159 |
+
assert file_list.exclude_pattern('*.py')
|
| 160 |
+
|
| 161 |
+
# test excludes
|
| 162 |
+
file_list = FileList()
|
| 163 |
+
file_list.files = ['a.py', 'a.txt']
|
| 164 |
+
file_list.exclude_pattern('*.py')
|
| 165 |
+
assert file_list.files == ['a.txt']
|
| 166 |
+
|
| 167 |
+
def test_include_pattern(self):
|
| 168 |
+
# return False if no match
|
| 169 |
+
file_list = FileList()
|
| 170 |
+
file_list.set_allfiles([])
|
| 171 |
+
assert not file_list.include_pattern('*.py')
|
| 172 |
+
|
| 173 |
+
# return True if files match
|
| 174 |
+
file_list = FileList()
|
| 175 |
+
file_list.set_allfiles(['a.py', 'b.txt'])
|
| 176 |
+
assert file_list.include_pattern('*.py')
|
| 177 |
+
|
| 178 |
+
# test * matches all files
|
| 179 |
+
file_list = FileList()
|
| 180 |
+
assert file_list.allfiles is None
|
| 181 |
+
file_list.set_allfiles(['a.py', 'b.txt'])
|
| 182 |
+
file_list.include_pattern('*')
|
| 183 |
+
assert file_list.allfiles == ['a.py', 'b.txt']
|
| 184 |
+
|
| 185 |
+
def test_process_template(self, caplog):
|
| 186 |
+
mlp = make_local_path
|
| 187 |
+
# invalid lines
|
| 188 |
+
file_list = FileList()
|
| 189 |
+
for action in (
|
| 190 |
+
'include',
|
| 191 |
+
'exclude',
|
| 192 |
+
'global-include',
|
| 193 |
+
'global-exclude',
|
| 194 |
+
'recursive-include',
|
| 195 |
+
'recursive-exclude',
|
| 196 |
+
'graft',
|
| 197 |
+
'prune',
|
| 198 |
+
'blarg',
|
| 199 |
+
):
|
| 200 |
+
with pytest.raises(DistutilsTemplateError):
|
| 201 |
+
file_list.process_template_line(action)
|
| 202 |
+
|
| 203 |
+
# include
|
| 204 |
+
file_list = FileList()
|
| 205 |
+
file_list.set_allfiles(['a.py', 'b.txt', mlp('d/c.py')])
|
| 206 |
+
|
| 207 |
+
file_list.process_template_line('include *.py')
|
| 208 |
+
assert file_list.files == ['a.py']
|
| 209 |
+
self.assertNoWarnings(caplog)
|
| 210 |
+
|
| 211 |
+
file_list.process_template_line('include *.rb')
|
| 212 |
+
assert file_list.files == ['a.py']
|
| 213 |
+
self.assertWarnings(caplog)
|
| 214 |
+
|
| 215 |
+
# exclude
|
| 216 |
+
file_list = FileList()
|
| 217 |
+
file_list.files = ['a.py', 'b.txt', mlp('d/c.py')]
|
| 218 |
+
|
| 219 |
+
file_list.process_template_line('exclude *.py')
|
| 220 |
+
assert file_list.files == ['b.txt', mlp('d/c.py')]
|
| 221 |
+
self.assertNoWarnings(caplog)
|
| 222 |
+
|
| 223 |
+
file_list.process_template_line('exclude *.rb')
|
| 224 |
+
assert file_list.files == ['b.txt', mlp('d/c.py')]
|
| 225 |
+
self.assertWarnings(caplog)
|
| 226 |
+
|
| 227 |
+
# global-include
|
| 228 |
+
file_list = FileList()
|
| 229 |
+
file_list.set_allfiles(['a.py', 'b.txt', mlp('d/c.py')])
|
| 230 |
+
|
| 231 |
+
file_list.process_template_line('global-include *.py')
|
| 232 |
+
assert file_list.files == ['a.py', mlp('d/c.py')]
|
| 233 |
+
self.assertNoWarnings(caplog)
|
| 234 |
+
|
| 235 |
+
file_list.process_template_line('global-include *.rb')
|
| 236 |
+
assert file_list.files == ['a.py', mlp('d/c.py')]
|
| 237 |
+
self.assertWarnings(caplog)
|
| 238 |
+
|
| 239 |
+
# global-exclude
|
| 240 |
+
file_list = FileList()
|
| 241 |
+
file_list.files = ['a.py', 'b.txt', mlp('d/c.py')]
|
| 242 |
+
|
| 243 |
+
file_list.process_template_line('global-exclude *.py')
|
| 244 |
+
assert file_list.files == ['b.txt']
|
| 245 |
+
self.assertNoWarnings(caplog)
|
| 246 |
+
|
| 247 |
+
file_list.process_template_line('global-exclude *.rb')
|
| 248 |
+
assert file_list.files == ['b.txt']
|
| 249 |
+
self.assertWarnings(caplog)
|
| 250 |
+
|
| 251 |
+
# recursive-include
|
| 252 |
+
file_list = FileList()
|
| 253 |
+
file_list.set_allfiles(['a.py', mlp('d/b.py'), mlp('d/c.txt'), mlp('d/d/e.py')])
|
| 254 |
+
|
| 255 |
+
file_list.process_template_line('recursive-include d *.py')
|
| 256 |
+
assert file_list.files == [mlp('d/b.py'), mlp('d/d/e.py')]
|
| 257 |
+
self.assertNoWarnings(caplog)
|
| 258 |
+
|
| 259 |
+
file_list.process_template_line('recursive-include e *.py')
|
| 260 |
+
assert file_list.files == [mlp('d/b.py'), mlp('d/d/e.py')]
|
| 261 |
+
self.assertWarnings(caplog)
|
| 262 |
+
|
| 263 |
+
# recursive-exclude
|
| 264 |
+
file_list = FileList()
|
| 265 |
+
file_list.files = ['a.py', mlp('d/b.py'), mlp('d/c.txt'), mlp('d/d/e.py')]
|
| 266 |
+
|
| 267 |
+
file_list.process_template_line('recursive-exclude d *.py')
|
| 268 |
+
assert file_list.files == ['a.py', mlp('d/c.txt')]
|
| 269 |
+
self.assertNoWarnings(caplog)
|
| 270 |
+
|
| 271 |
+
file_list.process_template_line('recursive-exclude e *.py')
|
| 272 |
+
assert file_list.files == ['a.py', mlp('d/c.txt')]
|
| 273 |
+
self.assertWarnings(caplog)
|
| 274 |
+
|
| 275 |
+
# graft
|
| 276 |
+
file_list = FileList()
|
| 277 |
+
file_list.set_allfiles(['a.py', mlp('d/b.py'), mlp('d/d/e.py'), mlp('f/f.py')])
|
| 278 |
+
|
| 279 |
+
file_list.process_template_line('graft d')
|
| 280 |
+
assert file_list.files == [mlp('d/b.py'), mlp('d/d/e.py')]
|
| 281 |
+
self.assertNoWarnings(caplog)
|
| 282 |
+
|
| 283 |
+
file_list.process_template_line('graft e')
|
| 284 |
+
assert file_list.files == [mlp('d/b.py'), mlp('d/d/e.py')]
|
| 285 |
+
self.assertWarnings(caplog)
|
| 286 |
+
|
| 287 |
+
# prune
|
| 288 |
+
file_list = FileList()
|
| 289 |
+
file_list.files = ['a.py', mlp('d/b.py'), mlp('d/d/e.py'), mlp('f/f.py')]
|
| 290 |
+
|
| 291 |
+
file_list.process_template_line('prune d')
|
| 292 |
+
assert file_list.files == ['a.py', mlp('f/f.py')]
|
| 293 |
+
self.assertNoWarnings(caplog)
|
| 294 |
+
|
| 295 |
+
file_list.process_template_line('prune e')
|
| 296 |
+
assert file_list.files == ['a.py', mlp('f/f.py')]
|
| 297 |
+
self.assertWarnings(caplog)
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
class TestFindAll:
|
| 301 |
+
@os_helper.skip_unless_symlink
|
| 302 |
+
def test_missing_symlink(self, temp_cwd):
|
| 303 |
+
os.symlink('foo', 'bar')
|
| 304 |
+
assert filelist.findall() == []
|
| 305 |
+
|
| 306 |
+
def test_basic_discovery(self, temp_cwd):
|
| 307 |
+
"""
|
| 308 |
+
When findall is called with no parameters or with
|
| 309 |
+
'.' as the parameter, the dot should be omitted from
|
| 310 |
+
the results.
|
| 311 |
+
"""
|
| 312 |
+
jaraco.path.build({'foo': {'file1.txt': ''}, 'bar': {'file2.txt': ''}})
|
| 313 |
+
file1 = os.path.join('foo', 'file1.txt')
|
| 314 |
+
file2 = os.path.join('bar', 'file2.txt')
|
| 315 |
+
expected = [file2, file1]
|
| 316 |
+
assert sorted(filelist.findall()) == expected
|
| 317 |
+
|
| 318 |
+
def test_non_local_discovery(self, tmp_path):
|
| 319 |
+
"""
|
| 320 |
+
When findall is called with another path, the full
|
| 321 |
+
path name should be returned.
|
| 322 |
+
"""
|
| 323 |
+
jaraco.path.build({'file1.txt': ''}, tmp_path)
|
| 324 |
+
expected = [str(tmp_path / 'file1.txt')]
|
| 325 |
+
assert filelist.findall(tmp_path) == expected
|
| 326 |
+
|
| 327 |
+
@os_helper.skip_unless_symlink
|
| 328 |
+
def test_symlink_loop(self, tmp_path):
|
| 329 |
+
jaraco.path.build(
|
| 330 |
+
{
|
| 331 |
+
'link-to-parent': jaraco.path.Symlink('.'),
|
| 332 |
+
'somefile': '',
|
| 333 |
+
},
|
| 334 |
+
tmp_path,
|
| 335 |
+
)
|
| 336 |
+
files = filelist.findall(tmp_path)
|
| 337 |
+
assert len(files) == 1
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_install.py
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.install."""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
import pathlib
|
| 6 |
+
import site
|
| 7 |
+
import sys
|
| 8 |
+
from distutils import sysconfig
|
| 9 |
+
from distutils.command import install as install_module
|
| 10 |
+
from distutils.command.build_ext import build_ext
|
| 11 |
+
from distutils.command.install import INSTALL_SCHEMES, install
|
| 12 |
+
from distutils.core import Distribution
|
| 13 |
+
from distutils.errors import DistutilsOptionError
|
| 14 |
+
from distutils.extension import Extension
|
| 15 |
+
from distutils.tests import missing_compiler_executable, support
|
| 16 |
+
from distutils.util import is_mingw
|
| 17 |
+
|
| 18 |
+
import pytest
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _make_ext_name(modname):
|
| 22 |
+
return modname + sysconfig.get_config_var('EXT_SUFFIX')
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@support.combine_markers
|
| 26 |
+
@pytest.mark.usefixtures('save_env')
|
| 27 |
+
class TestInstall(
|
| 28 |
+
support.TempdirManager,
|
| 29 |
+
):
|
| 30 |
+
@pytest.mark.xfail(
|
| 31 |
+
'platform.system() == "Windows" and sys.version_info > (3, 11)',
|
| 32 |
+
reason="pypa/distutils#148",
|
| 33 |
+
)
|
| 34 |
+
def test_home_installation_scheme(self):
|
| 35 |
+
# This ensure two things:
|
| 36 |
+
# - that --home generates the desired set of directory names
|
| 37 |
+
# - test --home is supported on all platforms
|
| 38 |
+
builddir = self.mkdtemp()
|
| 39 |
+
destination = os.path.join(builddir, "installation")
|
| 40 |
+
|
| 41 |
+
dist = Distribution({"name": "foopkg"})
|
| 42 |
+
# script_name need not exist, it just need to be initialized
|
| 43 |
+
dist.script_name = os.path.join(builddir, "setup.py")
|
| 44 |
+
dist.command_obj["build"] = support.DummyCommand(
|
| 45 |
+
build_base=builddir,
|
| 46 |
+
build_lib=os.path.join(builddir, "lib"),
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
cmd = install(dist)
|
| 50 |
+
cmd.home = destination
|
| 51 |
+
cmd.ensure_finalized()
|
| 52 |
+
|
| 53 |
+
assert cmd.install_base == destination
|
| 54 |
+
assert cmd.install_platbase == destination
|
| 55 |
+
|
| 56 |
+
def check_path(got, expected):
|
| 57 |
+
got = os.path.normpath(got)
|
| 58 |
+
expected = os.path.normpath(expected)
|
| 59 |
+
assert got == expected
|
| 60 |
+
|
| 61 |
+
impl_name = sys.implementation.name.replace("cpython", "python")
|
| 62 |
+
libdir = os.path.join(destination, "lib", impl_name)
|
| 63 |
+
check_path(cmd.install_lib, libdir)
|
| 64 |
+
_platlibdir = getattr(sys, "platlibdir", "lib")
|
| 65 |
+
platlibdir = os.path.join(destination, _platlibdir, impl_name)
|
| 66 |
+
check_path(cmd.install_platlib, platlibdir)
|
| 67 |
+
check_path(cmd.install_purelib, libdir)
|
| 68 |
+
check_path(
|
| 69 |
+
cmd.install_headers,
|
| 70 |
+
os.path.join(destination, "include", impl_name, "foopkg"),
|
| 71 |
+
)
|
| 72 |
+
check_path(cmd.install_scripts, os.path.join(destination, "bin"))
|
| 73 |
+
check_path(cmd.install_data, destination)
|
| 74 |
+
|
| 75 |
+
def test_user_site(self, monkeypatch):
|
| 76 |
+
# test install with --user
|
| 77 |
+
# preparing the environment for the test
|
| 78 |
+
self.tmpdir = self.mkdtemp()
|
| 79 |
+
orig_site = site.USER_SITE
|
| 80 |
+
orig_base = site.USER_BASE
|
| 81 |
+
monkeypatch.setattr(site, 'USER_BASE', os.path.join(self.tmpdir, 'B'))
|
| 82 |
+
monkeypatch.setattr(site, 'USER_SITE', os.path.join(self.tmpdir, 'S'))
|
| 83 |
+
monkeypatch.setattr(install_module, 'USER_BASE', site.USER_BASE)
|
| 84 |
+
monkeypatch.setattr(install_module, 'USER_SITE', site.USER_SITE)
|
| 85 |
+
|
| 86 |
+
def _expanduser(path):
|
| 87 |
+
if path.startswith('~'):
|
| 88 |
+
return os.path.normpath(self.tmpdir + path[1:])
|
| 89 |
+
return path
|
| 90 |
+
|
| 91 |
+
monkeypatch.setattr(os.path, 'expanduser', _expanduser)
|
| 92 |
+
|
| 93 |
+
for key in ('nt_user', 'posix_user'):
|
| 94 |
+
assert key in INSTALL_SCHEMES
|
| 95 |
+
|
| 96 |
+
dist = Distribution({'name': 'xx'})
|
| 97 |
+
cmd = install(dist)
|
| 98 |
+
|
| 99 |
+
# making sure the user option is there
|
| 100 |
+
options = [name for name, short, label in cmd.user_options]
|
| 101 |
+
assert 'user' in options
|
| 102 |
+
|
| 103 |
+
# setting a value
|
| 104 |
+
cmd.user = True
|
| 105 |
+
|
| 106 |
+
# user base and site shouldn't be created yet
|
| 107 |
+
assert not os.path.exists(site.USER_BASE)
|
| 108 |
+
assert not os.path.exists(site.USER_SITE)
|
| 109 |
+
|
| 110 |
+
# let's run finalize
|
| 111 |
+
cmd.ensure_finalized()
|
| 112 |
+
|
| 113 |
+
# now they should
|
| 114 |
+
assert os.path.exists(site.USER_BASE)
|
| 115 |
+
assert os.path.exists(site.USER_SITE)
|
| 116 |
+
|
| 117 |
+
assert 'userbase' in cmd.config_vars
|
| 118 |
+
assert 'usersite' in cmd.config_vars
|
| 119 |
+
|
| 120 |
+
actual_headers = os.path.relpath(cmd.install_headers, site.USER_BASE)
|
| 121 |
+
if os.name == 'nt' and not is_mingw():
|
| 122 |
+
site_path = os.path.relpath(os.path.dirname(orig_site), orig_base)
|
| 123 |
+
include = os.path.join(site_path, 'Include')
|
| 124 |
+
else:
|
| 125 |
+
include = sysconfig.get_python_inc(0, '')
|
| 126 |
+
expect_headers = os.path.join(include, 'xx')
|
| 127 |
+
|
| 128 |
+
assert os.path.normcase(actual_headers) == os.path.normcase(expect_headers)
|
| 129 |
+
|
| 130 |
+
def test_handle_extra_path(self):
|
| 131 |
+
dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
|
| 132 |
+
cmd = install(dist)
|
| 133 |
+
|
| 134 |
+
# two elements
|
| 135 |
+
cmd.handle_extra_path()
|
| 136 |
+
assert cmd.extra_path == ['path', 'dirs']
|
| 137 |
+
assert cmd.extra_dirs == 'dirs'
|
| 138 |
+
assert cmd.path_file == 'path'
|
| 139 |
+
|
| 140 |
+
# one element
|
| 141 |
+
cmd.extra_path = ['path']
|
| 142 |
+
cmd.handle_extra_path()
|
| 143 |
+
assert cmd.extra_path == ['path']
|
| 144 |
+
assert cmd.extra_dirs == 'path'
|
| 145 |
+
assert cmd.path_file == 'path'
|
| 146 |
+
|
| 147 |
+
# none
|
| 148 |
+
dist.extra_path = cmd.extra_path = None
|
| 149 |
+
cmd.handle_extra_path()
|
| 150 |
+
assert cmd.extra_path is None
|
| 151 |
+
assert cmd.extra_dirs == ''
|
| 152 |
+
assert cmd.path_file is None
|
| 153 |
+
|
| 154 |
+
# three elements (no way !)
|
| 155 |
+
cmd.extra_path = 'path,dirs,again'
|
| 156 |
+
with pytest.raises(DistutilsOptionError):
|
| 157 |
+
cmd.handle_extra_path()
|
| 158 |
+
|
| 159 |
+
def test_finalize_options(self):
|
| 160 |
+
dist = Distribution({'name': 'xx'})
|
| 161 |
+
cmd = install(dist)
|
| 162 |
+
|
| 163 |
+
# must supply either prefix/exec-prefix/home or
|
| 164 |
+
# install-base/install-platbase -- not both
|
| 165 |
+
cmd.prefix = 'prefix'
|
| 166 |
+
cmd.install_base = 'base'
|
| 167 |
+
with pytest.raises(DistutilsOptionError):
|
| 168 |
+
cmd.finalize_options()
|
| 169 |
+
|
| 170 |
+
# must supply either home or prefix/exec-prefix -- not both
|
| 171 |
+
cmd.install_base = None
|
| 172 |
+
cmd.home = 'home'
|
| 173 |
+
with pytest.raises(DistutilsOptionError):
|
| 174 |
+
cmd.finalize_options()
|
| 175 |
+
|
| 176 |
+
# can't combine user with prefix/exec_prefix/home or
|
| 177 |
+
# install_(plat)base
|
| 178 |
+
cmd.prefix = None
|
| 179 |
+
cmd.user = 'user'
|
| 180 |
+
with pytest.raises(DistutilsOptionError):
|
| 181 |
+
cmd.finalize_options()
|
| 182 |
+
|
| 183 |
+
def test_record(self):
|
| 184 |
+
install_dir = self.mkdtemp()
|
| 185 |
+
project_dir, dist = self.create_dist(py_modules=['hello'], scripts=['sayhi'])
|
| 186 |
+
os.chdir(project_dir)
|
| 187 |
+
self.write_file('hello.py', "def main(): print('o hai')")
|
| 188 |
+
self.write_file('sayhi', 'from hello import main; main()')
|
| 189 |
+
|
| 190 |
+
cmd = install(dist)
|
| 191 |
+
dist.command_obj['install'] = cmd
|
| 192 |
+
cmd.root = install_dir
|
| 193 |
+
cmd.record = os.path.join(project_dir, 'filelist')
|
| 194 |
+
cmd.ensure_finalized()
|
| 195 |
+
cmd.run()
|
| 196 |
+
|
| 197 |
+
content = pathlib.Path(cmd.record).read_text(encoding='utf-8')
|
| 198 |
+
|
| 199 |
+
found = [pathlib.Path(line).name for line in content.splitlines()]
|
| 200 |
+
expected = [
|
| 201 |
+
'hello.py',
|
| 202 |
+
f'hello.{sys.implementation.cache_tag}.pyc',
|
| 203 |
+
'sayhi',
|
| 204 |
+
'UNKNOWN-0.0.0-py{}.{}.egg-info'.format(*sys.version_info[:2]),
|
| 205 |
+
]
|
| 206 |
+
assert found == expected
|
| 207 |
+
|
| 208 |
+
def test_record_extensions(self):
|
| 209 |
+
cmd = missing_compiler_executable()
|
| 210 |
+
if cmd is not None:
|
| 211 |
+
pytest.skip(f'The {cmd!r} command is not found')
|
| 212 |
+
install_dir = self.mkdtemp()
|
| 213 |
+
project_dir, dist = self.create_dist(
|
| 214 |
+
ext_modules=[Extension('xx', ['xxmodule.c'])]
|
| 215 |
+
)
|
| 216 |
+
os.chdir(project_dir)
|
| 217 |
+
support.copy_xxmodule_c(project_dir)
|
| 218 |
+
|
| 219 |
+
buildextcmd = build_ext(dist)
|
| 220 |
+
support.fixup_build_ext(buildextcmd)
|
| 221 |
+
buildextcmd.ensure_finalized()
|
| 222 |
+
|
| 223 |
+
cmd = install(dist)
|
| 224 |
+
dist.command_obj['install'] = cmd
|
| 225 |
+
dist.command_obj['build_ext'] = buildextcmd
|
| 226 |
+
cmd.root = install_dir
|
| 227 |
+
cmd.record = os.path.join(project_dir, 'filelist')
|
| 228 |
+
cmd.ensure_finalized()
|
| 229 |
+
cmd.run()
|
| 230 |
+
|
| 231 |
+
content = pathlib.Path(cmd.record).read_text(encoding='utf-8')
|
| 232 |
+
|
| 233 |
+
found = [pathlib.Path(line).name for line in content.splitlines()]
|
| 234 |
+
expected = [
|
| 235 |
+
_make_ext_name('xx'),
|
| 236 |
+
'UNKNOWN-0.0.0-py{}.{}.egg-info'.format(*sys.version_info[:2]),
|
| 237 |
+
]
|
| 238 |
+
assert found == expected
|
| 239 |
+
|
| 240 |
+
def test_debug_mode(self, caplog, monkeypatch):
|
| 241 |
+
# this covers the code called when DEBUG is set
|
| 242 |
+
monkeypatch.setattr(install_module, 'DEBUG', True)
|
| 243 |
+
caplog.set_level(logging.DEBUG)
|
| 244 |
+
self.test_record()
|
| 245 |
+
assert any(rec for rec in caplog.records if rec.levelno == logging.DEBUG)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_install_data.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.install_data."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
from distutils.command.install_data import install_data
|
| 6 |
+
from distutils.tests import support
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@pytest.mark.usefixtures('save_env')
|
| 12 |
+
class TestInstallData(
|
| 13 |
+
support.TempdirManager,
|
| 14 |
+
):
|
| 15 |
+
def test_simple_run(self):
|
| 16 |
+
pkg_dir, dist = self.create_dist()
|
| 17 |
+
cmd = install_data(dist)
|
| 18 |
+
cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
|
| 19 |
+
|
| 20 |
+
# data_files can contain
|
| 21 |
+
# - simple files
|
| 22 |
+
# - a Path object
|
| 23 |
+
# - a tuple with a path, and a list of file
|
| 24 |
+
one = os.path.join(pkg_dir, 'one')
|
| 25 |
+
self.write_file(one, 'xxx')
|
| 26 |
+
inst2 = os.path.join(pkg_dir, 'inst2')
|
| 27 |
+
two = os.path.join(pkg_dir, 'two')
|
| 28 |
+
self.write_file(two, 'xxx')
|
| 29 |
+
three = pathlib.Path(pkg_dir) / 'three'
|
| 30 |
+
self.write_file(three, 'xxx')
|
| 31 |
+
|
| 32 |
+
cmd.data_files = [one, (inst2, [two]), three]
|
| 33 |
+
assert cmd.get_inputs() == [one, (inst2, [two]), three]
|
| 34 |
+
|
| 35 |
+
# let's run the command
|
| 36 |
+
cmd.ensure_finalized()
|
| 37 |
+
cmd.run()
|
| 38 |
+
|
| 39 |
+
# let's check the result
|
| 40 |
+
assert len(cmd.get_outputs()) == 3
|
| 41 |
+
rthree = os.path.split(one)[-1]
|
| 42 |
+
assert os.path.exists(os.path.join(inst, rthree))
|
| 43 |
+
rtwo = os.path.split(two)[-1]
|
| 44 |
+
assert os.path.exists(os.path.join(inst2, rtwo))
|
| 45 |
+
rone = os.path.split(one)[-1]
|
| 46 |
+
assert os.path.exists(os.path.join(inst, rone))
|
| 47 |
+
cmd.outfiles = []
|
| 48 |
+
|
| 49 |
+
# let's try with warn_dir one
|
| 50 |
+
cmd.warn_dir = True
|
| 51 |
+
cmd.ensure_finalized()
|
| 52 |
+
cmd.run()
|
| 53 |
+
|
| 54 |
+
# let's check the result
|
| 55 |
+
assert len(cmd.get_outputs()) == 3
|
| 56 |
+
assert os.path.exists(os.path.join(inst, rthree))
|
| 57 |
+
assert os.path.exists(os.path.join(inst2, rtwo))
|
| 58 |
+
assert os.path.exists(os.path.join(inst, rone))
|
| 59 |
+
cmd.outfiles = []
|
| 60 |
+
|
| 61 |
+
# now using root and empty dir
|
| 62 |
+
cmd.root = os.path.join(pkg_dir, 'root')
|
| 63 |
+
inst5 = os.path.join(pkg_dir, 'inst5')
|
| 64 |
+
four = os.path.join(cmd.install_dir, 'four')
|
| 65 |
+
self.write_file(four, 'xx')
|
| 66 |
+
cmd.data_files = [one, (inst2, [two]), three, ('inst5', [four]), (inst5, [])]
|
| 67 |
+
cmd.ensure_finalized()
|
| 68 |
+
cmd.run()
|
| 69 |
+
|
| 70 |
+
# let's check the result
|
| 71 |
+
assert len(cmd.get_outputs()) == 5
|
| 72 |
+
assert os.path.exists(os.path.join(inst, rthree))
|
| 73 |
+
assert os.path.exists(os.path.join(inst2, rtwo))
|
| 74 |
+
assert os.path.exists(os.path.join(inst, rone))
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_install_headers.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.install_headers."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from distutils.command.install_headers import install_headers
|
| 5 |
+
from distutils.tests import support
|
| 6 |
+
|
| 7 |
+
import pytest
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@pytest.mark.usefixtures('save_env')
|
| 11 |
+
class TestInstallHeaders(
|
| 12 |
+
support.TempdirManager,
|
| 13 |
+
):
|
| 14 |
+
def test_simple_run(self):
|
| 15 |
+
# we have two headers
|
| 16 |
+
header_list = self.mkdtemp()
|
| 17 |
+
header1 = os.path.join(header_list, 'header1')
|
| 18 |
+
header2 = os.path.join(header_list, 'header2')
|
| 19 |
+
self.write_file(header1)
|
| 20 |
+
self.write_file(header2)
|
| 21 |
+
headers = [header1, header2]
|
| 22 |
+
|
| 23 |
+
pkg_dir, dist = self.create_dist(headers=headers)
|
| 24 |
+
cmd = install_headers(dist)
|
| 25 |
+
assert cmd.get_inputs() == headers
|
| 26 |
+
|
| 27 |
+
# let's run the command
|
| 28 |
+
cmd.install_dir = os.path.join(pkg_dir, 'inst')
|
| 29 |
+
cmd.ensure_finalized()
|
| 30 |
+
cmd.run()
|
| 31 |
+
|
| 32 |
+
# let's check the results
|
| 33 |
+
assert len(cmd.get_outputs()) == 2
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_install_lib.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.install_data."""
|
| 2 |
+
|
| 3 |
+
import importlib.util
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
from distutils.command.install_lib import install_lib
|
| 7 |
+
from distutils.errors import DistutilsOptionError
|
| 8 |
+
from distutils.extension import Extension
|
| 9 |
+
from distutils.tests import support
|
| 10 |
+
|
| 11 |
+
import pytest
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@support.combine_markers
|
| 15 |
+
@pytest.mark.usefixtures('save_env')
|
| 16 |
+
class TestInstallLib(
|
| 17 |
+
support.TempdirManager,
|
| 18 |
+
):
|
| 19 |
+
def test_finalize_options(self):
|
| 20 |
+
dist = self.create_dist()[1]
|
| 21 |
+
cmd = install_lib(dist)
|
| 22 |
+
|
| 23 |
+
cmd.finalize_options()
|
| 24 |
+
assert cmd.compile == 1
|
| 25 |
+
assert cmd.optimize == 0
|
| 26 |
+
|
| 27 |
+
# optimize must be 0, 1, or 2
|
| 28 |
+
cmd.optimize = 'foo'
|
| 29 |
+
with pytest.raises(DistutilsOptionError):
|
| 30 |
+
cmd.finalize_options()
|
| 31 |
+
cmd.optimize = '4'
|
| 32 |
+
with pytest.raises(DistutilsOptionError):
|
| 33 |
+
cmd.finalize_options()
|
| 34 |
+
|
| 35 |
+
cmd.optimize = '2'
|
| 36 |
+
cmd.finalize_options()
|
| 37 |
+
assert cmd.optimize == 2
|
| 38 |
+
|
| 39 |
+
@pytest.mark.skipif('sys.dont_write_bytecode')
|
| 40 |
+
def test_byte_compile(self):
|
| 41 |
+
project_dir, dist = self.create_dist()
|
| 42 |
+
os.chdir(project_dir)
|
| 43 |
+
cmd = install_lib(dist)
|
| 44 |
+
cmd.compile = cmd.optimize = 1
|
| 45 |
+
|
| 46 |
+
f = os.path.join(project_dir, 'foo.py')
|
| 47 |
+
self.write_file(f, '# python file')
|
| 48 |
+
cmd.byte_compile([f])
|
| 49 |
+
pyc_file = importlib.util.cache_from_source('foo.py', optimization='')
|
| 50 |
+
pyc_opt_file = importlib.util.cache_from_source(
|
| 51 |
+
'foo.py', optimization=cmd.optimize
|
| 52 |
+
)
|
| 53 |
+
assert os.path.exists(pyc_file)
|
| 54 |
+
assert os.path.exists(pyc_opt_file)
|
| 55 |
+
|
| 56 |
+
def test_get_outputs(self):
|
| 57 |
+
project_dir, dist = self.create_dist()
|
| 58 |
+
os.chdir(project_dir)
|
| 59 |
+
os.mkdir('spam')
|
| 60 |
+
cmd = install_lib(dist)
|
| 61 |
+
|
| 62 |
+
# setting up a dist environment
|
| 63 |
+
cmd.compile = cmd.optimize = 1
|
| 64 |
+
cmd.install_dir = self.mkdtemp()
|
| 65 |
+
f = os.path.join(project_dir, 'spam', '__init__.py')
|
| 66 |
+
self.write_file(f, '# python package')
|
| 67 |
+
cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
|
| 68 |
+
cmd.distribution.packages = ['spam']
|
| 69 |
+
cmd.distribution.script_name = 'setup.py'
|
| 70 |
+
|
| 71 |
+
# get_outputs should return 4 elements: spam/__init__.py and .pyc,
|
| 72 |
+
# foo.import-tag-abiflags.so / foo.pyd
|
| 73 |
+
outputs = cmd.get_outputs()
|
| 74 |
+
assert len(outputs) == 4, outputs
|
| 75 |
+
|
| 76 |
+
def test_get_inputs(self):
|
| 77 |
+
project_dir, dist = self.create_dist()
|
| 78 |
+
os.chdir(project_dir)
|
| 79 |
+
os.mkdir('spam')
|
| 80 |
+
cmd = install_lib(dist)
|
| 81 |
+
|
| 82 |
+
# setting up a dist environment
|
| 83 |
+
cmd.compile = cmd.optimize = 1
|
| 84 |
+
cmd.install_dir = self.mkdtemp()
|
| 85 |
+
f = os.path.join(project_dir, 'spam', '__init__.py')
|
| 86 |
+
self.write_file(f, '# python package')
|
| 87 |
+
cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
|
| 88 |
+
cmd.distribution.packages = ['spam']
|
| 89 |
+
cmd.distribution.script_name = 'setup.py'
|
| 90 |
+
|
| 91 |
+
# get_inputs should return 2 elements: spam/__init__.py and
|
| 92 |
+
# foo.import-tag-abiflags.so / foo.pyd
|
| 93 |
+
inputs = cmd.get_inputs()
|
| 94 |
+
assert len(inputs) == 2, inputs
|
| 95 |
+
|
| 96 |
+
def test_dont_write_bytecode(self, caplog):
|
| 97 |
+
# makes sure byte_compile is not used
|
| 98 |
+
dist = self.create_dist()[1]
|
| 99 |
+
cmd = install_lib(dist)
|
| 100 |
+
cmd.compile = True
|
| 101 |
+
cmd.optimize = 1
|
| 102 |
+
|
| 103 |
+
old_dont_write_bytecode = sys.dont_write_bytecode
|
| 104 |
+
sys.dont_write_bytecode = True
|
| 105 |
+
try:
|
| 106 |
+
cmd.byte_compile([])
|
| 107 |
+
finally:
|
| 108 |
+
sys.dont_write_bytecode = old_dont_write_bytecode
|
| 109 |
+
|
| 110 |
+
assert 'byte-compiling is disabled' in caplog.messages[0]
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_install_scripts.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.install_scripts."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from distutils.command.install_scripts import install_scripts
|
| 5 |
+
from distutils.core import Distribution
|
| 6 |
+
from distutils.tests import support
|
| 7 |
+
|
| 8 |
+
from . import test_build_scripts
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TestInstallScripts(support.TempdirManager):
|
| 12 |
+
def test_default_settings(self):
|
| 13 |
+
dist = Distribution()
|
| 14 |
+
dist.command_obj["build"] = support.DummyCommand(build_scripts="/foo/bar")
|
| 15 |
+
dist.command_obj["install"] = support.DummyCommand(
|
| 16 |
+
install_scripts="/splat/funk",
|
| 17 |
+
force=True,
|
| 18 |
+
skip_build=True,
|
| 19 |
+
)
|
| 20 |
+
cmd = install_scripts(dist)
|
| 21 |
+
assert not cmd.force
|
| 22 |
+
assert not cmd.skip_build
|
| 23 |
+
assert cmd.build_dir is None
|
| 24 |
+
assert cmd.install_dir is None
|
| 25 |
+
|
| 26 |
+
cmd.finalize_options()
|
| 27 |
+
|
| 28 |
+
assert cmd.force
|
| 29 |
+
assert cmd.skip_build
|
| 30 |
+
assert cmd.build_dir == "/foo/bar"
|
| 31 |
+
assert cmd.install_dir == "/splat/funk"
|
| 32 |
+
|
| 33 |
+
def test_installation(self):
|
| 34 |
+
source = self.mkdtemp()
|
| 35 |
+
|
| 36 |
+
expected = test_build_scripts.TestBuildScripts.write_sample_scripts(source)
|
| 37 |
+
|
| 38 |
+
target = self.mkdtemp()
|
| 39 |
+
dist = Distribution()
|
| 40 |
+
dist.command_obj["build"] = support.DummyCommand(build_scripts=source)
|
| 41 |
+
dist.command_obj["install"] = support.DummyCommand(
|
| 42 |
+
install_scripts=target,
|
| 43 |
+
force=True,
|
| 44 |
+
skip_build=True,
|
| 45 |
+
)
|
| 46 |
+
cmd = install_scripts(dist)
|
| 47 |
+
cmd.finalize_options()
|
| 48 |
+
cmd.run()
|
| 49 |
+
|
| 50 |
+
installed = os.listdir(target)
|
| 51 |
+
for name in expected:
|
| 52 |
+
assert name in installed
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_log.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.log"""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
from distutils._log import log
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestLog:
|
| 8 |
+
def test_non_ascii(self, caplog):
|
| 9 |
+
caplog.set_level(logging.DEBUG)
|
| 10 |
+
log.debug('Dεbug\tMėssãge')
|
| 11 |
+
log.fatal('Fαtal\tÈrrōr')
|
| 12 |
+
assert caplog.messages == ['Dεbug\tMėssãge', 'Fαtal\tÈrrōr']
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_modified.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils._modified."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import types
|
| 5 |
+
from distutils._modified import newer, newer_group, newer_pairwise, newer_pairwise_group
|
| 6 |
+
from distutils.errors import DistutilsFileError
|
| 7 |
+
from distutils.tests import support
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class TestDepUtil(support.TempdirManager):
|
| 13 |
+
def test_newer(self):
|
| 14 |
+
tmpdir = self.mkdtemp()
|
| 15 |
+
new_file = os.path.join(tmpdir, 'new')
|
| 16 |
+
old_file = os.path.abspath(__file__)
|
| 17 |
+
|
| 18 |
+
# Raise DistutilsFileError if 'new_file' does not exist.
|
| 19 |
+
with pytest.raises(DistutilsFileError):
|
| 20 |
+
newer(new_file, old_file)
|
| 21 |
+
|
| 22 |
+
# Return true if 'new_file' exists and is more recently modified than
|
| 23 |
+
# 'old_file', or if 'new_file' exists and 'old_file' doesn't.
|
| 24 |
+
self.write_file(new_file)
|
| 25 |
+
assert newer(new_file, 'I_dont_exist')
|
| 26 |
+
assert newer(new_file, old_file)
|
| 27 |
+
|
| 28 |
+
# Return false if both exist and 'old_file' is the same age or younger
|
| 29 |
+
# than 'new_file'.
|
| 30 |
+
assert not newer(old_file, new_file)
|
| 31 |
+
|
| 32 |
+
def _setup_1234(self):
|
| 33 |
+
tmpdir = self.mkdtemp()
|
| 34 |
+
sources = os.path.join(tmpdir, 'sources')
|
| 35 |
+
targets = os.path.join(tmpdir, 'targets')
|
| 36 |
+
os.mkdir(sources)
|
| 37 |
+
os.mkdir(targets)
|
| 38 |
+
one = os.path.join(sources, 'one')
|
| 39 |
+
two = os.path.join(sources, 'two')
|
| 40 |
+
three = os.path.abspath(__file__) # I am the old file
|
| 41 |
+
four = os.path.join(targets, 'four')
|
| 42 |
+
self.write_file(one)
|
| 43 |
+
self.write_file(two)
|
| 44 |
+
self.write_file(four)
|
| 45 |
+
return one, two, three, four
|
| 46 |
+
|
| 47 |
+
def test_newer_pairwise(self):
|
| 48 |
+
one, two, three, four = self._setup_1234()
|
| 49 |
+
|
| 50 |
+
assert newer_pairwise([one, two], [three, four]) == ([one], [three])
|
| 51 |
+
|
| 52 |
+
def test_newer_pairwise_mismatch(self):
|
| 53 |
+
one, two, three, four = self._setup_1234()
|
| 54 |
+
|
| 55 |
+
with pytest.raises(ValueError):
|
| 56 |
+
newer_pairwise([one], [three, four])
|
| 57 |
+
|
| 58 |
+
with pytest.raises(ValueError):
|
| 59 |
+
newer_pairwise([one, two], [three])
|
| 60 |
+
|
| 61 |
+
def test_newer_pairwise_empty(self):
|
| 62 |
+
assert newer_pairwise([], []) == ([], [])
|
| 63 |
+
|
| 64 |
+
def test_newer_pairwise_fresh(self):
|
| 65 |
+
one, two, three, four = self._setup_1234()
|
| 66 |
+
|
| 67 |
+
assert newer_pairwise([one, three], [two, four]) == ([], [])
|
| 68 |
+
|
| 69 |
+
def test_newer_group(self):
|
| 70 |
+
tmpdir = self.mkdtemp()
|
| 71 |
+
sources = os.path.join(tmpdir, 'sources')
|
| 72 |
+
os.mkdir(sources)
|
| 73 |
+
one = os.path.join(sources, 'one')
|
| 74 |
+
two = os.path.join(sources, 'two')
|
| 75 |
+
three = os.path.join(sources, 'three')
|
| 76 |
+
old_file = os.path.abspath(__file__)
|
| 77 |
+
|
| 78 |
+
# return true if 'old_file' is out-of-date with respect to any file
|
| 79 |
+
# listed in 'sources'.
|
| 80 |
+
self.write_file(one)
|
| 81 |
+
self.write_file(two)
|
| 82 |
+
self.write_file(three)
|
| 83 |
+
assert newer_group([one, two, three], old_file)
|
| 84 |
+
assert not newer_group([one, two, old_file], three)
|
| 85 |
+
|
| 86 |
+
# missing handling
|
| 87 |
+
os.remove(one)
|
| 88 |
+
with pytest.raises(OSError):
|
| 89 |
+
newer_group([one, two, old_file], three)
|
| 90 |
+
|
| 91 |
+
assert not newer_group([one, two, old_file], three, missing='ignore')
|
| 92 |
+
|
| 93 |
+
assert newer_group([one, two, old_file], three, missing='newer')
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
@pytest.fixture
|
| 97 |
+
def groups_target(tmp_path):
|
| 98 |
+
"""
|
| 99 |
+
Set up some older sources, a target, and newer sources.
|
| 100 |
+
|
| 101 |
+
Returns a simple namespace with these values.
|
| 102 |
+
"""
|
| 103 |
+
filenames = ['older.c', 'older.h', 'target.o', 'newer.c', 'newer.h']
|
| 104 |
+
paths = [tmp_path / name for name in filenames]
|
| 105 |
+
|
| 106 |
+
for mtime, path in enumerate(paths):
|
| 107 |
+
path.write_text('', encoding='utf-8')
|
| 108 |
+
|
| 109 |
+
# make sure modification times are sequential
|
| 110 |
+
os.utime(path, (mtime, mtime))
|
| 111 |
+
|
| 112 |
+
return types.SimpleNamespace(older=paths[:2], target=paths[2], newer=paths[3:])
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def test_newer_pairwise_group(groups_target):
|
| 116 |
+
older = newer_pairwise_group([groups_target.older], [groups_target.target])
|
| 117 |
+
newer = newer_pairwise_group([groups_target.newer], [groups_target.target])
|
| 118 |
+
assert older == ([], [])
|
| 119 |
+
assert newer == ([groups_target.newer], [groups_target.target])
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def test_newer_group_no_sources_no_target(tmp_path):
|
| 123 |
+
"""
|
| 124 |
+
Consider no sources and no target "newer".
|
| 125 |
+
"""
|
| 126 |
+
assert newer_group([], str(tmp_path / 'does-not-exist'))
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_sdist.py
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.command.sdist."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
import shutil # noqa: F401
|
| 6 |
+
import tarfile
|
| 7 |
+
import zipfile
|
| 8 |
+
from distutils.archive_util import ARCHIVE_FORMATS
|
| 9 |
+
from distutils.command.sdist import sdist, show_formats
|
| 10 |
+
from distutils.core import Distribution
|
| 11 |
+
from distutils.errors import DistutilsOptionError
|
| 12 |
+
from distutils.filelist import FileList
|
| 13 |
+
from os.path import join
|
| 14 |
+
from textwrap import dedent
|
| 15 |
+
|
| 16 |
+
import jaraco.path
|
| 17 |
+
import path
|
| 18 |
+
import pytest
|
| 19 |
+
from more_itertools import ilen
|
| 20 |
+
|
| 21 |
+
from . import support
|
| 22 |
+
from .unix_compat import grp, pwd, require_uid_0, require_unix_id
|
| 23 |
+
|
| 24 |
+
SETUP_PY = """
|
| 25 |
+
from distutils.core import setup
|
| 26 |
+
import somecode
|
| 27 |
+
|
| 28 |
+
setup(name='fake')
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
MANIFEST = """\
|
| 32 |
+
# file GENERATED by distutils, do NOT edit
|
| 33 |
+
README
|
| 34 |
+
buildout.cfg
|
| 35 |
+
inroot.txt
|
| 36 |
+
setup.py
|
| 37 |
+
data%(sep)sdata.dt
|
| 38 |
+
scripts%(sep)sscript.py
|
| 39 |
+
some%(sep)sfile.txt
|
| 40 |
+
some%(sep)sother_file.txt
|
| 41 |
+
somecode%(sep)s__init__.py
|
| 42 |
+
somecode%(sep)sdoc.dat
|
| 43 |
+
somecode%(sep)sdoc.txt
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
@pytest.fixture(autouse=True)
|
| 48 |
+
def project_dir(request, distutils_managed_tempdir):
|
| 49 |
+
self = request.instance
|
| 50 |
+
self.tmp_dir = self.mkdtemp()
|
| 51 |
+
jaraco.path.build(
|
| 52 |
+
{
|
| 53 |
+
'somecode': {
|
| 54 |
+
'__init__.py': '#',
|
| 55 |
+
},
|
| 56 |
+
'README': 'xxx',
|
| 57 |
+
'setup.py': SETUP_PY,
|
| 58 |
+
},
|
| 59 |
+
self.tmp_dir,
|
| 60 |
+
)
|
| 61 |
+
with path.Path(self.tmp_dir):
|
| 62 |
+
yield
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def clean_lines(filepath):
|
| 66 |
+
with pathlib.Path(filepath).open(encoding='utf-8') as f:
|
| 67 |
+
yield from filter(None, map(str.strip, f))
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class TestSDist(support.TempdirManager):
|
| 71 |
+
def get_cmd(self, metadata=None):
|
| 72 |
+
"""Returns a cmd"""
|
| 73 |
+
if metadata is None:
|
| 74 |
+
metadata = {
|
| 75 |
+
'name': 'ns.fake--pkg',
|
| 76 |
+
'version': '1.0',
|
| 77 |
+
'url': 'xxx',
|
| 78 |
+
'author': 'xxx',
|
| 79 |
+
'author_email': 'xxx',
|
| 80 |
+
}
|
| 81 |
+
dist = Distribution(metadata)
|
| 82 |
+
dist.script_name = 'setup.py'
|
| 83 |
+
dist.packages = ['somecode']
|
| 84 |
+
dist.include_package_data = True
|
| 85 |
+
cmd = sdist(dist)
|
| 86 |
+
cmd.dist_dir = 'dist'
|
| 87 |
+
return dist, cmd
|
| 88 |
+
|
| 89 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 90 |
+
def test_prune_file_list(self):
|
| 91 |
+
# this test creates a project with some VCS dirs and an NFS rename
|
| 92 |
+
# file, then launches sdist to check they get pruned on all systems
|
| 93 |
+
|
| 94 |
+
# creating VCS directories with some files in them
|
| 95 |
+
os.mkdir(join(self.tmp_dir, 'somecode', '.svn'))
|
| 96 |
+
self.write_file((self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx')
|
| 97 |
+
|
| 98 |
+
os.mkdir(join(self.tmp_dir, 'somecode', '.hg'))
|
| 99 |
+
self.write_file((self.tmp_dir, 'somecode', '.hg', 'ok'), 'xxx')
|
| 100 |
+
|
| 101 |
+
os.mkdir(join(self.tmp_dir, 'somecode', '.git'))
|
| 102 |
+
self.write_file((self.tmp_dir, 'somecode', '.git', 'ok'), 'xxx')
|
| 103 |
+
|
| 104 |
+
self.write_file((self.tmp_dir, 'somecode', '.nfs0001'), 'xxx')
|
| 105 |
+
|
| 106 |
+
# now building a sdist
|
| 107 |
+
dist, cmd = self.get_cmd()
|
| 108 |
+
|
| 109 |
+
# zip is available universally
|
| 110 |
+
# (tar might not be installed under win32)
|
| 111 |
+
cmd.formats = ['zip']
|
| 112 |
+
|
| 113 |
+
cmd.ensure_finalized()
|
| 114 |
+
cmd.run()
|
| 115 |
+
|
| 116 |
+
# now let's check what we have
|
| 117 |
+
dist_folder = join(self.tmp_dir, 'dist')
|
| 118 |
+
files = os.listdir(dist_folder)
|
| 119 |
+
assert files == ['ns_fake_pkg-1.0.zip']
|
| 120 |
+
|
| 121 |
+
zip_file = zipfile.ZipFile(join(dist_folder, 'ns_fake_pkg-1.0.zip'))
|
| 122 |
+
try:
|
| 123 |
+
content = zip_file.namelist()
|
| 124 |
+
finally:
|
| 125 |
+
zip_file.close()
|
| 126 |
+
|
| 127 |
+
# making sure everything has been pruned correctly
|
| 128 |
+
expected = [
|
| 129 |
+
'',
|
| 130 |
+
'PKG-INFO',
|
| 131 |
+
'README',
|
| 132 |
+
'setup.py',
|
| 133 |
+
'somecode/',
|
| 134 |
+
'somecode/__init__.py',
|
| 135 |
+
]
|
| 136 |
+
assert sorted(content) == ['ns_fake_pkg-1.0/' + x for x in expected]
|
| 137 |
+
|
| 138 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 139 |
+
@pytest.mark.skipif("not shutil.which('tar')")
|
| 140 |
+
@pytest.mark.skipif("not shutil.which('gzip')")
|
| 141 |
+
def test_make_distribution(self):
|
| 142 |
+
# now building a sdist
|
| 143 |
+
dist, cmd = self.get_cmd()
|
| 144 |
+
|
| 145 |
+
# creating a gztar then a tar
|
| 146 |
+
cmd.formats = ['gztar', 'tar']
|
| 147 |
+
cmd.ensure_finalized()
|
| 148 |
+
cmd.run()
|
| 149 |
+
|
| 150 |
+
# making sure we have two files
|
| 151 |
+
dist_folder = join(self.tmp_dir, 'dist')
|
| 152 |
+
result = os.listdir(dist_folder)
|
| 153 |
+
result.sort()
|
| 154 |
+
assert result == ['ns_fake_pkg-1.0.tar', 'ns_fake_pkg-1.0.tar.gz']
|
| 155 |
+
|
| 156 |
+
os.remove(join(dist_folder, 'ns_fake_pkg-1.0.tar'))
|
| 157 |
+
os.remove(join(dist_folder, 'ns_fake_pkg-1.0.tar.gz'))
|
| 158 |
+
|
| 159 |
+
# now trying a tar then a gztar
|
| 160 |
+
cmd.formats = ['tar', 'gztar']
|
| 161 |
+
|
| 162 |
+
cmd.ensure_finalized()
|
| 163 |
+
cmd.run()
|
| 164 |
+
|
| 165 |
+
result = os.listdir(dist_folder)
|
| 166 |
+
result.sort()
|
| 167 |
+
assert result == ['ns_fake_pkg-1.0.tar', 'ns_fake_pkg-1.0.tar.gz']
|
| 168 |
+
|
| 169 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 170 |
+
def test_add_defaults(self):
|
| 171 |
+
# https://bugs.python.org/issue2279
|
| 172 |
+
|
| 173 |
+
# add_default should also include
|
| 174 |
+
# data_files and package_data
|
| 175 |
+
dist, cmd = self.get_cmd()
|
| 176 |
+
|
| 177 |
+
# filling data_files by pointing files
|
| 178 |
+
# in package_data
|
| 179 |
+
dist.package_data = {'': ['*.cfg', '*.dat'], 'somecode': ['*.txt']}
|
| 180 |
+
self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
|
| 181 |
+
self.write_file((self.tmp_dir, 'somecode', 'doc.dat'), '#')
|
| 182 |
+
|
| 183 |
+
# adding some data in data_files
|
| 184 |
+
data_dir = join(self.tmp_dir, 'data')
|
| 185 |
+
os.mkdir(data_dir)
|
| 186 |
+
self.write_file((data_dir, 'data.dt'), '#')
|
| 187 |
+
some_dir = join(self.tmp_dir, 'some')
|
| 188 |
+
os.mkdir(some_dir)
|
| 189 |
+
# make sure VCS directories are pruned (#14004)
|
| 190 |
+
hg_dir = join(self.tmp_dir, '.hg')
|
| 191 |
+
os.mkdir(hg_dir)
|
| 192 |
+
self.write_file((hg_dir, 'last-message.txt'), '#')
|
| 193 |
+
# a buggy regex used to prevent this from working on windows (#6884)
|
| 194 |
+
self.write_file((self.tmp_dir, 'buildout.cfg'), '#')
|
| 195 |
+
self.write_file((self.tmp_dir, 'inroot.txt'), '#')
|
| 196 |
+
self.write_file((some_dir, 'file.txt'), '#')
|
| 197 |
+
self.write_file((some_dir, 'other_file.txt'), '#')
|
| 198 |
+
|
| 199 |
+
dist.data_files = [
|
| 200 |
+
('data', ['data/data.dt', 'buildout.cfg', 'inroot.txt', 'notexisting']),
|
| 201 |
+
'some/file.txt',
|
| 202 |
+
'some/other_file.txt',
|
| 203 |
+
]
|
| 204 |
+
|
| 205 |
+
# adding a script
|
| 206 |
+
script_dir = join(self.tmp_dir, 'scripts')
|
| 207 |
+
os.mkdir(script_dir)
|
| 208 |
+
self.write_file((script_dir, 'script.py'), '#')
|
| 209 |
+
dist.scripts = [join('scripts', 'script.py')]
|
| 210 |
+
|
| 211 |
+
cmd.formats = ['zip']
|
| 212 |
+
cmd.use_defaults = True
|
| 213 |
+
|
| 214 |
+
cmd.ensure_finalized()
|
| 215 |
+
cmd.run()
|
| 216 |
+
|
| 217 |
+
# now let's check what we have
|
| 218 |
+
dist_folder = join(self.tmp_dir, 'dist')
|
| 219 |
+
files = os.listdir(dist_folder)
|
| 220 |
+
assert files == ['ns_fake_pkg-1.0.zip']
|
| 221 |
+
|
| 222 |
+
zip_file = zipfile.ZipFile(join(dist_folder, 'ns_fake_pkg-1.0.zip'))
|
| 223 |
+
try:
|
| 224 |
+
content = zip_file.namelist()
|
| 225 |
+
finally:
|
| 226 |
+
zip_file.close()
|
| 227 |
+
|
| 228 |
+
# making sure everything was added
|
| 229 |
+
expected = [
|
| 230 |
+
'',
|
| 231 |
+
'PKG-INFO',
|
| 232 |
+
'README',
|
| 233 |
+
'buildout.cfg',
|
| 234 |
+
'data/',
|
| 235 |
+
'data/data.dt',
|
| 236 |
+
'inroot.txt',
|
| 237 |
+
'scripts/',
|
| 238 |
+
'scripts/script.py',
|
| 239 |
+
'setup.py',
|
| 240 |
+
'some/',
|
| 241 |
+
'some/file.txt',
|
| 242 |
+
'some/other_file.txt',
|
| 243 |
+
'somecode/',
|
| 244 |
+
'somecode/__init__.py',
|
| 245 |
+
'somecode/doc.dat',
|
| 246 |
+
'somecode/doc.txt',
|
| 247 |
+
]
|
| 248 |
+
assert sorted(content) == ['ns_fake_pkg-1.0/' + x for x in expected]
|
| 249 |
+
|
| 250 |
+
# checking the MANIFEST
|
| 251 |
+
manifest = pathlib.Path(self.tmp_dir, 'MANIFEST').read_text(encoding='utf-8')
|
| 252 |
+
assert manifest == MANIFEST % {'sep': os.sep}
|
| 253 |
+
|
| 254 |
+
@staticmethod
|
| 255 |
+
def warnings(messages, prefix='warning: '):
|
| 256 |
+
return [msg for msg in messages if msg.startswith(prefix)]
|
| 257 |
+
|
| 258 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 259 |
+
def test_metadata_check_option(self, caplog):
|
| 260 |
+
# testing the `medata-check` option
|
| 261 |
+
dist, cmd = self.get_cmd(metadata={})
|
| 262 |
+
|
| 263 |
+
# this should raise some warnings !
|
| 264 |
+
# with the `check` subcommand
|
| 265 |
+
cmd.ensure_finalized()
|
| 266 |
+
cmd.run()
|
| 267 |
+
assert len(self.warnings(caplog.messages, 'warning: check: ')) == 1
|
| 268 |
+
|
| 269 |
+
# trying with a complete set of metadata
|
| 270 |
+
caplog.clear()
|
| 271 |
+
dist, cmd = self.get_cmd()
|
| 272 |
+
cmd.ensure_finalized()
|
| 273 |
+
cmd.metadata_check = False
|
| 274 |
+
cmd.run()
|
| 275 |
+
assert len(self.warnings(caplog.messages, 'warning: check: ')) == 0
|
| 276 |
+
|
| 277 |
+
def test_show_formats(self, capsys):
|
| 278 |
+
show_formats()
|
| 279 |
+
|
| 280 |
+
# the output should be a header line + one line per format
|
| 281 |
+
num_formats = len(ARCHIVE_FORMATS.keys())
|
| 282 |
+
output = [
|
| 283 |
+
line
|
| 284 |
+
for line in capsys.readouterr().out.split('\n')
|
| 285 |
+
if line.strip().startswith('--formats=')
|
| 286 |
+
]
|
| 287 |
+
assert len(output) == num_formats
|
| 288 |
+
|
| 289 |
+
def test_finalize_options(self):
|
| 290 |
+
dist, cmd = self.get_cmd()
|
| 291 |
+
cmd.finalize_options()
|
| 292 |
+
|
| 293 |
+
# default options set by finalize
|
| 294 |
+
assert cmd.manifest == 'MANIFEST'
|
| 295 |
+
assert cmd.template == 'MANIFEST.in'
|
| 296 |
+
assert cmd.dist_dir == 'dist'
|
| 297 |
+
|
| 298 |
+
# formats has to be a string splitable on (' ', ',') or
|
| 299 |
+
# a stringlist
|
| 300 |
+
cmd.formats = 1
|
| 301 |
+
with pytest.raises(DistutilsOptionError):
|
| 302 |
+
cmd.finalize_options()
|
| 303 |
+
cmd.formats = ['zip']
|
| 304 |
+
cmd.finalize_options()
|
| 305 |
+
|
| 306 |
+
# formats has to be known
|
| 307 |
+
cmd.formats = 'supazipa'
|
| 308 |
+
with pytest.raises(DistutilsOptionError):
|
| 309 |
+
cmd.finalize_options()
|
| 310 |
+
|
| 311 |
+
# the following tests make sure there is a nice error message instead
|
| 312 |
+
# of a traceback when parsing an invalid manifest template
|
| 313 |
+
|
| 314 |
+
def _check_template(self, content, caplog):
|
| 315 |
+
dist, cmd = self.get_cmd()
|
| 316 |
+
os.chdir(self.tmp_dir)
|
| 317 |
+
self.write_file('MANIFEST.in', content)
|
| 318 |
+
cmd.ensure_finalized()
|
| 319 |
+
cmd.filelist = FileList()
|
| 320 |
+
cmd.read_template()
|
| 321 |
+
assert len(self.warnings(caplog.messages)) == 1
|
| 322 |
+
|
| 323 |
+
def test_invalid_template_unknown_command(self, caplog):
|
| 324 |
+
self._check_template('taunt knights *', caplog)
|
| 325 |
+
|
| 326 |
+
def test_invalid_template_wrong_arguments(self, caplog):
|
| 327 |
+
# this manifest command takes one argument
|
| 328 |
+
self._check_template('prune', caplog)
|
| 329 |
+
|
| 330 |
+
@pytest.mark.skipif("platform.system() != 'Windows'")
|
| 331 |
+
def test_invalid_template_wrong_path(self, caplog):
|
| 332 |
+
# on Windows, trailing slashes are not allowed
|
| 333 |
+
# this used to crash instead of raising a warning: #8286
|
| 334 |
+
self._check_template('include examples/', caplog)
|
| 335 |
+
|
| 336 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 337 |
+
def test_get_file_list(self):
|
| 338 |
+
# make sure MANIFEST is recalculated
|
| 339 |
+
dist, cmd = self.get_cmd()
|
| 340 |
+
|
| 341 |
+
# filling data_files by pointing files in package_data
|
| 342 |
+
dist.package_data = {'somecode': ['*.txt']}
|
| 343 |
+
self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
|
| 344 |
+
cmd.formats = ['gztar']
|
| 345 |
+
cmd.ensure_finalized()
|
| 346 |
+
cmd.run()
|
| 347 |
+
|
| 348 |
+
assert ilen(clean_lines(cmd.manifest)) == 5
|
| 349 |
+
|
| 350 |
+
# adding a file
|
| 351 |
+
self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#')
|
| 352 |
+
|
| 353 |
+
# make sure build_py is reinitialized, like a fresh run
|
| 354 |
+
build_py = dist.get_command_obj('build_py')
|
| 355 |
+
build_py.finalized = False
|
| 356 |
+
build_py.ensure_finalized()
|
| 357 |
+
|
| 358 |
+
cmd.run()
|
| 359 |
+
|
| 360 |
+
manifest2 = list(clean_lines(cmd.manifest))
|
| 361 |
+
|
| 362 |
+
# do we have the new file in MANIFEST ?
|
| 363 |
+
assert len(manifest2) == 6
|
| 364 |
+
assert 'doc2.txt' in manifest2[-1]
|
| 365 |
+
|
| 366 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 367 |
+
def test_manifest_marker(self):
|
| 368 |
+
# check that autogenerated MANIFESTs have a marker
|
| 369 |
+
dist, cmd = self.get_cmd()
|
| 370 |
+
cmd.ensure_finalized()
|
| 371 |
+
cmd.run()
|
| 372 |
+
|
| 373 |
+
assert (
|
| 374 |
+
next(clean_lines(cmd.manifest))
|
| 375 |
+
== '# file GENERATED by distutils, do NOT edit'
|
| 376 |
+
)
|
| 377 |
+
|
| 378 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 379 |
+
def test_manifest_comments(self):
|
| 380 |
+
# make sure comments don't cause exceptions or wrong includes
|
| 381 |
+
contents = dedent(
|
| 382 |
+
"""\
|
| 383 |
+
# bad.py
|
| 384 |
+
#bad.py
|
| 385 |
+
good.py
|
| 386 |
+
"""
|
| 387 |
+
)
|
| 388 |
+
dist, cmd = self.get_cmd()
|
| 389 |
+
cmd.ensure_finalized()
|
| 390 |
+
self.write_file((self.tmp_dir, cmd.manifest), contents)
|
| 391 |
+
self.write_file((self.tmp_dir, 'good.py'), '# pick me!')
|
| 392 |
+
self.write_file((self.tmp_dir, 'bad.py'), "# don't pick me!")
|
| 393 |
+
self.write_file((self.tmp_dir, '#bad.py'), "# don't pick me!")
|
| 394 |
+
cmd.run()
|
| 395 |
+
assert cmd.filelist.files == ['good.py']
|
| 396 |
+
|
| 397 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 398 |
+
def test_manual_manifest(self):
|
| 399 |
+
# check that a MANIFEST without a marker is left alone
|
| 400 |
+
dist, cmd = self.get_cmd()
|
| 401 |
+
cmd.formats = ['gztar']
|
| 402 |
+
cmd.ensure_finalized()
|
| 403 |
+
self.write_file((self.tmp_dir, cmd.manifest), 'README.manual')
|
| 404 |
+
self.write_file(
|
| 405 |
+
(self.tmp_dir, 'README.manual'),
|
| 406 |
+
'This project maintains its MANIFEST file itself.',
|
| 407 |
+
)
|
| 408 |
+
cmd.run()
|
| 409 |
+
assert cmd.filelist.files == ['README.manual']
|
| 410 |
+
|
| 411 |
+
assert list(clean_lines(cmd.manifest)) == ['README.manual']
|
| 412 |
+
|
| 413 |
+
archive_name = join(self.tmp_dir, 'dist', 'ns_fake_pkg-1.0.tar.gz')
|
| 414 |
+
archive = tarfile.open(archive_name)
|
| 415 |
+
try:
|
| 416 |
+
filenames = [tarinfo.name for tarinfo in archive]
|
| 417 |
+
finally:
|
| 418 |
+
archive.close()
|
| 419 |
+
assert sorted(filenames) == [
|
| 420 |
+
'ns_fake_pkg-1.0',
|
| 421 |
+
'ns_fake_pkg-1.0/PKG-INFO',
|
| 422 |
+
'ns_fake_pkg-1.0/README.manual',
|
| 423 |
+
]
|
| 424 |
+
|
| 425 |
+
@pytest.mark.usefixtures('needs_zlib')
|
| 426 |
+
@require_unix_id
|
| 427 |
+
@require_uid_0
|
| 428 |
+
@pytest.mark.skipif("not shutil.which('tar')")
|
| 429 |
+
@pytest.mark.skipif("not shutil.which('gzip')")
|
| 430 |
+
def test_make_distribution_owner_group(self):
|
| 431 |
+
# now building a sdist
|
| 432 |
+
dist, cmd = self.get_cmd()
|
| 433 |
+
|
| 434 |
+
# creating a gztar and specifying the owner+group
|
| 435 |
+
cmd.formats = ['gztar']
|
| 436 |
+
cmd.owner = pwd.getpwuid(0)[0]
|
| 437 |
+
cmd.group = grp.getgrgid(0)[0]
|
| 438 |
+
cmd.ensure_finalized()
|
| 439 |
+
cmd.run()
|
| 440 |
+
|
| 441 |
+
# making sure we have the good rights
|
| 442 |
+
archive_name = join(self.tmp_dir, 'dist', 'ns_fake_pkg-1.0.tar.gz')
|
| 443 |
+
archive = tarfile.open(archive_name)
|
| 444 |
+
try:
|
| 445 |
+
for member in archive.getmembers():
|
| 446 |
+
assert member.uid == 0
|
| 447 |
+
assert member.gid == 0
|
| 448 |
+
finally:
|
| 449 |
+
archive.close()
|
| 450 |
+
|
| 451 |
+
# building a sdist again
|
| 452 |
+
dist, cmd = self.get_cmd()
|
| 453 |
+
|
| 454 |
+
# creating a gztar
|
| 455 |
+
cmd.formats = ['gztar']
|
| 456 |
+
cmd.ensure_finalized()
|
| 457 |
+
cmd.run()
|
| 458 |
+
|
| 459 |
+
# making sure we have the good rights
|
| 460 |
+
archive_name = join(self.tmp_dir, 'dist', 'ns_fake_pkg-1.0.tar.gz')
|
| 461 |
+
archive = tarfile.open(archive_name)
|
| 462 |
+
|
| 463 |
+
# note that we are not testing the group ownership here
|
| 464 |
+
# because, depending on the platforms and the container
|
| 465 |
+
# rights (see #7408)
|
| 466 |
+
try:
|
| 467 |
+
for member in archive.getmembers():
|
| 468 |
+
assert member.uid == os.getuid()
|
| 469 |
+
finally:
|
| 470 |
+
archive.close()
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_spawn.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.spawn."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import stat
|
| 5 |
+
import sys
|
| 6 |
+
import unittest.mock as mock
|
| 7 |
+
from distutils.errors import DistutilsExecError
|
| 8 |
+
from distutils.spawn import find_executable, spawn
|
| 9 |
+
from distutils.tests import support
|
| 10 |
+
|
| 11 |
+
import path
|
| 12 |
+
import pytest
|
| 13 |
+
from test.support import unix_shell
|
| 14 |
+
|
| 15 |
+
from .compat import py39 as os_helper
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class TestSpawn(support.TempdirManager):
|
| 19 |
+
@pytest.mark.skipif("os.name not in ('nt', 'posix')")
|
| 20 |
+
def test_spawn(self):
|
| 21 |
+
tmpdir = self.mkdtemp()
|
| 22 |
+
|
| 23 |
+
# creating something executable
|
| 24 |
+
# through the shell that returns 1
|
| 25 |
+
if sys.platform != 'win32':
|
| 26 |
+
exe = os.path.join(tmpdir, 'foo.sh')
|
| 27 |
+
self.write_file(exe, f'#!{unix_shell}\nexit 1')
|
| 28 |
+
else:
|
| 29 |
+
exe = os.path.join(tmpdir, 'foo.bat')
|
| 30 |
+
self.write_file(exe, 'exit 1')
|
| 31 |
+
|
| 32 |
+
os.chmod(exe, 0o777)
|
| 33 |
+
with pytest.raises(DistutilsExecError):
|
| 34 |
+
spawn([exe])
|
| 35 |
+
|
| 36 |
+
# now something that works
|
| 37 |
+
if sys.platform != 'win32':
|
| 38 |
+
exe = os.path.join(tmpdir, 'foo.sh')
|
| 39 |
+
self.write_file(exe, f'#!{unix_shell}\nexit 0')
|
| 40 |
+
else:
|
| 41 |
+
exe = os.path.join(tmpdir, 'foo.bat')
|
| 42 |
+
self.write_file(exe, 'exit 0')
|
| 43 |
+
|
| 44 |
+
os.chmod(exe, 0o777)
|
| 45 |
+
spawn([exe]) # should work without any error
|
| 46 |
+
|
| 47 |
+
def test_find_executable(self, tmp_path):
|
| 48 |
+
program_path = self._make_executable(tmp_path, '.exe')
|
| 49 |
+
program = program_path.name
|
| 50 |
+
program_noeext = program_path.with_suffix('').name
|
| 51 |
+
filename = str(program_path)
|
| 52 |
+
tmp_dir = path.Path(tmp_path)
|
| 53 |
+
|
| 54 |
+
# test path parameter
|
| 55 |
+
rv = find_executable(program, path=tmp_dir)
|
| 56 |
+
assert rv == filename
|
| 57 |
+
|
| 58 |
+
if sys.platform == 'win32':
|
| 59 |
+
# test without ".exe" extension
|
| 60 |
+
rv = find_executable(program_noeext, path=tmp_dir)
|
| 61 |
+
assert rv == filename
|
| 62 |
+
|
| 63 |
+
# test find in the current directory
|
| 64 |
+
with tmp_dir:
|
| 65 |
+
rv = find_executable(program)
|
| 66 |
+
assert rv == program
|
| 67 |
+
|
| 68 |
+
# test non-existent program
|
| 69 |
+
dont_exist_program = "dontexist_" + program
|
| 70 |
+
rv = find_executable(dont_exist_program, path=tmp_dir)
|
| 71 |
+
assert rv is None
|
| 72 |
+
|
| 73 |
+
# PATH='': no match, except in the current directory
|
| 74 |
+
with os_helper.EnvironmentVarGuard() as env:
|
| 75 |
+
env['PATH'] = ''
|
| 76 |
+
with (
|
| 77 |
+
mock.patch(
|
| 78 |
+
'distutils.spawn.os.confstr', return_value=tmp_dir, create=True
|
| 79 |
+
),
|
| 80 |
+
mock.patch('distutils.spawn.os.defpath', tmp_dir),
|
| 81 |
+
):
|
| 82 |
+
rv = find_executable(program)
|
| 83 |
+
assert rv is None
|
| 84 |
+
|
| 85 |
+
# look in current directory
|
| 86 |
+
with tmp_dir:
|
| 87 |
+
rv = find_executable(program)
|
| 88 |
+
assert rv == program
|
| 89 |
+
|
| 90 |
+
# PATH=':': explicitly looks in the current directory
|
| 91 |
+
with os_helper.EnvironmentVarGuard() as env:
|
| 92 |
+
env['PATH'] = os.pathsep
|
| 93 |
+
with (
|
| 94 |
+
mock.patch('distutils.spawn.os.confstr', return_value='', create=True),
|
| 95 |
+
mock.patch('distutils.spawn.os.defpath', ''),
|
| 96 |
+
):
|
| 97 |
+
rv = find_executable(program)
|
| 98 |
+
assert rv is None
|
| 99 |
+
|
| 100 |
+
# look in current directory
|
| 101 |
+
with tmp_dir:
|
| 102 |
+
rv = find_executable(program)
|
| 103 |
+
assert rv == program
|
| 104 |
+
|
| 105 |
+
# missing PATH: test os.confstr("CS_PATH") and os.defpath
|
| 106 |
+
with os_helper.EnvironmentVarGuard() as env:
|
| 107 |
+
env.pop('PATH', None)
|
| 108 |
+
|
| 109 |
+
# without confstr
|
| 110 |
+
with (
|
| 111 |
+
mock.patch(
|
| 112 |
+
'distutils.spawn.os.confstr', side_effect=ValueError, create=True
|
| 113 |
+
),
|
| 114 |
+
mock.patch('distutils.spawn.os.defpath', tmp_dir),
|
| 115 |
+
):
|
| 116 |
+
rv = find_executable(program)
|
| 117 |
+
assert rv == filename
|
| 118 |
+
|
| 119 |
+
# with confstr
|
| 120 |
+
with (
|
| 121 |
+
mock.patch(
|
| 122 |
+
'distutils.spawn.os.confstr', return_value=tmp_dir, create=True
|
| 123 |
+
),
|
| 124 |
+
mock.patch('distutils.spawn.os.defpath', ''),
|
| 125 |
+
):
|
| 126 |
+
rv = find_executable(program)
|
| 127 |
+
assert rv == filename
|
| 128 |
+
|
| 129 |
+
@staticmethod
|
| 130 |
+
def _make_executable(tmp_path, ext):
|
| 131 |
+
# Give the temporary program a suffix regardless of platform.
|
| 132 |
+
# It's needed on Windows and not harmful on others.
|
| 133 |
+
program = tmp_path.joinpath('program').with_suffix(ext)
|
| 134 |
+
program.write_text("", encoding='utf-8')
|
| 135 |
+
program.chmod(stat.S_IXUSR)
|
| 136 |
+
return program
|
| 137 |
+
|
| 138 |
+
def test_spawn_missing_exe(self):
|
| 139 |
+
with pytest.raises(DistutilsExecError) as ctx:
|
| 140 |
+
spawn(['does-not-exist'])
|
| 141 |
+
assert "command 'does-not-exist' failed" in str(ctx.value)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_sysconfig.py
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.sysconfig."""
|
| 2 |
+
|
| 3 |
+
import contextlib
|
| 4 |
+
import distutils
|
| 5 |
+
import os
|
| 6 |
+
import pathlib
|
| 7 |
+
import subprocess
|
| 8 |
+
import sys
|
| 9 |
+
from distutils import sysconfig
|
| 10 |
+
from distutils.ccompiler import new_compiler # noqa: F401
|
| 11 |
+
from distutils.unixccompiler import UnixCCompiler
|
| 12 |
+
|
| 13 |
+
import jaraco.envs
|
| 14 |
+
import path
|
| 15 |
+
import pytest
|
| 16 |
+
from jaraco.text import trim
|
| 17 |
+
from test.support import swap_item
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _gen_makefile(root, contents):
|
| 21 |
+
jaraco.path.build({'Makefile': trim(contents)}, root)
|
| 22 |
+
return root / 'Makefile'
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@pytest.mark.usefixtures('save_env')
|
| 26 |
+
class TestSysconfig:
|
| 27 |
+
def test_get_config_h_filename(self):
|
| 28 |
+
config_h = sysconfig.get_config_h_filename()
|
| 29 |
+
assert os.path.isfile(config_h)
|
| 30 |
+
|
| 31 |
+
@pytest.mark.skipif("platform.system() == 'Windows'")
|
| 32 |
+
@pytest.mark.skipif("sys.implementation.name != 'cpython'")
|
| 33 |
+
def test_get_makefile_filename(self):
|
| 34 |
+
makefile = sysconfig.get_makefile_filename()
|
| 35 |
+
assert os.path.isfile(makefile)
|
| 36 |
+
|
| 37 |
+
def test_get_python_lib(self, tmp_path):
|
| 38 |
+
assert sysconfig.get_python_lib() != sysconfig.get_python_lib(prefix=tmp_path)
|
| 39 |
+
|
| 40 |
+
def test_get_config_vars(self):
|
| 41 |
+
cvars = sysconfig.get_config_vars()
|
| 42 |
+
assert isinstance(cvars, dict)
|
| 43 |
+
assert cvars
|
| 44 |
+
|
| 45 |
+
@pytest.mark.skipif('sysconfig.IS_PYPY')
|
| 46 |
+
@pytest.mark.skipif('sysconfig.python_build')
|
| 47 |
+
@pytest.mark.xfail('platform.system() == "Windows"')
|
| 48 |
+
def test_srcdir_simple(self):
|
| 49 |
+
# See #15364.
|
| 50 |
+
srcdir = pathlib.Path(sysconfig.get_config_var('srcdir'))
|
| 51 |
+
|
| 52 |
+
assert srcdir.absolute()
|
| 53 |
+
assert srcdir.is_dir()
|
| 54 |
+
|
| 55 |
+
makefile = pathlib.Path(sysconfig.get_makefile_filename())
|
| 56 |
+
assert makefile.parent.samefile(srcdir)
|
| 57 |
+
|
| 58 |
+
@pytest.mark.skipif('sysconfig.IS_PYPY')
|
| 59 |
+
@pytest.mark.skipif('not sysconfig.python_build')
|
| 60 |
+
def test_srcdir_python_build(self):
|
| 61 |
+
# See #15364.
|
| 62 |
+
srcdir = pathlib.Path(sysconfig.get_config_var('srcdir'))
|
| 63 |
+
|
| 64 |
+
# The python executable has not been installed so srcdir
|
| 65 |
+
# should be a full source checkout.
|
| 66 |
+
Python_h = srcdir.joinpath('Include', 'Python.h')
|
| 67 |
+
assert Python_h.is_file()
|
| 68 |
+
assert sysconfig._is_python_source_dir(srcdir)
|
| 69 |
+
assert sysconfig._is_python_source_dir(str(srcdir))
|
| 70 |
+
|
| 71 |
+
def test_srcdir_independent_of_cwd(self):
|
| 72 |
+
"""
|
| 73 |
+
srcdir should be independent of the current working directory
|
| 74 |
+
"""
|
| 75 |
+
# See #15364.
|
| 76 |
+
srcdir = sysconfig.get_config_var('srcdir')
|
| 77 |
+
with path.Path('..'):
|
| 78 |
+
srcdir2 = sysconfig.get_config_var('srcdir')
|
| 79 |
+
assert srcdir == srcdir2
|
| 80 |
+
|
| 81 |
+
def customize_compiler(self):
|
| 82 |
+
# make sure AR gets caught
|
| 83 |
+
class compiler:
|
| 84 |
+
compiler_type = 'unix'
|
| 85 |
+
executables = UnixCCompiler.executables
|
| 86 |
+
|
| 87 |
+
def __init__(self):
|
| 88 |
+
self.exes = {}
|
| 89 |
+
|
| 90 |
+
def set_executables(self, **kw):
|
| 91 |
+
for k, v in kw.items():
|
| 92 |
+
self.exes[k] = v
|
| 93 |
+
|
| 94 |
+
sysconfig_vars = {
|
| 95 |
+
'AR': 'sc_ar',
|
| 96 |
+
'CC': 'sc_cc',
|
| 97 |
+
'CXX': 'sc_cxx',
|
| 98 |
+
'ARFLAGS': '--sc-arflags',
|
| 99 |
+
'CFLAGS': '--sc-cflags',
|
| 100 |
+
'CCSHARED': '--sc-ccshared',
|
| 101 |
+
'LDSHARED': 'sc_ldshared',
|
| 102 |
+
'SHLIB_SUFFIX': 'sc_shutil_suffix',
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
comp = compiler()
|
| 106 |
+
with contextlib.ExitStack() as cm:
|
| 107 |
+
for key, value in sysconfig_vars.items():
|
| 108 |
+
cm.enter_context(swap_item(sysconfig._config_vars, key, value))
|
| 109 |
+
sysconfig.customize_compiler(comp)
|
| 110 |
+
|
| 111 |
+
return comp
|
| 112 |
+
|
| 113 |
+
@pytest.mark.skipif("not isinstance(new_compiler(), UnixCCompiler)")
|
| 114 |
+
@pytest.mark.usefixtures('disable_macos_customization')
|
| 115 |
+
def test_customize_compiler(self):
|
| 116 |
+
# Make sure that sysconfig._config_vars is initialized
|
| 117 |
+
sysconfig.get_config_vars()
|
| 118 |
+
|
| 119 |
+
os.environ['AR'] = 'env_ar'
|
| 120 |
+
os.environ['CC'] = 'env_cc'
|
| 121 |
+
os.environ['CPP'] = 'env_cpp'
|
| 122 |
+
os.environ['CXX'] = 'env_cxx --env-cxx-flags'
|
| 123 |
+
os.environ['LDSHARED'] = 'env_ldshared'
|
| 124 |
+
os.environ['LDFLAGS'] = '--env-ldflags'
|
| 125 |
+
os.environ['ARFLAGS'] = '--env-arflags'
|
| 126 |
+
os.environ['CFLAGS'] = '--env-cflags'
|
| 127 |
+
os.environ['CPPFLAGS'] = '--env-cppflags'
|
| 128 |
+
os.environ['RANLIB'] = 'env_ranlib'
|
| 129 |
+
|
| 130 |
+
comp = self.customize_compiler()
|
| 131 |
+
assert comp.exes['archiver'] == 'env_ar --env-arflags'
|
| 132 |
+
assert comp.exes['preprocessor'] == 'env_cpp --env-cppflags'
|
| 133 |
+
assert comp.exes['compiler'] == 'env_cc --env-cflags --env-cppflags'
|
| 134 |
+
assert comp.exes['compiler_so'] == (
|
| 135 |
+
'env_cc --env-cflags --env-cppflags --sc-ccshared'
|
| 136 |
+
)
|
| 137 |
+
assert (
|
| 138 |
+
comp.exes['compiler_cxx']
|
| 139 |
+
== 'env_cxx --env-cxx-flags --sc-cflags --env-cppflags'
|
| 140 |
+
)
|
| 141 |
+
assert comp.exes['linker_exe'] == 'env_cc'
|
| 142 |
+
assert comp.exes['linker_so'] == (
|
| 143 |
+
'env_ldshared --env-ldflags --env-cflags --env-cppflags'
|
| 144 |
+
)
|
| 145 |
+
assert comp.shared_lib_extension == 'sc_shutil_suffix'
|
| 146 |
+
|
| 147 |
+
if sys.platform == "darwin":
|
| 148 |
+
assert comp.exes['ranlib'] == 'env_ranlib'
|
| 149 |
+
else:
|
| 150 |
+
assert 'ranlib' not in comp.exes
|
| 151 |
+
|
| 152 |
+
del os.environ['AR']
|
| 153 |
+
del os.environ['CC']
|
| 154 |
+
del os.environ['CPP']
|
| 155 |
+
del os.environ['CXX']
|
| 156 |
+
del os.environ['LDSHARED']
|
| 157 |
+
del os.environ['LDFLAGS']
|
| 158 |
+
del os.environ['ARFLAGS']
|
| 159 |
+
del os.environ['CFLAGS']
|
| 160 |
+
del os.environ['CPPFLAGS']
|
| 161 |
+
del os.environ['RANLIB']
|
| 162 |
+
|
| 163 |
+
comp = self.customize_compiler()
|
| 164 |
+
assert comp.exes['archiver'] == 'sc_ar --sc-arflags'
|
| 165 |
+
assert comp.exes['preprocessor'] == 'sc_cc -E'
|
| 166 |
+
assert comp.exes['compiler'] == 'sc_cc --sc-cflags'
|
| 167 |
+
assert comp.exes['compiler_so'] == 'sc_cc --sc-cflags --sc-ccshared'
|
| 168 |
+
assert comp.exes['compiler_cxx'] == 'sc_cxx --sc-cflags'
|
| 169 |
+
assert comp.exes['linker_exe'] == 'sc_cc'
|
| 170 |
+
assert comp.exes['linker_so'] == 'sc_ldshared'
|
| 171 |
+
assert comp.shared_lib_extension == 'sc_shutil_suffix'
|
| 172 |
+
assert 'ranlib' not in comp.exes
|
| 173 |
+
|
| 174 |
+
def test_parse_makefile_base(self, tmp_path):
|
| 175 |
+
makefile = _gen_makefile(
|
| 176 |
+
tmp_path,
|
| 177 |
+
"""
|
| 178 |
+
CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'
|
| 179 |
+
VAR=$OTHER
|
| 180 |
+
OTHER=foo
|
| 181 |
+
""",
|
| 182 |
+
)
|
| 183 |
+
d = sysconfig.parse_makefile(makefile)
|
| 184 |
+
assert d == {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'", 'OTHER': 'foo'}
|
| 185 |
+
|
| 186 |
+
def test_parse_makefile_literal_dollar(self, tmp_path):
|
| 187 |
+
makefile = _gen_makefile(
|
| 188 |
+
tmp_path,
|
| 189 |
+
"""
|
| 190 |
+
CONFIG_ARGS= '--arg1=optarg1' 'ENV=\\$$LIB'
|
| 191 |
+
VAR=$OTHER
|
| 192 |
+
OTHER=foo
|
| 193 |
+
""",
|
| 194 |
+
)
|
| 195 |
+
d = sysconfig.parse_makefile(makefile)
|
| 196 |
+
assert d == {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'", 'OTHER': 'foo'}
|
| 197 |
+
|
| 198 |
+
def test_sysconfig_module(self):
|
| 199 |
+
import sysconfig as global_sysconfig
|
| 200 |
+
|
| 201 |
+
assert global_sysconfig.get_config_var('CFLAGS') == sysconfig.get_config_var(
|
| 202 |
+
'CFLAGS'
|
| 203 |
+
)
|
| 204 |
+
assert global_sysconfig.get_config_var('LDFLAGS') == sysconfig.get_config_var(
|
| 205 |
+
'LDFLAGS'
|
| 206 |
+
)
|
| 207 |
+
|
| 208 |
+
# On macOS, binary installers support extension module building on
|
| 209 |
+
# various levels of the operating system with differing Xcode
|
| 210 |
+
# configurations, requiring customization of some of the
|
| 211 |
+
# compiler configuration directives to suit the environment on
|
| 212 |
+
# the installed machine. Some of these customizations may require
|
| 213 |
+
# running external programs and are thus deferred until needed by
|
| 214 |
+
# the first extension module build. Only
|
| 215 |
+
# the Distutils version of sysconfig is used for extension module
|
| 216 |
+
# builds, which happens earlier in the Distutils tests. This may
|
| 217 |
+
# cause the following tests to fail since no tests have caused
|
| 218 |
+
# the global version of sysconfig to call the customization yet.
|
| 219 |
+
# The solution for now is to simply skip this test in this case.
|
| 220 |
+
# The longer-term solution is to only have one version of sysconfig.
|
| 221 |
+
@pytest.mark.skipif("sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER')")
|
| 222 |
+
def test_sysconfig_compiler_vars(self):
|
| 223 |
+
import sysconfig as global_sysconfig
|
| 224 |
+
|
| 225 |
+
if sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'):
|
| 226 |
+
pytest.skip('compiler flags customized')
|
| 227 |
+
assert global_sysconfig.get_config_var('LDSHARED') == sysconfig.get_config_var(
|
| 228 |
+
'LDSHARED'
|
| 229 |
+
)
|
| 230 |
+
assert global_sysconfig.get_config_var('CC') == sysconfig.get_config_var('CC')
|
| 231 |
+
|
| 232 |
+
@pytest.mark.skipif("not sysconfig.get_config_var('EXT_SUFFIX')")
|
| 233 |
+
def test_SO_deprecation(self):
|
| 234 |
+
with pytest.warns(DeprecationWarning):
|
| 235 |
+
sysconfig.get_config_var('SO')
|
| 236 |
+
|
| 237 |
+
def test_customize_compiler_before_get_config_vars(self, tmp_path):
|
| 238 |
+
# Issue #21923: test that a Distribution compiler
|
| 239 |
+
# instance can be called without an explicit call to
|
| 240 |
+
# get_config_vars().
|
| 241 |
+
jaraco.path.build(
|
| 242 |
+
{
|
| 243 |
+
'file': trim("""
|
| 244 |
+
from distutils.core import Distribution
|
| 245 |
+
config = Distribution().get_command_obj('config')
|
| 246 |
+
# try_compile may pass or it may fail if no compiler
|
| 247 |
+
# is found but it should not raise an exception.
|
| 248 |
+
rc = config.try_compile('int x;')
|
| 249 |
+
""")
|
| 250 |
+
},
|
| 251 |
+
tmp_path,
|
| 252 |
+
)
|
| 253 |
+
p = subprocess.Popen(
|
| 254 |
+
[sys.executable, tmp_path / 'file'],
|
| 255 |
+
stdout=subprocess.PIPE,
|
| 256 |
+
stderr=subprocess.STDOUT,
|
| 257 |
+
universal_newlines=True,
|
| 258 |
+
encoding='utf-8',
|
| 259 |
+
)
|
| 260 |
+
outs, errs = p.communicate()
|
| 261 |
+
assert 0 == p.returncode, "Subprocess failed: " + outs
|
| 262 |
+
|
| 263 |
+
def test_parse_config_h(self):
|
| 264 |
+
config_h = sysconfig.get_config_h_filename()
|
| 265 |
+
input = {}
|
| 266 |
+
with open(config_h, encoding="utf-8") as f:
|
| 267 |
+
result = sysconfig.parse_config_h(f, g=input)
|
| 268 |
+
assert input is result
|
| 269 |
+
with open(config_h, encoding="utf-8") as f:
|
| 270 |
+
result = sysconfig.parse_config_h(f)
|
| 271 |
+
assert isinstance(result, dict)
|
| 272 |
+
|
| 273 |
+
@pytest.mark.skipif("platform.system() != 'Windows'")
|
| 274 |
+
@pytest.mark.skipif("sys.implementation.name != 'cpython'")
|
| 275 |
+
def test_win_ext_suffix(self):
|
| 276 |
+
assert sysconfig.get_config_var("EXT_SUFFIX").endswith(".pyd")
|
| 277 |
+
assert sysconfig.get_config_var("EXT_SUFFIX") != ".pyd"
|
| 278 |
+
|
| 279 |
+
@pytest.mark.skipif("platform.system() != 'Windows'")
|
| 280 |
+
@pytest.mark.skipif("sys.implementation.name != 'cpython'")
|
| 281 |
+
@pytest.mark.skipif(
|
| 282 |
+
'\\PCbuild\\'.casefold() not in sys.executable.casefold(),
|
| 283 |
+
reason='Need sys.executable to be in a source tree',
|
| 284 |
+
)
|
| 285 |
+
def test_win_build_venv_from_source_tree(self, tmp_path):
|
| 286 |
+
"""Ensure distutils.sysconfig detects venvs from source tree builds."""
|
| 287 |
+
env = jaraco.envs.VEnv()
|
| 288 |
+
env.create_opts = env.clean_opts
|
| 289 |
+
env.root = tmp_path
|
| 290 |
+
env.ensure_env()
|
| 291 |
+
cmd = [
|
| 292 |
+
env.exe(),
|
| 293 |
+
"-c",
|
| 294 |
+
"import distutils.sysconfig; print(distutils.sysconfig.python_build)",
|
| 295 |
+
]
|
| 296 |
+
distutils_path = os.path.dirname(os.path.dirname(distutils.__file__))
|
| 297 |
+
out = subprocess.check_output(
|
| 298 |
+
cmd, env={**os.environ, "PYTHONPATH": distutils_path}
|
| 299 |
+
)
|
| 300 |
+
assert out == "True"
|
| 301 |
+
|
| 302 |
+
def test_get_python_inc_missing_config_dir(self, monkeypatch):
|
| 303 |
+
"""
|
| 304 |
+
In portable Python installations, the sysconfig will be broken,
|
| 305 |
+
pointing to the directories where the installation was built and
|
| 306 |
+
not where it currently is. In this case, ensure that the missing
|
| 307 |
+
directory isn't used for get_python_inc.
|
| 308 |
+
|
| 309 |
+
See pypa/distutils#178.
|
| 310 |
+
"""
|
| 311 |
+
|
| 312 |
+
def override(name):
|
| 313 |
+
if name == 'INCLUDEPY':
|
| 314 |
+
return '/does-not-exist'
|
| 315 |
+
return sysconfig.get_config_var(name)
|
| 316 |
+
|
| 317 |
+
monkeypatch.setattr(sysconfig, 'get_config_var', override)
|
| 318 |
+
|
| 319 |
+
assert os.path.exists(sysconfig.get_python_inc())
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_text_file.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.text_file."""
|
| 2 |
+
|
| 3 |
+
from distutils.tests import support
|
| 4 |
+
from distutils.text_file import TextFile
|
| 5 |
+
|
| 6 |
+
import jaraco.path
|
| 7 |
+
import path
|
| 8 |
+
|
| 9 |
+
TEST_DATA = """# test file
|
| 10 |
+
|
| 11 |
+
line 3 \\
|
| 12 |
+
# intervening comment
|
| 13 |
+
continues on next line
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class TestTextFile(support.TempdirManager):
|
| 18 |
+
def test_class(self):
|
| 19 |
+
# old tests moved from text_file.__main__
|
| 20 |
+
# so they are really called by the buildbots
|
| 21 |
+
|
| 22 |
+
# result 1: no fancy options
|
| 23 |
+
result1 = [
|
| 24 |
+
'# test file\n',
|
| 25 |
+
'\n',
|
| 26 |
+
'line 3 \\\n',
|
| 27 |
+
'# intervening comment\n',
|
| 28 |
+
' continues on next line\n',
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
# result 2: just strip comments
|
| 32 |
+
result2 = ["\n", "line 3 \\\n", " continues on next line\n"]
|
| 33 |
+
|
| 34 |
+
# result 3: just strip blank lines
|
| 35 |
+
result3 = [
|
| 36 |
+
"# test file\n",
|
| 37 |
+
"line 3 \\\n",
|
| 38 |
+
"# intervening comment\n",
|
| 39 |
+
" continues on next line\n",
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
# result 4: default, strip comments, blank lines,
|
| 43 |
+
# and trailing whitespace
|
| 44 |
+
result4 = ["line 3 \\", " continues on next line"]
|
| 45 |
+
|
| 46 |
+
# result 5: strip comments and blanks, plus join lines (but don't
|
| 47 |
+
# "collapse" joined lines
|
| 48 |
+
result5 = ["line 3 continues on next line"]
|
| 49 |
+
|
| 50 |
+
# result 6: strip comments and blanks, plus join lines (and
|
| 51 |
+
# "collapse" joined lines
|
| 52 |
+
result6 = ["line 3 continues on next line"]
|
| 53 |
+
|
| 54 |
+
def test_input(count, description, file, expected_result):
|
| 55 |
+
result = file.readlines()
|
| 56 |
+
assert result == expected_result
|
| 57 |
+
|
| 58 |
+
tmp_path = path.Path(self.mkdtemp())
|
| 59 |
+
filename = tmp_path / 'test.txt'
|
| 60 |
+
jaraco.path.build({filename.name: TEST_DATA}, tmp_path)
|
| 61 |
+
|
| 62 |
+
in_file = TextFile(
|
| 63 |
+
filename,
|
| 64 |
+
strip_comments=False,
|
| 65 |
+
skip_blanks=False,
|
| 66 |
+
lstrip_ws=False,
|
| 67 |
+
rstrip_ws=False,
|
| 68 |
+
)
|
| 69 |
+
try:
|
| 70 |
+
test_input(1, "no processing", in_file, result1)
|
| 71 |
+
finally:
|
| 72 |
+
in_file.close()
|
| 73 |
+
|
| 74 |
+
in_file = TextFile(
|
| 75 |
+
filename,
|
| 76 |
+
strip_comments=True,
|
| 77 |
+
skip_blanks=False,
|
| 78 |
+
lstrip_ws=False,
|
| 79 |
+
rstrip_ws=False,
|
| 80 |
+
)
|
| 81 |
+
try:
|
| 82 |
+
test_input(2, "strip comments", in_file, result2)
|
| 83 |
+
finally:
|
| 84 |
+
in_file.close()
|
| 85 |
+
|
| 86 |
+
in_file = TextFile(
|
| 87 |
+
filename,
|
| 88 |
+
strip_comments=False,
|
| 89 |
+
skip_blanks=True,
|
| 90 |
+
lstrip_ws=False,
|
| 91 |
+
rstrip_ws=False,
|
| 92 |
+
)
|
| 93 |
+
try:
|
| 94 |
+
test_input(3, "strip blanks", in_file, result3)
|
| 95 |
+
finally:
|
| 96 |
+
in_file.close()
|
| 97 |
+
|
| 98 |
+
in_file = TextFile(filename)
|
| 99 |
+
try:
|
| 100 |
+
test_input(4, "default processing", in_file, result4)
|
| 101 |
+
finally:
|
| 102 |
+
in_file.close()
|
| 103 |
+
|
| 104 |
+
in_file = TextFile(
|
| 105 |
+
filename,
|
| 106 |
+
strip_comments=True,
|
| 107 |
+
skip_blanks=True,
|
| 108 |
+
join_lines=True,
|
| 109 |
+
rstrip_ws=True,
|
| 110 |
+
)
|
| 111 |
+
try:
|
| 112 |
+
test_input(5, "join lines without collapsing", in_file, result5)
|
| 113 |
+
finally:
|
| 114 |
+
in_file.close()
|
| 115 |
+
|
| 116 |
+
in_file = TextFile(
|
| 117 |
+
filename,
|
| 118 |
+
strip_comments=True,
|
| 119 |
+
skip_blanks=True,
|
| 120 |
+
join_lines=True,
|
| 121 |
+
rstrip_ws=True,
|
| 122 |
+
collapse_join=True,
|
| 123 |
+
)
|
| 124 |
+
try:
|
| 125 |
+
test_input(6, "join lines with collapsing", in_file, result6)
|
| 126 |
+
finally:
|
| 127 |
+
in_file.close()
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_util.py
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.util."""
|
| 2 |
+
|
| 3 |
+
import email
|
| 4 |
+
import email.generator
|
| 5 |
+
import email.policy
|
| 6 |
+
import io
|
| 7 |
+
import os
|
| 8 |
+
import pathlib
|
| 9 |
+
import sys
|
| 10 |
+
import sysconfig as stdlib_sysconfig
|
| 11 |
+
import unittest.mock as mock
|
| 12 |
+
from copy import copy
|
| 13 |
+
from distutils import sysconfig, util
|
| 14 |
+
from distutils.errors import DistutilsByteCompileError, DistutilsPlatformError
|
| 15 |
+
from distutils.util import (
|
| 16 |
+
byte_compile,
|
| 17 |
+
change_root,
|
| 18 |
+
check_environ,
|
| 19 |
+
convert_path,
|
| 20 |
+
get_host_platform,
|
| 21 |
+
get_platform,
|
| 22 |
+
grok_environment_error,
|
| 23 |
+
rfc822_escape,
|
| 24 |
+
split_quoted,
|
| 25 |
+
strtobool,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
import pytest
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
@pytest.fixture(autouse=True)
|
| 32 |
+
def environment(monkeypatch):
|
| 33 |
+
monkeypatch.setattr(os, 'name', os.name)
|
| 34 |
+
monkeypatch.setattr(sys, 'platform', sys.platform)
|
| 35 |
+
monkeypatch.setattr(sys, 'version', sys.version)
|
| 36 |
+
monkeypatch.setattr(os, 'sep', os.sep)
|
| 37 |
+
monkeypatch.setattr(os.path, 'join', os.path.join)
|
| 38 |
+
monkeypatch.setattr(os.path, 'isabs', os.path.isabs)
|
| 39 |
+
monkeypatch.setattr(os.path, 'splitdrive', os.path.splitdrive)
|
| 40 |
+
monkeypatch.setattr(sysconfig, '_config_vars', copy(sysconfig._config_vars))
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@pytest.mark.usefixtures('save_env')
|
| 44 |
+
class TestUtil:
|
| 45 |
+
def test_get_host_platform(self):
|
| 46 |
+
assert get_host_platform() == stdlib_sysconfig.get_platform()
|
| 47 |
+
|
| 48 |
+
def test_get_platform(self):
|
| 49 |
+
with mock.patch('os.name', 'nt'):
|
| 50 |
+
with mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'x86'}):
|
| 51 |
+
assert get_platform() == 'win32'
|
| 52 |
+
with mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'x64'}):
|
| 53 |
+
assert get_platform() == 'win-amd64'
|
| 54 |
+
with mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm'}):
|
| 55 |
+
assert get_platform() == 'win-arm32'
|
| 56 |
+
with mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm64'}):
|
| 57 |
+
assert get_platform() == 'win-arm64'
|
| 58 |
+
|
| 59 |
+
def test_convert_path(self):
|
| 60 |
+
expected = os.sep.join(('', 'home', 'to', 'my', 'stuff'))
|
| 61 |
+
assert convert_path('/home/to/my/stuff') == expected
|
| 62 |
+
assert convert_path(pathlib.Path('/home/to/my/stuff')) == expected
|
| 63 |
+
assert convert_path('.') == os.curdir
|
| 64 |
+
|
| 65 |
+
def test_change_root(self):
|
| 66 |
+
# linux/mac
|
| 67 |
+
os.name = 'posix'
|
| 68 |
+
|
| 69 |
+
def _isabs(path):
|
| 70 |
+
return path[0] == '/'
|
| 71 |
+
|
| 72 |
+
os.path.isabs = _isabs
|
| 73 |
+
|
| 74 |
+
def _join(*path):
|
| 75 |
+
return '/'.join(path)
|
| 76 |
+
|
| 77 |
+
os.path.join = _join
|
| 78 |
+
|
| 79 |
+
assert change_root('/root', '/old/its/here') == '/root/old/its/here'
|
| 80 |
+
assert change_root('/root', 'its/here') == '/root/its/here'
|
| 81 |
+
|
| 82 |
+
# windows
|
| 83 |
+
os.name = 'nt'
|
| 84 |
+
os.sep = '\\'
|
| 85 |
+
|
| 86 |
+
def _isabs(path):
|
| 87 |
+
return path.startswith('c:\\')
|
| 88 |
+
|
| 89 |
+
os.path.isabs = _isabs
|
| 90 |
+
|
| 91 |
+
def _splitdrive(path):
|
| 92 |
+
if path.startswith('c:'):
|
| 93 |
+
return ('', path.replace('c:', ''))
|
| 94 |
+
return ('', path)
|
| 95 |
+
|
| 96 |
+
os.path.splitdrive = _splitdrive
|
| 97 |
+
|
| 98 |
+
def _join(*path):
|
| 99 |
+
return '\\'.join(path)
|
| 100 |
+
|
| 101 |
+
os.path.join = _join
|
| 102 |
+
|
| 103 |
+
assert (
|
| 104 |
+
change_root('c:\\root', 'c:\\old\\its\\here') == 'c:\\root\\old\\its\\here'
|
| 105 |
+
)
|
| 106 |
+
assert change_root('c:\\root', 'its\\here') == 'c:\\root\\its\\here'
|
| 107 |
+
|
| 108 |
+
# BugsBunny os (it's a great os)
|
| 109 |
+
os.name = 'BugsBunny'
|
| 110 |
+
with pytest.raises(DistutilsPlatformError):
|
| 111 |
+
change_root('c:\\root', 'its\\here')
|
| 112 |
+
|
| 113 |
+
# XXX platforms to be covered: mac
|
| 114 |
+
|
| 115 |
+
def test_check_environ(self):
|
| 116 |
+
util.check_environ.cache_clear()
|
| 117 |
+
os.environ.pop('HOME', None)
|
| 118 |
+
|
| 119 |
+
check_environ()
|
| 120 |
+
|
| 121 |
+
assert os.environ['PLAT'] == get_platform()
|
| 122 |
+
|
| 123 |
+
@pytest.mark.skipif("os.name != 'posix'")
|
| 124 |
+
def test_check_environ_getpwuid(self):
|
| 125 |
+
util.check_environ.cache_clear()
|
| 126 |
+
os.environ.pop('HOME', None)
|
| 127 |
+
|
| 128 |
+
import pwd
|
| 129 |
+
|
| 130 |
+
# only set pw_dir field, other fields are not used
|
| 131 |
+
result = pwd.struct_passwd((
|
| 132 |
+
None,
|
| 133 |
+
None,
|
| 134 |
+
None,
|
| 135 |
+
None,
|
| 136 |
+
None,
|
| 137 |
+
'/home/distutils',
|
| 138 |
+
None,
|
| 139 |
+
))
|
| 140 |
+
with mock.patch.object(pwd, 'getpwuid', return_value=result):
|
| 141 |
+
check_environ()
|
| 142 |
+
assert os.environ['HOME'] == '/home/distutils'
|
| 143 |
+
|
| 144 |
+
util.check_environ.cache_clear()
|
| 145 |
+
os.environ.pop('HOME', None)
|
| 146 |
+
|
| 147 |
+
# bpo-10496: Catch pwd.getpwuid() error
|
| 148 |
+
with mock.patch.object(pwd, 'getpwuid', side_effect=KeyError):
|
| 149 |
+
check_environ()
|
| 150 |
+
assert 'HOME' not in os.environ
|
| 151 |
+
|
| 152 |
+
def test_split_quoted(self):
|
| 153 |
+
assert split_quoted('""one"" "two" \'three\' \\four') == [
|
| 154 |
+
'one',
|
| 155 |
+
'two',
|
| 156 |
+
'three',
|
| 157 |
+
'four',
|
| 158 |
+
]
|
| 159 |
+
|
| 160 |
+
def test_strtobool(self):
|
| 161 |
+
yes = ('y', 'Y', 'yes', 'True', 't', 'true', 'True', 'On', 'on', '1')
|
| 162 |
+
no = ('n', 'no', 'f', 'false', 'off', '0', 'Off', 'No', 'N')
|
| 163 |
+
|
| 164 |
+
for y in yes:
|
| 165 |
+
assert strtobool(y)
|
| 166 |
+
|
| 167 |
+
for n in no:
|
| 168 |
+
assert not strtobool(n)
|
| 169 |
+
|
| 170 |
+
indent = 8 * ' '
|
| 171 |
+
|
| 172 |
+
@pytest.mark.parametrize(
|
| 173 |
+
"given,wanted",
|
| 174 |
+
[
|
| 175 |
+
# 0x0b, 0x0c, ..., etc are also considered a line break by Python
|
| 176 |
+
("hello\x0b\nworld\n", f"hello\x0b{indent}\n{indent}world\n{indent}"),
|
| 177 |
+
("hello\x1eworld", f"hello\x1e{indent}world"),
|
| 178 |
+
("", ""),
|
| 179 |
+
(
|
| 180 |
+
"I am a\npoor\nlonesome\nheader\n",
|
| 181 |
+
f"I am a\n{indent}poor\n{indent}lonesome\n{indent}header\n{indent}",
|
| 182 |
+
),
|
| 183 |
+
],
|
| 184 |
+
)
|
| 185 |
+
def test_rfc822_escape(self, given, wanted):
|
| 186 |
+
"""
|
| 187 |
+
We want to ensure a multi-line header parses correctly.
|
| 188 |
+
|
| 189 |
+
For interoperability, the escaped value should also "round-trip" over
|
| 190 |
+
`email.generator.Generator.flatten` and `email.message_from_*`
|
| 191 |
+
(see pypa/setuptools#4033).
|
| 192 |
+
|
| 193 |
+
The main issue is that internally `email.policy.EmailPolicy` uses
|
| 194 |
+
`splitlines` which will split on some control chars. If all the new lines
|
| 195 |
+
are not prefixed with spaces, the parser will interrupt reading
|
| 196 |
+
the current header and produce an incomplete value, while
|
| 197 |
+
incorrectly interpreting the rest of the headers as part of the payload.
|
| 198 |
+
"""
|
| 199 |
+
res = rfc822_escape(given)
|
| 200 |
+
|
| 201 |
+
policy = email.policy.EmailPolicy(
|
| 202 |
+
utf8=True,
|
| 203 |
+
mangle_from_=False,
|
| 204 |
+
max_line_length=0,
|
| 205 |
+
)
|
| 206 |
+
with io.StringIO() as buffer:
|
| 207 |
+
raw = f"header: {res}\nother-header: 42\n\npayload\n"
|
| 208 |
+
orig = email.message_from_string(raw)
|
| 209 |
+
email.generator.Generator(buffer, policy=policy).flatten(orig)
|
| 210 |
+
buffer.seek(0)
|
| 211 |
+
regen = email.message_from_file(buffer)
|
| 212 |
+
|
| 213 |
+
for msg in (orig, regen):
|
| 214 |
+
assert msg.get_payload() == "payload\n"
|
| 215 |
+
assert msg["other-header"] == "42"
|
| 216 |
+
# Generator may replace control chars with `\n`
|
| 217 |
+
assert set(msg["header"].splitlines()) == set(res.splitlines())
|
| 218 |
+
|
| 219 |
+
assert res == wanted
|
| 220 |
+
|
| 221 |
+
def test_dont_write_bytecode(self):
|
| 222 |
+
# makes sure byte_compile raise a DistutilsError
|
| 223 |
+
# if sys.dont_write_bytecode is True
|
| 224 |
+
old_dont_write_bytecode = sys.dont_write_bytecode
|
| 225 |
+
sys.dont_write_bytecode = True
|
| 226 |
+
try:
|
| 227 |
+
with pytest.raises(DistutilsByteCompileError):
|
| 228 |
+
byte_compile([])
|
| 229 |
+
finally:
|
| 230 |
+
sys.dont_write_bytecode = old_dont_write_bytecode
|
| 231 |
+
|
| 232 |
+
def test_grok_environment_error(self):
|
| 233 |
+
# test obsolete function to ensure backward compat (#4931)
|
| 234 |
+
exc = OSError("Unable to find batch file")
|
| 235 |
+
msg = grok_environment_error(exc)
|
| 236 |
+
assert msg == "error: Unable to find batch file"
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_version.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.version."""
|
| 2 |
+
|
| 3 |
+
import distutils
|
| 4 |
+
from distutils.version import LooseVersion, StrictVersion
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@pytest.fixture(autouse=True)
|
| 10 |
+
def suppress_deprecation():
|
| 11 |
+
with distutils.version.suppress_known_deprecation():
|
| 12 |
+
yield
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TestVersion:
|
| 16 |
+
def test_prerelease(self):
|
| 17 |
+
version = StrictVersion('1.2.3a1')
|
| 18 |
+
assert version.version == (1, 2, 3)
|
| 19 |
+
assert version.prerelease == ('a', 1)
|
| 20 |
+
assert str(version) == '1.2.3a1'
|
| 21 |
+
|
| 22 |
+
version = StrictVersion('1.2.0')
|
| 23 |
+
assert str(version) == '1.2'
|
| 24 |
+
|
| 25 |
+
def test_cmp_strict(self):
|
| 26 |
+
versions = (
|
| 27 |
+
('1.5.1', '1.5.2b2', -1),
|
| 28 |
+
('161', '3.10a', ValueError),
|
| 29 |
+
('8.02', '8.02', 0),
|
| 30 |
+
('3.4j', '1996.07.12', ValueError),
|
| 31 |
+
('3.2.pl0', '3.1.1.6', ValueError),
|
| 32 |
+
('2g6', '11g', ValueError),
|
| 33 |
+
('0.9', '2.2', -1),
|
| 34 |
+
('1.2.1', '1.2', 1),
|
| 35 |
+
('1.1', '1.2.2', -1),
|
| 36 |
+
('1.2', '1.1', 1),
|
| 37 |
+
('1.2.1', '1.2.2', -1),
|
| 38 |
+
('1.2.2', '1.2', 1),
|
| 39 |
+
('1.2', '1.2.2', -1),
|
| 40 |
+
('0.4.0', '0.4', 0),
|
| 41 |
+
('1.13++', '5.5.kw', ValueError),
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
for v1, v2, wanted in versions:
|
| 45 |
+
try:
|
| 46 |
+
res = StrictVersion(v1)._cmp(StrictVersion(v2))
|
| 47 |
+
except ValueError:
|
| 48 |
+
if wanted is ValueError:
|
| 49 |
+
continue
|
| 50 |
+
else:
|
| 51 |
+
raise AssertionError(f"cmp({v1}, {v2}) shouldn't raise ValueError")
|
| 52 |
+
assert res == wanted, f'cmp({v1}, {v2}) should be {wanted}, got {res}'
|
| 53 |
+
res = StrictVersion(v1)._cmp(v2)
|
| 54 |
+
assert res == wanted, f'cmp({v1}, {v2}) should be {wanted}, got {res}'
|
| 55 |
+
res = StrictVersion(v1)._cmp(object())
|
| 56 |
+
assert res is NotImplemented, (
|
| 57 |
+
f'cmp({v1}, {v2}) should be NotImplemented, got {res}'
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
def test_cmp(self):
|
| 61 |
+
versions = (
|
| 62 |
+
('1.5.1', '1.5.2b2', -1),
|
| 63 |
+
('161', '3.10a', 1),
|
| 64 |
+
('8.02', '8.02', 0),
|
| 65 |
+
('3.4j', '1996.07.12', -1),
|
| 66 |
+
('3.2.pl0', '3.1.1.6', 1),
|
| 67 |
+
('2g6', '11g', -1),
|
| 68 |
+
('0.960923', '2.2beta29', -1),
|
| 69 |
+
('1.13++', '5.5.kw', -1),
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
for v1, v2, wanted in versions:
|
| 73 |
+
res = LooseVersion(v1)._cmp(LooseVersion(v2))
|
| 74 |
+
assert res == wanted, f'cmp({v1}, {v2}) should be {wanted}, got {res}'
|
| 75 |
+
res = LooseVersion(v1)._cmp(v2)
|
| 76 |
+
assert res == wanted, f'cmp({v1}, {v2}) should be {wanted}, got {res}'
|
| 77 |
+
res = LooseVersion(v1)._cmp(object())
|
| 78 |
+
assert res is NotImplemented, (
|
| 79 |
+
f'cmp({v1}, {v2}) should be NotImplemented, got {res}'
|
| 80 |
+
)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/test_versionpredicate.py
ADDED
|
File without changes
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_distutils/tests/unix_compat.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
|
| 3 |
+
try:
|
| 4 |
+
import grp
|
| 5 |
+
import pwd
|
| 6 |
+
except ImportError:
|
| 7 |
+
grp = pwd = None
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
UNIX_ID_SUPPORT = grp and pwd
|
| 12 |
+
UID_0_SUPPORT = UNIX_ID_SUPPORT and sys.platform != "cygwin"
|
| 13 |
+
|
| 14 |
+
require_unix_id = pytest.mark.skipif(
|
| 15 |
+
not UNIX_ID_SUPPORT, reason="Requires grp and pwd support"
|
| 16 |
+
)
|
| 17 |
+
require_uid_0 = pytest.mark.skipif(not UID_0_SUPPORT, reason="Requires UID 0 support")
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/backports/tarfile/__init__.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/backports/tarfile/__main__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import main
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
if __name__ == '__main__':
|
| 5 |
+
main()
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/backports/tarfile/compat/__init__.py
ADDED
|
File without changes
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/backports/tarfile/compat/py38.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
if sys.version_info < (3, 9):
|
| 5 |
+
|
| 6 |
+
def removesuffix(self, suffix):
|
| 7 |
+
# suffix='' should not call self[:-0].
|
| 8 |
+
if suffix and self.endswith(suffix):
|
| 9 |
+
return self[: -len(suffix)]
|
| 10 |
+
else:
|
| 11 |
+
return self[:]
|
| 12 |
+
|
| 13 |
+
def removeprefix(self, prefix):
|
| 14 |
+
if self.startswith(prefix):
|
| 15 |
+
return self[len(prefix) :]
|
| 16 |
+
else:
|
| 17 |
+
return self[:]
|
| 18 |
+
else:
|
| 19 |
+
|
| 20 |
+
def removesuffix(self, suffix):
|
| 21 |
+
return self.removesuffix(suffix)
|
| 22 |
+
|
| 23 |
+
def removeprefix(self, prefix):
|
| 24 |
+
return self.removeprefix(prefix)
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/importlib_metadata-8.7.1.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
| 10 |
+
|
| 11 |
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
| 12 |
+
|
| 13 |
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
| 14 |
+
|
| 15 |
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
| 16 |
+
|
| 17 |
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
| 18 |
+
|
| 19 |
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
| 20 |
+
|
| 21 |
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
| 22 |
+
|
| 23 |
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
| 24 |
+
|
| 25 |
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
| 26 |
+
|
| 27 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
| 28 |
+
|
| 29 |
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
| 30 |
+
|
| 31 |
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
| 32 |
+
|
| 33 |
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
| 34 |
+
|
| 35 |
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
| 36 |
+
|
| 37 |
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
| 38 |
+
|
| 39 |
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
| 40 |
+
|
| 41 |
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
| 42 |
+
|
| 43 |
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
| 44 |
+
|
| 45 |
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
| 46 |
+
|
| 47 |
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
| 48 |
+
|
| 49 |
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
| 50 |
+
|
| 51 |
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
| 52 |
+
|
| 53 |
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
| 54 |
+
|
| 55 |
+
END OF TERMS AND CONDITIONS
|
| 56 |
+
|
| 57 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 58 |
+
|
| 59 |
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
| 60 |
+
|
| 61 |
+
Copyright 2025 [name of copyright owner]
|
| 62 |
+
|
| 63 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 64 |
+
you may not use this file except in compliance with the License.
|
| 65 |
+
You may obtain a copy of the License at
|
| 66 |
+
|
| 67 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 68 |
+
|
| 69 |
+
Unless required by applicable law or agreed to in writing, software
|
| 70 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 71 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 72 |
+
See the License for the specific language governing permissions and
|
| 73 |
+
limitations under the License.
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/importlib_metadata/compat/__init__.py
ADDED
|
File without changes
|
data/diffusion/.venv/lib/python3.11/site-packages/setuptools/_vendor/importlib_metadata/compat/py311.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pathlib
|
| 3 |
+
import sys
|
| 4 |
+
import types
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def wrap(path): # pragma: no cover
|
| 8 |
+
"""
|
| 9 |
+
Workaround for https://github.com/python/cpython/issues/84538
|
| 10 |
+
to add backward compatibility for walk_up=True.
|
| 11 |
+
An example affected package is dask-labextension, which uses
|
| 12 |
+
jupyter-packaging to install JupyterLab javascript files outside
|
| 13 |
+
of site-packages.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
def relative_to(root, *, walk_up=False):
|
| 17 |
+
return pathlib.Path(os.path.relpath(path, root))
|
| 18 |
+
|
| 19 |
+
return types.SimpleNamespace(relative_to=relative_to)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
relative_fix = wrap if sys.version_info < (3, 12) else lambda x: x
|