Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/_deprecation_warning.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/archive_util.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/build_meta.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/config.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/dep_util.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/installer.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/launch.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/version.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/windows_support.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/dist.py +1257 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/extension.py +240 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/fancy_getopt.py +457 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/log.py +77 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/sysconfig.py +601 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/text_file.py +286 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/util.py +548 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/__init__.py +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/ordered_set.py +488 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/__about__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/_manylinux.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/_musllinux.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/_structures.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/requirements.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/specifiers.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/tags.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/utils.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/version.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/pyparsing.py +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/alias.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/bdist_egg.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/bdist_rpm.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/build_clib.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/build_ext.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/build_py.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/develop.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/dist_info.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/easy_install.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/egg_info.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/install.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/install_egg_info.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/install_lib.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/install_scripts.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/py36compat.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/register.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/rotate.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/saveopts.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/sdist.cpython-310.pyc +0 -0
llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (8.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/_deprecation_warning.cpython-310.pyc
ADDED
Binary file (555 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/archive_util.cpython-310.pyc
ADDED
Binary file (5.85 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/build_meta.cpython-310.pyc
ADDED
Binary file (9.47 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/config.cpython-310.pyc
ADDED
Binary file (20.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/dep_util.cpython-310.pyc
ADDED
Binary file (862 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/installer.cpython-310.pyc
ADDED
Binary file (2.99 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/launch.cpython-310.pyc
ADDED
Binary file (912 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/version.cpython-310.pyc
ADDED
Binary file (329 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/__pycache__/windows_support.cpython-310.pyc
ADDED
Binary file (1.03 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/dist.py
ADDED
@@ -0,0 +1,1257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.dist
|
2 |
+
|
3 |
+
Provides the Distribution class, which represents the module distribution
|
4 |
+
being built/installed/distributed.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import sys
|
8 |
+
import os
|
9 |
+
import re
|
10 |
+
from email import message_from_file
|
11 |
+
|
12 |
+
try:
|
13 |
+
import warnings
|
14 |
+
except ImportError:
|
15 |
+
warnings = None
|
16 |
+
|
17 |
+
from distutils.errors import *
|
18 |
+
from distutils.fancy_getopt import FancyGetopt, translate_longopt
|
19 |
+
from distutils.util import check_environ, strtobool, rfc822_escape
|
20 |
+
from distutils import log
|
21 |
+
from distutils.debug import DEBUG
|
22 |
+
|
23 |
+
# Regex to define acceptable Distutils command names. This is not *quite*
|
24 |
+
# the same as a Python NAME -- I don't allow leading underscores. The fact
|
25 |
+
# that they're very similar is no coincidence; the default naming scheme is
|
26 |
+
# to look for a Python module named after the command.
|
27 |
+
command_re = re.compile(r'^[a-zA-Z]([a-zA-Z0-9_]*)$')
|
28 |
+
|
29 |
+
|
30 |
+
def _ensure_list(value, fieldname):
|
31 |
+
if isinstance(value, str):
|
32 |
+
# a string containing comma separated values is okay. It will
|
33 |
+
# be converted to a list by Distribution.finalize_options().
|
34 |
+
pass
|
35 |
+
elif not isinstance(value, list):
|
36 |
+
# passing a tuple or an iterator perhaps, warn and convert
|
37 |
+
typename = type(value).__name__
|
38 |
+
msg = "Warning: '{fieldname}' should be a list, got type '{typename}'"
|
39 |
+
msg = msg.format(**locals())
|
40 |
+
log.log(log.WARN, msg)
|
41 |
+
value = list(value)
|
42 |
+
return value
|
43 |
+
|
44 |
+
|
45 |
+
class Distribution:
|
46 |
+
"""The core of the Distutils. Most of the work hiding behind 'setup'
|
47 |
+
is really done within a Distribution instance, which farms the work out
|
48 |
+
to the Distutils commands specified on the command line.
|
49 |
+
|
50 |
+
Setup scripts will almost never instantiate Distribution directly,
|
51 |
+
unless the 'setup()' function is totally inadequate to their needs.
|
52 |
+
However, it is conceivable that a setup script might wish to subclass
|
53 |
+
Distribution for some specialized purpose, and then pass the subclass
|
54 |
+
to 'setup()' as the 'distclass' keyword argument. If so, it is
|
55 |
+
necessary to respect the expectations that 'setup' has of Distribution.
|
56 |
+
See the code for 'setup()', in core.py, for details.
|
57 |
+
"""
|
58 |
+
|
59 |
+
# 'global_options' describes the command-line options that may be
|
60 |
+
# supplied to the setup script prior to any actual commands.
|
61 |
+
# Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of
|
62 |
+
# these global options. This list should be kept to a bare minimum,
|
63 |
+
# since every global option is also valid as a command option -- and we
|
64 |
+
# don't want to pollute the commands with too many options that they
|
65 |
+
# have minimal control over.
|
66 |
+
# The fourth entry for verbose means that it can be repeated.
|
67 |
+
global_options = [
|
68 |
+
('verbose', 'v', "run verbosely (default)", 1),
|
69 |
+
('quiet', 'q', "run quietly (turns verbosity off)"),
|
70 |
+
('dry-run', 'n', "don't actually do anything"),
|
71 |
+
('help', 'h', "show detailed help message"),
|
72 |
+
('no-user-cfg', None,
|
73 |
+
'ignore pydistutils.cfg in your home directory'),
|
74 |
+
]
|
75 |
+
|
76 |
+
# 'common_usage' is a short (2-3 line) string describing the common
|
77 |
+
# usage of the setup script.
|
78 |
+
common_usage = """\
|
79 |
+
Common commands: (see '--help-commands' for more)
|
80 |
+
|
81 |
+
setup.py build will build the package underneath 'build/'
|
82 |
+
setup.py install will install the package
|
83 |
+
"""
|
84 |
+
|
85 |
+
# options that are not propagated to the commands
|
86 |
+
display_options = [
|
87 |
+
('help-commands', None,
|
88 |
+
"list all available commands"),
|
89 |
+
('name', None,
|
90 |
+
"print package name"),
|
91 |
+
('version', 'V',
|
92 |
+
"print package version"),
|
93 |
+
('fullname', None,
|
94 |
+
"print <package name>-<version>"),
|
95 |
+
('author', None,
|
96 |
+
"print the author's name"),
|
97 |
+
('author-email', None,
|
98 |
+
"print the author's email address"),
|
99 |
+
('maintainer', None,
|
100 |
+
"print the maintainer's name"),
|
101 |
+
('maintainer-email', None,
|
102 |
+
"print the maintainer's email address"),
|
103 |
+
('contact', None,
|
104 |
+
"print the maintainer's name if known, else the author's"),
|
105 |
+
('contact-email', None,
|
106 |
+
"print the maintainer's email address if known, else the author's"),
|
107 |
+
('url', None,
|
108 |
+
"print the URL for this package"),
|
109 |
+
('license', None,
|
110 |
+
"print the license of the package"),
|
111 |
+
('licence', None,
|
112 |
+
"alias for --license"),
|
113 |
+
('description', None,
|
114 |
+
"print the package description"),
|
115 |
+
('long-description', None,
|
116 |
+
"print the long package description"),
|
117 |
+
('platforms', None,
|
118 |
+
"print the list of platforms"),
|
119 |
+
('classifiers', None,
|
120 |
+
"print the list of classifiers"),
|
121 |
+
('keywords', None,
|
122 |
+
"print the list of keywords"),
|
123 |
+
('provides', None,
|
124 |
+
"print the list of packages/modules provided"),
|
125 |
+
('requires', None,
|
126 |
+
"print the list of packages/modules required"),
|
127 |
+
('obsoletes', None,
|
128 |
+
"print the list of packages/modules made obsolete")
|
129 |
+
]
|
130 |
+
display_option_names = [translate_longopt(x[0]) for x in display_options]
|
131 |
+
|
132 |
+
# negative options are options that exclude other options
|
133 |
+
negative_opt = {'quiet': 'verbose'}
|
134 |
+
|
135 |
+
# -- Creation/initialization methods -------------------------------
|
136 |
+
|
137 |
+
def __init__(self, attrs=None):
|
138 |
+
"""Construct a new Distribution instance: initialize all the
|
139 |
+
attributes of a Distribution, and then use 'attrs' (a dictionary
|
140 |
+
mapping attribute names to values) to assign some of those
|
141 |
+
attributes their "real" values. (Any attributes not mentioned in
|
142 |
+
'attrs' will be assigned to some null value: 0, None, an empty list
|
143 |
+
or dictionary, etc.) Most importantly, initialize the
|
144 |
+
'command_obj' attribute to the empty dictionary; this will be
|
145 |
+
filled in with real command objects by 'parse_command_line()'.
|
146 |
+
"""
|
147 |
+
|
148 |
+
# Default values for our command-line options
|
149 |
+
self.verbose = 1
|
150 |
+
self.dry_run = 0
|
151 |
+
self.help = 0
|
152 |
+
for attr in self.display_option_names:
|
153 |
+
setattr(self, attr, 0)
|
154 |
+
|
155 |
+
# Store the distribution meta-data (name, version, author, and so
|
156 |
+
# forth) in a separate object -- we're getting to have enough
|
157 |
+
# information here (and enough command-line options) that it's
|
158 |
+
# worth it. Also delegate 'get_XXX()' methods to the 'metadata'
|
159 |
+
# object in a sneaky and underhanded (but efficient!) way.
|
160 |
+
self.metadata = DistributionMetadata()
|
161 |
+
for basename in self.metadata._METHOD_BASENAMES:
|
162 |
+
method_name = "get_" + basename
|
163 |
+
setattr(self, method_name, getattr(self.metadata, method_name))
|
164 |
+
|
165 |
+
# 'cmdclass' maps command names to class objects, so we
|
166 |
+
# can 1) quickly figure out which class to instantiate when
|
167 |
+
# we need to create a new command object, and 2) have a way
|
168 |
+
# for the setup script to override command classes
|
169 |
+
self.cmdclass = {}
|
170 |
+
|
171 |
+
# 'command_packages' is a list of packages in which commands
|
172 |
+
# are searched for. The factory for command 'foo' is expected
|
173 |
+
# to be named 'foo' in the module 'foo' in one of the packages
|
174 |
+
# named here. This list is searched from the left; an error
|
175 |
+
# is raised if no named package provides the command being
|
176 |
+
# searched for. (Always access using get_command_packages().)
|
177 |
+
self.command_packages = None
|
178 |
+
|
179 |
+
# 'script_name' and 'script_args' are usually set to sys.argv[0]
|
180 |
+
# and sys.argv[1:], but they can be overridden when the caller is
|
181 |
+
# not necessarily a setup script run from the command-line.
|
182 |
+
self.script_name = None
|
183 |
+
self.script_args = None
|
184 |
+
|
185 |
+
# 'command_options' is where we store command options between
|
186 |
+
# parsing them (from config files, the command-line, etc.) and when
|
187 |
+
# they are actually needed -- ie. when the command in question is
|
188 |
+
# instantiated. It is a dictionary of dictionaries of 2-tuples:
|
189 |
+
# command_options = { command_name : { option : (source, value) } }
|
190 |
+
self.command_options = {}
|
191 |
+
|
192 |
+
# 'dist_files' is the list of (command, pyversion, file) that
|
193 |
+
# have been created by any dist commands run so far. This is
|
194 |
+
# filled regardless of whether the run is dry or not. pyversion
|
195 |
+
# gives sysconfig.get_python_version() if the dist file is
|
196 |
+
# specific to a Python version, 'any' if it is good for all
|
197 |
+
# Python versions on the target platform, and '' for a source
|
198 |
+
# file. pyversion should not be used to specify minimum or
|
199 |
+
# maximum required Python versions; use the metainfo for that
|
200 |
+
# instead.
|
201 |
+
self.dist_files = []
|
202 |
+
|
203 |
+
# These options are really the business of various commands, rather
|
204 |
+
# than of the Distribution itself. We provide aliases for them in
|
205 |
+
# Distribution as a convenience to the developer.
|
206 |
+
self.packages = None
|
207 |
+
self.package_data = {}
|
208 |
+
self.package_dir = None
|
209 |
+
self.py_modules = None
|
210 |
+
self.libraries = None
|
211 |
+
self.headers = None
|
212 |
+
self.ext_modules = None
|
213 |
+
self.ext_package = None
|
214 |
+
self.include_dirs = None
|
215 |
+
self.extra_path = None
|
216 |
+
self.scripts = None
|
217 |
+
self.data_files = None
|
218 |
+
self.password = ''
|
219 |
+
|
220 |
+
# And now initialize bookkeeping stuff that can't be supplied by
|
221 |
+
# the caller at all. 'command_obj' maps command names to
|
222 |
+
# Command instances -- that's how we enforce that every command
|
223 |
+
# class is a singleton.
|
224 |
+
self.command_obj = {}
|
225 |
+
|
226 |
+
# 'have_run' maps command names to boolean values; it keeps track
|
227 |
+
# of whether we have actually run a particular command, to make it
|
228 |
+
# cheap to "run" a command whenever we think we might need to -- if
|
229 |
+
# it's already been done, no need for expensive filesystem
|
230 |
+
# operations, we just check the 'have_run' dictionary and carry on.
|
231 |
+
# It's only safe to query 'have_run' for a command class that has
|
232 |
+
# been instantiated -- a false value will be inserted when the
|
233 |
+
# command object is created, and replaced with a true value when
|
234 |
+
# the command is successfully run. Thus it's probably best to use
|
235 |
+
# '.get()' rather than a straight lookup.
|
236 |
+
self.have_run = {}
|
237 |
+
|
238 |
+
# Now we'll use the attrs dictionary (ultimately, keyword args from
|
239 |
+
# the setup script) to possibly override any or all of these
|
240 |
+
# distribution options.
|
241 |
+
|
242 |
+
if attrs:
|
243 |
+
# Pull out the set of command options and work on them
|
244 |
+
# specifically. Note that this order guarantees that aliased
|
245 |
+
# command options will override any supplied redundantly
|
246 |
+
# through the general options dictionary.
|
247 |
+
options = attrs.get('options')
|
248 |
+
if options is not None:
|
249 |
+
del attrs['options']
|
250 |
+
for (command, cmd_options) in options.items():
|
251 |
+
opt_dict = self.get_option_dict(command)
|
252 |
+
for (opt, val) in cmd_options.items():
|
253 |
+
opt_dict[opt] = ("setup script", val)
|
254 |
+
|
255 |
+
if 'licence' in attrs:
|
256 |
+
attrs['license'] = attrs['licence']
|
257 |
+
del attrs['licence']
|
258 |
+
msg = "'licence' distribution option is deprecated; use 'license'"
|
259 |
+
if warnings is not None:
|
260 |
+
warnings.warn(msg)
|
261 |
+
else:
|
262 |
+
sys.stderr.write(msg + "\n")
|
263 |
+
|
264 |
+
# Now work on the rest of the attributes. Any attribute that's
|
265 |
+
# not already defined is invalid!
|
266 |
+
for (key, val) in attrs.items():
|
267 |
+
if hasattr(self.metadata, "set_" + key):
|
268 |
+
getattr(self.metadata, "set_" + key)(val)
|
269 |
+
elif hasattr(self.metadata, key):
|
270 |
+
setattr(self.metadata, key, val)
|
271 |
+
elif hasattr(self, key):
|
272 |
+
setattr(self, key, val)
|
273 |
+
else:
|
274 |
+
msg = "Unknown distribution option: %s" % repr(key)
|
275 |
+
warnings.warn(msg)
|
276 |
+
|
277 |
+
# no-user-cfg is handled before other command line args
|
278 |
+
# because other args override the config files, and this
|
279 |
+
# one is needed before we can load the config files.
|
280 |
+
# If attrs['script_args'] wasn't passed, assume false.
|
281 |
+
#
|
282 |
+
# This also make sure we just look at the global options
|
283 |
+
self.want_user_cfg = True
|
284 |
+
|
285 |
+
if self.script_args is not None:
|
286 |
+
for arg in self.script_args:
|
287 |
+
if not arg.startswith('-'):
|
288 |
+
break
|
289 |
+
if arg == '--no-user-cfg':
|
290 |
+
self.want_user_cfg = False
|
291 |
+
break
|
292 |
+
|
293 |
+
self.finalize_options()
|
294 |
+
|
295 |
+
def get_option_dict(self, command):
|
296 |
+
"""Get the option dictionary for a given command. If that
|
297 |
+
command's option dictionary hasn't been created yet, then create it
|
298 |
+
and return the new dictionary; otherwise, return the existing
|
299 |
+
option dictionary.
|
300 |
+
"""
|
301 |
+
dict = self.command_options.get(command)
|
302 |
+
if dict is None:
|
303 |
+
dict = self.command_options[command] = {}
|
304 |
+
return dict
|
305 |
+
|
306 |
+
def dump_option_dicts(self, header=None, commands=None, indent=""):
|
307 |
+
from pprint import pformat
|
308 |
+
|
309 |
+
if commands is None: # dump all command option dicts
|
310 |
+
commands = sorted(self.command_options.keys())
|
311 |
+
|
312 |
+
if header is not None:
|
313 |
+
self.announce(indent + header)
|
314 |
+
indent = indent + " "
|
315 |
+
|
316 |
+
if not commands:
|
317 |
+
self.announce(indent + "no commands known yet")
|
318 |
+
return
|
319 |
+
|
320 |
+
for cmd_name in commands:
|
321 |
+
opt_dict = self.command_options.get(cmd_name)
|
322 |
+
if opt_dict is None:
|
323 |
+
self.announce(indent +
|
324 |
+
"no option dict for '%s' command" % cmd_name)
|
325 |
+
else:
|
326 |
+
self.announce(indent +
|
327 |
+
"option dict for '%s' command:" % cmd_name)
|
328 |
+
out = pformat(opt_dict)
|
329 |
+
for line in out.split('\n'):
|
330 |
+
self.announce(indent + " " + line)
|
331 |
+
|
332 |
+
# -- Config file finding/parsing methods ---------------------------
|
333 |
+
|
334 |
+
def find_config_files(self):
|
335 |
+
"""Find as many configuration files as should be processed for this
|
336 |
+
platform, and return a list of filenames in the order in which they
|
337 |
+
should be parsed. The filenames returned are guaranteed to exist
|
338 |
+
(modulo nasty race conditions).
|
339 |
+
|
340 |
+
There are three possible config files: distutils.cfg in the
|
341 |
+
Distutils installation directory (ie. where the top-level
|
342 |
+
Distutils __inst__.py file lives), a file in the user's home
|
343 |
+
directory named .pydistutils.cfg on Unix and pydistutils.cfg
|
344 |
+
on Windows/Mac; and setup.cfg in the current directory.
|
345 |
+
|
346 |
+
The file in the user's home directory can be disabled with the
|
347 |
+
--no-user-cfg option.
|
348 |
+
"""
|
349 |
+
files = []
|
350 |
+
check_environ()
|
351 |
+
|
352 |
+
# Where to look for the system-wide Distutils config file
|
353 |
+
sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
|
354 |
+
|
355 |
+
# Look for the system config file
|
356 |
+
sys_file = os.path.join(sys_dir, "distutils.cfg")
|
357 |
+
if os.path.isfile(sys_file):
|
358 |
+
files.append(sys_file)
|
359 |
+
|
360 |
+
# What to call the per-user config file
|
361 |
+
if os.name == 'posix':
|
362 |
+
user_filename = ".pydistutils.cfg"
|
363 |
+
else:
|
364 |
+
user_filename = "pydistutils.cfg"
|
365 |
+
|
366 |
+
# And look for the user config file
|
367 |
+
if self.want_user_cfg:
|
368 |
+
user_file = os.path.join(os.path.expanduser('~'), user_filename)
|
369 |
+
if os.path.isfile(user_file):
|
370 |
+
files.append(user_file)
|
371 |
+
|
372 |
+
# All platforms support local setup.cfg
|
373 |
+
local_file = "setup.cfg"
|
374 |
+
if os.path.isfile(local_file):
|
375 |
+
files.append(local_file)
|
376 |
+
|
377 |
+
if DEBUG:
|
378 |
+
self.announce("using config files: %s" % ', '.join(files))
|
379 |
+
|
380 |
+
return files
|
381 |
+
|
382 |
+
def parse_config_files(self, filenames=None):
|
383 |
+
from configparser import ConfigParser
|
384 |
+
|
385 |
+
# Ignore install directory options if we have a venv
|
386 |
+
if sys.prefix != sys.base_prefix:
|
387 |
+
ignore_options = [
|
388 |
+
'install-base', 'install-platbase', 'install-lib',
|
389 |
+
'install-platlib', 'install-purelib', 'install-headers',
|
390 |
+
'install-scripts', 'install-data', 'prefix', 'exec-prefix',
|
391 |
+
'home', 'user', 'root']
|
392 |
+
else:
|
393 |
+
ignore_options = []
|
394 |
+
|
395 |
+
ignore_options = frozenset(ignore_options)
|
396 |
+
|
397 |
+
if filenames is None:
|
398 |
+
filenames = self.find_config_files()
|
399 |
+
|
400 |
+
if DEBUG:
|
401 |
+
self.announce("Distribution.parse_config_files():")
|
402 |
+
|
403 |
+
parser = ConfigParser()
|
404 |
+
for filename in filenames:
|
405 |
+
if DEBUG:
|
406 |
+
self.announce(" reading %s" % filename)
|
407 |
+
parser.read(filename)
|
408 |
+
for section in parser.sections():
|
409 |
+
options = parser.options(section)
|
410 |
+
opt_dict = self.get_option_dict(section)
|
411 |
+
|
412 |
+
for opt in options:
|
413 |
+
if opt != '__name__' and opt not in ignore_options:
|
414 |
+
val = parser.get(section,opt)
|
415 |
+
opt = opt.replace('-', '_')
|
416 |
+
opt_dict[opt] = (filename, val)
|
417 |
+
|
418 |
+
# Make the ConfigParser forget everything (so we retain
|
419 |
+
# the original filenames that options come from)
|
420 |
+
parser.__init__()
|
421 |
+
|
422 |
+
# If there was a "global" section in the config file, use it
|
423 |
+
# to set Distribution options.
|
424 |
+
|
425 |
+
if 'global' in self.command_options:
|
426 |
+
for (opt, (src, val)) in self.command_options['global'].items():
|
427 |
+
alias = self.negative_opt.get(opt)
|
428 |
+
try:
|
429 |
+
if alias:
|
430 |
+
setattr(self, alias, not strtobool(val))
|
431 |
+
elif opt in ('verbose', 'dry_run'): # ugh!
|
432 |
+
setattr(self, opt, strtobool(val))
|
433 |
+
else:
|
434 |
+
setattr(self, opt, val)
|
435 |
+
except ValueError as msg:
|
436 |
+
raise DistutilsOptionError(msg)
|
437 |
+
|
438 |
+
# -- Command-line parsing methods ----------------------------------
|
439 |
+
|
440 |
+
def parse_command_line(self):
|
441 |
+
"""Parse the setup script's command line, taken from the
|
442 |
+
'script_args' instance attribute (which defaults to 'sys.argv[1:]'
|
443 |
+
-- see 'setup()' in core.py). This list is first processed for
|
444 |
+
"global options" -- options that set attributes of the Distribution
|
445 |
+
instance. Then, it is alternately scanned for Distutils commands
|
446 |
+
and options for that command. Each new command terminates the
|
447 |
+
options for the previous command. The allowed options for a
|
448 |
+
command are determined by the 'user_options' attribute of the
|
449 |
+
command class -- thus, we have to be able to load command classes
|
450 |
+
in order to parse the command line. Any error in that 'options'
|
451 |
+
attribute raises DistutilsGetoptError; any error on the
|
452 |
+
command-line raises DistutilsArgError. If no Distutils commands
|
453 |
+
were found on the command line, raises DistutilsArgError. Return
|
454 |
+
true if command-line was successfully parsed and we should carry
|
455 |
+
on with executing commands; false if no errors but we shouldn't
|
456 |
+
execute commands (currently, this only happens if user asks for
|
457 |
+
help).
|
458 |
+
"""
|
459 |
+
#
|
460 |
+
# We now have enough information to show the Macintosh dialog
|
461 |
+
# that allows the user to interactively specify the "command line".
|
462 |
+
#
|
463 |
+
toplevel_options = self._get_toplevel_options()
|
464 |
+
|
465 |
+
# We have to parse the command line a bit at a time -- global
|
466 |
+
# options, then the first command, then its options, and so on --
|
467 |
+
# because each command will be handled by a different class, and
|
468 |
+
# the options that are valid for a particular class aren't known
|
469 |
+
# until we have loaded the command class, which doesn't happen
|
470 |
+
# until we know what the command is.
|
471 |
+
|
472 |
+
self.commands = []
|
473 |
+
parser = FancyGetopt(toplevel_options + self.display_options)
|
474 |
+
parser.set_negative_aliases(self.negative_opt)
|
475 |
+
parser.set_aliases({'licence': 'license'})
|
476 |
+
args = parser.getopt(args=self.script_args, object=self)
|
477 |
+
option_order = parser.get_option_order()
|
478 |
+
log.set_verbosity(self.verbose)
|
479 |
+
|
480 |
+
# for display options we return immediately
|
481 |
+
if self.handle_display_options(option_order):
|
482 |
+
return
|
483 |
+
while args:
|
484 |
+
args = self._parse_command_opts(parser, args)
|
485 |
+
if args is None: # user asked for help (and got it)
|
486 |
+
return
|
487 |
+
|
488 |
+
# Handle the cases of --help as a "global" option, ie.
|
489 |
+
# "setup.py --help" and "setup.py --help command ...". For the
|
490 |
+
# former, we show global options (--verbose, --dry-run, etc.)
|
491 |
+
# and display-only options (--name, --version, etc.); for the
|
492 |
+
# latter, we omit the display-only options and show help for
|
493 |
+
# each command listed on the command line.
|
494 |
+
if self.help:
|
495 |
+
self._show_help(parser,
|
496 |
+
display_options=len(self.commands) == 0,
|
497 |
+
commands=self.commands)
|
498 |
+
return
|
499 |
+
|
500 |
+
# Oops, no commands found -- an end-user error
|
501 |
+
if not self.commands:
|
502 |
+
raise DistutilsArgError("no commands supplied")
|
503 |
+
|
504 |
+
# All is well: return true
|
505 |
+
return True
|
506 |
+
|
507 |
+
def _get_toplevel_options(self):
|
508 |
+
"""Return the non-display options recognized at the top level.
|
509 |
+
|
510 |
+
This includes options that are recognized *only* at the top
|
511 |
+
level as well as options recognized for commands.
|
512 |
+
"""
|
513 |
+
return self.global_options + [
|
514 |
+
("command-packages=", None,
|
515 |
+
"list of packages that provide distutils commands"),
|
516 |
+
]
|
517 |
+
|
518 |
+
def _parse_command_opts(self, parser, args):
|
519 |
+
"""Parse the command-line options for a single command.
|
520 |
+
'parser' must be a FancyGetopt instance; 'args' must be the list
|
521 |
+
of arguments, starting with the current command (whose options
|
522 |
+
we are about to parse). Returns a new version of 'args' with
|
523 |
+
the next command at the front of the list; will be the empty
|
524 |
+
list if there are no more commands on the command line. Returns
|
525 |
+
None if the user asked for help on this command.
|
526 |
+
"""
|
527 |
+
# late import because of mutual dependence between these modules
|
528 |
+
from distutils.cmd import Command
|
529 |
+
|
530 |
+
# Pull the current command from the head of the command line
|
531 |
+
command = args[0]
|
532 |
+
if not command_re.match(command):
|
533 |
+
raise SystemExit("invalid command name '%s'" % command)
|
534 |
+
self.commands.append(command)
|
535 |
+
|
536 |
+
# Dig up the command class that implements this command, so we
|
537 |
+
# 1) know that it's a valid command, and 2) know which options
|
538 |
+
# it takes.
|
539 |
+
try:
|
540 |
+
cmd_class = self.get_command_class(command)
|
541 |
+
except DistutilsModuleError as msg:
|
542 |
+
raise DistutilsArgError(msg)
|
543 |
+
|
544 |
+
# Require that the command class be derived from Command -- want
|
545 |
+
# to be sure that the basic "command" interface is implemented.
|
546 |
+
if not issubclass(cmd_class, Command):
|
547 |
+
raise DistutilsClassError(
|
548 |
+
"command class %s must subclass Command" % cmd_class)
|
549 |
+
|
550 |
+
# Also make sure that the command object provides a list of its
|
551 |
+
# known options.
|
552 |
+
if not (hasattr(cmd_class, 'user_options') and
|
553 |
+
isinstance(cmd_class.user_options, list)):
|
554 |
+
msg = ("command class %s must provide "
|
555 |
+
"'user_options' attribute (a list of tuples)")
|
556 |
+
raise DistutilsClassError(msg % cmd_class)
|
557 |
+
|
558 |
+
# If the command class has a list of negative alias options,
|
559 |
+
# merge it in with the global negative aliases.
|
560 |
+
negative_opt = self.negative_opt
|
561 |
+
if hasattr(cmd_class, 'negative_opt'):
|
562 |
+
negative_opt = negative_opt.copy()
|
563 |
+
negative_opt.update(cmd_class.negative_opt)
|
564 |
+
|
565 |
+
# Check for help_options in command class. They have a different
|
566 |
+
# format (tuple of four) so we need to preprocess them here.
|
567 |
+
if (hasattr(cmd_class, 'help_options') and
|
568 |
+
isinstance(cmd_class.help_options, list)):
|
569 |
+
help_options = fix_help_options(cmd_class.help_options)
|
570 |
+
else:
|
571 |
+
help_options = []
|
572 |
+
|
573 |
+
# All commands support the global options too, just by adding
|
574 |
+
# in 'global_options'.
|
575 |
+
parser.set_option_table(self.global_options +
|
576 |
+
cmd_class.user_options +
|
577 |
+
help_options)
|
578 |
+
parser.set_negative_aliases(negative_opt)
|
579 |
+
(args, opts) = parser.getopt(args[1:])
|
580 |
+
if hasattr(opts, 'help') and opts.help:
|
581 |
+
self._show_help(parser, display_options=0, commands=[cmd_class])
|
582 |
+
return
|
583 |
+
|
584 |
+
if (hasattr(cmd_class, 'help_options') and
|
585 |
+
isinstance(cmd_class.help_options, list)):
|
586 |
+
help_option_found=0
|
587 |
+
for (help_option, short, desc, func) in cmd_class.help_options:
|
588 |
+
if hasattr(opts, parser.get_attr_name(help_option)):
|
589 |
+
help_option_found=1
|
590 |
+
if callable(func):
|
591 |
+
func()
|
592 |
+
else:
|
593 |
+
raise DistutilsClassError(
|
594 |
+
"invalid help function %r for help option '%s': "
|
595 |
+
"must be a callable object (function, etc.)"
|
596 |
+
% (func, help_option))
|
597 |
+
|
598 |
+
if help_option_found:
|
599 |
+
return
|
600 |
+
|
601 |
+
# Put the options from the command-line into their official
|
602 |
+
# holding pen, the 'command_options' dictionary.
|
603 |
+
opt_dict = self.get_option_dict(command)
|
604 |
+
for (name, value) in vars(opts).items():
|
605 |
+
opt_dict[name] = ("command line", value)
|
606 |
+
|
607 |
+
return args
|
608 |
+
|
609 |
+
def finalize_options(self):
|
610 |
+
"""Set final values for all the options on the Distribution
|
611 |
+
instance, analogous to the .finalize_options() method of Command
|
612 |
+
objects.
|
613 |
+
"""
|
614 |
+
for attr in ('keywords', 'platforms'):
|
615 |
+
value = getattr(self.metadata, attr)
|
616 |
+
if value is None:
|
617 |
+
continue
|
618 |
+
if isinstance(value, str):
|
619 |
+
value = [elm.strip() for elm in value.split(',')]
|
620 |
+
setattr(self.metadata, attr, value)
|
621 |
+
|
622 |
+
def _show_help(self, parser, global_options=1, display_options=1,
|
623 |
+
commands=[]):
|
624 |
+
"""Show help for the setup script command-line in the form of
|
625 |
+
several lists of command-line options. 'parser' should be a
|
626 |
+
FancyGetopt instance; do not expect it to be returned in the
|
627 |
+
same state, as its option table will be reset to make it
|
628 |
+
generate the correct help text.
|
629 |
+
|
630 |
+
If 'global_options' is true, lists the global options:
|
631 |
+
--verbose, --dry-run, etc. If 'display_options' is true, lists
|
632 |
+
the "display-only" options: --name, --version, etc. Finally,
|
633 |
+
lists per-command help for every command name or command class
|
634 |
+
in 'commands'.
|
635 |
+
"""
|
636 |
+
# late import because of mutual dependence between these modules
|
637 |
+
from distutils.core import gen_usage
|
638 |
+
from distutils.cmd import Command
|
639 |
+
|
640 |
+
if global_options:
|
641 |
+
if display_options:
|
642 |
+
options = self._get_toplevel_options()
|
643 |
+
else:
|
644 |
+
options = self.global_options
|
645 |
+
parser.set_option_table(options)
|
646 |
+
parser.print_help(self.common_usage + "\nGlobal options:")
|
647 |
+
print('')
|
648 |
+
|
649 |
+
if display_options:
|
650 |
+
parser.set_option_table(self.display_options)
|
651 |
+
parser.print_help(
|
652 |
+
"Information display options (just display " +
|
653 |
+
"information, ignore any commands)")
|
654 |
+
print('')
|
655 |
+
|
656 |
+
for command in self.commands:
|
657 |
+
if isinstance(command, type) and issubclass(command, Command):
|
658 |
+
klass = command
|
659 |
+
else:
|
660 |
+
klass = self.get_command_class(command)
|
661 |
+
if (hasattr(klass, 'help_options') and
|
662 |
+
isinstance(klass.help_options, list)):
|
663 |
+
parser.set_option_table(klass.user_options +
|
664 |
+
fix_help_options(klass.help_options))
|
665 |
+
else:
|
666 |
+
parser.set_option_table(klass.user_options)
|
667 |
+
parser.print_help("Options for '%s' command:" % klass.__name__)
|
668 |
+
print('')
|
669 |
+
|
670 |
+
print(gen_usage(self.script_name))
|
671 |
+
|
672 |
+
def handle_display_options(self, option_order):
|
673 |
+
"""If there were any non-global "display-only" options
|
674 |
+
(--help-commands or the metadata display options) on the command
|
675 |
+
line, display the requested info and return true; else return
|
676 |
+
false.
|
677 |
+
"""
|
678 |
+
from distutils.core import gen_usage
|
679 |
+
|
680 |
+
# User just wants a list of commands -- we'll print it out and stop
|
681 |
+
# processing now (ie. if they ran "setup --help-commands foo bar",
|
682 |
+
# we ignore "foo bar").
|
683 |
+
if self.help_commands:
|
684 |
+
self.print_commands()
|
685 |
+
print('')
|
686 |
+
print(gen_usage(self.script_name))
|
687 |
+
return 1
|
688 |
+
|
689 |
+
# If user supplied any of the "display metadata" options, then
|
690 |
+
# display that metadata in the order in which the user supplied the
|
691 |
+
# metadata options.
|
692 |
+
any_display_options = 0
|
693 |
+
is_display_option = {}
|
694 |
+
for option in self.display_options:
|
695 |
+
is_display_option[option[0]] = 1
|
696 |
+
|
697 |
+
for (opt, val) in option_order:
|
698 |
+
if val and is_display_option.get(opt):
|
699 |
+
opt = translate_longopt(opt)
|
700 |
+
value = getattr(self.metadata, "get_"+opt)()
|
701 |
+
if opt in ['keywords', 'platforms']:
|
702 |
+
print(','.join(value))
|
703 |
+
elif opt in ('classifiers', 'provides', 'requires',
|
704 |
+
'obsoletes'):
|
705 |
+
print('\n'.join(value))
|
706 |
+
else:
|
707 |
+
print(value)
|
708 |
+
any_display_options = 1
|
709 |
+
|
710 |
+
return any_display_options
|
711 |
+
|
712 |
+
def print_command_list(self, commands, header, max_length):
|
713 |
+
"""Print a subset of the list of all commands -- used by
|
714 |
+
'print_commands()'.
|
715 |
+
"""
|
716 |
+
print(header + ":")
|
717 |
+
|
718 |
+
for cmd in commands:
|
719 |
+
klass = self.cmdclass.get(cmd)
|
720 |
+
if not klass:
|
721 |
+
klass = self.get_command_class(cmd)
|
722 |
+
try:
|
723 |
+
description = klass.description
|
724 |
+
except AttributeError:
|
725 |
+
description = "(no description available)"
|
726 |
+
|
727 |
+
print(" %-*s %s" % (max_length, cmd, description))
|
728 |
+
|
729 |
+
def print_commands(self):
|
730 |
+
"""Print out a help message listing all available commands with a
|
731 |
+
description of each. The list is divided into "standard commands"
|
732 |
+
(listed in distutils.command.__all__) and "extra commands"
|
733 |
+
(mentioned in self.cmdclass, but not a standard command). The
|
734 |
+
descriptions come from the command class attribute
|
735 |
+
'description'.
|
736 |
+
"""
|
737 |
+
import distutils.command
|
738 |
+
std_commands = distutils.command.__all__
|
739 |
+
is_std = {}
|
740 |
+
for cmd in std_commands:
|
741 |
+
is_std[cmd] = 1
|
742 |
+
|
743 |
+
extra_commands = []
|
744 |
+
for cmd in self.cmdclass.keys():
|
745 |
+
if not is_std.get(cmd):
|
746 |
+
extra_commands.append(cmd)
|
747 |
+
|
748 |
+
max_length = 0
|
749 |
+
for cmd in (std_commands + extra_commands):
|
750 |
+
if len(cmd) > max_length:
|
751 |
+
max_length = len(cmd)
|
752 |
+
|
753 |
+
self.print_command_list(std_commands,
|
754 |
+
"Standard commands",
|
755 |
+
max_length)
|
756 |
+
if extra_commands:
|
757 |
+
print()
|
758 |
+
self.print_command_list(extra_commands,
|
759 |
+
"Extra commands",
|
760 |
+
max_length)
|
761 |
+
|
762 |
+
def get_command_list(self):
|
763 |
+
"""Get a list of (command, description) tuples.
|
764 |
+
The list is divided into "standard commands" (listed in
|
765 |
+
distutils.command.__all__) and "extra commands" (mentioned in
|
766 |
+
self.cmdclass, but not a standard command). The descriptions come
|
767 |
+
from the command class attribute 'description'.
|
768 |
+
"""
|
769 |
+
# Currently this is only used on Mac OS, for the Mac-only GUI
|
770 |
+
# Distutils interface (by Jack Jansen)
|
771 |
+
import distutils.command
|
772 |
+
std_commands = distutils.command.__all__
|
773 |
+
is_std = {}
|
774 |
+
for cmd in std_commands:
|
775 |
+
is_std[cmd] = 1
|
776 |
+
|
777 |
+
extra_commands = []
|
778 |
+
for cmd in self.cmdclass.keys():
|
779 |
+
if not is_std.get(cmd):
|
780 |
+
extra_commands.append(cmd)
|
781 |
+
|
782 |
+
rv = []
|
783 |
+
for cmd in (std_commands + extra_commands):
|
784 |
+
klass = self.cmdclass.get(cmd)
|
785 |
+
if not klass:
|
786 |
+
klass = self.get_command_class(cmd)
|
787 |
+
try:
|
788 |
+
description = klass.description
|
789 |
+
except AttributeError:
|
790 |
+
description = "(no description available)"
|
791 |
+
rv.append((cmd, description))
|
792 |
+
return rv
|
793 |
+
|
794 |
+
# -- Command class/object methods ----------------------------------
|
795 |
+
|
796 |
+
def get_command_packages(self):
|
797 |
+
"""Return a list of packages from which commands are loaded."""
|
798 |
+
pkgs = self.command_packages
|
799 |
+
if not isinstance(pkgs, list):
|
800 |
+
if pkgs is None:
|
801 |
+
pkgs = ''
|
802 |
+
pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != '']
|
803 |
+
if "distutils.command" not in pkgs:
|
804 |
+
pkgs.insert(0, "distutils.command")
|
805 |
+
self.command_packages = pkgs
|
806 |
+
return pkgs
|
807 |
+
|
808 |
+
def get_command_class(self, command):
|
809 |
+
"""Return the class that implements the Distutils command named by
|
810 |
+
'command'. First we check the 'cmdclass' dictionary; if the
|
811 |
+
command is mentioned there, we fetch the class object from the
|
812 |
+
dictionary and return it. Otherwise we load the command module
|
813 |
+
("distutils.command." + command) and fetch the command class from
|
814 |
+
the module. The loaded class is also stored in 'cmdclass'
|
815 |
+
to speed future calls to 'get_command_class()'.
|
816 |
+
|
817 |
+
Raises DistutilsModuleError if the expected module could not be
|
818 |
+
found, or if that module does not define the expected class.
|
819 |
+
"""
|
820 |
+
klass = self.cmdclass.get(command)
|
821 |
+
if klass:
|
822 |
+
return klass
|
823 |
+
|
824 |
+
for pkgname in self.get_command_packages():
|
825 |
+
module_name = "%s.%s" % (pkgname, command)
|
826 |
+
klass_name = command
|
827 |
+
|
828 |
+
try:
|
829 |
+
__import__(module_name)
|
830 |
+
module = sys.modules[module_name]
|
831 |
+
except ImportError:
|
832 |
+
continue
|
833 |
+
|
834 |
+
try:
|
835 |
+
klass = getattr(module, klass_name)
|
836 |
+
except AttributeError:
|
837 |
+
raise DistutilsModuleError(
|
838 |
+
"invalid command '%s' (no class '%s' in module '%s')"
|
839 |
+
% (command, klass_name, module_name))
|
840 |
+
|
841 |
+
self.cmdclass[command] = klass
|
842 |
+
return klass
|
843 |
+
|
844 |
+
raise DistutilsModuleError("invalid command '%s'" % command)
|
845 |
+
|
846 |
+
def get_command_obj(self, command, create=1):
|
847 |
+
"""Return the command object for 'command'. Normally this object
|
848 |
+
is cached on a previous call to 'get_command_obj()'; if no command
|
849 |
+
object for 'command' is in the cache, then we either create and
|
850 |
+
return it (if 'create' is true) or return None.
|
851 |
+
"""
|
852 |
+
cmd_obj = self.command_obj.get(command)
|
853 |
+
if not cmd_obj and create:
|
854 |
+
if DEBUG:
|
855 |
+
self.announce("Distribution.get_command_obj(): "
|
856 |
+
"creating '%s' command object" % command)
|
857 |
+
|
858 |
+
klass = self.get_command_class(command)
|
859 |
+
cmd_obj = self.command_obj[command] = klass(self)
|
860 |
+
self.have_run[command] = 0
|
861 |
+
|
862 |
+
# Set any options that were supplied in config files
|
863 |
+
# or on the command line. (NB. support for error
|
864 |
+
# reporting is lame here: any errors aren't reported
|
865 |
+
# until 'finalize_options()' is called, which means
|
866 |
+
# we won't report the source of the error.)
|
867 |
+
options = self.command_options.get(command)
|
868 |
+
if options:
|
869 |
+
self._set_command_options(cmd_obj, options)
|
870 |
+
|
871 |
+
return cmd_obj
|
872 |
+
|
873 |
+
def _set_command_options(self, command_obj, option_dict=None):
|
874 |
+
"""Set the options for 'command_obj' from 'option_dict'. Basically
|
875 |
+
this means copying elements of a dictionary ('option_dict') to
|
876 |
+
attributes of an instance ('command').
|
877 |
+
|
878 |
+
'command_obj' must be a Command instance. If 'option_dict' is not
|
879 |
+
supplied, uses the standard option dictionary for this command
|
880 |
+
(from 'self.command_options').
|
881 |
+
"""
|
882 |
+
command_name = command_obj.get_command_name()
|
883 |
+
if option_dict is None:
|
884 |
+
option_dict = self.get_option_dict(command_name)
|
885 |
+
|
886 |
+
if DEBUG:
|
887 |
+
self.announce(" setting options for '%s' command:" % command_name)
|
888 |
+
for (option, (source, value)) in option_dict.items():
|
889 |
+
if DEBUG:
|
890 |
+
self.announce(" %s = %s (from %s)" % (option, value,
|
891 |
+
source))
|
892 |
+
try:
|
893 |
+
bool_opts = [translate_longopt(o)
|
894 |
+
for o in command_obj.boolean_options]
|
895 |
+
except AttributeError:
|
896 |
+
bool_opts = []
|
897 |
+
try:
|
898 |
+
neg_opt = command_obj.negative_opt
|
899 |
+
except AttributeError:
|
900 |
+
neg_opt = {}
|
901 |
+
|
902 |
+
try:
|
903 |
+
is_string = isinstance(value, str)
|
904 |
+
if option in neg_opt and is_string:
|
905 |
+
setattr(command_obj, neg_opt[option], not strtobool(value))
|
906 |
+
elif option in bool_opts and is_string:
|
907 |
+
setattr(command_obj, option, strtobool(value))
|
908 |
+
elif hasattr(command_obj, option):
|
909 |
+
setattr(command_obj, option, value)
|
910 |
+
else:
|
911 |
+
raise DistutilsOptionError(
|
912 |
+
"error in %s: command '%s' has no such option '%s'"
|
913 |
+
% (source, command_name, option))
|
914 |
+
except ValueError as msg:
|
915 |
+
raise DistutilsOptionError(msg)
|
916 |
+
|
917 |
+
def reinitialize_command(self, command, reinit_subcommands=0):
|
918 |
+
"""Reinitializes a command to the state it was in when first
|
919 |
+
returned by 'get_command_obj()': ie., initialized but not yet
|
920 |
+
finalized. This provides the opportunity to sneak option
|
921 |
+
values in programmatically, overriding or supplementing
|
922 |
+
user-supplied values from the config files and command line.
|
923 |
+
You'll have to re-finalize the command object (by calling
|
924 |
+
'finalize_options()' or 'ensure_finalized()') before using it for
|
925 |
+
real.
|
926 |
+
|
927 |
+
'command' should be a command name (string) or command object. If
|
928 |
+
'reinit_subcommands' is true, also reinitializes the command's
|
929 |
+
sub-commands, as declared by the 'sub_commands' class attribute (if
|
930 |
+
it has one). See the "install" command for an example. Only
|
931 |
+
reinitializes the sub-commands that actually matter, ie. those
|
932 |
+
whose test predicates return true.
|
933 |
+
|
934 |
+
Returns the reinitialized command object.
|
935 |
+
"""
|
936 |
+
from distutils.cmd import Command
|
937 |
+
if not isinstance(command, Command):
|
938 |
+
command_name = command
|
939 |
+
command = self.get_command_obj(command_name)
|
940 |
+
else:
|
941 |
+
command_name = command.get_command_name()
|
942 |
+
|
943 |
+
if not command.finalized:
|
944 |
+
return command
|
945 |
+
command.initialize_options()
|
946 |
+
command.finalized = 0
|
947 |
+
self.have_run[command_name] = 0
|
948 |
+
self._set_command_options(command)
|
949 |
+
|
950 |
+
if reinit_subcommands:
|
951 |
+
for sub in command.get_sub_commands():
|
952 |
+
self.reinitialize_command(sub, reinit_subcommands)
|
953 |
+
|
954 |
+
return command
|
955 |
+
|
956 |
+
# -- Methods that operate on the Distribution ----------------------
|
957 |
+
|
958 |
+
def announce(self, msg, level=log.INFO):
|
959 |
+
log.log(level, msg)
|
960 |
+
|
961 |
+
def run_commands(self):
|
962 |
+
"""Run each command that was seen on the setup script command line.
|
963 |
+
Uses the list of commands found and cache of command objects
|
964 |
+
created by 'get_command_obj()'.
|
965 |
+
"""
|
966 |
+
for cmd in self.commands:
|
967 |
+
self.run_command(cmd)
|
968 |
+
|
969 |
+
# -- Methods that operate on its Commands --------------------------
|
970 |
+
|
971 |
+
def run_command(self, command):
|
972 |
+
"""Do whatever it takes to run a command (including nothing at all,
|
973 |
+
if the command has already been run). Specifically: if we have
|
974 |
+
already created and run the command named by 'command', return
|
975 |
+
silently without doing anything. If the command named by 'command'
|
976 |
+
doesn't even have a command object yet, create one. Then invoke
|
977 |
+
'run()' on that command object (or an existing one).
|
978 |
+
"""
|
979 |
+
# Already been here, done that? then return silently.
|
980 |
+
if self.have_run.get(command):
|
981 |
+
return
|
982 |
+
|
983 |
+
log.info("running %s", command)
|
984 |
+
cmd_obj = self.get_command_obj(command)
|
985 |
+
cmd_obj.ensure_finalized()
|
986 |
+
cmd_obj.run()
|
987 |
+
self.have_run[command] = 1
|
988 |
+
|
989 |
+
# -- Distribution query methods ------------------------------------
|
990 |
+
|
991 |
+
def has_pure_modules(self):
|
992 |
+
return len(self.packages or self.py_modules or []) > 0
|
993 |
+
|
994 |
+
def has_ext_modules(self):
|
995 |
+
return self.ext_modules and len(self.ext_modules) > 0
|
996 |
+
|
997 |
+
def has_c_libraries(self):
|
998 |
+
return self.libraries and len(self.libraries) > 0
|
999 |
+
|
1000 |
+
def has_modules(self):
|
1001 |
+
return self.has_pure_modules() or self.has_ext_modules()
|
1002 |
+
|
1003 |
+
def has_headers(self):
|
1004 |
+
return self.headers and len(self.headers) > 0
|
1005 |
+
|
1006 |
+
def has_scripts(self):
|
1007 |
+
return self.scripts and len(self.scripts) > 0
|
1008 |
+
|
1009 |
+
def has_data_files(self):
|
1010 |
+
return self.data_files and len(self.data_files) > 0
|
1011 |
+
|
1012 |
+
def is_pure(self):
|
1013 |
+
return (self.has_pure_modules() and
|
1014 |
+
not self.has_ext_modules() and
|
1015 |
+
not self.has_c_libraries())
|
1016 |
+
|
1017 |
+
# -- Metadata query methods ----------------------------------------
|
1018 |
+
|
1019 |
+
# If you're looking for 'get_name()', 'get_version()', and so forth,
|
1020 |
+
# they are defined in a sneaky way: the constructor binds self.get_XXX
|
1021 |
+
# to self.metadata.get_XXX. The actual code is in the
|
1022 |
+
# DistributionMetadata class, below.
|
1023 |
+
|
1024 |
+
class DistributionMetadata:
|
1025 |
+
"""Dummy class to hold the distribution meta-data: name, version,
|
1026 |
+
author, and so forth.
|
1027 |
+
"""
|
1028 |
+
|
1029 |
+
_METHOD_BASENAMES = ("name", "version", "author", "author_email",
|
1030 |
+
"maintainer", "maintainer_email", "url",
|
1031 |
+
"license", "description", "long_description",
|
1032 |
+
"keywords", "platforms", "fullname", "contact",
|
1033 |
+
"contact_email", "classifiers", "download_url",
|
1034 |
+
# PEP 314
|
1035 |
+
"provides", "requires", "obsoletes",
|
1036 |
+
)
|
1037 |
+
|
1038 |
+
def __init__(self, path=None):
|
1039 |
+
if path is not None:
|
1040 |
+
self.read_pkg_file(open(path))
|
1041 |
+
else:
|
1042 |
+
self.name = None
|
1043 |
+
self.version = None
|
1044 |
+
self.author = None
|
1045 |
+
self.author_email = None
|
1046 |
+
self.maintainer = None
|
1047 |
+
self.maintainer_email = None
|
1048 |
+
self.url = None
|
1049 |
+
self.license = None
|
1050 |
+
self.description = None
|
1051 |
+
self.long_description = None
|
1052 |
+
self.keywords = None
|
1053 |
+
self.platforms = None
|
1054 |
+
self.classifiers = None
|
1055 |
+
self.download_url = None
|
1056 |
+
# PEP 314
|
1057 |
+
self.provides = None
|
1058 |
+
self.requires = None
|
1059 |
+
self.obsoletes = None
|
1060 |
+
|
1061 |
+
def read_pkg_file(self, file):
|
1062 |
+
"""Reads the metadata values from a file object."""
|
1063 |
+
msg = message_from_file(file)
|
1064 |
+
|
1065 |
+
def _read_field(name):
|
1066 |
+
value = msg[name]
|
1067 |
+
if value == 'UNKNOWN':
|
1068 |
+
return None
|
1069 |
+
return value
|
1070 |
+
|
1071 |
+
def _read_list(name):
|
1072 |
+
values = msg.get_all(name, None)
|
1073 |
+
if values == []:
|
1074 |
+
return None
|
1075 |
+
return values
|
1076 |
+
|
1077 |
+
metadata_version = msg['metadata-version']
|
1078 |
+
self.name = _read_field('name')
|
1079 |
+
self.version = _read_field('version')
|
1080 |
+
self.description = _read_field('summary')
|
1081 |
+
# we are filling author only.
|
1082 |
+
self.author = _read_field('author')
|
1083 |
+
self.maintainer = None
|
1084 |
+
self.author_email = _read_field('author-email')
|
1085 |
+
self.maintainer_email = None
|
1086 |
+
self.url = _read_field('home-page')
|
1087 |
+
self.license = _read_field('license')
|
1088 |
+
|
1089 |
+
if 'download-url' in msg:
|
1090 |
+
self.download_url = _read_field('download-url')
|
1091 |
+
else:
|
1092 |
+
self.download_url = None
|
1093 |
+
|
1094 |
+
self.long_description = _read_field('description')
|
1095 |
+
self.description = _read_field('summary')
|
1096 |
+
|
1097 |
+
if 'keywords' in msg:
|
1098 |
+
self.keywords = _read_field('keywords').split(',')
|
1099 |
+
|
1100 |
+
self.platforms = _read_list('platform')
|
1101 |
+
self.classifiers = _read_list('classifier')
|
1102 |
+
|
1103 |
+
# PEP 314 - these fields only exist in 1.1
|
1104 |
+
if metadata_version == '1.1':
|
1105 |
+
self.requires = _read_list('requires')
|
1106 |
+
self.provides = _read_list('provides')
|
1107 |
+
self.obsoletes = _read_list('obsoletes')
|
1108 |
+
else:
|
1109 |
+
self.requires = None
|
1110 |
+
self.provides = None
|
1111 |
+
self.obsoletes = None
|
1112 |
+
|
1113 |
+
def write_pkg_info(self, base_dir):
|
1114 |
+
"""Write the PKG-INFO file into the release tree.
|
1115 |
+
"""
|
1116 |
+
with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
|
1117 |
+
encoding='UTF-8') as pkg_info:
|
1118 |
+
self.write_pkg_file(pkg_info)
|
1119 |
+
|
1120 |
+
def write_pkg_file(self, file):
|
1121 |
+
"""Write the PKG-INFO format data to a file object.
|
1122 |
+
"""
|
1123 |
+
version = '1.0'
|
1124 |
+
if (self.provides or self.requires or self.obsoletes or
|
1125 |
+
self.classifiers or self.download_url):
|
1126 |
+
version = '1.1'
|
1127 |
+
|
1128 |
+
file.write('Metadata-Version: %s\n' % version)
|
1129 |
+
file.write('Name: %s\n' % self.get_name())
|
1130 |
+
file.write('Version: %s\n' % self.get_version())
|
1131 |
+
file.write('Summary: %s\n' % self.get_description())
|
1132 |
+
file.write('Home-page: %s\n' % self.get_url())
|
1133 |
+
file.write('Author: %s\n' % self.get_contact())
|
1134 |
+
file.write('Author-email: %s\n' % self.get_contact_email())
|
1135 |
+
file.write('License: %s\n' % self.get_license())
|
1136 |
+
if self.download_url:
|
1137 |
+
file.write('Download-URL: %s\n' % self.download_url)
|
1138 |
+
|
1139 |
+
long_desc = rfc822_escape(self.get_long_description())
|
1140 |
+
file.write('Description: %s\n' % long_desc)
|
1141 |
+
|
1142 |
+
keywords = ','.join(self.get_keywords())
|
1143 |
+
if keywords:
|
1144 |
+
file.write('Keywords: %s\n' % keywords)
|
1145 |
+
|
1146 |
+
self._write_list(file, 'Platform', self.get_platforms())
|
1147 |
+
self._write_list(file, 'Classifier', self.get_classifiers())
|
1148 |
+
|
1149 |
+
# PEP 314
|
1150 |
+
self._write_list(file, 'Requires', self.get_requires())
|
1151 |
+
self._write_list(file, 'Provides', self.get_provides())
|
1152 |
+
self._write_list(file, 'Obsoletes', self.get_obsoletes())
|
1153 |
+
|
1154 |
+
def _write_list(self, file, name, values):
|
1155 |
+
for value in values:
|
1156 |
+
file.write('%s: %s\n' % (name, value))
|
1157 |
+
|
1158 |
+
# -- Metadata query methods ----------------------------------------
|
1159 |
+
|
1160 |
+
def get_name(self):
|
1161 |
+
return self.name or "UNKNOWN"
|
1162 |
+
|
1163 |
+
def get_version(self):
|
1164 |
+
return self.version or "0.0.0"
|
1165 |
+
|
1166 |
+
def get_fullname(self):
|
1167 |
+
return "%s-%s" % (self.get_name(), self.get_version())
|
1168 |
+
|
1169 |
+
def get_author(self):
|
1170 |
+
return self.author or "UNKNOWN"
|
1171 |
+
|
1172 |
+
def get_author_email(self):
|
1173 |
+
return self.author_email or "UNKNOWN"
|
1174 |
+
|
1175 |
+
def get_maintainer(self):
|
1176 |
+
return self.maintainer or "UNKNOWN"
|
1177 |
+
|
1178 |
+
def get_maintainer_email(self):
|
1179 |
+
return self.maintainer_email or "UNKNOWN"
|
1180 |
+
|
1181 |
+
def get_contact(self):
|
1182 |
+
return self.maintainer or self.author or "UNKNOWN"
|
1183 |
+
|
1184 |
+
def get_contact_email(self):
|
1185 |
+
return self.maintainer_email or self.author_email or "UNKNOWN"
|
1186 |
+
|
1187 |
+
def get_url(self):
|
1188 |
+
return self.url or "UNKNOWN"
|
1189 |
+
|
1190 |
+
def get_license(self):
|
1191 |
+
return self.license or "UNKNOWN"
|
1192 |
+
get_licence = get_license
|
1193 |
+
|
1194 |
+
def get_description(self):
|
1195 |
+
return self.description or "UNKNOWN"
|
1196 |
+
|
1197 |
+
def get_long_description(self):
|
1198 |
+
return self.long_description or "UNKNOWN"
|
1199 |
+
|
1200 |
+
def get_keywords(self):
|
1201 |
+
return self.keywords or []
|
1202 |
+
|
1203 |
+
def set_keywords(self, value):
|
1204 |
+
self.keywords = _ensure_list(value, 'keywords')
|
1205 |
+
|
1206 |
+
def get_platforms(self):
|
1207 |
+
return self.platforms or ["UNKNOWN"]
|
1208 |
+
|
1209 |
+
def set_platforms(self, value):
|
1210 |
+
self.platforms = _ensure_list(value, 'platforms')
|
1211 |
+
|
1212 |
+
def get_classifiers(self):
|
1213 |
+
return self.classifiers or []
|
1214 |
+
|
1215 |
+
def set_classifiers(self, value):
|
1216 |
+
self.classifiers = _ensure_list(value, 'classifiers')
|
1217 |
+
|
1218 |
+
def get_download_url(self):
|
1219 |
+
return self.download_url or "UNKNOWN"
|
1220 |
+
|
1221 |
+
# PEP 314
|
1222 |
+
def get_requires(self):
|
1223 |
+
return self.requires or []
|
1224 |
+
|
1225 |
+
def set_requires(self, value):
|
1226 |
+
import distutils.versionpredicate
|
1227 |
+
for v in value:
|
1228 |
+
distutils.versionpredicate.VersionPredicate(v)
|
1229 |
+
self.requires = list(value)
|
1230 |
+
|
1231 |
+
def get_provides(self):
|
1232 |
+
return self.provides or []
|
1233 |
+
|
1234 |
+
def set_provides(self, value):
|
1235 |
+
value = [v.strip() for v in value]
|
1236 |
+
for v in value:
|
1237 |
+
import distutils.versionpredicate
|
1238 |
+
distutils.versionpredicate.split_provision(v)
|
1239 |
+
self.provides = value
|
1240 |
+
|
1241 |
+
def get_obsoletes(self):
|
1242 |
+
return self.obsoletes or []
|
1243 |
+
|
1244 |
+
def set_obsoletes(self, value):
|
1245 |
+
import distutils.versionpredicate
|
1246 |
+
for v in value:
|
1247 |
+
distutils.versionpredicate.VersionPredicate(v)
|
1248 |
+
self.obsoletes = list(value)
|
1249 |
+
|
1250 |
+
def fix_help_options(options):
|
1251 |
+
"""Convert a 4-tuple 'help_options' list as found in various command
|
1252 |
+
classes to the 3-tuple form required by FancyGetopt.
|
1253 |
+
"""
|
1254 |
+
new_options = []
|
1255 |
+
for help_tuple in options:
|
1256 |
+
new_options.append(help_tuple[0:3])
|
1257 |
+
return new_options
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/extension.py
ADDED
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.extension
|
2 |
+
|
3 |
+
Provides the Extension class, used to describe C/C++ extension
|
4 |
+
modules in setup scripts."""
|
5 |
+
|
6 |
+
import os
|
7 |
+
import warnings
|
8 |
+
|
9 |
+
# This class is really only used by the "build_ext" command, so it might
|
10 |
+
# make sense to put it in distutils.command.build_ext. However, that
|
11 |
+
# module is already big enough, and I want to make this class a bit more
|
12 |
+
# complex to simplify some common cases ("foo" module in "foo.c") and do
|
13 |
+
# better error-checking ("foo.c" actually exists).
|
14 |
+
#
|
15 |
+
# Also, putting this in build_ext.py means every setup script would have to
|
16 |
+
# import that large-ish module (indirectly, through distutils.core) in
|
17 |
+
# order to do anything.
|
18 |
+
|
19 |
+
class Extension:
|
20 |
+
"""Just a collection of attributes that describes an extension
|
21 |
+
module and everything needed to build it (hopefully in a portable
|
22 |
+
way, but there are hooks that let you be as unportable as you need).
|
23 |
+
|
24 |
+
Instance attributes:
|
25 |
+
name : string
|
26 |
+
the full name of the extension, including any packages -- ie.
|
27 |
+
*not* a filename or pathname, but Python dotted name
|
28 |
+
sources : [string]
|
29 |
+
list of source filenames, relative to the distribution root
|
30 |
+
(where the setup script lives), in Unix form (slash-separated)
|
31 |
+
for portability. Source files may be C, C++, SWIG (.i),
|
32 |
+
platform-specific resource files, or whatever else is recognized
|
33 |
+
by the "build_ext" command as source for a Python extension.
|
34 |
+
include_dirs : [string]
|
35 |
+
list of directories to search for C/C++ header files (in Unix
|
36 |
+
form for portability)
|
37 |
+
define_macros : [(name : string, value : string|None)]
|
38 |
+
list of macros to define; each macro is defined using a 2-tuple,
|
39 |
+
where 'value' is either the string to define it to or None to
|
40 |
+
define it without a particular value (equivalent of "#define
|
41 |
+
FOO" in source or -DFOO on Unix C compiler command line)
|
42 |
+
undef_macros : [string]
|
43 |
+
list of macros to undefine explicitly
|
44 |
+
library_dirs : [string]
|
45 |
+
list of directories to search for C/C++ libraries at link time
|
46 |
+
libraries : [string]
|
47 |
+
list of library names (not filenames or paths) to link against
|
48 |
+
runtime_library_dirs : [string]
|
49 |
+
list of directories to search for C/C++ libraries at run time
|
50 |
+
(for shared extensions, this is when the extension is loaded)
|
51 |
+
extra_objects : [string]
|
52 |
+
list of extra files to link with (eg. object files not implied
|
53 |
+
by 'sources', static library that must be explicitly specified,
|
54 |
+
binary resource files, etc.)
|
55 |
+
extra_compile_args : [string]
|
56 |
+
any extra platform- and compiler-specific information to use
|
57 |
+
when compiling the source files in 'sources'. For platforms and
|
58 |
+
compilers where "command line" makes sense, this is typically a
|
59 |
+
list of command-line arguments, but for other platforms it could
|
60 |
+
be anything.
|
61 |
+
extra_link_args : [string]
|
62 |
+
any extra platform- and compiler-specific information to use
|
63 |
+
when linking object files together to create the extension (or
|
64 |
+
to create a new static Python interpreter). Similar
|
65 |
+
interpretation as for 'extra_compile_args'.
|
66 |
+
export_symbols : [string]
|
67 |
+
list of symbols to be exported from a shared extension. Not
|
68 |
+
used on all platforms, and not generally necessary for Python
|
69 |
+
extensions, which typically export exactly one symbol: "init" +
|
70 |
+
extension_name.
|
71 |
+
swig_opts : [string]
|
72 |
+
any extra options to pass to SWIG if a source file has the .i
|
73 |
+
extension.
|
74 |
+
depends : [string]
|
75 |
+
list of files that the extension depends on
|
76 |
+
language : string
|
77 |
+
extension language (i.e. "c", "c++", "objc"). Will be detected
|
78 |
+
from the source extensions if not provided.
|
79 |
+
optional : boolean
|
80 |
+
specifies that a build failure in the extension should not abort the
|
81 |
+
build process, but simply not install the failing extension.
|
82 |
+
"""
|
83 |
+
|
84 |
+
# When adding arguments to this constructor, be sure to update
|
85 |
+
# setup_keywords in core.py.
|
86 |
+
def __init__(self, name, sources,
|
87 |
+
include_dirs=None,
|
88 |
+
define_macros=None,
|
89 |
+
undef_macros=None,
|
90 |
+
library_dirs=None,
|
91 |
+
libraries=None,
|
92 |
+
runtime_library_dirs=None,
|
93 |
+
extra_objects=None,
|
94 |
+
extra_compile_args=None,
|
95 |
+
extra_link_args=None,
|
96 |
+
export_symbols=None,
|
97 |
+
swig_opts = None,
|
98 |
+
depends=None,
|
99 |
+
language=None,
|
100 |
+
optional=None,
|
101 |
+
**kw # To catch unknown keywords
|
102 |
+
):
|
103 |
+
if not isinstance(name, str):
|
104 |
+
raise AssertionError("'name' must be a string")
|
105 |
+
if not (isinstance(sources, list) and
|
106 |
+
all(isinstance(v, str) for v in sources)):
|
107 |
+
raise AssertionError("'sources' must be a list of strings")
|
108 |
+
|
109 |
+
self.name = name
|
110 |
+
self.sources = sources
|
111 |
+
self.include_dirs = include_dirs or []
|
112 |
+
self.define_macros = define_macros or []
|
113 |
+
self.undef_macros = undef_macros or []
|
114 |
+
self.library_dirs = library_dirs or []
|
115 |
+
self.libraries = libraries or []
|
116 |
+
self.runtime_library_dirs = runtime_library_dirs or []
|
117 |
+
self.extra_objects = extra_objects or []
|
118 |
+
self.extra_compile_args = extra_compile_args or []
|
119 |
+
self.extra_link_args = extra_link_args or []
|
120 |
+
self.export_symbols = export_symbols or []
|
121 |
+
self.swig_opts = swig_opts or []
|
122 |
+
self.depends = depends or []
|
123 |
+
self.language = language
|
124 |
+
self.optional = optional
|
125 |
+
|
126 |
+
# If there are unknown keyword options, warn about them
|
127 |
+
if len(kw) > 0:
|
128 |
+
options = [repr(option) for option in kw]
|
129 |
+
options = ', '.join(sorted(options))
|
130 |
+
msg = "Unknown Extension options: %s" % options
|
131 |
+
warnings.warn(msg)
|
132 |
+
|
133 |
+
def __repr__(self):
|
134 |
+
return '<%s.%s(%r) at %#x>' % (
|
135 |
+
self.__class__.__module__,
|
136 |
+
self.__class__.__qualname__,
|
137 |
+
self.name,
|
138 |
+
id(self))
|
139 |
+
|
140 |
+
|
141 |
+
def read_setup_file(filename):
|
142 |
+
"""Reads a Setup file and returns Extension instances."""
|
143 |
+
from distutils.sysconfig import (parse_makefile, expand_makefile_vars,
|
144 |
+
_variable_rx)
|
145 |
+
|
146 |
+
from distutils.text_file import TextFile
|
147 |
+
from distutils.util import split_quoted
|
148 |
+
|
149 |
+
# First pass over the file to gather "VAR = VALUE" assignments.
|
150 |
+
vars = parse_makefile(filename)
|
151 |
+
|
152 |
+
# Second pass to gobble up the real content: lines of the form
|
153 |
+
# <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
|
154 |
+
file = TextFile(filename,
|
155 |
+
strip_comments=1, skip_blanks=1, join_lines=1,
|
156 |
+
lstrip_ws=1, rstrip_ws=1)
|
157 |
+
try:
|
158 |
+
extensions = []
|
159 |
+
|
160 |
+
while True:
|
161 |
+
line = file.readline()
|
162 |
+
if line is None: # eof
|
163 |
+
break
|
164 |
+
if _variable_rx.match(line): # VAR=VALUE, handled in first pass
|
165 |
+
continue
|
166 |
+
|
167 |
+
if line[0] == line[-1] == "*":
|
168 |
+
file.warn("'%s' lines not handled yet" % line)
|
169 |
+
continue
|
170 |
+
|
171 |
+
line = expand_makefile_vars(line, vars)
|
172 |
+
words = split_quoted(line)
|
173 |
+
|
174 |
+
# NB. this parses a slightly different syntax than the old
|
175 |
+
# makesetup script: here, there must be exactly one extension per
|
176 |
+
# line, and it must be the first word of the line. I have no idea
|
177 |
+
# why the old syntax supported multiple extensions per line, as
|
178 |
+
# they all wind up being the same.
|
179 |
+
|
180 |
+
module = words[0]
|
181 |
+
ext = Extension(module, [])
|
182 |
+
append_next_word = None
|
183 |
+
|
184 |
+
for word in words[1:]:
|
185 |
+
if append_next_word is not None:
|
186 |
+
append_next_word.append(word)
|
187 |
+
append_next_word = None
|
188 |
+
continue
|
189 |
+
|
190 |
+
suffix = os.path.splitext(word)[1]
|
191 |
+
switch = word[0:2] ; value = word[2:]
|
192 |
+
|
193 |
+
if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"):
|
194 |
+
# hmm, should we do something about C vs. C++ sources?
|
195 |
+
# or leave it up to the CCompiler implementation to
|
196 |
+
# worry about?
|
197 |
+
ext.sources.append(word)
|
198 |
+
elif switch == "-I":
|
199 |
+
ext.include_dirs.append(value)
|
200 |
+
elif switch == "-D":
|
201 |
+
equals = value.find("=")
|
202 |
+
if equals == -1: # bare "-DFOO" -- no value
|
203 |
+
ext.define_macros.append((value, None))
|
204 |
+
else: # "-DFOO=blah"
|
205 |
+
ext.define_macros.append((value[0:equals],
|
206 |
+
value[equals+2:]))
|
207 |
+
elif switch == "-U":
|
208 |
+
ext.undef_macros.append(value)
|
209 |
+
elif switch == "-C": # only here 'cause makesetup has it!
|
210 |
+
ext.extra_compile_args.append(word)
|
211 |
+
elif switch == "-l":
|
212 |
+
ext.libraries.append(value)
|
213 |
+
elif switch == "-L":
|
214 |
+
ext.library_dirs.append(value)
|
215 |
+
elif switch == "-R":
|
216 |
+
ext.runtime_library_dirs.append(value)
|
217 |
+
elif word == "-rpath":
|
218 |
+
append_next_word = ext.runtime_library_dirs
|
219 |
+
elif word == "-Xlinker":
|
220 |
+
append_next_word = ext.extra_link_args
|
221 |
+
elif word == "-Xcompiler":
|
222 |
+
append_next_word = ext.extra_compile_args
|
223 |
+
elif switch == "-u":
|
224 |
+
ext.extra_link_args.append(word)
|
225 |
+
if not value:
|
226 |
+
append_next_word = ext.extra_link_args
|
227 |
+
elif suffix in (".a", ".so", ".sl", ".o", ".dylib"):
|
228 |
+
# NB. a really faithful emulation of makesetup would
|
229 |
+
# append a .o file to extra_objects only if it
|
230 |
+
# had a slash in it; otherwise, it would s/.o/.c/
|
231 |
+
# and append it to sources. Hmmmm.
|
232 |
+
ext.extra_objects.append(word)
|
233 |
+
else:
|
234 |
+
file.warn("unrecognized argument '%s'" % word)
|
235 |
+
|
236 |
+
extensions.append(ext)
|
237 |
+
finally:
|
238 |
+
file.close()
|
239 |
+
|
240 |
+
return extensions
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/fancy_getopt.py
ADDED
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.fancy_getopt
|
2 |
+
|
3 |
+
Wrapper around the standard getopt module that provides the following
|
4 |
+
additional features:
|
5 |
+
* short and long options are tied together
|
6 |
+
* options have help strings, so fancy_getopt could potentially
|
7 |
+
create a complete usage summary
|
8 |
+
* options set attributes of a passed-in object
|
9 |
+
"""
|
10 |
+
|
11 |
+
import sys, string, re
|
12 |
+
import getopt
|
13 |
+
from distutils.errors import *
|
14 |
+
|
15 |
+
# Much like command_re in distutils.core, this is close to but not quite
|
16 |
+
# the same as a Python NAME -- except, in the spirit of most GNU
|
17 |
+
# utilities, we use '-' in place of '_'. (The spirit of LISP lives on!)
|
18 |
+
# The similarities to NAME are again not a coincidence...
|
19 |
+
longopt_pat = r'[a-zA-Z](?:[a-zA-Z0-9-]*)'
|
20 |
+
longopt_re = re.compile(r'^%s$' % longopt_pat)
|
21 |
+
|
22 |
+
# For recognizing "negative alias" options, eg. "quiet=!verbose"
|
23 |
+
neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat))
|
24 |
+
|
25 |
+
# This is used to translate long options to legitimate Python identifiers
|
26 |
+
# (for use as attributes of some object).
|
27 |
+
longopt_xlate = str.maketrans('-', '_')
|
28 |
+
|
29 |
+
class FancyGetopt:
|
30 |
+
"""Wrapper around the standard 'getopt()' module that provides some
|
31 |
+
handy extra functionality:
|
32 |
+
* short and long options are tied together
|
33 |
+
* options have help strings, and help text can be assembled
|
34 |
+
from them
|
35 |
+
* options set attributes of a passed-in object
|
36 |
+
* boolean options can have "negative aliases" -- eg. if
|
37 |
+
--quiet is the "negative alias" of --verbose, then "--quiet"
|
38 |
+
on the command line sets 'verbose' to false
|
39 |
+
"""
|
40 |
+
|
41 |
+
def __init__(self, option_table=None):
|
42 |
+
# The option table is (currently) a list of tuples. The
|
43 |
+
# tuples may have 3 or four values:
|
44 |
+
# (long_option, short_option, help_string [, repeatable])
|
45 |
+
# if an option takes an argument, its long_option should have '='
|
46 |
+
# appended; short_option should just be a single character, no ':'
|
47 |
+
# in any case. If a long_option doesn't have a corresponding
|
48 |
+
# short_option, short_option should be None. All option tuples
|
49 |
+
# must have long options.
|
50 |
+
self.option_table = option_table
|
51 |
+
|
52 |
+
# 'option_index' maps long option names to entries in the option
|
53 |
+
# table (ie. those 3-tuples).
|
54 |
+
self.option_index = {}
|
55 |
+
if self.option_table:
|
56 |
+
self._build_index()
|
57 |
+
|
58 |
+
# 'alias' records (duh) alias options; {'foo': 'bar'} means
|
59 |
+
# --foo is an alias for --bar
|
60 |
+
self.alias = {}
|
61 |
+
|
62 |
+
# 'negative_alias' keeps track of options that are the boolean
|
63 |
+
# opposite of some other option
|
64 |
+
self.negative_alias = {}
|
65 |
+
|
66 |
+
# These keep track of the information in the option table. We
|
67 |
+
# don't actually populate these structures until we're ready to
|
68 |
+
# parse the command-line, since the 'option_table' passed in here
|
69 |
+
# isn't necessarily the final word.
|
70 |
+
self.short_opts = []
|
71 |
+
self.long_opts = []
|
72 |
+
self.short2long = {}
|
73 |
+
self.attr_name = {}
|
74 |
+
self.takes_arg = {}
|
75 |
+
|
76 |
+
# And 'option_order' is filled up in 'getopt()'; it records the
|
77 |
+
# original order of options (and their values) on the command-line,
|
78 |
+
# but expands short options, converts aliases, etc.
|
79 |
+
self.option_order = []
|
80 |
+
|
81 |
+
def _build_index(self):
|
82 |
+
self.option_index.clear()
|
83 |
+
for option in self.option_table:
|
84 |
+
self.option_index[option[0]] = option
|
85 |
+
|
86 |
+
def set_option_table(self, option_table):
|
87 |
+
self.option_table = option_table
|
88 |
+
self._build_index()
|
89 |
+
|
90 |
+
def add_option(self, long_option, short_option=None, help_string=None):
|
91 |
+
if long_option in self.option_index:
|
92 |
+
raise DistutilsGetoptError(
|
93 |
+
"option conflict: already an option '%s'" % long_option)
|
94 |
+
else:
|
95 |
+
option = (long_option, short_option, help_string)
|
96 |
+
self.option_table.append(option)
|
97 |
+
self.option_index[long_option] = option
|
98 |
+
|
99 |
+
def has_option(self, long_option):
|
100 |
+
"""Return true if the option table for this parser has an
|
101 |
+
option with long name 'long_option'."""
|
102 |
+
return long_option in self.option_index
|
103 |
+
|
104 |
+
def get_attr_name(self, long_option):
|
105 |
+
"""Translate long option name 'long_option' to the form it
|
106 |
+
has as an attribute of some object: ie., translate hyphens
|
107 |
+
to underscores."""
|
108 |
+
return long_option.translate(longopt_xlate)
|
109 |
+
|
110 |
+
def _check_alias_dict(self, aliases, what):
|
111 |
+
assert isinstance(aliases, dict)
|
112 |
+
for (alias, opt) in aliases.items():
|
113 |
+
if alias not in self.option_index:
|
114 |
+
raise DistutilsGetoptError(("invalid %s '%s': "
|
115 |
+
"option '%s' not defined") % (what, alias, alias))
|
116 |
+
if opt not in self.option_index:
|
117 |
+
raise DistutilsGetoptError(("invalid %s '%s': "
|
118 |
+
"aliased option '%s' not defined") % (what, alias, opt))
|
119 |
+
|
120 |
+
def set_aliases(self, alias):
|
121 |
+
"""Set the aliases for this option parser."""
|
122 |
+
self._check_alias_dict(alias, "alias")
|
123 |
+
self.alias = alias
|
124 |
+
|
125 |
+
def set_negative_aliases(self, negative_alias):
|
126 |
+
"""Set the negative aliases for this option parser.
|
127 |
+
'negative_alias' should be a dictionary mapping option names to
|
128 |
+
option names, both the key and value must already be defined
|
129 |
+
in the option table."""
|
130 |
+
self._check_alias_dict(negative_alias, "negative alias")
|
131 |
+
self.negative_alias = negative_alias
|
132 |
+
|
133 |
+
def _grok_option_table(self):
|
134 |
+
"""Populate the various data structures that keep tabs on the
|
135 |
+
option table. Called by 'getopt()' before it can do anything
|
136 |
+
worthwhile.
|
137 |
+
"""
|
138 |
+
self.long_opts = []
|
139 |
+
self.short_opts = []
|
140 |
+
self.short2long.clear()
|
141 |
+
self.repeat = {}
|
142 |
+
|
143 |
+
for option in self.option_table:
|
144 |
+
if len(option) == 3:
|
145 |
+
long, short, help = option
|
146 |
+
repeat = 0
|
147 |
+
elif len(option) == 4:
|
148 |
+
long, short, help, repeat = option
|
149 |
+
else:
|
150 |
+
# the option table is part of the code, so simply
|
151 |
+
# assert that it is correct
|
152 |
+
raise ValueError("invalid option tuple: %r" % (option,))
|
153 |
+
|
154 |
+
# Type- and value-check the option names
|
155 |
+
if not isinstance(long, str) or len(long) < 2:
|
156 |
+
raise DistutilsGetoptError(("invalid long option '%s': "
|
157 |
+
"must be a string of length >= 2") % long)
|
158 |
+
|
159 |
+
if (not ((short is None) or
|
160 |
+
(isinstance(short, str) and len(short) == 1))):
|
161 |
+
raise DistutilsGetoptError("invalid short option '%s': "
|
162 |
+
"must a single character or None" % short)
|
163 |
+
|
164 |
+
self.repeat[long] = repeat
|
165 |
+
self.long_opts.append(long)
|
166 |
+
|
167 |
+
if long[-1] == '=': # option takes an argument?
|
168 |
+
if short: short = short + ':'
|
169 |
+
long = long[0:-1]
|
170 |
+
self.takes_arg[long] = 1
|
171 |
+
else:
|
172 |
+
# Is option is a "negative alias" for some other option (eg.
|
173 |
+
# "quiet" == "!verbose")?
|
174 |
+
alias_to = self.negative_alias.get(long)
|
175 |
+
if alias_to is not None:
|
176 |
+
if self.takes_arg[alias_to]:
|
177 |
+
raise DistutilsGetoptError(
|
178 |
+
"invalid negative alias '%s': "
|
179 |
+
"aliased option '%s' takes a value"
|
180 |
+
% (long, alias_to))
|
181 |
+
|
182 |
+
self.long_opts[-1] = long # XXX redundant?!
|
183 |
+
self.takes_arg[long] = 0
|
184 |
+
|
185 |
+
# If this is an alias option, make sure its "takes arg" flag is
|
186 |
+
# the same as the option it's aliased to.
|
187 |
+
alias_to = self.alias.get(long)
|
188 |
+
if alias_to is not None:
|
189 |
+
if self.takes_arg[long] != self.takes_arg[alias_to]:
|
190 |
+
raise DistutilsGetoptError(
|
191 |
+
"invalid alias '%s': inconsistent with "
|
192 |
+
"aliased option '%s' (one of them takes a value, "
|
193 |
+
"the other doesn't"
|
194 |
+
% (long, alias_to))
|
195 |
+
|
196 |
+
# Now enforce some bondage on the long option name, so we can
|
197 |
+
# later translate it to an attribute name on some object. Have
|
198 |
+
# to do this a bit late to make sure we've removed any trailing
|
199 |
+
# '='.
|
200 |
+
if not longopt_re.match(long):
|
201 |
+
raise DistutilsGetoptError(
|
202 |
+
"invalid long option name '%s' "
|
203 |
+
"(must be letters, numbers, hyphens only" % long)
|
204 |
+
|
205 |
+
self.attr_name[long] = self.get_attr_name(long)
|
206 |
+
if short:
|
207 |
+
self.short_opts.append(short)
|
208 |
+
self.short2long[short[0]] = long
|
209 |
+
|
210 |
+
def getopt(self, args=None, object=None):
|
211 |
+
"""Parse command-line options in args. Store as attributes on object.
|
212 |
+
|
213 |
+
If 'args' is None or not supplied, uses 'sys.argv[1:]'. If
|
214 |
+
'object' is None or not supplied, creates a new OptionDummy
|
215 |
+
object, stores option values there, and returns a tuple (args,
|
216 |
+
object). If 'object' is supplied, it is modified in place and
|
217 |
+
'getopt()' just returns 'args'; in both cases, the returned
|
218 |
+
'args' is a modified copy of the passed-in 'args' list, which
|
219 |
+
is left untouched.
|
220 |
+
"""
|
221 |
+
if args is None:
|
222 |
+
args = sys.argv[1:]
|
223 |
+
if object is None:
|
224 |
+
object = OptionDummy()
|
225 |
+
created_object = True
|
226 |
+
else:
|
227 |
+
created_object = False
|
228 |
+
|
229 |
+
self._grok_option_table()
|
230 |
+
|
231 |
+
short_opts = ' '.join(self.short_opts)
|
232 |
+
try:
|
233 |
+
opts, args = getopt.getopt(args, short_opts, self.long_opts)
|
234 |
+
except getopt.error as msg:
|
235 |
+
raise DistutilsArgError(msg)
|
236 |
+
|
237 |
+
for opt, val in opts:
|
238 |
+
if len(opt) == 2 and opt[0] == '-': # it's a short option
|
239 |
+
opt = self.short2long[opt[1]]
|
240 |
+
else:
|
241 |
+
assert len(opt) > 2 and opt[:2] == '--'
|
242 |
+
opt = opt[2:]
|
243 |
+
|
244 |
+
alias = self.alias.get(opt)
|
245 |
+
if alias:
|
246 |
+
opt = alias
|
247 |
+
|
248 |
+
if not self.takes_arg[opt]: # boolean option?
|
249 |
+
assert val == '', "boolean option can't have value"
|
250 |
+
alias = self.negative_alias.get(opt)
|
251 |
+
if alias:
|
252 |
+
opt = alias
|
253 |
+
val = 0
|
254 |
+
else:
|
255 |
+
val = 1
|
256 |
+
|
257 |
+
attr = self.attr_name[opt]
|
258 |
+
# The only repeating option at the moment is 'verbose'.
|
259 |
+
# It has a negative option -q quiet, which should set verbose = 0.
|
260 |
+
if val and self.repeat.get(attr) is not None:
|
261 |
+
val = getattr(object, attr, 0) + 1
|
262 |
+
setattr(object, attr, val)
|
263 |
+
self.option_order.append((opt, val))
|
264 |
+
|
265 |
+
# for opts
|
266 |
+
if created_object:
|
267 |
+
return args, object
|
268 |
+
else:
|
269 |
+
return args
|
270 |
+
|
271 |
+
def get_option_order(self):
|
272 |
+
"""Returns the list of (option, value) tuples processed by the
|
273 |
+
previous run of 'getopt()'. Raises RuntimeError if
|
274 |
+
'getopt()' hasn't been called yet.
|
275 |
+
"""
|
276 |
+
if self.option_order is None:
|
277 |
+
raise RuntimeError("'getopt()' hasn't been called yet")
|
278 |
+
else:
|
279 |
+
return self.option_order
|
280 |
+
|
281 |
+
def generate_help(self, header=None):
|
282 |
+
"""Generate help text (a list of strings, one per suggested line of
|
283 |
+
output) from the option table for this FancyGetopt object.
|
284 |
+
"""
|
285 |
+
# Blithely assume the option table is good: probably wouldn't call
|
286 |
+
# 'generate_help()' unless you've already called 'getopt()'.
|
287 |
+
|
288 |
+
# First pass: determine maximum length of long option names
|
289 |
+
max_opt = 0
|
290 |
+
for option in self.option_table:
|
291 |
+
long = option[0]
|
292 |
+
short = option[1]
|
293 |
+
l = len(long)
|
294 |
+
if long[-1] == '=':
|
295 |
+
l = l - 1
|
296 |
+
if short is not None:
|
297 |
+
l = l + 5 # " (-x)" where short == 'x'
|
298 |
+
if l > max_opt:
|
299 |
+
max_opt = l
|
300 |
+
|
301 |
+
opt_width = max_opt + 2 + 2 + 2 # room for indent + dashes + gutter
|
302 |
+
|
303 |
+
# Typical help block looks like this:
|
304 |
+
# --foo controls foonabulation
|
305 |
+
# Help block for longest option looks like this:
|
306 |
+
# --flimflam set the flim-flam level
|
307 |
+
# and with wrapped text:
|
308 |
+
# --flimflam set the flim-flam level (must be between
|
309 |
+
# 0 and 100, except on Tuesdays)
|
310 |
+
# Options with short names will have the short name shown (but
|
311 |
+
# it doesn't contribute to max_opt):
|
312 |
+
# --foo (-f) controls foonabulation
|
313 |
+
# If adding the short option would make the left column too wide,
|
314 |
+
# we push the explanation off to the next line
|
315 |
+
# --flimflam (-l)
|
316 |
+
# set the flim-flam level
|
317 |
+
# Important parameters:
|
318 |
+
# - 2 spaces before option block start lines
|
319 |
+
# - 2 dashes for each long option name
|
320 |
+
# - min. 2 spaces between option and explanation (gutter)
|
321 |
+
# - 5 characters (incl. space) for short option name
|
322 |
+
|
323 |
+
# Now generate lines of help text. (If 80 columns were good enough
|
324 |
+
# for Jesus, then 78 columns are good enough for me!)
|
325 |
+
line_width = 78
|
326 |
+
text_width = line_width - opt_width
|
327 |
+
big_indent = ' ' * opt_width
|
328 |
+
if header:
|
329 |
+
lines = [header]
|
330 |
+
else:
|
331 |
+
lines = ['Option summary:']
|
332 |
+
|
333 |
+
for option in self.option_table:
|
334 |
+
long, short, help = option[:3]
|
335 |
+
text = wrap_text(help, text_width)
|
336 |
+
if long[-1] == '=':
|
337 |
+
long = long[0:-1]
|
338 |
+
|
339 |
+
# Case 1: no short option at all (makes life easy)
|
340 |
+
if short is None:
|
341 |
+
if text:
|
342 |
+
lines.append(" --%-*s %s" % (max_opt, long, text[0]))
|
343 |
+
else:
|
344 |
+
lines.append(" --%-*s " % (max_opt, long))
|
345 |
+
|
346 |
+
# Case 2: we have a short option, so we have to include it
|
347 |
+
# just after the long option
|
348 |
+
else:
|
349 |
+
opt_names = "%s (-%s)" % (long, short)
|
350 |
+
if text:
|
351 |
+
lines.append(" --%-*s %s" %
|
352 |
+
(max_opt, opt_names, text[0]))
|
353 |
+
else:
|
354 |
+
lines.append(" --%-*s" % opt_names)
|
355 |
+
|
356 |
+
for l in text[1:]:
|
357 |
+
lines.append(big_indent + l)
|
358 |
+
return lines
|
359 |
+
|
360 |
+
def print_help(self, header=None, file=None):
|
361 |
+
if file is None:
|
362 |
+
file = sys.stdout
|
363 |
+
for line in self.generate_help(header):
|
364 |
+
file.write(line + "\n")
|
365 |
+
|
366 |
+
|
367 |
+
def fancy_getopt(options, negative_opt, object, args):
|
368 |
+
parser = FancyGetopt(options)
|
369 |
+
parser.set_negative_aliases(negative_opt)
|
370 |
+
return parser.getopt(args, object)
|
371 |
+
|
372 |
+
|
373 |
+
WS_TRANS = {ord(_wschar) : ' ' for _wschar in string.whitespace}
|
374 |
+
|
375 |
+
def wrap_text(text, width):
|
376 |
+
"""wrap_text(text : string, width : int) -> [string]
|
377 |
+
|
378 |
+
Split 'text' into multiple lines of no more than 'width' characters
|
379 |
+
each, and return the list of strings that results.
|
380 |
+
"""
|
381 |
+
if text is None:
|
382 |
+
return []
|
383 |
+
if len(text) <= width:
|
384 |
+
return [text]
|
385 |
+
|
386 |
+
text = text.expandtabs()
|
387 |
+
text = text.translate(WS_TRANS)
|
388 |
+
chunks = re.split(r'( +|-+)', text)
|
389 |
+
chunks = [ch for ch in chunks if ch] # ' - ' results in empty strings
|
390 |
+
lines = []
|
391 |
+
|
392 |
+
while chunks:
|
393 |
+
cur_line = [] # list of chunks (to-be-joined)
|
394 |
+
cur_len = 0 # length of current line
|
395 |
+
|
396 |
+
while chunks:
|
397 |
+
l = len(chunks[0])
|
398 |
+
if cur_len + l <= width: # can squeeze (at least) this chunk in
|
399 |
+
cur_line.append(chunks[0])
|
400 |
+
del chunks[0]
|
401 |
+
cur_len = cur_len + l
|
402 |
+
else: # this line is full
|
403 |
+
# drop last chunk if all space
|
404 |
+
if cur_line and cur_line[-1][0] == ' ':
|
405 |
+
del cur_line[-1]
|
406 |
+
break
|
407 |
+
|
408 |
+
if chunks: # any chunks left to process?
|
409 |
+
# if the current line is still empty, then we had a single
|
410 |
+
# chunk that's too big too fit on a line -- so we break
|
411 |
+
# down and break it up at the line width
|
412 |
+
if cur_len == 0:
|
413 |
+
cur_line.append(chunks[0][0:width])
|
414 |
+
chunks[0] = chunks[0][width:]
|
415 |
+
|
416 |
+
# all-whitespace chunks at the end of a line can be discarded
|
417 |
+
# (and we know from the re.split above that if a chunk has
|
418 |
+
# *any* whitespace, it is *all* whitespace)
|
419 |
+
if chunks[0][0] == ' ':
|
420 |
+
del chunks[0]
|
421 |
+
|
422 |
+
# and store this line in the list-of-all-lines -- as a single
|
423 |
+
# string, of course!
|
424 |
+
lines.append(''.join(cur_line))
|
425 |
+
|
426 |
+
return lines
|
427 |
+
|
428 |
+
|
429 |
+
def translate_longopt(opt):
|
430 |
+
"""Convert a long option name to a valid Python identifier by
|
431 |
+
changing "-" to "_".
|
432 |
+
"""
|
433 |
+
return opt.translate(longopt_xlate)
|
434 |
+
|
435 |
+
|
436 |
+
class OptionDummy:
|
437 |
+
"""Dummy class just used as a place to hold command-line option
|
438 |
+
values as instance attributes."""
|
439 |
+
|
440 |
+
def __init__(self, options=[]):
|
441 |
+
"""Create a new OptionDummy instance. The attributes listed in
|
442 |
+
'options' will be initialized to None."""
|
443 |
+
for opt in options:
|
444 |
+
setattr(self, opt, None)
|
445 |
+
|
446 |
+
|
447 |
+
if __name__ == "__main__":
|
448 |
+
text = """\
|
449 |
+
Tra-la-la, supercalifragilisticexpialidocious.
|
450 |
+
How *do* you spell that odd word, anyways?
|
451 |
+
(Someone ask Mary -- she'll know [or she'll
|
452 |
+
say, "How should I know?"].)"""
|
453 |
+
|
454 |
+
for w in (10, 20, 30, 40):
|
455 |
+
print("width: %d" % w)
|
456 |
+
print("\n".join(wrap_text(text, w)))
|
457 |
+
print()
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/log.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""A simple log mechanism styled after PEP 282."""
|
2 |
+
|
3 |
+
# The class here is styled after PEP 282 so that it could later be
|
4 |
+
# replaced with a standard Python logging implementation.
|
5 |
+
|
6 |
+
DEBUG = 1
|
7 |
+
INFO = 2
|
8 |
+
WARN = 3
|
9 |
+
ERROR = 4
|
10 |
+
FATAL = 5
|
11 |
+
|
12 |
+
import sys
|
13 |
+
|
14 |
+
class Log:
|
15 |
+
|
16 |
+
def __init__(self, threshold=WARN):
|
17 |
+
self.threshold = threshold
|
18 |
+
|
19 |
+
def _log(self, level, msg, args):
|
20 |
+
if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
|
21 |
+
raise ValueError('%s wrong log level' % str(level))
|
22 |
+
|
23 |
+
if level >= self.threshold:
|
24 |
+
if args:
|
25 |
+
msg = msg % args
|
26 |
+
if level in (WARN, ERROR, FATAL):
|
27 |
+
stream = sys.stderr
|
28 |
+
else:
|
29 |
+
stream = sys.stdout
|
30 |
+
try:
|
31 |
+
stream.write('%s\n' % msg)
|
32 |
+
except UnicodeEncodeError:
|
33 |
+
# emulate backslashreplace error handler
|
34 |
+
encoding = stream.encoding
|
35 |
+
msg = msg.encode(encoding, "backslashreplace").decode(encoding)
|
36 |
+
stream.write('%s\n' % msg)
|
37 |
+
stream.flush()
|
38 |
+
|
39 |
+
def log(self, level, msg, *args):
|
40 |
+
self._log(level, msg, args)
|
41 |
+
|
42 |
+
def debug(self, msg, *args):
|
43 |
+
self._log(DEBUG, msg, args)
|
44 |
+
|
45 |
+
def info(self, msg, *args):
|
46 |
+
self._log(INFO, msg, args)
|
47 |
+
|
48 |
+
def warn(self, msg, *args):
|
49 |
+
self._log(WARN, msg, args)
|
50 |
+
|
51 |
+
def error(self, msg, *args):
|
52 |
+
self._log(ERROR, msg, args)
|
53 |
+
|
54 |
+
def fatal(self, msg, *args):
|
55 |
+
self._log(FATAL, msg, args)
|
56 |
+
|
57 |
+
_global_log = Log()
|
58 |
+
log = _global_log.log
|
59 |
+
debug = _global_log.debug
|
60 |
+
info = _global_log.info
|
61 |
+
warn = _global_log.warn
|
62 |
+
error = _global_log.error
|
63 |
+
fatal = _global_log.fatal
|
64 |
+
|
65 |
+
def set_threshold(level):
|
66 |
+
# return the old threshold for use from tests
|
67 |
+
old = _global_log.threshold
|
68 |
+
_global_log.threshold = level
|
69 |
+
return old
|
70 |
+
|
71 |
+
def set_verbosity(v):
|
72 |
+
if v <= 0:
|
73 |
+
set_threshold(WARN)
|
74 |
+
elif v == 1:
|
75 |
+
set_threshold(INFO)
|
76 |
+
elif v >= 2:
|
77 |
+
set_threshold(DEBUG)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/sysconfig.py
ADDED
@@ -0,0 +1,601 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Provide access to Python's configuration information. The specific
|
2 |
+
configuration variables available depend heavily on the platform and
|
3 |
+
configuration. The values may be retrieved using
|
4 |
+
get_config_var(name), and the list of variables is available via
|
5 |
+
get_config_vars().keys(). Additional convenience functions are also
|
6 |
+
available.
|
7 |
+
|
8 |
+
Written by: Fred L. Drake, Jr.
|
9 |
+
Email: <[email protected]>
|
10 |
+
"""
|
11 |
+
|
12 |
+
import _imp
|
13 |
+
import os
|
14 |
+
import re
|
15 |
+
import sys
|
16 |
+
|
17 |
+
from .errors import DistutilsPlatformError
|
18 |
+
|
19 |
+
IS_PYPY = '__pypy__' in sys.builtin_module_names
|
20 |
+
|
21 |
+
# These are needed in a couple of spots, so just compute them once.
|
22 |
+
PREFIX = os.path.normpath(sys.prefix)
|
23 |
+
EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
|
24 |
+
BASE_PREFIX = os.path.normpath(sys.base_prefix)
|
25 |
+
BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
|
26 |
+
|
27 |
+
# Path to the base directory of the project. On Windows the binary may
|
28 |
+
# live in project/PCbuild/win32 or project/PCbuild/amd64.
|
29 |
+
# set for cross builds
|
30 |
+
if "_PYTHON_PROJECT_BASE" in os.environ:
|
31 |
+
project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"])
|
32 |
+
else:
|
33 |
+
if sys.executable:
|
34 |
+
project_base = os.path.dirname(os.path.abspath(sys.executable))
|
35 |
+
else:
|
36 |
+
# sys.executable can be empty if argv[0] has been changed and Python is
|
37 |
+
# unable to retrieve the real program name
|
38 |
+
project_base = os.getcwd()
|
39 |
+
|
40 |
+
|
41 |
+
# python_build: (Boolean) if true, we're either building Python or
|
42 |
+
# building an extension with an un-installed Python, so we use
|
43 |
+
# different (hard-wired) directories.
|
44 |
+
def _is_python_source_dir(d):
|
45 |
+
for fn in ("Setup", "Setup.local"):
|
46 |
+
if os.path.isfile(os.path.join(d, "Modules", fn)):
|
47 |
+
return True
|
48 |
+
return False
|
49 |
+
|
50 |
+
_sys_home = getattr(sys, '_home', None)
|
51 |
+
|
52 |
+
if os.name == 'nt':
|
53 |
+
def _fix_pcbuild(d):
|
54 |
+
if d and os.path.normcase(d).startswith(
|
55 |
+
os.path.normcase(os.path.join(PREFIX, "PCbuild"))):
|
56 |
+
return PREFIX
|
57 |
+
return d
|
58 |
+
project_base = _fix_pcbuild(project_base)
|
59 |
+
_sys_home = _fix_pcbuild(_sys_home)
|
60 |
+
|
61 |
+
def _python_build():
|
62 |
+
if _sys_home:
|
63 |
+
return _is_python_source_dir(_sys_home)
|
64 |
+
return _is_python_source_dir(project_base)
|
65 |
+
|
66 |
+
python_build = _python_build()
|
67 |
+
|
68 |
+
|
69 |
+
# Calculate the build qualifier flags if they are defined. Adding the flags
|
70 |
+
# to the include and lib directories only makes sense for an installation, not
|
71 |
+
# an in-source build.
|
72 |
+
build_flags = ''
|
73 |
+
try:
|
74 |
+
if not python_build:
|
75 |
+
build_flags = sys.abiflags
|
76 |
+
except AttributeError:
|
77 |
+
# It's not a configure-based build, so the sys module doesn't have
|
78 |
+
# this attribute, which is fine.
|
79 |
+
pass
|
80 |
+
|
81 |
+
def get_python_version():
|
82 |
+
"""Return a string containing the major and minor Python version,
|
83 |
+
leaving off the patchlevel. Sample return values could be '1.5'
|
84 |
+
or '2.2'.
|
85 |
+
"""
|
86 |
+
return '%d.%d' % sys.version_info[:2]
|
87 |
+
|
88 |
+
|
89 |
+
def get_python_inc(plat_specific=0, prefix=None):
|
90 |
+
"""Return the directory containing installed Python header files.
|
91 |
+
|
92 |
+
If 'plat_specific' is false (the default), this is the path to the
|
93 |
+
non-platform-specific header files, i.e. Python.h and so on;
|
94 |
+
otherwise, this is the path to platform-specific header files
|
95 |
+
(namely pyconfig.h).
|
96 |
+
|
97 |
+
If 'prefix' is supplied, use it instead of sys.base_prefix or
|
98 |
+
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
|
99 |
+
"""
|
100 |
+
if prefix is None:
|
101 |
+
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
|
102 |
+
if os.name == "posix":
|
103 |
+
if IS_PYPY and sys.version_info < (3, 8):
|
104 |
+
return os.path.join(prefix, 'include')
|
105 |
+
if python_build:
|
106 |
+
# Assume the executable is in the build directory. The
|
107 |
+
# pyconfig.h file should be in the same directory. Since
|
108 |
+
# the build directory may not be the source directory, we
|
109 |
+
# must use "srcdir" from the makefile to find the "Include"
|
110 |
+
# directory.
|
111 |
+
if plat_specific:
|
112 |
+
return _sys_home or project_base
|
113 |
+
else:
|
114 |
+
incdir = os.path.join(get_config_var('srcdir'), 'Include')
|
115 |
+
return os.path.normpath(incdir)
|
116 |
+
implementation = 'pypy' if IS_PYPY else 'python'
|
117 |
+
python_dir = implementation + get_python_version() + build_flags
|
118 |
+
return os.path.join(prefix, "include", python_dir)
|
119 |
+
elif os.name == "nt":
|
120 |
+
if python_build:
|
121 |
+
# Include both the include and PC dir to ensure we can find
|
122 |
+
# pyconfig.h
|
123 |
+
return (os.path.join(prefix, "include") + os.path.pathsep +
|
124 |
+
os.path.join(prefix, "PC"))
|
125 |
+
return os.path.join(prefix, "include")
|
126 |
+
else:
|
127 |
+
raise DistutilsPlatformError(
|
128 |
+
"I don't know where Python installs its C header files "
|
129 |
+
"on platform '%s'" % os.name)
|
130 |
+
|
131 |
+
|
132 |
+
# allow this behavior to be monkey-patched. Ref pypa/distutils#2.
|
133 |
+
def _posix_lib(standard_lib, libpython, early_prefix, prefix):
|
134 |
+
if standard_lib:
|
135 |
+
return libpython
|
136 |
+
else:
|
137 |
+
return os.path.join(libpython, "site-packages")
|
138 |
+
|
139 |
+
|
140 |
+
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
141 |
+
"""Return the directory containing the Python library (standard or
|
142 |
+
site additions).
|
143 |
+
|
144 |
+
If 'plat_specific' is true, return the directory containing
|
145 |
+
platform-specific modules, i.e. any module from a non-pure-Python
|
146 |
+
module distribution; otherwise, return the platform-shared library
|
147 |
+
directory. If 'standard_lib' is true, return the directory
|
148 |
+
containing standard Python library modules; otherwise, return the
|
149 |
+
directory for site-specific modules.
|
150 |
+
|
151 |
+
If 'prefix' is supplied, use it instead of sys.base_prefix or
|
152 |
+
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
|
153 |
+
"""
|
154 |
+
|
155 |
+
if IS_PYPY and sys.version_info < (3, 8):
|
156 |
+
# PyPy-specific schema
|
157 |
+
if prefix is None:
|
158 |
+
prefix = PREFIX
|
159 |
+
if standard_lib:
|
160 |
+
return os.path.join(prefix, "lib-python", sys.version[0])
|
161 |
+
return os.path.join(prefix, 'site-packages')
|
162 |
+
|
163 |
+
early_prefix = prefix
|
164 |
+
|
165 |
+
if prefix is None:
|
166 |
+
if standard_lib:
|
167 |
+
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
|
168 |
+
else:
|
169 |
+
prefix = plat_specific and EXEC_PREFIX or PREFIX
|
170 |
+
|
171 |
+
if os.name == "posix":
|
172 |
+
if plat_specific or standard_lib:
|
173 |
+
# Platform-specific modules (any module from a non-pure-Python
|
174 |
+
# module distribution) or standard Python library modules.
|
175 |
+
libdir = getattr(sys, "platlibdir", "lib")
|
176 |
+
else:
|
177 |
+
# Pure Python
|
178 |
+
libdir = "lib"
|
179 |
+
implementation = 'pypy' if IS_PYPY else 'python'
|
180 |
+
libpython = os.path.join(prefix, libdir,
|
181 |
+
implementation + get_python_version())
|
182 |
+
return _posix_lib(standard_lib, libpython, early_prefix, prefix)
|
183 |
+
elif os.name == "nt":
|
184 |
+
if standard_lib:
|
185 |
+
return os.path.join(prefix, "Lib")
|
186 |
+
else:
|
187 |
+
return os.path.join(prefix, "Lib", "site-packages")
|
188 |
+
else:
|
189 |
+
raise DistutilsPlatformError(
|
190 |
+
"I don't know where Python installs its library "
|
191 |
+
"on platform '%s'" % os.name)
|
192 |
+
|
193 |
+
|
194 |
+
|
195 |
+
def customize_compiler(compiler):
|
196 |
+
"""Do any platform-specific customization of a CCompiler instance.
|
197 |
+
|
198 |
+
Mainly needed on Unix, so we can plug in the information that
|
199 |
+
varies across Unices and is stored in Python's Makefile.
|
200 |
+
"""
|
201 |
+
if compiler.compiler_type == "unix":
|
202 |
+
if sys.platform == "darwin":
|
203 |
+
# Perform first-time customization of compiler-related
|
204 |
+
# config vars on OS X now that we know we need a compiler.
|
205 |
+
# This is primarily to support Pythons from binary
|
206 |
+
# installers. The kind and paths to build tools on
|
207 |
+
# the user system may vary significantly from the system
|
208 |
+
# that Python itself was built on. Also the user OS
|
209 |
+
# version and build tools may not support the same set
|
210 |
+
# of CPU architectures for universal builds.
|
211 |
+
global _config_vars
|
212 |
+
# Use get_config_var() to ensure _config_vars is initialized.
|
213 |
+
if not get_config_var('CUSTOMIZED_OSX_COMPILER'):
|
214 |
+
import _osx_support
|
215 |
+
_osx_support.customize_compiler(_config_vars)
|
216 |
+
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
|
217 |
+
|
218 |
+
(cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
|
219 |
+
get_config_vars('CC', 'CXX', 'CFLAGS',
|
220 |
+
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
|
221 |
+
|
222 |
+
if 'CC' in os.environ:
|
223 |
+
newcc = os.environ['CC']
|
224 |
+
if('LDSHARED' not in os.environ
|
225 |
+
and ldshared.startswith(cc)):
|
226 |
+
# If CC is overridden, use that as the default
|
227 |
+
# command for LDSHARED as well
|
228 |
+
ldshared = newcc + ldshared[len(cc):]
|
229 |
+
cc = newcc
|
230 |
+
if 'CXX' in os.environ:
|
231 |
+
cxx = os.environ['CXX']
|
232 |
+
if 'LDSHARED' in os.environ:
|
233 |
+
ldshared = os.environ['LDSHARED']
|
234 |
+
if 'CPP' in os.environ:
|
235 |
+
cpp = os.environ['CPP']
|
236 |
+
else:
|
237 |
+
cpp = cc + " -E" # not always
|
238 |
+
if 'LDFLAGS' in os.environ:
|
239 |
+
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
|
240 |
+
if 'CFLAGS' in os.environ:
|
241 |
+
cflags = cflags + ' ' + os.environ['CFLAGS']
|
242 |
+
ldshared = ldshared + ' ' + os.environ['CFLAGS']
|
243 |
+
if 'CPPFLAGS' in os.environ:
|
244 |
+
cpp = cpp + ' ' + os.environ['CPPFLAGS']
|
245 |
+
cflags = cflags + ' ' + os.environ['CPPFLAGS']
|
246 |
+
ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
|
247 |
+
if 'AR' in os.environ:
|
248 |
+
ar = os.environ['AR']
|
249 |
+
if 'ARFLAGS' in os.environ:
|
250 |
+
archiver = ar + ' ' + os.environ['ARFLAGS']
|
251 |
+
else:
|
252 |
+
archiver = ar + ' ' + ar_flags
|
253 |
+
|
254 |
+
cc_cmd = cc + ' ' + cflags
|
255 |
+
compiler.set_executables(
|
256 |
+
preprocessor=cpp,
|
257 |
+
compiler=cc_cmd,
|
258 |
+
compiler_so=cc_cmd + ' ' + ccshared,
|
259 |
+
compiler_cxx=cxx,
|
260 |
+
linker_so=ldshared,
|
261 |
+
linker_exe=cc,
|
262 |
+
archiver=archiver)
|
263 |
+
|
264 |
+
if 'RANLIB' in os.environ and compiler.executables.get('ranlib', None):
|
265 |
+
compiler.set_executables(ranlib=os.environ['RANLIB'])
|
266 |
+
|
267 |
+
compiler.shared_lib_extension = shlib_suffix
|
268 |
+
|
269 |
+
|
270 |
+
def get_config_h_filename():
|
271 |
+
"""Return full pathname of installed pyconfig.h file."""
|
272 |
+
if python_build:
|
273 |
+
if os.name == "nt":
|
274 |
+
inc_dir = os.path.join(_sys_home or project_base, "PC")
|
275 |
+
else:
|
276 |
+
inc_dir = _sys_home or project_base
|
277 |
+
else:
|
278 |
+
inc_dir = get_python_inc(plat_specific=1)
|
279 |
+
|
280 |
+
return os.path.join(inc_dir, 'pyconfig.h')
|
281 |
+
|
282 |
+
|
283 |
+
# Allow this value to be patched by pkgsrc. Ref pypa/distutils#16.
|
284 |
+
_makefile_tmpl = 'config-{python_ver}{build_flags}{multiarch}'
|
285 |
+
|
286 |
+
|
287 |
+
def get_makefile_filename():
|
288 |
+
"""Return full pathname of installed Makefile from the Python build."""
|
289 |
+
if python_build:
|
290 |
+
return os.path.join(_sys_home or project_base, "Makefile")
|
291 |
+
lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
|
292 |
+
multiarch = (
|
293 |
+
'-%s' % sys.implementation._multiarch
|
294 |
+
if hasattr(sys.implementation, '_multiarch') else ''
|
295 |
+
)
|
296 |
+
config_file = _makefile_tmpl.format(
|
297 |
+
python_ver=get_python_version(),
|
298 |
+
build_flags=build_flags,
|
299 |
+
multiarch=multiarch,
|
300 |
+
)
|
301 |
+
return os.path.join(lib_dir, config_file, 'Makefile')
|
302 |
+
|
303 |
+
|
304 |
+
def parse_config_h(fp, g=None):
|
305 |
+
"""Parse a config.h-style file.
|
306 |
+
|
307 |
+
A dictionary containing name/value pairs is returned. If an
|
308 |
+
optional dictionary is passed in as the second argument, it is
|
309 |
+
used instead of a new dictionary.
|
310 |
+
"""
|
311 |
+
if g is None:
|
312 |
+
g = {}
|
313 |
+
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
|
314 |
+
undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
|
315 |
+
#
|
316 |
+
while True:
|
317 |
+
line = fp.readline()
|
318 |
+
if not line:
|
319 |
+
break
|
320 |
+
m = define_rx.match(line)
|
321 |
+
if m:
|
322 |
+
n, v = m.group(1, 2)
|
323 |
+
try: v = int(v)
|
324 |
+
except ValueError: pass
|
325 |
+
g[n] = v
|
326 |
+
else:
|
327 |
+
m = undef_rx.match(line)
|
328 |
+
if m:
|
329 |
+
g[m.group(1)] = 0
|
330 |
+
return g
|
331 |
+
|
332 |
+
|
333 |
+
# Regexes needed for parsing Makefile (and similar syntaxes,
|
334 |
+
# like old-style Setup files).
|
335 |
+
_variable_rx = re.compile(r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
|
336 |
+
_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
|
337 |
+
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
|
338 |
+
|
339 |
+
def parse_makefile(fn, g=None):
|
340 |
+
"""Parse a Makefile-style file.
|
341 |
+
|
342 |
+
A dictionary containing name/value pairs is returned. If an
|
343 |
+
optional dictionary is passed in as the second argument, it is
|
344 |
+
used instead of a new dictionary.
|
345 |
+
"""
|
346 |
+
from distutils.text_file import TextFile
|
347 |
+
fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
|
348 |
+
|
349 |
+
if g is None:
|
350 |
+
g = {}
|
351 |
+
done = {}
|
352 |
+
notdone = {}
|
353 |
+
|
354 |
+
while True:
|
355 |
+
line = fp.readline()
|
356 |
+
if line is None: # eof
|
357 |
+
break
|
358 |
+
m = _variable_rx.match(line)
|
359 |
+
if m:
|
360 |
+
n, v = m.group(1, 2)
|
361 |
+
v = v.strip()
|
362 |
+
# `$$' is a literal `$' in make
|
363 |
+
tmpv = v.replace('$$', '')
|
364 |
+
|
365 |
+
if "$" in tmpv:
|
366 |
+
notdone[n] = v
|
367 |
+
else:
|
368 |
+
try:
|
369 |
+
v = int(v)
|
370 |
+
except ValueError:
|
371 |
+
# insert literal `$'
|
372 |
+
done[n] = v.replace('$$', '$')
|
373 |
+
else:
|
374 |
+
done[n] = v
|
375 |
+
|
376 |
+
# Variables with a 'PY_' prefix in the makefile. These need to
|
377 |
+
# be made available without that prefix through sysconfig.
|
378 |
+
# Special care is needed to ensure that variable expansion works, even
|
379 |
+
# if the expansion uses the name without a prefix.
|
380 |
+
renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
|
381 |
+
|
382 |
+
# do variable interpolation here
|
383 |
+
while notdone:
|
384 |
+
for name in list(notdone):
|
385 |
+
value = notdone[name]
|
386 |
+
m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
|
387 |
+
if m:
|
388 |
+
n = m.group(1)
|
389 |
+
found = True
|
390 |
+
if n in done:
|
391 |
+
item = str(done[n])
|
392 |
+
elif n in notdone:
|
393 |
+
# get it on a subsequent round
|
394 |
+
found = False
|
395 |
+
elif n in os.environ:
|
396 |
+
# do it like make: fall back to environment
|
397 |
+
item = os.environ[n]
|
398 |
+
|
399 |
+
elif n in renamed_variables:
|
400 |
+
if name.startswith('PY_') and name[3:] in renamed_variables:
|
401 |
+
item = ""
|
402 |
+
|
403 |
+
elif 'PY_' + n in notdone:
|
404 |
+
found = False
|
405 |
+
|
406 |
+
else:
|
407 |
+
item = str(done['PY_' + n])
|
408 |
+
else:
|
409 |
+
done[n] = item = ""
|
410 |
+
if found:
|
411 |
+
after = value[m.end():]
|
412 |
+
value = value[:m.start()] + item + after
|
413 |
+
if "$" in after:
|
414 |
+
notdone[name] = value
|
415 |
+
else:
|
416 |
+
try: value = int(value)
|
417 |
+
except ValueError:
|
418 |
+
done[name] = value.strip()
|
419 |
+
else:
|
420 |
+
done[name] = value
|
421 |
+
del notdone[name]
|
422 |
+
|
423 |
+
if name.startswith('PY_') \
|
424 |
+
and name[3:] in renamed_variables:
|
425 |
+
|
426 |
+
name = name[3:]
|
427 |
+
if name not in done:
|
428 |
+
done[name] = value
|
429 |
+
else:
|
430 |
+
# bogus variable reference; just drop it since we can't deal
|
431 |
+
del notdone[name]
|
432 |
+
|
433 |
+
fp.close()
|
434 |
+
|
435 |
+
# strip spurious spaces
|
436 |
+
for k, v in done.items():
|
437 |
+
if isinstance(v, str):
|
438 |
+
done[k] = v.strip()
|
439 |
+
|
440 |
+
# save the results in the global dictionary
|
441 |
+
g.update(done)
|
442 |
+
return g
|
443 |
+
|
444 |
+
|
445 |
+
def expand_makefile_vars(s, vars):
|
446 |
+
"""Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
|
447 |
+
'string' according to 'vars' (a dictionary mapping variable names to
|
448 |
+
values). Variables not present in 'vars' are silently expanded to the
|
449 |
+
empty string. The variable values in 'vars' should not contain further
|
450 |
+
variable expansions; if 'vars' is the output of 'parse_makefile()',
|
451 |
+
you're fine. Returns a variable-expanded version of 's'.
|
452 |
+
"""
|
453 |
+
|
454 |
+
# This algorithm does multiple expansion, so if vars['foo'] contains
|
455 |
+
# "${bar}", it will expand ${foo} to ${bar}, and then expand
|
456 |
+
# ${bar}... and so forth. This is fine as long as 'vars' comes from
|
457 |
+
# 'parse_makefile()', which takes care of such expansions eagerly,
|
458 |
+
# according to make's variable expansion semantics.
|
459 |
+
|
460 |
+
while True:
|
461 |
+
m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
|
462 |
+
if m:
|
463 |
+
(beg, end) = m.span()
|
464 |
+
s = s[0:beg] + vars.get(m.group(1)) + s[end:]
|
465 |
+
else:
|
466 |
+
break
|
467 |
+
return s
|
468 |
+
|
469 |
+
|
470 |
+
_config_vars = None
|
471 |
+
|
472 |
+
|
473 |
+
_sysconfig_name_tmpl = '_sysconfigdata_{abi}_{platform}_{multiarch}'
|
474 |
+
|
475 |
+
|
476 |
+
def _init_posix():
|
477 |
+
"""Initialize the module as appropriate for POSIX systems."""
|
478 |
+
# _sysconfigdata is generated at build time, see the sysconfig module
|
479 |
+
name = os.environ.get(
|
480 |
+
'_PYTHON_SYSCONFIGDATA_NAME',
|
481 |
+
_sysconfig_name_tmpl.format(
|
482 |
+
abi=sys.abiflags,
|
483 |
+
platform=sys.platform,
|
484 |
+
multiarch=getattr(sys.implementation, '_multiarch', ''),
|
485 |
+
),
|
486 |
+
)
|
487 |
+
try:
|
488 |
+
_temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
|
489 |
+
except ImportError:
|
490 |
+
# Python 3.5 and pypy 7.3.1
|
491 |
+
_temp = __import__(
|
492 |
+
'_sysconfigdata', globals(), locals(), ['build_time_vars'], 0)
|
493 |
+
build_time_vars = _temp.build_time_vars
|
494 |
+
global _config_vars
|
495 |
+
_config_vars = {}
|
496 |
+
_config_vars.update(build_time_vars)
|
497 |
+
|
498 |
+
|
499 |
+
def _init_nt():
|
500 |
+
"""Initialize the module as appropriate for NT"""
|
501 |
+
g = {}
|
502 |
+
# set basic install directories
|
503 |
+
g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
|
504 |
+
g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
|
505 |
+
|
506 |
+
# XXX hmmm.. a normal install puts include files here
|
507 |
+
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
|
508 |
+
|
509 |
+
g['EXT_SUFFIX'] = _imp.extension_suffixes()[0]
|
510 |
+
g['EXE'] = ".exe"
|
511 |
+
g['VERSION'] = get_python_version().replace(".", "")
|
512 |
+
g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
|
513 |
+
|
514 |
+
global _config_vars
|
515 |
+
_config_vars = g
|
516 |
+
|
517 |
+
|
518 |
+
def get_config_vars(*args):
|
519 |
+
"""With no arguments, return a dictionary of all configuration
|
520 |
+
variables relevant for the current platform. Generally this includes
|
521 |
+
everything needed to build extensions and install both pure modules and
|
522 |
+
extensions. On Unix, this means every variable defined in Python's
|
523 |
+
installed Makefile; on Windows it's a much smaller set.
|
524 |
+
|
525 |
+
With arguments, return a list of values that result from looking up
|
526 |
+
each argument in the configuration variable dictionary.
|
527 |
+
"""
|
528 |
+
global _config_vars
|
529 |
+
if _config_vars is None:
|
530 |
+
func = globals().get("_init_" + os.name)
|
531 |
+
if func:
|
532 |
+
func()
|
533 |
+
else:
|
534 |
+
_config_vars = {}
|
535 |
+
|
536 |
+
# Normalized versions of prefix and exec_prefix are handy to have;
|
537 |
+
# in fact, these are the standard versions used most places in the
|
538 |
+
# Distutils.
|
539 |
+
_config_vars['prefix'] = PREFIX
|
540 |
+
_config_vars['exec_prefix'] = EXEC_PREFIX
|
541 |
+
|
542 |
+
if not IS_PYPY:
|
543 |
+
# For backward compatibility, see issue19555
|
544 |
+
SO = _config_vars.get('EXT_SUFFIX')
|
545 |
+
if SO is not None:
|
546 |
+
_config_vars['SO'] = SO
|
547 |
+
|
548 |
+
# Always convert srcdir to an absolute path
|
549 |
+
srcdir = _config_vars.get('srcdir', project_base)
|
550 |
+
if os.name == 'posix':
|
551 |
+
if python_build:
|
552 |
+
# If srcdir is a relative path (typically '.' or '..')
|
553 |
+
# then it should be interpreted relative to the directory
|
554 |
+
# containing Makefile.
|
555 |
+
base = os.path.dirname(get_makefile_filename())
|
556 |
+
srcdir = os.path.join(base, srcdir)
|
557 |
+
else:
|
558 |
+
# srcdir is not meaningful since the installation is
|
559 |
+
# spread about the filesystem. We choose the
|
560 |
+
# directory containing the Makefile since we know it
|
561 |
+
# exists.
|
562 |
+
srcdir = os.path.dirname(get_makefile_filename())
|
563 |
+
_config_vars['srcdir'] = os.path.abspath(os.path.normpath(srcdir))
|
564 |
+
|
565 |
+
# Convert srcdir into an absolute path if it appears necessary.
|
566 |
+
# Normally it is relative to the build directory. However, during
|
567 |
+
# testing, for example, we might be running a non-installed python
|
568 |
+
# from a different directory.
|
569 |
+
if python_build and os.name == "posix":
|
570 |
+
base = project_base
|
571 |
+
if (not os.path.isabs(_config_vars['srcdir']) and
|
572 |
+
base != os.getcwd()):
|
573 |
+
# srcdir is relative and we are not in the same directory
|
574 |
+
# as the executable. Assume executable is in the build
|
575 |
+
# directory and make srcdir absolute.
|
576 |
+
srcdir = os.path.join(base, _config_vars['srcdir'])
|
577 |
+
_config_vars['srcdir'] = os.path.normpath(srcdir)
|
578 |
+
|
579 |
+
# OS X platforms require special customization to handle
|
580 |
+
# multi-architecture, multi-os-version installers
|
581 |
+
if sys.platform == 'darwin':
|
582 |
+
import _osx_support
|
583 |
+
_osx_support.customize_config_vars(_config_vars)
|
584 |
+
|
585 |
+
if args:
|
586 |
+
vals = []
|
587 |
+
for name in args:
|
588 |
+
vals.append(_config_vars.get(name))
|
589 |
+
return vals
|
590 |
+
else:
|
591 |
+
return _config_vars
|
592 |
+
|
593 |
+
def get_config_var(name):
|
594 |
+
"""Return the value of a single variable using the dictionary
|
595 |
+
returned by 'get_config_vars()'. Equivalent to
|
596 |
+
get_config_vars().get(name)
|
597 |
+
"""
|
598 |
+
if name == 'SO':
|
599 |
+
import warnings
|
600 |
+
warnings.warn('SO is deprecated, use EXT_SUFFIX', DeprecationWarning, 2)
|
601 |
+
return get_config_vars().get(name)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/text_file.py
ADDED
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""text_file
|
2 |
+
|
3 |
+
provides the TextFile class, which gives an interface to text files
|
4 |
+
that (optionally) takes care of stripping comments, ignoring blank
|
5 |
+
lines, and joining lines with backslashes."""
|
6 |
+
|
7 |
+
import sys, io
|
8 |
+
|
9 |
+
|
10 |
+
class TextFile:
|
11 |
+
"""Provides a file-like object that takes care of all the things you
|
12 |
+
commonly want to do when processing a text file that has some
|
13 |
+
line-by-line syntax: strip comments (as long as "#" is your
|
14 |
+
comment character), skip blank lines, join adjacent lines by
|
15 |
+
escaping the newline (ie. backslash at end of line), strip
|
16 |
+
leading and/or trailing whitespace. All of these are optional
|
17 |
+
and independently controllable.
|
18 |
+
|
19 |
+
Provides a 'warn()' method so you can generate warning messages that
|
20 |
+
report physical line number, even if the logical line in question
|
21 |
+
spans multiple physical lines. Also provides 'unreadline()' for
|
22 |
+
implementing line-at-a-time lookahead.
|
23 |
+
|
24 |
+
Constructor is called as:
|
25 |
+
|
26 |
+
TextFile (filename=None, file=None, **options)
|
27 |
+
|
28 |
+
It bombs (RuntimeError) if both 'filename' and 'file' are None;
|
29 |
+
'filename' should be a string, and 'file' a file object (or
|
30 |
+
something that provides 'readline()' and 'close()' methods). It is
|
31 |
+
recommended that you supply at least 'filename', so that TextFile
|
32 |
+
can include it in warning messages. If 'file' is not supplied,
|
33 |
+
TextFile creates its own using 'io.open()'.
|
34 |
+
|
35 |
+
The options are all boolean, and affect the value returned by
|
36 |
+
'readline()':
|
37 |
+
strip_comments [default: true]
|
38 |
+
strip from "#" to end-of-line, as well as any whitespace
|
39 |
+
leading up to the "#" -- unless it is escaped by a backslash
|
40 |
+
lstrip_ws [default: false]
|
41 |
+
strip leading whitespace from each line before returning it
|
42 |
+
rstrip_ws [default: true]
|
43 |
+
strip trailing whitespace (including line terminator!) from
|
44 |
+
each line before returning it
|
45 |
+
skip_blanks [default: true}
|
46 |
+
skip lines that are empty *after* stripping comments and
|
47 |
+
whitespace. (If both lstrip_ws and rstrip_ws are false,
|
48 |
+
then some lines may consist of solely whitespace: these will
|
49 |
+
*not* be skipped, even if 'skip_blanks' is true.)
|
50 |
+
join_lines [default: false]
|
51 |
+
if a backslash is the last non-newline character on a line
|
52 |
+
after stripping comments and whitespace, join the following line
|
53 |
+
to it to form one "logical line"; if N consecutive lines end
|
54 |
+
with a backslash, then N+1 physical lines will be joined to
|
55 |
+
form one logical line.
|
56 |
+
collapse_join [default: false]
|
57 |
+
strip leading whitespace from lines that are joined to their
|
58 |
+
predecessor; only matters if (join_lines and not lstrip_ws)
|
59 |
+
errors [default: 'strict']
|
60 |
+
error handler used to decode the file content
|
61 |
+
|
62 |
+
Note that since 'rstrip_ws' can strip the trailing newline, the
|
63 |
+
semantics of 'readline()' must differ from those of the builtin file
|
64 |
+
object's 'readline()' method! In particular, 'readline()' returns
|
65 |
+
None for end-of-file: an empty string might just be a blank line (or
|
66 |
+
an all-whitespace line), if 'rstrip_ws' is true but 'skip_blanks' is
|
67 |
+
not."""
|
68 |
+
|
69 |
+
default_options = { 'strip_comments': 1,
|
70 |
+
'skip_blanks': 1,
|
71 |
+
'lstrip_ws': 0,
|
72 |
+
'rstrip_ws': 1,
|
73 |
+
'join_lines': 0,
|
74 |
+
'collapse_join': 0,
|
75 |
+
'errors': 'strict',
|
76 |
+
}
|
77 |
+
|
78 |
+
def __init__(self, filename=None, file=None, **options):
|
79 |
+
"""Construct a new TextFile object. At least one of 'filename'
|
80 |
+
(a string) and 'file' (a file-like object) must be supplied.
|
81 |
+
They keyword argument options are described above and affect
|
82 |
+
the values returned by 'readline()'."""
|
83 |
+
if filename is None and file is None:
|
84 |
+
raise RuntimeError("you must supply either or both of 'filename' and 'file'")
|
85 |
+
|
86 |
+
# set values for all options -- either from client option hash
|
87 |
+
# or fallback to default_options
|
88 |
+
for opt in self.default_options.keys():
|
89 |
+
if opt in options:
|
90 |
+
setattr(self, opt, options[opt])
|
91 |
+
else:
|
92 |
+
setattr(self, opt, self.default_options[opt])
|
93 |
+
|
94 |
+
# sanity check client option hash
|
95 |
+
for opt in options.keys():
|
96 |
+
if opt not in self.default_options:
|
97 |
+
raise KeyError("invalid TextFile option '%s'" % opt)
|
98 |
+
|
99 |
+
if file is None:
|
100 |
+
self.open(filename)
|
101 |
+
else:
|
102 |
+
self.filename = filename
|
103 |
+
self.file = file
|
104 |
+
self.current_line = 0 # assuming that file is at BOF!
|
105 |
+
|
106 |
+
# 'linebuf' is a stack of lines that will be emptied before we
|
107 |
+
# actually read from the file; it's only populated by an
|
108 |
+
# 'unreadline()' operation
|
109 |
+
self.linebuf = []
|
110 |
+
|
111 |
+
def open(self, filename):
|
112 |
+
"""Open a new file named 'filename'. This overrides both the
|
113 |
+
'filename' and 'file' arguments to the constructor."""
|
114 |
+
self.filename = filename
|
115 |
+
self.file = io.open(self.filename, 'r', errors=self.errors)
|
116 |
+
self.current_line = 0
|
117 |
+
|
118 |
+
def close(self):
|
119 |
+
"""Close the current file and forget everything we know about it
|
120 |
+
(filename, current line number)."""
|
121 |
+
file = self.file
|
122 |
+
self.file = None
|
123 |
+
self.filename = None
|
124 |
+
self.current_line = None
|
125 |
+
file.close()
|
126 |
+
|
127 |
+
def gen_error(self, msg, line=None):
|
128 |
+
outmsg = []
|
129 |
+
if line is None:
|
130 |
+
line = self.current_line
|
131 |
+
outmsg.append(self.filename + ", ")
|
132 |
+
if isinstance(line, (list, tuple)):
|
133 |
+
outmsg.append("lines %d-%d: " % tuple(line))
|
134 |
+
else:
|
135 |
+
outmsg.append("line %d: " % line)
|
136 |
+
outmsg.append(str(msg))
|
137 |
+
return "".join(outmsg)
|
138 |
+
|
139 |
+
def error(self, msg, line=None):
|
140 |
+
raise ValueError("error: " + self.gen_error(msg, line))
|
141 |
+
|
142 |
+
def warn(self, msg, line=None):
|
143 |
+
"""Print (to stderr) a warning message tied to the current logical
|
144 |
+
line in the current file. If the current logical line in the
|
145 |
+
file spans multiple physical lines, the warning refers to the
|
146 |
+
whole range, eg. "lines 3-5". If 'line' supplied, it overrides
|
147 |
+
the current line number; it may be a list or tuple to indicate a
|
148 |
+
range of physical lines, or an integer for a single physical
|
149 |
+
line."""
|
150 |
+
sys.stderr.write("warning: " + self.gen_error(msg, line) + "\n")
|
151 |
+
|
152 |
+
def readline(self):
|
153 |
+
"""Read and return a single logical line from the current file (or
|
154 |
+
from an internal buffer if lines have previously been "unread"
|
155 |
+
with 'unreadline()'). If the 'join_lines' option is true, this
|
156 |
+
may involve reading multiple physical lines concatenated into a
|
157 |
+
single string. Updates the current line number, so calling
|
158 |
+
'warn()' after 'readline()' emits a warning about the physical
|
159 |
+
line(s) just read. Returns None on end-of-file, since the empty
|
160 |
+
string can occur if 'rstrip_ws' is true but 'strip_blanks' is
|
161 |
+
not."""
|
162 |
+
# If any "unread" lines waiting in 'linebuf', return the top
|
163 |
+
# one. (We don't actually buffer read-ahead data -- lines only
|
164 |
+
# get put in 'linebuf' if the client explicitly does an
|
165 |
+
# 'unreadline()'.
|
166 |
+
if self.linebuf:
|
167 |
+
line = self.linebuf[-1]
|
168 |
+
del self.linebuf[-1]
|
169 |
+
return line
|
170 |
+
|
171 |
+
buildup_line = ''
|
172 |
+
|
173 |
+
while True:
|
174 |
+
# read the line, make it None if EOF
|
175 |
+
line = self.file.readline()
|
176 |
+
if line == '':
|
177 |
+
line = None
|
178 |
+
|
179 |
+
if self.strip_comments and line:
|
180 |
+
|
181 |
+
# Look for the first "#" in the line. If none, never
|
182 |
+
# mind. If we find one and it's the first character, or
|
183 |
+
# is not preceded by "\", then it starts a comment --
|
184 |
+
# strip the comment, strip whitespace before it, and
|
185 |
+
# carry on. Otherwise, it's just an escaped "#", so
|
186 |
+
# unescape it (and any other escaped "#"'s that might be
|
187 |
+
# lurking in there) and otherwise leave the line alone.
|
188 |
+
|
189 |
+
pos = line.find("#")
|
190 |
+
if pos == -1: # no "#" -- no comments
|
191 |
+
pass
|
192 |
+
|
193 |
+
# It's definitely a comment -- either "#" is the first
|
194 |
+
# character, or it's elsewhere and unescaped.
|
195 |
+
elif pos == 0 or line[pos-1] != "\\":
|
196 |
+
# Have to preserve the trailing newline, because it's
|
197 |
+
# the job of a later step (rstrip_ws) to remove it --
|
198 |
+
# and if rstrip_ws is false, we'd better preserve it!
|
199 |
+
# (NB. this means that if the final line is all comment
|
200 |
+
# and has no trailing newline, we will think that it's
|
201 |
+
# EOF; I think that's OK.)
|
202 |
+
eol = (line[-1] == '\n') and '\n' or ''
|
203 |
+
line = line[0:pos] + eol
|
204 |
+
|
205 |
+
# If all that's left is whitespace, then skip line
|
206 |
+
# *now*, before we try to join it to 'buildup_line' --
|
207 |
+
# that way constructs like
|
208 |
+
# hello \\
|
209 |
+
# # comment that should be ignored
|
210 |
+
# there
|
211 |
+
# result in "hello there".
|
212 |
+
if line.strip() == "":
|
213 |
+
continue
|
214 |
+
else: # it's an escaped "#"
|
215 |
+
line = line.replace("\\#", "#")
|
216 |
+
|
217 |
+
# did previous line end with a backslash? then accumulate
|
218 |
+
if self.join_lines and buildup_line:
|
219 |
+
# oops: end of file
|
220 |
+
if line is None:
|
221 |
+
self.warn("continuation line immediately precedes "
|
222 |
+
"end-of-file")
|
223 |
+
return buildup_line
|
224 |
+
|
225 |
+
if self.collapse_join:
|
226 |
+
line = line.lstrip()
|
227 |
+
line = buildup_line + line
|
228 |
+
|
229 |
+
# careful: pay attention to line number when incrementing it
|
230 |
+
if isinstance(self.current_line, list):
|
231 |
+
self.current_line[1] = self.current_line[1] + 1
|
232 |
+
else:
|
233 |
+
self.current_line = [self.current_line,
|
234 |
+
self.current_line + 1]
|
235 |
+
# just an ordinary line, read it as usual
|
236 |
+
else:
|
237 |
+
if line is None: # eof
|
238 |
+
return None
|
239 |
+
|
240 |
+
# still have to be careful about incrementing the line number!
|
241 |
+
if isinstance(self.current_line, list):
|
242 |
+
self.current_line = self.current_line[1] + 1
|
243 |
+
else:
|
244 |
+
self.current_line = self.current_line + 1
|
245 |
+
|
246 |
+
# strip whitespace however the client wants (leading and
|
247 |
+
# trailing, or one or the other, or neither)
|
248 |
+
if self.lstrip_ws and self.rstrip_ws:
|
249 |
+
line = line.strip()
|
250 |
+
elif self.lstrip_ws:
|
251 |
+
line = line.lstrip()
|
252 |
+
elif self.rstrip_ws:
|
253 |
+
line = line.rstrip()
|
254 |
+
|
255 |
+
# blank line (whether we rstrip'ed or not)? skip to next line
|
256 |
+
# if appropriate
|
257 |
+
if (line == '' or line == '\n') and self.skip_blanks:
|
258 |
+
continue
|
259 |
+
|
260 |
+
if self.join_lines:
|
261 |
+
if line[-1] == '\\':
|
262 |
+
buildup_line = line[:-1]
|
263 |
+
continue
|
264 |
+
|
265 |
+
if line[-2:] == '\\\n':
|
266 |
+
buildup_line = line[0:-2] + '\n'
|
267 |
+
continue
|
268 |
+
|
269 |
+
# well, I guess there's some actual content there: return it
|
270 |
+
return line
|
271 |
+
|
272 |
+
def readlines(self):
|
273 |
+
"""Read and return the list of all logical lines remaining in the
|
274 |
+
current file."""
|
275 |
+
lines = []
|
276 |
+
while True:
|
277 |
+
line = self.readline()
|
278 |
+
if line is None:
|
279 |
+
return lines
|
280 |
+
lines.append(line)
|
281 |
+
|
282 |
+
def unreadline(self, line):
|
283 |
+
"""Push 'line' (a string) onto an internal buffer that will be
|
284 |
+
checked by future 'readline()' calls. Handy for implementing
|
285 |
+
a parser with line-at-a-time lookahead."""
|
286 |
+
self.linebuf.append(line)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/util.py
ADDED
@@ -0,0 +1,548 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.util
|
2 |
+
|
3 |
+
Miscellaneous utility functions -- anything that doesn't fit into
|
4 |
+
one of the other *util.py modules.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import os
|
8 |
+
import re
|
9 |
+
import importlib.util
|
10 |
+
import string
|
11 |
+
import sys
|
12 |
+
from distutils.errors import DistutilsPlatformError
|
13 |
+
from distutils.dep_util import newer
|
14 |
+
from distutils.spawn import spawn
|
15 |
+
from distutils import log
|
16 |
+
from distutils.errors import DistutilsByteCompileError
|
17 |
+
from .py35compat import _optim_args_from_interpreter_flags
|
18 |
+
|
19 |
+
|
20 |
+
def get_host_platform():
|
21 |
+
"""Return a string that identifies the current platform. This is used mainly to
|
22 |
+
distinguish platform-specific build directories and platform-specific built
|
23 |
+
distributions. Typically includes the OS name and version and the
|
24 |
+
architecture (as supplied by 'os.uname()'), although the exact information
|
25 |
+
included depends on the OS; eg. on Linux, the kernel version isn't
|
26 |
+
particularly important.
|
27 |
+
|
28 |
+
Examples of returned values:
|
29 |
+
linux-i586
|
30 |
+
linux-alpha (?)
|
31 |
+
solaris-2.6-sun4u
|
32 |
+
|
33 |
+
Windows will return one of:
|
34 |
+
win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
|
35 |
+
win32 (all others - specifically, sys.platform is returned)
|
36 |
+
|
37 |
+
For other non-POSIX platforms, currently just returns 'sys.platform'.
|
38 |
+
|
39 |
+
"""
|
40 |
+
if os.name == 'nt':
|
41 |
+
if 'amd64' in sys.version.lower():
|
42 |
+
return 'win-amd64'
|
43 |
+
if '(arm)' in sys.version.lower():
|
44 |
+
return 'win-arm32'
|
45 |
+
if '(arm64)' in sys.version.lower():
|
46 |
+
return 'win-arm64'
|
47 |
+
return sys.platform
|
48 |
+
|
49 |
+
# Set for cross builds explicitly
|
50 |
+
if "_PYTHON_HOST_PLATFORM" in os.environ:
|
51 |
+
return os.environ["_PYTHON_HOST_PLATFORM"]
|
52 |
+
|
53 |
+
if os.name != "posix" or not hasattr(os, 'uname'):
|
54 |
+
# XXX what about the architecture? NT is Intel or Alpha,
|
55 |
+
# Mac OS is M68k or PPC, etc.
|
56 |
+
return sys.platform
|
57 |
+
|
58 |
+
# Try to distinguish various flavours of Unix
|
59 |
+
|
60 |
+
(osname, host, release, version, machine) = os.uname()
|
61 |
+
|
62 |
+
# Convert the OS name to lowercase, remove '/' characters, and translate
|
63 |
+
# spaces (for "Power Macintosh")
|
64 |
+
osname = osname.lower().replace('/', '')
|
65 |
+
machine = machine.replace(' ', '_')
|
66 |
+
machine = machine.replace('/', '-')
|
67 |
+
|
68 |
+
if osname[:5] == "linux":
|
69 |
+
# At least on Linux/Intel, 'machine' is the processor --
|
70 |
+
# i386, etc.
|
71 |
+
# XXX what about Alpha, SPARC, etc?
|
72 |
+
return "%s-%s" % (osname, machine)
|
73 |
+
elif osname[:5] == "sunos":
|
74 |
+
if release[0] >= "5": # SunOS 5 == Solaris 2
|
75 |
+
osname = "solaris"
|
76 |
+
release = "%d.%s" % (int(release[0]) - 3, release[2:])
|
77 |
+
# We can't use "platform.architecture()[0]" because a
|
78 |
+
# bootstrap problem. We use a dict to get an error
|
79 |
+
# if some suspicious happens.
|
80 |
+
bitness = {2147483647:"32bit", 9223372036854775807:"64bit"}
|
81 |
+
machine += ".%s" % bitness[sys.maxsize]
|
82 |
+
# fall through to standard osname-release-machine representation
|
83 |
+
elif osname[:3] == "aix":
|
84 |
+
from .py38compat import aix_platform
|
85 |
+
return aix_platform(osname, version, release)
|
86 |
+
elif osname[:6] == "cygwin":
|
87 |
+
osname = "cygwin"
|
88 |
+
rel_re = re.compile (r'[\d.]+', re.ASCII)
|
89 |
+
m = rel_re.match(release)
|
90 |
+
if m:
|
91 |
+
release = m.group()
|
92 |
+
elif osname[:6] == "darwin":
|
93 |
+
import _osx_support, distutils.sysconfig
|
94 |
+
osname, release, machine = _osx_support.get_platform_osx(
|
95 |
+
distutils.sysconfig.get_config_vars(),
|
96 |
+
osname, release, machine)
|
97 |
+
|
98 |
+
return "%s-%s-%s" % (osname, release, machine)
|
99 |
+
|
100 |
+
def get_platform():
|
101 |
+
if os.name == 'nt':
|
102 |
+
TARGET_TO_PLAT = {
|
103 |
+
'x86' : 'win32',
|
104 |
+
'x64' : 'win-amd64',
|
105 |
+
'arm' : 'win-arm32',
|
106 |
+
'arm64': 'win-arm64',
|
107 |
+
}
|
108 |
+
return TARGET_TO_PLAT.get(os.environ.get('VSCMD_ARG_TGT_ARCH')) or get_host_platform()
|
109 |
+
else:
|
110 |
+
return get_host_platform()
|
111 |
+
|
112 |
+
|
113 |
+
if sys.platform == 'darwin':
|
114 |
+
_syscfg_macosx_ver = None # cache the version pulled from sysconfig
|
115 |
+
MACOSX_VERSION_VAR = 'MACOSX_DEPLOYMENT_TARGET'
|
116 |
+
|
117 |
+
def _clear_cached_macosx_ver():
|
118 |
+
"""For testing only. Do not call."""
|
119 |
+
global _syscfg_macosx_ver
|
120 |
+
_syscfg_macosx_ver = None
|
121 |
+
|
122 |
+
def get_macosx_target_ver_from_syscfg():
|
123 |
+
"""Get the version of macOS latched in the Python interpreter configuration.
|
124 |
+
Returns the version as a string or None if can't obtain one. Cached."""
|
125 |
+
global _syscfg_macosx_ver
|
126 |
+
if _syscfg_macosx_ver is None:
|
127 |
+
from distutils import sysconfig
|
128 |
+
ver = sysconfig.get_config_var(MACOSX_VERSION_VAR) or ''
|
129 |
+
if ver:
|
130 |
+
_syscfg_macosx_ver = ver
|
131 |
+
return _syscfg_macosx_ver
|
132 |
+
|
133 |
+
def get_macosx_target_ver():
|
134 |
+
"""Return the version of macOS for which we are building.
|
135 |
+
|
136 |
+
The target version defaults to the version in sysconfig latched at time
|
137 |
+
the Python interpreter was built, unless overridden by an environment
|
138 |
+
variable. If neither source has a value, then None is returned"""
|
139 |
+
|
140 |
+
syscfg_ver = get_macosx_target_ver_from_syscfg()
|
141 |
+
env_ver = os.environ.get(MACOSX_VERSION_VAR)
|
142 |
+
|
143 |
+
if env_ver:
|
144 |
+
# Validate overridden version against sysconfig version, if have both.
|
145 |
+
# Ensure that the deployment target of the build process is not less
|
146 |
+
# than 10.3 if the interpreter was built for 10.3 or later. This
|
147 |
+
# ensures extension modules are built with correct compatibility
|
148 |
+
# values, specifically LDSHARED which can use
|
149 |
+
# '-undefined dynamic_lookup' which only works on >= 10.3.
|
150 |
+
if syscfg_ver and split_version(syscfg_ver) >= [10, 3] and \
|
151 |
+
split_version(env_ver) < [10, 3]:
|
152 |
+
my_msg = ('$' + MACOSX_VERSION_VAR + ' mismatch: '
|
153 |
+
'now "%s" but "%s" during configure; '
|
154 |
+
'must use 10.3 or later'
|
155 |
+
% (env_ver, syscfg_ver))
|
156 |
+
raise DistutilsPlatformError(my_msg)
|
157 |
+
return env_ver
|
158 |
+
return syscfg_ver
|
159 |
+
|
160 |
+
|
161 |
+
def split_version(s):
|
162 |
+
"""Convert a dot-separated string into a list of numbers for comparisons"""
|
163 |
+
return [int(n) for n in s.split('.')]
|
164 |
+
|
165 |
+
|
166 |
+
def convert_path (pathname):
|
167 |
+
"""Return 'pathname' as a name that will work on the native filesystem,
|
168 |
+
i.e. split it on '/' and put it back together again using the current
|
169 |
+
directory separator. Needed because filenames in the setup script are
|
170 |
+
always supplied in Unix style, and have to be converted to the local
|
171 |
+
convention before we can actually use them in the filesystem. Raises
|
172 |
+
ValueError on non-Unix-ish systems if 'pathname' either starts or
|
173 |
+
ends with a slash.
|
174 |
+
"""
|
175 |
+
if os.sep == '/':
|
176 |
+
return pathname
|
177 |
+
if not pathname:
|
178 |
+
return pathname
|
179 |
+
if pathname[0] == '/':
|
180 |
+
raise ValueError("path '%s' cannot be absolute" % pathname)
|
181 |
+
if pathname[-1] == '/':
|
182 |
+
raise ValueError("path '%s' cannot end with '/'" % pathname)
|
183 |
+
|
184 |
+
paths = pathname.split('/')
|
185 |
+
while '.' in paths:
|
186 |
+
paths.remove('.')
|
187 |
+
if not paths:
|
188 |
+
return os.curdir
|
189 |
+
return os.path.join(*paths)
|
190 |
+
|
191 |
+
# convert_path ()
|
192 |
+
|
193 |
+
|
194 |
+
def change_root (new_root, pathname):
|
195 |
+
"""Return 'pathname' with 'new_root' prepended. If 'pathname' is
|
196 |
+
relative, this is equivalent to "os.path.join(new_root,pathname)".
|
197 |
+
Otherwise, it requires making 'pathname' relative and then joining the
|
198 |
+
two, which is tricky on DOS/Windows and Mac OS.
|
199 |
+
"""
|
200 |
+
if os.name == 'posix':
|
201 |
+
if not os.path.isabs(pathname):
|
202 |
+
return os.path.join(new_root, pathname)
|
203 |
+
else:
|
204 |
+
return os.path.join(new_root, pathname[1:])
|
205 |
+
|
206 |
+
elif os.name == 'nt':
|
207 |
+
(drive, path) = os.path.splitdrive(pathname)
|
208 |
+
if path[0] == '\\':
|
209 |
+
path = path[1:]
|
210 |
+
return os.path.join(new_root, path)
|
211 |
+
|
212 |
+
else:
|
213 |
+
raise DistutilsPlatformError("nothing known about platform '%s'" % os.name)
|
214 |
+
|
215 |
+
|
216 |
+
_environ_checked = 0
|
217 |
+
def check_environ ():
|
218 |
+
"""Ensure that 'os.environ' has all the environment variables we
|
219 |
+
guarantee that users can use in config files, command-line options,
|
220 |
+
etc. Currently this includes:
|
221 |
+
HOME - user's home directory (Unix only)
|
222 |
+
PLAT - description of the current platform, including hardware
|
223 |
+
and OS (see 'get_platform()')
|
224 |
+
"""
|
225 |
+
global _environ_checked
|
226 |
+
if _environ_checked:
|
227 |
+
return
|
228 |
+
|
229 |
+
if os.name == 'posix' and 'HOME' not in os.environ:
|
230 |
+
try:
|
231 |
+
import pwd
|
232 |
+
os.environ['HOME'] = pwd.getpwuid(os.getuid())[5]
|
233 |
+
except (ImportError, KeyError):
|
234 |
+
# bpo-10496: if the current user identifier doesn't exist in the
|
235 |
+
# password database, do nothing
|
236 |
+
pass
|
237 |
+
|
238 |
+
if 'PLAT' not in os.environ:
|
239 |
+
os.environ['PLAT'] = get_platform()
|
240 |
+
|
241 |
+
_environ_checked = 1
|
242 |
+
|
243 |
+
|
244 |
+
def subst_vars (s, local_vars):
|
245 |
+
"""
|
246 |
+
Perform variable substitution on 'string'.
|
247 |
+
Variables are indicated by format-style braces ("{var}").
|
248 |
+
Variable is substituted by the value found in the 'local_vars'
|
249 |
+
dictionary or in 'os.environ' if it's not in 'local_vars'.
|
250 |
+
'os.environ' is first checked/augmented to guarantee that it contains
|
251 |
+
certain values: see 'check_environ()'. Raise ValueError for any
|
252 |
+
variables not found in either 'local_vars' or 'os.environ'.
|
253 |
+
"""
|
254 |
+
check_environ()
|
255 |
+
lookup = dict(os.environ)
|
256 |
+
lookup.update((name, str(value)) for name, value in local_vars.items())
|
257 |
+
try:
|
258 |
+
return _subst_compat(s).format_map(lookup)
|
259 |
+
except KeyError as var:
|
260 |
+
raise ValueError(f"invalid variable {var}")
|
261 |
+
|
262 |
+
# subst_vars ()
|
263 |
+
|
264 |
+
|
265 |
+
def _subst_compat(s):
|
266 |
+
"""
|
267 |
+
Replace shell/Perl-style variable substitution with
|
268 |
+
format-style. For compatibility.
|
269 |
+
"""
|
270 |
+
def _subst(match):
|
271 |
+
return f'{{{match.group(1)}}}'
|
272 |
+
repl = re.sub(r'\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, s)
|
273 |
+
if repl != s:
|
274 |
+
import warnings
|
275 |
+
warnings.warn(
|
276 |
+
"shell/Perl-style substitions are deprecated",
|
277 |
+
DeprecationWarning,
|
278 |
+
)
|
279 |
+
return repl
|
280 |
+
|
281 |
+
|
282 |
+
def grok_environment_error (exc, prefix="error: "):
|
283 |
+
# Function kept for backward compatibility.
|
284 |
+
# Used to try clever things with EnvironmentErrors,
|
285 |
+
# but nowadays str(exception) produces good messages.
|
286 |
+
return prefix + str(exc)
|
287 |
+
|
288 |
+
|
289 |
+
# Needed by 'split_quoted()'
|
290 |
+
_wordchars_re = _squote_re = _dquote_re = None
|
291 |
+
def _init_regex():
|
292 |
+
global _wordchars_re, _squote_re, _dquote_re
|
293 |
+
_wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace)
|
294 |
+
_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
|
295 |
+
_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
|
296 |
+
|
297 |
+
def split_quoted (s):
|
298 |
+
"""Split a string up according to Unix shell-like rules for quotes and
|
299 |
+
backslashes. In short: words are delimited by spaces, as long as those
|
300 |
+
spaces are not escaped by a backslash, or inside a quoted string.
|
301 |
+
Single and double quotes are equivalent, and the quote characters can
|
302 |
+
be backslash-escaped. The backslash is stripped from any two-character
|
303 |
+
escape sequence, leaving only the escaped character. The quote
|
304 |
+
characters are stripped from any quoted string. Returns a list of
|
305 |
+
words.
|
306 |
+
"""
|
307 |
+
|
308 |
+
# This is a nice algorithm for splitting up a single string, since it
|
309 |
+
# doesn't require character-by-character examination. It was a little
|
310 |
+
# bit of a brain-bender to get it working right, though...
|
311 |
+
if _wordchars_re is None: _init_regex()
|
312 |
+
|
313 |
+
s = s.strip()
|
314 |
+
words = []
|
315 |
+
pos = 0
|
316 |
+
|
317 |
+
while s:
|
318 |
+
m = _wordchars_re.match(s, pos)
|
319 |
+
end = m.end()
|
320 |
+
if end == len(s):
|
321 |
+
words.append(s[:end])
|
322 |
+
break
|
323 |
+
|
324 |
+
if s[end] in string.whitespace: # unescaped, unquoted whitespace: now
|
325 |
+
words.append(s[:end]) # we definitely have a word delimiter
|
326 |
+
s = s[end:].lstrip()
|
327 |
+
pos = 0
|
328 |
+
|
329 |
+
elif s[end] == '\\': # preserve whatever is being escaped;
|
330 |
+
# will become part of the current word
|
331 |
+
s = s[:end] + s[end+1:]
|
332 |
+
pos = end+1
|
333 |
+
|
334 |
+
else:
|
335 |
+
if s[end] == "'": # slurp singly-quoted string
|
336 |
+
m = _squote_re.match(s, end)
|
337 |
+
elif s[end] == '"': # slurp doubly-quoted string
|
338 |
+
m = _dquote_re.match(s, end)
|
339 |
+
else:
|
340 |
+
raise RuntimeError("this can't happen (bad char '%c')" % s[end])
|
341 |
+
|
342 |
+
if m is None:
|
343 |
+
raise ValueError("bad string (mismatched %s quotes?)" % s[end])
|
344 |
+
|
345 |
+
(beg, end) = m.span()
|
346 |
+
s = s[:beg] + s[beg+1:end-1] + s[end:]
|
347 |
+
pos = m.end() - 2
|
348 |
+
|
349 |
+
if pos >= len(s):
|
350 |
+
words.append(s)
|
351 |
+
break
|
352 |
+
|
353 |
+
return words
|
354 |
+
|
355 |
+
# split_quoted ()
|
356 |
+
|
357 |
+
|
358 |
+
def execute (func, args, msg=None, verbose=0, dry_run=0):
|
359 |
+
"""Perform some action that affects the outside world (eg. by
|
360 |
+
writing to the filesystem). Such actions are special because they
|
361 |
+
are disabled by the 'dry_run' flag. This method takes care of all
|
362 |
+
that bureaucracy for you; all you have to do is supply the
|
363 |
+
function to call and an argument tuple for it (to embody the
|
364 |
+
"external action" being performed), and an optional message to
|
365 |
+
print.
|
366 |
+
"""
|
367 |
+
if msg is None:
|
368 |
+
msg = "%s%r" % (func.__name__, args)
|
369 |
+
if msg[-2:] == ',)': # correct for singleton tuple
|
370 |
+
msg = msg[0:-2] + ')'
|
371 |
+
|
372 |
+
log.info(msg)
|
373 |
+
if not dry_run:
|
374 |
+
func(*args)
|
375 |
+
|
376 |
+
|
377 |
+
def strtobool (val):
|
378 |
+
"""Convert a string representation of truth to true (1) or false (0).
|
379 |
+
|
380 |
+
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
|
381 |
+
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
|
382 |
+
'val' is anything else.
|
383 |
+
"""
|
384 |
+
val = val.lower()
|
385 |
+
if val in ('y', 'yes', 't', 'true', 'on', '1'):
|
386 |
+
return 1
|
387 |
+
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
|
388 |
+
return 0
|
389 |
+
else:
|
390 |
+
raise ValueError("invalid truth value %r" % (val,))
|
391 |
+
|
392 |
+
|
393 |
+
def byte_compile (py_files,
|
394 |
+
optimize=0, force=0,
|
395 |
+
prefix=None, base_dir=None,
|
396 |
+
verbose=1, dry_run=0,
|
397 |
+
direct=None):
|
398 |
+
"""Byte-compile a collection of Python source files to .pyc
|
399 |
+
files in a __pycache__ subdirectory. 'py_files' is a list
|
400 |
+
of files to compile; any files that don't end in ".py" are silently
|
401 |
+
skipped. 'optimize' must be one of the following:
|
402 |
+
0 - don't optimize
|
403 |
+
1 - normal optimization (like "python -O")
|
404 |
+
2 - extra optimization (like "python -OO")
|
405 |
+
If 'force' is true, all files are recompiled regardless of
|
406 |
+
timestamps.
|
407 |
+
|
408 |
+
The source filename encoded in each bytecode file defaults to the
|
409 |
+
filenames listed in 'py_files'; you can modify these with 'prefix' and
|
410 |
+
'basedir'. 'prefix' is a string that will be stripped off of each
|
411 |
+
source filename, and 'base_dir' is a directory name that will be
|
412 |
+
prepended (after 'prefix' is stripped). You can supply either or both
|
413 |
+
(or neither) of 'prefix' and 'base_dir', as you wish.
|
414 |
+
|
415 |
+
If 'dry_run' is true, doesn't actually do anything that would
|
416 |
+
affect the filesystem.
|
417 |
+
|
418 |
+
Byte-compilation is either done directly in this interpreter process
|
419 |
+
with the standard py_compile module, or indirectly by writing a
|
420 |
+
temporary script and executing it. Normally, you should let
|
421 |
+
'byte_compile()' figure out to use direct compilation or not (see
|
422 |
+
the source for details). The 'direct' flag is used by the script
|
423 |
+
generated in indirect mode; unless you know what you're doing, leave
|
424 |
+
it set to None.
|
425 |
+
"""
|
426 |
+
|
427 |
+
# Late import to fix a bootstrap issue: _posixsubprocess is built by
|
428 |
+
# setup.py, but setup.py uses distutils.
|
429 |
+
import subprocess
|
430 |
+
|
431 |
+
# nothing is done if sys.dont_write_bytecode is True
|
432 |
+
if sys.dont_write_bytecode:
|
433 |
+
raise DistutilsByteCompileError('byte-compiling is disabled.')
|
434 |
+
|
435 |
+
# First, if the caller didn't force us into direct or indirect mode,
|
436 |
+
# figure out which mode we should be in. We take a conservative
|
437 |
+
# approach: choose direct mode *only* if the current interpreter is
|
438 |
+
# in debug mode and optimize is 0. If we're not in debug mode (-O
|
439 |
+
# or -OO), we don't know which level of optimization this
|
440 |
+
# interpreter is running with, so we can't do direct
|
441 |
+
# byte-compilation and be certain that it's the right thing. Thus,
|
442 |
+
# always compile indirectly if the current interpreter is in either
|
443 |
+
# optimize mode, or if either optimization level was requested by
|
444 |
+
# the caller.
|
445 |
+
if direct is None:
|
446 |
+
direct = (__debug__ and optimize == 0)
|
447 |
+
|
448 |
+
# "Indirect" byte-compilation: write a temporary script and then
|
449 |
+
# run it with the appropriate flags.
|
450 |
+
if not direct:
|
451 |
+
try:
|
452 |
+
from tempfile import mkstemp
|
453 |
+
(script_fd, script_name) = mkstemp(".py")
|
454 |
+
except ImportError:
|
455 |
+
from tempfile import mktemp
|
456 |
+
(script_fd, script_name) = None, mktemp(".py")
|
457 |
+
log.info("writing byte-compilation script '%s'", script_name)
|
458 |
+
if not dry_run:
|
459 |
+
if script_fd is not None:
|
460 |
+
script = os.fdopen(script_fd, "w")
|
461 |
+
else:
|
462 |
+
script = open(script_name, "w")
|
463 |
+
|
464 |
+
with script:
|
465 |
+
script.write("""\
|
466 |
+
from distutils.util import byte_compile
|
467 |
+
files = [
|
468 |
+
""")
|
469 |
+
|
470 |
+
# XXX would be nice to write absolute filenames, just for
|
471 |
+
# safety's sake (script should be more robust in the face of
|
472 |
+
# chdir'ing before running it). But this requires abspath'ing
|
473 |
+
# 'prefix' as well, and that breaks the hack in build_lib's
|
474 |
+
# 'byte_compile()' method that carefully tacks on a trailing
|
475 |
+
# slash (os.sep really) to make sure the prefix here is "just
|
476 |
+
# right". This whole prefix business is rather delicate -- the
|
477 |
+
# problem is that it's really a directory, but I'm treating it
|
478 |
+
# as a dumb string, so trailing slashes and so forth matter.
|
479 |
+
|
480 |
+
#py_files = map(os.path.abspath, py_files)
|
481 |
+
#if prefix:
|
482 |
+
# prefix = os.path.abspath(prefix)
|
483 |
+
|
484 |
+
script.write(",\n".join(map(repr, py_files)) + "]\n")
|
485 |
+
script.write("""
|
486 |
+
byte_compile(files, optimize=%r, force=%r,
|
487 |
+
prefix=%r, base_dir=%r,
|
488 |
+
verbose=%r, dry_run=0,
|
489 |
+
direct=1)
|
490 |
+
""" % (optimize, force, prefix, base_dir, verbose))
|
491 |
+
|
492 |
+
cmd = [sys.executable]
|
493 |
+
cmd.extend(_optim_args_from_interpreter_flags())
|
494 |
+
cmd.append(script_name)
|
495 |
+
spawn(cmd, dry_run=dry_run)
|
496 |
+
execute(os.remove, (script_name,), "removing %s" % script_name,
|
497 |
+
dry_run=dry_run)
|
498 |
+
|
499 |
+
# "Direct" byte-compilation: use the py_compile module to compile
|
500 |
+
# right here, right now. Note that the script generated in indirect
|
501 |
+
# mode simply calls 'byte_compile()' in direct mode, a weird sort of
|
502 |
+
# cross-process recursion. Hey, it works!
|
503 |
+
else:
|
504 |
+
from py_compile import compile
|
505 |
+
|
506 |
+
for file in py_files:
|
507 |
+
if file[-3:] != ".py":
|
508 |
+
# This lets us be lazy and not filter filenames in
|
509 |
+
# the "install_lib" command.
|
510 |
+
continue
|
511 |
+
|
512 |
+
# Terminology from the py_compile module:
|
513 |
+
# cfile - byte-compiled file
|
514 |
+
# dfile - purported source filename (same as 'file' by default)
|
515 |
+
if optimize >= 0:
|
516 |
+
opt = '' if optimize == 0 else optimize
|
517 |
+
cfile = importlib.util.cache_from_source(
|
518 |
+
file, optimization=opt)
|
519 |
+
else:
|
520 |
+
cfile = importlib.util.cache_from_source(file)
|
521 |
+
dfile = file
|
522 |
+
if prefix:
|
523 |
+
if file[:len(prefix)] != prefix:
|
524 |
+
raise ValueError("invalid prefix: filename %r doesn't start with %r"
|
525 |
+
% (file, prefix))
|
526 |
+
dfile = dfile[len(prefix):]
|
527 |
+
if base_dir:
|
528 |
+
dfile = os.path.join(base_dir, dfile)
|
529 |
+
|
530 |
+
cfile_base = os.path.basename(cfile)
|
531 |
+
if direct:
|
532 |
+
if force or newer(file, cfile):
|
533 |
+
log.info("byte-compiling %s to %s", file, cfile_base)
|
534 |
+
if not dry_run:
|
535 |
+
compile(file, cfile, dfile)
|
536 |
+
else:
|
537 |
+
log.debug("skipping byte-compilation of %s to %s",
|
538 |
+
file, cfile_base)
|
539 |
+
|
540 |
+
# byte_compile ()
|
541 |
+
|
542 |
+
def rfc822_escape (header):
|
543 |
+
"""Return a version of the string escaped for inclusion in an
|
544 |
+
RFC-822 header, by ensuring there are 8 spaces space after each newline.
|
545 |
+
"""
|
546 |
+
lines = header.split('\n')
|
547 |
+
sep = '\n' + 8 * ' '
|
548 |
+
return sep.join(lines)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/__init__.py
ADDED
File without changes
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/ordered_set.py
ADDED
@@ -0,0 +1,488 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
An OrderedSet is a custom MutableSet that remembers its order, so that every
|
3 |
+
entry has an index that can be looked up.
|
4 |
+
|
5 |
+
Based on a recipe originally posted to ActiveState Recipes by Raymond Hettiger,
|
6 |
+
and released under the MIT license.
|
7 |
+
"""
|
8 |
+
import itertools as it
|
9 |
+
from collections import deque
|
10 |
+
|
11 |
+
try:
|
12 |
+
# Python 3
|
13 |
+
from collections.abc import MutableSet, Sequence
|
14 |
+
except ImportError:
|
15 |
+
# Python 2.7
|
16 |
+
from collections import MutableSet, Sequence
|
17 |
+
|
18 |
+
SLICE_ALL = slice(None)
|
19 |
+
__version__ = "3.1"
|
20 |
+
|
21 |
+
|
22 |
+
def is_iterable(obj):
|
23 |
+
"""
|
24 |
+
Are we being asked to look up a list of things, instead of a single thing?
|
25 |
+
We check for the `__iter__` attribute so that this can cover types that
|
26 |
+
don't have to be known by this module, such as NumPy arrays.
|
27 |
+
|
28 |
+
Strings, however, should be considered as atomic values to look up, not
|
29 |
+
iterables. The same goes for tuples, since they are immutable and therefore
|
30 |
+
valid entries.
|
31 |
+
|
32 |
+
We don't need to check for the Python 2 `unicode` type, because it doesn't
|
33 |
+
have an `__iter__` attribute anyway.
|
34 |
+
"""
|
35 |
+
return (
|
36 |
+
hasattr(obj, "__iter__")
|
37 |
+
and not isinstance(obj, str)
|
38 |
+
and not isinstance(obj, tuple)
|
39 |
+
)
|
40 |
+
|
41 |
+
|
42 |
+
class OrderedSet(MutableSet, Sequence):
|
43 |
+
"""
|
44 |
+
An OrderedSet is a custom MutableSet that remembers its order, so that
|
45 |
+
every entry has an index that can be looked up.
|
46 |
+
|
47 |
+
Example:
|
48 |
+
>>> OrderedSet([1, 1, 2, 3, 2])
|
49 |
+
OrderedSet([1, 2, 3])
|
50 |
+
"""
|
51 |
+
|
52 |
+
def __init__(self, iterable=None):
|
53 |
+
self.items = []
|
54 |
+
self.map = {}
|
55 |
+
if iterable is not None:
|
56 |
+
self |= iterable
|
57 |
+
|
58 |
+
def __len__(self):
|
59 |
+
"""
|
60 |
+
Returns the number of unique elements in the ordered set
|
61 |
+
|
62 |
+
Example:
|
63 |
+
>>> len(OrderedSet([]))
|
64 |
+
0
|
65 |
+
>>> len(OrderedSet([1, 2]))
|
66 |
+
2
|
67 |
+
"""
|
68 |
+
return len(self.items)
|
69 |
+
|
70 |
+
def __getitem__(self, index):
|
71 |
+
"""
|
72 |
+
Get the item at a given index.
|
73 |
+
|
74 |
+
If `index` is a slice, you will get back that slice of items, as a
|
75 |
+
new OrderedSet.
|
76 |
+
|
77 |
+
If `index` is a list or a similar iterable, you'll get a list of
|
78 |
+
items corresponding to those indices. This is similar to NumPy's
|
79 |
+
"fancy indexing". The result is not an OrderedSet because you may ask
|
80 |
+
for duplicate indices, and the number of elements returned should be
|
81 |
+
the number of elements asked for.
|
82 |
+
|
83 |
+
Example:
|
84 |
+
>>> oset = OrderedSet([1, 2, 3])
|
85 |
+
>>> oset[1]
|
86 |
+
2
|
87 |
+
"""
|
88 |
+
if isinstance(index, slice) and index == SLICE_ALL:
|
89 |
+
return self.copy()
|
90 |
+
elif is_iterable(index):
|
91 |
+
return [self.items[i] for i in index]
|
92 |
+
elif hasattr(index, "__index__") or isinstance(index, slice):
|
93 |
+
result = self.items[index]
|
94 |
+
if isinstance(result, list):
|
95 |
+
return self.__class__(result)
|
96 |
+
else:
|
97 |
+
return result
|
98 |
+
else:
|
99 |
+
raise TypeError("Don't know how to index an OrderedSet by %r" % index)
|
100 |
+
|
101 |
+
def copy(self):
|
102 |
+
"""
|
103 |
+
Return a shallow copy of this object.
|
104 |
+
|
105 |
+
Example:
|
106 |
+
>>> this = OrderedSet([1, 2, 3])
|
107 |
+
>>> other = this.copy()
|
108 |
+
>>> this == other
|
109 |
+
True
|
110 |
+
>>> this is other
|
111 |
+
False
|
112 |
+
"""
|
113 |
+
return self.__class__(self)
|
114 |
+
|
115 |
+
def __getstate__(self):
|
116 |
+
if len(self) == 0:
|
117 |
+
# The state can't be an empty list.
|
118 |
+
# We need to return a truthy value, or else __setstate__ won't be run.
|
119 |
+
#
|
120 |
+
# This could have been done more gracefully by always putting the state
|
121 |
+
# in a tuple, but this way is backwards- and forwards- compatible with
|
122 |
+
# previous versions of OrderedSet.
|
123 |
+
return (None,)
|
124 |
+
else:
|
125 |
+
return list(self)
|
126 |
+
|
127 |
+
def __setstate__(self, state):
|
128 |
+
if state == (None,):
|
129 |
+
self.__init__([])
|
130 |
+
else:
|
131 |
+
self.__init__(state)
|
132 |
+
|
133 |
+
def __contains__(self, key):
|
134 |
+
"""
|
135 |
+
Test if the item is in this ordered set
|
136 |
+
|
137 |
+
Example:
|
138 |
+
>>> 1 in OrderedSet([1, 3, 2])
|
139 |
+
True
|
140 |
+
>>> 5 in OrderedSet([1, 3, 2])
|
141 |
+
False
|
142 |
+
"""
|
143 |
+
return key in self.map
|
144 |
+
|
145 |
+
def add(self, key):
|
146 |
+
"""
|
147 |
+
Add `key` as an item to this OrderedSet, then return its index.
|
148 |
+
|
149 |
+
If `key` is already in the OrderedSet, return the index it already
|
150 |
+
had.
|
151 |
+
|
152 |
+
Example:
|
153 |
+
>>> oset = OrderedSet()
|
154 |
+
>>> oset.append(3)
|
155 |
+
0
|
156 |
+
>>> print(oset)
|
157 |
+
OrderedSet([3])
|
158 |
+
"""
|
159 |
+
if key not in self.map:
|
160 |
+
self.map[key] = len(self.items)
|
161 |
+
self.items.append(key)
|
162 |
+
return self.map[key]
|
163 |
+
|
164 |
+
append = add
|
165 |
+
|
166 |
+
def update(self, sequence):
|
167 |
+
"""
|
168 |
+
Update the set with the given iterable sequence, then return the index
|
169 |
+
of the last element inserted.
|
170 |
+
|
171 |
+
Example:
|
172 |
+
>>> oset = OrderedSet([1, 2, 3])
|
173 |
+
>>> oset.update([3, 1, 5, 1, 4])
|
174 |
+
4
|
175 |
+
>>> print(oset)
|
176 |
+
OrderedSet([1, 2, 3, 5, 4])
|
177 |
+
"""
|
178 |
+
item_index = None
|
179 |
+
try:
|
180 |
+
for item in sequence:
|
181 |
+
item_index = self.add(item)
|
182 |
+
except TypeError:
|
183 |
+
raise ValueError(
|
184 |
+
"Argument needs to be an iterable, got %s" % type(sequence)
|
185 |
+
)
|
186 |
+
return item_index
|
187 |
+
|
188 |
+
def index(self, key):
|
189 |
+
"""
|
190 |
+
Get the index of a given entry, raising an IndexError if it's not
|
191 |
+
present.
|
192 |
+
|
193 |
+
`key` can be an iterable of entries that is not a string, in which case
|
194 |
+
this returns a list of indices.
|
195 |
+
|
196 |
+
Example:
|
197 |
+
>>> oset = OrderedSet([1, 2, 3])
|
198 |
+
>>> oset.index(2)
|
199 |
+
1
|
200 |
+
"""
|
201 |
+
if is_iterable(key):
|
202 |
+
return [self.index(subkey) for subkey in key]
|
203 |
+
return self.map[key]
|
204 |
+
|
205 |
+
# Provide some compatibility with pd.Index
|
206 |
+
get_loc = index
|
207 |
+
get_indexer = index
|
208 |
+
|
209 |
+
def pop(self):
|
210 |
+
"""
|
211 |
+
Remove and return the last element from the set.
|
212 |
+
|
213 |
+
Raises KeyError if the set is empty.
|
214 |
+
|
215 |
+
Example:
|
216 |
+
>>> oset = OrderedSet([1, 2, 3])
|
217 |
+
>>> oset.pop()
|
218 |
+
3
|
219 |
+
"""
|
220 |
+
if not self.items:
|
221 |
+
raise KeyError("Set is empty")
|
222 |
+
|
223 |
+
elem = self.items[-1]
|
224 |
+
del self.items[-1]
|
225 |
+
del self.map[elem]
|
226 |
+
return elem
|
227 |
+
|
228 |
+
def discard(self, key):
|
229 |
+
"""
|
230 |
+
Remove an element. Do not raise an exception if absent.
|
231 |
+
|
232 |
+
The MutableSet mixin uses this to implement the .remove() method, which
|
233 |
+
*does* raise an error when asked to remove a non-existent item.
|
234 |
+
|
235 |
+
Example:
|
236 |
+
>>> oset = OrderedSet([1, 2, 3])
|
237 |
+
>>> oset.discard(2)
|
238 |
+
>>> print(oset)
|
239 |
+
OrderedSet([1, 3])
|
240 |
+
>>> oset.discard(2)
|
241 |
+
>>> print(oset)
|
242 |
+
OrderedSet([1, 3])
|
243 |
+
"""
|
244 |
+
if key in self:
|
245 |
+
i = self.map[key]
|
246 |
+
del self.items[i]
|
247 |
+
del self.map[key]
|
248 |
+
for k, v in self.map.items():
|
249 |
+
if v >= i:
|
250 |
+
self.map[k] = v - 1
|
251 |
+
|
252 |
+
def clear(self):
|
253 |
+
"""
|
254 |
+
Remove all items from this OrderedSet.
|
255 |
+
"""
|
256 |
+
del self.items[:]
|
257 |
+
self.map.clear()
|
258 |
+
|
259 |
+
def __iter__(self):
|
260 |
+
"""
|
261 |
+
Example:
|
262 |
+
>>> list(iter(OrderedSet([1, 2, 3])))
|
263 |
+
[1, 2, 3]
|
264 |
+
"""
|
265 |
+
return iter(self.items)
|
266 |
+
|
267 |
+
def __reversed__(self):
|
268 |
+
"""
|
269 |
+
Example:
|
270 |
+
>>> list(reversed(OrderedSet([1, 2, 3])))
|
271 |
+
[3, 2, 1]
|
272 |
+
"""
|
273 |
+
return reversed(self.items)
|
274 |
+
|
275 |
+
def __repr__(self):
|
276 |
+
if not self:
|
277 |
+
return "%s()" % (self.__class__.__name__,)
|
278 |
+
return "%s(%r)" % (self.__class__.__name__, list(self))
|
279 |
+
|
280 |
+
def __eq__(self, other):
|
281 |
+
"""
|
282 |
+
Returns true if the containers have the same items. If `other` is a
|
283 |
+
Sequence, then order is checked, otherwise it is ignored.
|
284 |
+
|
285 |
+
Example:
|
286 |
+
>>> oset = OrderedSet([1, 3, 2])
|
287 |
+
>>> oset == [1, 3, 2]
|
288 |
+
True
|
289 |
+
>>> oset == [1, 2, 3]
|
290 |
+
False
|
291 |
+
>>> oset == [2, 3]
|
292 |
+
False
|
293 |
+
>>> oset == OrderedSet([3, 2, 1])
|
294 |
+
False
|
295 |
+
"""
|
296 |
+
# In Python 2 deque is not a Sequence, so treat it as one for
|
297 |
+
# consistent behavior with Python 3.
|
298 |
+
if isinstance(other, (Sequence, deque)):
|
299 |
+
# Check that this OrderedSet contains the same elements, in the
|
300 |
+
# same order, as the other object.
|
301 |
+
return list(self) == list(other)
|
302 |
+
try:
|
303 |
+
other_as_set = set(other)
|
304 |
+
except TypeError:
|
305 |
+
# If `other` can't be converted into a set, it's not equal.
|
306 |
+
return False
|
307 |
+
else:
|
308 |
+
return set(self) == other_as_set
|
309 |
+
|
310 |
+
def union(self, *sets):
|
311 |
+
"""
|
312 |
+
Combines all unique items.
|
313 |
+
Each items order is defined by its first appearance.
|
314 |
+
|
315 |
+
Example:
|
316 |
+
>>> oset = OrderedSet.union(OrderedSet([3, 1, 4, 1, 5]), [1, 3], [2, 0])
|
317 |
+
>>> print(oset)
|
318 |
+
OrderedSet([3, 1, 4, 5, 2, 0])
|
319 |
+
>>> oset.union([8, 9])
|
320 |
+
OrderedSet([3, 1, 4, 5, 2, 0, 8, 9])
|
321 |
+
>>> oset | {10}
|
322 |
+
OrderedSet([3, 1, 4, 5, 2, 0, 10])
|
323 |
+
"""
|
324 |
+
cls = self.__class__ if isinstance(self, OrderedSet) else OrderedSet
|
325 |
+
containers = map(list, it.chain([self], sets))
|
326 |
+
items = it.chain.from_iterable(containers)
|
327 |
+
return cls(items)
|
328 |
+
|
329 |
+
def __and__(self, other):
|
330 |
+
# the parent implementation of this is backwards
|
331 |
+
return self.intersection(other)
|
332 |
+
|
333 |
+
def intersection(self, *sets):
|
334 |
+
"""
|
335 |
+
Returns elements in common between all sets. Order is defined only
|
336 |
+
by the first set.
|
337 |
+
|
338 |
+
Example:
|
339 |
+
>>> oset = OrderedSet.intersection(OrderedSet([0, 1, 2, 3]), [1, 2, 3])
|
340 |
+
>>> print(oset)
|
341 |
+
OrderedSet([1, 2, 3])
|
342 |
+
>>> oset.intersection([2, 4, 5], [1, 2, 3, 4])
|
343 |
+
OrderedSet([2])
|
344 |
+
>>> oset.intersection()
|
345 |
+
OrderedSet([1, 2, 3])
|
346 |
+
"""
|
347 |
+
cls = self.__class__ if isinstance(self, OrderedSet) else OrderedSet
|
348 |
+
if sets:
|
349 |
+
common = set.intersection(*map(set, sets))
|
350 |
+
items = (item for item in self if item in common)
|
351 |
+
else:
|
352 |
+
items = self
|
353 |
+
return cls(items)
|
354 |
+
|
355 |
+
def difference(self, *sets):
|
356 |
+
"""
|
357 |
+
Returns all elements that are in this set but not the others.
|
358 |
+
|
359 |
+
Example:
|
360 |
+
>>> OrderedSet([1, 2, 3]).difference(OrderedSet([2]))
|
361 |
+
OrderedSet([1, 3])
|
362 |
+
>>> OrderedSet([1, 2, 3]).difference(OrderedSet([2]), OrderedSet([3]))
|
363 |
+
OrderedSet([1])
|
364 |
+
>>> OrderedSet([1, 2, 3]) - OrderedSet([2])
|
365 |
+
OrderedSet([1, 3])
|
366 |
+
>>> OrderedSet([1, 2, 3]).difference()
|
367 |
+
OrderedSet([1, 2, 3])
|
368 |
+
"""
|
369 |
+
cls = self.__class__
|
370 |
+
if sets:
|
371 |
+
other = set.union(*map(set, sets))
|
372 |
+
items = (item for item in self if item not in other)
|
373 |
+
else:
|
374 |
+
items = self
|
375 |
+
return cls(items)
|
376 |
+
|
377 |
+
def issubset(self, other):
|
378 |
+
"""
|
379 |
+
Report whether another set contains this set.
|
380 |
+
|
381 |
+
Example:
|
382 |
+
>>> OrderedSet([1, 2, 3]).issubset({1, 2})
|
383 |
+
False
|
384 |
+
>>> OrderedSet([1, 2, 3]).issubset({1, 2, 3, 4})
|
385 |
+
True
|
386 |
+
>>> OrderedSet([1, 2, 3]).issubset({1, 4, 3, 5})
|
387 |
+
False
|
388 |
+
"""
|
389 |
+
if len(self) > len(other): # Fast check for obvious cases
|
390 |
+
return False
|
391 |
+
return all(item in other for item in self)
|
392 |
+
|
393 |
+
def issuperset(self, other):
|
394 |
+
"""
|
395 |
+
Report whether this set contains another set.
|
396 |
+
|
397 |
+
Example:
|
398 |
+
>>> OrderedSet([1, 2]).issuperset([1, 2, 3])
|
399 |
+
False
|
400 |
+
>>> OrderedSet([1, 2, 3, 4]).issuperset({1, 2, 3})
|
401 |
+
True
|
402 |
+
>>> OrderedSet([1, 4, 3, 5]).issuperset({1, 2, 3})
|
403 |
+
False
|
404 |
+
"""
|
405 |
+
if len(self) < len(other): # Fast check for obvious cases
|
406 |
+
return False
|
407 |
+
return all(item in self for item in other)
|
408 |
+
|
409 |
+
def symmetric_difference(self, other):
|
410 |
+
"""
|
411 |
+
Return the symmetric difference of two OrderedSets as a new set.
|
412 |
+
That is, the new set will contain all elements that are in exactly
|
413 |
+
one of the sets.
|
414 |
+
|
415 |
+
Their order will be preserved, with elements from `self` preceding
|
416 |
+
elements from `other`.
|
417 |
+
|
418 |
+
Example:
|
419 |
+
>>> this = OrderedSet([1, 4, 3, 5, 7])
|
420 |
+
>>> other = OrderedSet([9, 7, 1, 3, 2])
|
421 |
+
>>> this.symmetric_difference(other)
|
422 |
+
OrderedSet([4, 5, 9, 2])
|
423 |
+
"""
|
424 |
+
cls = self.__class__ if isinstance(self, OrderedSet) else OrderedSet
|
425 |
+
diff1 = cls(self).difference(other)
|
426 |
+
diff2 = cls(other).difference(self)
|
427 |
+
return diff1.union(diff2)
|
428 |
+
|
429 |
+
def _update_items(self, items):
|
430 |
+
"""
|
431 |
+
Replace the 'items' list of this OrderedSet with a new one, updating
|
432 |
+
self.map accordingly.
|
433 |
+
"""
|
434 |
+
self.items = items
|
435 |
+
self.map = {item: idx for (idx, item) in enumerate(items)}
|
436 |
+
|
437 |
+
def difference_update(self, *sets):
|
438 |
+
"""
|
439 |
+
Update this OrderedSet to remove items from one or more other sets.
|
440 |
+
|
441 |
+
Example:
|
442 |
+
>>> this = OrderedSet([1, 2, 3])
|
443 |
+
>>> this.difference_update(OrderedSet([2, 4]))
|
444 |
+
>>> print(this)
|
445 |
+
OrderedSet([1, 3])
|
446 |
+
|
447 |
+
>>> this = OrderedSet([1, 2, 3, 4, 5])
|
448 |
+
>>> this.difference_update(OrderedSet([2, 4]), OrderedSet([1, 4, 6]))
|
449 |
+
>>> print(this)
|
450 |
+
OrderedSet([3, 5])
|
451 |
+
"""
|
452 |
+
items_to_remove = set()
|
453 |
+
for other in sets:
|
454 |
+
items_to_remove |= set(other)
|
455 |
+
self._update_items([item for item in self.items if item not in items_to_remove])
|
456 |
+
|
457 |
+
def intersection_update(self, other):
|
458 |
+
"""
|
459 |
+
Update this OrderedSet to keep only items in another set, preserving
|
460 |
+
their order in this set.
|
461 |
+
|
462 |
+
Example:
|
463 |
+
>>> this = OrderedSet([1, 4, 3, 5, 7])
|
464 |
+
>>> other = OrderedSet([9, 7, 1, 3, 2])
|
465 |
+
>>> this.intersection_update(other)
|
466 |
+
>>> print(this)
|
467 |
+
OrderedSet([1, 3, 7])
|
468 |
+
"""
|
469 |
+
other = set(other)
|
470 |
+
self._update_items([item for item in self.items if item in other])
|
471 |
+
|
472 |
+
def symmetric_difference_update(self, other):
|
473 |
+
"""
|
474 |
+
Update this OrderedSet to remove items from another set, then
|
475 |
+
add items from the other set that were not present in this set.
|
476 |
+
|
477 |
+
Example:
|
478 |
+
>>> this = OrderedSet([1, 4, 3, 5, 7])
|
479 |
+
>>> other = OrderedSet([9, 7, 1, 3, 2])
|
480 |
+
>>> this.symmetric_difference_update(other)
|
481 |
+
>>> print(this)
|
482 |
+
OrderedSet([4, 5, 9, 2])
|
483 |
+
"""
|
484 |
+
items_to_add = [item for item in other if item not in self]
|
485 |
+
items_to_remove = set(other)
|
486 |
+
self._update_items(
|
487 |
+
[item for item in self.items if item not in items_to_remove] + items_to_add
|
488 |
+
)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/__about__.cpython-310.pyc
ADDED
Binary file (598 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (454 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/_manylinux.cpython-310.pyc
ADDED
Binary file (7.31 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/_musllinux.cpython-310.pyc
ADDED
Binary file (4.62 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/_structures.cpython-310.pyc
ADDED
Binary file (2.98 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/requirements.cpython-310.pyc
ADDED
Binary file (3.99 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/specifiers.cpython-310.pyc
ADDED
Binary file (22.2 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/tags.cpython-310.pyc
ADDED
Binary file (12.2 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/utils.cpython-310.pyc
ADDED
Binary file (3.58 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/packaging/__pycache__/version.cpython-310.pyc
ADDED
Binary file (12.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_vendor/pyparsing.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (380 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/alias.cpython-310.pyc
ADDED
Binary file (2.38 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/bdist_egg.cpython-310.pyc
ADDED
Binary file (13.1 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/bdist_rpm.cpython-310.pyc
ADDED
Binary file (1.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/build_clib.cpython-310.pyc
ADDED
Binary file (2.47 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/build_ext.cpython-310.pyc
ADDED
Binary file (9.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/build_py.cpython-310.pyc
ADDED
Binary file (8.27 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/develop.cpython-310.pyc
ADDED
Binary file (6.16 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/dist_info.cpython-310.pyc
ADDED
Binary file (1.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/easy_install.cpython-310.pyc
ADDED
Binary file (65.2 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/egg_info.cpython-310.pyc
ADDED
Binary file (22.8 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/install.cpython-310.pyc
ADDED
Binary file (4.21 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/install_egg_info.cpython-310.pyc
ADDED
Binary file (2.93 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/install_lib.cpython-310.pyc
ADDED
Binary file (5.15 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/install_scripts.cpython-310.pyc
ADDED
Binary file (2.44 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/py36compat.cpython-310.pyc
ADDED
Binary file (4.54 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/register.cpython-310.pyc
ADDED
Binary file (846 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/rotate.cpython-310.pyc
ADDED
Binary file (2.51 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/saveopts.cpython-310.pyc
ADDED
Binary file (932 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/command/__pycache__/sdist.cpython-310.pyc
ADDED
Binary file (6.96 kB). View file
|
|