Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- parrot/lib/python3.10/asyncio/__pycache__/constants.cpython-310.pyc +0 -0
- parrot/lib/python3.10/asyncio/__pycache__/events.cpython-310.pyc +0 -0
- parrot/lib/python3.10/asyncio/__pycache__/mixins.cpython-310.pyc +0 -0
- parrot/lib/python3.10/asyncio/__pycache__/proactor_events.cpython-310.pyc +0 -0
- parrot/lib/python3.10/asyncio/__pycache__/streams.cpython-310.pyc +0 -0
- parrot/lib/python3.10/asyncio/transports.py +335 -0
- parrot/lib/python3.10/asyncio/windows_events.py +924 -0
- videollama2/lib/python3.10/site-packages/setuptools/_core_metadata.py +321 -0
- videollama2/lib/python3.10/site-packages/setuptools/_entry_points.py +90 -0
- videollama2/lib/python3.10/site-packages/setuptools/_imp.py +87 -0
- videollama2/lib/python3.10/site-packages/setuptools/_itertools.py +23 -0
- videollama2/lib/python3.10/site-packages/setuptools/_normalization.py +144 -0
- videollama2/lib/python3.10/site-packages/setuptools/_path.py +84 -0
- videollama2/lib/python3.10/site-packages/setuptools/_reqs.py +42 -0
- videollama2/lib/python3.10/site-packages/setuptools/_static.py +188 -0
- videollama2/lib/python3.10/site-packages/setuptools/build_meta.py +560 -0
- videollama2/lib/python3.10/site-packages/setuptools/cli-arm64.exe +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/NOTICE +10 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/__init__.py +43 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/__pycache__/__init__.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/__pycache__/expand.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/__pycache__/setupcfg.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_apply_pyprojecttoml.py +488 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/NOTICE +438 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__init__.py +34 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/__init__.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/error_reporting.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_exceptions.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_validations.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/formats.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/error_reporting.py +336 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/extra_validations.py +52 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/fastjsonschema_exceptions.py +51 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/fastjsonschema_validations.py +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/distutils.schema.json +26 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/expand.py +452 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py +468 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/setupcfg.py +780 -0
- videollama2/lib/python3.10/site-packages/setuptools/config/setuptools.schema.json +433 -0
- videollama2/lib/python3.10/site-packages/setuptools/depends.py +185 -0
- videollama2/lib/python3.10/site-packages/setuptools/discovery.py +614 -0
- videollama2/lib/python3.10/site-packages/setuptools/dist.py +1004 -0
- videollama2/lib/python3.10/site-packages/setuptools/extension.py +177 -0
- videollama2/lib/python3.10/site-packages/setuptools/glob.py +185 -0
- videollama2/lib/python3.10/site-packages/setuptools/gui.exe +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/installer.py +150 -0
- videollama2/lib/python3.10/site-packages/setuptools/launch.py +36 -0
- videollama2/lib/python3.10/site-packages/setuptools/logging.py +40 -0
- videollama2/lib/python3.10/site-packages/setuptools/modified.py +18 -0
- videollama2/lib/python3.10/site-packages/setuptools/sandbox.py +536 -0
parrot/lib/python3.10/asyncio/__pycache__/constants.cpython-310.pyc
ADDED
|
Binary file (840 Bytes). View file
|
|
|
parrot/lib/python3.10/asyncio/__pycache__/events.cpython-310.pyc
ADDED
|
Binary file (28.6 kB). View file
|
|
|
parrot/lib/python3.10/asyncio/__pycache__/mixins.cpython-310.pyc
ADDED
|
Binary file (1.07 kB). View file
|
|
|
parrot/lib/python3.10/asyncio/__pycache__/proactor_events.cpython-310.pyc
ADDED
|
Binary file (24.7 kB). View file
|
|
|
parrot/lib/python3.10/asyncio/__pycache__/streams.cpython-310.pyc
ADDED
|
Binary file (20.4 kB). View file
|
|
|
parrot/lib/python3.10/asyncio/transports.py
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Abstract Transport class."""
|
| 2 |
+
|
| 3 |
+
__all__ = (
|
| 4 |
+
'BaseTransport', 'ReadTransport', 'WriteTransport',
|
| 5 |
+
'Transport', 'DatagramTransport', 'SubprocessTransport',
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class BaseTransport:
|
| 10 |
+
"""Base class for transports."""
|
| 11 |
+
|
| 12 |
+
__slots__ = ('_extra',)
|
| 13 |
+
|
| 14 |
+
def __init__(self, extra=None):
|
| 15 |
+
if extra is None:
|
| 16 |
+
extra = {}
|
| 17 |
+
self._extra = extra
|
| 18 |
+
|
| 19 |
+
def get_extra_info(self, name, default=None):
|
| 20 |
+
"""Get optional transport information."""
|
| 21 |
+
return self._extra.get(name, default)
|
| 22 |
+
|
| 23 |
+
def is_closing(self):
|
| 24 |
+
"""Return True if the transport is closing or closed."""
|
| 25 |
+
raise NotImplementedError
|
| 26 |
+
|
| 27 |
+
def close(self):
|
| 28 |
+
"""Close the transport.
|
| 29 |
+
|
| 30 |
+
Buffered data will be flushed asynchronously. No more data
|
| 31 |
+
will be received. After all buffered data is flushed, the
|
| 32 |
+
protocol's connection_lost() method will (eventually) be
|
| 33 |
+
called with None as its argument.
|
| 34 |
+
"""
|
| 35 |
+
raise NotImplementedError
|
| 36 |
+
|
| 37 |
+
def set_protocol(self, protocol):
|
| 38 |
+
"""Set a new protocol."""
|
| 39 |
+
raise NotImplementedError
|
| 40 |
+
|
| 41 |
+
def get_protocol(self):
|
| 42 |
+
"""Return the current protocol."""
|
| 43 |
+
raise NotImplementedError
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class ReadTransport(BaseTransport):
|
| 47 |
+
"""Interface for read-only transports."""
|
| 48 |
+
|
| 49 |
+
__slots__ = ()
|
| 50 |
+
|
| 51 |
+
def is_reading(self):
|
| 52 |
+
"""Return True if the transport is receiving."""
|
| 53 |
+
raise NotImplementedError
|
| 54 |
+
|
| 55 |
+
def pause_reading(self):
|
| 56 |
+
"""Pause the receiving end.
|
| 57 |
+
|
| 58 |
+
No data will be passed to the protocol's data_received()
|
| 59 |
+
method until resume_reading() is called.
|
| 60 |
+
"""
|
| 61 |
+
raise NotImplementedError
|
| 62 |
+
|
| 63 |
+
def resume_reading(self):
|
| 64 |
+
"""Resume the receiving end.
|
| 65 |
+
|
| 66 |
+
Data received will once again be passed to the protocol's
|
| 67 |
+
data_received() method.
|
| 68 |
+
"""
|
| 69 |
+
raise NotImplementedError
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class WriteTransport(BaseTransport):
|
| 73 |
+
"""Interface for write-only transports."""
|
| 74 |
+
|
| 75 |
+
__slots__ = ()
|
| 76 |
+
|
| 77 |
+
def set_write_buffer_limits(self, high=None, low=None):
|
| 78 |
+
"""Set the high- and low-water limits for write flow control.
|
| 79 |
+
|
| 80 |
+
These two values control when to call the protocol's
|
| 81 |
+
pause_writing() and resume_writing() methods. If specified,
|
| 82 |
+
the low-water limit must be less than or equal to the
|
| 83 |
+
high-water limit. Neither value can be negative.
|
| 84 |
+
|
| 85 |
+
The defaults are implementation-specific. If only the
|
| 86 |
+
high-water limit is given, the low-water limit defaults to an
|
| 87 |
+
implementation-specific value less than or equal to the
|
| 88 |
+
high-water limit. Setting high to zero forces low to zero as
|
| 89 |
+
well, and causes pause_writing() to be called whenever the
|
| 90 |
+
buffer becomes non-empty. Setting low to zero causes
|
| 91 |
+
resume_writing() to be called only once the buffer is empty.
|
| 92 |
+
Use of zero for either limit is generally sub-optimal as it
|
| 93 |
+
reduces opportunities for doing I/O and computation
|
| 94 |
+
concurrently.
|
| 95 |
+
"""
|
| 96 |
+
raise NotImplementedError
|
| 97 |
+
|
| 98 |
+
def get_write_buffer_size(self):
|
| 99 |
+
"""Return the current size of the write buffer."""
|
| 100 |
+
raise NotImplementedError
|
| 101 |
+
|
| 102 |
+
def get_write_buffer_limits(self):
|
| 103 |
+
"""Get the high and low watermarks for write flow control.
|
| 104 |
+
Return a tuple (low, high) where low and high are
|
| 105 |
+
positive number of bytes."""
|
| 106 |
+
raise NotImplementedError
|
| 107 |
+
|
| 108 |
+
def write(self, data):
|
| 109 |
+
"""Write some data bytes to the transport.
|
| 110 |
+
|
| 111 |
+
This does not block; it buffers the data and arranges for it
|
| 112 |
+
to be sent out asynchronously.
|
| 113 |
+
"""
|
| 114 |
+
raise NotImplementedError
|
| 115 |
+
|
| 116 |
+
def writelines(self, list_of_data):
|
| 117 |
+
"""Write a list (or any iterable) of data bytes to the transport.
|
| 118 |
+
|
| 119 |
+
The default implementation concatenates the arguments and
|
| 120 |
+
calls write() on the result.
|
| 121 |
+
"""
|
| 122 |
+
data = b''.join(list_of_data)
|
| 123 |
+
self.write(data)
|
| 124 |
+
|
| 125 |
+
def write_eof(self):
|
| 126 |
+
"""Close the write end after flushing buffered data.
|
| 127 |
+
|
| 128 |
+
(This is like typing ^D into a UNIX program reading from stdin.)
|
| 129 |
+
|
| 130 |
+
Data may still be received.
|
| 131 |
+
"""
|
| 132 |
+
raise NotImplementedError
|
| 133 |
+
|
| 134 |
+
def can_write_eof(self):
|
| 135 |
+
"""Return True if this transport supports write_eof(), False if not."""
|
| 136 |
+
raise NotImplementedError
|
| 137 |
+
|
| 138 |
+
def abort(self):
|
| 139 |
+
"""Close the transport immediately.
|
| 140 |
+
|
| 141 |
+
Buffered data will be lost. No more data will be received.
|
| 142 |
+
The protocol's connection_lost() method will (eventually) be
|
| 143 |
+
called with None as its argument.
|
| 144 |
+
"""
|
| 145 |
+
raise NotImplementedError
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
class Transport(ReadTransport, WriteTransport):
|
| 149 |
+
"""Interface representing a bidirectional transport.
|
| 150 |
+
|
| 151 |
+
There may be several implementations, but typically, the user does
|
| 152 |
+
not implement new transports; rather, the platform provides some
|
| 153 |
+
useful transports that are implemented using the platform's best
|
| 154 |
+
practices.
|
| 155 |
+
|
| 156 |
+
The user never instantiates a transport directly; they call a
|
| 157 |
+
utility function, passing it a protocol factory and other
|
| 158 |
+
information necessary to create the transport and protocol. (E.g.
|
| 159 |
+
EventLoop.create_connection() or EventLoop.create_server().)
|
| 160 |
+
|
| 161 |
+
The utility function will asynchronously create a transport and a
|
| 162 |
+
protocol and hook them up by calling the protocol's
|
| 163 |
+
connection_made() method, passing it the transport.
|
| 164 |
+
|
| 165 |
+
The implementation here raises NotImplemented for every method
|
| 166 |
+
except writelines(), which calls write() in a loop.
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
__slots__ = ()
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
class DatagramTransport(BaseTransport):
|
| 173 |
+
"""Interface for datagram (UDP) transports."""
|
| 174 |
+
|
| 175 |
+
__slots__ = ()
|
| 176 |
+
|
| 177 |
+
def sendto(self, data, addr=None):
|
| 178 |
+
"""Send data to the transport.
|
| 179 |
+
|
| 180 |
+
This does not block; it buffers the data and arranges for it
|
| 181 |
+
to be sent out asynchronously.
|
| 182 |
+
addr is target socket address.
|
| 183 |
+
If addr is None use target address pointed on transport creation.
|
| 184 |
+
"""
|
| 185 |
+
raise NotImplementedError
|
| 186 |
+
|
| 187 |
+
def abort(self):
|
| 188 |
+
"""Close the transport immediately.
|
| 189 |
+
|
| 190 |
+
Buffered data will be lost. No more data will be received.
|
| 191 |
+
The protocol's connection_lost() method will (eventually) be
|
| 192 |
+
called with None as its argument.
|
| 193 |
+
"""
|
| 194 |
+
raise NotImplementedError
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
class SubprocessTransport(BaseTransport):
|
| 198 |
+
|
| 199 |
+
__slots__ = ()
|
| 200 |
+
|
| 201 |
+
def get_pid(self):
|
| 202 |
+
"""Get subprocess id."""
|
| 203 |
+
raise NotImplementedError
|
| 204 |
+
|
| 205 |
+
def get_returncode(self):
|
| 206 |
+
"""Get subprocess returncode.
|
| 207 |
+
|
| 208 |
+
See also
|
| 209 |
+
http://docs.python.org/3/library/subprocess#subprocess.Popen.returncode
|
| 210 |
+
"""
|
| 211 |
+
raise NotImplementedError
|
| 212 |
+
|
| 213 |
+
def get_pipe_transport(self, fd):
|
| 214 |
+
"""Get transport for pipe with number fd."""
|
| 215 |
+
raise NotImplementedError
|
| 216 |
+
|
| 217 |
+
def send_signal(self, signal):
|
| 218 |
+
"""Send signal to subprocess.
|
| 219 |
+
|
| 220 |
+
See also:
|
| 221 |
+
docs.python.org/3/library/subprocess#subprocess.Popen.send_signal
|
| 222 |
+
"""
|
| 223 |
+
raise NotImplementedError
|
| 224 |
+
|
| 225 |
+
def terminate(self):
|
| 226 |
+
"""Stop the subprocess.
|
| 227 |
+
|
| 228 |
+
Alias for close() method.
|
| 229 |
+
|
| 230 |
+
On Posix OSs the method sends SIGTERM to the subprocess.
|
| 231 |
+
On Windows the Win32 API function TerminateProcess()
|
| 232 |
+
is called to stop the subprocess.
|
| 233 |
+
|
| 234 |
+
See also:
|
| 235 |
+
http://docs.python.org/3/library/subprocess#subprocess.Popen.terminate
|
| 236 |
+
"""
|
| 237 |
+
raise NotImplementedError
|
| 238 |
+
|
| 239 |
+
def kill(self):
|
| 240 |
+
"""Kill the subprocess.
|
| 241 |
+
|
| 242 |
+
On Posix OSs the function sends SIGKILL to the subprocess.
|
| 243 |
+
On Windows kill() is an alias for terminate().
|
| 244 |
+
|
| 245 |
+
See also:
|
| 246 |
+
http://docs.python.org/3/library/subprocess#subprocess.Popen.kill
|
| 247 |
+
"""
|
| 248 |
+
raise NotImplementedError
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
class _FlowControlMixin(Transport):
|
| 252 |
+
"""All the logic for (write) flow control in a mix-in base class.
|
| 253 |
+
|
| 254 |
+
The subclass must implement get_write_buffer_size(). It must call
|
| 255 |
+
_maybe_pause_protocol() whenever the write buffer size increases,
|
| 256 |
+
and _maybe_resume_protocol() whenever it decreases. It may also
|
| 257 |
+
override set_write_buffer_limits() (e.g. to specify different
|
| 258 |
+
defaults).
|
| 259 |
+
|
| 260 |
+
The subclass constructor must call super().__init__(extra). This
|
| 261 |
+
will call set_write_buffer_limits().
|
| 262 |
+
|
| 263 |
+
The user may call set_write_buffer_limits() and
|
| 264 |
+
get_write_buffer_size(), and their protocol's pause_writing() and
|
| 265 |
+
resume_writing() may be called.
|
| 266 |
+
"""
|
| 267 |
+
|
| 268 |
+
__slots__ = ('_loop', '_protocol_paused', '_high_water', '_low_water')
|
| 269 |
+
|
| 270 |
+
def __init__(self, extra=None, loop=None):
|
| 271 |
+
super().__init__(extra)
|
| 272 |
+
assert loop is not None
|
| 273 |
+
self._loop = loop
|
| 274 |
+
self._protocol_paused = False
|
| 275 |
+
self._set_write_buffer_limits()
|
| 276 |
+
|
| 277 |
+
def _maybe_pause_protocol(self):
|
| 278 |
+
size = self.get_write_buffer_size()
|
| 279 |
+
if size <= self._high_water:
|
| 280 |
+
return
|
| 281 |
+
if not self._protocol_paused:
|
| 282 |
+
self._protocol_paused = True
|
| 283 |
+
try:
|
| 284 |
+
self._protocol.pause_writing()
|
| 285 |
+
except (SystemExit, KeyboardInterrupt):
|
| 286 |
+
raise
|
| 287 |
+
except BaseException as exc:
|
| 288 |
+
self._loop.call_exception_handler({
|
| 289 |
+
'message': 'protocol.pause_writing() failed',
|
| 290 |
+
'exception': exc,
|
| 291 |
+
'transport': self,
|
| 292 |
+
'protocol': self._protocol,
|
| 293 |
+
})
|
| 294 |
+
|
| 295 |
+
def _maybe_resume_protocol(self):
|
| 296 |
+
if (self._protocol_paused and
|
| 297 |
+
self.get_write_buffer_size() <= self._low_water):
|
| 298 |
+
self._protocol_paused = False
|
| 299 |
+
try:
|
| 300 |
+
self._protocol.resume_writing()
|
| 301 |
+
except (SystemExit, KeyboardInterrupt):
|
| 302 |
+
raise
|
| 303 |
+
except BaseException as exc:
|
| 304 |
+
self._loop.call_exception_handler({
|
| 305 |
+
'message': 'protocol.resume_writing() failed',
|
| 306 |
+
'exception': exc,
|
| 307 |
+
'transport': self,
|
| 308 |
+
'protocol': self._protocol,
|
| 309 |
+
})
|
| 310 |
+
|
| 311 |
+
def get_write_buffer_limits(self):
|
| 312 |
+
return (self._low_water, self._high_water)
|
| 313 |
+
|
| 314 |
+
def _set_write_buffer_limits(self, high=None, low=None):
|
| 315 |
+
if high is None:
|
| 316 |
+
if low is None:
|
| 317 |
+
high = 64 * 1024
|
| 318 |
+
else:
|
| 319 |
+
high = 4 * low
|
| 320 |
+
if low is None:
|
| 321 |
+
low = high // 4
|
| 322 |
+
|
| 323 |
+
if not high >= low >= 0:
|
| 324 |
+
raise ValueError(
|
| 325 |
+
f'high ({high!r}) must be >= low ({low!r}) must be >= 0')
|
| 326 |
+
|
| 327 |
+
self._high_water = high
|
| 328 |
+
self._low_water = low
|
| 329 |
+
|
| 330 |
+
def set_write_buffer_limits(self, high=None, low=None):
|
| 331 |
+
self._set_write_buffer_limits(high=high, low=low)
|
| 332 |
+
self._maybe_pause_protocol()
|
| 333 |
+
|
| 334 |
+
def get_write_buffer_size(self):
|
| 335 |
+
raise NotImplementedError
|
parrot/lib/python3.10/asyncio/windows_events.py
ADDED
|
@@ -0,0 +1,924 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Selector and proactor event loops for Windows."""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
if sys.platform != 'win32': # pragma: no cover
|
| 6 |
+
raise ImportError('win32 only')
|
| 7 |
+
|
| 8 |
+
import _overlapped
|
| 9 |
+
import _winapi
|
| 10 |
+
import errno
|
| 11 |
+
import math
|
| 12 |
+
import msvcrt
|
| 13 |
+
import socket
|
| 14 |
+
import struct
|
| 15 |
+
import time
|
| 16 |
+
import weakref
|
| 17 |
+
|
| 18 |
+
from . import events
|
| 19 |
+
from . import base_subprocess
|
| 20 |
+
from . import futures
|
| 21 |
+
from . import exceptions
|
| 22 |
+
from . import proactor_events
|
| 23 |
+
from . import selector_events
|
| 24 |
+
from . import tasks
|
| 25 |
+
from . import windows_utils
|
| 26 |
+
from .log import logger
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
__all__ = (
|
| 30 |
+
'SelectorEventLoop', 'ProactorEventLoop', 'IocpProactor',
|
| 31 |
+
'DefaultEventLoopPolicy', 'WindowsSelectorEventLoopPolicy',
|
| 32 |
+
'WindowsProactorEventLoopPolicy',
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
NULL = 0
|
| 37 |
+
INFINITE = 0xffffffff
|
| 38 |
+
ERROR_CONNECTION_REFUSED = 1225
|
| 39 |
+
ERROR_CONNECTION_ABORTED = 1236
|
| 40 |
+
|
| 41 |
+
# Initial delay in seconds for connect_pipe() before retrying to connect
|
| 42 |
+
CONNECT_PIPE_INIT_DELAY = 0.001
|
| 43 |
+
|
| 44 |
+
# Maximum delay in seconds for connect_pipe() before retrying to connect
|
| 45 |
+
CONNECT_PIPE_MAX_DELAY = 0.100
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class _OverlappedFuture(futures.Future):
|
| 49 |
+
"""Subclass of Future which represents an overlapped operation.
|
| 50 |
+
|
| 51 |
+
Cancelling it will immediately cancel the overlapped operation.
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
def __init__(self, ov, *, loop=None):
|
| 55 |
+
super().__init__(loop=loop)
|
| 56 |
+
if self._source_traceback:
|
| 57 |
+
del self._source_traceback[-1]
|
| 58 |
+
self._ov = ov
|
| 59 |
+
|
| 60 |
+
def _repr_info(self):
|
| 61 |
+
info = super()._repr_info()
|
| 62 |
+
if self._ov is not None:
|
| 63 |
+
state = 'pending' if self._ov.pending else 'completed'
|
| 64 |
+
info.insert(1, f'overlapped=<{state}, {self._ov.address:#x}>')
|
| 65 |
+
return info
|
| 66 |
+
|
| 67 |
+
def _cancel_overlapped(self):
|
| 68 |
+
if self._ov is None:
|
| 69 |
+
return
|
| 70 |
+
try:
|
| 71 |
+
self._ov.cancel()
|
| 72 |
+
except OSError as exc:
|
| 73 |
+
context = {
|
| 74 |
+
'message': 'Cancelling an overlapped future failed',
|
| 75 |
+
'exception': exc,
|
| 76 |
+
'future': self,
|
| 77 |
+
}
|
| 78 |
+
if self._source_traceback:
|
| 79 |
+
context['source_traceback'] = self._source_traceback
|
| 80 |
+
self._loop.call_exception_handler(context)
|
| 81 |
+
self._ov = None
|
| 82 |
+
|
| 83 |
+
def cancel(self, msg=None):
|
| 84 |
+
self._cancel_overlapped()
|
| 85 |
+
return super().cancel(msg=msg)
|
| 86 |
+
|
| 87 |
+
def set_exception(self, exception):
|
| 88 |
+
super().set_exception(exception)
|
| 89 |
+
self._cancel_overlapped()
|
| 90 |
+
|
| 91 |
+
def set_result(self, result):
|
| 92 |
+
super().set_result(result)
|
| 93 |
+
self._ov = None
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class _BaseWaitHandleFuture(futures.Future):
|
| 97 |
+
"""Subclass of Future which represents a wait handle."""
|
| 98 |
+
|
| 99 |
+
def __init__(self, ov, handle, wait_handle, *, loop=None):
|
| 100 |
+
super().__init__(loop=loop)
|
| 101 |
+
if self._source_traceback:
|
| 102 |
+
del self._source_traceback[-1]
|
| 103 |
+
# Keep a reference to the Overlapped object to keep it alive until the
|
| 104 |
+
# wait is unregistered
|
| 105 |
+
self._ov = ov
|
| 106 |
+
self._handle = handle
|
| 107 |
+
self._wait_handle = wait_handle
|
| 108 |
+
|
| 109 |
+
# Should we call UnregisterWaitEx() if the wait completes
|
| 110 |
+
# or is cancelled?
|
| 111 |
+
self._registered = True
|
| 112 |
+
|
| 113 |
+
def _poll(self):
|
| 114 |
+
# non-blocking wait: use a timeout of 0 millisecond
|
| 115 |
+
return (_winapi.WaitForSingleObject(self._handle, 0) ==
|
| 116 |
+
_winapi.WAIT_OBJECT_0)
|
| 117 |
+
|
| 118 |
+
def _repr_info(self):
|
| 119 |
+
info = super()._repr_info()
|
| 120 |
+
info.append(f'handle={self._handle:#x}')
|
| 121 |
+
if self._handle is not None:
|
| 122 |
+
state = 'signaled' if self._poll() else 'waiting'
|
| 123 |
+
info.append(state)
|
| 124 |
+
if self._wait_handle is not None:
|
| 125 |
+
info.append(f'wait_handle={self._wait_handle:#x}')
|
| 126 |
+
return info
|
| 127 |
+
|
| 128 |
+
def _unregister_wait_cb(self, fut):
|
| 129 |
+
# The wait was unregistered: it's not safe to destroy the Overlapped
|
| 130 |
+
# object
|
| 131 |
+
self._ov = None
|
| 132 |
+
|
| 133 |
+
def _unregister_wait(self):
|
| 134 |
+
if not self._registered:
|
| 135 |
+
return
|
| 136 |
+
self._registered = False
|
| 137 |
+
|
| 138 |
+
wait_handle = self._wait_handle
|
| 139 |
+
self._wait_handle = None
|
| 140 |
+
try:
|
| 141 |
+
_overlapped.UnregisterWait(wait_handle)
|
| 142 |
+
except OSError as exc:
|
| 143 |
+
if exc.winerror != _overlapped.ERROR_IO_PENDING:
|
| 144 |
+
context = {
|
| 145 |
+
'message': 'Failed to unregister the wait handle',
|
| 146 |
+
'exception': exc,
|
| 147 |
+
'future': self,
|
| 148 |
+
}
|
| 149 |
+
if self._source_traceback:
|
| 150 |
+
context['source_traceback'] = self._source_traceback
|
| 151 |
+
self._loop.call_exception_handler(context)
|
| 152 |
+
return
|
| 153 |
+
# ERROR_IO_PENDING means that the unregister is pending
|
| 154 |
+
|
| 155 |
+
self._unregister_wait_cb(None)
|
| 156 |
+
|
| 157 |
+
def cancel(self, msg=None):
|
| 158 |
+
self._unregister_wait()
|
| 159 |
+
return super().cancel(msg=msg)
|
| 160 |
+
|
| 161 |
+
def set_exception(self, exception):
|
| 162 |
+
self._unregister_wait()
|
| 163 |
+
super().set_exception(exception)
|
| 164 |
+
|
| 165 |
+
def set_result(self, result):
|
| 166 |
+
self._unregister_wait()
|
| 167 |
+
super().set_result(result)
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
class _WaitCancelFuture(_BaseWaitHandleFuture):
|
| 171 |
+
"""Subclass of Future which represents a wait for the cancellation of a
|
| 172 |
+
_WaitHandleFuture using an event.
|
| 173 |
+
"""
|
| 174 |
+
|
| 175 |
+
def __init__(self, ov, event, wait_handle, *, loop=None):
|
| 176 |
+
super().__init__(ov, event, wait_handle, loop=loop)
|
| 177 |
+
|
| 178 |
+
self._done_callback = None
|
| 179 |
+
|
| 180 |
+
def cancel(self):
|
| 181 |
+
raise RuntimeError("_WaitCancelFuture must not be cancelled")
|
| 182 |
+
|
| 183 |
+
def set_result(self, result):
|
| 184 |
+
super().set_result(result)
|
| 185 |
+
if self._done_callback is not None:
|
| 186 |
+
self._done_callback(self)
|
| 187 |
+
|
| 188 |
+
def set_exception(self, exception):
|
| 189 |
+
super().set_exception(exception)
|
| 190 |
+
if self._done_callback is not None:
|
| 191 |
+
self._done_callback(self)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
class _WaitHandleFuture(_BaseWaitHandleFuture):
|
| 195 |
+
def __init__(self, ov, handle, wait_handle, proactor, *, loop=None):
|
| 196 |
+
super().__init__(ov, handle, wait_handle, loop=loop)
|
| 197 |
+
self._proactor = proactor
|
| 198 |
+
self._unregister_proactor = True
|
| 199 |
+
self._event = _overlapped.CreateEvent(None, True, False, None)
|
| 200 |
+
self._event_fut = None
|
| 201 |
+
|
| 202 |
+
def _unregister_wait_cb(self, fut):
|
| 203 |
+
if self._event is not None:
|
| 204 |
+
_winapi.CloseHandle(self._event)
|
| 205 |
+
self._event = None
|
| 206 |
+
self._event_fut = None
|
| 207 |
+
|
| 208 |
+
# If the wait was cancelled, the wait may never be signalled, so
|
| 209 |
+
# it's required to unregister it. Otherwise, IocpProactor.close() will
|
| 210 |
+
# wait forever for an event which will never come.
|
| 211 |
+
#
|
| 212 |
+
# If the IocpProactor already received the event, it's safe to call
|
| 213 |
+
# _unregister() because we kept a reference to the Overlapped object
|
| 214 |
+
# which is used as a unique key.
|
| 215 |
+
self._proactor._unregister(self._ov)
|
| 216 |
+
self._proactor = None
|
| 217 |
+
|
| 218 |
+
super()._unregister_wait_cb(fut)
|
| 219 |
+
|
| 220 |
+
def _unregister_wait(self):
|
| 221 |
+
if not self._registered:
|
| 222 |
+
return
|
| 223 |
+
self._registered = False
|
| 224 |
+
|
| 225 |
+
wait_handle = self._wait_handle
|
| 226 |
+
self._wait_handle = None
|
| 227 |
+
try:
|
| 228 |
+
_overlapped.UnregisterWaitEx(wait_handle, self._event)
|
| 229 |
+
except OSError as exc:
|
| 230 |
+
if exc.winerror != _overlapped.ERROR_IO_PENDING:
|
| 231 |
+
context = {
|
| 232 |
+
'message': 'Failed to unregister the wait handle',
|
| 233 |
+
'exception': exc,
|
| 234 |
+
'future': self,
|
| 235 |
+
}
|
| 236 |
+
if self._source_traceback:
|
| 237 |
+
context['source_traceback'] = self._source_traceback
|
| 238 |
+
self._loop.call_exception_handler(context)
|
| 239 |
+
return
|
| 240 |
+
# ERROR_IO_PENDING is not an error, the wait was unregistered
|
| 241 |
+
|
| 242 |
+
self._event_fut = self._proactor._wait_cancel(self._event,
|
| 243 |
+
self._unregister_wait_cb)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
class PipeServer(object):
|
| 247 |
+
"""Class representing a pipe server.
|
| 248 |
+
|
| 249 |
+
This is much like a bound, listening socket.
|
| 250 |
+
"""
|
| 251 |
+
def __init__(self, address):
|
| 252 |
+
self._address = address
|
| 253 |
+
self._free_instances = weakref.WeakSet()
|
| 254 |
+
# initialize the pipe attribute before calling _server_pipe_handle()
|
| 255 |
+
# because this function can raise an exception and the destructor calls
|
| 256 |
+
# the close() method
|
| 257 |
+
self._pipe = None
|
| 258 |
+
self._accept_pipe_future = None
|
| 259 |
+
self._pipe = self._server_pipe_handle(True)
|
| 260 |
+
|
| 261 |
+
def _get_unconnected_pipe(self):
|
| 262 |
+
# Create new instance and return previous one. This ensures
|
| 263 |
+
# that (until the server is closed) there is always at least
|
| 264 |
+
# one pipe handle for address. Therefore if a client attempt
|
| 265 |
+
# to connect it will not fail with FileNotFoundError.
|
| 266 |
+
tmp, self._pipe = self._pipe, self._server_pipe_handle(False)
|
| 267 |
+
return tmp
|
| 268 |
+
|
| 269 |
+
def _server_pipe_handle(self, first):
|
| 270 |
+
# Return a wrapper for a new pipe handle.
|
| 271 |
+
if self.closed():
|
| 272 |
+
return None
|
| 273 |
+
flags = _winapi.PIPE_ACCESS_DUPLEX | _winapi.FILE_FLAG_OVERLAPPED
|
| 274 |
+
if first:
|
| 275 |
+
flags |= _winapi.FILE_FLAG_FIRST_PIPE_INSTANCE
|
| 276 |
+
h = _winapi.CreateNamedPipe(
|
| 277 |
+
self._address, flags,
|
| 278 |
+
_winapi.PIPE_TYPE_MESSAGE | _winapi.PIPE_READMODE_MESSAGE |
|
| 279 |
+
_winapi.PIPE_WAIT,
|
| 280 |
+
_winapi.PIPE_UNLIMITED_INSTANCES,
|
| 281 |
+
windows_utils.BUFSIZE, windows_utils.BUFSIZE,
|
| 282 |
+
_winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL)
|
| 283 |
+
pipe = windows_utils.PipeHandle(h)
|
| 284 |
+
self._free_instances.add(pipe)
|
| 285 |
+
return pipe
|
| 286 |
+
|
| 287 |
+
def closed(self):
|
| 288 |
+
return (self._address is None)
|
| 289 |
+
|
| 290 |
+
def close(self):
|
| 291 |
+
if self._accept_pipe_future is not None:
|
| 292 |
+
self._accept_pipe_future.cancel()
|
| 293 |
+
self._accept_pipe_future = None
|
| 294 |
+
# Close all instances which have not been connected to by a client.
|
| 295 |
+
if self._address is not None:
|
| 296 |
+
for pipe in self._free_instances:
|
| 297 |
+
pipe.close()
|
| 298 |
+
self._pipe = None
|
| 299 |
+
self._address = None
|
| 300 |
+
self._free_instances.clear()
|
| 301 |
+
|
| 302 |
+
__del__ = close
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
class _WindowsSelectorEventLoop(selector_events.BaseSelectorEventLoop):
|
| 306 |
+
"""Windows version of selector event loop."""
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
class ProactorEventLoop(proactor_events.BaseProactorEventLoop):
|
| 310 |
+
"""Windows version of proactor event loop using IOCP."""
|
| 311 |
+
|
| 312 |
+
def __init__(self, proactor=None):
|
| 313 |
+
if proactor is None:
|
| 314 |
+
proactor = IocpProactor()
|
| 315 |
+
super().__init__(proactor)
|
| 316 |
+
|
| 317 |
+
def run_forever(self):
|
| 318 |
+
try:
|
| 319 |
+
assert self._self_reading_future is None
|
| 320 |
+
self.call_soon(self._loop_self_reading)
|
| 321 |
+
super().run_forever()
|
| 322 |
+
finally:
|
| 323 |
+
if self._self_reading_future is not None:
|
| 324 |
+
ov = self._self_reading_future._ov
|
| 325 |
+
self._self_reading_future.cancel()
|
| 326 |
+
# self_reading_future always uses IOCP, so even though it's
|
| 327 |
+
# been cancelled, we need to make sure that the IOCP message
|
| 328 |
+
# is received so that the kernel is not holding on to the
|
| 329 |
+
# memory, possibly causing memory corruption later. Only
|
| 330 |
+
# unregister it if IO is complete in all respects. Otherwise
|
| 331 |
+
# we need another _poll() later to complete the IO.
|
| 332 |
+
if ov is not None and not ov.pending:
|
| 333 |
+
self._proactor._unregister(ov)
|
| 334 |
+
self._self_reading_future = None
|
| 335 |
+
|
| 336 |
+
async def create_pipe_connection(self, protocol_factory, address):
|
| 337 |
+
f = self._proactor.connect_pipe(address)
|
| 338 |
+
pipe = await f
|
| 339 |
+
protocol = protocol_factory()
|
| 340 |
+
trans = self._make_duplex_pipe_transport(pipe, protocol,
|
| 341 |
+
extra={'addr': address})
|
| 342 |
+
return trans, protocol
|
| 343 |
+
|
| 344 |
+
async def start_serving_pipe(self, protocol_factory, address):
|
| 345 |
+
server = PipeServer(address)
|
| 346 |
+
|
| 347 |
+
def loop_accept_pipe(f=None):
|
| 348 |
+
pipe = None
|
| 349 |
+
try:
|
| 350 |
+
if f:
|
| 351 |
+
pipe = f.result()
|
| 352 |
+
server._free_instances.discard(pipe)
|
| 353 |
+
|
| 354 |
+
if server.closed():
|
| 355 |
+
# A client connected before the server was closed:
|
| 356 |
+
# drop the client (close the pipe) and exit
|
| 357 |
+
pipe.close()
|
| 358 |
+
return
|
| 359 |
+
|
| 360 |
+
protocol = protocol_factory()
|
| 361 |
+
self._make_duplex_pipe_transport(
|
| 362 |
+
pipe, protocol, extra={'addr': address})
|
| 363 |
+
|
| 364 |
+
pipe = server._get_unconnected_pipe()
|
| 365 |
+
if pipe is None:
|
| 366 |
+
return
|
| 367 |
+
|
| 368 |
+
f = self._proactor.accept_pipe(pipe)
|
| 369 |
+
except BrokenPipeError:
|
| 370 |
+
if pipe and pipe.fileno() != -1:
|
| 371 |
+
pipe.close()
|
| 372 |
+
self.call_soon(loop_accept_pipe)
|
| 373 |
+
except OSError as exc:
|
| 374 |
+
if pipe and pipe.fileno() != -1:
|
| 375 |
+
self.call_exception_handler({
|
| 376 |
+
'message': 'Pipe accept failed',
|
| 377 |
+
'exception': exc,
|
| 378 |
+
'pipe': pipe,
|
| 379 |
+
})
|
| 380 |
+
pipe.close()
|
| 381 |
+
elif self._debug:
|
| 382 |
+
logger.warning("Accept pipe failed on pipe %r",
|
| 383 |
+
pipe, exc_info=True)
|
| 384 |
+
self.call_soon(loop_accept_pipe)
|
| 385 |
+
except exceptions.CancelledError:
|
| 386 |
+
if pipe:
|
| 387 |
+
pipe.close()
|
| 388 |
+
else:
|
| 389 |
+
server._accept_pipe_future = f
|
| 390 |
+
f.add_done_callback(loop_accept_pipe)
|
| 391 |
+
|
| 392 |
+
self.call_soon(loop_accept_pipe)
|
| 393 |
+
return [server]
|
| 394 |
+
|
| 395 |
+
async def _make_subprocess_transport(self, protocol, args, shell,
|
| 396 |
+
stdin, stdout, stderr, bufsize,
|
| 397 |
+
extra=None, **kwargs):
|
| 398 |
+
waiter = self.create_future()
|
| 399 |
+
transp = _WindowsSubprocessTransport(self, protocol, args, shell,
|
| 400 |
+
stdin, stdout, stderr, bufsize,
|
| 401 |
+
waiter=waiter, extra=extra,
|
| 402 |
+
**kwargs)
|
| 403 |
+
try:
|
| 404 |
+
await waiter
|
| 405 |
+
except (SystemExit, KeyboardInterrupt):
|
| 406 |
+
raise
|
| 407 |
+
except BaseException:
|
| 408 |
+
transp.close()
|
| 409 |
+
await transp._wait()
|
| 410 |
+
raise
|
| 411 |
+
|
| 412 |
+
return transp
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
class IocpProactor:
|
| 416 |
+
"""Proactor implementation using IOCP."""
|
| 417 |
+
|
| 418 |
+
def __init__(self, concurrency=0xffffffff):
|
| 419 |
+
self._loop = None
|
| 420 |
+
self._results = []
|
| 421 |
+
self._iocp = _overlapped.CreateIoCompletionPort(
|
| 422 |
+
_overlapped.INVALID_HANDLE_VALUE, NULL, 0, concurrency)
|
| 423 |
+
self._cache = {}
|
| 424 |
+
self._registered = weakref.WeakSet()
|
| 425 |
+
self._unregistered = []
|
| 426 |
+
self._stopped_serving = weakref.WeakSet()
|
| 427 |
+
|
| 428 |
+
def _check_closed(self):
|
| 429 |
+
if self._iocp is None:
|
| 430 |
+
raise RuntimeError('IocpProactor is closed')
|
| 431 |
+
|
| 432 |
+
def __repr__(self):
|
| 433 |
+
info = ['overlapped#=%s' % len(self._cache),
|
| 434 |
+
'result#=%s' % len(self._results)]
|
| 435 |
+
if self._iocp is None:
|
| 436 |
+
info.append('closed')
|
| 437 |
+
return '<%s %s>' % (self.__class__.__name__, " ".join(info))
|
| 438 |
+
|
| 439 |
+
def set_loop(self, loop):
|
| 440 |
+
self._loop = loop
|
| 441 |
+
|
| 442 |
+
def select(self, timeout=None):
|
| 443 |
+
if not self._results:
|
| 444 |
+
self._poll(timeout)
|
| 445 |
+
tmp = self._results
|
| 446 |
+
self._results = []
|
| 447 |
+
try:
|
| 448 |
+
return tmp
|
| 449 |
+
finally:
|
| 450 |
+
# Needed to break cycles when an exception occurs.
|
| 451 |
+
tmp = None
|
| 452 |
+
|
| 453 |
+
def _result(self, value):
|
| 454 |
+
fut = self._loop.create_future()
|
| 455 |
+
fut.set_result(value)
|
| 456 |
+
return fut
|
| 457 |
+
|
| 458 |
+
def recv(self, conn, nbytes, flags=0):
|
| 459 |
+
self._register_with_iocp(conn)
|
| 460 |
+
ov = _overlapped.Overlapped(NULL)
|
| 461 |
+
try:
|
| 462 |
+
if isinstance(conn, socket.socket):
|
| 463 |
+
ov.WSARecv(conn.fileno(), nbytes, flags)
|
| 464 |
+
else:
|
| 465 |
+
ov.ReadFile(conn.fileno(), nbytes)
|
| 466 |
+
except BrokenPipeError:
|
| 467 |
+
return self._result(b'')
|
| 468 |
+
|
| 469 |
+
def finish_recv(trans, key, ov):
|
| 470 |
+
try:
|
| 471 |
+
return ov.getresult()
|
| 472 |
+
except OSError as exc:
|
| 473 |
+
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
|
| 474 |
+
_overlapped.ERROR_OPERATION_ABORTED):
|
| 475 |
+
raise ConnectionResetError(*exc.args)
|
| 476 |
+
else:
|
| 477 |
+
raise
|
| 478 |
+
|
| 479 |
+
return self._register(ov, conn, finish_recv)
|
| 480 |
+
|
| 481 |
+
def recv_into(self, conn, buf, flags=0):
|
| 482 |
+
self._register_with_iocp(conn)
|
| 483 |
+
ov = _overlapped.Overlapped(NULL)
|
| 484 |
+
try:
|
| 485 |
+
if isinstance(conn, socket.socket):
|
| 486 |
+
ov.WSARecvInto(conn.fileno(), buf, flags)
|
| 487 |
+
else:
|
| 488 |
+
ov.ReadFileInto(conn.fileno(), buf)
|
| 489 |
+
except BrokenPipeError:
|
| 490 |
+
return self._result(0)
|
| 491 |
+
|
| 492 |
+
def finish_recv(trans, key, ov):
|
| 493 |
+
try:
|
| 494 |
+
return ov.getresult()
|
| 495 |
+
except OSError as exc:
|
| 496 |
+
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
|
| 497 |
+
_overlapped.ERROR_OPERATION_ABORTED):
|
| 498 |
+
raise ConnectionResetError(*exc.args)
|
| 499 |
+
else:
|
| 500 |
+
raise
|
| 501 |
+
|
| 502 |
+
return self._register(ov, conn, finish_recv)
|
| 503 |
+
|
| 504 |
+
def recvfrom(self, conn, nbytes, flags=0):
|
| 505 |
+
self._register_with_iocp(conn)
|
| 506 |
+
ov = _overlapped.Overlapped(NULL)
|
| 507 |
+
try:
|
| 508 |
+
ov.WSARecvFrom(conn.fileno(), nbytes, flags)
|
| 509 |
+
except BrokenPipeError:
|
| 510 |
+
return self._result((b'', None))
|
| 511 |
+
|
| 512 |
+
def finish_recv(trans, key, ov):
|
| 513 |
+
try:
|
| 514 |
+
return ov.getresult()
|
| 515 |
+
except OSError as exc:
|
| 516 |
+
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
|
| 517 |
+
_overlapped.ERROR_OPERATION_ABORTED):
|
| 518 |
+
raise ConnectionResetError(*exc.args)
|
| 519 |
+
else:
|
| 520 |
+
raise
|
| 521 |
+
|
| 522 |
+
return self._register(ov, conn, finish_recv)
|
| 523 |
+
|
| 524 |
+
def sendto(self, conn, buf, flags=0, addr=None):
|
| 525 |
+
self._register_with_iocp(conn)
|
| 526 |
+
ov = _overlapped.Overlapped(NULL)
|
| 527 |
+
|
| 528 |
+
ov.WSASendTo(conn.fileno(), buf, flags, addr)
|
| 529 |
+
|
| 530 |
+
def finish_send(trans, key, ov):
|
| 531 |
+
try:
|
| 532 |
+
return ov.getresult()
|
| 533 |
+
except OSError as exc:
|
| 534 |
+
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
|
| 535 |
+
_overlapped.ERROR_OPERATION_ABORTED):
|
| 536 |
+
raise ConnectionResetError(*exc.args)
|
| 537 |
+
else:
|
| 538 |
+
raise
|
| 539 |
+
|
| 540 |
+
return self._register(ov, conn, finish_send)
|
| 541 |
+
|
| 542 |
+
def send(self, conn, buf, flags=0):
|
| 543 |
+
self._register_with_iocp(conn)
|
| 544 |
+
ov = _overlapped.Overlapped(NULL)
|
| 545 |
+
if isinstance(conn, socket.socket):
|
| 546 |
+
ov.WSASend(conn.fileno(), buf, flags)
|
| 547 |
+
else:
|
| 548 |
+
ov.WriteFile(conn.fileno(), buf)
|
| 549 |
+
|
| 550 |
+
def finish_send(trans, key, ov):
|
| 551 |
+
try:
|
| 552 |
+
return ov.getresult()
|
| 553 |
+
except OSError as exc:
|
| 554 |
+
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
|
| 555 |
+
_overlapped.ERROR_OPERATION_ABORTED):
|
| 556 |
+
raise ConnectionResetError(*exc.args)
|
| 557 |
+
else:
|
| 558 |
+
raise
|
| 559 |
+
|
| 560 |
+
return self._register(ov, conn, finish_send)
|
| 561 |
+
|
| 562 |
+
def accept(self, listener):
|
| 563 |
+
self._register_with_iocp(listener)
|
| 564 |
+
conn = self._get_accept_socket(listener.family)
|
| 565 |
+
ov = _overlapped.Overlapped(NULL)
|
| 566 |
+
ov.AcceptEx(listener.fileno(), conn.fileno())
|
| 567 |
+
|
| 568 |
+
def finish_accept(trans, key, ov):
|
| 569 |
+
ov.getresult()
|
| 570 |
+
# Use SO_UPDATE_ACCEPT_CONTEXT so getsockname() etc work.
|
| 571 |
+
buf = struct.pack('@P', listener.fileno())
|
| 572 |
+
conn.setsockopt(socket.SOL_SOCKET,
|
| 573 |
+
_overlapped.SO_UPDATE_ACCEPT_CONTEXT, buf)
|
| 574 |
+
conn.settimeout(listener.gettimeout())
|
| 575 |
+
return conn, conn.getpeername()
|
| 576 |
+
|
| 577 |
+
async def accept_coro(future, conn):
|
| 578 |
+
# Coroutine closing the accept socket if the future is cancelled
|
| 579 |
+
try:
|
| 580 |
+
await future
|
| 581 |
+
except exceptions.CancelledError:
|
| 582 |
+
conn.close()
|
| 583 |
+
raise
|
| 584 |
+
|
| 585 |
+
future = self._register(ov, listener, finish_accept)
|
| 586 |
+
coro = accept_coro(future, conn)
|
| 587 |
+
tasks.ensure_future(coro, loop=self._loop)
|
| 588 |
+
return future
|
| 589 |
+
|
| 590 |
+
def connect(self, conn, address):
|
| 591 |
+
if conn.type == socket.SOCK_DGRAM:
|
| 592 |
+
# WSAConnect will complete immediately for UDP sockets so we don't
|
| 593 |
+
# need to register any IOCP operation
|
| 594 |
+
_overlapped.WSAConnect(conn.fileno(), address)
|
| 595 |
+
fut = self._loop.create_future()
|
| 596 |
+
fut.set_result(None)
|
| 597 |
+
return fut
|
| 598 |
+
|
| 599 |
+
self._register_with_iocp(conn)
|
| 600 |
+
# The socket needs to be locally bound before we call ConnectEx().
|
| 601 |
+
try:
|
| 602 |
+
_overlapped.BindLocal(conn.fileno(), conn.family)
|
| 603 |
+
except OSError as e:
|
| 604 |
+
if e.winerror != errno.WSAEINVAL:
|
| 605 |
+
raise
|
| 606 |
+
# Probably already locally bound; check using getsockname().
|
| 607 |
+
if conn.getsockname()[1] == 0:
|
| 608 |
+
raise
|
| 609 |
+
ov = _overlapped.Overlapped(NULL)
|
| 610 |
+
ov.ConnectEx(conn.fileno(), address)
|
| 611 |
+
|
| 612 |
+
def finish_connect(trans, key, ov):
|
| 613 |
+
ov.getresult()
|
| 614 |
+
# Use SO_UPDATE_CONNECT_CONTEXT so getsockname() etc work.
|
| 615 |
+
conn.setsockopt(socket.SOL_SOCKET,
|
| 616 |
+
_overlapped.SO_UPDATE_CONNECT_CONTEXT, 0)
|
| 617 |
+
return conn
|
| 618 |
+
|
| 619 |
+
return self._register(ov, conn, finish_connect)
|
| 620 |
+
|
| 621 |
+
def sendfile(self, sock, file, offset, count):
|
| 622 |
+
self._register_with_iocp(sock)
|
| 623 |
+
ov = _overlapped.Overlapped(NULL)
|
| 624 |
+
offset_low = offset & 0xffff_ffff
|
| 625 |
+
offset_high = (offset >> 32) & 0xffff_ffff
|
| 626 |
+
ov.TransmitFile(sock.fileno(),
|
| 627 |
+
msvcrt.get_osfhandle(file.fileno()),
|
| 628 |
+
offset_low, offset_high,
|
| 629 |
+
count, 0, 0)
|
| 630 |
+
|
| 631 |
+
def finish_sendfile(trans, key, ov):
|
| 632 |
+
try:
|
| 633 |
+
return ov.getresult()
|
| 634 |
+
except OSError as exc:
|
| 635 |
+
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
|
| 636 |
+
_overlapped.ERROR_OPERATION_ABORTED):
|
| 637 |
+
raise ConnectionResetError(*exc.args)
|
| 638 |
+
else:
|
| 639 |
+
raise
|
| 640 |
+
return self._register(ov, sock, finish_sendfile)
|
| 641 |
+
|
| 642 |
+
def accept_pipe(self, pipe):
|
| 643 |
+
self._register_with_iocp(pipe)
|
| 644 |
+
ov = _overlapped.Overlapped(NULL)
|
| 645 |
+
connected = ov.ConnectNamedPipe(pipe.fileno())
|
| 646 |
+
|
| 647 |
+
if connected:
|
| 648 |
+
# ConnectNamePipe() failed with ERROR_PIPE_CONNECTED which means
|
| 649 |
+
# that the pipe is connected. There is no need to wait for the
|
| 650 |
+
# completion of the connection.
|
| 651 |
+
return self._result(pipe)
|
| 652 |
+
|
| 653 |
+
def finish_accept_pipe(trans, key, ov):
|
| 654 |
+
ov.getresult()
|
| 655 |
+
return pipe
|
| 656 |
+
|
| 657 |
+
return self._register(ov, pipe, finish_accept_pipe)
|
| 658 |
+
|
| 659 |
+
async def connect_pipe(self, address):
|
| 660 |
+
delay = CONNECT_PIPE_INIT_DELAY
|
| 661 |
+
while True:
|
| 662 |
+
# Unfortunately there is no way to do an overlapped connect to
|
| 663 |
+
# a pipe. Call CreateFile() in a loop until it doesn't fail with
|
| 664 |
+
# ERROR_PIPE_BUSY.
|
| 665 |
+
try:
|
| 666 |
+
handle = _overlapped.ConnectPipe(address)
|
| 667 |
+
break
|
| 668 |
+
except OSError as exc:
|
| 669 |
+
if exc.winerror != _overlapped.ERROR_PIPE_BUSY:
|
| 670 |
+
raise
|
| 671 |
+
|
| 672 |
+
# ConnectPipe() failed with ERROR_PIPE_BUSY: retry later
|
| 673 |
+
delay = min(delay * 2, CONNECT_PIPE_MAX_DELAY)
|
| 674 |
+
await tasks.sleep(delay)
|
| 675 |
+
|
| 676 |
+
return windows_utils.PipeHandle(handle)
|
| 677 |
+
|
| 678 |
+
def wait_for_handle(self, handle, timeout=None):
|
| 679 |
+
"""Wait for a handle.
|
| 680 |
+
|
| 681 |
+
Return a Future object. The result of the future is True if the wait
|
| 682 |
+
completed, or False if the wait did not complete (on timeout).
|
| 683 |
+
"""
|
| 684 |
+
return self._wait_for_handle(handle, timeout, False)
|
| 685 |
+
|
| 686 |
+
def _wait_cancel(self, event, done_callback):
|
| 687 |
+
fut = self._wait_for_handle(event, None, True)
|
| 688 |
+
# add_done_callback() cannot be used because the wait may only complete
|
| 689 |
+
# in IocpProactor.close(), while the event loop is not running.
|
| 690 |
+
fut._done_callback = done_callback
|
| 691 |
+
return fut
|
| 692 |
+
|
| 693 |
+
def _wait_for_handle(self, handle, timeout, _is_cancel):
|
| 694 |
+
self._check_closed()
|
| 695 |
+
|
| 696 |
+
if timeout is None:
|
| 697 |
+
ms = _winapi.INFINITE
|
| 698 |
+
else:
|
| 699 |
+
# RegisterWaitForSingleObject() has a resolution of 1 millisecond,
|
| 700 |
+
# round away from zero to wait *at least* timeout seconds.
|
| 701 |
+
ms = math.ceil(timeout * 1e3)
|
| 702 |
+
|
| 703 |
+
# We only create ov so we can use ov.address as a key for the cache.
|
| 704 |
+
ov = _overlapped.Overlapped(NULL)
|
| 705 |
+
wait_handle = _overlapped.RegisterWaitWithQueue(
|
| 706 |
+
handle, self._iocp, ov.address, ms)
|
| 707 |
+
if _is_cancel:
|
| 708 |
+
f = _WaitCancelFuture(ov, handle, wait_handle, loop=self._loop)
|
| 709 |
+
else:
|
| 710 |
+
f = _WaitHandleFuture(ov, handle, wait_handle, self,
|
| 711 |
+
loop=self._loop)
|
| 712 |
+
if f._source_traceback:
|
| 713 |
+
del f._source_traceback[-1]
|
| 714 |
+
|
| 715 |
+
def finish_wait_for_handle(trans, key, ov):
|
| 716 |
+
# Note that this second wait means that we should only use
|
| 717 |
+
# this with handles types where a successful wait has no
|
| 718 |
+
# effect. So events or processes are all right, but locks
|
| 719 |
+
# or semaphores are not. Also note if the handle is
|
| 720 |
+
# signalled and then quickly reset, then we may return
|
| 721 |
+
# False even though we have not timed out.
|
| 722 |
+
return f._poll()
|
| 723 |
+
|
| 724 |
+
self._cache[ov.address] = (f, ov, 0, finish_wait_for_handle)
|
| 725 |
+
return f
|
| 726 |
+
|
| 727 |
+
def _register_with_iocp(self, obj):
|
| 728 |
+
# To get notifications of finished ops on this objects sent to the
|
| 729 |
+
# completion port, were must register the handle.
|
| 730 |
+
if obj not in self._registered:
|
| 731 |
+
self._registered.add(obj)
|
| 732 |
+
_overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
|
| 733 |
+
# XXX We could also use SetFileCompletionNotificationModes()
|
| 734 |
+
# to avoid sending notifications to completion port of ops
|
| 735 |
+
# that succeed immediately.
|
| 736 |
+
|
| 737 |
+
def _register(self, ov, obj, callback):
|
| 738 |
+
self._check_closed()
|
| 739 |
+
|
| 740 |
+
# Return a future which will be set with the result of the
|
| 741 |
+
# operation when it completes. The future's value is actually
|
| 742 |
+
# the value returned by callback().
|
| 743 |
+
f = _OverlappedFuture(ov, loop=self._loop)
|
| 744 |
+
if f._source_traceback:
|
| 745 |
+
del f._source_traceback[-1]
|
| 746 |
+
if not ov.pending:
|
| 747 |
+
# The operation has completed, so no need to postpone the
|
| 748 |
+
# work. We cannot take this short cut if we need the
|
| 749 |
+
# NumberOfBytes, CompletionKey values returned by
|
| 750 |
+
# PostQueuedCompletionStatus().
|
| 751 |
+
try:
|
| 752 |
+
value = callback(None, None, ov)
|
| 753 |
+
except OSError as e:
|
| 754 |
+
f.set_exception(e)
|
| 755 |
+
else:
|
| 756 |
+
f.set_result(value)
|
| 757 |
+
# Even if GetOverlappedResult() was called, we have to wait for the
|
| 758 |
+
# notification of the completion in GetQueuedCompletionStatus().
|
| 759 |
+
# Register the overlapped operation to keep a reference to the
|
| 760 |
+
# OVERLAPPED object, otherwise the memory is freed and Windows may
|
| 761 |
+
# read uninitialized memory.
|
| 762 |
+
|
| 763 |
+
# Register the overlapped operation for later. Note that
|
| 764 |
+
# we only store obj to prevent it from being garbage
|
| 765 |
+
# collected too early.
|
| 766 |
+
self._cache[ov.address] = (f, ov, obj, callback)
|
| 767 |
+
return f
|
| 768 |
+
|
| 769 |
+
def _unregister(self, ov):
|
| 770 |
+
"""Unregister an overlapped object.
|
| 771 |
+
|
| 772 |
+
Call this method when its future has been cancelled. The event can
|
| 773 |
+
already be signalled (pending in the proactor event queue). It is also
|
| 774 |
+
safe if the event is never signalled (because it was cancelled).
|
| 775 |
+
"""
|
| 776 |
+
self._check_closed()
|
| 777 |
+
self._unregistered.append(ov)
|
| 778 |
+
|
| 779 |
+
def _get_accept_socket(self, family):
|
| 780 |
+
s = socket.socket(family)
|
| 781 |
+
s.settimeout(0)
|
| 782 |
+
return s
|
| 783 |
+
|
| 784 |
+
def _poll(self, timeout=None):
|
| 785 |
+
if timeout is None:
|
| 786 |
+
ms = INFINITE
|
| 787 |
+
elif timeout < 0:
|
| 788 |
+
raise ValueError("negative timeout")
|
| 789 |
+
else:
|
| 790 |
+
# GetQueuedCompletionStatus() has a resolution of 1 millisecond,
|
| 791 |
+
# round away from zero to wait *at least* timeout seconds.
|
| 792 |
+
ms = math.ceil(timeout * 1e3)
|
| 793 |
+
if ms >= INFINITE:
|
| 794 |
+
raise ValueError("timeout too big")
|
| 795 |
+
|
| 796 |
+
while True:
|
| 797 |
+
status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
|
| 798 |
+
if status is None:
|
| 799 |
+
break
|
| 800 |
+
ms = 0
|
| 801 |
+
|
| 802 |
+
err, transferred, key, address = status
|
| 803 |
+
try:
|
| 804 |
+
f, ov, obj, callback = self._cache.pop(address)
|
| 805 |
+
except KeyError:
|
| 806 |
+
if self._loop.get_debug():
|
| 807 |
+
self._loop.call_exception_handler({
|
| 808 |
+
'message': ('GetQueuedCompletionStatus() returned an '
|
| 809 |
+
'unexpected event'),
|
| 810 |
+
'status': ('err=%s transferred=%s key=%#x address=%#x'
|
| 811 |
+
% (err, transferred, key, address)),
|
| 812 |
+
})
|
| 813 |
+
|
| 814 |
+
# key is either zero, or it is used to return a pipe
|
| 815 |
+
# handle which should be closed to avoid a leak.
|
| 816 |
+
if key not in (0, _overlapped.INVALID_HANDLE_VALUE):
|
| 817 |
+
_winapi.CloseHandle(key)
|
| 818 |
+
continue
|
| 819 |
+
|
| 820 |
+
if obj in self._stopped_serving:
|
| 821 |
+
f.cancel()
|
| 822 |
+
# Don't call the callback if _register() already read the result or
|
| 823 |
+
# if the overlapped has been cancelled
|
| 824 |
+
elif not f.done():
|
| 825 |
+
try:
|
| 826 |
+
value = callback(transferred, key, ov)
|
| 827 |
+
except OSError as e:
|
| 828 |
+
f.set_exception(e)
|
| 829 |
+
self._results.append(f)
|
| 830 |
+
else:
|
| 831 |
+
f.set_result(value)
|
| 832 |
+
self._results.append(f)
|
| 833 |
+
finally:
|
| 834 |
+
f = None
|
| 835 |
+
|
| 836 |
+
# Remove unregistered futures
|
| 837 |
+
for ov in self._unregistered:
|
| 838 |
+
self._cache.pop(ov.address, None)
|
| 839 |
+
self._unregistered.clear()
|
| 840 |
+
|
| 841 |
+
def _stop_serving(self, obj):
|
| 842 |
+
# obj is a socket or pipe handle. It will be closed in
|
| 843 |
+
# BaseProactorEventLoop._stop_serving() which will make any
|
| 844 |
+
# pending operations fail quickly.
|
| 845 |
+
self._stopped_serving.add(obj)
|
| 846 |
+
|
| 847 |
+
def close(self):
|
| 848 |
+
if self._iocp is None:
|
| 849 |
+
# already closed
|
| 850 |
+
return
|
| 851 |
+
|
| 852 |
+
# Cancel remaining registered operations.
|
| 853 |
+
for address, (fut, ov, obj, callback) in list(self._cache.items()):
|
| 854 |
+
if fut.cancelled():
|
| 855 |
+
# Nothing to do with cancelled futures
|
| 856 |
+
pass
|
| 857 |
+
elif isinstance(fut, _WaitCancelFuture):
|
| 858 |
+
# _WaitCancelFuture must not be cancelled
|
| 859 |
+
pass
|
| 860 |
+
else:
|
| 861 |
+
try:
|
| 862 |
+
fut.cancel()
|
| 863 |
+
except OSError as exc:
|
| 864 |
+
if self._loop is not None:
|
| 865 |
+
context = {
|
| 866 |
+
'message': 'Cancelling a future failed',
|
| 867 |
+
'exception': exc,
|
| 868 |
+
'future': fut,
|
| 869 |
+
}
|
| 870 |
+
if fut._source_traceback:
|
| 871 |
+
context['source_traceback'] = fut._source_traceback
|
| 872 |
+
self._loop.call_exception_handler(context)
|
| 873 |
+
|
| 874 |
+
# Wait until all cancelled overlapped complete: don't exit with running
|
| 875 |
+
# overlapped to prevent a crash. Display progress every second if the
|
| 876 |
+
# loop is still running.
|
| 877 |
+
msg_update = 1.0
|
| 878 |
+
start_time = time.monotonic()
|
| 879 |
+
next_msg = start_time + msg_update
|
| 880 |
+
while self._cache:
|
| 881 |
+
if next_msg <= time.monotonic():
|
| 882 |
+
logger.debug('%r is running after closing for %.1f seconds',
|
| 883 |
+
self, time.monotonic() - start_time)
|
| 884 |
+
next_msg = time.monotonic() + msg_update
|
| 885 |
+
|
| 886 |
+
# handle a few events, or timeout
|
| 887 |
+
self._poll(msg_update)
|
| 888 |
+
|
| 889 |
+
self._results = []
|
| 890 |
+
|
| 891 |
+
_winapi.CloseHandle(self._iocp)
|
| 892 |
+
self._iocp = None
|
| 893 |
+
|
| 894 |
+
def __del__(self):
|
| 895 |
+
self.close()
|
| 896 |
+
|
| 897 |
+
|
| 898 |
+
class _WindowsSubprocessTransport(base_subprocess.BaseSubprocessTransport):
|
| 899 |
+
|
| 900 |
+
def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
|
| 901 |
+
self._proc = windows_utils.Popen(
|
| 902 |
+
args, shell=shell, stdin=stdin, stdout=stdout, stderr=stderr,
|
| 903 |
+
bufsize=bufsize, **kwargs)
|
| 904 |
+
|
| 905 |
+
def callback(f):
|
| 906 |
+
returncode = self._proc.poll()
|
| 907 |
+
self._process_exited(returncode)
|
| 908 |
+
|
| 909 |
+
f = self._loop._proactor.wait_for_handle(int(self._proc._handle))
|
| 910 |
+
f.add_done_callback(callback)
|
| 911 |
+
|
| 912 |
+
|
| 913 |
+
SelectorEventLoop = _WindowsSelectorEventLoop
|
| 914 |
+
|
| 915 |
+
|
| 916 |
+
class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
|
| 917 |
+
_loop_factory = SelectorEventLoop
|
| 918 |
+
|
| 919 |
+
|
| 920 |
+
class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
|
| 921 |
+
_loop_factory = ProactorEventLoop
|
| 922 |
+
|
| 923 |
+
|
| 924 |
+
DefaultEventLoopPolicy = WindowsProactorEventLoopPolicy
|
videollama2/lib/python3.10/site-packages/setuptools/_core_metadata.py
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Handling of Core Metadata for Python packages (including reading and writing).
|
| 3 |
+
|
| 4 |
+
See: https://packaging.python.org/en/latest/specifications/core-metadata/
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import stat
|
| 11 |
+
import textwrap
|
| 12 |
+
from email import message_from_file
|
| 13 |
+
from email.message import Message
|
| 14 |
+
from tempfile import NamedTemporaryFile
|
| 15 |
+
|
| 16 |
+
from packaging.markers import Marker
|
| 17 |
+
from packaging.requirements import Requirement
|
| 18 |
+
from packaging.utils import canonicalize_name, canonicalize_version
|
| 19 |
+
from packaging.version import Version
|
| 20 |
+
|
| 21 |
+
from . import _normalization, _reqs
|
| 22 |
+
from ._static import is_static
|
| 23 |
+
from .warnings import SetuptoolsDeprecationWarning
|
| 24 |
+
|
| 25 |
+
from distutils.util import rfc822_escape
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def get_metadata_version(self):
|
| 29 |
+
mv = getattr(self, 'metadata_version', None)
|
| 30 |
+
if mv is None:
|
| 31 |
+
mv = Version('2.2')
|
| 32 |
+
self.metadata_version = mv
|
| 33 |
+
return mv
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def rfc822_unescape(content: str) -> str:
|
| 37 |
+
"""Reverse RFC-822 escaping by removing leading whitespaces from content."""
|
| 38 |
+
lines = content.splitlines()
|
| 39 |
+
if len(lines) == 1:
|
| 40 |
+
return lines[0].lstrip()
|
| 41 |
+
return '\n'.join((lines[0].lstrip(), textwrap.dedent('\n'.join(lines[1:]))))
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def _read_field_from_msg(msg: Message, field: str) -> str | None:
|
| 45 |
+
"""Read Message header field."""
|
| 46 |
+
value = msg[field]
|
| 47 |
+
if value == 'UNKNOWN':
|
| 48 |
+
return None
|
| 49 |
+
return value
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def _read_field_unescaped_from_msg(msg: Message, field: str) -> str | None:
|
| 53 |
+
"""Read Message header field and apply rfc822_unescape."""
|
| 54 |
+
value = _read_field_from_msg(msg, field)
|
| 55 |
+
if value is None:
|
| 56 |
+
return value
|
| 57 |
+
return rfc822_unescape(value)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _read_list_from_msg(msg: Message, field: str) -> list[str] | None:
|
| 61 |
+
"""Read Message header field and return all results as list."""
|
| 62 |
+
values = msg.get_all(field, None)
|
| 63 |
+
if values == []:
|
| 64 |
+
return None
|
| 65 |
+
return values
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _read_payload_from_msg(msg: Message) -> str | None:
|
| 69 |
+
value = str(msg.get_payload()).strip()
|
| 70 |
+
if value == 'UNKNOWN' or not value:
|
| 71 |
+
return None
|
| 72 |
+
return value
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def read_pkg_file(self, file):
|
| 76 |
+
"""Reads the metadata values from a file object."""
|
| 77 |
+
msg = message_from_file(file)
|
| 78 |
+
|
| 79 |
+
self.metadata_version = Version(msg['metadata-version'])
|
| 80 |
+
self.name = _read_field_from_msg(msg, 'name')
|
| 81 |
+
self.version = _read_field_from_msg(msg, 'version')
|
| 82 |
+
self.description = _read_field_from_msg(msg, 'summary')
|
| 83 |
+
# we are filling author only.
|
| 84 |
+
self.author = _read_field_from_msg(msg, 'author')
|
| 85 |
+
self.maintainer = None
|
| 86 |
+
self.author_email = _read_field_from_msg(msg, 'author-email')
|
| 87 |
+
self.maintainer_email = None
|
| 88 |
+
self.url = _read_field_from_msg(msg, 'home-page')
|
| 89 |
+
self.download_url = _read_field_from_msg(msg, 'download-url')
|
| 90 |
+
self.license = _read_field_unescaped_from_msg(msg, 'license')
|
| 91 |
+
|
| 92 |
+
self.long_description = _read_field_unescaped_from_msg(msg, 'description')
|
| 93 |
+
if self.long_description is None and self.metadata_version >= Version('2.1'):
|
| 94 |
+
self.long_description = _read_payload_from_msg(msg)
|
| 95 |
+
self.description = _read_field_from_msg(msg, 'summary')
|
| 96 |
+
|
| 97 |
+
if 'keywords' in msg:
|
| 98 |
+
self.keywords = _read_field_from_msg(msg, 'keywords').split(',')
|
| 99 |
+
|
| 100 |
+
self.platforms = _read_list_from_msg(msg, 'platform')
|
| 101 |
+
self.classifiers = _read_list_from_msg(msg, 'classifier')
|
| 102 |
+
|
| 103 |
+
# PEP 314 - these fields only exist in 1.1
|
| 104 |
+
if self.metadata_version == Version('1.1'):
|
| 105 |
+
self.requires = _read_list_from_msg(msg, 'requires')
|
| 106 |
+
self.provides = _read_list_from_msg(msg, 'provides')
|
| 107 |
+
self.obsoletes = _read_list_from_msg(msg, 'obsoletes')
|
| 108 |
+
else:
|
| 109 |
+
self.requires = None
|
| 110 |
+
self.provides = None
|
| 111 |
+
self.obsoletes = None
|
| 112 |
+
|
| 113 |
+
self.license_files = _read_list_from_msg(msg, 'license-file')
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def single_line(val):
|
| 117 |
+
"""
|
| 118 |
+
Quick and dirty validation for Summary pypa/setuptools#1390.
|
| 119 |
+
"""
|
| 120 |
+
if '\n' in val:
|
| 121 |
+
# TODO: Replace with `raise ValueError("newlines not allowed")`
|
| 122 |
+
# after reviewing #2893.
|
| 123 |
+
msg = "newlines are not allowed in `summary` and will break in the future"
|
| 124 |
+
SetuptoolsDeprecationWarning.emit("Invalid config.", msg)
|
| 125 |
+
# due_date is undefined. Controversial change, there was a lot of push back.
|
| 126 |
+
val = val.strip().split('\n')[0]
|
| 127 |
+
return val
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def write_pkg_info(self, base_dir):
|
| 131 |
+
"""Write the PKG-INFO file into the release tree."""
|
| 132 |
+
temp = ""
|
| 133 |
+
final = os.path.join(base_dir, 'PKG-INFO')
|
| 134 |
+
try:
|
| 135 |
+
# Use a temporary file while writing to avoid race conditions
|
| 136 |
+
# (e.g. `importlib.metadata` reading `.egg-info/PKG-INFO`):
|
| 137 |
+
with NamedTemporaryFile("w", encoding="utf-8", dir=base_dir, delete=False) as f:
|
| 138 |
+
temp = f.name
|
| 139 |
+
self.write_pkg_file(f)
|
| 140 |
+
permissions = stat.S_IMODE(os.lstat(temp).st_mode)
|
| 141 |
+
os.chmod(temp, permissions | stat.S_IRGRP | stat.S_IROTH)
|
| 142 |
+
os.replace(temp, final) # atomic operation.
|
| 143 |
+
finally:
|
| 144 |
+
if temp and os.path.exists(temp):
|
| 145 |
+
os.remove(temp)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
# Based on Python 3.5 version
|
| 149 |
+
def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME
|
| 150 |
+
"""Write the PKG-INFO format data to a file object."""
|
| 151 |
+
version = self.get_metadata_version()
|
| 152 |
+
|
| 153 |
+
def write_field(key, value):
|
| 154 |
+
file.write(f"{key}: {value}\n")
|
| 155 |
+
|
| 156 |
+
write_field('Metadata-Version', str(version))
|
| 157 |
+
write_field('Name', self.get_name())
|
| 158 |
+
write_field('Version', self.get_version())
|
| 159 |
+
|
| 160 |
+
summary = self.get_description()
|
| 161 |
+
if summary:
|
| 162 |
+
write_field('Summary', single_line(summary))
|
| 163 |
+
|
| 164 |
+
optional_fields = (
|
| 165 |
+
('Home-page', 'url'),
|
| 166 |
+
('Download-URL', 'download_url'),
|
| 167 |
+
('Author', 'author'),
|
| 168 |
+
('Author-email', 'author_email'),
|
| 169 |
+
('Maintainer', 'maintainer'),
|
| 170 |
+
('Maintainer-email', 'maintainer_email'),
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
for field, attr in optional_fields:
|
| 174 |
+
attr_val = getattr(self, attr, None)
|
| 175 |
+
if attr_val is not None:
|
| 176 |
+
write_field(field, attr_val)
|
| 177 |
+
|
| 178 |
+
license = self.get_license()
|
| 179 |
+
if license:
|
| 180 |
+
write_field('License', rfc822_escape(license))
|
| 181 |
+
|
| 182 |
+
for label, url in self.project_urls.items():
|
| 183 |
+
write_field('Project-URL', f'{label}, {url}')
|
| 184 |
+
|
| 185 |
+
keywords = ','.join(self.get_keywords())
|
| 186 |
+
if keywords:
|
| 187 |
+
write_field('Keywords', keywords)
|
| 188 |
+
|
| 189 |
+
platforms = self.get_platforms() or []
|
| 190 |
+
for platform in platforms:
|
| 191 |
+
write_field('Platform', platform)
|
| 192 |
+
|
| 193 |
+
self._write_list(file, 'Classifier', self.get_classifiers())
|
| 194 |
+
|
| 195 |
+
# PEP 314
|
| 196 |
+
self._write_list(file, 'Requires', self.get_requires())
|
| 197 |
+
self._write_list(file, 'Provides', self.get_provides())
|
| 198 |
+
self._write_list(file, 'Obsoletes', self.get_obsoletes())
|
| 199 |
+
|
| 200 |
+
# Setuptools specific for PEP 345
|
| 201 |
+
if hasattr(self, 'python_requires'):
|
| 202 |
+
write_field('Requires-Python', self.python_requires)
|
| 203 |
+
|
| 204 |
+
# PEP 566
|
| 205 |
+
if self.long_description_content_type:
|
| 206 |
+
write_field('Description-Content-Type', self.long_description_content_type)
|
| 207 |
+
|
| 208 |
+
self._write_list(file, 'License-File', self.license_files or [])
|
| 209 |
+
_write_requirements(self, file)
|
| 210 |
+
|
| 211 |
+
for field, attr in _POSSIBLE_DYNAMIC_FIELDS.items():
|
| 212 |
+
if (val := getattr(self, attr, None)) and not is_static(val):
|
| 213 |
+
write_field('Dynamic', field)
|
| 214 |
+
|
| 215 |
+
long_description = self.get_long_description()
|
| 216 |
+
if long_description:
|
| 217 |
+
file.write(f"\n{long_description}")
|
| 218 |
+
if not long_description.endswith("\n"):
|
| 219 |
+
file.write("\n")
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def _write_requirements(self, file):
|
| 223 |
+
for req in _reqs.parse(self.install_requires):
|
| 224 |
+
file.write(f"Requires-Dist: {req}\n")
|
| 225 |
+
|
| 226 |
+
processed_extras = {}
|
| 227 |
+
for augmented_extra, reqs in self.extras_require.items():
|
| 228 |
+
# Historically, setuptools allows "augmented extras": `<extra>:<condition>`
|
| 229 |
+
unsafe_extra, _, condition = augmented_extra.partition(":")
|
| 230 |
+
unsafe_extra = unsafe_extra.strip()
|
| 231 |
+
extra = _normalization.safe_extra(unsafe_extra)
|
| 232 |
+
|
| 233 |
+
if extra:
|
| 234 |
+
_write_provides_extra(file, processed_extras, extra, unsafe_extra)
|
| 235 |
+
for req in _reqs.parse_strings(reqs):
|
| 236 |
+
r = _include_extra(req, extra, condition.strip())
|
| 237 |
+
file.write(f"Requires-Dist: {r}\n")
|
| 238 |
+
|
| 239 |
+
return processed_extras
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def _include_extra(req: str, extra: str, condition: str) -> Requirement:
|
| 243 |
+
r = Requirement(req) # create a fresh object that can be modified
|
| 244 |
+
parts = (
|
| 245 |
+
f"({r.marker})" if r.marker else None,
|
| 246 |
+
f"({condition})" if condition else None,
|
| 247 |
+
f"extra == {extra!r}" if extra else None,
|
| 248 |
+
)
|
| 249 |
+
r.marker = Marker(" and ".join(x for x in parts if x))
|
| 250 |
+
return r
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def _write_provides_extra(file, processed_extras, safe, unsafe):
|
| 254 |
+
previous = processed_extras.get(safe)
|
| 255 |
+
if previous == unsafe:
|
| 256 |
+
SetuptoolsDeprecationWarning.emit(
|
| 257 |
+
'Ambiguity during "extra" normalization for dependencies.',
|
| 258 |
+
f"""
|
| 259 |
+
{previous!r} and {unsafe!r} normalize to the same value:\n
|
| 260 |
+
{safe!r}\n
|
| 261 |
+
In future versions, setuptools might halt the build process.
|
| 262 |
+
""",
|
| 263 |
+
see_url="https://peps.python.org/pep-0685/",
|
| 264 |
+
)
|
| 265 |
+
else:
|
| 266 |
+
processed_extras[safe] = unsafe
|
| 267 |
+
file.write(f"Provides-Extra: {safe}\n")
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
# from pypa/distutils#244; needed only until that logic is always available
|
| 271 |
+
def get_fullname(self):
|
| 272 |
+
return _distribution_fullname(self.get_name(), self.get_version())
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def _distribution_fullname(name: str, version: str) -> str:
|
| 276 |
+
"""
|
| 277 |
+
>>> _distribution_fullname('setup.tools', '1.0-2')
|
| 278 |
+
'setup_tools-1.0.post2'
|
| 279 |
+
>>> _distribution_fullname('setup-tools', '1.2post2')
|
| 280 |
+
'setup_tools-1.2.post2'
|
| 281 |
+
>>> _distribution_fullname('setup-tools', '1.0-r2')
|
| 282 |
+
'setup_tools-1.0.post2'
|
| 283 |
+
>>> _distribution_fullname('setup.tools', '1.0.post')
|
| 284 |
+
'setup_tools-1.0.post0'
|
| 285 |
+
>>> _distribution_fullname('setup.tools', '1.0+ubuntu-1')
|
| 286 |
+
'setup_tools-1.0+ubuntu.1'
|
| 287 |
+
"""
|
| 288 |
+
return "{}-{}".format(
|
| 289 |
+
canonicalize_name(name).replace('-', '_'),
|
| 290 |
+
canonicalize_version(version, strip_trailing_zero=False),
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
_POSSIBLE_DYNAMIC_FIELDS = {
|
| 295 |
+
# Core Metadata Field x related Distribution attribute
|
| 296 |
+
"author": "author",
|
| 297 |
+
"author-email": "author_email",
|
| 298 |
+
"classifier": "classifiers",
|
| 299 |
+
"description": "long_description",
|
| 300 |
+
"description-content-type": "long_description_content_type",
|
| 301 |
+
"download-url": "download_url",
|
| 302 |
+
"home-page": "url",
|
| 303 |
+
"keywords": "keywords",
|
| 304 |
+
"license": "license",
|
| 305 |
+
# "license-file": "license_files", # XXX: does PEP 639 exempt Dynamic ??
|
| 306 |
+
"maintainer": "maintainer",
|
| 307 |
+
"maintainer-email": "maintainer_email",
|
| 308 |
+
"obsoletes": "obsoletes",
|
| 309 |
+
# "obsoletes-dist": "obsoletes_dist", # NOT USED
|
| 310 |
+
"platform": "platforms",
|
| 311 |
+
"project-url": "project_urls",
|
| 312 |
+
"provides": "provides",
|
| 313 |
+
# "provides-dist": "provides_dist", # NOT USED
|
| 314 |
+
"provides-extra": "extras_require",
|
| 315 |
+
"requires": "requires",
|
| 316 |
+
"requires-dist": "install_requires",
|
| 317 |
+
# "requires-external": "requires_external", # NOT USED
|
| 318 |
+
"requires-python": "python_requires",
|
| 319 |
+
"summary": "description",
|
| 320 |
+
# "supported-platform": "supported_platforms", # NOT USED
|
| 321 |
+
}
|
videollama2/lib/python3.10/site-packages/setuptools/_entry_points.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import itertools
|
| 3 |
+
import operator
|
| 4 |
+
|
| 5 |
+
from jaraco.functools import pass_none
|
| 6 |
+
from jaraco.text import yield_lines
|
| 7 |
+
from more_itertools import consume
|
| 8 |
+
|
| 9 |
+
from ._importlib import metadata
|
| 10 |
+
from ._itertools import ensure_unique
|
| 11 |
+
from .errors import OptionError
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def ensure_valid(ep):
|
| 15 |
+
"""
|
| 16 |
+
Exercise one of the dynamic properties to trigger
|
| 17 |
+
the pattern match.
|
| 18 |
+
"""
|
| 19 |
+
try:
|
| 20 |
+
ep.extras
|
| 21 |
+
except (AttributeError, AssertionError) as ex:
|
| 22 |
+
# Why both? See https://github.com/python/importlib_metadata/issues/488
|
| 23 |
+
msg = (
|
| 24 |
+
f"Problems to parse {ep}.\nPlease ensure entry-point follows the spec: "
|
| 25 |
+
"https://packaging.python.org/en/latest/specifications/entry-points/"
|
| 26 |
+
)
|
| 27 |
+
raise OptionError(msg) from ex
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def load_group(value, group):
|
| 31 |
+
"""
|
| 32 |
+
Given a value of an entry point or series of entry points,
|
| 33 |
+
return each as an EntryPoint.
|
| 34 |
+
"""
|
| 35 |
+
# normalize to a single sequence of lines
|
| 36 |
+
lines = yield_lines(value)
|
| 37 |
+
text = f'[{group}]\n' + '\n'.join(lines)
|
| 38 |
+
return metadata.EntryPoints._from_text(text)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def by_group_and_name(ep):
|
| 42 |
+
return ep.group, ep.name
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def validate(eps: metadata.EntryPoints):
|
| 46 |
+
"""
|
| 47 |
+
Ensure entry points are unique by group and name and validate each.
|
| 48 |
+
"""
|
| 49 |
+
consume(map(ensure_valid, ensure_unique(eps, key=by_group_and_name)))
|
| 50 |
+
return eps
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
@functools.singledispatch
|
| 54 |
+
def load(eps):
|
| 55 |
+
"""
|
| 56 |
+
Given a Distribution.entry_points, produce EntryPoints.
|
| 57 |
+
"""
|
| 58 |
+
groups = itertools.chain.from_iterable(
|
| 59 |
+
load_group(value, group) for group, value in eps.items()
|
| 60 |
+
)
|
| 61 |
+
return validate(metadata.EntryPoints(groups))
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@load.register(str)
|
| 65 |
+
def _(eps):
|
| 66 |
+
r"""
|
| 67 |
+
>>> ep, = load('[console_scripts]\nfoo=bar')
|
| 68 |
+
>>> ep.group
|
| 69 |
+
'console_scripts'
|
| 70 |
+
>>> ep.name
|
| 71 |
+
'foo'
|
| 72 |
+
>>> ep.value
|
| 73 |
+
'bar'
|
| 74 |
+
"""
|
| 75 |
+
return validate(metadata.EntryPoints(metadata.EntryPoints._from_text(eps)))
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
load.register(type(None), lambda x: x)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
@pass_none
|
| 82 |
+
def render(eps: metadata.EntryPoints):
|
| 83 |
+
by_group = operator.attrgetter('group')
|
| 84 |
+
groups = itertools.groupby(sorted(eps, key=by_group), by_group)
|
| 85 |
+
|
| 86 |
+
return '\n'.join(f'[{group}]\n{render_items(items)}\n' for group, items in groups)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def render_items(eps):
|
| 90 |
+
return '\n'.join(f'{ep.name} = {ep.value}' for ep in sorted(eps))
|
videollama2/lib/python3.10/site-packages/setuptools/_imp.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Re-implementation of find_module and get_frozen_object
|
| 3 |
+
from the deprecated imp module.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import importlib.machinery
|
| 7 |
+
import importlib.util
|
| 8 |
+
import os
|
| 9 |
+
import tokenize
|
| 10 |
+
from importlib.util import module_from_spec
|
| 11 |
+
|
| 12 |
+
PY_SOURCE = 1
|
| 13 |
+
PY_COMPILED = 2
|
| 14 |
+
C_EXTENSION = 3
|
| 15 |
+
C_BUILTIN = 6
|
| 16 |
+
PY_FROZEN = 7
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def find_spec(module, paths):
|
| 20 |
+
finder = (
|
| 21 |
+
importlib.machinery.PathFinder().find_spec
|
| 22 |
+
if isinstance(paths, list)
|
| 23 |
+
else importlib.util.find_spec
|
| 24 |
+
)
|
| 25 |
+
return finder(module, paths)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def find_module(module, paths=None):
|
| 29 |
+
"""Just like 'imp.find_module()', but with package support"""
|
| 30 |
+
spec = find_spec(module, paths)
|
| 31 |
+
if spec is None:
|
| 32 |
+
raise ImportError(f"Can't find {module}")
|
| 33 |
+
if not spec.has_location and hasattr(spec, 'submodule_search_locations'):
|
| 34 |
+
spec = importlib.util.spec_from_loader('__init__.py', spec.loader)
|
| 35 |
+
|
| 36 |
+
kind = -1
|
| 37 |
+
file = None
|
| 38 |
+
static = isinstance(spec.loader, type)
|
| 39 |
+
if (
|
| 40 |
+
spec.origin == 'frozen'
|
| 41 |
+
or static
|
| 42 |
+
and issubclass(spec.loader, importlib.machinery.FrozenImporter)
|
| 43 |
+
):
|
| 44 |
+
kind = PY_FROZEN
|
| 45 |
+
path = None # imp compabilty
|
| 46 |
+
suffix = mode = '' # imp compatibility
|
| 47 |
+
elif (
|
| 48 |
+
spec.origin == 'built-in'
|
| 49 |
+
or static
|
| 50 |
+
and issubclass(spec.loader, importlib.machinery.BuiltinImporter)
|
| 51 |
+
):
|
| 52 |
+
kind = C_BUILTIN
|
| 53 |
+
path = None # imp compabilty
|
| 54 |
+
suffix = mode = '' # imp compatibility
|
| 55 |
+
elif spec.has_location:
|
| 56 |
+
path = spec.origin
|
| 57 |
+
suffix = os.path.splitext(path)[1]
|
| 58 |
+
mode = 'r' if suffix in importlib.machinery.SOURCE_SUFFIXES else 'rb'
|
| 59 |
+
|
| 60 |
+
if suffix in importlib.machinery.SOURCE_SUFFIXES:
|
| 61 |
+
kind = PY_SOURCE
|
| 62 |
+
file = tokenize.open(path)
|
| 63 |
+
elif suffix in importlib.machinery.BYTECODE_SUFFIXES:
|
| 64 |
+
kind = PY_COMPILED
|
| 65 |
+
file = open(path, 'rb')
|
| 66 |
+
elif suffix in importlib.machinery.EXTENSION_SUFFIXES:
|
| 67 |
+
kind = C_EXTENSION
|
| 68 |
+
|
| 69 |
+
else:
|
| 70 |
+
path = None
|
| 71 |
+
suffix = mode = ''
|
| 72 |
+
|
| 73 |
+
return file, path, (suffix, mode, kind)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def get_frozen_object(module, paths=None):
|
| 77 |
+
spec = find_spec(module, paths)
|
| 78 |
+
if not spec:
|
| 79 |
+
raise ImportError(f"Can't find {module}")
|
| 80 |
+
return spec.loader.get_code(module)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def get_module(module, paths, info):
|
| 84 |
+
spec = find_spec(module, paths)
|
| 85 |
+
if not spec:
|
| 86 |
+
raise ImportError(f"Can't find {module}")
|
| 87 |
+
return module_from_spec(spec)
|
videollama2/lib/python3.10/site-packages/setuptools/_itertools.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from more_itertools import consume # noqa: F401
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
# copied from jaraco.itertools 6.1
|
| 5 |
+
def ensure_unique(iterable, key=lambda x: x):
|
| 6 |
+
"""
|
| 7 |
+
Wrap an iterable to raise a ValueError if non-unique values are encountered.
|
| 8 |
+
|
| 9 |
+
>>> list(ensure_unique('abc'))
|
| 10 |
+
['a', 'b', 'c']
|
| 11 |
+
>>> consume(ensure_unique('abca'))
|
| 12 |
+
Traceback (most recent call last):
|
| 13 |
+
...
|
| 14 |
+
ValueError: Duplicate element 'a' encountered.
|
| 15 |
+
"""
|
| 16 |
+
seen = set()
|
| 17 |
+
seen_add = seen.add
|
| 18 |
+
for element in iterable:
|
| 19 |
+
k = key(element)
|
| 20 |
+
if k in seen:
|
| 21 |
+
raise ValueError(f"Duplicate element {element!r} encountered.")
|
| 22 |
+
seen_add(k)
|
| 23 |
+
yield element
|
videollama2/lib/python3.10/site-packages/setuptools/_normalization.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Helpers for normalization as expected in wheel/sdist/module file names
|
| 3 |
+
and core metadata
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import re
|
| 7 |
+
|
| 8 |
+
import packaging
|
| 9 |
+
|
| 10 |
+
# https://packaging.python.org/en/latest/specifications/core-metadata/#name
|
| 11 |
+
_VALID_NAME = re.compile(r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.I)
|
| 12 |
+
_UNSAFE_NAME_CHARS = re.compile(r"[^A-Z0-9._-]+", re.I)
|
| 13 |
+
_NON_ALPHANUMERIC = re.compile(r"[^A-Z0-9]+", re.I)
|
| 14 |
+
_PEP440_FALLBACK = re.compile(r"^v?(?P<safe>(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.I)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def safe_identifier(name: str) -> str:
|
| 18 |
+
"""Make a string safe to be used as Python identifier.
|
| 19 |
+
>>> safe_identifier("12abc")
|
| 20 |
+
'_12abc'
|
| 21 |
+
>>> safe_identifier("__editable__.myns.pkg-78.9.3_local")
|
| 22 |
+
'__editable___myns_pkg_78_9_3_local'
|
| 23 |
+
"""
|
| 24 |
+
safe = re.sub(r'\W|^(?=\d)', '_', name)
|
| 25 |
+
assert safe.isidentifier()
|
| 26 |
+
return safe
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def safe_name(component: str) -> str:
|
| 30 |
+
"""Escape a component used as a project name according to Core Metadata.
|
| 31 |
+
>>> safe_name("hello world")
|
| 32 |
+
'hello-world'
|
| 33 |
+
>>> safe_name("hello?world")
|
| 34 |
+
'hello-world'
|
| 35 |
+
>>> safe_name("hello_world")
|
| 36 |
+
'hello_world'
|
| 37 |
+
"""
|
| 38 |
+
# See pkg_resources.safe_name
|
| 39 |
+
return _UNSAFE_NAME_CHARS.sub("-", component)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def safe_version(version: str) -> str:
|
| 43 |
+
"""Convert an arbitrary string into a valid version string.
|
| 44 |
+
Can still raise an ``InvalidVersion`` exception.
|
| 45 |
+
To avoid exceptions use ``best_effort_version``.
|
| 46 |
+
>>> safe_version("1988 12 25")
|
| 47 |
+
'1988.12.25'
|
| 48 |
+
>>> safe_version("v0.2.1")
|
| 49 |
+
'0.2.1'
|
| 50 |
+
>>> safe_version("v0.2?beta")
|
| 51 |
+
'0.2b0'
|
| 52 |
+
>>> safe_version("v0.2 beta")
|
| 53 |
+
'0.2b0'
|
| 54 |
+
>>> safe_version("ubuntu lts")
|
| 55 |
+
Traceback (most recent call last):
|
| 56 |
+
...
|
| 57 |
+
packaging.version.InvalidVersion: Invalid version: 'ubuntu.lts'
|
| 58 |
+
"""
|
| 59 |
+
v = version.replace(' ', '.')
|
| 60 |
+
try:
|
| 61 |
+
return str(packaging.version.Version(v))
|
| 62 |
+
except packaging.version.InvalidVersion:
|
| 63 |
+
attempt = _UNSAFE_NAME_CHARS.sub("-", v)
|
| 64 |
+
return str(packaging.version.Version(attempt))
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def best_effort_version(version: str) -> str:
|
| 68 |
+
"""Convert an arbitrary string into a version-like string.
|
| 69 |
+
Fallback when ``safe_version`` is not safe enough.
|
| 70 |
+
>>> best_effort_version("v0.2 beta")
|
| 71 |
+
'0.2b0'
|
| 72 |
+
>>> best_effort_version("ubuntu lts")
|
| 73 |
+
'0.dev0+sanitized.ubuntu.lts'
|
| 74 |
+
>>> best_effort_version("0.23ubuntu1")
|
| 75 |
+
'0.23.dev0+sanitized.ubuntu1'
|
| 76 |
+
>>> best_effort_version("0.23-")
|
| 77 |
+
'0.23.dev0+sanitized'
|
| 78 |
+
>>> best_effort_version("0.-_")
|
| 79 |
+
'0.dev0+sanitized'
|
| 80 |
+
>>> best_effort_version("42.+?1")
|
| 81 |
+
'42.dev0+sanitized.1'
|
| 82 |
+
"""
|
| 83 |
+
# See pkg_resources._forgiving_version
|
| 84 |
+
try:
|
| 85 |
+
return safe_version(version)
|
| 86 |
+
except packaging.version.InvalidVersion:
|
| 87 |
+
v = version.replace(' ', '.')
|
| 88 |
+
match = _PEP440_FALLBACK.search(v)
|
| 89 |
+
if match:
|
| 90 |
+
safe = match["safe"]
|
| 91 |
+
rest = v[len(safe) :]
|
| 92 |
+
else:
|
| 93 |
+
safe = "0"
|
| 94 |
+
rest = version
|
| 95 |
+
safe_rest = _NON_ALPHANUMERIC.sub(".", rest).strip(".")
|
| 96 |
+
local = f"sanitized.{safe_rest}".strip(".")
|
| 97 |
+
return safe_version(f"{safe}.dev0+{local}")
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def safe_extra(extra: str) -> str:
|
| 101 |
+
"""Normalize extra name according to PEP 685
|
| 102 |
+
>>> safe_extra("_FrIeNdLy-._.-bArD")
|
| 103 |
+
'friendly-bard'
|
| 104 |
+
>>> safe_extra("FrIeNdLy-._.-bArD__._-")
|
| 105 |
+
'friendly-bard'
|
| 106 |
+
"""
|
| 107 |
+
return _NON_ALPHANUMERIC.sub("-", extra).strip("-").lower()
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def filename_component(value: str) -> str:
|
| 111 |
+
"""Normalize each component of a filename (e.g. distribution/version part of wheel)
|
| 112 |
+
Note: ``value`` needs to be already normalized.
|
| 113 |
+
>>> filename_component("my-pkg")
|
| 114 |
+
'my_pkg'
|
| 115 |
+
"""
|
| 116 |
+
return value.replace("-", "_").strip("_")
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def filename_component_broken(value: str) -> str:
|
| 120 |
+
"""
|
| 121 |
+
Produce the incorrect filename component for compatibility.
|
| 122 |
+
|
| 123 |
+
See pypa/setuptools#4167 for detailed analysis.
|
| 124 |
+
|
| 125 |
+
TODO: replace this with filename_component after pip 24 is
|
| 126 |
+
nearly-ubiquitous.
|
| 127 |
+
|
| 128 |
+
>>> filename_component_broken('foo_bar-baz')
|
| 129 |
+
'foo-bar-baz'
|
| 130 |
+
"""
|
| 131 |
+
return value.replace('_', '-')
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def safer_name(value: str) -> str:
|
| 135 |
+
"""Like ``safe_name`` but can be used as filename component for wheel"""
|
| 136 |
+
# See bdist_wheel.safer_name
|
| 137 |
+
return filename_component(safe_name(value))
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def safer_best_effort_version(value: str) -> str:
|
| 141 |
+
"""Like ``best_effort_version`` but can be used as filename component for wheel"""
|
| 142 |
+
# See bdist_wheel.safer_verion
|
| 143 |
+
# TODO: Replace with only safe_version in the future (no need for best effort)
|
| 144 |
+
return filename_component(best_effort_version(value))
|
videollama2/lib/python3.10/site-packages/setuptools/_path.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import contextlib
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
from typing import TYPE_CHECKING, TypeVar, Union
|
| 7 |
+
|
| 8 |
+
from more_itertools import unique_everseen
|
| 9 |
+
|
| 10 |
+
if TYPE_CHECKING:
|
| 11 |
+
from typing_extensions import TypeAlias
|
| 12 |
+
|
| 13 |
+
StrPath: TypeAlias = Union[str, os.PathLike[str]] # Same as _typeshed.StrPath
|
| 14 |
+
StrPathT = TypeVar("StrPathT", bound=Union[str, os.PathLike[str]])
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def ensure_directory(path):
|
| 18 |
+
"""Ensure that the parent directory of `path` exists"""
|
| 19 |
+
dirname = os.path.dirname(path)
|
| 20 |
+
os.makedirs(dirname, exist_ok=True)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def same_path(p1: StrPath, p2: StrPath) -> bool:
|
| 24 |
+
"""Differs from os.path.samefile because it does not require paths to exist.
|
| 25 |
+
Purely string based (no comparison between i-nodes).
|
| 26 |
+
>>> same_path("a/b", "./a/b")
|
| 27 |
+
True
|
| 28 |
+
>>> same_path("a/b", "a/./b")
|
| 29 |
+
True
|
| 30 |
+
>>> same_path("a/b", "././a/b")
|
| 31 |
+
True
|
| 32 |
+
>>> same_path("a/b", "./a/b/c/..")
|
| 33 |
+
True
|
| 34 |
+
>>> same_path("a/b", "../a/b/c")
|
| 35 |
+
False
|
| 36 |
+
>>> same_path("a", "a/b")
|
| 37 |
+
False
|
| 38 |
+
"""
|
| 39 |
+
return normpath(p1) == normpath(p2)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def normpath(filename: StrPath) -> str:
|
| 43 |
+
"""Normalize a file/dir name for comparison purposes."""
|
| 44 |
+
# See pkg_resources.normalize_path for notes about cygwin
|
| 45 |
+
file = os.path.abspath(filename) if sys.platform == 'cygwin' else filename
|
| 46 |
+
return os.path.normcase(os.path.realpath(os.path.normpath(file)))
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
@contextlib.contextmanager
|
| 50 |
+
def paths_on_pythonpath(paths):
|
| 51 |
+
"""
|
| 52 |
+
Add the indicated paths to the head of the PYTHONPATH environment
|
| 53 |
+
variable so that subprocesses will also see the packages at
|
| 54 |
+
these paths.
|
| 55 |
+
|
| 56 |
+
Do this in a context that restores the value on exit.
|
| 57 |
+
|
| 58 |
+
>>> getfixture('monkeypatch').setenv('PYTHONPATH', 'anything')
|
| 59 |
+
>>> with paths_on_pythonpath(['foo', 'bar']):
|
| 60 |
+
... assert 'foo' in os.environ['PYTHONPATH']
|
| 61 |
+
... assert 'anything' in os.environ['PYTHONPATH']
|
| 62 |
+
>>> os.environ['PYTHONPATH']
|
| 63 |
+
'anything'
|
| 64 |
+
|
| 65 |
+
>>> getfixture('monkeypatch').delenv('PYTHONPATH')
|
| 66 |
+
>>> with paths_on_pythonpath(['foo', 'bar']):
|
| 67 |
+
... assert 'foo' in os.environ['PYTHONPATH']
|
| 68 |
+
>>> os.environ.get('PYTHONPATH')
|
| 69 |
+
"""
|
| 70 |
+
nothing = object()
|
| 71 |
+
orig_pythonpath = os.environ.get('PYTHONPATH', nothing)
|
| 72 |
+
current_pythonpath = os.environ.get('PYTHONPATH', '')
|
| 73 |
+
try:
|
| 74 |
+
prefix = os.pathsep.join(unique_everseen(paths))
|
| 75 |
+
to_join = filter(None, [prefix, current_pythonpath])
|
| 76 |
+
new_path = os.pathsep.join(to_join)
|
| 77 |
+
if new_path:
|
| 78 |
+
os.environ['PYTHONPATH'] = new_path
|
| 79 |
+
yield
|
| 80 |
+
finally:
|
| 81 |
+
if orig_pythonpath is nothing:
|
| 82 |
+
os.environ.pop('PYTHONPATH', None)
|
| 83 |
+
else:
|
| 84 |
+
os.environ['PYTHONPATH'] = orig_pythonpath
|
videollama2/lib/python3.10/site-packages/setuptools/_reqs.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from collections.abc import Iterable, Iterator
|
| 4 |
+
from functools import lru_cache
|
| 5 |
+
from typing import TYPE_CHECKING, Callable, TypeVar, Union, overload
|
| 6 |
+
|
| 7 |
+
import jaraco.text as text
|
| 8 |
+
from packaging.requirements import Requirement
|
| 9 |
+
|
| 10 |
+
if TYPE_CHECKING:
|
| 11 |
+
from typing_extensions import TypeAlias
|
| 12 |
+
|
| 13 |
+
_T = TypeVar("_T")
|
| 14 |
+
_StrOrIter: TypeAlias = Union[str, Iterable[str]]
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
parse_req: Callable[[str], Requirement] = lru_cache()(Requirement)
|
| 18 |
+
# Setuptools parses the same requirement many times
|
| 19 |
+
# (e.g. first for validation than for normalisation),
|
| 20 |
+
# so it might be worth to cache.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def parse_strings(strs: _StrOrIter) -> Iterator[str]:
|
| 24 |
+
"""
|
| 25 |
+
Yield requirement strings for each specification in `strs`.
|
| 26 |
+
|
| 27 |
+
`strs` must be a string, or a (possibly-nested) iterable thereof.
|
| 28 |
+
"""
|
| 29 |
+
return text.join_continuation(map(text.drop_comment, text.yield_lines(strs)))
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# These overloads are only needed because of a mypy false-positive, pyright gets it right
|
| 33 |
+
# https://github.com/python/mypy/issues/3737
|
| 34 |
+
@overload
|
| 35 |
+
def parse(strs: _StrOrIter) -> Iterator[Requirement]: ...
|
| 36 |
+
@overload
|
| 37 |
+
def parse(strs: _StrOrIter, parser: Callable[[str], _T]) -> Iterator[_T]: ...
|
| 38 |
+
def parse(strs: _StrOrIter, parser: Callable[[str], _T] = parse_req) -> Iterator[_T]: # type: ignore[assignment]
|
| 39 |
+
"""
|
| 40 |
+
Replacement for ``pkg_resources.parse_requirements`` that uses ``packaging``.
|
| 41 |
+
"""
|
| 42 |
+
return map(parser, parse_strings(strs))
|
videollama2/lib/python3.10/site-packages/setuptools/_static.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import wraps
|
| 2 |
+
from typing import TypeVar
|
| 3 |
+
|
| 4 |
+
import packaging.specifiers
|
| 5 |
+
|
| 6 |
+
from .warnings import SetuptoolsDeprecationWarning
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Static:
|
| 10 |
+
"""
|
| 11 |
+
Wrapper for built-in object types that are allow setuptools to identify
|
| 12 |
+
static core metadata (in opposition to ``Dynamic``, as defined :pep:`643`).
|
| 13 |
+
|
| 14 |
+
The trick is to mark values with :class:`Static` when they come from
|
| 15 |
+
``pyproject.toml`` or ``setup.cfg``, so if any plugin overwrite the value
|
| 16 |
+
with a built-in, setuptools will be able to recognise the change.
|
| 17 |
+
|
| 18 |
+
We inherit from built-in classes, so that we don't need to change the existing
|
| 19 |
+
code base to deal with the new types.
|
| 20 |
+
We also should strive for immutability objects to avoid changes after the
|
| 21 |
+
initial parsing.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
_mutated_: bool = False # TODO: Remove after deprecation warning is solved
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _prevent_modification(target: type, method: str, copying: str) -> None:
|
| 28 |
+
"""
|
| 29 |
+
Because setuptools is very flexible we cannot fully prevent
|
| 30 |
+
plugins and user customisations from modifying static values that were
|
| 31 |
+
parsed from config files.
|
| 32 |
+
But we can attempt to block "in-place" mutations and identify when they
|
| 33 |
+
were done.
|
| 34 |
+
"""
|
| 35 |
+
fn = getattr(target, method, None)
|
| 36 |
+
if fn is None:
|
| 37 |
+
return
|
| 38 |
+
|
| 39 |
+
@wraps(fn)
|
| 40 |
+
def _replacement(self: Static, *args, **kwargs):
|
| 41 |
+
# TODO: After deprecation period raise NotImplementedError instead of warning
|
| 42 |
+
# which obviated the existence and checks of the `_mutated_` attribute.
|
| 43 |
+
self._mutated_ = True
|
| 44 |
+
SetuptoolsDeprecationWarning.emit(
|
| 45 |
+
"Direct modification of value will be disallowed",
|
| 46 |
+
f"""
|
| 47 |
+
In an effort to implement PEP 643, direct/in-place changes of static values
|
| 48 |
+
that come from configuration files are deprecated.
|
| 49 |
+
If you need to modify this value, please first create a copy with {copying}
|
| 50 |
+
and make sure conform to all relevant standards when overriding setuptools
|
| 51 |
+
functionality (https://packaging.python.org/en/latest/specifications/).
|
| 52 |
+
""",
|
| 53 |
+
due_date=(2025, 10, 10), # Initially introduced in 2024-09-06
|
| 54 |
+
)
|
| 55 |
+
return fn(self, *args, **kwargs)
|
| 56 |
+
|
| 57 |
+
_replacement.__doc__ = "" # otherwise doctest may fail.
|
| 58 |
+
setattr(target, method, _replacement)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class Str(str, Static):
|
| 62 |
+
pass
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class Tuple(tuple, Static):
|
| 66 |
+
pass
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class List(list, Static):
|
| 70 |
+
"""
|
| 71 |
+
:meta private:
|
| 72 |
+
>>> x = List([1, 2, 3])
|
| 73 |
+
>>> is_static(x)
|
| 74 |
+
True
|
| 75 |
+
>>> x += [0] # doctest: +IGNORE_EXCEPTION_DETAIL
|
| 76 |
+
Traceback (most recent call last):
|
| 77 |
+
SetuptoolsDeprecationWarning: Direct modification ...
|
| 78 |
+
>>> is_static(x) # no longer static after modification
|
| 79 |
+
False
|
| 80 |
+
>>> y = list(x)
|
| 81 |
+
>>> y.clear()
|
| 82 |
+
>>> y
|
| 83 |
+
[]
|
| 84 |
+
>>> y == x
|
| 85 |
+
False
|
| 86 |
+
>>> is_static(List(y))
|
| 87 |
+
True
|
| 88 |
+
"""
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# Make `List` immutable-ish
|
| 92 |
+
# (certain places of setuptools/distutils issue a warn if we use tuple instead of list)
|
| 93 |
+
for _method in (
|
| 94 |
+
'__delitem__',
|
| 95 |
+
'__iadd__',
|
| 96 |
+
'__setitem__',
|
| 97 |
+
'append',
|
| 98 |
+
'clear',
|
| 99 |
+
'extend',
|
| 100 |
+
'insert',
|
| 101 |
+
'remove',
|
| 102 |
+
'reverse',
|
| 103 |
+
'pop',
|
| 104 |
+
):
|
| 105 |
+
_prevent_modification(List, _method, "`list(value)`")
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class Dict(dict, Static):
|
| 109 |
+
"""
|
| 110 |
+
:meta private:
|
| 111 |
+
>>> x = Dict({'a': 1, 'b': 2})
|
| 112 |
+
>>> is_static(x)
|
| 113 |
+
True
|
| 114 |
+
>>> x['c'] = 0 # doctest: +IGNORE_EXCEPTION_DETAIL
|
| 115 |
+
Traceback (most recent call last):
|
| 116 |
+
SetuptoolsDeprecationWarning: Direct modification ...
|
| 117 |
+
>>> x._mutated_
|
| 118 |
+
True
|
| 119 |
+
>>> is_static(x) # no longer static after modification
|
| 120 |
+
False
|
| 121 |
+
>>> y = dict(x)
|
| 122 |
+
>>> y.popitem()
|
| 123 |
+
('b', 2)
|
| 124 |
+
>>> y == x
|
| 125 |
+
False
|
| 126 |
+
>>> is_static(Dict(y))
|
| 127 |
+
True
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
# Make `Dict` immutable-ish (we cannot inherit from types.MappingProxyType):
|
| 132 |
+
for _method in (
|
| 133 |
+
'__delitem__',
|
| 134 |
+
'__ior__',
|
| 135 |
+
'__setitem__',
|
| 136 |
+
'clear',
|
| 137 |
+
'pop',
|
| 138 |
+
'popitem',
|
| 139 |
+
'setdefault',
|
| 140 |
+
'update',
|
| 141 |
+
):
|
| 142 |
+
_prevent_modification(Dict, _method, "`dict(value)`")
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
class SpecifierSet(packaging.specifiers.SpecifierSet, Static):
|
| 146 |
+
"""Not exactly a built-in type but useful for ``requires-python``"""
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
T = TypeVar("T")
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def noop(value: T) -> T:
|
| 153 |
+
"""
|
| 154 |
+
>>> noop(42)
|
| 155 |
+
42
|
| 156 |
+
"""
|
| 157 |
+
return value
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
_CONVERSIONS = {str: Str, tuple: Tuple, list: List, dict: Dict}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def attempt_conversion(value: T) -> T:
|
| 164 |
+
"""
|
| 165 |
+
>>> is_static(attempt_conversion("hello"))
|
| 166 |
+
True
|
| 167 |
+
>>> is_static(object())
|
| 168 |
+
False
|
| 169 |
+
"""
|
| 170 |
+
return _CONVERSIONS.get(type(value), noop)(value) # type: ignore[call-overload]
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def is_static(value: object) -> bool:
|
| 174 |
+
"""
|
| 175 |
+
>>> is_static(a := Dict({'a': 1}))
|
| 176 |
+
True
|
| 177 |
+
>>> is_static(dict(a))
|
| 178 |
+
False
|
| 179 |
+
>>> is_static(b := List([1, 2, 3]))
|
| 180 |
+
True
|
| 181 |
+
>>> is_static(list(b))
|
| 182 |
+
False
|
| 183 |
+
"""
|
| 184 |
+
return isinstance(value, Static) and not value._mutated_
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A PEP 517 interface to setuptools
|
| 2 |
+
|
| 3 |
+
Previously, when a user or a command line tool (let's call it a "frontend")
|
| 4 |
+
needed to make a request of setuptools to take a certain action, for
|
| 5 |
+
example, generating a list of installation requirements, the frontend
|
| 6 |
+
would call "setup.py egg_info" or "setup.py bdist_wheel" on the command line.
|
| 7 |
+
|
| 8 |
+
PEP 517 defines a different method of interfacing with setuptools. Rather
|
| 9 |
+
than calling "setup.py" directly, the frontend should:
|
| 10 |
+
|
| 11 |
+
1. Set the current directory to the directory with a setup.py file
|
| 12 |
+
2. Import this module into a safe python interpreter (one in which
|
| 13 |
+
setuptools can potentially set global variables or crash hard).
|
| 14 |
+
3. Call one of the functions defined in PEP 517.
|
| 15 |
+
|
| 16 |
+
What each function does is defined in PEP 517. However, here is a "casual"
|
| 17 |
+
definition of the functions (this definition should not be relied on for
|
| 18 |
+
bug reports or API stability):
|
| 19 |
+
|
| 20 |
+
- `build_wheel`: build a wheel in the folder and return the basename
|
| 21 |
+
- `get_requires_for_build_wheel`: get the `setup_requires` to build
|
| 22 |
+
- `prepare_metadata_for_build_wheel`: get the `install_requires`
|
| 23 |
+
- `build_sdist`: build an sdist in the folder and return the basename
|
| 24 |
+
- `get_requires_for_build_sdist`: get the `setup_requires` to build
|
| 25 |
+
|
| 26 |
+
Again, this is not a formal definition! Just a "taste" of the module.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
from __future__ import annotations
|
| 30 |
+
|
| 31 |
+
import contextlib
|
| 32 |
+
import io
|
| 33 |
+
import os
|
| 34 |
+
import shlex
|
| 35 |
+
import shutil
|
| 36 |
+
import sys
|
| 37 |
+
import tempfile
|
| 38 |
+
import tokenize
|
| 39 |
+
import warnings
|
| 40 |
+
from collections.abc import Iterable, Iterator, Mapping
|
| 41 |
+
from pathlib import Path
|
| 42 |
+
from typing import TYPE_CHECKING, Union
|
| 43 |
+
|
| 44 |
+
import setuptools
|
| 45 |
+
|
| 46 |
+
from . import errors
|
| 47 |
+
from ._path import StrPath, same_path
|
| 48 |
+
from ._reqs import parse_strings
|
| 49 |
+
from .warnings import SetuptoolsDeprecationWarning
|
| 50 |
+
|
| 51 |
+
import distutils
|
| 52 |
+
from distutils.util import strtobool
|
| 53 |
+
|
| 54 |
+
if TYPE_CHECKING:
|
| 55 |
+
from typing_extensions import TypeAlias
|
| 56 |
+
|
| 57 |
+
__all__ = [
|
| 58 |
+
'get_requires_for_build_sdist',
|
| 59 |
+
'get_requires_for_build_wheel',
|
| 60 |
+
'prepare_metadata_for_build_wheel',
|
| 61 |
+
'build_wheel',
|
| 62 |
+
'build_sdist',
|
| 63 |
+
'get_requires_for_build_editable',
|
| 64 |
+
'prepare_metadata_for_build_editable',
|
| 65 |
+
'build_editable',
|
| 66 |
+
'__legacy__',
|
| 67 |
+
'SetupRequirementsError',
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
SETUPTOOLS_ENABLE_FEATURES = os.getenv("SETUPTOOLS_ENABLE_FEATURES", "").lower()
|
| 71 |
+
LEGACY_EDITABLE = "legacy-editable" in SETUPTOOLS_ENABLE_FEATURES.replace("_", "-")
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class SetupRequirementsError(BaseException):
|
| 75 |
+
def __init__(self, specifiers) -> None:
|
| 76 |
+
self.specifiers = specifiers
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class Distribution(setuptools.dist.Distribution):
|
| 80 |
+
def fetch_build_eggs(self, specifiers):
|
| 81 |
+
specifier_list = list(parse_strings(specifiers))
|
| 82 |
+
|
| 83 |
+
raise SetupRequirementsError(specifier_list)
|
| 84 |
+
|
| 85 |
+
@classmethod
|
| 86 |
+
@contextlib.contextmanager
|
| 87 |
+
def patch(cls):
|
| 88 |
+
"""
|
| 89 |
+
Replace
|
| 90 |
+
distutils.dist.Distribution with this class
|
| 91 |
+
for the duration of this context.
|
| 92 |
+
"""
|
| 93 |
+
orig = distutils.core.Distribution
|
| 94 |
+
distutils.core.Distribution = cls # type: ignore[misc] # monkeypatching
|
| 95 |
+
try:
|
| 96 |
+
yield
|
| 97 |
+
finally:
|
| 98 |
+
distutils.core.Distribution = orig # type: ignore[misc] # monkeypatching
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
@contextlib.contextmanager
|
| 102 |
+
def no_install_setup_requires():
|
| 103 |
+
"""Temporarily disable installing setup_requires
|
| 104 |
+
|
| 105 |
+
Under PEP 517, the backend reports build dependencies to the frontend,
|
| 106 |
+
and the frontend is responsible for ensuring they're installed.
|
| 107 |
+
So setuptools (acting as a backend) should not try to install them.
|
| 108 |
+
"""
|
| 109 |
+
orig = setuptools._install_setup_requires
|
| 110 |
+
setuptools._install_setup_requires = lambda attrs: None
|
| 111 |
+
try:
|
| 112 |
+
yield
|
| 113 |
+
finally:
|
| 114 |
+
setuptools._install_setup_requires = orig
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def _get_immediate_subdirectories(a_dir):
|
| 118 |
+
return [
|
| 119 |
+
name for name in os.listdir(a_dir) if os.path.isdir(os.path.join(a_dir, name))
|
| 120 |
+
]
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def _file_with_extension(directory: StrPath, extension: str | tuple[str, ...]):
|
| 124 |
+
matching = (f for f in os.listdir(directory) if f.endswith(extension))
|
| 125 |
+
try:
|
| 126 |
+
(file,) = matching
|
| 127 |
+
except ValueError:
|
| 128 |
+
raise ValueError(
|
| 129 |
+
'No distribution was found. Ensure that `setup.py` '
|
| 130 |
+
'is not empty and that it calls `setup()`.'
|
| 131 |
+
) from None
|
| 132 |
+
return file
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _open_setup_script(setup_script):
|
| 136 |
+
if not os.path.exists(setup_script):
|
| 137 |
+
# Supply a default setup.py
|
| 138 |
+
return io.StringIO("from setuptools import setup; setup()")
|
| 139 |
+
|
| 140 |
+
return tokenize.open(setup_script)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
@contextlib.contextmanager
|
| 144 |
+
def suppress_known_deprecation():
|
| 145 |
+
with warnings.catch_warnings():
|
| 146 |
+
warnings.filterwarnings('ignore', 'setup.py install is deprecated')
|
| 147 |
+
yield
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
_ConfigSettings: TypeAlias = Union[Mapping[str, Union[str, list[str], None]], None]
|
| 151 |
+
"""
|
| 152 |
+
Currently the user can run::
|
| 153 |
+
|
| 154 |
+
pip install -e . --config-settings key=value
|
| 155 |
+
python -m build -C--key=value -C key=value
|
| 156 |
+
|
| 157 |
+
- pip will pass both key and value as strings and overwriting repeated keys
|
| 158 |
+
(pypa/pip#11059).
|
| 159 |
+
- build will accumulate values associated with repeated keys in a list.
|
| 160 |
+
It will also accept keys with no associated value.
|
| 161 |
+
This means that an option passed by build can be ``str | list[str] | None``.
|
| 162 |
+
- PEP 517 specifies that ``config_settings`` is an optional dict.
|
| 163 |
+
"""
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
class _ConfigSettingsTranslator:
|
| 167 |
+
"""Translate ``config_settings`` into distutils-style command arguments.
|
| 168 |
+
Only a limited number of options is currently supported.
|
| 169 |
+
"""
|
| 170 |
+
|
| 171 |
+
# See pypa/setuptools#1928 pypa/setuptools#2491
|
| 172 |
+
|
| 173 |
+
def _get_config(self, key: str, config_settings: _ConfigSettings) -> list[str]:
|
| 174 |
+
"""
|
| 175 |
+
Get the value of a specific key in ``config_settings`` as a list of strings.
|
| 176 |
+
|
| 177 |
+
>>> fn = _ConfigSettingsTranslator()._get_config
|
| 178 |
+
>>> fn("--global-option", None)
|
| 179 |
+
[]
|
| 180 |
+
>>> fn("--global-option", {})
|
| 181 |
+
[]
|
| 182 |
+
>>> fn("--global-option", {'--global-option': 'foo'})
|
| 183 |
+
['foo']
|
| 184 |
+
>>> fn("--global-option", {'--global-option': ['foo']})
|
| 185 |
+
['foo']
|
| 186 |
+
>>> fn("--global-option", {'--global-option': 'foo'})
|
| 187 |
+
['foo']
|
| 188 |
+
>>> fn("--global-option", {'--global-option': 'foo bar'})
|
| 189 |
+
['foo', 'bar']
|
| 190 |
+
"""
|
| 191 |
+
cfg = config_settings or {}
|
| 192 |
+
opts = cfg.get(key) or []
|
| 193 |
+
return shlex.split(opts) if isinstance(opts, str) else opts
|
| 194 |
+
|
| 195 |
+
def _global_args(self, config_settings: _ConfigSettings) -> Iterator[str]:
|
| 196 |
+
"""
|
| 197 |
+
Let the user specify ``verbose`` or ``quiet`` + escape hatch via
|
| 198 |
+
``--global-option``.
|
| 199 |
+
Note: ``-v``, ``-vv``, ``-vvv`` have similar effects in setuptools,
|
| 200 |
+
so we just have to cover the basic scenario ``-v``.
|
| 201 |
+
|
| 202 |
+
>>> fn = _ConfigSettingsTranslator()._global_args
|
| 203 |
+
>>> list(fn(None))
|
| 204 |
+
[]
|
| 205 |
+
>>> list(fn({"verbose": "False"}))
|
| 206 |
+
['-q']
|
| 207 |
+
>>> list(fn({"verbose": "1"}))
|
| 208 |
+
['-v']
|
| 209 |
+
>>> list(fn({"--verbose": None}))
|
| 210 |
+
['-v']
|
| 211 |
+
>>> list(fn({"verbose": "true", "--global-option": "-q --no-user-cfg"}))
|
| 212 |
+
['-v', '-q', '--no-user-cfg']
|
| 213 |
+
>>> list(fn({"--quiet": None}))
|
| 214 |
+
['-q']
|
| 215 |
+
"""
|
| 216 |
+
cfg = config_settings or {}
|
| 217 |
+
falsey = {"false", "no", "0", "off"}
|
| 218 |
+
if "verbose" in cfg or "--verbose" in cfg:
|
| 219 |
+
level = str(cfg.get("verbose") or cfg.get("--verbose") or "1")
|
| 220 |
+
yield ("-q" if level.lower() in falsey else "-v")
|
| 221 |
+
if "quiet" in cfg or "--quiet" in cfg:
|
| 222 |
+
level = str(cfg.get("quiet") or cfg.get("--quiet") or "1")
|
| 223 |
+
yield ("-v" if level.lower() in falsey else "-q")
|
| 224 |
+
|
| 225 |
+
yield from self._get_config("--global-option", config_settings)
|
| 226 |
+
|
| 227 |
+
def __dist_info_args(self, config_settings: _ConfigSettings) -> Iterator[str]:
|
| 228 |
+
"""
|
| 229 |
+
The ``dist_info`` command accepts ``tag-date`` and ``tag-build``.
|
| 230 |
+
|
| 231 |
+
.. warning::
|
| 232 |
+
We cannot use this yet as it requires the ``sdist`` and ``bdist_wheel``
|
| 233 |
+
commands run in ``build_sdist`` and ``build_wheel`` to reuse the egg-info
|
| 234 |
+
directory created in ``prepare_metadata_for_build_wheel``.
|
| 235 |
+
|
| 236 |
+
>>> fn = _ConfigSettingsTranslator()._ConfigSettingsTranslator__dist_info_args
|
| 237 |
+
>>> list(fn(None))
|
| 238 |
+
[]
|
| 239 |
+
>>> list(fn({"tag-date": "False"}))
|
| 240 |
+
['--no-date']
|
| 241 |
+
>>> list(fn({"tag-date": None}))
|
| 242 |
+
['--no-date']
|
| 243 |
+
>>> list(fn({"tag-date": "true", "tag-build": ".a"}))
|
| 244 |
+
['--tag-date', '--tag-build', '.a']
|
| 245 |
+
"""
|
| 246 |
+
cfg = config_settings or {}
|
| 247 |
+
if "tag-date" in cfg:
|
| 248 |
+
val = strtobool(str(cfg["tag-date"] or "false"))
|
| 249 |
+
yield ("--tag-date" if val else "--no-date")
|
| 250 |
+
if "tag-build" in cfg:
|
| 251 |
+
yield from ["--tag-build", str(cfg["tag-build"])]
|
| 252 |
+
|
| 253 |
+
def _editable_args(self, config_settings: _ConfigSettings) -> Iterator[str]:
|
| 254 |
+
"""
|
| 255 |
+
The ``editable_wheel`` command accepts ``editable-mode=strict``.
|
| 256 |
+
|
| 257 |
+
>>> fn = _ConfigSettingsTranslator()._editable_args
|
| 258 |
+
>>> list(fn(None))
|
| 259 |
+
[]
|
| 260 |
+
>>> list(fn({"editable-mode": "strict"}))
|
| 261 |
+
['--mode', 'strict']
|
| 262 |
+
"""
|
| 263 |
+
cfg = config_settings or {}
|
| 264 |
+
mode = cfg.get("editable-mode") or cfg.get("editable_mode")
|
| 265 |
+
if not mode:
|
| 266 |
+
return
|
| 267 |
+
yield from ["--mode", str(mode)]
|
| 268 |
+
|
| 269 |
+
def _arbitrary_args(self, config_settings: _ConfigSettings) -> Iterator[str]:
|
| 270 |
+
"""
|
| 271 |
+
Users may expect to pass arbitrary lists of arguments to a command
|
| 272 |
+
via "--global-option" (example provided in PEP 517 of a "escape hatch").
|
| 273 |
+
|
| 274 |
+
>>> fn = _ConfigSettingsTranslator()._arbitrary_args
|
| 275 |
+
>>> list(fn(None))
|
| 276 |
+
[]
|
| 277 |
+
>>> list(fn({}))
|
| 278 |
+
[]
|
| 279 |
+
>>> list(fn({'--build-option': 'foo'}))
|
| 280 |
+
['foo']
|
| 281 |
+
>>> list(fn({'--build-option': ['foo']}))
|
| 282 |
+
['foo']
|
| 283 |
+
>>> list(fn({'--build-option': 'foo'}))
|
| 284 |
+
['foo']
|
| 285 |
+
>>> list(fn({'--build-option': 'foo bar'}))
|
| 286 |
+
['foo', 'bar']
|
| 287 |
+
>>> list(fn({'--global-option': 'foo'}))
|
| 288 |
+
[]
|
| 289 |
+
"""
|
| 290 |
+
yield from self._get_config("--build-option", config_settings)
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
class _BuildMetaBackend(_ConfigSettingsTranslator):
|
| 294 |
+
def _get_build_requires(
|
| 295 |
+
self, config_settings: _ConfigSettings, requirements: list[str]
|
| 296 |
+
):
|
| 297 |
+
sys.argv = [
|
| 298 |
+
*sys.argv[:1],
|
| 299 |
+
*self._global_args(config_settings),
|
| 300 |
+
"egg_info",
|
| 301 |
+
]
|
| 302 |
+
try:
|
| 303 |
+
with Distribution.patch():
|
| 304 |
+
self.run_setup()
|
| 305 |
+
except SetupRequirementsError as e:
|
| 306 |
+
requirements += e.specifiers
|
| 307 |
+
|
| 308 |
+
return requirements
|
| 309 |
+
|
| 310 |
+
def run_setup(self, setup_script: str = 'setup.py'):
|
| 311 |
+
# Note that we can reuse our build directory between calls
|
| 312 |
+
# Correctness comes first, then optimization later
|
| 313 |
+
__file__ = os.path.abspath(setup_script)
|
| 314 |
+
__name__ = '__main__'
|
| 315 |
+
|
| 316 |
+
with _open_setup_script(__file__) as f:
|
| 317 |
+
code = f.read().replace(r'\r\n', r'\n')
|
| 318 |
+
|
| 319 |
+
try:
|
| 320 |
+
exec(code, locals())
|
| 321 |
+
except SystemExit as e:
|
| 322 |
+
if e.code:
|
| 323 |
+
raise
|
| 324 |
+
# We ignore exit code indicating success
|
| 325 |
+
SetuptoolsDeprecationWarning.emit(
|
| 326 |
+
"Running `setup.py` directly as CLI tool is deprecated.",
|
| 327 |
+
"Please avoid using `sys.exit(0)` or similar statements "
|
| 328 |
+
"that don't fit in the paradigm of a configuration file.",
|
| 329 |
+
see_url="https://blog.ganssle.io/articles/2021/10/"
|
| 330 |
+
"setup-py-deprecated.html",
|
| 331 |
+
)
|
| 332 |
+
|
| 333 |
+
def get_requires_for_build_wheel(self, config_settings: _ConfigSettings = None):
|
| 334 |
+
return self._get_build_requires(config_settings, requirements=[])
|
| 335 |
+
|
| 336 |
+
def get_requires_for_build_sdist(self, config_settings: _ConfigSettings = None):
|
| 337 |
+
return self._get_build_requires(config_settings, requirements=[])
|
| 338 |
+
|
| 339 |
+
def _bubble_up_info_directory(
|
| 340 |
+
self, metadata_directory: StrPath, suffix: str
|
| 341 |
+
) -> str:
|
| 342 |
+
"""
|
| 343 |
+
PEP 517 requires that the .dist-info directory be placed in the
|
| 344 |
+
metadata_directory. To comply, we MUST copy the directory to the root.
|
| 345 |
+
|
| 346 |
+
Returns the basename of the info directory, e.g. `proj-0.0.0.dist-info`.
|
| 347 |
+
"""
|
| 348 |
+
info_dir = self._find_info_directory(metadata_directory, suffix)
|
| 349 |
+
if not same_path(info_dir.parent, metadata_directory):
|
| 350 |
+
shutil.move(str(info_dir), metadata_directory)
|
| 351 |
+
# PEP 517 allow other files and dirs to exist in metadata_directory
|
| 352 |
+
return info_dir.name
|
| 353 |
+
|
| 354 |
+
def _find_info_directory(self, metadata_directory: StrPath, suffix: str) -> Path:
|
| 355 |
+
for parent, dirs, _ in os.walk(metadata_directory):
|
| 356 |
+
candidates = [f for f in dirs if f.endswith(suffix)]
|
| 357 |
+
|
| 358 |
+
if len(candidates) != 0 or len(dirs) != 1:
|
| 359 |
+
assert len(candidates) == 1, f"Multiple {suffix} directories found"
|
| 360 |
+
return Path(parent, candidates[0])
|
| 361 |
+
|
| 362 |
+
msg = f"No {suffix} directory found in {metadata_directory}"
|
| 363 |
+
raise errors.InternalError(msg)
|
| 364 |
+
|
| 365 |
+
def prepare_metadata_for_build_wheel(
|
| 366 |
+
self, metadata_directory: StrPath, config_settings: _ConfigSettings = None
|
| 367 |
+
):
|
| 368 |
+
sys.argv = [
|
| 369 |
+
*sys.argv[:1],
|
| 370 |
+
*self._global_args(config_settings),
|
| 371 |
+
"dist_info",
|
| 372 |
+
"--output-dir",
|
| 373 |
+
str(metadata_directory),
|
| 374 |
+
"--keep-egg-info",
|
| 375 |
+
]
|
| 376 |
+
with no_install_setup_requires():
|
| 377 |
+
self.run_setup()
|
| 378 |
+
|
| 379 |
+
self._bubble_up_info_directory(metadata_directory, ".egg-info")
|
| 380 |
+
return self._bubble_up_info_directory(metadata_directory, ".dist-info")
|
| 381 |
+
|
| 382 |
+
def _build_with_temp_dir(
|
| 383 |
+
self,
|
| 384 |
+
setup_command: Iterable[str],
|
| 385 |
+
result_extension: str | tuple[str, ...],
|
| 386 |
+
result_directory: StrPath,
|
| 387 |
+
config_settings: _ConfigSettings,
|
| 388 |
+
arbitrary_args: Iterable[str] = (),
|
| 389 |
+
):
|
| 390 |
+
result_directory = os.path.abspath(result_directory)
|
| 391 |
+
|
| 392 |
+
# Build in a temporary directory, then copy to the target.
|
| 393 |
+
os.makedirs(result_directory, exist_ok=True)
|
| 394 |
+
|
| 395 |
+
with tempfile.TemporaryDirectory(
|
| 396 |
+
prefix=".tmp-", dir=result_directory
|
| 397 |
+
) as tmp_dist_dir:
|
| 398 |
+
sys.argv = [
|
| 399 |
+
*sys.argv[:1],
|
| 400 |
+
*self._global_args(config_settings),
|
| 401 |
+
*setup_command,
|
| 402 |
+
"--dist-dir",
|
| 403 |
+
tmp_dist_dir,
|
| 404 |
+
*arbitrary_args,
|
| 405 |
+
]
|
| 406 |
+
with no_install_setup_requires():
|
| 407 |
+
self.run_setup()
|
| 408 |
+
|
| 409 |
+
result_basename = _file_with_extension(tmp_dist_dir, result_extension)
|
| 410 |
+
result_path = os.path.join(result_directory, result_basename)
|
| 411 |
+
if os.path.exists(result_path):
|
| 412 |
+
# os.rename will fail overwriting on non-Unix.
|
| 413 |
+
os.remove(result_path)
|
| 414 |
+
os.rename(os.path.join(tmp_dist_dir, result_basename), result_path)
|
| 415 |
+
|
| 416 |
+
return result_basename
|
| 417 |
+
|
| 418 |
+
def build_wheel(
|
| 419 |
+
self,
|
| 420 |
+
wheel_directory: StrPath,
|
| 421 |
+
config_settings: _ConfigSettings = None,
|
| 422 |
+
metadata_directory: StrPath | None = None,
|
| 423 |
+
):
|
| 424 |
+
def _build(cmd: list[str]):
|
| 425 |
+
with suppress_known_deprecation():
|
| 426 |
+
return self._build_with_temp_dir(
|
| 427 |
+
cmd,
|
| 428 |
+
'.whl',
|
| 429 |
+
wheel_directory,
|
| 430 |
+
config_settings,
|
| 431 |
+
self._arbitrary_args(config_settings),
|
| 432 |
+
)
|
| 433 |
+
|
| 434 |
+
if metadata_directory is None:
|
| 435 |
+
return _build(['bdist_wheel'])
|
| 436 |
+
|
| 437 |
+
try:
|
| 438 |
+
return _build(['bdist_wheel', '--dist-info-dir', str(metadata_directory)])
|
| 439 |
+
except SystemExit as ex: # pragma: nocover
|
| 440 |
+
# pypa/setuptools#4683
|
| 441 |
+
if "--dist-info-dir not recognized" not in str(ex):
|
| 442 |
+
raise
|
| 443 |
+
_IncompatibleBdistWheel.emit()
|
| 444 |
+
return _build(['bdist_wheel'])
|
| 445 |
+
|
| 446 |
+
def build_sdist(
|
| 447 |
+
self, sdist_directory: StrPath, config_settings: _ConfigSettings = None
|
| 448 |
+
):
|
| 449 |
+
return self._build_with_temp_dir(
|
| 450 |
+
['sdist', '--formats', 'gztar'], '.tar.gz', sdist_directory, config_settings
|
| 451 |
+
)
|
| 452 |
+
|
| 453 |
+
def _get_dist_info_dir(self, metadata_directory: StrPath | None) -> str | None:
|
| 454 |
+
if not metadata_directory:
|
| 455 |
+
return None
|
| 456 |
+
dist_info_candidates = list(Path(metadata_directory).glob("*.dist-info"))
|
| 457 |
+
assert len(dist_info_candidates) <= 1
|
| 458 |
+
return str(dist_info_candidates[0]) if dist_info_candidates else None
|
| 459 |
+
|
| 460 |
+
if not LEGACY_EDITABLE:
|
| 461 |
+
# PEP660 hooks:
|
| 462 |
+
# build_editable
|
| 463 |
+
# get_requires_for_build_editable
|
| 464 |
+
# prepare_metadata_for_build_editable
|
| 465 |
+
def build_editable(
|
| 466 |
+
self,
|
| 467 |
+
wheel_directory: StrPath,
|
| 468 |
+
config_settings: _ConfigSettings = None,
|
| 469 |
+
metadata_directory: StrPath | None = None,
|
| 470 |
+
):
|
| 471 |
+
# XXX can or should we hide our editable_wheel command normally?
|
| 472 |
+
info_dir = self._get_dist_info_dir(metadata_directory)
|
| 473 |
+
opts = ["--dist-info-dir", info_dir] if info_dir else []
|
| 474 |
+
cmd = ["editable_wheel", *opts, *self._editable_args(config_settings)]
|
| 475 |
+
with suppress_known_deprecation():
|
| 476 |
+
return self._build_with_temp_dir(
|
| 477 |
+
cmd, ".whl", wheel_directory, config_settings
|
| 478 |
+
)
|
| 479 |
+
|
| 480 |
+
def get_requires_for_build_editable(
|
| 481 |
+
self, config_settings: _ConfigSettings = None
|
| 482 |
+
):
|
| 483 |
+
return self.get_requires_for_build_wheel(config_settings)
|
| 484 |
+
|
| 485 |
+
def prepare_metadata_for_build_editable(
|
| 486 |
+
self, metadata_directory: StrPath, config_settings: _ConfigSettings = None
|
| 487 |
+
):
|
| 488 |
+
return self.prepare_metadata_for_build_wheel(
|
| 489 |
+
metadata_directory, config_settings
|
| 490 |
+
)
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
class _BuildMetaLegacyBackend(_BuildMetaBackend):
|
| 494 |
+
"""Compatibility backend for setuptools
|
| 495 |
+
|
| 496 |
+
This is a version of setuptools.build_meta that endeavors
|
| 497 |
+
to maintain backwards
|
| 498 |
+
compatibility with pre-PEP 517 modes of invocation. It
|
| 499 |
+
exists as a temporary
|
| 500 |
+
bridge between the old packaging mechanism and the new
|
| 501 |
+
packaging mechanism,
|
| 502 |
+
and will eventually be removed.
|
| 503 |
+
"""
|
| 504 |
+
|
| 505 |
+
def run_setup(self, setup_script: str = 'setup.py'):
|
| 506 |
+
# In order to maintain compatibility with scripts assuming that
|
| 507 |
+
# the setup.py script is in a directory on the PYTHONPATH, inject
|
| 508 |
+
# '' into sys.path. (pypa/setuptools#1642)
|
| 509 |
+
sys_path = list(sys.path) # Save the original path
|
| 510 |
+
|
| 511 |
+
script_dir = os.path.dirname(os.path.abspath(setup_script))
|
| 512 |
+
if script_dir not in sys.path:
|
| 513 |
+
sys.path.insert(0, script_dir)
|
| 514 |
+
|
| 515 |
+
# Some setup.py scripts (e.g. in pygame and numpy) use sys.argv[0] to
|
| 516 |
+
# get the directory of the source code. They expect it to refer to the
|
| 517 |
+
# setup.py script.
|
| 518 |
+
sys_argv_0 = sys.argv[0]
|
| 519 |
+
sys.argv[0] = setup_script
|
| 520 |
+
|
| 521 |
+
try:
|
| 522 |
+
super().run_setup(setup_script=setup_script)
|
| 523 |
+
finally:
|
| 524 |
+
# While PEP 517 frontends should be calling each hook in a fresh
|
| 525 |
+
# subprocess according to the standard (and thus it should not be
|
| 526 |
+
# strictly necessary to restore the old sys.path), we'll restore
|
| 527 |
+
# the original path so that the path manipulation does not persist
|
| 528 |
+
# within the hook after run_setup is called.
|
| 529 |
+
sys.path[:] = sys_path
|
| 530 |
+
sys.argv[0] = sys_argv_0
|
| 531 |
+
|
| 532 |
+
|
| 533 |
+
class _IncompatibleBdistWheel(SetuptoolsDeprecationWarning):
|
| 534 |
+
_SUMMARY = "wheel.bdist_wheel is deprecated, please import it from setuptools"
|
| 535 |
+
_DETAILS = """
|
| 536 |
+
Ensure that any custom bdist_wheel implementation is a subclass of
|
| 537 |
+
setuptools.command.bdist_wheel.bdist_wheel.
|
| 538 |
+
"""
|
| 539 |
+
_DUE_DATE = (2025, 10, 15)
|
| 540 |
+
# Initially introduced in 2024/10/15, but maybe too disruptive to be enforced?
|
| 541 |
+
_SEE_URL = "https://github.com/pypa/wheel/pull/631"
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
# The primary backend
|
| 545 |
+
_BACKEND = _BuildMetaBackend()
|
| 546 |
+
|
| 547 |
+
get_requires_for_build_wheel = _BACKEND.get_requires_for_build_wheel
|
| 548 |
+
get_requires_for_build_sdist = _BACKEND.get_requires_for_build_sdist
|
| 549 |
+
prepare_metadata_for_build_wheel = _BACKEND.prepare_metadata_for_build_wheel
|
| 550 |
+
build_wheel = _BACKEND.build_wheel
|
| 551 |
+
build_sdist = _BACKEND.build_sdist
|
| 552 |
+
|
| 553 |
+
if not LEGACY_EDITABLE:
|
| 554 |
+
get_requires_for_build_editable = _BACKEND.get_requires_for_build_editable
|
| 555 |
+
prepare_metadata_for_build_editable = _BACKEND.prepare_metadata_for_build_editable
|
| 556 |
+
build_editable = _BACKEND.build_editable
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
# The legacy backend
|
| 560 |
+
__legacy__ = _BuildMetaLegacyBackend()
|
videollama2/lib/python3.10/site-packages/setuptools/cli-arm64.exe
ADDED
|
Binary file (13.8 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/config/NOTICE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The following files include code from opensource projects
|
| 2 |
+
(either as direct copies or modified versions):
|
| 3 |
+
|
| 4 |
+
- `setuptools.schema.json`, `distutils.schema.json`:
|
| 5 |
+
- project: `validate-pyproject` - licensed under MPL-2.0
|
| 6 |
+
(https://github.com/abravalheri/validate-pyproject):
|
| 7 |
+
|
| 8 |
+
This Source Code Form is subject to the terms of the Mozilla Public
|
| 9 |
+
License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
| 10 |
+
You can obtain one at https://mozilla.org/MPL/2.0/.
|
videollama2/lib/python3.10/site-packages/setuptools/config/__init__.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""For backward compatibility, expose main functions from
|
| 2 |
+
``setuptools.config.setupcfg``
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from functools import wraps
|
| 6 |
+
from typing import Callable, TypeVar, cast
|
| 7 |
+
|
| 8 |
+
from ..warnings import SetuptoolsDeprecationWarning
|
| 9 |
+
from . import setupcfg
|
| 10 |
+
|
| 11 |
+
Fn = TypeVar("Fn", bound=Callable)
|
| 12 |
+
|
| 13 |
+
__all__ = ('parse_configuration', 'read_configuration')
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _deprecation_notice(fn: Fn) -> Fn:
|
| 17 |
+
@wraps(fn)
|
| 18 |
+
def _wrapper(*args, **kwargs):
|
| 19 |
+
SetuptoolsDeprecationWarning.emit(
|
| 20 |
+
"Deprecated API usage.",
|
| 21 |
+
f"""
|
| 22 |
+
As setuptools moves its configuration towards `pyproject.toml`,
|
| 23 |
+
`{__name__}.{fn.__name__}` became deprecated.
|
| 24 |
+
|
| 25 |
+
For the time being, you can use the `{setupcfg.__name__}` module
|
| 26 |
+
to access a backward compatible API, but this module is provisional
|
| 27 |
+
and might be removed in the future.
|
| 28 |
+
|
| 29 |
+
To read project metadata, consider using
|
| 30 |
+
``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
|
| 31 |
+
For simple scenarios, you can also try parsing the file directly
|
| 32 |
+
with the help of ``configparser``.
|
| 33 |
+
""",
|
| 34 |
+
# due_date not defined yet, because the community still heavily relies on it
|
| 35 |
+
# Warning introduced in 24 Mar 2022
|
| 36 |
+
)
|
| 37 |
+
return fn(*args, **kwargs)
|
| 38 |
+
|
| 39 |
+
return cast(Fn, _wrapper)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
read_configuration = _deprecation_notice(setupcfg.read_configuration)
|
| 43 |
+
parse_configuration = _deprecation_notice(setupcfg.parse_configuration)
|
videollama2/lib/python3.10/site-packages/setuptools/config/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.61 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/config/__pycache__/expand.cpython-310.pyc
ADDED
|
Binary file (18.2 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/config/__pycache__/setupcfg.cpython-310.pyc
ADDED
|
Binary file (24.2 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/config/_apply_pypr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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Translation layer between pyproject config and setuptools distribution and
|
| 2 |
+
metadata objects.
|
| 3 |
+
|
| 4 |
+
The distribution and metadata objects are modeled after (an old version of)
|
| 5 |
+
core metadata, therefore configs in the format specified for ``pyproject.toml``
|
| 6 |
+
need to be processed before being applied.
|
| 7 |
+
|
| 8 |
+
**PRIVATE MODULE**: API reserved for setuptools internal usage only.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import logging
|
| 14 |
+
import os
|
| 15 |
+
from collections.abc import Mapping
|
| 16 |
+
from email.headerregistry import Address
|
| 17 |
+
from functools import partial, reduce
|
| 18 |
+
from inspect import cleandoc
|
| 19 |
+
from itertools import chain
|
| 20 |
+
from types import MappingProxyType
|
| 21 |
+
from typing import TYPE_CHECKING, Any, Callable, TypeVar, Union
|
| 22 |
+
|
| 23 |
+
from .. import _static
|
| 24 |
+
from .._path import StrPath
|
| 25 |
+
from ..errors import RemovedConfigError
|
| 26 |
+
from ..extension import Extension
|
| 27 |
+
from ..warnings import SetuptoolsWarning
|
| 28 |
+
|
| 29 |
+
if TYPE_CHECKING:
|
| 30 |
+
from typing_extensions import TypeAlias
|
| 31 |
+
|
| 32 |
+
from setuptools._importlib import metadata
|
| 33 |
+
from setuptools.dist import Distribution
|
| 34 |
+
|
| 35 |
+
from distutils.dist import _OptionsList # Comes from typeshed
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
EMPTY: Mapping = MappingProxyType({}) # Immutable dict-like
|
| 39 |
+
_ProjectReadmeValue: TypeAlias = Union[str, dict[str, str]]
|
| 40 |
+
_Correspondence: TypeAlias = Callable[["Distribution", Any, Union[StrPath, None]], None]
|
| 41 |
+
_T = TypeVar("_T")
|
| 42 |
+
|
| 43 |
+
_logger = logging.getLogger(__name__)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def apply(dist: Distribution, config: dict, filename: StrPath) -> Distribution:
|
| 47 |
+
"""Apply configuration dict read with :func:`read_configuration`"""
|
| 48 |
+
|
| 49 |
+
if not config:
|
| 50 |
+
return dist # short-circuit unrelated pyproject.toml file
|
| 51 |
+
|
| 52 |
+
root_dir = os.path.dirname(filename) or "."
|
| 53 |
+
|
| 54 |
+
_apply_project_table(dist, config, root_dir)
|
| 55 |
+
_apply_tool_table(dist, config, filename)
|
| 56 |
+
|
| 57 |
+
current_directory = os.getcwd()
|
| 58 |
+
os.chdir(root_dir)
|
| 59 |
+
try:
|
| 60 |
+
dist._finalize_requires()
|
| 61 |
+
dist._finalize_license_files()
|
| 62 |
+
finally:
|
| 63 |
+
os.chdir(current_directory)
|
| 64 |
+
|
| 65 |
+
return dist
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _apply_project_table(dist: Distribution, config: dict, root_dir: StrPath):
|
| 69 |
+
orig_config = config.get("project", {})
|
| 70 |
+
if not orig_config:
|
| 71 |
+
return # short-circuit
|
| 72 |
+
|
| 73 |
+
project_table = {k: _static.attempt_conversion(v) for k, v in orig_config.items()}
|
| 74 |
+
_handle_missing_dynamic(dist, project_table)
|
| 75 |
+
_unify_entry_points(project_table)
|
| 76 |
+
|
| 77 |
+
for field, value in project_table.items():
|
| 78 |
+
norm_key = json_compatible_key(field)
|
| 79 |
+
corresp = PYPROJECT_CORRESPONDENCE.get(norm_key, norm_key)
|
| 80 |
+
if callable(corresp):
|
| 81 |
+
corresp(dist, value, root_dir)
|
| 82 |
+
else:
|
| 83 |
+
_set_config(dist, corresp, value)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def _apply_tool_table(dist: Distribution, config: dict, filename: StrPath):
|
| 87 |
+
tool_table = config.get("tool", {}).get("setuptools", {})
|
| 88 |
+
if not tool_table:
|
| 89 |
+
return # short-circuit
|
| 90 |
+
|
| 91 |
+
for field, value in tool_table.items():
|
| 92 |
+
norm_key = json_compatible_key(field)
|
| 93 |
+
|
| 94 |
+
if norm_key in TOOL_TABLE_REMOVALS:
|
| 95 |
+
suggestion = cleandoc(TOOL_TABLE_REMOVALS[norm_key])
|
| 96 |
+
msg = f"""
|
| 97 |
+
The parameter `tool.setuptools.{field}` was long deprecated
|
| 98 |
+
and has been removed from `pyproject.toml`.
|
| 99 |
+
"""
|
| 100 |
+
raise RemovedConfigError("\n".join([cleandoc(msg), suggestion]))
|
| 101 |
+
|
| 102 |
+
norm_key = TOOL_TABLE_RENAMES.get(norm_key, norm_key)
|
| 103 |
+
corresp = TOOL_TABLE_CORRESPONDENCE.get(norm_key, norm_key)
|
| 104 |
+
if callable(corresp):
|
| 105 |
+
corresp(dist, value)
|
| 106 |
+
else:
|
| 107 |
+
_set_config(dist, corresp, value)
|
| 108 |
+
|
| 109 |
+
_copy_command_options(config, dist, filename)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def _handle_missing_dynamic(dist: Distribution, project_table: dict):
|
| 113 |
+
"""Be temporarily forgiving with ``dynamic`` fields not listed in ``dynamic``"""
|
| 114 |
+
dynamic = set(project_table.get("dynamic", []))
|
| 115 |
+
for field, getter in _PREVIOUSLY_DEFINED.items():
|
| 116 |
+
if not (field in project_table or field in dynamic):
|
| 117 |
+
value = getter(dist)
|
| 118 |
+
if value:
|
| 119 |
+
_MissingDynamic.emit(field=field, value=value)
|
| 120 |
+
project_table[field] = _RESET_PREVIOUSLY_DEFINED.get(field)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def json_compatible_key(key: str) -> str:
|
| 124 |
+
"""As defined in :pep:`566#json-compatible-metadata`"""
|
| 125 |
+
return key.lower().replace("-", "_")
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def _set_config(dist: Distribution, field: str, value: Any):
|
| 129 |
+
val = _PREPROCESS.get(field, _noop)(dist, value)
|
| 130 |
+
setter = getattr(dist.metadata, f"set_{field}", None)
|
| 131 |
+
if setter:
|
| 132 |
+
setter(val)
|
| 133 |
+
elif hasattr(dist.metadata, field) or field in SETUPTOOLS_PATCHES:
|
| 134 |
+
setattr(dist.metadata, field, val)
|
| 135 |
+
else:
|
| 136 |
+
setattr(dist, field, val)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
_CONTENT_TYPES = {
|
| 140 |
+
".md": "text/markdown",
|
| 141 |
+
".rst": "text/x-rst",
|
| 142 |
+
".txt": "text/plain",
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def _guess_content_type(file: str) -> str | None:
|
| 147 |
+
_, ext = os.path.splitext(file.lower())
|
| 148 |
+
if not ext:
|
| 149 |
+
return None
|
| 150 |
+
|
| 151 |
+
if ext in _CONTENT_TYPES:
|
| 152 |
+
return _static.Str(_CONTENT_TYPES[ext])
|
| 153 |
+
|
| 154 |
+
valid = ", ".join(f"{k} ({v})" for k, v in _CONTENT_TYPES.items())
|
| 155 |
+
msg = f"only the following file extensions are recognized: {valid}."
|
| 156 |
+
raise ValueError(f"Undefined content type for {file}, {msg}")
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def _long_description(
|
| 160 |
+
dist: Distribution, val: _ProjectReadmeValue, root_dir: StrPath | None
|
| 161 |
+
):
|
| 162 |
+
from setuptools.config import expand
|
| 163 |
+
|
| 164 |
+
file: str | tuple[()]
|
| 165 |
+
if isinstance(val, str):
|
| 166 |
+
file = val
|
| 167 |
+
text = expand.read_files(file, root_dir)
|
| 168 |
+
ctype = _guess_content_type(file)
|
| 169 |
+
else:
|
| 170 |
+
file = val.get("file") or ()
|
| 171 |
+
text = val.get("text") or expand.read_files(file, root_dir)
|
| 172 |
+
ctype = val["content-type"]
|
| 173 |
+
|
| 174 |
+
# XXX: Is it completely safe to assume static?
|
| 175 |
+
_set_config(dist, "long_description", _static.Str(text))
|
| 176 |
+
|
| 177 |
+
if ctype:
|
| 178 |
+
_set_config(dist, "long_description_content_type", _static.Str(ctype))
|
| 179 |
+
|
| 180 |
+
if file:
|
| 181 |
+
dist._referenced_files.add(file)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def _license(dist: Distribution, val: dict, root_dir: StrPath | None):
|
| 185 |
+
from setuptools.config import expand
|
| 186 |
+
|
| 187 |
+
if "file" in val:
|
| 188 |
+
# XXX: Is it completely safe to assume static?
|
| 189 |
+
value = expand.read_files([val["file"]], root_dir)
|
| 190 |
+
_set_config(dist, "license", _static.Str(value))
|
| 191 |
+
dist._referenced_files.add(val["file"])
|
| 192 |
+
else:
|
| 193 |
+
_set_config(dist, "license", _static.Str(val["text"]))
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _people(dist: Distribution, val: list[dict], _root_dir: StrPath | None, kind: str):
|
| 197 |
+
field = []
|
| 198 |
+
email_field = []
|
| 199 |
+
for person in val:
|
| 200 |
+
if "name" not in person:
|
| 201 |
+
email_field.append(person["email"])
|
| 202 |
+
elif "email" not in person:
|
| 203 |
+
field.append(person["name"])
|
| 204 |
+
else:
|
| 205 |
+
addr = Address(display_name=person["name"], addr_spec=person["email"])
|
| 206 |
+
email_field.append(str(addr))
|
| 207 |
+
|
| 208 |
+
if field:
|
| 209 |
+
_set_config(dist, kind, _static.Str(", ".join(field)))
|
| 210 |
+
if email_field:
|
| 211 |
+
_set_config(dist, f"{kind}_email", _static.Str(", ".join(email_field)))
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def _project_urls(dist: Distribution, val: dict, _root_dir: StrPath | None):
|
| 215 |
+
_set_config(dist, "project_urls", val)
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def _python_requires(dist: Distribution, val: str, _root_dir: StrPath | None):
|
| 219 |
+
_set_config(dist, "python_requires", _static.SpecifierSet(val))
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def _dependencies(dist: Distribution, val: list, _root_dir: StrPath | None):
|
| 223 |
+
if getattr(dist, "install_requires", []):
|
| 224 |
+
msg = "`install_requires` overwritten in `pyproject.toml` (dependencies)"
|
| 225 |
+
SetuptoolsWarning.emit(msg)
|
| 226 |
+
dist.install_requires = val
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def _optional_dependencies(dist: Distribution, val: dict, _root_dir: StrPath | None):
|
| 230 |
+
if getattr(dist, "extras_require", None):
|
| 231 |
+
msg = "`extras_require` overwritten in `pyproject.toml` (optional-dependencies)"
|
| 232 |
+
SetuptoolsWarning.emit(msg)
|
| 233 |
+
dist.extras_require = val
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def _ext_modules(dist: Distribution, val: list[dict]) -> list[Extension]:
|
| 237 |
+
existing = dist.ext_modules or []
|
| 238 |
+
args = ({k.replace("-", "_"): v for k, v in x.items()} for x in val)
|
| 239 |
+
new = [Extension(**kw) for kw in args]
|
| 240 |
+
return [*existing, *new]
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
def _noop(_dist: Distribution, val: _T) -> _T:
|
| 244 |
+
return val
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def _identity(val: _T) -> _T:
|
| 248 |
+
return val
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def _unify_entry_points(project_table: dict):
|
| 252 |
+
project = project_table
|
| 253 |
+
given = project.pop("entry-points", project.pop("entry_points", {}))
|
| 254 |
+
entry_points = dict(given) # Avoid problems with static
|
| 255 |
+
renaming = {"scripts": "console_scripts", "gui_scripts": "gui_scripts"}
|
| 256 |
+
for key, value in list(project.items()): # eager to allow modifications
|
| 257 |
+
norm_key = json_compatible_key(key)
|
| 258 |
+
if norm_key in renaming:
|
| 259 |
+
# Don't skip even if value is empty (reason: reset missing `dynamic`)
|
| 260 |
+
entry_points[renaming[norm_key]] = project.pop(key)
|
| 261 |
+
|
| 262 |
+
if entry_points:
|
| 263 |
+
project["entry-points"] = {
|
| 264 |
+
name: [f"{k} = {v}" for k, v in group.items()]
|
| 265 |
+
for name, group in entry_points.items()
|
| 266 |
+
if group # now we can skip empty groups
|
| 267 |
+
}
|
| 268 |
+
# Sometimes this will set `project["entry-points"] = {}`, and that is
|
| 269 |
+
# intentional (for resetting configurations that are missing `dynamic`).
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
def _copy_command_options(pyproject: dict, dist: Distribution, filename: StrPath):
|
| 273 |
+
tool_table = pyproject.get("tool", {})
|
| 274 |
+
cmdclass = tool_table.get("setuptools", {}).get("cmdclass", {})
|
| 275 |
+
valid_options = _valid_command_options(cmdclass)
|
| 276 |
+
|
| 277 |
+
cmd_opts = dist.command_options
|
| 278 |
+
for cmd, config in pyproject.get("tool", {}).get("distutils", {}).items():
|
| 279 |
+
cmd = json_compatible_key(cmd)
|
| 280 |
+
valid = valid_options.get(cmd, set())
|
| 281 |
+
cmd_opts.setdefault(cmd, {})
|
| 282 |
+
for key, value in config.items():
|
| 283 |
+
key = json_compatible_key(key)
|
| 284 |
+
cmd_opts[cmd][key] = (str(filename), value)
|
| 285 |
+
if key not in valid:
|
| 286 |
+
# To avoid removing options that are specified dynamically we
|
| 287 |
+
# just log a warn...
|
| 288 |
+
_logger.warning(f"Command option {cmd}.{key} is not defined")
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def _valid_command_options(cmdclass: Mapping = EMPTY) -> dict[str, set[str]]:
|
| 292 |
+
from setuptools.dist import Distribution
|
| 293 |
+
|
| 294 |
+
from .._importlib import metadata
|
| 295 |
+
|
| 296 |
+
valid_options = {"global": _normalise_cmd_options(Distribution.global_options)}
|
| 297 |
+
|
| 298 |
+
unloaded_entry_points = metadata.entry_points(group='distutils.commands')
|
| 299 |
+
loaded_entry_points = (_load_ep(ep) for ep in unloaded_entry_points)
|
| 300 |
+
entry_points = (ep for ep in loaded_entry_points if ep)
|
| 301 |
+
for cmd, cmd_class in chain(entry_points, cmdclass.items()):
|
| 302 |
+
opts = valid_options.get(cmd, set())
|
| 303 |
+
opts = opts | _normalise_cmd_options(getattr(cmd_class, "user_options", []))
|
| 304 |
+
valid_options[cmd] = opts
|
| 305 |
+
|
| 306 |
+
return valid_options
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
def _load_ep(ep: metadata.EntryPoint) -> tuple[str, type] | None:
|
| 310 |
+
if ep.value.startswith("wheel.bdist_wheel"):
|
| 311 |
+
# Ignore deprecated entrypoint from wheel and avoid warning pypa/wheel#631
|
| 312 |
+
# TODO: remove check when `bdist_wheel` has been fully removed from pypa/wheel
|
| 313 |
+
return None
|
| 314 |
+
|
| 315 |
+
# Ignore all the errors
|
| 316 |
+
try:
|
| 317 |
+
return (ep.name, ep.load())
|
| 318 |
+
except Exception as ex:
|
| 319 |
+
msg = f"{ex.__class__.__name__} while trying to load entry-point {ep.name}"
|
| 320 |
+
_logger.warning(f"{msg}: {ex}")
|
| 321 |
+
return None
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
def _normalise_cmd_option_key(name: str) -> str:
|
| 325 |
+
return json_compatible_key(name).strip("_=")
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
def _normalise_cmd_options(desc: _OptionsList) -> set[str]:
|
| 329 |
+
return {_normalise_cmd_option_key(fancy_option[0]) for fancy_option in desc}
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
def _get_previous_entrypoints(dist: Distribution) -> dict[str, list]:
|
| 333 |
+
ignore = ("console_scripts", "gui_scripts")
|
| 334 |
+
value = getattr(dist, "entry_points", None) or {}
|
| 335 |
+
return {k: v for k, v in value.items() if k not in ignore}
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def _get_previous_scripts(dist: Distribution) -> list | None:
|
| 339 |
+
value = getattr(dist, "entry_points", None) or {}
|
| 340 |
+
return value.get("console_scripts")
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
def _get_previous_gui_scripts(dist: Distribution) -> list | None:
|
| 344 |
+
value = getattr(dist, "entry_points", None) or {}
|
| 345 |
+
return value.get("gui_scripts")
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
def _set_static_list_metadata(attr: str, dist: Distribution, val: list) -> None:
|
| 349 |
+
"""Apply distutils metadata validation but preserve "static" behaviour"""
|
| 350 |
+
meta = dist.metadata
|
| 351 |
+
setter, getter = getattr(meta, f"set_{attr}"), getattr(meta, f"get_{attr}")
|
| 352 |
+
setter(val)
|
| 353 |
+
setattr(meta, attr, _static.List(getter()))
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
def _attrgetter(attr):
|
| 357 |
+
"""
|
| 358 |
+
Similar to ``operator.attrgetter`` but returns None if ``attr`` is not found
|
| 359 |
+
>>> from types import SimpleNamespace
|
| 360 |
+
>>> obj = SimpleNamespace(a=42, b=SimpleNamespace(c=13))
|
| 361 |
+
>>> _attrgetter("a")(obj)
|
| 362 |
+
42
|
| 363 |
+
>>> _attrgetter("b.c")(obj)
|
| 364 |
+
13
|
| 365 |
+
>>> _attrgetter("d")(obj) is None
|
| 366 |
+
True
|
| 367 |
+
"""
|
| 368 |
+
return partial(reduce, lambda acc, x: getattr(acc, x, None), attr.split("."))
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
def _some_attrgetter(*items):
|
| 372 |
+
"""
|
| 373 |
+
Return the first "truth-y" attribute or None
|
| 374 |
+
>>> from types import SimpleNamespace
|
| 375 |
+
>>> obj = SimpleNamespace(a=42, b=SimpleNamespace(c=13))
|
| 376 |
+
>>> _some_attrgetter("d", "a", "b.c")(obj)
|
| 377 |
+
42
|
| 378 |
+
>>> _some_attrgetter("d", "e", "b.c", "a")(obj)
|
| 379 |
+
13
|
| 380 |
+
>>> _some_attrgetter("d", "e", "f")(obj) is None
|
| 381 |
+
True
|
| 382 |
+
"""
|
| 383 |
+
|
| 384 |
+
def _acessor(obj):
|
| 385 |
+
values = (_attrgetter(i)(obj) for i in items)
|
| 386 |
+
return next((i for i in values if i is not None), None)
|
| 387 |
+
|
| 388 |
+
return _acessor
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
PYPROJECT_CORRESPONDENCE: dict[str, _Correspondence] = {
|
| 392 |
+
"readme": _long_description,
|
| 393 |
+
"license": _license,
|
| 394 |
+
"authors": partial(_people, kind="author"),
|
| 395 |
+
"maintainers": partial(_people, kind="maintainer"),
|
| 396 |
+
"urls": _project_urls,
|
| 397 |
+
"dependencies": _dependencies,
|
| 398 |
+
"optional_dependencies": _optional_dependencies,
|
| 399 |
+
"requires_python": _python_requires,
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
TOOL_TABLE_RENAMES = {"script_files": "scripts"}
|
| 403 |
+
TOOL_TABLE_REMOVALS = {
|
| 404 |
+
"namespace_packages": """
|
| 405 |
+
Please migrate to implicit native namespaces instead.
|
| 406 |
+
See https://packaging.python.org/en/latest/guides/packaging-namespace-packages/.
|
| 407 |
+
""",
|
| 408 |
+
}
|
| 409 |
+
TOOL_TABLE_CORRESPONDENCE = {
|
| 410 |
+
# Fields with corresponding core metadata need to be marked as static:
|
| 411 |
+
"obsoletes": partial(_set_static_list_metadata, "obsoletes"),
|
| 412 |
+
"provides": partial(_set_static_list_metadata, "provides"),
|
| 413 |
+
"platforms": partial(_set_static_list_metadata, "platforms"),
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
SETUPTOOLS_PATCHES = {
|
| 417 |
+
"long_description_content_type",
|
| 418 |
+
"project_urls",
|
| 419 |
+
"provides_extras",
|
| 420 |
+
"license_file",
|
| 421 |
+
"license_files",
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
_PREPROCESS = {
|
| 425 |
+
"ext_modules": _ext_modules,
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
_PREVIOUSLY_DEFINED = {
|
| 429 |
+
"name": _attrgetter("metadata.name"),
|
| 430 |
+
"version": _attrgetter("metadata.version"),
|
| 431 |
+
"description": _attrgetter("metadata.description"),
|
| 432 |
+
"readme": _attrgetter("metadata.long_description"),
|
| 433 |
+
"requires-python": _some_attrgetter("python_requires", "metadata.python_requires"),
|
| 434 |
+
"license": _attrgetter("metadata.license"),
|
| 435 |
+
"authors": _some_attrgetter("metadata.author", "metadata.author_email"),
|
| 436 |
+
"maintainers": _some_attrgetter("metadata.maintainer", "metadata.maintainer_email"),
|
| 437 |
+
"keywords": _attrgetter("metadata.keywords"),
|
| 438 |
+
"classifiers": _attrgetter("metadata.classifiers"),
|
| 439 |
+
"urls": _attrgetter("metadata.project_urls"),
|
| 440 |
+
"entry-points": _get_previous_entrypoints,
|
| 441 |
+
"scripts": _get_previous_scripts,
|
| 442 |
+
"gui-scripts": _get_previous_gui_scripts,
|
| 443 |
+
"dependencies": _attrgetter("install_requires"),
|
| 444 |
+
"optional-dependencies": _attrgetter("extras_require"),
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
_RESET_PREVIOUSLY_DEFINED: dict = {
|
| 449 |
+
# Fix improper setting: given in `setup.py`, but not listed in `dynamic`
|
| 450 |
+
# dict: pyproject name => value to which reset
|
| 451 |
+
"license": _static.EMPTY_DICT,
|
| 452 |
+
"authors": _static.EMPTY_LIST,
|
| 453 |
+
"maintainers": _static.EMPTY_LIST,
|
| 454 |
+
"keywords": _static.EMPTY_LIST,
|
| 455 |
+
"classifiers": _static.EMPTY_LIST,
|
| 456 |
+
"urls": _static.EMPTY_DICT,
|
| 457 |
+
"entry-points": _static.EMPTY_DICT,
|
| 458 |
+
"scripts": _static.EMPTY_DICT,
|
| 459 |
+
"gui-scripts": _static.EMPTY_DICT,
|
| 460 |
+
"dependencies": _static.EMPTY_LIST,
|
| 461 |
+
"optional-dependencies": _static.EMPTY_DICT,
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
class _MissingDynamic(SetuptoolsWarning):
|
| 466 |
+
_SUMMARY = "`{field}` defined outside of `pyproject.toml` is ignored."
|
| 467 |
+
|
| 468 |
+
_DETAILS = """
|
| 469 |
+
The following seems to be defined outside of `pyproject.toml`:
|
| 470 |
+
|
| 471 |
+
`{field} = {value!r}`
|
| 472 |
+
|
| 473 |
+
According to the spec (see the link below), however, setuptools CANNOT
|
| 474 |
+
consider this value unless `{field}` is listed as `dynamic`.
|
| 475 |
+
|
| 476 |
+
https://packaging.python.org/en/latest/specifications/pyproject-toml/#declaring-project-metadata-the-project-table
|
| 477 |
+
|
| 478 |
+
To prevent this problem, you can list `{field}` under `dynamic` or alternatively
|
| 479 |
+
remove the `[project]` table from your file and rely entirely on other means of
|
| 480 |
+
configuration.
|
| 481 |
+
"""
|
| 482 |
+
# TODO: Consider removing this check in the future?
|
| 483 |
+
# There is a trade-off here between improving "debug-ability" and the cost
|
| 484 |
+
# of running/testing/maintaining these unnecessary checks...
|
| 485 |
+
|
| 486 |
+
@classmethod
|
| 487 |
+
def details(cls, field: str, value: Any) -> str:
|
| 488 |
+
return cls._DETAILS.format(field=field, value=value)
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/NOTICE
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The code contained in this directory was automatically generated using the
|
| 2 |
+
following command:
|
| 3 |
+
|
| 4 |
+
python -m validate_pyproject.pre_compile --output-dir=setuptools/config/_validate_pyproject --enable-plugins setuptools distutils --very-verbose -t distutils=setuptools/config/distutils.schema.json -t setuptools=setuptools/config/setuptools.schema.json
|
| 5 |
+
|
| 6 |
+
Please avoid changing it manually.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
You can report issues or suggest changes directly to `validate-pyproject`
|
| 10 |
+
(or to the relevant plugin repository)
|
| 11 |
+
|
| 12 |
+
- https://github.com/abravalheri/validate-pyproject/issues
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
***
|
| 16 |
+
|
| 17 |
+
The following files include code from opensource projects
|
| 18 |
+
(either as direct copies or modified versions):
|
| 19 |
+
|
| 20 |
+
- `fastjsonschema_exceptions.py`:
|
| 21 |
+
- project: `fastjsonschema` - licensed under BSD-3-Clause
|
| 22 |
+
(https://github.com/horejsek/python-fastjsonschema)
|
| 23 |
+
- `extra_validations.py` and `format.py`, `error_reporting.py`:
|
| 24 |
+
- project: `validate-pyproject` - licensed under MPL-2.0
|
| 25 |
+
(https://github.com/abravalheri/validate-pyproject)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Additionally the following files are automatically generated by tools provided
|
| 29 |
+
by the same projects:
|
| 30 |
+
|
| 31 |
+
- `__init__.py`
|
| 32 |
+
- `fastjsonschema_validations.py`
|
| 33 |
+
|
| 34 |
+
The relevant copyright notes and licenses are included below.
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
***
|
| 38 |
+
|
| 39 |
+
`fastjsonschema`
|
| 40 |
+
================
|
| 41 |
+
|
| 42 |
+
Copyright (c) 2018, Michal Horejsek
|
| 43 |
+
All rights reserved.
|
| 44 |
+
|
| 45 |
+
Redistribution and use in source and binary forms, with or without modification,
|
| 46 |
+
are permitted provided that the following conditions are met:
|
| 47 |
+
|
| 48 |
+
Redistributions of source code must retain the above copyright notice, this
|
| 49 |
+
list of conditions and the following disclaimer.
|
| 50 |
+
|
| 51 |
+
Redistributions in binary form must reproduce the above copyright notice, this
|
| 52 |
+
list of conditions and the following disclaimer in the documentation and/or
|
| 53 |
+
other materials provided with the distribution.
|
| 54 |
+
|
| 55 |
+
Neither the name of the {organization} nor the names of its
|
| 56 |
+
contributors may be used to endorse or promote products derived from
|
| 57 |
+
this software without specific prior written permission.
|
| 58 |
+
|
| 59 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 60 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 61 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 62 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
| 63 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 64 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 65 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
| 66 |
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 67 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 68 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
***
|
| 73 |
+
|
| 74 |
+
`validate-pyproject`
|
| 75 |
+
====================
|
| 76 |
+
|
| 77 |
+
Mozilla Public License, version 2.0
|
| 78 |
+
|
| 79 |
+
1. Definitions
|
| 80 |
+
|
| 81 |
+
1.1. "Contributor"
|
| 82 |
+
|
| 83 |
+
means each individual or legal entity that creates, contributes to the
|
| 84 |
+
creation of, or owns Covered Software.
|
| 85 |
+
|
| 86 |
+
1.2. "Contributor Version"
|
| 87 |
+
|
| 88 |
+
means the combination of the Contributions of others (if any) used by a
|
| 89 |
+
Contributor and that particular Contributor's Contribution.
|
| 90 |
+
|
| 91 |
+
1.3. "Contribution"
|
| 92 |
+
|
| 93 |
+
means Covered Software of a particular Contributor.
|
| 94 |
+
|
| 95 |
+
1.4. "Covered Software"
|
| 96 |
+
|
| 97 |
+
means Source Code Form to which the initial Contributor has attached the
|
| 98 |
+
notice in Exhibit A, the Executable Form of such Source Code Form, and
|
| 99 |
+
Modifications of such Source Code Form, in each case including portions
|
| 100 |
+
thereof.
|
| 101 |
+
|
| 102 |
+
1.5. "Incompatible With Secondary Licenses"
|
| 103 |
+
means
|
| 104 |
+
|
| 105 |
+
a. that the initial Contributor has attached the notice described in
|
| 106 |
+
Exhibit B to the Covered Software; or
|
| 107 |
+
|
| 108 |
+
b. that the Covered Software was made available under the terms of
|
| 109 |
+
version 1.1 or earlier of the License, but not also under the terms of
|
| 110 |
+
a Secondary License.
|
| 111 |
+
|
| 112 |
+
1.6. "Executable Form"
|
| 113 |
+
|
| 114 |
+
means any form of the work other than Source Code Form.
|
| 115 |
+
|
| 116 |
+
1.7. "Larger Work"
|
| 117 |
+
|
| 118 |
+
means a work that combines Covered Software with other material, in a
|
| 119 |
+
separate file or files, that is not Covered Software.
|
| 120 |
+
|
| 121 |
+
1.8. "License"
|
| 122 |
+
|
| 123 |
+
means this document.
|
| 124 |
+
|
| 125 |
+
1.9. "Licensable"
|
| 126 |
+
|
| 127 |
+
means having the right to grant, to the maximum extent possible, whether
|
| 128 |
+
at the time of the initial grant or subsequently, any and all of the
|
| 129 |
+
rights conveyed by this License.
|
| 130 |
+
|
| 131 |
+
1.10. "Modifications"
|
| 132 |
+
|
| 133 |
+
means any of the following:
|
| 134 |
+
|
| 135 |
+
a. any file in Source Code Form that results from an addition to,
|
| 136 |
+
deletion from, or modification of the contents of Covered Software; or
|
| 137 |
+
|
| 138 |
+
b. any new file in Source Code Form that contains any Covered Software.
|
| 139 |
+
|
| 140 |
+
1.11. "Patent Claims" of a Contributor
|
| 141 |
+
|
| 142 |
+
means any patent claim(s), including without limitation, method,
|
| 143 |
+
process, and apparatus claims, in any patent Licensable by such
|
| 144 |
+
Contributor that would be infringed, but for the grant of the License,
|
| 145 |
+
by the making, using, selling, offering for sale, having made, import,
|
| 146 |
+
or transfer of either its Contributions or its Contributor Version.
|
| 147 |
+
|
| 148 |
+
1.12. "Secondary License"
|
| 149 |
+
|
| 150 |
+
means either the GNU General Public License, Version 2.0, the GNU Lesser
|
| 151 |
+
General Public License, Version 2.1, the GNU Affero General Public
|
| 152 |
+
License, Version 3.0, or any later versions of those licenses.
|
| 153 |
+
|
| 154 |
+
1.13. "Source Code Form"
|
| 155 |
+
|
| 156 |
+
means the form of the work preferred for making modifications.
|
| 157 |
+
|
| 158 |
+
1.14. "You" (or "Your")
|
| 159 |
+
|
| 160 |
+
means an individual or a legal entity exercising rights under this
|
| 161 |
+
License. For legal entities, "You" includes any entity that controls, is
|
| 162 |
+
controlled by, or is under common control with You. For purposes of this
|
| 163 |
+
definition, "control" means (a) the power, direct or indirect, to cause
|
| 164 |
+
the direction or management of such entity, whether by contract or
|
| 165 |
+
otherwise, or (b) ownership of more than fifty percent (50%) of the
|
| 166 |
+
outstanding shares or beneficial ownership of such entity.
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
2. License Grants and Conditions
|
| 170 |
+
|
| 171 |
+
2.1. Grants
|
| 172 |
+
|
| 173 |
+
Each Contributor hereby grants You a world-wide, royalty-free,
|
| 174 |
+
non-exclusive license:
|
| 175 |
+
|
| 176 |
+
a. under intellectual property rights (other than patent or trademark)
|
| 177 |
+
Licensable by such Contributor to use, reproduce, make available,
|
| 178 |
+
modify, display, perform, distribute, and otherwise exploit its
|
| 179 |
+
Contributions, either on an unmodified basis, with Modifications, or
|
| 180 |
+
as part of a Larger Work; and
|
| 181 |
+
|
| 182 |
+
b. under Patent Claims of such Contributor to make, use, sell, offer for
|
| 183 |
+
sale, have made, import, and otherwise transfer either its
|
| 184 |
+
Contributions or its Contributor Version.
|
| 185 |
+
|
| 186 |
+
2.2. Effective Date
|
| 187 |
+
|
| 188 |
+
The licenses granted in Section 2.1 with respect to any Contribution
|
| 189 |
+
become effective for each Contribution on the date the Contributor first
|
| 190 |
+
distributes such Contribution.
|
| 191 |
+
|
| 192 |
+
2.3. Limitations on Grant Scope
|
| 193 |
+
|
| 194 |
+
The licenses granted in this Section 2 are the only rights granted under
|
| 195 |
+
this License. No additional rights or licenses will be implied from the
|
| 196 |
+
distribution or licensing of Covered Software under this License.
|
| 197 |
+
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
| 198 |
+
Contributor:
|
| 199 |
+
|
| 200 |
+
a. for any code that a Contributor has removed from Covered Software; or
|
| 201 |
+
|
| 202 |
+
b. for infringements caused by: (i) Your and any other third party's
|
| 203 |
+
modifications of Covered Software, or (ii) the combination of its
|
| 204 |
+
Contributions with other software (except as part of its Contributor
|
| 205 |
+
Version); or
|
| 206 |
+
|
| 207 |
+
c. under Patent Claims infringed by Covered Software in the absence of
|
| 208 |
+
its Contributions.
|
| 209 |
+
|
| 210 |
+
This License does not grant any rights in the trademarks, service marks,
|
| 211 |
+
or logos of any Contributor (except as may be necessary to comply with
|
| 212 |
+
the notice requirements in Section 3.4).
|
| 213 |
+
|
| 214 |
+
2.4. Subsequent Licenses
|
| 215 |
+
|
| 216 |
+
No Contributor makes additional grants as a result of Your choice to
|
| 217 |
+
distribute the Covered Software under a subsequent version of this
|
| 218 |
+
License (see Section 10.2) or under the terms of a Secondary License (if
|
| 219 |
+
permitted under the terms of Section 3.3).
|
| 220 |
+
|
| 221 |
+
2.5. Representation
|
| 222 |
+
|
| 223 |
+
Each Contributor represents that the Contributor believes its
|
| 224 |
+
Contributions are its original creation(s) or it has sufficient rights to
|
| 225 |
+
grant the rights to its Contributions conveyed by this License.
|
| 226 |
+
|
| 227 |
+
2.6. Fair Use
|
| 228 |
+
|
| 229 |
+
This License is not intended to limit any rights You have under
|
| 230 |
+
applicable copyright doctrines of fair use, fair dealing, or other
|
| 231 |
+
equivalents.
|
| 232 |
+
|
| 233 |
+
2.7. Conditions
|
| 234 |
+
|
| 235 |
+
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
|
| 236 |
+
Section 2.1.
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
3. Responsibilities
|
| 240 |
+
|
| 241 |
+
3.1. Distribution of Source Form
|
| 242 |
+
|
| 243 |
+
All distribution of Covered Software in Source Code Form, including any
|
| 244 |
+
Modifications that You create or to which You contribute, must be under
|
| 245 |
+
the terms of this License. You must inform recipients that the Source
|
| 246 |
+
Code Form of the Covered Software is governed by the terms of this
|
| 247 |
+
License, and how they can obtain a copy of this License. You may not
|
| 248 |
+
attempt to alter or restrict the recipients' rights in the Source Code
|
| 249 |
+
Form.
|
| 250 |
+
|
| 251 |
+
3.2. Distribution of Executable Form
|
| 252 |
+
|
| 253 |
+
If You distribute Covered Software in Executable Form then:
|
| 254 |
+
|
| 255 |
+
a. such Covered Software must also be made available in Source Code Form,
|
| 256 |
+
as described in Section 3.1, and You must inform recipients of the
|
| 257 |
+
Executable Form how they can obtain a copy of such Source Code Form by
|
| 258 |
+
reasonable means in a timely manner, at a charge no more than the cost
|
| 259 |
+
of distribution to the recipient; and
|
| 260 |
+
|
| 261 |
+
b. You may distribute such Executable Form under the terms of this
|
| 262 |
+
License, or sublicense it under different terms, provided that the
|
| 263 |
+
license for the Executable Form does not attempt to limit or alter the
|
| 264 |
+
recipients' rights in the Source Code Form under this License.
|
| 265 |
+
|
| 266 |
+
3.3. Distribution of a Larger Work
|
| 267 |
+
|
| 268 |
+
You may create and distribute a Larger Work under terms of Your choice,
|
| 269 |
+
provided that You also comply with the requirements of this License for
|
| 270 |
+
the Covered Software. If the Larger Work is a combination of Covered
|
| 271 |
+
Software with a work governed by one or more Secondary Licenses, and the
|
| 272 |
+
Covered Software is not Incompatible With Secondary Licenses, this
|
| 273 |
+
License permits You to additionally distribute such Covered Software
|
| 274 |
+
under the terms of such Secondary License(s), so that the recipient of
|
| 275 |
+
the Larger Work may, at their option, further distribute the Covered
|
| 276 |
+
Software under the terms of either this License or such Secondary
|
| 277 |
+
License(s).
|
| 278 |
+
|
| 279 |
+
3.4. Notices
|
| 280 |
+
|
| 281 |
+
You may not remove or alter the substance of any license notices
|
| 282 |
+
(including copyright notices, patent notices, disclaimers of warranty, or
|
| 283 |
+
limitations of liability) contained within the Source Code Form of the
|
| 284 |
+
Covered Software, except that You may alter any license notices to the
|
| 285 |
+
extent required to remedy known factual inaccuracies.
|
| 286 |
+
|
| 287 |
+
3.5. Application of Additional Terms
|
| 288 |
+
|
| 289 |
+
You may choose to offer, and to charge a fee for, warranty, support,
|
| 290 |
+
indemnity or liability obligations to one or more recipients of Covered
|
| 291 |
+
Software. However, You may do so only on Your own behalf, and not on
|
| 292 |
+
behalf of any Contributor. You must make it absolutely clear that any
|
| 293 |
+
such warranty, support, indemnity, or liability obligation is offered by
|
| 294 |
+
You alone, and You hereby agree to indemnify every Contributor for any
|
| 295 |
+
liability incurred by such Contributor as a result of warranty, support,
|
| 296 |
+
indemnity or liability terms You offer. You may include additional
|
| 297 |
+
disclaimers of warranty and limitations of liability specific to any
|
| 298 |
+
jurisdiction.
|
| 299 |
+
|
| 300 |
+
4. Inability to Comply Due to Statute or Regulation
|
| 301 |
+
|
| 302 |
+
If it is impossible for You to comply with any of the terms of this License
|
| 303 |
+
with respect to some or all of the Covered Software due to statute,
|
| 304 |
+
judicial order, or regulation then You must: (a) comply with the terms of
|
| 305 |
+
this License to the maximum extent possible; and (b) describe the
|
| 306 |
+
limitations and the code they affect. Such description must be placed in a
|
| 307 |
+
text file included with all distributions of the Covered Software under
|
| 308 |
+
this License. Except to the extent prohibited by statute or regulation,
|
| 309 |
+
such description must be sufficiently detailed for a recipient of ordinary
|
| 310 |
+
skill to be able to understand it.
|
| 311 |
+
|
| 312 |
+
5. Termination
|
| 313 |
+
|
| 314 |
+
5.1. The rights granted under this License will terminate automatically if You
|
| 315 |
+
fail to comply with any of its terms. However, if You become compliant,
|
| 316 |
+
then the rights granted under this License from a particular Contributor
|
| 317 |
+
are reinstated (a) provisionally, unless and until such Contributor
|
| 318 |
+
explicitly and finally terminates Your grants, and (b) on an ongoing
|
| 319 |
+
basis, if such Contributor fails to notify You of the non-compliance by
|
| 320 |
+
some reasonable means prior to 60 days after You have come back into
|
| 321 |
+
compliance. Moreover, Your grants from a particular Contributor are
|
| 322 |
+
reinstated on an ongoing basis if such Contributor notifies You of the
|
| 323 |
+
non-compliance by some reasonable means, this is the first time You have
|
| 324 |
+
received notice of non-compliance with this License from such
|
| 325 |
+
Contributor, and You become compliant prior to 30 days after Your receipt
|
| 326 |
+
of the notice.
|
| 327 |
+
|
| 328 |
+
5.2. If You initiate litigation against any entity by asserting a patent
|
| 329 |
+
infringement claim (excluding declaratory judgment actions,
|
| 330 |
+
counter-claims, and cross-claims) alleging that a Contributor Version
|
| 331 |
+
directly or indirectly infringes any patent, then the rights granted to
|
| 332 |
+
You by any and all Contributors for the Covered Software under Section
|
| 333 |
+
2.1 of this License shall terminate.
|
| 334 |
+
|
| 335 |
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
|
| 336 |
+
license agreements (excluding distributors and resellers) which have been
|
| 337 |
+
validly granted by You or Your distributors under this License prior to
|
| 338 |
+
termination shall survive termination.
|
| 339 |
+
|
| 340 |
+
6. Disclaimer of Warranty
|
| 341 |
+
|
| 342 |
+
Covered Software is provided under this License on an "as is" basis,
|
| 343 |
+
without warranty of any kind, either expressed, implied, or statutory,
|
| 344 |
+
including, without limitation, warranties that the Covered Software is free
|
| 345 |
+
of defects, merchantable, fit for a particular purpose or non-infringing.
|
| 346 |
+
The entire risk as to the quality and performance of the Covered Software
|
| 347 |
+
is with You. Should any Covered Software prove defective in any respect,
|
| 348 |
+
You (not any Contributor) assume the cost of any necessary servicing,
|
| 349 |
+
repair, or correction. This disclaimer of warranty constitutes an essential
|
| 350 |
+
part of this License. No use of any Covered Software is authorized under
|
| 351 |
+
this License except under this disclaimer.
|
| 352 |
+
|
| 353 |
+
7. Limitation of Liability
|
| 354 |
+
|
| 355 |
+
Under no circumstances and under no legal theory, whether tort (including
|
| 356 |
+
negligence), contract, or otherwise, shall any Contributor, or anyone who
|
| 357 |
+
distributes Covered Software as permitted above, be liable to You for any
|
| 358 |
+
direct, indirect, special, incidental, or consequential damages of any
|
| 359 |
+
character including, without limitation, damages for lost profits, loss of
|
| 360 |
+
goodwill, work stoppage, computer failure or malfunction, or any and all
|
| 361 |
+
other commercial damages or losses, even if such party shall have been
|
| 362 |
+
informed of the possibility of such damages. This limitation of liability
|
| 363 |
+
shall not apply to liability for death or personal injury resulting from
|
| 364 |
+
such party's negligence to the extent applicable law prohibits such
|
| 365 |
+
limitation. Some jurisdictions do not allow the exclusion or limitation of
|
| 366 |
+
incidental or consequential damages, so this exclusion and limitation may
|
| 367 |
+
not apply to You.
|
| 368 |
+
|
| 369 |
+
8. Litigation
|
| 370 |
+
|
| 371 |
+
Any litigation relating to this License may be brought only in the courts
|
| 372 |
+
of a jurisdiction where the defendant maintains its principal place of
|
| 373 |
+
business and such litigation shall be governed by laws of that
|
| 374 |
+
jurisdiction, without reference to its conflict-of-law provisions. Nothing
|
| 375 |
+
in this Section shall prevent a party's ability to bring cross-claims or
|
| 376 |
+
counter-claims.
|
| 377 |
+
|
| 378 |
+
9. Miscellaneous
|
| 379 |
+
|
| 380 |
+
This License represents the complete agreement concerning the subject
|
| 381 |
+
matter hereof. If any provision of this License is held to be
|
| 382 |
+
unenforceable, such provision shall be reformed only to the extent
|
| 383 |
+
necessary to make it enforceable. Any law or regulation which provides that
|
| 384 |
+
the language of a contract shall be construed against the drafter shall not
|
| 385 |
+
be used to construe this License against a Contributor.
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
10. Versions of the License
|
| 389 |
+
|
| 390 |
+
10.1. New Versions
|
| 391 |
+
|
| 392 |
+
Mozilla Foundation is the license steward. Except as provided in Section
|
| 393 |
+
10.3, no one other than the license steward has the right to modify or
|
| 394 |
+
publish new versions of this License. Each version will be given a
|
| 395 |
+
distinguishing version number.
|
| 396 |
+
|
| 397 |
+
10.2. Effect of New Versions
|
| 398 |
+
|
| 399 |
+
You may distribute the Covered Software under the terms of the version
|
| 400 |
+
of the License under which You originally received the Covered Software,
|
| 401 |
+
or under the terms of any subsequent version published by the license
|
| 402 |
+
steward.
|
| 403 |
+
|
| 404 |
+
10.3. Modified Versions
|
| 405 |
+
|
| 406 |
+
If you create software not governed by this License, and you want to
|
| 407 |
+
create a new license for such software, you may create and use a
|
| 408 |
+
modified version of this License if you rename the license and remove
|
| 409 |
+
any references to the name of the license steward (except to note that
|
| 410 |
+
such modified license differs from this License).
|
| 411 |
+
|
| 412 |
+
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
| 413 |
+
Licenses If You choose to distribute Source Code Form that is
|
| 414 |
+
Incompatible With Secondary Licenses under the terms of this version of
|
| 415 |
+
the License, the notice described in Exhibit B of this License must be
|
| 416 |
+
attached.
|
| 417 |
+
|
| 418 |
+
Exhibit A - Source Code Form License Notice
|
| 419 |
+
|
| 420 |
+
This Source Code Form is subject to the
|
| 421 |
+
terms of the Mozilla Public License, v.
|
| 422 |
+
2.0. If a copy of the MPL was not
|
| 423 |
+
distributed with this file, You can
|
| 424 |
+
obtain one at
|
| 425 |
+
https://mozilla.org/MPL/2.0/.
|
| 426 |
+
|
| 427 |
+
If it is not possible or desirable to put the notice in a particular file,
|
| 428 |
+
then You may include the notice in a location (such as a LICENSE file in a
|
| 429 |
+
relevant directory) where a recipient would be likely to look for such a
|
| 430 |
+
notice.
|
| 431 |
+
|
| 432 |
+
You may add additional accurate notices of copyright ownership.
|
| 433 |
+
|
| 434 |
+
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
| 435 |
+
|
| 436 |
+
This Source Code Form is "Incompatible
|
| 437 |
+
With Secondary Licenses", as defined by
|
| 438 |
+
the Mozilla Public License, v. 2.0.
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import reduce
|
| 2 |
+
from typing import Any, Callable, Dict
|
| 3 |
+
|
| 4 |
+
from . import formats
|
| 5 |
+
from .error_reporting import detailed_errors, ValidationError
|
| 6 |
+
from .extra_validations import EXTRA_VALIDATIONS
|
| 7 |
+
from .fastjsonschema_exceptions import JsonSchemaException, JsonSchemaValueException
|
| 8 |
+
from .fastjsonschema_validations import validate as _validate
|
| 9 |
+
|
| 10 |
+
__all__ = [
|
| 11 |
+
"validate",
|
| 12 |
+
"FORMAT_FUNCTIONS",
|
| 13 |
+
"EXTRA_VALIDATIONS",
|
| 14 |
+
"ValidationError",
|
| 15 |
+
"JsonSchemaException",
|
| 16 |
+
"JsonSchemaValueException",
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
FORMAT_FUNCTIONS: Dict[str, Callable[[str], bool]] = {
|
| 21 |
+
fn.__name__.replace("_", "-"): fn
|
| 22 |
+
for fn in formats.__dict__.values()
|
| 23 |
+
if callable(fn) and not fn.__name__.startswith("_")
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def validate(data: Any) -> bool:
|
| 28 |
+
"""Validate the given ``data`` object using JSON Schema
|
| 29 |
+
This function raises ``ValidationError`` if ``data`` is invalid.
|
| 30 |
+
"""
|
| 31 |
+
with detailed_errors():
|
| 32 |
+
_validate(data, custom_formats=FORMAT_FUNCTIONS)
|
| 33 |
+
reduce(lambda acc, fn: fn(acc), EXTRA_VALIDATIONS, data)
|
| 34 |
+
return True
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.49 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/error_reporting.cpython-310.pyc
ADDED
|
Binary file (12 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_exceptions.cpython-310.pyc
ADDED
|
Binary file (2.42 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_validations.cpython-310.pyc
ADDED
|
Binary file (85.8 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/__pycache__/formats.cpython-310.pyc
ADDED
|
Binary file (12.5 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/error_reporting.py
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import json
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
+
import typing
|
| 7 |
+
from contextlib import contextmanager
|
| 8 |
+
from textwrap import indent, wrap
|
| 9 |
+
from typing import Any, Dict, Generator, Iterator, List, Optional, Sequence, Union
|
| 10 |
+
|
| 11 |
+
from .fastjsonschema_exceptions import JsonSchemaValueException
|
| 12 |
+
|
| 13 |
+
if typing.TYPE_CHECKING:
|
| 14 |
+
import sys
|
| 15 |
+
|
| 16 |
+
if sys.version_info < (3, 11):
|
| 17 |
+
from typing_extensions import Self
|
| 18 |
+
else:
|
| 19 |
+
from typing import Self
|
| 20 |
+
|
| 21 |
+
_logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
_MESSAGE_REPLACEMENTS = {
|
| 24 |
+
"must be named by propertyName definition": "keys must be named by",
|
| 25 |
+
"one of contains definition": "at least one item that matches",
|
| 26 |
+
" same as const definition:": "",
|
| 27 |
+
"only specified items": "only items matching the definition",
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
_SKIP_DETAILS = (
|
| 31 |
+
"must not be empty",
|
| 32 |
+
"is always invalid",
|
| 33 |
+
"must not be there",
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
_NEED_DETAILS = {"anyOf", "oneOf", "allOf", "contains", "propertyNames", "not", "items"}
|
| 37 |
+
|
| 38 |
+
_CAMEL_CASE_SPLITTER = re.compile(r"\W+|([A-Z][^A-Z\W]*)")
|
| 39 |
+
_IDENTIFIER = re.compile(r"^[\w_]+$", re.I)
|
| 40 |
+
|
| 41 |
+
_TOML_JARGON = {
|
| 42 |
+
"object": "table",
|
| 43 |
+
"property": "key",
|
| 44 |
+
"properties": "keys",
|
| 45 |
+
"property names": "keys",
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
_FORMATS_HELP = """
|
| 49 |
+
For more details about `format` see
|
| 50 |
+
https://validate-pyproject.readthedocs.io/en/latest/api/validate_pyproject.formats.html
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class ValidationError(JsonSchemaValueException):
|
| 55 |
+
"""Report violations of a given JSON schema.
|
| 56 |
+
|
| 57 |
+
This class extends :exc:`~fastjsonschema.JsonSchemaValueException`
|
| 58 |
+
by adding the following properties:
|
| 59 |
+
|
| 60 |
+
- ``summary``: an improved version of the ``JsonSchemaValueException`` error message
|
| 61 |
+
with only the necessary information)
|
| 62 |
+
|
| 63 |
+
- ``details``: more contextual information about the error like the failing schema
|
| 64 |
+
itself and the value that violates the schema.
|
| 65 |
+
|
| 66 |
+
Depending on the level of the verbosity of the ``logging`` configuration
|
| 67 |
+
the exception message will be only ``summary`` (default) or a combination of
|
| 68 |
+
``summary`` and ``details`` (when the logging level is set to :obj:`logging.DEBUG`).
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
summary = ""
|
| 72 |
+
details = ""
|
| 73 |
+
_original_message = ""
|
| 74 |
+
|
| 75 |
+
@classmethod
|
| 76 |
+
def _from_jsonschema(cls, ex: JsonSchemaValueException) -> "Self":
|
| 77 |
+
formatter = _ErrorFormatting(ex)
|
| 78 |
+
obj = cls(str(formatter), ex.value, formatter.name, ex.definition, ex.rule)
|
| 79 |
+
debug_code = os.getenv("JSONSCHEMA_DEBUG_CODE_GENERATION", "false").lower()
|
| 80 |
+
if debug_code != "false": # pragma: no cover
|
| 81 |
+
obj.__cause__, obj.__traceback__ = ex.__cause__, ex.__traceback__
|
| 82 |
+
obj._original_message = ex.message
|
| 83 |
+
obj.summary = formatter.summary
|
| 84 |
+
obj.details = formatter.details
|
| 85 |
+
return obj
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
@contextmanager
|
| 89 |
+
def detailed_errors() -> Generator[None, None, None]:
|
| 90 |
+
try:
|
| 91 |
+
yield
|
| 92 |
+
except JsonSchemaValueException as ex:
|
| 93 |
+
raise ValidationError._from_jsonschema(ex) from None
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class _ErrorFormatting:
|
| 97 |
+
def __init__(self, ex: JsonSchemaValueException):
|
| 98 |
+
self.ex = ex
|
| 99 |
+
self.name = f"`{self._simplify_name(ex.name)}`"
|
| 100 |
+
self._original_message: str = self.ex.message.replace(ex.name, self.name)
|
| 101 |
+
self._summary = ""
|
| 102 |
+
self._details = ""
|
| 103 |
+
|
| 104 |
+
def __str__(self) -> str:
|
| 105 |
+
if _logger.getEffectiveLevel() <= logging.DEBUG and self.details:
|
| 106 |
+
return f"{self.summary}\n\n{self.details}"
|
| 107 |
+
|
| 108 |
+
return self.summary
|
| 109 |
+
|
| 110 |
+
@property
|
| 111 |
+
def summary(self) -> str:
|
| 112 |
+
if not self._summary:
|
| 113 |
+
self._summary = self._expand_summary()
|
| 114 |
+
|
| 115 |
+
return self._summary
|
| 116 |
+
|
| 117 |
+
@property
|
| 118 |
+
def details(self) -> str:
|
| 119 |
+
if not self._details:
|
| 120 |
+
self._details = self._expand_details()
|
| 121 |
+
|
| 122 |
+
return self._details
|
| 123 |
+
|
| 124 |
+
@staticmethod
|
| 125 |
+
def _simplify_name(name: str) -> str:
|
| 126 |
+
x = len("data.")
|
| 127 |
+
return name[x:] if name.startswith("data.") else name
|
| 128 |
+
|
| 129 |
+
def _expand_summary(self) -> str:
|
| 130 |
+
msg = self._original_message
|
| 131 |
+
|
| 132 |
+
for bad, repl in _MESSAGE_REPLACEMENTS.items():
|
| 133 |
+
msg = msg.replace(bad, repl)
|
| 134 |
+
|
| 135 |
+
if any(substring in msg for substring in _SKIP_DETAILS):
|
| 136 |
+
return msg
|
| 137 |
+
|
| 138 |
+
schema = self.ex.rule_definition
|
| 139 |
+
if self.ex.rule in _NEED_DETAILS and schema:
|
| 140 |
+
summary = _SummaryWriter(_TOML_JARGON)
|
| 141 |
+
return f"{msg}:\n\n{indent(summary(schema), ' ')}"
|
| 142 |
+
|
| 143 |
+
return msg
|
| 144 |
+
|
| 145 |
+
def _expand_details(self) -> str:
|
| 146 |
+
optional = []
|
| 147 |
+
definition = self.ex.definition or {}
|
| 148 |
+
desc_lines = definition.pop("$$description", [])
|
| 149 |
+
desc = definition.pop("description", None) or " ".join(desc_lines)
|
| 150 |
+
if desc:
|
| 151 |
+
description = "\n".join(
|
| 152 |
+
wrap(
|
| 153 |
+
desc,
|
| 154 |
+
width=80,
|
| 155 |
+
initial_indent=" ",
|
| 156 |
+
subsequent_indent=" ",
|
| 157 |
+
break_long_words=False,
|
| 158 |
+
)
|
| 159 |
+
)
|
| 160 |
+
optional.append(f"DESCRIPTION:\n{description}")
|
| 161 |
+
schema = json.dumps(definition, indent=4)
|
| 162 |
+
value = json.dumps(self.ex.value, indent=4)
|
| 163 |
+
defaults = [
|
| 164 |
+
f"GIVEN VALUE:\n{indent(value, ' ')}",
|
| 165 |
+
f"OFFENDING RULE: {self.ex.rule!r}",
|
| 166 |
+
f"DEFINITION:\n{indent(schema, ' ')}",
|
| 167 |
+
]
|
| 168 |
+
msg = "\n\n".join(optional + defaults)
|
| 169 |
+
epilog = f"\n{_FORMATS_HELP}" if "format" in msg.lower() else ""
|
| 170 |
+
return msg + epilog
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
class _SummaryWriter:
|
| 174 |
+
_IGNORE = frozenset(("description", "default", "title", "examples"))
|
| 175 |
+
|
| 176 |
+
def __init__(self, jargon: Optional[Dict[str, str]] = None):
|
| 177 |
+
self.jargon: Dict[str, str] = jargon or {}
|
| 178 |
+
# Clarify confusing terms
|
| 179 |
+
self._terms = {
|
| 180 |
+
"anyOf": "at least one of the following",
|
| 181 |
+
"oneOf": "exactly one of the following",
|
| 182 |
+
"allOf": "all of the following",
|
| 183 |
+
"not": "(*NOT* the following)",
|
| 184 |
+
"prefixItems": f"{self._jargon('items')} (in order)",
|
| 185 |
+
"items": "items",
|
| 186 |
+
"contains": "contains at least one of",
|
| 187 |
+
"propertyNames": (
|
| 188 |
+
f"non-predefined acceptable {self._jargon('property names')}"
|
| 189 |
+
),
|
| 190 |
+
"patternProperties": f"{self._jargon('properties')} named via pattern",
|
| 191 |
+
"const": "predefined value",
|
| 192 |
+
"enum": "one of",
|
| 193 |
+
}
|
| 194 |
+
# Attributes that indicate that the definition is easy and can be done
|
| 195 |
+
# inline (e.g. string and number)
|
| 196 |
+
self._guess_inline_defs = [
|
| 197 |
+
"enum",
|
| 198 |
+
"const",
|
| 199 |
+
"maxLength",
|
| 200 |
+
"minLength",
|
| 201 |
+
"pattern",
|
| 202 |
+
"format",
|
| 203 |
+
"minimum",
|
| 204 |
+
"maximum",
|
| 205 |
+
"exclusiveMinimum",
|
| 206 |
+
"exclusiveMaximum",
|
| 207 |
+
"multipleOf",
|
| 208 |
+
]
|
| 209 |
+
|
| 210 |
+
def _jargon(self, term: Union[str, List[str]]) -> Union[str, List[str]]:
|
| 211 |
+
if isinstance(term, list):
|
| 212 |
+
return [self.jargon.get(t, t) for t in term]
|
| 213 |
+
return self.jargon.get(term, term)
|
| 214 |
+
|
| 215 |
+
def __call__(
|
| 216 |
+
self,
|
| 217 |
+
schema: Union[dict, List[dict]],
|
| 218 |
+
prefix: str = "",
|
| 219 |
+
*,
|
| 220 |
+
_path: Sequence[str] = (),
|
| 221 |
+
) -> str:
|
| 222 |
+
if isinstance(schema, list):
|
| 223 |
+
return self._handle_list(schema, prefix, _path)
|
| 224 |
+
|
| 225 |
+
filtered = self._filter_unecessary(schema, _path)
|
| 226 |
+
simple = self._handle_simple_dict(filtered, _path)
|
| 227 |
+
if simple:
|
| 228 |
+
return f"{prefix}{simple}"
|
| 229 |
+
|
| 230 |
+
child_prefix = self._child_prefix(prefix, " ")
|
| 231 |
+
item_prefix = self._child_prefix(prefix, "- ")
|
| 232 |
+
indent = len(prefix) * " "
|
| 233 |
+
with io.StringIO() as buffer:
|
| 234 |
+
for i, (key, value) in enumerate(filtered.items()):
|
| 235 |
+
child_path = [*_path, key]
|
| 236 |
+
line_prefix = prefix if i == 0 else indent
|
| 237 |
+
buffer.write(f"{line_prefix}{self._label(child_path)}:")
|
| 238 |
+
# ^ just the first item should receive the complete prefix
|
| 239 |
+
if isinstance(value, dict):
|
| 240 |
+
filtered = self._filter_unecessary(value, child_path)
|
| 241 |
+
simple = self._handle_simple_dict(filtered, child_path)
|
| 242 |
+
buffer.write(
|
| 243 |
+
f" {simple}"
|
| 244 |
+
if simple
|
| 245 |
+
else f"\n{self(value, child_prefix, _path=child_path)}"
|
| 246 |
+
)
|
| 247 |
+
elif isinstance(value, list) and (
|
| 248 |
+
key != "type" or self._is_property(child_path)
|
| 249 |
+
):
|
| 250 |
+
children = self._handle_list(value, item_prefix, child_path)
|
| 251 |
+
sep = " " if children.startswith("[") else "\n"
|
| 252 |
+
buffer.write(f"{sep}{children}")
|
| 253 |
+
else:
|
| 254 |
+
buffer.write(f" {self._value(value, child_path)}\n")
|
| 255 |
+
return buffer.getvalue()
|
| 256 |
+
|
| 257 |
+
def _is_unecessary(self, path: Sequence[str]) -> bool:
|
| 258 |
+
if self._is_property(path) or not path: # empty path => instruction @ root
|
| 259 |
+
return False
|
| 260 |
+
key = path[-1]
|
| 261 |
+
return any(key.startswith(k) for k in "$_") or key in self._IGNORE
|
| 262 |
+
|
| 263 |
+
def _filter_unecessary(
|
| 264 |
+
self, schema: Dict[str, Any], path: Sequence[str]
|
| 265 |
+
) -> Dict[str, Any]:
|
| 266 |
+
return {
|
| 267 |
+
key: value
|
| 268 |
+
for key, value in schema.items()
|
| 269 |
+
if not self._is_unecessary([*path, key])
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
def _handle_simple_dict(self, value: dict, path: Sequence[str]) -> Optional[str]:
|
| 273 |
+
inline = any(p in value for p in self._guess_inline_defs)
|
| 274 |
+
simple = not any(isinstance(v, (list, dict)) for v in value.values())
|
| 275 |
+
if inline or simple:
|
| 276 |
+
return f"{{{', '.join(self._inline_attrs(value, path))}}}\n"
|
| 277 |
+
return None
|
| 278 |
+
|
| 279 |
+
def _handle_list(
|
| 280 |
+
self, schemas: list, prefix: str = "", path: Sequence[str] = ()
|
| 281 |
+
) -> str:
|
| 282 |
+
if self._is_unecessary(path):
|
| 283 |
+
return ""
|
| 284 |
+
|
| 285 |
+
repr_ = repr(schemas)
|
| 286 |
+
if all(not isinstance(e, (dict, list)) for e in schemas) and len(repr_) < 60:
|
| 287 |
+
return f"{repr_}\n"
|
| 288 |
+
|
| 289 |
+
item_prefix = self._child_prefix(prefix, "- ")
|
| 290 |
+
return "".join(
|
| 291 |
+
self(v, item_prefix, _path=[*path, f"[{i}]"]) for i, v in enumerate(schemas)
|
| 292 |
+
)
|
| 293 |
+
|
| 294 |
+
def _is_property(self, path: Sequence[str]) -> bool:
|
| 295 |
+
"""Check if the given path can correspond to an arbitrarily named property"""
|
| 296 |
+
counter = 0
|
| 297 |
+
for key in path[-2::-1]:
|
| 298 |
+
if key not in {"properties", "patternProperties"}:
|
| 299 |
+
break
|
| 300 |
+
counter += 1
|
| 301 |
+
|
| 302 |
+
# If the counter if even, the path correspond to a JSON Schema keyword
|
| 303 |
+
# otherwise it can be any arbitrary string naming a property
|
| 304 |
+
return counter % 2 == 1
|
| 305 |
+
|
| 306 |
+
def _label(self, path: Sequence[str]) -> str:
|
| 307 |
+
*parents, key = path
|
| 308 |
+
if not self._is_property(path):
|
| 309 |
+
norm_key = _separate_terms(key)
|
| 310 |
+
return self._terms.get(key) or " ".join(self._jargon(norm_key))
|
| 311 |
+
|
| 312 |
+
if parents[-1] == "patternProperties":
|
| 313 |
+
return f"(regex {key!r})"
|
| 314 |
+
return repr(key) # property name
|
| 315 |
+
|
| 316 |
+
def _value(self, value: Any, path: Sequence[str]) -> str:
|
| 317 |
+
if path[-1] == "type" and not self._is_property(path):
|
| 318 |
+
type_ = self._jargon(value)
|
| 319 |
+
return f"[{', '.join(type_)}]" if isinstance(type_, list) else type_
|
| 320 |
+
return repr(value)
|
| 321 |
+
|
| 322 |
+
def _inline_attrs(self, schema: dict, path: Sequence[str]) -> Iterator[str]:
|
| 323 |
+
for key, value in schema.items():
|
| 324 |
+
child_path = [*path, key]
|
| 325 |
+
yield f"{self._label(child_path)}: {self._value(value, child_path)}"
|
| 326 |
+
|
| 327 |
+
def _child_prefix(self, parent_prefix: str, child_prefix: str) -> str:
|
| 328 |
+
return len(parent_prefix) * " " + child_prefix
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def _separate_terms(word: str) -> List[str]:
|
| 332 |
+
"""
|
| 333 |
+
>>> _separate_terms("FooBar-foo")
|
| 334 |
+
['foo', 'bar', 'foo']
|
| 335 |
+
"""
|
| 336 |
+
return [w.lower() for w in _CAMEL_CASE_SPLITTER.split(word) if w]
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/extra_validations.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The purpose of this module is implement PEP 621 validations that are
|
| 2 |
+
difficult to express as a JSON Schema (or that are not supported by the current
|
| 3 |
+
JSON Schema library).
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from inspect import cleandoc
|
| 7 |
+
from typing import Mapping, TypeVar
|
| 8 |
+
|
| 9 |
+
from .error_reporting import ValidationError
|
| 10 |
+
|
| 11 |
+
T = TypeVar("T", bound=Mapping)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class RedefiningStaticFieldAsDynamic(ValidationError):
|
| 15 |
+
_DESC = """According to PEP 621:
|
| 16 |
+
|
| 17 |
+
Build back-ends MUST raise an error if the metadata specifies a field
|
| 18 |
+
statically as well as being listed in dynamic.
|
| 19 |
+
"""
|
| 20 |
+
__doc__ = _DESC
|
| 21 |
+
_URL = (
|
| 22 |
+
"https://packaging.python.org/en/latest/specifications/"
|
| 23 |
+
"pyproject-toml/#dynamic"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def validate_project_dynamic(pyproject: T) -> T:
|
| 28 |
+
project_table = pyproject.get("project", {})
|
| 29 |
+
dynamic = project_table.get("dynamic", [])
|
| 30 |
+
|
| 31 |
+
for field in dynamic:
|
| 32 |
+
if field in project_table:
|
| 33 |
+
raise RedefiningStaticFieldAsDynamic(
|
| 34 |
+
message=f"You cannot provide a value for `project.{field}` and "
|
| 35 |
+
"list it under `project.dynamic` at the same time",
|
| 36 |
+
value={
|
| 37 |
+
field: project_table[field],
|
| 38 |
+
"...": " # ...",
|
| 39 |
+
"dynamic": dynamic,
|
| 40 |
+
},
|
| 41 |
+
name=f"data.project.{field}",
|
| 42 |
+
definition={
|
| 43 |
+
"description": cleandoc(RedefiningStaticFieldAsDynamic._DESC),
|
| 44 |
+
"see": RedefiningStaticFieldAsDynamic._URL,
|
| 45 |
+
},
|
| 46 |
+
rule="PEP 621",
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
return pyproject
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
EXTRA_VALIDATIONS = (validate_project_dynamic,)
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/fastjsonschema_exceptions.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
SPLIT_RE = re.compile(r'[\.\[\]]+')
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class JsonSchemaException(ValueError):
|
| 8 |
+
"""
|
| 9 |
+
Base exception of ``fastjsonschema`` library.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class JsonSchemaValueException(JsonSchemaException):
|
| 14 |
+
"""
|
| 15 |
+
Exception raised by validation function. Available properties:
|
| 16 |
+
|
| 17 |
+
* ``message`` containing human-readable information what is wrong (e.g. ``data.property[index] must be smaller than or equal to 42``),
|
| 18 |
+
* invalid ``value`` (e.g. ``60``),
|
| 19 |
+
* ``name`` of a path in the data structure (e.g. ``data.property[index]``),
|
| 20 |
+
* ``path`` as an array in the data structure (e.g. ``['data', 'property', 'index']``),
|
| 21 |
+
* the whole ``definition`` which the ``value`` has to fulfil (e.g. ``{'type': 'number', 'maximum': 42}``),
|
| 22 |
+
* ``rule`` which the ``value`` is breaking (e.g. ``maximum``)
|
| 23 |
+
* and ``rule_definition`` (e.g. ``42``).
|
| 24 |
+
|
| 25 |
+
.. versionchanged:: 2.14.0
|
| 26 |
+
Added all extra properties.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
def __init__(self, message, value=None, name=None, definition=None, rule=None):
|
| 30 |
+
super().__init__(message)
|
| 31 |
+
self.message = message
|
| 32 |
+
self.value = value
|
| 33 |
+
self.name = name
|
| 34 |
+
self.definition = definition
|
| 35 |
+
self.rule = rule
|
| 36 |
+
|
| 37 |
+
@property
|
| 38 |
+
def path(self):
|
| 39 |
+
return [item for item in SPLIT_RE.split(self.name) if item != '']
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def rule_definition(self):
|
| 43 |
+
if not self.rule or not self.definition:
|
| 44 |
+
return None
|
| 45 |
+
return self.definition.get(self.rule)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class JsonSchemaDefinitionException(JsonSchemaException):
|
| 49 |
+
"""
|
| 50 |
+
Exception raised by generator of validation function.
|
| 51 |
+
"""
|
videollama2/lib/python3.10/site-packages/setuptools/config/_validate_pyproject/fastjsonschema_validations.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/config/distutils.schema.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 3 |
+
|
| 4 |
+
"$id": "https://setuptools.pypa.io/en/latest/deprecated/distutils/configfile.html",
|
| 5 |
+
"title": "``tool.distutils`` table",
|
| 6 |
+
"$$description": [
|
| 7 |
+
"**EXPERIMENTAL** (NOT OFFICIALLY SUPPORTED): Use ``tool.distutils``",
|
| 8 |
+
"subtables to configure arguments for ``distutils`` commands.",
|
| 9 |
+
"Originally, ``distutils`` allowed developers to configure arguments for",
|
| 10 |
+
"``setup.py`` commands via `distutils configuration files",
|
| 11 |
+
"<https://setuptools.pypa.io/en/latest/deprecated/distutils/configfile.html>`_.",
|
| 12 |
+
"See also `the old Python docs <https://docs.python.org/3.11/install/>_`."
|
| 13 |
+
],
|
| 14 |
+
|
| 15 |
+
"type": "object",
|
| 16 |
+
"properties": {
|
| 17 |
+
"global": {
|
| 18 |
+
"type": "object",
|
| 19 |
+
"description": "Global options applied to all ``distutils`` commands"
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
"patternProperties": {
|
| 23 |
+
".+": {"type": "object"}
|
| 24 |
+
},
|
| 25 |
+
"$comment": "TODO: Is there a practical way of making this schema more specific?"
|
| 26 |
+
}
|
videollama2/lib/python3.10/site-packages/setuptools/config/expand.py
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utility functions to expand configuration directives or special values
|
| 2 |
+
(such glob patterns).
|
| 3 |
+
|
| 4 |
+
We can split the process of interpreting configuration files into 2 steps:
|
| 5 |
+
|
| 6 |
+
1. The parsing the file contents from strings to value objects
|
| 7 |
+
that can be understand by Python (for example a string with a comma
|
| 8 |
+
separated list of keywords into an actual Python list of strings).
|
| 9 |
+
|
| 10 |
+
2. The expansion (or post-processing) of these values according to the
|
| 11 |
+
semantics ``setuptools`` assign to them (for example a configuration field
|
| 12 |
+
with the ``file:`` directive should be expanded from a list of file paths to
|
| 13 |
+
a single string with the contents of those files concatenated)
|
| 14 |
+
|
| 15 |
+
This module focus on the second step, and therefore allow sharing the expansion
|
| 16 |
+
functions among several configuration file formats.
|
| 17 |
+
|
| 18 |
+
**PRIVATE MODULE**: API reserved for setuptools internal usage only.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
from __future__ import annotations
|
| 22 |
+
|
| 23 |
+
import ast
|
| 24 |
+
import importlib
|
| 25 |
+
import os
|
| 26 |
+
import pathlib
|
| 27 |
+
import sys
|
| 28 |
+
from collections.abc import Iterable, Iterator, Mapping
|
| 29 |
+
from configparser import ConfigParser
|
| 30 |
+
from glob import iglob
|
| 31 |
+
from importlib.machinery import ModuleSpec, all_suffixes
|
| 32 |
+
from itertools import chain
|
| 33 |
+
from pathlib import Path
|
| 34 |
+
from types import ModuleType, TracebackType
|
| 35 |
+
from typing import TYPE_CHECKING, Any, Callable, TypeVar
|
| 36 |
+
|
| 37 |
+
from .. import _static
|
| 38 |
+
from .._path import StrPath, same_path as _same_path
|
| 39 |
+
from ..discovery import find_package_path
|
| 40 |
+
from ..warnings import SetuptoolsWarning
|
| 41 |
+
|
| 42 |
+
from distutils.errors import DistutilsOptionError
|
| 43 |
+
|
| 44 |
+
if TYPE_CHECKING:
|
| 45 |
+
from typing_extensions import Self
|
| 46 |
+
|
| 47 |
+
from setuptools.dist import Distribution
|
| 48 |
+
|
| 49 |
+
_K = TypeVar("_K")
|
| 50 |
+
_V_co = TypeVar("_V_co", covariant=True)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class StaticModule:
|
| 54 |
+
"""Proxy to a module object that avoids executing arbitrary code."""
|
| 55 |
+
|
| 56 |
+
def __init__(self, name: str, spec: ModuleSpec) -> None:
|
| 57 |
+
module = ast.parse(pathlib.Path(spec.origin).read_bytes()) # type: ignore[arg-type] # Let it raise an error on None
|
| 58 |
+
vars(self).update(locals())
|
| 59 |
+
del self.self
|
| 60 |
+
|
| 61 |
+
def _find_assignments(self) -> Iterator[tuple[ast.AST, ast.AST]]:
|
| 62 |
+
for statement in self.module.body:
|
| 63 |
+
if isinstance(statement, ast.Assign):
|
| 64 |
+
yield from ((target, statement.value) for target in statement.targets)
|
| 65 |
+
elif isinstance(statement, ast.AnnAssign) and statement.value:
|
| 66 |
+
yield (statement.target, statement.value)
|
| 67 |
+
|
| 68 |
+
def __getattr__(self, attr: str):
|
| 69 |
+
"""Attempt to load an attribute "statically", via :func:`ast.literal_eval`."""
|
| 70 |
+
try:
|
| 71 |
+
return next(
|
| 72 |
+
ast.literal_eval(value)
|
| 73 |
+
for target, value in self._find_assignments()
|
| 74 |
+
if isinstance(target, ast.Name) and target.id == attr
|
| 75 |
+
)
|
| 76 |
+
except Exception as e:
|
| 77 |
+
raise AttributeError(f"{self.name} has no attribute {attr}") from e
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def glob_relative(
|
| 81 |
+
patterns: Iterable[str], root_dir: StrPath | None = None
|
| 82 |
+
) -> list[str]:
|
| 83 |
+
"""Expand the list of glob patterns, but preserving relative paths.
|
| 84 |
+
|
| 85 |
+
:param list[str] patterns: List of glob patterns
|
| 86 |
+
:param str root_dir: Path to which globs should be relative
|
| 87 |
+
(current directory by default)
|
| 88 |
+
:rtype: list
|
| 89 |
+
"""
|
| 90 |
+
glob_characters = {'*', '?', '[', ']', '{', '}'}
|
| 91 |
+
expanded_values = []
|
| 92 |
+
root_dir = root_dir or os.getcwd()
|
| 93 |
+
for value in patterns:
|
| 94 |
+
# Has globby characters?
|
| 95 |
+
if any(char in value for char in glob_characters):
|
| 96 |
+
# then expand the glob pattern while keeping paths *relative*:
|
| 97 |
+
glob_path = os.path.abspath(os.path.join(root_dir, value))
|
| 98 |
+
expanded_values.extend(
|
| 99 |
+
sorted(
|
| 100 |
+
os.path.relpath(path, root_dir).replace(os.sep, "/")
|
| 101 |
+
for path in iglob(glob_path, recursive=True)
|
| 102 |
+
)
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
else:
|
| 106 |
+
# take the value as-is
|
| 107 |
+
path = os.path.relpath(value, root_dir).replace(os.sep, "/")
|
| 108 |
+
expanded_values.append(path)
|
| 109 |
+
|
| 110 |
+
return expanded_values
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def read_files(
|
| 114 |
+
filepaths: StrPath | Iterable[StrPath], root_dir: StrPath | None = None
|
| 115 |
+
) -> str:
|
| 116 |
+
"""Return the content of the files concatenated using ``\n`` as str
|
| 117 |
+
|
| 118 |
+
This function is sandboxed and won't reach anything outside ``root_dir``
|
| 119 |
+
|
| 120 |
+
(By default ``root_dir`` is the current directory).
|
| 121 |
+
"""
|
| 122 |
+
from more_itertools import always_iterable
|
| 123 |
+
|
| 124 |
+
root_dir = os.path.abspath(root_dir or os.getcwd())
|
| 125 |
+
_filepaths = (os.path.join(root_dir, path) for path in always_iterable(filepaths))
|
| 126 |
+
return '\n'.join(
|
| 127 |
+
_read_file(path)
|
| 128 |
+
for path in _filter_existing_files(_filepaths)
|
| 129 |
+
if _assert_local(path, root_dir)
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def _filter_existing_files(filepaths: Iterable[StrPath]) -> Iterator[StrPath]:
|
| 134 |
+
for path in filepaths:
|
| 135 |
+
if os.path.isfile(path):
|
| 136 |
+
yield path
|
| 137 |
+
else:
|
| 138 |
+
SetuptoolsWarning.emit(f"File {path!r} cannot be found")
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def _read_file(filepath: bytes | StrPath) -> str:
|
| 142 |
+
with open(filepath, encoding='utf-8') as f:
|
| 143 |
+
return f.read()
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def _assert_local(filepath: StrPath, root_dir: str):
|
| 147 |
+
if Path(os.path.abspath(root_dir)) not in Path(os.path.abspath(filepath)).parents:
|
| 148 |
+
msg = f"Cannot access {filepath!r} (or anything outside {root_dir!r})"
|
| 149 |
+
raise DistutilsOptionError(msg)
|
| 150 |
+
|
| 151 |
+
return True
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def read_attr(
|
| 155 |
+
attr_desc: str,
|
| 156 |
+
package_dir: Mapping[str, str] | None = None,
|
| 157 |
+
root_dir: StrPath | None = None,
|
| 158 |
+
) -> Any:
|
| 159 |
+
"""Reads the value of an attribute from a module.
|
| 160 |
+
|
| 161 |
+
This function will try to read the attributed statically first
|
| 162 |
+
(via :func:`ast.literal_eval`), and only evaluate the module if it fails.
|
| 163 |
+
|
| 164 |
+
Examples:
|
| 165 |
+
read_attr("package.attr")
|
| 166 |
+
read_attr("package.module.attr")
|
| 167 |
+
|
| 168 |
+
:param str attr_desc: Dot-separated string describing how to reach the
|
| 169 |
+
attribute (see examples above)
|
| 170 |
+
:param dict[str, str] package_dir: Mapping of package names to their
|
| 171 |
+
location in disk (represented by paths relative to ``root_dir``).
|
| 172 |
+
:param str root_dir: Path to directory containing all the packages in
|
| 173 |
+
``package_dir`` (current directory by default).
|
| 174 |
+
:rtype: str
|
| 175 |
+
"""
|
| 176 |
+
root_dir = root_dir or os.getcwd()
|
| 177 |
+
attrs_path = attr_desc.strip().split('.')
|
| 178 |
+
attr_name = attrs_path.pop()
|
| 179 |
+
module_name = '.'.join(attrs_path)
|
| 180 |
+
module_name = module_name or '__init__'
|
| 181 |
+
path = _find_module(module_name, package_dir, root_dir)
|
| 182 |
+
spec = _find_spec(module_name, path)
|
| 183 |
+
|
| 184 |
+
try:
|
| 185 |
+
value = getattr(StaticModule(module_name, spec), attr_name)
|
| 186 |
+
# XXX: Is marking as static contents coming from modules too optimistic?
|
| 187 |
+
return _static.attempt_conversion(value)
|
| 188 |
+
except Exception:
|
| 189 |
+
# fallback to evaluate module
|
| 190 |
+
module = _load_spec(spec, module_name)
|
| 191 |
+
return getattr(module, attr_name)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def _find_spec(module_name: str, module_path: StrPath | None) -> ModuleSpec:
|
| 195 |
+
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
| 196 |
+
spec = spec or importlib.util.find_spec(module_name)
|
| 197 |
+
|
| 198 |
+
if spec is None:
|
| 199 |
+
raise ModuleNotFoundError(module_name)
|
| 200 |
+
|
| 201 |
+
return spec
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def _load_spec(spec: ModuleSpec, module_name: str) -> ModuleType:
|
| 205 |
+
name = getattr(spec, "__name__", module_name)
|
| 206 |
+
if name in sys.modules:
|
| 207 |
+
return sys.modules[name]
|
| 208 |
+
module = importlib.util.module_from_spec(spec)
|
| 209 |
+
sys.modules[name] = module # cache (it also ensures `==` works on loaded items)
|
| 210 |
+
assert spec.loader is not None
|
| 211 |
+
spec.loader.exec_module(module)
|
| 212 |
+
return module
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def _find_module(
|
| 216 |
+
module_name: str, package_dir: Mapping[str, str] | None, root_dir: StrPath
|
| 217 |
+
) -> str | None:
|
| 218 |
+
"""Find the path to the module named ``module_name``,
|
| 219 |
+
considering the ``package_dir`` in the build configuration and ``root_dir``.
|
| 220 |
+
|
| 221 |
+
>>> tmp = getfixture('tmpdir')
|
| 222 |
+
>>> _ = tmp.ensure("a/b/c.py")
|
| 223 |
+
>>> _ = tmp.ensure("a/b/d/__init__.py")
|
| 224 |
+
>>> r = lambda x: x.replace(str(tmp), "tmp").replace(os.sep, "/")
|
| 225 |
+
>>> r(_find_module("a.b.c", None, tmp))
|
| 226 |
+
'tmp/a/b/c.py'
|
| 227 |
+
>>> r(_find_module("f.g.h", {"": "1", "f": "2", "f.g": "3", "f.g.h": "a/b/d"}, tmp))
|
| 228 |
+
'tmp/a/b/d/__init__.py'
|
| 229 |
+
"""
|
| 230 |
+
path_start = find_package_path(module_name, package_dir or {}, root_dir)
|
| 231 |
+
candidates = chain.from_iterable(
|
| 232 |
+
(f"{path_start}{ext}", os.path.join(path_start, f"__init__{ext}"))
|
| 233 |
+
for ext in all_suffixes()
|
| 234 |
+
)
|
| 235 |
+
return next((x for x in candidates if os.path.isfile(x)), None)
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def resolve_class(
|
| 239 |
+
qualified_class_name: str,
|
| 240 |
+
package_dir: Mapping[str, str] | None = None,
|
| 241 |
+
root_dir: StrPath | None = None,
|
| 242 |
+
) -> Callable:
|
| 243 |
+
"""Given a qualified class name, return the associated class object"""
|
| 244 |
+
root_dir = root_dir or os.getcwd()
|
| 245 |
+
idx = qualified_class_name.rfind('.')
|
| 246 |
+
class_name = qualified_class_name[idx + 1 :]
|
| 247 |
+
pkg_name = qualified_class_name[:idx]
|
| 248 |
+
|
| 249 |
+
path = _find_module(pkg_name, package_dir, root_dir)
|
| 250 |
+
module = _load_spec(_find_spec(pkg_name, path), pkg_name)
|
| 251 |
+
return getattr(module, class_name)
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def cmdclass(
|
| 255 |
+
values: dict[str, str],
|
| 256 |
+
package_dir: Mapping[str, str] | None = None,
|
| 257 |
+
root_dir: StrPath | None = None,
|
| 258 |
+
) -> dict[str, Callable]:
|
| 259 |
+
"""Given a dictionary mapping command names to strings for qualified class
|
| 260 |
+
names, apply :func:`resolve_class` to the dict values.
|
| 261 |
+
"""
|
| 262 |
+
return {k: resolve_class(v, package_dir, root_dir) for k, v in values.items()}
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
def find_packages(
|
| 266 |
+
*,
|
| 267 |
+
namespaces=True,
|
| 268 |
+
fill_package_dir: dict[str, str] | None = None,
|
| 269 |
+
root_dir: StrPath | None = None,
|
| 270 |
+
**kwargs,
|
| 271 |
+
) -> list[str]:
|
| 272 |
+
"""Works similarly to :func:`setuptools.find_packages`, but with all
|
| 273 |
+
arguments given as keyword arguments. Moreover, ``where`` can be given
|
| 274 |
+
as a list (the results will be simply concatenated).
|
| 275 |
+
|
| 276 |
+
When the additional keyword argument ``namespaces`` is ``True``, it will
|
| 277 |
+
behave like :func:`setuptools.find_namespace_packages`` (i.e. include
|
| 278 |
+
implicit namespaces as per :pep:`420`).
|
| 279 |
+
|
| 280 |
+
The ``where`` argument will be considered relative to ``root_dir`` (or the current
|
| 281 |
+
working directory when ``root_dir`` is not given).
|
| 282 |
+
|
| 283 |
+
If the ``fill_package_dir`` argument is passed, this function will consider it as a
|
| 284 |
+
similar data structure to the ``package_dir`` configuration parameter add fill-in
|
| 285 |
+
any missing package location.
|
| 286 |
+
|
| 287 |
+
:rtype: list
|
| 288 |
+
"""
|
| 289 |
+
from more_itertools import always_iterable, unique_everseen
|
| 290 |
+
|
| 291 |
+
from setuptools.discovery import construct_package_dir
|
| 292 |
+
|
| 293 |
+
# check "not namespaces" first due to python/mypy#6232
|
| 294 |
+
if not namespaces:
|
| 295 |
+
from setuptools.discovery import PackageFinder
|
| 296 |
+
else:
|
| 297 |
+
from setuptools.discovery import PEP420PackageFinder as PackageFinder
|
| 298 |
+
|
| 299 |
+
root_dir = root_dir or os.curdir
|
| 300 |
+
where = kwargs.pop('where', ['.'])
|
| 301 |
+
packages: list[str] = []
|
| 302 |
+
fill_package_dir = {} if fill_package_dir is None else fill_package_dir
|
| 303 |
+
search = list(unique_everseen(always_iterable(where)))
|
| 304 |
+
|
| 305 |
+
if len(search) == 1 and all(not _same_path(search[0], x) for x in (".", root_dir)):
|
| 306 |
+
fill_package_dir.setdefault("", search[0])
|
| 307 |
+
|
| 308 |
+
for path in search:
|
| 309 |
+
package_path = _nest_path(root_dir, path)
|
| 310 |
+
pkgs = PackageFinder.find(package_path, **kwargs)
|
| 311 |
+
packages.extend(pkgs)
|
| 312 |
+
if pkgs and not (
|
| 313 |
+
fill_package_dir.get("") == path or os.path.samefile(package_path, root_dir)
|
| 314 |
+
):
|
| 315 |
+
fill_package_dir.update(construct_package_dir(pkgs, path))
|
| 316 |
+
|
| 317 |
+
return packages
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def _nest_path(parent: StrPath, path: StrPath) -> str:
|
| 321 |
+
path = parent if path in {".", ""} else os.path.join(parent, path)
|
| 322 |
+
return os.path.normpath(path)
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def version(value: Callable | Iterable[str | int] | str) -> str:
|
| 326 |
+
"""When getting the version directly from an attribute,
|
| 327 |
+
it should be normalised to string.
|
| 328 |
+
"""
|
| 329 |
+
_value = value() if callable(value) else value
|
| 330 |
+
|
| 331 |
+
if isinstance(_value, str):
|
| 332 |
+
return _value
|
| 333 |
+
if hasattr(_value, '__iter__'):
|
| 334 |
+
return '.'.join(map(str, _value))
|
| 335 |
+
return f'{_value}'
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def canonic_package_data(package_data: dict) -> dict:
|
| 339 |
+
if "*" in package_data:
|
| 340 |
+
package_data[""] = package_data.pop("*")
|
| 341 |
+
return package_data
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def canonic_data_files(
|
| 345 |
+
data_files: list | dict, root_dir: StrPath | None = None
|
| 346 |
+
) -> list[tuple[str, list[str]]]:
|
| 347 |
+
"""For compatibility with ``setup.py``, ``data_files`` should be a list
|
| 348 |
+
of pairs instead of a dict.
|
| 349 |
+
|
| 350 |
+
This function also expands glob patterns.
|
| 351 |
+
"""
|
| 352 |
+
if isinstance(data_files, list):
|
| 353 |
+
return data_files
|
| 354 |
+
|
| 355 |
+
return [
|
| 356 |
+
(dest, glob_relative(patterns, root_dir))
|
| 357 |
+
for dest, patterns in data_files.items()
|
| 358 |
+
]
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
def entry_points(
|
| 362 |
+
text: str, text_source: str = "entry-points"
|
| 363 |
+
) -> dict[str, dict[str, str]]:
|
| 364 |
+
"""Given the contents of entry-points file,
|
| 365 |
+
process it into a 2-level dictionary (``dict[str, dict[str, str]]``).
|
| 366 |
+
The first level keys are entry-point groups, the second level keys are
|
| 367 |
+
entry-point names, and the second level values are references to objects
|
| 368 |
+
(that correspond to the entry-point value).
|
| 369 |
+
"""
|
| 370 |
+
# Using undocumented behaviour, see python/typeshed#12700
|
| 371 |
+
parser = ConfigParser(default_section=None, delimiters=("=",)) # type: ignore[call-overload]
|
| 372 |
+
parser.optionxform = str # case sensitive
|
| 373 |
+
parser.read_string(text, text_source)
|
| 374 |
+
groups = {k: dict(v.items()) for k, v in parser.items()}
|
| 375 |
+
groups.pop(parser.default_section, None)
|
| 376 |
+
return groups
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
class EnsurePackagesDiscovered:
|
| 380 |
+
"""Some expand functions require all the packages to already be discovered before
|
| 381 |
+
they run, e.g. :func:`read_attr`, :func:`resolve_class`, :func:`cmdclass`.
|
| 382 |
+
|
| 383 |
+
Therefore in some cases we will need to run autodiscovery during the evaluation of
|
| 384 |
+
the configuration. However, it is better to postpone calling package discovery as
|
| 385 |
+
much as possible, because some parameters can influence it (e.g. ``package_dir``),
|
| 386 |
+
and those might not have been processed yet.
|
| 387 |
+
"""
|
| 388 |
+
|
| 389 |
+
def __init__(self, distribution: Distribution) -> None:
|
| 390 |
+
self._dist = distribution
|
| 391 |
+
self._called = False
|
| 392 |
+
|
| 393 |
+
def __call__(self):
|
| 394 |
+
"""Trigger the automatic package discovery, if it is still necessary."""
|
| 395 |
+
if not self._called:
|
| 396 |
+
self._called = True
|
| 397 |
+
self._dist.set_defaults(name=False) # Skip name, we can still be parsing
|
| 398 |
+
|
| 399 |
+
def __enter__(self) -> Self:
|
| 400 |
+
return self
|
| 401 |
+
|
| 402 |
+
def __exit__(
|
| 403 |
+
self,
|
| 404 |
+
exc_type: type[BaseException] | None,
|
| 405 |
+
exc_value: BaseException | None,
|
| 406 |
+
traceback: TracebackType | None,
|
| 407 |
+
):
|
| 408 |
+
if self._called:
|
| 409 |
+
self._dist.set_defaults.analyse_name() # Now we can set a default name
|
| 410 |
+
|
| 411 |
+
def _get_package_dir(self) -> Mapping[str, str]:
|
| 412 |
+
self()
|
| 413 |
+
pkg_dir = self._dist.package_dir
|
| 414 |
+
return {} if pkg_dir is None else pkg_dir
|
| 415 |
+
|
| 416 |
+
@property
|
| 417 |
+
def package_dir(self) -> Mapping[str, str]:
|
| 418 |
+
"""Proxy to ``package_dir`` that may trigger auto-discovery when used."""
|
| 419 |
+
return LazyMappingProxy(self._get_package_dir)
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
class LazyMappingProxy(Mapping[_K, _V_co]):
|
| 423 |
+
"""Mapping proxy that delays resolving the target object, until really needed.
|
| 424 |
+
|
| 425 |
+
>>> def obtain_mapping():
|
| 426 |
+
... print("Running expensive function!")
|
| 427 |
+
... return {"key": "value", "other key": "other value"}
|
| 428 |
+
>>> mapping = LazyMappingProxy(obtain_mapping)
|
| 429 |
+
>>> mapping["key"]
|
| 430 |
+
Running expensive function!
|
| 431 |
+
'value'
|
| 432 |
+
>>> mapping["other key"]
|
| 433 |
+
'other value'
|
| 434 |
+
"""
|
| 435 |
+
|
| 436 |
+
def __init__(self, obtain_mapping_value: Callable[[], Mapping[_K, _V_co]]) -> None:
|
| 437 |
+
self._obtain = obtain_mapping_value
|
| 438 |
+
self._value: Mapping[_K, _V_co] | None = None
|
| 439 |
+
|
| 440 |
+
def _target(self) -> Mapping[_K, _V_co]:
|
| 441 |
+
if self._value is None:
|
| 442 |
+
self._value = self._obtain()
|
| 443 |
+
return self._value
|
| 444 |
+
|
| 445 |
+
def __getitem__(self, key: _K) -> _V_co:
|
| 446 |
+
return self._target()[key]
|
| 447 |
+
|
| 448 |
+
def __len__(self) -> int:
|
| 449 |
+
return len(self._target())
|
| 450 |
+
|
| 451 |
+
def __iter__(self) -> Iterator[_K]:
|
| 452 |
+
return iter(self._target())
|
videollama2/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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API reserved for setuptools internal usage only.
|
| 5 |
+
|
| 6 |
+
To read project metadata, consider using
|
| 7 |
+
``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
|
| 8 |
+
For simple scenarios, you can also try parsing the file directly
|
| 9 |
+
with the help of ``tomllib`` or ``tomli``.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from __future__ import annotations
|
| 13 |
+
|
| 14 |
+
import logging
|
| 15 |
+
import os
|
| 16 |
+
from collections.abc import Mapping
|
| 17 |
+
from contextlib import contextmanager
|
| 18 |
+
from functools import partial
|
| 19 |
+
from types import TracebackType
|
| 20 |
+
from typing import TYPE_CHECKING, Any, Callable
|
| 21 |
+
|
| 22 |
+
from .._path import StrPath
|
| 23 |
+
from ..errors import FileError, InvalidConfigError
|
| 24 |
+
from ..warnings import SetuptoolsWarning
|
| 25 |
+
from . import expand as _expand
|
| 26 |
+
from ._apply_pyprojecttoml import _PREVIOUSLY_DEFINED, _MissingDynamic, apply as _apply
|
| 27 |
+
|
| 28 |
+
if TYPE_CHECKING:
|
| 29 |
+
from typing_extensions import Self
|
| 30 |
+
|
| 31 |
+
from setuptools.dist import Distribution
|
| 32 |
+
|
| 33 |
+
_logger = logging.getLogger(__name__)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def load_file(filepath: StrPath) -> dict:
|
| 37 |
+
from ..compat.py310 import tomllib
|
| 38 |
+
|
| 39 |
+
with open(filepath, "rb") as file:
|
| 40 |
+
return tomllib.load(file)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def validate(config: dict, filepath: StrPath) -> bool:
|
| 44 |
+
from . import _validate_pyproject as validator
|
| 45 |
+
|
| 46 |
+
trove_classifier = validator.FORMAT_FUNCTIONS.get("trove-classifier")
|
| 47 |
+
if hasattr(trove_classifier, "_disable_download"):
|
| 48 |
+
# Improve reproducibility by default. See abravalheri/validate-pyproject#31
|
| 49 |
+
trove_classifier._disable_download() # type: ignore[union-attr]
|
| 50 |
+
|
| 51 |
+
try:
|
| 52 |
+
return validator.validate(config)
|
| 53 |
+
except validator.ValidationError as ex:
|
| 54 |
+
summary = f"configuration error: {ex.summary}"
|
| 55 |
+
if ex.name.strip("`") != "project":
|
| 56 |
+
# Probably it is just a field missing/misnamed, not worthy the verbosity...
|
| 57 |
+
_logger.debug(summary)
|
| 58 |
+
_logger.debug(ex.details)
|
| 59 |
+
|
| 60 |
+
error = f"invalid pyproject.toml config: {ex.name}."
|
| 61 |
+
raise ValueError(f"{error}\n{summary}") from None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def apply_configuration(
|
| 65 |
+
dist: Distribution,
|
| 66 |
+
filepath: StrPath,
|
| 67 |
+
ignore_option_errors: bool = False,
|
| 68 |
+
) -> Distribution:
|
| 69 |
+
"""Apply the configuration from a ``pyproject.toml`` file into an existing
|
| 70 |
+
distribution object.
|
| 71 |
+
"""
|
| 72 |
+
config = read_configuration(filepath, True, ignore_option_errors, dist)
|
| 73 |
+
return _apply(dist, config, filepath)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def read_configuration(
|
| 77 |
+
filepath: StrPath,
|
| 78 |
+
expand: bool = True,
|
| 79 |
+
ignore_option_errors: bool = False,
|
| 80 |
+
dist: Distribution | None = None,
|
| 81 |
+
) -> dict[str, Any]:
|
| 82 |
+
"""Read given configuration file and returns options from it as a dict.
|
| 83 |
+
|
| 84 |
+
:param str|unicode filepath: Path to configuration file in the ``pyproject.toml``
|
| 85 |
+
format.
|
| 86 |
+
|
| 87 |
+
:param bool expand: Whether to expand directives and other computed values
|
| 88 |
+
(i.e. post-process the given configuration)
|
| 89 |
+
|
| 90 |
+
:param bool ignore_option_errors: Whether to silently ignore
|
| 91 |
+
options, values of which could not be resolved (e.g. due to exceptions
|
| 92 |
+
in directives such as file:, attr:, etc.).
|
| 93 |
+
If False exceptions are propagated as expected.
|
| 94 |
+
|
| 95 |
+
:param Distribution|None: Distribution object to which the configuration refers.
|
| 96 |
+
If not given a dummy object will be created and discarded after the
|
| 97 |
+
configuration is read. This is used for auto-discovery of packages and in the
|
| 98 |
+
case a dynamic configuration (e.g. ``attr`` or ``cmdclass``) is expanded.
|
| 99 |
+
When ``expand=False`` this object is simply ignored.
|
| 100 |
+
|
| 101 |
+
:rtype: dict
|
| 102 |
+
"""
|
| 103 |
+
filepath = os.path.abspath(filepath)
|
| 104 |
+
|
| 105 |
+
if not os.path.isfile(filepath):
|
| 106 |
+
raise FileError(f"Configuration file {filepath!r} does not exist.")
|
| 107 |
+
|
| 108 |
+
asdict = load_file(filepath) or {}
|
| 109 |
+
project_table = asdict.get("project", {})
|
| 110 |
+
tool_table = asdict.get("tool", {})
|
| 111 |
+
setuptools_table = tool_table.get("setuptools", {})
|
| 112 |
+
if not asdict or not (project_table or setuptools_table):
|
| 113 |
+
return {} # User is not using pyproject to configure setuptools
|
| 114 |
+
|
| 115 |
+
if "setuptools" in asdict.get("tools", {}):
|
| 116 |
+
# let the user know they probably have a typo in their metadata
|
| 117 |
+
_ToolsTypoInMetadata.emit()
|
| 118 |
+
|
| 119 |
+
if "distutils" in tool_table:
|
| 120 |
+
_ExperimentalConfiguration.emit(subject="[tool.distutils]")
|
| 121 |
+
|
| 122 |
+
# There is an overall sense in the community that making include_package_data=True
|
| 123 |
+
# the default would be an improvement.
|
| 124 |
+
# `ini2toml` backfills include_package_data=False when nothing is explicitly given,
|
| 125 |
+
# therefore setting a default here is backwards compatible.
|
| 126 |
+
if dist and dist.include_package_data is not None:
|
| 127 |
+
setuptools_table.setdefault("include-package-data", dist.include_package_data)
|
| 128 |
+
else:
|
| 129 |
+
setuptools_table.setdefault("include-package-data", True)
|
| 130 |
+
# Persist changes:
|
| 131 |
+
asdict["tool"] = tool_table
|
| 132 |
+
tool_table["setuptools"] = setuptools_table
|
| 133 |
+
|
| 134 |
+
if "ext-modules" in setuptools_table:
|
| 135 |
+
_ExperimentalConfiguration.emit(subject="[tool.setuptools.ext-modules]")
|
| 136 |
+
|
| 137 |
+
with _ignore_errors(ignore_option_errors):
|
| 138 |
+
# Don't complain about unrelated errors (e.g. tools not using the "tool" table)
|
| 139 |
+
subset = {"project": project_table, "tool": {"setuptools": setuptools_table}}
|
| 140 |
+
validate(subset, filepath)
|
| 141 |
+
|
| 142 |
+
if expand:
|
| 143 |
+
root_dir = os.path.dirname(filepath)
|
| 144 |
+
return expand_configuration(asdict, root_dir, ignore_option_errors, dist)
|
| 145 |
+
|
| 146 |
+
return asdict
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def expand_configuration(
|
| 150 |
+
config: dict,
|
| 151 |
+
root_dir: StrPath | None = None,
|
| 152 |
+
ignore_option_errors: bool = False,
|
| 153 |
+
dist: Distribution | None = None,
|
| 154 |
+
) -> dict:
|
| 155 |
+
"""Given a configuration with unresolved fields (e.g. dynamic, cmdclass, ...)
|
| 156 |
+
find their final values.
|
| 157 |
+
|
| 158 |
+
:param dict config: Dict containing the configuration for the distribution
|
| 159 |
+
:param str root_dir: Top-level directory for the distribution/project
|
| 160 |
+
(the same directory where ``pyproject.toml`` is place)
|
| 161 |
+
:param bool ignore_option_errors: see :func:`read_configuration`
|
| 162 |
+
:param Distribution|None: Distribution object to which the configuration refers.
|
| 163 |
+
If not given a dummy object will be created and discarded after the
|
| 164 |
+
configuration is read. Used in the case a dynamic configuration
|
| 165 |
+
(e.g. ``attr`` or ``cmdclass``).
|
| 166 |
+
|
| 167 |
+
:rtype: dict
|
| 168 |
+
"""
|
| 169 |
+
return _ConfigExpander(config, root_dir, ignore_option_errors, dist).expand()
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
class _ConfigExpander:
|
| 173 |
+
def __init__(
|
| 174 |
+
self,
|
| 175 |
+
config: dict,
|
| 176 |
+
root_dir: StrPath | None = None,
|
| 177 |
+
ignore_option_errors: bool = False,
|
| 178 |
+
dist: Distribution | None = None,
|
| 179 |
+
) -> None:
|
| 180 |
+
self.config = config
|
| 181 |
+
self.root_dir = root_dir or os.getcwd()
|
| 182 |
+
self.project_cfg = config.get("project", {})
|
| 183 |
+
self.dynamic = self.project_cfg.get("dynamic", [])
|
| 184 |
+
self.setuptools_cfg = config.get("tool", {}).get("setuptools", {})
|
| 185 |
+
self.dynamic_cfg = self.setuptools_cfg.get("dynamic", {})
|
| 186 |
+
self.ignore_option_errors = ignore_option_errors
|
| 187 |
+
self._dist = dist
|
| 188 |
+
self._referenced_files = set[str]()
|
| 189 |
+
|
| 190 |
+
def _ensure_dist(self) -> Distribution:
|
| 191 |
+
from setuptools.dist import Distribution
|
| 192 |
+
|
| 193 |
+
attrs = {"src_root": self.root_dir, "name": self.project_cfg.get("name", None)}
|
| 194 |
+
return self._dist or Distribution(attrs)
|
| 195 |
+
|
| 196 |
+
def _process_field(self, container: dict, field: str, fn: Callable):
|
| 197 |
+
if field in container:
|
| 198 |
+
with _ignore_errors(self.ignore_option_errors):
|
| 199 |
+
container[field] = fn(container[field])
|
| 200 |
+
|
| 201 |
+
def _canonic_package_data(self, field="package-data"):
|
| 202 |
+
package_data = self.setuptools_cfg.get(field, {})
|
| 203 |
+
return _expand.canonic_package_data(package_data)
|
| 204 |
+
|
| 205 |
+
def expand(self):
|
| 206 |
+
self._expand_packages()
|
| 207 |
+
self._canonic_package_data()
|
| 208 |
+
self._canonic_package_data("exclude-package-data")
|
| 209 |
+
|
| 210 |
+
# A distribution object is required for discovering the correct package_dir
|
| 211 |
+
dist = self._ensure_dist()
|
| 212 |
+
ctx = _EnsurePackagesDiscovered(dist, self.project_cfg, self.setuptools_cfg)
|
| 213 |
+
with ctx as ensure_discovered:
|
| 214 |
+
package_dir = ensure_discovered.package_dir
|
| 215 |
+
self._expand_data_files()
|
| 216 |
+
self._expand_cmdclass(package_dir)
|
| 217 |
+
self._expand_all_dynamic(dist, package_dir)
|
| 218 |
+
|
| 219 |
+
dist._referenced_files.update(self._referenced_files)
|
| 220 |
+
return self.config
|
| 221 |
+
|
| 222 |
+
def _expand_packages(self):
|
| 223 |
+
packages = self.setuptools_cfg.get("packages")
|
| 224 |
+
if packages is None or isinstance(packages, (list, tuple)):
|
| 225 |
+
return
|
| 226 |
+
|
| 227 |
+
find = packages.get("find")
|
| 228 |
+
if isinstance(find, dict):
|
| 229 |
+
find["root_dir"] = self.root_dir
|
| 230 |
+
find["fill_package_dir"] = self.setuptools_cfg.setdefault("package-dir", {})
|
| 231 |
+
with _ignore_errors(self.ignore_option_errors):
|
| 232 |
+
self.setuptools_cfg["packages"] = _expand.find_packages(**find)
|
| 233 |
+
|
| 234 |
+
def _expand_data_files(self):
|
| 235 |
+
data_files = partial(_expand.canonic_data_files, root_dir=self.root_dir)
|
| 236 |
+
self._process_field(self.setuptools_cfg, "data-files", data_files)
|
| 237 |
+
|
| 238 |
+
def _expand_cmdclass(self, package_dir: Mapping[str, str]):
|
| 239 |
+
root_dir = self.root_dir
|
| 240 |
+
cmdclass = partial(_expand.cmdclass, package_dir=package_dir, root_dir=root_dir)
|
| 241 |
+
self._process_field(self.setuptools_cfg, "cmdclass", cmdclass)
|
| 242 |
+
|
| 243 |
+
def _expand_all_dynamic(self, dist: Distribution, package_dir: Mapping[str, str]):
|
| 244 |
+
special = ( # need special handling
|
| 245 |
+
"version",
|
| 246 |
+
"readme",
|
| 247 |
+
"entry-points",
|
| 248 |
+
"scripts",
|
| 249 |
+
"gui-scripts",
|
| 250 |
+
"classifiers",
|
| 251 |
+
"dependencies",
|
| 252 |
+
"optional-dependencies",
|
| 253 |
+
)
|
| 254 |
+
# `_obtain` functions are assumed to raise appropriate exceptions/warnings.
|
| 255 |
+
obtained_dynamic = {
|
| 256 |
+
field: self._obtain(dist, field, package_dir)
|
| 257 |
+
for field in self.dynamic
|
| 258 |
+
if field not in special
|
| 259 |
+
}
|
| 260 |
+
obtained_dynamic.update(
|
| 261 |
+
self._obtain_entry_points(dist, package_dir) or {},
|
| 262 |
+
version=self._obtain_version(dist, package_dir),
|
| 263 |
+
readme=self._obtain_readme(dist),
|
| 264 |
+
classifiers=self._obtain_classifiers(dist),
|
| 265 |
+
dependencies=self._obtain_dependencies(dist),
|
| 266 |
+
optional_dependencies=self._obtain_optional_dependencies(dist),
|
| 267 |
+
)
|
| 268 |
+
# `None` indicates there is nothing in `tool.setuptools.dynamic` but the value
|
| 269 |
+
# might have already been set by setup.py/extensions, so avoid overwriting.
|
| 270 |
+
updates = {k: v for k, v in obtained_dynamic.items() if v is not None}
|
| 271 |
+
self.project_cfg.update(updates)
|
| 272 |
+
|
| 273 |
+
def _ensure_previously_set(self, dist: Distribution, field: str):
|
| 274 |
+
previous = _PREVIOUSLY_DEFINED[field](dist)
|
| 275 |
+
if previous is None and not self.ignore_option_errors:
|
| 276 |
+
msg = (
|
| 277 |
+
f"No configuration found for dynamic {field!r}.\n"
|
| 278 |
+
"Some dynamic fields need to be specified via `tool.setuptools.dynamic`"
|
| 279 |
+
"\nothers must be specified via the equivalent attribute in `setup.py`."
|
| 280 |
+
)
|
| 281 |
+
raise InvalidConfigError(msg)
|
| 282 |
+
|
| 283 |
+
def _expand_directive(
|
| 284 |
+
self, specifier: str, directive, package_dir: Mapping[str, str]
|
| 285 |
+
):
|
| 286 |
+
from more_itertools import always_iterable
|
| 287 |
+
|
| 288 |
+
with _ignore_errors(self.ignore_option_errors):
|
| 289 |
+
root_dir = self.root_dir
|
| 290 |
+
if "file" in directive:
|
| 291 |
+
self._referenced_files.update(always_iterable(directive["file"]))
|
| 292 |
+
return _expand.read_files(directive["file"], root_dir)
|
| 293 |
+
if "attr" in directive:
|
| 294 |
+
return _expand.read_attr(directive["attr"], package_dir, root_dir)
|
| 295 |
+
raise ValueError(f"invalid `{specifier}`: {directive!r}")
|
| 296 |
+
return None
|
| 297 |
+
|
| 298 |
+
def _obtain(self, dist: Distribution, field: str, package_dir: Mapping[str, str]):
|
| 299 |
+
if field in self.dynamic_cfg:
|
| 300 |
+
return self._expand_directive(
|
| 301 |
+
f"tool.setuptools.dynamic.{field}",
|
| 302 |
+
self.dynamic_cfg[field],
|
| 303 |
+
package_dir,
|
| 304 |
+
)
|
| 305 |
+
self._ensure_previously_set(dist, field)
|
| 306 |
+
return None
|
| 307 |
+
|
| 308 |
+
def _obtain_version(self, dist: Distribution, package_dir: Mapping[str, str]):
|
| 309 |
+
# Since plugins can set version, let's silently skip if it cannot be obtained
|
| 310 |
+
if "version" in self.dynamic and "version" in self.dynamic_cfg:
|
| 311 |
+
return _expand.version(
|
| 312 |
+
# We already do an early check for the presence of "version"
|
| 313 |
+
self._obtain(dist, "version", package_dir) # pyright: ignore[reportArgumentType]
|
| 314 |
+
)
|
| 315 |
+
return None
|
| 316 |
+
|
| 317 |
+
def _obtain_readme(self, dist: Distribution) -> dict[str, str] | None:
|
| 318 |
+
if "readme" not in self.dynamic:
|
| 319 |
+
return None
|
| 320 |
+
|
| 321 |
+
dynamic_cfg = self.dynamic_cfg
|
| 322 |
+
if "readme" in dynamic_cfg:
|
| 323 |
+
return {
|
| 324 |
+
# We already do an early check for the presence of "readme"
|
| 325 |
+
"text": self._obtain(dist, "readme", {}),
|
| 326 |
+
"content-type": dynamic_cfg["readme"].get("content-type", "text/x-rst"),
|
| 327 |
+
} # pyright: ignore[reportReturnType]
|
| 328 |
+
|
| 329 |
+
self._ensure_previously_set(dist, "readme")
|
| 330 |
+
return None
|
| 331 |
+
|
| 332 |
+
def _obtain_entry_points(
|
| 333 |
+
self, dist: Distribution, package_dir: Mapping[str, str]
|
| 334 |
+
) -> dict[str, dict[str, Any]] | None:
|
| 335 |
+
fields = ("entry-points", "scripts", "gui-scripts")
|
| 336 |
+
if not any(field in self.dynamic for field in fields):
|
| 337 |
+
return None
|
| 338 |
+
|
| 339 |
+
text = self._obtain(dist, "entry-points", package_dir)
|
| 340 |
+
if text is None:
|
| 341 |
+
return None
|
| 342 |
+
|
| 343 |
+
groups = _expand.entry_points(text)
|
| 344 |
+
# Any is str | dict[str, str], but causes variance issues
|
| 345 |
+
expanded: dict[str, dict[str, Any]] = {"entry-points": groups}
|
| 346 |
+
|
| 347 |
+
def _set_scripts(field: str, group: str):
|
| 348 |
+
if group in groups:
|
| 349 |
+
value = groups.pop(group)
|
| 350 |
+
if field not in self.dynamic:
|
| 351 |
+
raise InvalidConfigError(_MissingDynamic.details(field, value))
|
| 352 |
+
expanded[field] = value
|
| 353 |
+
|
| 354 |
+
_set_scripts("scripts", "console_scripts")
|
| 355 |
+
_set_scripts("gui-scripts", "gui_scripts")
|
| 356 |
+
|
| 357 |
+
return expanded
|
| 358 |
+
|
| 359 |
+
def _obtain_classifiers(self, dist: Distribution):
|
| 360 |
+
if "classifiers" in self.dynamic:
|
| 361 |
+
value = self._obtain(dist, "classifiers", {})
|
| 362 |
+
if value:
|
| 363 |
+
return value.splitlines()
|
| 364 |
+
return None
|
| 365 |
+
|
| 366 |
+
def _obtain_dependencies(self, dist: Distribution):
|
| 367 |
+
if "dependencies" in self.dynamic:
|
| 368 |
+
value = self._obtain(dist, "dependencies", {})
|
| 369 |
+
if value:
|
| 370 |
+
return _parse_requirements_list(value)
|
| 371 |
+
return None
|
| 372 |
+
|
| 373 |
+
def _obtain_optional_dependencies(self, dist: Distribution):
|
| 374 |
+
if "optional-dependencies" not in self.dynamic:
|
| 375 |
+
return None
|
| 376 |
+
if "optional-dependencies" in self.dynamic_cfg:
|
| 377 |
+
optional_dependencies_map = self.dynamic_cfg["optional-dependencies"]
|
| 378 |
+
assert isinstance(optional_dependencies_map, dict)
|
| 379 |
+
return {
|
| 380 |
+
group: _parse_requirements_list(
|
| 381 |
+
self._expand_directive(
|
| 382 |
+
f"tool.setuptools.dynamic.optional-dependencies.{group}",
|
| 383 |
+
directive,
|
| 384 |
+
{},
|
| 385 |
+
)
|
| 386 |
+
)
|
| 387 |
+
for group, directive in optional_dependencies_map.items()
|
| 388 |
+
}
|
| 389 |
+
self._ensure_previously_set(dist, "optional-dependencies")
|
| 390 |
+
return None
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
def _parse_requirements_list(value):
|
| 394 |
+
return [
|
| 395 |
+
line
|
| 396 |
+
for line in value.splitlines()
|
| 397 |
+
if line.strip() and not line.strip().startswith("#")
|
| 398 |
+
]
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
@contextmanager
|
| 402 |
+
def _ignore_errors(ignore_option_errors: bool):
|
| 403 |
+
if not ignore_option_errors:
|
| 404 |
+
yield
|
| 405 |
+
return
|
| 406 |
+
|
| 407 |
+
try:
|
| 408 |
+
yield
|
| 409 |
+
except Exception as ex:
|
| 410 |
+
_logger.debug(f"ignored error: {ex.__class__.__name__} - {ex}")
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
class _EnsurePackagesDiscovered(_expand.EnsurePackagesDiscovered):
|
| 414 |
+
def __init__(
|
| 415 |
+
self, distribution: Distribution, project_cfg: dict, setuptools_cfg: dict
|
| 416 |
+
) -> None:
|
| 417 |
+
super().__init__(distribution)
|
| 418 |
+
self._project_cfg = project_cfg
|
| 419 |
+
self._setuptools_cfg = setuptools_cfg
|
| 420 |
+
|
| 421 |
+
def __enter__(self) -> Self:
|
| 422 |
+
"""When entering the context, the values of ``packages``, ``py_modules`` and
|
| 423 |
+
``package_dir`` that are missing in ``dist`` are copied from ``setuptools_cfg``.
|
| 424 |
+
"""
|
| 425 |
+
dist, cfg = self._dist, self._setuptools_cfg
|
| 426 |
+
package_dir: dict[str, str] = cfg.setdefault("package-dir", {})
|
| 427 |
+
package_dir.update(dist.package_dir or {})
|
| 428 |
+
dist.package_dir = package_dir # needs to be the same object
|
| 429 |
+
|
| 430 |
+
dist.set_defaults._ignore_ext_modules() # pyproject.toml-specific behaviour
|
| 431 |
+
|
| 432 |
+
# Set `name`, `py_modules` and `packages` in dist to short-circuit
|
| 433 |
+
# auto-discovery, but avoid overwriting empty lists purposefully set by users.
|
| 434 |
+
if dist.metadata.name is None:
|
| 435 |
+
dist.metadata.name = self._project_cfg.get("name")
|
| 436 |
+
if dist.py_modules is None:
|
| 437 |
+
dist.py_modules = cfg.get("py-modules")
|
| 438 |
+
if dist.packages is None:
|
| 439 |
+
dist.packages = cfg.get("packages")
|
| 440 |
+
|
| 441 |
+
return super().__enter__()
|
| 442 |
+
|
| 443 |
+
def __exit__(
|
| 444 |
+
self,
|
| 445 |
+
exc_type: type[BaseException] | None,
|
| 446 |
+
exc_value: BaseException | None,
|
| 447 |
+
traceback: TracebackType | None,
|
| 448 |
+
) -> None:
|
| 449 |
+
"""When exiting the context, if values of ``packages``, ``py_modules`` and
|
| 450 |
+
``package_dir`` are missing in ``setuptools_cfg``, copy from ``dist``.
|
| 451 |
+
"""
|
| 452 |
+
# If anything was discovered set them back, so they count in the final config.
|
| 453 |
+
self._setuptools_cfg.setdefault("packages", self._dist.packages)
|
| 454 |
+
self._setuptools_cfg.setdefault("py-modules", self._dist.py_modules)
|
| 455 |
+
return super().__exit__(exc_type, exc_value, traceback)
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
class _ExperimentalConfiguration(SetuptoolsWarning):
|
| 459 |
+
_SUMMARY = (
|
| 460 |
+
"`{subject}` in `pyproject.toml` is still *experimental* "
|
| 461 |
+
"and likely to change in future releases."
|
| 462 |
+
)
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
class _ToolsTypoInMetadata(SetuptoolsWarning):
|
| 466 |
+
_SUMMARY = (
|
| 467 |
+
"Ignoring [tools.setuptools] in pyproject.toml, did you mean [tool.setuptools]?"
|
| 468 |
+
)
|
videollama2/lib/python3.10/site-packages/setuptools/config/setupcfg.py
ADDED
|
@@ -0,0 +1,780 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Load setuptools configuration from ``setup.cfg`` files.
|
| 3 |
+
|
| 4 |
+
**API will be made private in the future**
|
| 5 |
+
|
| 6 |
+
To read project metadata, consider using
|
| 7 |
+
``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
|
| 8 |
+
For simple scenarios, you can also try parsing the file directly
|
| 9 |
+
with the help of ``configparser``.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from __future__ import annotations
|
| 13 |
+
|
| 14 |
+
import contextlib
|
| 15 |
+
import functools
|
| 16 |
+
import os
|
| 17 |
+
from collections import defaultdict
|
| 18 |
+
from collections.abc import Iterable, Iterator
|
| 19 |
+
from functools import partial, wraps
|
| 20 |
+
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Generic, TypeVar, cast
|
| 21 |
+
|
| 22 |
+
from packaging.markers import default_environment as marker_env
|
| 23 |
+
from packaging.requirements import InvalidRequirement, Requirement
|
| 24 |
+
from packaging.version import InvalidVersion, Version
|
| 25 |
+
|
| 26 |
+
from .. import _static
|
| 27 |
+
from .._path import StrPath
|
| 28 |
+
from ..errors import FileError, OptionError
|
| 29 |
+
from ..warnings import SetuptoolsDeprecationWarning
|
| 30 |
+
from . import expand
|
| 31 |
+
|
| 32 |
+
if TYPE_CHECKING:
|
| 33 |
+
from typing_extensions import TypeAlias
|
| 34 |
+
|
| 35 |
+
from setuptools.dist import Distribution
|
| 36 |
+
|
| 37 |
+
from distutils.dist import DistributionMetadata
|
| 38 |
+
|
| 39 |
+
SingleCommandOptions: TypeAlias = dict[str, tuple[str, Any]]
|
| 40 |
+
"""Dict that associate the name of the options of a particular command to a
|
| 41 |
+
tuple. The first element of the tuple indicates the origin of the option value
|
| 42 |
+
(e.g. the name of the configuration file where it was read from),
|
| 43 |
+
while the second element of the tuple is the option value itself
|
| 44 |
+
"""
|
| 45 |
+
AllCommandOptions: TypeAlias = dict[str, SingleCommandOptions]
|
| 46 |
+
"""cmd name => its options"""
|
| 47 |
+
Target = TypeVar("Target", "Distribution", "DistributionMetadata")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def read_configuration(
|
| 51 |
+
filepath: StrPath, find_others: bool = False, ignore_option_errors: bool = False
|
| 52 |
+
) -> dict:
|
| 53 |
+
"""Read given configuration file and returns options from it as a dict.
|
| 54 |
+
|
| 55 |
+
:param str|unicode filepath: Path to configuration file
|
| 56 |
+
to get options from.
|
| 57 |
+
|
| 58 |
+
:param bool find_others: Whether to search for other configuration files
|
| 59 |
+
which could be on in various places.
|
| 60 |
+
|
| 61 |
+
:param bool ignore_option_errors: Whether to silently ignore
|
| 62 |
+
options, values of which could not be resolved (e.g. due to exceptions
|
| 63 |
+
in directives such as file:, attr:, etc.).
|
| 64 |
+
If False exceptions are propagated as expected.
|
| 65 |
+
|
| 66 |
+
:rtype: dict
|
| 67 |
+
"""
|
| 68 |
+
from setuptools.dist import Distribution
|
| 69 |
+
|
| 70 |
+
dist = Distribution()
|
| 71 |
+
filenames = dist.find_config_files() if find_others else []
|
| 72 |
+
handlers = _apply(dist, filepath, filenames, ignore_option_errors)
|
| 73 |
+
return configuration_to_dict(handlers)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def apply_configuration(dist: Distribution, filepath: StrPath) -> Distribution:
|
| 77 |
+
"""Apply the configuration from a ``setup.cfg`` file into an existing
|
| 78 |
+
distribution object.
|
| 79 |
+
"""
|
| 80 |
+
_apply(dist, filepath)
|
| 81 |
+
dist._finalize_requires()
|
| 82 |
+
return dist
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _apply(
|
| 86 |
+
dist: Distribution,
|
| 87 |
+
filepath: StrPath,
|
| 88 |
+
other_files: Iterable[StrPath] = (),
|
| 89 |
+
ignore_option_errors: bool = False,
|
| 90 |
+
) -> tuple[ConfigMetadataHandler, ConfigOptionsHandler]:
|
| 91 |
+
"""Read configuration from ``filepath`` and applies to the ``dist`` object."""
|
| 92 |
+
from setuptools.dist import _Distribution
|
| 93 |
+
|
| 94 |
+
filepath = os.path.abspath(filepath)
|
| 95 |
+
|
| 96 |
+
if not os.path.isfile(filepath):
|
| 97 |
+
raise FileError(f'Configuration file {filepath} does not exist.')
|
| 98 |
+
|
| 99 |
+
current_directory = os.getcwd()
|
| 100 |
+
os.chdir(os.path.dirname(filepath))
|
| 101 |
+
filenames = [*other_files, filepath]
|
| 102 |
+
|
| 103 |
+
try:
|
| 104 |
+
# TODO: Temporary cast until mypy 1.12 is released with upstream fixes from typeshed
|
| 105 |
+
_Distribution.parse_config_files(dist, filenames=cast(list[str], filenames))
|
| 106 |
+
handlers = parse_configuration(
|
| 107 |
+
dist, dist.command_options, ignore_option_errors=ignore_option_errors
|
| 108 |
+
)
|
| 109 |
+
dist._finalize_license_files()
|
| 110 |
+
finally:
|
| 111 |
+
os.chdir(current_directory)
|
| 112 |
+
|
| 113 |
+
return handlers
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def _get_option(target_obj: Distribution | DistributionMetadata, key: str):
|
| 117 |
+
"""
|
| 118 |
+
Given a target object and option key, get that option from
|
| 119 |
+
the target object, either through a get_{key} method or
|
| 120 |
+
from an attribute directly.
|
| 121 |
+
"""
|
| 122 |
+
getter_name = f'get_{key}'
|
| 123 |
+
by_attribute = functools.partial(getattr, target_obj, key)
|
| 124 |
+
getter = getattr(target_obj, getter_name, by_attribute)
|
| 125 |
+
return getter()
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def configuration_to_dict(
|
| 129 |
+
handlers: Iterable[
|
| 130 |
+
ConfigHandler[Distribution] | ConfigHandler[DistributionMetadata]
|
| 131 |
+
],
|
| 132 |
+
) -> dict:
|
| 133 |
+
"""Returns configuration data gathered by given handlers as a dict.
|
| 134 |
+
|
| 135 |
+
:param Iterable[ConfigHandler] handlers: Handlers list,
|
| 136 |
+
usually from parse_configuration()
|
| 137 |
+
|
| 138 |
+
:rtype: dict
|
| 139 |
+
"""
|
| 140 |
+
config_dict: dict = defaultdict(dict)
|
| 141 |
+
|
| 142 |
+
for handler in handlers:
|
| 143 |
+
for option in handler.set_options:
|
| 144 |
+
value = _get_option(handler.target_obj, option)
|
| 145 |
+
config_dict[handler.section_prefix][option] = value
|
| 146 |
+
|
| 147 |
+
return config_dict
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def parse_configuration(
|
| 151 |
+
distribution: Distribution,
|
| 152 |
+
command_options: AllCommandOptions,
|
| 153 |
+
ignore_option_errors: bool = False,
|
| 154 |
+
) -> tuple[ConfigMetadataHandler, ConfigOptionsHandler]:
|
| 155 |
+
"""Performs additional parsing of configuration options
|
| 156 |
+
for a distribution.
|
| 157 |
+
|
| 158 |
+
Returns a list of used option handlers.
|
| 159 |
+
|
| 160 |
+
:param Distribution distribution:
|
| 161 |
+
:param dict command_options:
|
| 162 |
+
:param bool ignore_option_errors: Whether to silently ignore
|
| 163 |
+
options, values of which could not be resolved (e.g. due to exceptions
|
| 164 |
+
in directives such as file:, attr:, etc.).
|
| 165 |
+
If False exceptions are propagated as expected.
|
| 166 |
+
:rtype: list
|
| 167 |
+
"""
|
| 168 |
+
with expand.EnsurePackagesDiscovered(distribution) as ensure_discovered:
|
| 169 |
+
options = ConfigOptionsHandler(
|
| 170 |
+
distribution,
|
| 171 |
+
command_options,
|
| 172 |
+
ignore_option_errors,
|
| 173 |
+
ensure_discovered,
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
options.parse()
|
| 177 |
+
if not distribution.package_dir:
|
| 178 |
+
distribution.package_dir = options.package_dir # Filled by `find_packages`
|
| 179 |
+
|
| 180 |
+
meta = ConfigMetadataHandler(
|
| 181 |
+
distribution.metadata,
|
| 182 |
+
command_options,
|
| 183 |
+
ignore_option_errors,
|
| 184 |
+
ensure_discovered,
|
| 185 |
+
distribution.package_dir,
|
| 186 |
+
distribution.src_root,
|
| 187 |
+
)
|
| 188 |
+
meta.parse()
|
| 189 |
+
distribution._referenced_files.update(
|
| 190 |
+
options._referenced_files, meta._referenced_files
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
return meta, options
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _warn_accidental_env_marker_misconfig(label: str, orig_value: str, parsed: list):
|
| 197 |
+
"""Because users sometimes misinterpret this configuration:
|
| 198 |
+
|
| 199 |
+
[options.extras_require]
|
| 200 |
+
foo = bar;python_version<"4"
|
| 201 |
+
|
| 202 |
+
It looks like one requirement with an environment marker
|
| 203 |
+
but because there is no newline, it's parsed as two requirements
|
| 204 |
+
with a semicolon as separator.
|
| 205 |
+
|
| 206 |
+
Therefore, if:
|
| 207 |
+
* input string does not contain a newline AND
|
| 208 |
+
* parsed result contains two requirements AND
|
| 209 |
+
* parsing of the two parts from the result ("<first>;<second>")
|
| 210 |
+
leads in a valid Requirement with a valid marker
|
| 211 |
+
a UserWarning is shown to inform the user about the possible problem.
|
| 212 |
+
"""
|
| 213 |
+
if "\n" in orig_value or len(parsed) != 2:
|
| 214 |
+
return
|
| 215 |
+
|
| 216 |
+
markers = marker_env().keys()
|
| 217 |
+
|
| 218 |
+
try:
|
| 219 |
+
req = Requirement(parsed[1])
|
| 220 |
+
if req.name in markers:
|
| 221 |
+
_AmbiguousMarker.emit(field=label, req=parsed[1])
|
| 222 |
+
except InvalidRequirement as ex:
|
| 223 |
+
if any(parsed[1].startswith(marker) for marker in markers):
|
| 224 |
+
msg = _AmbiguousMarker.message(field=label, req=parsed[1])
|
| 225 |
+
raise InvalidRequirement(msg) from ex
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
class ConfigHandler(Generic[Target]):
|
| 229 |
+
"""Handles metadata supplied in configuration files."""
|
| 230 |
+
|
| 231 |
+
section_prefix: str
|
| 232 |
+
"""Prefix for config sections handled by this handler.
|
| 233 |
+
Must be provided by class heirs.
|
| 234 |
+
|
| 235 |
+
"""
|
| 236 |
+
|
| 237 |
+
aliases: ClassVar[dict[str, str]] = {}
|
| 238 |
+
"""Options aliases.
|
| 239 |
+
For compatibility with various packages. E.g.: d2to1 and pbr.
|
| 240 |
+
Note: `-` in keys is replaced with `_` by config parser.
|
| 241 |
+
|
| 242 |
+
"""
|
| 243 |
+
|
| 244 |
+
def __init__(
|
| 245 |
+
self,
|
| 246 |
+
target_obj: Target,
|
| 247 |
+
options: AllCommandOptions,
|
| 248 |
+
ignore_option_errors,
|
| 249 |
+
ensure_discovered: expand.EnsurePackagesDiscovered,
|
| 250 |
+
) -> None:
|
| 251 |
+
self.ignore_option_errors = ignore_option_errors
|
| 252 |
+
self.target_obj: Target = target_obj
|
| 253 |
+
self.sections = dict(self._section_options(options))
|
| 254 |
+
self.set_options: list[str] = []
|
| 255 |
+
self.ensure_discovered = ensure_discovered
|
| 256 |
+
self._referenced_files = set[str]()
|
| 257 |
+
"""After parsing configurations, this property will enumerate
|
| 258 |
+
all files referenced by the "file:" directive. Private API for setuptools only.
|
| 259 |
+
"""
|
| 260 |
+
|
| 261 |
+
@classmethod
|
| 262 |
+
def _section_options(
|
| 263 |
+
cls, options: AllCommandOptions
|
| 264 |
+
) -> Iterator[tuple[str, SingleCommandOptions]]:
|
| 265 |
+
for full_name, value in options.items():
|
| 266 |
+
pre, _sep, name = full_name.partition(cls.section_prefix)
|
| 267 |
+
if pre:
|
| 268 |
+
continue
|
| 269 |
+
yield name.lstrip('.'), value
|
| 270 |
+
|
| 271 |
+
@property
|
| 272 |
+
def parsers(self):
|
| 273 |
+
"""Metadata item name to parser function mapping."""
|
| 274 |
+
raise NotImplementedError(
|
| 275 |
+
f'{self.__class__.__name__} must provide .parsers property'
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
def __setitem__(self, option_name, value) -> None:
|
| 279 |
+
target_obj = self.target_obj
|
| 280 |
+
|
| 281 |
+
# Translate alias into real name.
|
| 282 |
+
option_name = self.aliases.get(option_name, option_name)
|
| 283 |
+
|
| 284 |
+
try:
|
| 285 |
+
current_value = getattr(target_obj, option_name)
|
| 286 |
+
except AttributeError as e:
|
| 287 |
+
raise KeyError(option_name) from e
|
| 288 |
+
|
| 289 |
+
if current_value:
|
| 290 |
+
# Already inhabited. Skipping.
|
| 291 |
+
return
|
| 292 |
+
|
| 293 |
+
try:
|
| 294 |
+
parsed = self.parsers.get(option_name, lambda x: x)(value)
|
| 295 |
+
except (Exception,) * self.ignore_option_errors:
|
| 296 |
+
return
|
| 297 |
+
|
| 298 |
+
simple_setter = functools.partial(target_obj.__setattr__, option_name)
|
| 299 |
+
setter = getattr(target_obj, f"set_{option_name}", simple_setter)
|
| 300 |
+
setter(parsed)
|
| 301 |
+
|
| 302 |
+
self.set_options.append(option_name)
|
| 303 |
+
|
| 304 |
+
@classmethod
|
| 305 |
+
def _parse_list(cls, value, separator=','):
|
| 306 |
+
"""Represents value as a list.
|
| 307 |
+
|
| 308 |
+
Value is split either by separator (defaults to comma) or by lines.
|
| 309 |
+
|
| 310 |
+
:param value:
|
| 311 |
+
:param separator: List items separator character.
|
| 312 |
+
:rtype: list
|
| 313 |
+
"""
|
| 314 |
+
if isinstance(value, list): # _get_parser_compound case
|
| 315 |
+
return value
|
| 316 |
+
|
| 317 |
+
if '\n' in value:
|
| 318 |
+
value = value.splitlines()
|
| 319 |
+
else:
|
| 320 |
+
value = value.split(separator)
|
| 321 |
+
|
| 322 |
+
return [chunk.strip() for chunk in value if chunk.strip()]
|
| 323 |
+
|
| 324 |
+
@classmethod
|
| 325 |
+
def _parse_dict(cls, value):
|
| 326 |
+
"""Represents value as a dict.
|
| 327 |
+
|
| 328 |
+
:param value:
|
| 329 |
+
:rtype: dict
|
| 330 |
+
"""
|
| 331 |
+
separator = '='
|
| 332 |
+
result = {}
|
| 333 |
+
for line in cls._parse_list(value):
|
| 334 |
+
key, sep, val = line.partition(separator)
|
| 335 |
+
if sep != separator:
|
| 336 |
+
raise OptionError(f"Unable to parse option value to dict: {value}")
|
| 337 |
+
result[key.strip()] = val.strip()
|
| 338 |
+
|
| 339 |
+
return result
|
| 340 |
+
|
| 341 |
+
@classmethod
|
| 342 |
+
def _parse_bool(cls, value):
|
| 343 |
+
"""Represents value as boolean.
|
| 344 |
+
|
| 345 |
+
:param value:
|
| 346 |
+
:rtype: bool
|
| 347 |
+
"""
|
| 348 |
+
value = value.lower()
|
| 349 |
+
return value in ('1', 'true', 'yes')
|
| 350 |
+
|
| 351 |
+
@classmethod
|
| 352 |
+
def _exclude_files_parser(cls, key):
|
| 353 |
+
"""Returns a parser function to make sure field inputs
|
| 354 |
+
are not files.
|
| 355 |
+
|
| 356 |
+
Parses a value after getting the key so error messages are
|
| 357 |
+
more informative.
|
| 358 |
+
|
| 359 |
+
:param key:
|
| 360 |
+
:rtype: callable
|
| 361 |
+
"""
|
| 362 |
+
|
| 363 |
+
def parser(value):
|
| 364 |
+
exclude_directive = 'file:'
|
| 365 |
+
if value.startswith(exclude_directive):
|
| 366 |
+
raise ValueError(
|
| 367 |
+
f'Only strings are accepted for the {key} field, '
|
| 368 |
+
'files are not accepted'
|
| 369 |
+
)
|
| 370 |
+
return _static.Str(value)
|
| 371 |
+
|
| 372 |
+
return parser
|
| 373 |
+
|
| 374 |
+
def _parse_file(self, value, root_dir: StrPath | None):
|
| 375 |
+
"""Represents value as a string, allowing including text
|
| 376 |
+
from nearest files using `file:` directive.
|
| 377 |
+
|
| 378 |
+
Directive is sandboxed and won't reach anything outside
|
| 379 |
+
directory with setup.py.
|
| 380 |
+
|
| 381 |
+
Examples:
|
| 382 |
+
file: README.rst, CHANGELOG.md, src/file.txt
|
| 383 |
+
|
| 384 |
+
:param str value:
|
| 385 |
+
:rtype: str
|
| 386 |
+
"""
|
| 387 |
+
include_directive = 'file:'
|
| 388 |
+
|
| 389 |
+
if not isinstance(value, str):
|
| 390 |
+
return value
|
| 391 |
+
|
| 392 |
+
if not value.startswith(include_directive):
|
| 393 |
+
return _static.Str(value)
|
| 394 |
+
|
| 395 |
+
spec = value[len(include_directive) :]
|
| 396 |
+
filepaths = [path.strip() for path in spec.split(',')]
|
| 397 |
+
self._referenced_files.update(filepaths)
|
| 398 |
+
# XXX: Is marking as static contents coming from files too optimistic?
|
| 399 |
+
return _static.Str(expand.read_files(filepaths, root_dir))
|
| 400 |
+
|
| 401 |
+
def _parse_attr(self, value, package_dir, root_dir: StrPath):
|
| 402 |
+
"""Represents value as a module attribute.
|
| 403 |
+
|
| 404 |
+
Examples:
|
| 405 |
+
attr: package.attr
|
| 406 |
+
attr: package.module.attr
|
| 407 |
+
|
| 408 |
+
:param str value:
|
| 409 |
+
:rtype: str
|
| 410 |
+
"""
|
| 411 |
+
attr_directive = 'attr:'
|
| 412 |
+
if not value.startswith(attr_directive):
|
| 413 |
+
return _static.Str(value)
|
| 414 |
+
|
| 415 |
+
attr_desc = value.replace(attr_directive, '')
|
| 416 |
+
|
| 417 |
+
# Make sure package_dir is populated correctly, so `attr:` directives can work
|
| 418 |
+
package_dir.update(self.ensure_discovered.package_dir)
|
| 419 |
+
return expand.read_attr(attr_desc, package_dir, root_dir)
|
| 420 |
+
|
| 421 |
+
@classmethod
|
| 422 |
+
def _get_parser_compound(cls, *parse_methods):
|
| 423 |
+
"""Returns parser function to represents value as a list.
|
| 424 |
+
|
| 425 |
+
Parses a value applying given methods one after another.
|
| 426 |
+
|
| 427 |
+
:param parse_methods:
|
| 428 |
+
:rtype: callable
|
| 429 |
+
"""
|
| 430 |
+
|
| 431 |
+
def parse(value):
|
| 432 |
+
parsed = value
|
| 433 |
+
|
| 434 |
+
for method in parse_methods:
|
| 435 |
+
parsed = method(parsed)
|
| 436 |
+
|
| 437 |
+
return parsed
|
| 438 |
+
|
| 439 |
+
return parse
|
| 440 |
+
|
| 441 |
+
@classmethod
|
| 442 |
+
def _parse_section_to_dict_with_key(cls, section_options, values_parser):
|
| 443 |
+
"""Parses section options into a dictionary.
|
| 444 |
+
|
| 445 |
+
Applies a given parser to each option in a section.
|
| 446 |
+
|
| 447 |
+
:param dict section_options:
|
| 448 |
+
:param callable values_parser: function with 2 args corresponding to key, value
|
| 449 |
+
:rtype: dict
|
| 450 |
+
"""
|
| 451 |
+
value = {}
|
| 452 |
+
for key, (_, val) in section_options.items():
|
| 453 |
+
value[key] = values_parser(key, val)
|
| 454 |
+
return value
|
| 455 |
+
|
| 456 |
+
@classmethod
|
| 457 |
+
def _parse_section_to_dict(cls, section_options, values_parser=None):
|
| 458 |
+
"""Parses section options into a dictionary.
|
| 459 |
+
|
| 460 |
+
Optionally applies a given parser to each value.
|
| 461 |
+
|
| 462 |
+
:param dict section_options:
|
| 463 |
+
:param callable values_parser: function with 1 arg corresponding to option value
|
| 464 |
+
:rtype: dict
|
| 465 |
+
"""
|
| 466 |
+
parser = (lambda _, v: values_parser(v)) if values_parser else (lambda _, v: v)
|
| 467 |
+
return cls._parse_section_to_dict_with_key(section_options, parser)
|
| 468 |
+
|
| 469 |
+
def parse_section(self, section_options) -> None:
|
| 470 |
+
"""Parses configuration file section.
|
| 471 |
+
|
| 472 |
+
:param dict section_options:
|
| 473 |
+
"""
|
| 474 |
+
for name, (_, value) in section_options.items():
|
| 475 |
+
with contextlib.suppress(KeyError):
|
| 476 |
+
# Keep silent for a new option may appear anytime.
|
| 477 |
+
self[name] = value
|
| 478 |
+
|
| 479 |
+
def parse(self) -> None:
|
| 480 |
+
"""Parses configuration file items from one
|
| 481 |
+
or more related sections.
|
| 482 |
+
|
| 483 |
+
"""
|
| 484 |
+
for section_name, section_options in self.sections.items():
|
| 485 |
+
method_postfix = ''
|
| 486 |
+
if section_name: # [section.option] variant
|
| 487 |
+
method_postfix = f"_{section_name}"
|
| 488 |
+
|
| 489 |
+
section_parser_method: Callable | None = getattr(
|
| 490 |
+
self,
|
| 491 |
+
# Dots in section names are translated into dunderscores.
|
| 492 |
+
f'parse_section{method_postfix}'.replace('.', '__'),
|
| 493 |
+
None,
|
| 494 |
+
)
|
| 495 |
+
|
| 496 |
+
if section_parser_method is None:
|
| 497 |
+
raise OptionError(
|
| 498 |
+
"Unsupported distribution option section: "
|
| 499 |
+
f"[{self.section_prefix}.{section_name}]"
|
| 500 |
+
)
|
| 501 |
+
|
| 502 |
+
section_parser_method(section_options)
|
| 503 |
+
|
| 504 |
+
def _deprecated_config_handler(self, func, msg, **kw):
|
| 505 |
+
"""this function will wrap around parameters that are deprecated
|
| 506 |
+
|
| 507 |
+
:param msg: deprecation message
|
| 508 |
+
:param func: function to be wrapped around
|
| 509 |
+
"""
|
| 510 |
+
|
| 511 |
+
@wraps(func)
|
| 512 |
+
def config_handler(*args, **kwargs):
|
| 513 |
+
kw.setdefault("stacklevel", 2)
|
| 514 |
+
_DeprecatedConfig.emit("Deprecated config in `setup.cfg`", msg, **kw)
|
| 515 |
+
return func(*args, **kwargs)
|
| 516 |
+
|
| 517 |
+
return config_handler
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
class ConfigMetadataHandler(ConfigHandler["DistributionMetadata"]):
|
| 521 |
+
section_prefix = 'metadata'
|
| 522 |
+
|
| 523 |
+
aliases = {
|
| 524 |
+
'home_page': 'url',
|
| 525 |
+
'summary': 'description',
|
| 526 |
+
'classifier': 'classifiers',
|
| 527 |
+
'platform': 'platforms',
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
strict_mode = False
|
| 531 |
+
"""We need to keep it loose, to be partially compatible with
|
| 532 |
+
`pbr` and `d2to1` packages which also uses `metadata` section.
|
| 533 |
+
|
| 534 |
+
"""
|
| 535 |
+
|
| 536 |
+
def __init__(
|
| 537 |
+
self,
|
| 538 |
+
target_obj: DistributionMetadata,
|
| 539 |
+
options: AllCommandOptions,
|
| 540 |
+
ignore_option_errors: bool,
|
| 541 |
+
ensure_discovered: expand.EnsurePackagesDiscovered,
|
| 542 |
+
package_dir: dict | None = None,
|
| 543 |
+
root_dir: StrPath | None = os.curdir,
|
| 544 |
+
) -> None:
|
| 545 |
+
super().__init__(target_obj, options, ignore_option_errors, ensure_discovered)
|
| 546 |
+
self.package_dir = package_dir
|
| 547 |
+
self.root_dir = root_dir
|
| 548 |
+
|
| 549 |
+
@property
|
| 550 |
+
def parsers(self):
|
| 551 |
+
"""Metadata item name to parser function mapping."""
|
| 552 |
+
parse_list_static = self._get_parser_compound(self._parse_list, _static.List)
|
| 553 |
+
parse_dict_static = self._get_parser_compound(self._parse_dict, _static.Dict)
|
| 554 |
+
parse_file = partial(self._parse_file, root_dir=self.root_dir)
|
| 555 |
+
exclude_files_parser = self._exclude_files_parser
|
| 556 |
+
|
| 557 |
+
return {
|
| 558 |
+
'author': _static.Str,
|
| 559 |
+
'author_email': _static.Str,
|
| 560 |
+
'maintainer': _static.Str,
|
| 561 |
+
'maintainer_email': _static.Str,
|
| 562 |
+
'platforms': parse_list_static,
|
| 563 |
+
'keywords': parse_list_static,
|
| 564 |
+
'provides': parse_list_static,
|
| 565 |
+
'obsoletes': parse_list_static,
|
| 566 |
+
'classifiers': self._get_parser_compound(parse_file, parse_list_static),
|
| 567 |
+
'license': exclude_files_parser('license'),
|
| 568 |
+
'license_files': parse_list_static,
|
| 569 |
+
'description': parse_file,
|
| 570 |
+
'long_description': parse_file,
|
| 571 |
+
'long_description_content_type': _static.Str,
|
| 572 |
+
'version': self._parse_version, # Cannot be marked as dynamic
|
| 573 |
+
'url': _static.Str,
|
| 574 |
+
'project_urls': parse_dict_static,
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
def _parse_version(self, value):
|
| 578 |
+
"""Parses `version` option value.
|
| 579 |
+
|
| 580 |
+
:param value:
|
| 581 |
+
:rtype: str
|
| 582 |
+
|
| 583 |
+
"""
|
| 584 |
+
version = self._parse_file(value, self.root_dir)
|
| 585 |
+
|
| 586 |
+
if version != value:
|
| 587 |
+
version = version.strip()
|
| 588 |
+
# Be strict about versions loaded from file because it's easy to
|
| 589 |
+
# accidentally include newlines and other unintended content
|
| 590 |
+
try:
|
| 591 |
+
Version(version)
|
| 592 |
+
except InvalidVersion as e:
|
| 593 |
+
raise OptionError(
|
| 594 |
+
f'Version loaded from {value} does not '
|
| 595 |
+
f'comply with PEP 440: {version}'
|
| 596 |
+
) from e
|
| 597 |
+
|
| 598 |
+
return version
|
| 599 |
+
|
| 600 |
+
return expand.version(self._parse_attr(value, self.package_dir, self.root_dir))
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
class ConfigOptionsHandler(ConfigHandler["Distribution"]):
|
| 604 |
+
section_prefix = 'options'
|
| 605 |
+
|
| 606 |
+
def __init__(
|
| 607 |
+
self,
|
| 608 |
+
target_obj: Distribution,
|
| 609 |
+
options: AllCommandOptions,
|
| 610 |
+
ignore_option_errors: bool,
|
| 611 |
+
ensure_discovered: expand.EnsurePackagesDiscovered,
|
| 612 |
+
) -> None:
|
| 613 |
+
super().__init__(target_obj, options, ignore_option_errors, ensure_discovered)
|
| 614 |
+
self.root_dir = target_obj.src_root
|
| 615 |
+
self.package_dir: dict[str, str] = {} # To be filled by `find_packages`
|
| 616 |
+
|
| 617 |
+
@classmethod
|
| 618 |
+
def _parse_list_semicolon(cls, value):
|
| 619 |
+
return cls._parse_list(value, separator=';')
|
| 620 |
+
|
| 621 |
+
def _parse_file_in_root(self, value):
|
| 622 |
+
return self._parse_file(value, root_dir=self.root_dir)
|
| 623 |
+
|
| 624 |
+
def _parse_requirements_list(self, label: str, value: str):
|
| 625 |
+
# Parse a requirements list, either by reading in a `file:`, or a list.
|
| 626 |
+
parsed = self._parse_list_semicolon(self._parse_file_in_root(value))
|
| 627 |
+
_warn_accidental_env_marker_misconfig(label, value, parsed)
|
| 628 |
+
# Filter it to only include lines that are not comments. `parse_list`
|
| 629 |
+
# will have stripped each line and filtered out empties.
|
| 630 |
+
return _static.List(line for line in parsed if not line.startswith("#"))
|
| 631 |
+
# ^-- Use `_static.List` to mark a non-`Dynamic` Core Metadata
|
| 632 |
+
|
| 633 |
+
@property
|
| 634 |
+
def parsers(self):
|
| 635 |
+
"""Metadata item name to parser function mapping."""
|
| 636 |
+
parse_list = self._parse_list
|
| 637 |
+
parse_bool = self._parse_bool
|
| 638 |
+
parse_cmdclass = self._parse_cmdclass
|
| 639 |
+
|
| 640 |
+
return {
|
| 641 |
+
'zip_safe': parse_bool,
|
| 642 |
+
'include_package_data': parse_bool,
|
| 643 |
+
'package_dir': self._parse_dict,
|
| 644 |
+
'scripts': parse_list,
|
| 645 |
+
'eager_resources': parse_list,
|
| 646 |
+
'dependency_links': parse_list,
|
| 647 |
+
'namespace_packages': self._deprecated_config_handler(
|
| 648 |
+
parse_list,
|
| 649 |
+
"The namespace_packages parameter is deprecated, "
|
| 650 |
+
"consider using implicit namespaces instead (PEP 420).",
|
| 651 |
+
# TODO: define due date, see setuptools.dist:check_nsp.
|
| 652 |
+
),
|
| 653 |
+
'install_requires': partial( # Core Metadata
|
| 654 |
+
self._parse_requirements_list, "install_requires"
|
| 655 |
+
),
|
| 656 |
+
'setup_requires': self._parse_list_semicolon,
|
| 657 |
+
'packages': self._parse_packages,
|
| 658 |
+
'entry_points': self._parse_file_in_root,
|
| 659 |
+
'py_modules': parse_list,
|
| 660 |
+
'python_requires': _static.SpecifierSet, # Core Metadata
|
| 661 |
+
'cmdclass': parse_cmdclass,
|
| 662 |
+
}
|
| 663 |
+
|
| 664 |
+
def _parse_cmdclass(self, value):
|
| 665 |
+
package_dir = self.ensure_discovered.package_dir
|
| 666 |
+
return expand.cmdclass(self._parse_dict(value), package_dir, self.root_dir)
|
| 667 |
+
|
| 668 |
+
def _parse_packages(self, value):
|
| 669 |
+
"""Parses `packages` option value.
|
| 670 |
+
|
| 671 |
+
:param value:
|
| 672 |
+
:rtype: list
|
| 673 |
+
"""
|
| 674 |
+
find_directives = ['find:', 'find_namespace:']
|
| 675 |
+
trimmed_value = value.strip()
|
| 676 |
+
|
| 677 |
+
if trimmed_value not in find_directives:
|
| 678 |
+
return self._parse_list(value)
|
| 679 |
+
|
| 680 |
+
# Read function arguments from a dedicated section.
|
| 681 |
+
find_kwargs = self.parse_section_packages__find(
|
| 682 |
+
self.sections.get('packages.find', {})
|
| 683 |
+
)
|
| 684 |
+
|
| 685 |
+
find_kwargs.update(
|
| 686 |
+
namespaces=(trimmed_value == find_directives[1]),
|
| 687 |
+
root_dir=self.root_dir,
|
| 688 |
+
fill_package_dir=self.package_dir,
|
| 689 |
+
)
|
| 690 |
+
|
| 691 |
+
return expand.find_packages(**find_kwargs)
|
| 692 |
+
|
| 693 |
+
def parse_section_packages__find(self, section_options):
|
| 694 |
+
"""Parses `packages.find` configuration file section.
|
| 695 |
+
|
| 696 |
+
To be used in conjunction with _parse_packages().
|
| 697 |
+
|
| 698 |
+
:param dict section_options:
|
| 699 |
+
"""
|
| 700 |
+
section_data = self._parse_section_to_dict(section_options, self._parse_list)
|
| 701 |
+
|
| 702 |
+
valid_keys = ['where', 'include', 'exclude']
|
| 703 |
+
find_kwargs = {k: v for k, v in section_data.items() if k in valid_keys and v}
|
| 704 |
+
|
| 705 |
+
where = find_kwargs.get('where')
|
| 706 |
+
if where is not None:
|
| 707 |
+
find_kwargs['where'] = where[0] # cast list to single val
|
| 708 |
+
|
| 709 |
+
return find_kwargs
|
| 710 |
+
|
| 711 |
+
def parse_section_entry_points(self, section_options) -> None:
|
| 712 |
+
"""Parses `entry_points` configuration file section.
|
| 713 |
+
|
| 714 |
+
:param dict section_options:
|
| 715 |
+
"""
|
| 716 |
+
parsed = self._parse_section_to_dict(section_options, self._parse_list)
|
| 717 |
+
self['entry_points'] = parsed
|
| 718 |
+
|
| 719 |
+
def _parse_package_data(self, section_options):
|
| 720 |
+
package_data = self._parse_section_to_dict(section_options, self._parse_list)
|
| 721 |
+
return expand.canonic_package_data(package_data)
|
| 722 |
+
|
| 723 |
+
def parse_section_package_data(self, section_options) -> None:
|
| 724 |
+
"""Parses `package_data` configuration file section.
|
| 725 |
+
|
| 726 |
+
:param dict section_options:
|
| 727 |
+
"""
|
| 728 |
+
self['package_data'] = self._parse_package_data(section_options)
|
| 729 |
+
|
| 730 |
+
def parse_section_exclude_package_data(self, section_options) -> None:
|
| 731 |
+
"""Parses `exclude_package_data` configuration file section.
|
| 732 |
+
|
| 733 |
+
:param dict section_options:
|
| 734 |
+
"""
|
| 735 |
+
self['exclude_package_data'] = self._parse_package_data(section_options)
|
| 736 |
+
|
| 737 |
+
def parse_section_extras_require(self, section_options) -> None: # Core Metadata
|
| 738 |
+
"""Parses `extras_require` configuration file section.
|
| 739 |
+
|
| 740 |
+
:param dict section_options:
|
| 741 |
+
"""
|
| 742 |
+
parsed = self._parse_section_to_dict_with_key(
|
| 743 |
+
section_options,
|
| 744 |
+
lambda k, v: self._parse_requirements_list(f"extras_require[{k}]", v),
|
| 745 |
+
)
|
| 746 |
+
|
| 747 |
+
self['extras_require'] = _static.Dict(parsed)
|
| 748 |
+
# ^-- Use `_static.Dict` to mark a non-`Dynamic` Core Metadata
|
| 749 |
+
|
| 750 |
+
def parse_section_data_files(self, section_options) -> None:
|
| 751 |
+
"""Parses `data_files` configuration file section.
|
| 752 |
+
|
| 753 |
+
:param dict section_options:
|
| 754 |
+
"""
|
| 755 |
+
parsed = self._parse_section_to_dict(section_options, self._parse_list)
|
| 756 |
+
self['data_files'] = expand.canonic_data_files(parsed, self.root_dir)
|
| 757 |
+
|
| 758 |
+
|
| 759 |
+
class _AmbiguousMarker(SetuptoolsDeprecationWarning):
|
| 760 |
+
_SUMMARY = "Ambiguous requirement marker."
|
| 761 |
+
_DETAILS = """
|
| 762 |
+
One of the parsed requirements in `{field}` looks like a valid environment marker:
|
| 763 |
+
|
| 764 |
+
{req!r}
|
| 765 |
+
|
| 766 |
+
Please make sure that the configuration file is correct.
|
| 767 |
+
You can use dangling lines to avoid this problem.
|
| 768 |
+
"""
|
| 769 |
+
_SEE_DOCS = "userguide/declarative_config.html#opt-2"
|
| 770 |
+
# TODO: should we include due_date here? Initially introduced in 6 Aug 2022.
|
| 771 |
+
# Does this make sense with latest version of packaging?
|
| 772 |
+
|
| 773 |
+
@classmethod
|
| 774 |
+
def message(cls, **kw):
|
| 775 |
+
docs = f"https://setuptools.pypa.io/en/latest/{cls._SEE_DOCS}"
|
| 776 |
+
return cls._format(cls._SUMMARY, cls._DETAILS, see_url=docs, format_args=kw)
|
| 777 |
+
|
| 778 |
+
|
| 779 |
+
class _DeprecatedConfig(SetuptoolsDeprecationWarning):
|
| 780 |
+
_SEE_DOCS = "userguide/declarative_config.html"
|
videollama2/lib/python3.10/site-packages/setuptools/config/setuptools.schema.json
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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project_config.html",
|
| 5 |
+
"title": "``tool.setuptools`` table",
|
| 6 |
+
"$$description": [
|
| 7 |
+
"``setuptools``-specific configurations that can be set by users that require",
|
| 8 |
+
"customization.",
|
| 9 |
+
"These configurations are completely optional and probably can be skipped when",
|
| 10 |
+
"creating simple packages. They are equivalent to some of the `Keywords",
|
| 11 |
+
"<https://setuptools.pypa.io/en/latest/references/keywords.html>`_",
|
| 12 |
+
"used by the ``setup.py`` file, and can be set via the ``tool.setuptools`` table.",
|
| 13 |
+
"It considers only ``setuptools`` `parameters",
|
| 14 |
+
"<https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#setuptools-specific-configuration>`_",
|
| 15 |
+
"that are not covered by :pep:`621`; and intentionally excludes ``dependency_links``",
|
| 16 |
+
"and ``setup_requires`` (incompatible with modern workflows/standards)."
|
| 17 |
+
],
|
| 18 |
+
|
| 19 |
+
"type": "object",
|
| 20 |
+
"additionalProperties": false,
|
| 21 |
+
"properties": {
|
| 22 |
+
"platforms": {
|
| 23 |
+
"type": "array",
|
| 24 |
+
"items": {"type": "string"}
|
| 25 |
+
},
|
| 26 |
+
"provides": {
|
| 27 |
+
"$$description": [
|
| 28 |
+
"Package and virtual package names contained within this package",
|
| 29 |
+
"**(not supported by pip)**"
|
| 30 |
+
],
|
| 31 |
+
"type": "array",
|
| 32 |
+
"items": {"type": "string", "format": "pep508-identifier"}
|
| 33 |
+
},
|
| 34 |
+
"obsoletes": {
|
| 35 |
+
"$$description": [
|
| 36 |
+
"Packages which this package renders obsolete",
|
| 37 |
+
"**(not supported by pip)**"
|
| 38 |
+
],
|
| 39 |
+
"type": "array",
|
| 40 |
+
"items": {"type": "string", "format": "pep508-identifier"}
|
| 41 |
+
},
|
| 42 |
+
"zip-safe": {
|
| 43 |
+
"$$description": [
|
| 44 |
+
"Whether the project can be safely installed and run from a zip file.",
|
| 45 |
+
"**OBSOLETE**: only relevant for ``pkg_resources``, ``easy_install`` and",
|
| 46 |
+
"``setup.py install`` in the context of ``eggs`` (**DEPRECATED**)."
|
| 47 |
+
],
|
| 48 |
+
"type": "boolean"
|
| 49 |
+
},
|
| 50 |
+
"script-files": {
|
| 51 |
+
"$$description": [
|
| 52 |
+
"Legacy way of defining scripts (entry-points are preferred).",
|
| 53 |
+
"Equivalent to the ``script`` keyword in ``setup.py``",
|
| 54 |
+
"(it was renamed to avoid confusion with entry-point based ``project.scripts``",
|
| 55 |
+
"defined in :pep:`621`).",
|
| 56 |
+
"**DISCOURAGED**: generic script wrappers are tricky and may not work properly.",
|
| 57 |
+
"Whenever possible, please use ``project.scripts`` instead."
|
| 58 |
+
],
|
| 59 |
+
"type": "array",
|
| 60 |
+
"items": {"type": "string"},
|
| 61 |
+
"$comment": "TODO: is this field deprecated/should be removed?"
|
| 62 |
+
},
|
| 63 |
+
"eager-resources": {
|
| 64 |
+
"$$description": [
|
| 65 |
+
"Resources that should be extracted together, if any of them is needed,",
|
| 66 |
+
"or if any C extensions included in the project are imported.",
|
| 67 |
+
"**OBSOLETE**: only relevant for ``pkg_resources``, ``easy_install`` and",
|
| 68 |
+
"``setup.py install`` in the context of ``eggs`` (**DEPRECATED**)."
|
| 69 |
+
],
|
| 70 |
+
"type": "array",
|
| 71 |
+
"items": {"type": "string"}
|
| 72 |
+
},
|
| 73 |
+
"packages": {
|
| 74 |
+
"$$description": [
|
| 75 |
+
"Packages that should be included in the distribution.",
|
| 76 |
+
"It can be given either as a list of package identifiers",
|
| 77 |
+
"or as a ``dict``-like structure with a single key ``find``",
|
| 78 |
+
"which corresponds to a dynamic call to",
|
| 79 |
+
"``setuptools.config.expand.find_packages`` function.",
|
| 80 |
+
"The ``find`` key is associated with a nested ``dict``-like structure that can",
|
| 81 |
+
"contain ``where``, ``include``, ``exclude`` and ``namespaces`` keys,",
|
| 82 |
+
"mimicking the keyword arguments of the associated function."
|
| 83 |
+
],
|
| 84 |
+
"oneOf": [
|
| 85 |
+
{
|
| 86 |
+
"title": "Array of Python package identifiers",
|
| 87 |
+
"type": "array",
|
| 88 |
+
"items": {"$ref": "#/definitions/package-name"}
|
| 89 |
+
},
|
| 90 |
+
{"$ref": "#/definitions/find-directive"}
|
| 91 |
+
]
|
| 92 |
+
},
|
| 93 |
+
"package-dir": {
|
| 94 |
+
"$$description": [
|
| 95 |
+
":class:`dict`-like structure mapping from package names to directories where their",
|
| 96 |
+
"code can be found.",
|
| 97 |
+
"The empty string (as key) means that all packages are contained inside",
|
| 98 |
+
"the given directory will be included in the distribution."
|
| 99 |
+
],
|
| 100 |
+
"type": "object",
|
| 101 |
+
"additionalProperties": false,
|
| 102 |
+
"propertyNames": {
|
| 103 |
+
"anyOf": [{"const": ""}, {"$ref": "#/definitions/package-name"}]
|
| 104 |
+
},
|
| 105 |
+
"patternProperties": {
|
| 106 |
+
"^.*$": {"type": "string" }
|
| 107 |
+
}
|
| 108 |
+
},
|
| 109 |
+
"package-data": {
|
| 110 |
+
"$$description": [
|
| 111 |
+
"Mapping from package names to lists of glob patterns.",
|
| 112 |
+
"Usually this option is not needed when using ``include-package-data = true``",
|
| 113 |
+
"For more information on how to include data files, check ``setuptools`` `docs",
|
| 114 |
+
"<https://setuptools.pypa.io/en/latest/userguide/datafiles.html>`_."
|
| 115 |
+
],
|
| 116 |
+
"type": "object",
|
| 117 |
+
"additionalProperties": false,
|
| 118 |
+
"propertyNames": {
|
| 119 |
+
"anyOf": [{"type": "string", "format": "python-module-name"}, {"const": "*"}]
|
| 120 |
+
},
|
| 121 |
+
"patternProperties": {
|
| 122 |
+
"^.*$": {"type": "array", "items": {"type": "string"}}
|
| 123 |
+
}
|
| 124 |
+
},
|
| 125 |
+
"include-package-data": {
|
| 126 |
+
"$$description": [
|
| 127 |
+
"Automatically include any data files inside the package directories",
|
| 128 |
+
"that are specified by ``MANIFEST.in``",
|
| 129 |
+
"For more information on how to include data files, check ``setuptools`` `docs",
|
| 130 |
+
"<https://setuptools.pypa.io/en/latest/userguide/datafiles.html>`_."
|
| 131 |
+
],
|
| 132 |
+
"type": "boolean"
|
| 133 |
+
},
|
| 134 |
+
"exclude-package-data": {
|
| 135 |
+
"$$description": [
|
| 136 |
+
"Mapping from package names to lists of glob patterns that should be excluded",
|
| 137 |
+
"For more information on how to include data files, check ``setuptools`` `docs",
|
| 138 |
+
"<https://setuptools.pypa.io/en/latest/userguide/datafiles.html>`_."
|
| 139 |
+
],
|
| 140 |
+
"type": "object",
|
| 141 |
+
"additionalProperties": false,
|
| 142 |
+
"propertyNames": {
|
| 143 |
+
"anyOf": [{"type": "string", "format": "python-module-name"}, {"const": "*"}]
|
| 144 |
+
},
|
| 145 |
+
"patternProperties": {
|
| 146 |
+
"^.*$": {"type": "array", "items": {"type": "string"}}
|
| 147 |
+
}
|
| 148 |
+
},
|
| 149 |
+
"namespace-packages": {
|
| 150 |
+
"type": "array",
|
| 151 |
+
"items": {"type": "string", "format": "python-module-name-relaxed"},
|
| 152 |
+
"$comment": "https://setuptools.pypa.io/en/latest/userguide/package_discovery.html",
|
| 153 |
+
"description": "**DEPRECATED**: use implicit namespaces instead (:pep:`420`)."
|
| 154 |
+
},
|
| 155 |
+
"py-modules": {
|
| 156 |
+
"description": "Modules that setuptools will manipulate",
|
| 157 |
+
"type": "array",
|
| 158 |
+
"items": {"type": "string", "format": "python-module-name-relaxed"},
|
| 159 |
+
"$comment": "TODO: clarify the relationship with ``packages``"
|
| 160 |
+
},
|
| 161 |
+
"ext-modules": {
|
| 162 |
+
"description": "Extension modules to be compiled by setuptools",
|
| 163 |
+
"type": "array",
|
| 164 |
+
"items": {"$ref": "#/definitions/ext-module"}
|
| 165 |
+
},
|
| 166 |
+
"data-files": {
|
| 167 |
+
"$$description": [
|
| 168 |
+
"``dict``-like structure where each key represents a directory and",
|
| 169 |
+
"the value is a list of glob patterns that should be installed in them.",
|
| 170 |
+
"**DISCOURAGED**: please notice this might not work as expected with wheels.",
|
| 171 |
+
"Whenever possible, consider using data files inside the package directories",
|
| 172 |
+
"(or create a new namespace package that only contains data files).",
|
| 173 |
+
"See `data files support",
|
| 174 |
+
"<https://setuptools.pypa.io/en/latest/userguide/datafiles.html>`_."
|
| 175 |
+
],
|
| 176 |
+
"type": "object",
|
| 177 |
+
"patternProperties": {
|
| 178 |
+
"^.*$": {"type": "array", "items": {"type": "string"}}
|
| 179 |
+
}
|
| 180 |
+
},
|
| 181 |
+
"cmdclass": {
|
| 182 |
+
"$$description": [
|
| 183 |
+
"Mapping of distutils-style command names to ``setuptools.Command`` subclasses",
|
| 184 |
+
"which in turn should be represented by strings with a qualified class name",
|
| 185 |
+
"(i.e., \"dotted\" form with module), e.g.::\n\n",
|
| 186 |
+
" cmdclass = {mycmd = \"pkg.subpkg.module.CommandClass\"}\n\n",
|
| 187 |
+
"The command class should be a directly defined at the top-level of the",
|
| 188 |
+
"containing module (no class nesting)."
|
| 189 |
+
],
|
| 190 |
+
"type": "object",
|
| 191 |
+
"patternProperties": {
|
| 192 |
+
"^.*$": {"type": "string", "format": "python-qualified-identifier"}
|
| 193 |
+
}
|
| 194 |
+
},
|
| 195 |
+
"license-files": {
|
| 196 |
+
"type": "array",
|
| 197 |
+
"items": {"type": "string"},
|
| 198 |
+
"$$description": [
|
| 199 |
+
"**PROVISIONAL**: list of glob patterns for all license files being distributed.",
|
| 200 |
+
"(likely to become standard with :pep:`639`).",
|
| 201 |
+
"By default: ``['LICEN[CS]E*', 'COPYING*', 'NOTICE*', 'AUTHORS*']``"
|
| 202 |
+
],
|
| 203 |
+
"$comment": "TODO: revise if PEP 639 is accepted. Probably ``project.license-files``?"
|
| 204 |
+
},
|
| 205 |
+
"dynamic": {
|
| 206 |
+
"type": "object",
|
| 207 |
+
"description": "Instructions for loading :pep:`621`-related metadata dynamically",
|
| 208 |
+
"additionalProperties": false,
|
| 209 |
+
"properties": {
|
| 210 |
+
"version": {
|
| 211 |
+
"$$description": [
|
| 212 |
+
"A version dynamically loaded via either the ``attr:`` or ``file:``",
|
| 213 |
+
"directives. Please make sure the given file or attribute respects :pep:`440`.",
|
| 214 |
+
"Also ensure to set ``project.dynamic`` accordingly."
|
| 215 |
+
],
|
| 216 |
+
"oneOf": [
|
| 217 |
+
{"$ref": "#/definitions/attr-directive"},
|
| 218 |
+
{"$ref": "#/definitions/file-directive"}
|
| 219 |
+
]
|
| 220 |
+
},
|
| 221 |
+
"classifiers": {"$ref": "#/definitions/file-directive"},
|
| 222 |
+
"description": {"$ref": "#/definitions/file-directive"},
|
| 223 |
+
"entry-points": {"$ref": "#/definitions/file-directive"},
|
| 224 |
+
"dependencies": {"$ref": "#/definitions/file-directive-for-dependencies"},
|
| 225 |
+
"optional-dependencies": {
|
| 226 |
+
"type": "object",
|
| 227 |
+
"propertyNames": {"type": "string", "format": "pep508-identifier"},
|
| 228 |
+
"additionalProperties": false,
|
| 229 |
+
"patternProperties": {
|
| 230 |
+
".+": {"$ref": "#/definitions/file-directive-for-dependencies"}
|
| 231 |
+
}
|
| 232 |
+
},
|
| 233 |
+
"readme": {
|
| 234 |
+
"type": "object",
|
| 235 |
+
"anyOf": [
|
| 236 |
+
{"$ref": "#/definitions/file-directive"},
|
| 237 |
+
{
|
| 238 |
+
"type": "object",
|
| 239 |
+
"properties": {
|
| 240 |
+
"content-type": {"type": "string"},
|
| 241 |
+
"file": { "$ref": "#/definitions/file-directive/properties/file" }
|
| 242 |
+
},
|
| 243 |
+
"additionalProperties": false}
|
| 244 |
+
],
|
| 245 |
+
"required": ["file"]
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
},
|
| 250 |
+
|
| 251 |
+
"definitions": {
|
| 252 |
+
"package-name": {
|
| 253 |
+
"$id": "#/definitions/package-name",
|
| 254 |
+
"title": "Valid package name",
|
| 255 |
+
"description": "Valid package name (importable or :pep:`561`).",
|
| 256 |
+
"type": "string",
|
| 257 |
+
"anyOf": [
|
| 258 |
+
{"type": "string", "format": "python-module-name-relaxed"},
|
| 259 |
+
{"type": "string", "format": "pep561-stub-name"}
|
| 260 |
+
]
|
| 261 |
+
},
|
| 262 |
+
"ext-module": {
|
| 263 |
+
"$id": "#/definitions/ext-module",
|
| 264 |
+
"title": "Extension module",
|
| 265 |
+
"description": "Parameters to construct a :class:`setuptools.Extension` object",
|
| 266 |
+
"type": "object",
|
| 267 |
+
"required": ["name", "sources"],
|
| 268 |
+
"additionalProperties": false,
|
| 269 |
+
"properties": {
|
| 270 |
+
"name": {
|
| 271 |
+
"type": "string",
|
| 272 |
+
"format": "python-module-name-relaxed"
|
| 273 |
+
},
|
| 274 |
+
"sources": {
|
| 275 |
+
"type": "array",
|
| 276 |
+
"items": {"type": "string"}
|
| 277 |
+
},
|
| 278 |
+
"include-dirs":{
|
| 279 |
+
"type": "array",
|
| 280 |
+
"items": {"type": "string"}
|
| 281 |
+
},
|
| 282 |
+
"define-macros": {
|
| 283 |
+
"type": "array",
|
| 284 |
+
"items": {
|
| 285 |
+
"type": "array",
|
| 286 |
+
"items": [
|
| 287 |
+
{"description": "macro name", "type": "string"},
|
| 288 |
+
{"description": "macro value", "oneOf": [{"type": "string"}, {"type": "null"}]}
|
| 289 |
+
],
|
| 290 |
+
"additionalItems": false
|
| 291 |
+
}
|
| 292 |
+
},
|
| 293 |
+
"undef-macros": {
|
| 294 |
+
"type": "array",
|
| 295 |
+
"items": {"type": "string"}
|
| 296 |
+
},
|
| 297 |
+
"library-dirs": {
|
| 298 |
+
"type": "array",
|
| 299 |
+
"items": {"type": "string"}
|
| 300 |
+
},
|
| 301 |
+
"libraries": {
|
| 302 |
+
"type": "array",
|
| 303 |
+
"items": {"type": "string"}
|
| 304 |
+
},
|
| 305 |
+
"runtime-library-dirs": {
|
| 306 |
+
"type": "array",
|
| 307 |
+
"items": {"type": "string"}
|
| 308 |
+
},
|
| 309 |
+
"extra-objects": {
|
| 310 |
+
"type": "array",
|
| 311 |
+
"items": {"type": "string"}
|
| 312 |
+
},
|
| 313 |
+
"extra-compile-args": {
|
| 314 |
+
"type": "array",
|
| 315 |
+
"items": {"type": "string"}
|
| 316 |
+
},
|
| 317 |
+
"extra-link-args": {
|
| 318 |
+
"type": "array",
|
| 319 |
+
"items": {"type": "string"}
|
| 320 |
+
},
|
| 321 |
+
"export-symbols": {
|
| 322 |
+
"type": "array",
|
| 323 |
+
"items": {"type": "string"}
|
| 324 |
+
},
|
| 325 |
+
"swig-opts": {
|
| 326 |
+
"type": "array",
|
| 327 |
+
"items": {"type": "string"}
|
| 328 |
+
},
|
| 329 |
+
"depends": {
|
| 330 |
+
"type": "array",
|
| 331 |
+
"items": {"type": "string"}
|
| 332 |
+
},
|
| 333 |
+
"language": {"type": "string"},
|
| 334 |
+
"optional": {"type": "boolean"},
|
| 335 |
+
"py-limited-api": {"type": "boolean"}
|
| 336 |
+
}
|
| 337 |
+
},
|
| 338 |
+
"file-directive": {
|
| 339 |
+
"$id": "#/definitions/file-directive",
|
| 340 |
+
"title": "'file:' directive",
|
| 341 |
+
"description":
|
| 342 |
+
"Value is read from a file (or list of files and then concatenated)",
|
| 343 |
+
"type": "object",
|
| 344 |
+
"additionalProperties": false,
|
| 345 |
+
"properties": {
|
| 346 |
+
"file": {
|
| 347 |
+
"oneOf": [
|
| 348 |
+
{"type": "string"},
|
| 349 |
+
{"type": "array", "items": {"type": "string"}}
|
| 350 |
+
]
|
| 351 |
+
}
|
| 352 |
+
},
|
| 353 |
+
"required": ["file"]
|
| 354 |
+
},
|
| 355 |
+
"file-directive-for-dependencies": {
|
| 356 |
+
"title": "'file:' directive for dependencies",
|
| 357 |
+
"allOf": [
|
| 358 |
+
{
|
| 359 |
+
"$$description": [
|
| 360 |
+
"**BETA**: subset of the ``requirements.txt`` format",
|
| 361 |
+
"without ``pip`` flags and options",
|
| 362 |
+
"(one :pep:`508`-compliant string per line,",
|
| 363 |
+
"lines that are blank or start with ``#`` are excluded).",
|
| 364 |
+
"See `dynamic metadata",
|
| 365 |
+
"<https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata>`_."
|
| 366 |
+
]
|
| 367 |
+
},
|
| 368 |
+
{"$ref": "#/definitions/file-directive"}
|
| 369 |
+
]
|
| 370 |
+
},
|
| 371 |
+
"attr-directive": {
|
| 372 |
+
"title": "'attr:' directive",
|
| 373 |
+
"$id": "#/definitions/attr-directive",
|
| 374 |
+
"$$description": [
|
| 375 |
+
"Value is read from a module attribute. Supports callables and iterables;",
|
| 376 |
+
"unsupported types are cast via ``str()``"
|
| 377 |
+
],
|
| 378 |
+
"type": "object",
|
| 379 |
+
"additionalProperties": false,
|
| 380 |
+
"properties": {
|
| 381 |
+
"attr": {"type": "string", "format": "python-qualified-identifier"}
|
| 382 |
+
},
|
| 383 |
+
"required": ["attr"]
|
| 384 |
+
},
|
| 385 |
+
"find-directive": {
|
| 386 |
+
"$id": "#/definitions/find-directive",
|
| 387 |
+
"title": "'find:' directive",
|
| 388 |
+
"type": "object",
|
| 389 |
+
"additionalProperties": false,
|
| 390 |
+
"properties": {
|
| 391 |
+
"find": {
|
| 392 |
+
"type": "object",
|
| 393 |
+
"$$description": [
|
| 394 |
+
"Dynamic `package discovery",
|
| 395 |
+
"<https://setuptools.pypa.io/en/latest/userguide/package_discovery.html>`_."
|
| 396 |
+
],
|
| 397 |
+
"additionalProperties": false,
|
| 398 |
+
"properties": {
|
| 399 |
+
"where": {
|
| 400 |
+
"description":
|
| 401 |
+
"Directories to be searched for packages (Unix-style relative path)",
|
| 402 |
+
"type": "array",
|
| 403 |
+
"items": {"type": "string"}
|
| 404 |
+
},
|
| 405 |
+
"exclude": {
|
| 406 |
+
"type": "array",
|
| 407 |
+
"$$description": [
|
| 408 |
+
"Exclude packages that match the values listed in this field.",
|
| 409 |
+
"Can container shell-style wildcards (e.g. ``'pkg.*'``)"
|
| 410 |
+
],
|
| 411 |
+
"items": {"type": "string"}
|
| 412 |
+
},
|
| 413 |
+
"include": {
|
| 414 |
+
"type": "array",
|
| 415 |
+
"$$description": [
|
| 416 |
+
"Restrict the found packages to just the ones listed in this field.",
|
| 417 |
+
"Can container shell-style wildcards (e.g. ``'pkg.*'``)"
|
| 418 |
+
],
|
| 419 |
+
"items": {"type": "string"}
|
| 420 |
+
},
|
| 421 |
+
"namespaces": {
|
| 422 |
+
"type": "boolean",
|
| 423 |
+
"$$description": [
|
| 424 |
+
"When ``True``, directories without a ``__init__.py`` file will also",
|
| 425 |
+
"be scanned for :pep:`420`-style implicit namespaces"
|
| 426 |
+
]
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
}
|
videollama2/lib/python3.10/site-packages/setuptools/depends.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import contextlib
|
| 4 |
+
import dis
|
| 5 |
+
import marshal
|
| 6 |
+
import sys
|
| 7 |
+
from types import CodeType
|
| 8 |
+
from typing import Any, Literal, TypeVar
|
| 9 |
+
|
| 10 |
+
from packaging.version import Version
|
| 11 |
+
|
| 12 |
+
from . import _imp
|
| 13 |
+
from ._imp import PY_COMPILED, PY_FROZEN, PY_SOURCE, find_module
|
| 14 |
+
|
| 15 |
+
_T = TypeVar("_T")
|
| 16 |
+
|
| 17 |
+
__all__ = ['Require', 'find_module']
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class Require:
|
| 21 |
+
"""A prerequisite to building or installing a distribution"""
|
| 22 |
+
|
| 23 |
+
def __init__(
|
| 24 |
+
self,
|
| 25 |
+
name,
|
| 26 |
+
requested_version,
|
| 27 |
+
module,
|
| 28 |
+
homepage: str = '',
|
| 29 |
+
attribute=None,
|
| 30 |
+
format=None,
|
| 31 |
+
) -> None:
|
| 32 |
+
if format is None and requested_version is not None:
|
| 33 |
+
format = Version
|
| 34 |
+
|
| 35 |
+
if format is not None:
|
| 36 |
+
requested_version = format(requested_version)
|
| 37 |
+
if attribute is None:
|
| 38 |
+
attribute = '__version__'
|
| 39 |
+
|
| 40 |
+
self.__dict__.update(locals())
|
| 41 |
+
del self.self
|
| 42 |
+
|
| 43 |
+
def full_name(self):
|
| 44 |
+
"""Return full package/distribution name, w/version"""
|
| 45 |
+
if self.requested_version is not None:
|
| 46 |
+
return f'{self.name}-{self.requested_version}'
|
| 47 |
+
return self.name
|
| 48 |
+
|
| 49 |
+
def version_ok(self, version):
|
| 50 |
+
"""Is 'version' sufficiently up-to-date?"""
|
| 51 |
+
return (
|
| 52 |
+
self.attribute is None
|
| 53 |
+
or self.format is None
|
| 54 |
+
or str(version) != "unknown"
|
| 55 |
+
and self.format(version) >= self.requested_version
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
def get_version(
|
| 59 |
+
self, paths=None, default: _T | Literal["unknown"] = "unknown"
|
| 60 |
+
) -> _T | Literal["unknown"] | None | Any:
|
| 61 |
+
"""Get version number of installed module, 'None', or 'default'
|
| 62 |
+
|
| 63 |
+
Search 'paths' for module. If not found, return 'None'. If found,
|
| 64 |
+
return the extracted version attribute, or 'default' if no version
|
| 65 |
+
attribute was specified, or the value cannot be determined without
|
| 66 |
+
importing the module. The version is formatted according to the
|
| 67 |
+
requirement's version format (if any), unless it is 'None' or the
|
| 68 |
+
supplied 'default'.
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
if self.attribute is None:
|
| 72 |
+
try:
|
| 73 |
+
f, _p, _i = find_module(self.module, paths)
|
| 74 |
+
except ImportError:
|
| 75 |
+
return None
|
| 76 |
+
if f:
|
| 77 |
+
f.close()
|
| 78 |
+
return default
|
| 79 |
+
|
| 80 |
+
v = get_module_constant(self.module, self.attribute, default, paths)
|
| 81 |
+
|
| 82 |
+
if v is not None and v is not default and self.format is not None:
|
| 83 |
+
return self.format(v)
|
| 84 |
+
|
| 85 |
+
return v
|
| 86 |
+
|
| 87 |
+
def is_present(self, paths=None):
|
| 88 |
+
"""Return true if dependency is present on 'paths'"""
|
| 89 |
+
return self.get_version(paths) is not None
|
| 90 |
+
|
| 91 |
+
def is_current(self, paths=None):
|
| 92 |
+
"""Return true if dependency is present and up-to-date on 'paths'"""
|
| 93 |
+
version = self.get_version(paths)
|
| 94 |
+
if version is None:
|
| 95 |
+
return False
|
| 96 |
+
return self.version_ok(str(version))
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def maybe_close(f):
|
| 100 |
+
@contextlib.contextmanager
|
| 101 |
+
def empty():
|
| 102 |
+
yield
|
| 103 |
+
return
|
| 104 |
+
|
| 105 |
+
if not f:
|
| 106 |
+
return empty()
|
| 107 |
+
|
| 108 |
+
return contextlib.closing(f)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# Some objects are not available on some platforms.
|
| 112 |
+
# XXX it'd be better to test assertions about bytecode instead.
|
| 113 |
+
if not sys.platform.startswith('java') and sys.platform != 'cli':
|
| 114 |
+
|
| 115 |
+
def get_module_constant(
|
| 116 |
+
module, symbol, default: _T | int = -1, paths=None
|
| 117 |
+
) -> _T | int | None | Any:
|
| 118 |
+
"""Find 'module' by searching 'paths', and extract 'symbol'
|
| 119 |
+
|
| 120 |
+
Return 'None' if 'module' does not exist on 'paths', or it does not define
|
| 121 |
+
'symbol'. If the module defines 'symbol' as a constant, return the
|
| 122 |
+
constant. Otherwise, return 'default'."""
|
| 123 |
+
|
| 124 |
+
try:
|
| 125 |
+
f, path, (_suffix, _mode, kind) = info = find_module(module, paths)
|
| 126 |
+
except ImportError:
|
| 127 |
+
# Module doesn't exist
|
| 128 |
+
return None
|
| 129 |
+
|
| 130 |
+
with maybe_close(f):
|
| 131 |
+
if kind == PY_COMPILED:
|
| 132 |
+
f.read(8) # skip magic & date
|
| 133 |
+
code = marshal.load(f)
|
| 134 |
+
elif kind == PY_FROZEN:
|
| 135 |
+
code = _imp.get_frozen_object(module, paths)
|
| 136 |
+
elif kind == PY_SOURCE:
|
| 137 |
+
code = compile(f.read(), path, 'exec')
|
| 138 |
+
else:
|
| 139 |
+
# Not something we can parse; we'll have to import it. :(
|
| 140 |
+
imported = _imp.get_module(module, paths, info)
|
| 141 |
+
return getattr(imported, symbol, None)
|
| 142 |
+
|
| 143 |
+
return extract_constant(code, symbol, default)
|
| 144 |
+
|
| 145 |
+
def extract_constant(
|
| 146 |
+
code: CodeType, symbol: str, default: _T | int = -1
|
| 147 |
+
) -> _T | int | None | Any:
|
| 148 |
+
"""Extract the constant value of 'symbol' from 'code'
|
| 149 |
+
|
| 150 |
+
If the name 'symbol' is bound to a constant value by the Python code
|
| 151 |
+
object 'code', return that value. If 'symbol' is bound to an expression,
|
| 152 |
+
return 'default'. Otherwise, return 'None'.
|
| 153 |
+
|
| 154 |
+
Return value is based on the first assignment to 'symbol'. 'symbol' must
|
| 155 |
+
be a global, or at least a non-"fast" local in the code block. That is,
|
| 156 |
+
only 'STORE_NAME' and 'STORE_GLOBAL' opcodes are checked, and 'symbol'
|
| 157 |
+
must be present in 'code.co_names'.
|
| 158 |
+
"""
|
| 159 |
+
if symbol not in code.co_names:
|
| 160 |
+
# name's not there, can't possibly be an assignment
|
| 161 |
+
return None
|
| 162 |
+
|
| 163 |
+
name_idx = list(code.co_names).index(symbol)
|
| 164 |
+
|
| 165 |
+
STORE_NAME = dis.opmap['STORE_NAME']
|
| 166 |
+
STORE_GLOBAL = dis.opmap['STORE_GLOBAL']
|
| 167 |
+
LOAD_CONST = dis.opmap['LOAD_CONST']
|
| 168 |
+
|
| 169 |
+
const = default
|
| 170 |
+
|
| 171 |
+
for byte_code in dis.Bytecode(code):
|
| 172 |
+
op = byte_code.opcode
|
| 173 |
+
arg = byte_code.arg
|
| 174 |
+
|
| 175 |
+
if op == LOAD_CONST:
|
| 176 |
+
assert arg is not None
|
| 177 |
+
const = code.co_consts[arg]
|
| 178 |
+
elif arg == name_idx and (op == STORE_NAME or op == STORE_GLOBAL):
|
| 179 |
+
return const
|
| 180 |
+
else:
|
| 181 |
+
const = default
|
| 182 |
+
|
| 183 |
+
return None
|
| 184 |
+
|
| 185 |
+
__all__ += ['get_module_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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Automatic discovery of Python modules and packages (for inclusion in the
|
| 2 |
+
distribution) and other config values.
|
| 3 |
+
|
| 4 |
+
For the purposes of this module, the following nomenclature is used:
|
| 5 |
+
|
| 6 |
+
- "src-layout": a directory representing a Python project that contains a "src"
|
| 7 |
+
folder. Everything under the "src" folder is meant to be included in the
|
| 8 |
+
distribution when packaging the project. Example::
|
| 9 |
+
|
| 10 |
+
.
|
| 11 |
+
├── tox.ini
|
| 12 |
+
├── pyproject.toml
|
| 13 |
+
└── src/
|
| 14 |
+
└── mypkg/
|
| 15 |
+
├── __init__.py
|
| 16 |
+
├── mymodule.py
|
| 17 |
+
└── my_data_file.txt
|
| 18 |
+
|
| 19 |
+
- "flat-layout": a Python project that does not use "src-layout" but instead
|
| 20 |
+
have a directory under the project root for each package::
|
| 21 |
+
|
| 22 |
+
.
|
| 23 |
+
├── tox.ini
|
| 24 |
+
├── pyproject.toml
|
| 25 |
+
└── mypkg/
|
| 26 |
+
├── __init__.py
|
| 27 |
+
├── mymodule.py
|
| 28 |
+
└── my_data_file.txt
|
| 29 |
+
|
| 30 |
+
- "single-module": a project that contains a single Python script direct under
|
| 31 |
+
the project root (no directory used)::
|
| 32 |
+
|
| 33 |
+
.
|
| 34 |
+
├── tox.ini
|
| 35 |
+
├── pyproject.toml
|
| 36 |
+
└── mymodule.py
|
| 37 |
+
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
from __future__ import annotations
|
| 41 |
+
|
| 42 |
+
import itertools
|
| 43 |
+
import os
|
| 44 |
+
from collections.abc import Iterable, Iterator, Mapping
|
| 45 |
+
from fnmatch import fnmatchcase
|
| 46 |
+
from glob import glob
|
| 47 |
+
from pathlib import Path
|
| 48 |
+
from typing import TYPE_CHECKING, ClassVar
|
| 49 |
+
|
| 50 |
+
import _distutils_hack.override # noqa: F401
|
| 51 |
+
|
| 52 |
+
from ._path import StrPath
|
| 53 |
+
|
| 54 |
+
from distutils import log
|
| 55 |
+
from distutils.util import convert_path
|
| 56 |
+
|
| 57 |
+
if TYPE_CHECKING:
|
| 58 |
+
from setuptools import Distribution
|
| 59 |
+
|
| 60 |
+
chain_iter = itertools.chain.from_iterable
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def _valid_name(path: StrPath) -> bool:
|
| 64 |
+
# Ignore invalid names that cannot be imported directly
|
| 65 |
+
return os.path.basename(path).isidentifier()
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class _Filter:
|
| 69 |
+
"""
|
| 70 |
+
Given a list of patterns, create a callable that will be true only if
|
| 71 |
+
the input matches at least one of the patterns.
|
| 72 |
+
"""
|
| 73 |
+
|
| 74 |
+
def __init__(self, *patterns: str) -> None:
|
| 75 |
+
self._patterns = dict.fromkeys(patterns)
|
| 76 |
+
|
| 77 |
+
def __call__(self, item: str) -> bool:
|
| 78 |
+
return any(fnmatchcase(item, pat) for pat in self._patterns)
|
| 79 |
+
|
| 80 |
+
def __contains__(self, item: str) -> bool:
|
| 81 |
+
return item in self._patterns
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class _Finder:
|
| 85 |
+
"""Base class that exposes functionality for module/package finders"""
|
| 86 |
+
|
| 87 |
+
ALWAYS_EXCLUDE: ClassVar[tuple[str, ...]] = ()
|
| 88 |
+
DEFAULT_EXCLUDE: ClassVar[tuple[str, ...]] = ()
|
| 89 |
+
|
| 90 |
+
@classmethod
|
| 91 |
+
def find(
|
| 92 |
+
cls,
|
| 93 |
+
where: StrPath = '.',
|
| 94 |
+
exclude: Iterable[str] = (),
|
| 95 |
+
include: Iterable[str] = ('*',),
|
| 96 |
+
) -> list[str]:
|
| 97 |
+
"""Return a list of all Python items (packages or modules, depending on
|
| 98 |
+
the finder implementation) found within directory 'where'.
|
| 99 |
+
|
| 100 |
+
'where' is the root directory which will be searched.
|
| 101 |
+
It should be supplied as a "cross-platform" (i.e. URL-style) path;
|
| 102 |
+
it will be converted to the appropriate local path syntax.
|
| 103 |
+
|
| 104 |
+
'exclude' is a sequence of names to exclude; '*' can be used
|
| 105 |
+
as a wildcard in the names.
|
| 106 |
+
When finding packages, 'foo.*' will exclude all subpackages of 'foo'
|
| 107 |
+
(but not 'foo' itself).
|
| 108 |
+
|
| 109 |
+
'include' is a sequence of names to include.
|
| 110 |
+
If it's specified, only the named items will be included.
|
| 111 |
+
If it's not specified, all found items will be included.
|
| 112 |
+
'include' can contain shell style wildcard patterns just like
|
| 113 |
+
'exclude'.
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
exclude = exclude or cls.DEFAULT_EXCLUDE
|
| 117 |
+
return list(
|
| 118 |
+
cls._find_iter(
|
| 119 |
+
convert_path(str(where)),
|
| 120 |
+
_Filter(*cls.ALWAYS_EXCLUDE, *exclude),
|
| 121 |
+
_Filter(*include),
|
| 122 |
+
)
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
@classmethod
|
| 126 |
+
def _find_iter(
|
| 127 |
+
cls, where: StrPath, exclude: _Filter, include: _Filter
|
| 128 |
+
) -> Iterator[str]:
|
| 129 |
+
raise NotImplementedError
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
class PackageFinder(_Finder):
|
| 133 |
+
"""
|
| 134 |
+
Generate a list of all Python packages found within a directory
|
| 135 |
+
"""
|
| 136 |
+
|
| 137 |
+
ALWAYS_EXCLUDE = ("ez_setup", "*__pycache__")
|
| 138 |
+
|
| 139 |
+
@classmethod
|
| 140 |
+
def _find_iter(
|
| 141 |
+
cls, where: StrPath, exclude: _Filter, include: _Filter
|
| 142 |
+
) -> Iterator[str]:
|
| 143 |
+
"""
|
| 144 |
+
All the packages found in 'where' that pass the 'include' filter, but
|
| 145 |
+
not the 'exclude' filter.
|
| 146 |
+
"""
|
| 147 |
+
for root, dirs, files in os.walk(str(where), followlinks=True):
|
| 148 |
+
# Copy dirs to iterate over it, then empty dirs.
|
| 149 |
+
all_dirs = dirs[:]
|
| 150 |
+
dirs[:] = []
|
| 151 |
+
|
| 152 |
+
for dir in all_dirs:
|
| 153 |
+
full_path = os.path.join(root, dir)
|
| 154 |
+
rel_path = os.path.relpath(full_path, where)
|
| 155 |
+
package = rel_path.replace(os.path.sep, '.')
|
| 156 |
+
|
| 157 |
+
# Skip directory trees that are not valid packages
|
| 158 |
+
if '.' in dir or not cls._looks_like_package(full_path, package):
|
| 159 |
+
continue
|
| 160 |
+
|
| 161 |
+
# Should this package be included?
|
| 162 |
+
if include(package) and not exclude(package):
|
| 163 |
+
yield package
|
| 164 |
+
|
| 165 |
+
# Early pruning if there is nothing else to be scanned
|
| 166 |
+
if f"{package}*" in exclude or f"{package}.*" in exclude:
|
| 167 |
+
continue
|
| 168 |
+
|
| 169 |
+
# Keep searching subdirectories, as there may be more packages
|
| 170 |
+
# down there, even if the parent was excluded.
|
| 171 |
+
dirs.append(dir)
|
| 172 |
+
|
| 173 |
+
@staticmethod
|
| 174 |
+
def _looks_like_package(path: StrPath, _package_name: str) -> bool:
|
| 175 |
+
"""Does a directory look like a package?"""
|
| 176 |
+
return os.path.isfile(os.path.join(path, '__init__.py'))
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
class PEP420PackageFinder(PackageFinder):
|
| 180 |
+
@staticmethod
|
| 181 |
+
def _looks_like_package(_path: StrPath, _package_name: str) -> bool:
|
| 182 |
+
return True
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
class ModuleFinder(_Finder):
|
| 186 |
+
"""Find isolated Python modules.
|
| 187 |
+
This function will **not** recurse subdirectories.
|
| 188 |
+
"""
|
| 189 |
+
|
| 190 |
+
@classmethod
|
| 191 |
+
def _find_iter(
|
| 192 |
+
cls, where: StrPath, exclude: _Filter, include: _Filter
|
| 193 |
+
) -> Iterator[str]:
|
| 194 |
+
for file in glob(os.path.join(where, "*.py")):
|
| 195 |
+
module, _ext = os.path.splitext(os.path.basename(file))
|
| 196 |
+
|
| 197 |
+
if not cls._looks_like_module(module):
|
| 198 |
+
continue
|
| 199 |
+
|
| 200 |
+
if include(module) and not exclude(module):
|
| 201 |
+
yield module
|
| 202 |
+
|
| 203 |
+
_looks_like_module = staticmethod(_valid_name)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
# We have to be extra careful in the case of flat layout to not include files
|
| 207 |
+
# and directories not meant for distribution (e.g. tool-related)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
class FlatLayoutPackageFinder(PEP420PackageFinder):
|
| 211 |
+
_EXCLUDE = (
|
| 212 |
+
"ci",
|
| 213 |
+
"bin",
|
| 214 |
+
"debian",
|
| 215 |
+
"doc",
|
| 216 |
+
"docs",
|
| 217 |
+
"documentation",
|
| 218 |
+
"manpages",
|
| 219 |
+
"news",
|
| 220 |
+
"newsfragments",
|
| 221 |
+
"changelog",
|
| 222 |
+
"test",
|
| 223 |
+
"tests",
|
| 224 |
+
"unit_test",
|
| 225 |
+
"unit_tests",
|
| 226 |
+
"example",
|
| 227 |
+
"examples",
|
| 228 |
+
"scripts",
|
| 229 |
+
"tools",
|
| 230 |
+
"util",
|
| 231 |
+
"utils",
|
| 232 |
+
"python",
|
| 233 |
+
"build",
|
| 234 |
+
"dist",
|
| 235 |
+
"venv",
|
| 236 |
+
"env",
|
| 237 |
+
"requirements",
|
| 238 |
+
# ---- Task runners / Build tools ----
|
| 239 |
+
"tasks", # invoke
|
| 240 |
+
"fabfile", # fabric
|
| 241 |
+
"site_scons", # SCons
|
| 242 |
+
# ---- Other tools ----
|
| 243 |
+
"benchmark",
|
| 244 |
+
"benchmarks",
|
| 245 |
+
"exercise",
|
| 246 |
+
"exercises",
|
| 247 |
+
"htmlcov", # Coverage.py
|
| 248 |
+
# ---- Hidden directories/Private packages ----
|
| 249 |
+
"[._]*",
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
DEFAULT_EXCLUDE = tuple(chain_iter((p, f"{p}.*") for p in _EXCLUDE))
|
| 253 |
+
"""Reserved package names"""
|
| 254 |
+
|
| 255 |
+
@staticmethod
|
| 256 |
+
def _looks_like_package(_path: StrPath, package_name: str) -> bool:
|
| 257 |
+
names = package_name.split('.')
|
| 258 |
+
# Consider PEP 561
|
| 259 |
+
root_pkg_is_valid = names[0].isidentifier() or names[0].endswith("-stubs")
|
| 260 |
+
return root_pkg_is_valid and all(name.isidentifier() for name in names[1:])
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
class FlatLayoutModuleFinder(ModuleFinder):
|
| 264 |
+
DEFAULT_EXCLUDE = (
|
| 265 |
+
"setup",
|
| 266 |
+
"conftest",
|
| 267 |
+
"test",
|
| 268 |
+
"tests",
|
| 269 |
+
"example",
|
| 270 |
+
"examples",
|
| 271 |
+
"build",
|
| 272 |
+
# ---- Task runners ----
|
| 273 |
+
"toxfile",
|
| 274 |
+
"noxfile",
|
| 275 |
+
"pavement",
|
| 276 |
+
"dodo",
|
| 277 |
+
"tasks",
|
| 278 |
+
"fabfile",
|
| 279 |
+
# ---- Other tools ----
|
| 280 |
+
"[Ss][Cc]onstruct", # SCons
|
| 281 |
+
"conanfile", # Connan: C/C++ build tool
|
| 282 |
+
"manage", # Django
|
| 283 |
+
"benchmark",
|
| 284 |
+
"benchmarks",
|
| 285 |
+
"exercise",
|
| 286 |
+
"exercises",
|
| 287 |
+
# ---- Hidden files/Private modules ----
|
| 288 |
+
"[._]*",
|
| 289 |
+
)
|
| 290 |
+
"""Reserved top-level module names"""
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def _find_packages_within(root_pkg: str, pkg_dir: StrPath) -> list[str]:
|
| 294 |
+
nested = PEP420PackageFinder.find(pkg_dir)
|
| 295 |
+
return [root_pkg] + [".".join((root_pkg, n)) for n in nested]
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
class ConfigDiscovery:
|
| 299 |
+
"""Fill-in metadata and options that can be automatically derived
|
| 300 |
+
(from other metadata/options, the file system or conventions)
|
| 301 |
+
"""
|
| 302 |
+
|
| 303 |
+
def __init__(self, distribution: Distribution) -> None:
|
| 304 |
+
self.dist = distribution
|
| 305 |
+
self._called = False
|
| 306 |
+
self._disabled = False
|
| 307 |
+
self._skip_ext_modules = False
|
| 308 |
+
|
| 309 |
+
def _disable(self):
|
| 310 |
+
"""Internal API to disable automatic discovery"""
|
| 311 |
+
self._disabled = True
|
| 312 |
+
|
| 313 |
+
def _ignore_ext_modules(self):
|
| 314 |
+
"""Internal API to disregard ext_modules.
|
| 315 |
+
|
| 316 |
+
Normally auto-discovery would not be triggered if ``ext_modules`` are set
|
| 317 |
+
(this is done for backward compatibility with existing packages relying on
|
| 318 |
+
``setup.py`` or ``setup.cfg``). However, ``setuptools`` can call this function
|
| 319 |
+
to ignore given ``ext_modules`` and proceed with the auto-discovery if
|
| 320 |
+
``packages`` and ``py_modules`` are not given (e.g. when using pyproject.toml
|
| 321 |
+
metadata).
|
| 322 |
+
"""
|
| 323 |
+
self._skip_ext_modules = True
|
| 324 |
+
|
| 325 |
+
@property
|
| 326 |
+
def _root_dir(self) -> StrPath:
|
| 327 |
+
# The best is to wait until `src_root` is set in dist, before using _root_dir.
|
| 328 |
+
return self.dist.src_root or os.curdir
|
| 329 |
+
|
| 330 |
+
@property
|
| 331 |
+
def _package_dir(self) -> dict[str, str]:
|
| 332 |
+
if self.dist.package_dir is None:
|
| 333 |
+
return {}
|
| 334 |
+
return self.dist.package_dir
|
| 335 |
+
|
| 336 |
+
def __call__(
|
| 337 |
+
self, force: bool = False, name: bool = True, ignore_ext_modules: bool = False
|
| 338 |
+
):
|
| 339 |
+
"""Automatically discover missing configuration fields
|
| 340 |
+
and modifies the given ``distribution`` object in-place.
|
| 341 |
+
|
| 342 |
+
Note that by default this will only have an effect the first time the
|
| 343 |
+
``ConfigDiscovery`` object is called.
|
| 344 |
+
|
| 345 |
+
To repeatedly invoke automatic discovery (e.g. when the project
|
| 346 |
+
directory changes), please use ``force=True`` (or create a new
|
| 347 |
+
``ConfigDiscovery`` instance).
|
| 348 |
+
"""
|
| 349 |
+
if force is False and (self._called or self._disabled):
|
| 350 |
+
# Avoid overhead of multiple calls
|
| 351 |
+
return
|
| 352 |
+
|
| 353 |
+
self._analyse_package_layout(ignore_ext_modules)
|
| 354 |
+
if name:
|
| 355 |
+
self.analyse_name() # depends on ``packages`` and ``py_modules``
|
| 356 |
+
|
| 357 |
+
self._called = True
|
| 358 |
+
|
| 359 |
+
def _explicitly_specified(self, ignore_ext_modules: bool) -> bool:
|
| 360 |
+
"""``True`` if the user has specified some form of package/module listing"""
|
| 361 |
+
ignore_ext_modules = ignore_ext_modules or self._skip_ext_modules
|
| 362 |
+
ext_modules = not (self.dist.ext_modules is None or ignore_ext_modules)
|
| 363 |
+
return (
|
| 364 |
+
self.dist.packages is not None
|
| 365 |
+
or self.dist.py_modules is not None
|
| 366 |
+
or ext_modules
|
| 367 |
+
or hasattr(self.dist, "configuration")
|
| 368 |
+
and self.dist.configuration
|
| 369 |
+
# ^ Some projects use numpy.distutils.misc_util.Configuration
|
| 370 |
+
)
|
| 371 |
+
|
| 372 |
+
def _analyse_package_layout(self, ignore_ext_modules: bool) -> bool:
|
| 373 |
+
if self._explicitly_specified(ignore_ext_modules):
|
| 374 |
+
# For backward compatibility, just try to find modules/packages
|
| 375 |
+
# when nothing is given
|
| 376 |
+
return True
|
| 377 |
+
|
| 378 |
+
log.debug(
|
| 379 |
+
"No `packages` or `py_modules` configuration, performing "
|
| 380 |
+
"automatic discovery."
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
return (
|
| 384 |
+
self._analyse_explicit_layout()
|
| 385 |
+
or self._analyse_src_layout()
|
| 386 |
+
# flat-layout is the trickiest for discovery so it should be last
|
| 387 |
+
or self._analyse_flat_layout()
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
def _analyse_explicit_layout(self) -> bool:
|
| 391 |
+
"""The user can explicitly give a package layout via ``package_dir``"""
|
| 392 |
+
package_dir = self._package_dir.copy() # don't modify directly
|
| 393 |
+
package_dir.pop("", None) # This falls under the "src-layout" umbrella
|
| 394 |
+
root_dir = self._root_dir
|
| 395 |
+
|
| 396 |
+
if not package_dir:
|
| 397 |
+
return False
|
| 398 |
+
|
| 399 |
+
log.debug(f"`explicit-layout` detected -- analysing {package_dir}")
|
| 400 |
+
pkgs = chain_iter(
|
| 401 |
+
_find_packages_within(pkg, os.path.join(root_dir, parent_dir))
|
| 402 |
+
for pkg, parent_dir in package_dir.items()
|
| 403 |
+
)
|
| 404 |
+
self.dist.packages = list(pkgs)
|
| 405 |
+
log.debug(f"discovered packages -- {self.dist.packages}")
|
| 406 |
+
return True
|
| 407 |
+
|
| 408 |
+
def _analyse_src_layout(self) -> bool:
|
| 409 |
+
"""Try to find all packages or modules under the ``src`` directory
|
| 410 |
+
(or anything pointed by ``package_dir[""]``).
|
| 411 |
+
|
| 412 |
+
The "src-layout" is relatively safe for automatic discovery.
|
| 413 |
+
We assume that everything within is meant to be included in the
|
| 414 |
+
distribution.
|
| 415 |
+
|
| 416 |
+
If ``package_dir[""]`` is not given, but the ``src`` directory exists,
|
| 417 |
+
this function will set ``package_dir[""] = "src"``.
|
| 418 |
+
"""
|
| 419 |
+
package_dir = self._package_dir
|
| 420 |
+
src_dir = os.path.join(self._root_dir, package_dir.get("", "src"))
|
| 421 |
+
if not os.path.isdir(src_dir):
|
| 422 |
+
return False
|
| 423 |
+
|
| 424 |
+
log.debug(f"`src-layout` detected -- analysing {src_dir}")
|
| 425 |
+
package_dir.setdefault("", os.path.basename(src_dir))
|
| 426 |
+
self.dist.package_dir = package_dir # persist eventual modifications
|
| 427 |
+
self.dist.packages = PEP420PackageFinder.find(src_dir)
|
| 428 |
+
self.dist.py_modules = ModuleFinder.find(src_dir)
|
| 429 |
+
log.debug(f"discovered packages -- {self.dist.packages}")
|
| 430 |
+
log.debug(f"discovered py_modules -- {self.dist.py_modules}")
|
| 431 |
+
return True
|
| 432 |
+
|
| 433 |
+
def _analyse_flat_layout(self) -> bool:
|
| 434 |
+
"""Try to find all packages and modules under the project root.
|
| 435 |
+
|
| 436 |
+
Since the ``flat-layout`` is more dangerous in terms of accidentally including
|
| 437 |
+
extra files/directories, this function is more conservative and will raise an
|
| 438 |
+
error if multiple packages or modules are found.
|
| 439 |
+
|
| 440 |
+
This assumes that multi-package dists are uncommon and refuse to support that
|
| 441 |
+
use case in order to be able to prevent unintended errors.
|
| 442 |
+
"""
|
| 443 |
+
log.debug(f"`flat-layout` detected -- analysing {self._root_dir}")
|
| 444 |
+
return self._analyse_flat_packages() or self._analyse_flat_modules()
|
| 445 |
+
|
| 446 |
+
def _analyse_flat_packages(self) -> bool:
|
| 447 |
+
self.dist.packages = FlatLayoutPackageFinder.find(self._root_dir)
|
| 448 |
+
top_level = remove_nested_packages(remove_stubs(self.dist.packages))
|
| 449 |
+
log.debug(f"discovered packages -- {self.dist.packages}")
|
| 450 |
+
self._ensure_no_accidental_inclusion(top_level, "packages")
|
| 451 |
+
return bool(top_level)
|
| 452 |
+
|
| 453 |
+
def _analyse_flat_modules(self) -> bool:
|
| 454 |
+
self.dist.py_modules = FlatLayoutModuleFinder.find(self._root_dir)
|
| 455 |
+
log.debug(f"discovered py_modules -- {self.dist.py_modules}")
|
| 456 |
+
self._ensure_no_accidental_inclusion(self.dist.py_modules, "modules")
|
| 457 |
+
return bool(self.dist.py_modules)
|
| 458 |
+
|
| 459 |
+
def _ensure_no_accidental_inclusion(self, detected: list[str], kind: str):
|
| 460 |
+
if len(detected) > 1:
|
| 461 |
+
from inspect import cleandoc
|
| 462 |
+
|
| 463 |
+
from setuptools.errors import PackageDiscoveryError
|
| 464 |
+
|
| 465 |
+
msg = f"""Multiple top-level {kind} discovered in a flat-layout: {detected}.
|
| 466 |
+
|
| 467 |
+
To avoid accidental inclusion of unwanted files or directories,
|
| 468 |
+
setuptools will not proceed with this build.
|
| 469 |
+
|
| 470 |
+
If you are trying to create a single distribution with multiple {kind}
|
| 471 |
+
on purpose, you should not rely on automatic discovery.
|
| 472 |
+
Instead, consider the following options:
|
| 473 |
+
|
| 474 |
+
1. set up custom discovery (`find` directive with `include` or `exclude`)
|
| 475 |
+
2. use a `src-layout`
|
| 476 |
+
3. explicitly set `py_modules` or `packages` with a list of names
|
| 477 |
+
|
| 478 |
+
To find more information, look for "package discovery" on setuptools docs.
|
| 479 |
+
"""
|
| 480 |
+
raise PackageDiscoveryError(cleandoc(msg))
|
| 481 |
+
|
| 482 |
+
def analyse_name(self) -> None:
|
| 483 |
+
"""The packages/modules are the essential contribution of the author.
|
| 484 |
+
Therefore the name of the distribution can be derived from them.
|
| 485 |
+
"""
|
| 486 |
+
if self.dist.metadata.name or self.dist.name:
|
| 487 |
+
# get_name() is not reliable (can return "UNKNOWN")
|
| 488 |
+
return
|
| 489 |
+
|
| 490 |
+
log.debug("No `name` configuration, performing automatic discovery")
|
| 491 |
+
|
| 492 |
+
name = (
|
| 493 |
+
self._find_name_single_package_or_module()
|
| 494 |
+
or self._find_name_from_packages()
|
| 495 |
+
)
|
| 496 |
+
if name:
|
| 497 |
+
self.dist.metadata.name = name
|
| 498 |
+
|
| 499 |
+
def _find_name_single_package_or_module(self) -> str | None:
|
| 500 |
+
"""Exactly one module or package"""
|
| 501 |
+
for field in ('packages', 'py_modules'):
|
| 502 |
+
items = getattr(self.dist, field, None) or []
|
| 503 |
+
if items and len(items) == 1:
|
| 504 |
+
log.debug(f"Single module/package detected, name: {items[0]}")
|
| 505 |
+
return items[0]
|
| 506 |
+
|
| 507 |
+
return None
|
| 508 |
+
|
| 509 |
+
def _find_name_from_packages(self) -> str | None:
|
| 510 |
+
"""Try to find the root package that is not a PEP 420 namespace"""
|
| 511 |
+
if not self.dist.packages:
|
| 512 |
+
return None
|
| 513 |
+
|
| 514 |
+
packages = remove_stubs(sorted(self.dist.packages, key=len))
|
| 515 |
+
package_dir = self.dist.package_dir or {}
|
| 516 |
+
|
| 517 |
+
parent_pkg = find_parent_package(packages, package_dir, self._root_dir)
|
| 518 |
+
if parent_pkg:
|
| 519 |
+
log.debug(f"Common parent package detected, name: {parent_pkg}")
|
| 520 |
+
return parent_pkg
|
| 521 |
+
|
| 522 |
+
log.warn("No parent package detected, impossible to derive `name`")
|
| 523 |
+
return None
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
def remove_nested_packages(packages: list[str]) -> list[str]:
|
| 527 |
+
"""Remove nested packages from a list of packages.
|
| 528 |
+
|
| 529 |
+
>>> remove_nested_packages(["a", "a.b1", "a.b2", "a.b1.c1"])
|
| 530 |
+
['a']
|
| 531 |
+
>>> remove_nested_packages(["a", "b", "c.d", "c.d.e.f", "g.h", "a.a1"])
|
| 532 |
+
['a', 'b', 'c.d', 'g.h']
|
| 533 |
+
"""
|
| 534 |
+
pkgs = sorted(packages, key=len)
|
| 535 |
+
top_level = pkgs[:]
|
| 536 |
+
size = len(pkgs)
|
| 537 |
+
for i, name in enumerate(reversed(pkgs)):
|
| 538 |
+
if any(name.startswith(f"{other}.") for other in top_level):
|
| 539 |
+
top_level.pop(size - i - 1)
|
| 540 |
+
|
| 541 |
+
return top_level
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
def remove_stubs(packages: list[str]) -> list[str]:
|
| 545 |
+
"""Remove type stubs (:pep:`561`) from a list of packages.
|
| 546 |
+
|
| 547 |
+
>>> remove_stubs(["a", "a.b", "a-stubs", "a-stubs.b.c", "b", "c-stubs"])
|
| 548 |
+
['a', 'a.b', 'b']
|
| 549 |
+
"""
|
| 550 |
+
return [pkg for pkg in packages if not pkg.split(".")[0].endswith("-stubs")]
|
| 551 |
+
|
| 552 |
+
|
| 553 |
+
def find_parent_package(
|
| 554 |
+
packages: list[str], package_dir: Mapping[str, str], root_dir: StrPath
|
| 555 |
+
) -> str | None:
|
| 556 |
+
"""Find the parent package that is not a namespace."""
|
| 557 |
+
packages = sorted(packages, key=len)
|
| 558 |
+
common_ancestors = []
|
| 559 |
+
for i, name in enumerate(packages):
|
| 560 |
+
if not all(n.startswith(f"{name}.") for n in packages[i + 1 :]):
|
| 561 |
+
# Since packages are sorted by length, this condition is able
|
| 562 |
+
# to find a list of all common ancestors.
|
| 563 |
+
# When there is divergence (e.g. multiple root packages)
|
| 564 |
+
# the list will be empty
|
| 565 |
+
break
|
| 566 |
+
common_ancestors.append(name)
|
| 567 |
+
|
| 568 |
+
for name in common_ancestors:
|
| 569 |
+
pkg_path = find_package_path(name, package_dir, root_dir)
|
| 570 |
+
init = os.path.join(pkg_path, "__init__.py")
|
| 571 |
+
if os.path.isfile(init):
|
| 572 |
+
return name
|
| 573 |
+
|
| 574 |
+
return None
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
def find_package_path(
|
| 578 |
+
name: str, package_dir: Mapping[str, str], root_dir: StrPath
|
| 579 |
+
) -> str:
|
| 580 |
+
"""Given a package name, return the path where it should be found on
|
| 581 |
+
disk, considering the ``package_dir`` option.
|
| 582 |
+
|
| 583 |
+
>>> path = find_package_path("my.pkg", {"": "root/is/nested"}, ".")
|
| 584 |
+
>>> path.replace(os.sep, "/")
|
| 585 |
+
'./root/is/nested/my/pkg'
|
| 586 |
+
|
| 587 |
+
>>> path = find_package_path("my.pkg", {"my": "root/is/nested"}, ".")
|
| 588 |
+
>>> path.replace(os.sep, "/")
|
| 589 |
+
'./root/is/nested/pkg'
|
| 590 |
+
|
| 591 |
+
>>> path = find_package_path("my.pkg", {"my.pkg": "root/is/nested"}, ".")
|
| 592 |
+
>>> path.replace(os.sep, "/")
|
| 593 |
+
'./root/is/nested'
|
| 594 |
+
|
| 595 |
+
>>> path = find_package_path("other.pkg", {"my.pkg": "root/is/nested"}, ".")
|
| 596 |
+
>>> path.replace(os.sep, "/")
|
| 597 |
+
'./other/pkg'
|
| 598 |
+
"""
|
| 599 |
+
parts = name.split(".")
|
| 600 |
+
for i in range(len(parts), 0, -1):
|
| 601 |
+
# Look backwards, the most specific package_dir first
|
| 602 |
+
partial_name = ".".join(parts[:i])
|
| 603 |
+
if partial_name in package_dir:
|
| 604 |
+
parent = package_dir[partial_name]
|
| 605 |
+
return os.path.join(root_dir, parent, *parts[i:])
|
| 606 |
+
|
| 607 |
+
parent = package_dir.get("") or ""
|
| 608 |
+
return os.path.join(root_dir, *parent.split("/"), *parts)
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
def construct_package_dir(packages: list[str], package_path: StrPath) -> dict[str, str]:
|
| 612 |
+
parent_pkgs = remove_nested_packages(packages)
|
| 613 |
+
prefix = Path(package_path).parts
|
| 614 |
+
return {pkg: "/".join([*prefix, *pkg.split(".")]) for pkg in parent_pkgs}
|
videollama2/lib/python3.10/site-packages/setuptools/dist.py
ADDED
|
@@ -0,0 +1,1004 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import io
|
| 4 |
+
import itertools
|
| 5 |
+
import numbers
|
| 6 |
+
import os
|
| 7 |
+
import re
|
| 8 |
+
import sys
|
| 9 |
+
from collections.abc import Iterable, MutableMapping, Sequence
|
| 10 |
+
from glob import iglob
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import TYPE_CHECKING, Any, Union
|
| 13 |
+
|
| 14 |
+
from more_itertools import partition, unique_everseen
|
| 15 |
+
from packaging.markers import InvalidMarker, Marker
|
| 16 |
+
from packaging.specifiers import InvalidSpecifier, SpecifierSet
|
| 17 |
+
from packaging.version import Version
|
| 18 |
+
|
| 19 |
+
from . import (
|
| 20 |
+
_entry_points,
|
| 21 |
+
_reqs,
|
| 22 |
+
_static,
|
| 23 |
+
command as _, # noqa: F401 # imported for side-effects
|
| 24 |
+
)
|
| 25 |
+
from ._importlib import metadata
|
| 26 |
+
from ._path import StrPath
|
| 27 |
+
from ._reqs import _StrOrIter
|
| 28 |
+
from .config import pyprojecttoml, setupcfg
|
| 29 |
+
from .discovery import ConfigDiscovery
|
| 30 |
+
from .monkey import get_unpatched
|
| 31 |
+
from .warnings import InformationOnly, SetuptoolsDeprecationWarning
|
| 32 |
+
|
| 33 |
+
import distutils.cmd
|
| 34 |
+
import distutils.command
|
| 35 |
+
import distutils.core
|
| 36 |
+
import distutils.dist
|
| 37 |
+
import distutils.log
|
| 38 |
+
from distutils.debug import DEBUG
|
| 39 |
+
from distutils.errors import DistutilsOptionError, DistutilsSetupError
|
| 40 |
+
from distutils.fancy_getopt import translate_longopt
|
| 41 |
+
from distutils.util import strtobool
|
| 42 |
+
|
| 43 |
+
if TYPE_CHECKING:
|
| 44 |
+
from typing_extensions import TypeAlias
|
| 45 |
+
|
| 46 |
+
from pkg_resources import Distribution as _pkg_resources_Distribution
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
__all__ = ['Distribution']
|
| 50 |
+
|
| 51 |
+
_sequence = tuple, list
|
| 52 |
+
"""
|
| 53 |
+
:meta private:
|
| 54 |
+
|
| 55 |
+
Supported iterable types that are known to be:
|
| 56 |
+
- ordered (which `set` isn't)
|
| 57 |
+
- not match a str (which `Sequence[str]` does)
|
| 58 |
+
- not imply a nested type (like `dict`)
|
| 59 |
+
for use with `isinstance`.
|
| 60 |
+
"""
|
| 61 |
+
_Sequence: TypeAlias = Union[tuple[str, ...], list[str]]
|
| 62 |
+
# This is how stringifying _Sequence would look in Python 3.10
|
| 63 |
+
_sequence_type_repr = "tuple[str, ...] | list[str]"
|
| 64 |
+
_OrderedStrSequence: TypeAlias = Union[str, dict[str, Any], Sequence[str]]
|
| 65 |
+
"""
|
| 66 |
+
:meta private:
|
| 67 |
+
Avoid single-use iterable. Disallow sets.
|
| 68 |
+
A poor approximation of an OrderedSequence (dict doesn't match a Sequence).
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def __getattr__(name: str) -> Any: # pragma: no cover
|
| 73 |
+
if name == "sequence":
|
| 74 |
+
SetuptoolsDeprecationWarning.emit(
|
| 75 |
+
"`setuptools.dist.sequence` is an internal implementation detail.",
|
| 76 |
+
"Please define your own `sequence = tuple, list` instead.",
|
| 77 |
+
due_date=(2025, 8, 28), # Originally added on 2024-08-27
|
| 78 |
+
)
|
| 79 |
+
return _sequence
|
| 80 |
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def check_importable(dist, attr, value):
|
| 84 |
+
try:
|
| 85 |
+
ep = metadata.EntryPoint(value=value, name=None, group=None)
|
| 86 |
+
assert not ep.extras
|
| 87 |
+
except (TypeError, ValueError, AttributeError, AssertionError) as e:
|
| 88 |
+
raise DistutilsSetupError(
|
| 89 |
+
f"{attr!r} must be importable 'module:attrs' string (got {value!r})"
|
| 90 |
+
) from e
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def assert_string_list(dist, attr: str, value: _Sequence) -> None:
|
| 94 |
+
"""Verify that value is a string list"""
|
| 95 |
+
try:
|
| 96 |
+
# verify that value is a list or tuple to exclude unordered
|
| 97 |
+
# or single-use iterables
|
| 98 |
+
assert isinstance(value, _sequence)
|
| 99 |
+
# verify that elements of value are strings
|
| 100 |
+
assert ''.join(value) != value
|
| 101 |
+
except (TypeError, ValueError, AttributeError, AssertionError) as e:
|
| 102 |
+
raise DistutilsSetupError(
|
| 103 |
+
f"{attr!r} must be of type <{_sequence_type_repr}> (got {value!r})"
|
| 104 |
+
) from e
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def check_nsp(dist, attr, value):
|
| 108 |
+
"""Verify that namespace packages are valid"""
|
| 109 |
+
ns_packages = value
|
| 110 |
+
assert_string_list(dist, attr, ns_packages)
|
| 111 |
+
for nsp in ns_packages:
|
| 112 |
+
if not dist.has_contents_for(nsp):
|
| 113 |
+
raise DistutilsSetupError(
|
| 114 |
+
f"Distribution contains no modules or packages for namespace package {nsp!r}"
|
| 115 |
+
)
|
| 116 |
+
parent, _sep, _child = nsp.rpartition('.')
|
| 117 |
+
if parent and parent not in ns_packages:
|
| 118 |
+
distutils.log.warn(
|
| 119 |
+
"WARNING: %r is declared as a package namespace, but %r"
|
| 120 |
+
" is not: please correct this in setup.py",
|
| 121 |
+
nsp,
|
| 122 |
+
parent,
|
| 123 |
+
)
|
| 124 |
+
SetuptoolsDeprecationWarning.emit(
|
| 125 |
+
"The namespace_packages parameter is deprecated.",
|
| 126 |
+
"Please replace its usage with implicit namespaces (PEP 420).",
|
| 127 |
+
see_docs="references/keywords.html#keyword-namespace-packages",
|
| 128 |
+
# TODO: define due_date, it may break old packages that are no longer
|
| 129 |
+
# maintained (e.g. sphinxcontrib extensions) when installed from source.
|
| 130 |
+
# Warning officially introduced in May 2022, however the deprecation
|
| 131 |
+
# was mentioned much earlier in the docs (May 2020, see #2149).
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def check_extras(dist, attr, value):
|
| 136 |
+
"""Verify that extras_require mapping is valid"""
|
| 137 |
+
try:
|
| 138 |
+
list(itertools.starmap(_check_extra, value.items()))
|
| 139 |
+
except (TypeError, ValueError, AttributeError) as e:
|
| 140 |
+
raise DistutilsSetupError(
|
| 141 |
+
"'extras_require' must be a dictionary whose values are "
|
| 142 |
+
"strings or lists of strings containing valid project/version "
|
| 143 |
+
"requirement specifiers."
|
| 144 |
+
) from e
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def _check_extra(extra, reqs):
|
| 148 |
+
_name, _sep, marker = extra.partition(':')
|
| 149 |
+
try:
|
| 150 |
+
_check_marker(marker)
|
| 151 |
+
except InvalidMarker:
|
| 152 |
+
msg = f"Invalid environment marker: {marker} ({extra!r})"
|
| 153 |
+
raise DistutilsSetupError(msg) from None
|
| 154 |
+
list(_reqs.parse(reqs))
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def _check_marker(marker):
|
| 158 |
+
if not marker:
|
| 159 |
+
return
|
| 160 |
+
m = Marker(marker)
|
| 161 |
+
m.evaluate()
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def assert_bool(dist, attr, value):
|
| 165 |
+
"""Verify that value is True, False, 0, or 1"""
|
| 166 |
+
if bool(value) != value:
|
| 167 |
+
raise DistutilsSetupError(f"{attr!r} must be a boolean value (got {value!r})")
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def invalid_unless_false(dist, attr, value):
|
| 171 |
+
if not value:
|
| 172 |
+
DistDeprecationWarning.emit(f"{attr} is ignored.")
|
| 173 |
+
# TODO: should there be a `due_date` here?
|
| 174 |
+
return
|
| 175 |
+
raise DistutilsSetupError(f"{attr} is invalid.")
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def check_requirements(dist, attr: str, value: _OrderedStrSequence) -> None:
|
| 179 |
+
"""Verify that install_requires is a valid requirements list"""
|
| 180 |
+
try:
|
| 181 |
+
list(_reqs.parse(value))
|
| 182 |
+
if isinstance(value, set):
|
| 183 |
+
raise TypeError("Unordered types are not allowed")
|
| 184 |
+
except (TypeError, ValueError) as error:
|
| 185 |
+
msg = (
|
| 186 |
+
f"{attr!r} must be a string or iterable of strings "
|
| 187 |
+
f"containing valid project/version requirement specifiers; {error}"
|
| 188 |
+
)
|
| 189 |
+
raise DistutilsSetupError(msg) from error
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def check_specifier(dist, attr, value):
|
| 193 |
+
"""Verify that value is a valid version specifier"""
|
| 194 |
+
try:
|
| 195 |
+
SpecifierSet(value)
|
| 196 |
+
except (InvalidSpecifier, AttributeError) as error:
|
| 197 |
+
msg = f"{attr!r} must be a string containing valid version specifiers; {error}"
|
| 198 |
+
raise DistutilsSetupError(msg) from error
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def check_entry_points(dist, attr, value):
|
| 202 |
+
"""Verify that entry_points map is parseable"""
|
| 203 |
+
try:
|
| 204 |
+
_entry_points.load(value)
|
| 205 |
+
except Exception as e:
|
| 206 |
+
raise DistutilsSetupError(e) from e
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
def check_package_data(dist, attr, value):
|
| 210 |
+
"""Verify that value is a dictionary of package names to glob lists"""
|
| 211 |
+
if not isinstance(value, dict):
|
| 212 |
+
raise DistutilsSetupError(
|
| 213 |
+
f"{attr!r} must be a dictionary mapping package names to lists of "
|
| 214 |
+
"string wildcard patterns"
|
| 215 |
+
)
|
| 216 |
+
for k, v in value.items():
|
| 217 |
+
if not isinstance(k, str):
|
| 218 |
+
raise DistutilsSetupError(
|
| 219 |
+
f"keys of {attr!r} dict must be strings (got {k!r})"
|
| 220 |
+
)
|
| 221 |
+
assert_string_list(dist, f'values of {attr!r} dict', v)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def check_packages(dist, attr, value):
|
| 225 |
+
for pkgname in value:
|
| 226 |
+
if not re.match(r'\w+(\.\w+)*', pkgname):
|
| 227 |
+
distutils.log.warn(
|
| 228 |
+
"WARNING: %r not a valid package name; please use only "
|
| 229 |
+
".-separated package names in setup.py",
|
| 230 |
+
pkgname,
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
if TYPE_CHECKING:
|
| 235 |
+
# Work around a mypy issue where type[T] can't be used as a base: https://github.com/python/mypy/issues/10962
|
| 236 |
+
from distutils.core import Distribution as _Distribution
|
| 237 |
+
else:
|
| 238 |
+
_Distribution = get_unpatched(distutils.core.Distribution)
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
class Distribution(_Distribution):
|
| 242 |
+
"""Distribution with support for tests and package data
|
| 243 |
+
|
| 244 |
+
This is an enhanced version of 'distutils.dist.Distribution' that
|
| 245 |
+
effectively adds the following new optional keyword arguments to 'setup()':
|
| 246 |
+
|
| 247 |
+
'install_requires' -- a string or sequence of strings specifying project
|
| 248 |
+
versions that the distribution requires when installed, in the format
|
| 249 |
+
used by 'pkg_resources.require()'. They will be installed
|
| 250 |
+
automatically when the package is installed. If you wish to use
|
| 251 |
+
packages that are not available in PyPI, or want to give your users an
|
| 252 |
+
alternate download location, you can add a 'find_links' option to the
|
| 253 |
+
'[easy_install]' section of your project's 'setup.cfg' file, and then
|
| 254 |
+
setuptools will scan the listed web pages for links that satisfy the
|
| 255 |
+
requirements.
|
| 256 |
+
|
| 257 |
+
'extras_require' -- a dictionary mapping names of optional "extras" to the
|
| 258 |
+
additional requirement(s) that using those extras incurs. For example,
|
| 259 |
+
this::
|
| 260 |
+
|
| 261 |
+
extras_require = dict(reST = ["docutils>=0.3", "reSTedit"])
|
| 262 |
+
|
| 263 |
+
indicates that the distribution can optionally provide an extra
|
| 264 |
+
capability called "reST", but it can only be used if docutils and
|
| 265 |
+
reSTedit are installed. If the user installs your package using
|
| 266 |
+
EasyInstall and requests one of your extras, the corresponding
|
| 267 |
+
additional requirements will be installed if needed.
|
| 268 |
+
|
| 269 |
+
'package_data' -- a dictionary mapping package names to lists of filenames
|
| 270 |
+
or globs to use to find data files contained in the named packages.
|
| 271 |
+
If the dictionary has filenames or globs listed under '""' (the empty
|
| 272 |
+
string), those names will be searched for in every package, in addition
|
| 273 |
+
to any names for the specific package. Data files found using these
|
| 274 |
+
names/globs will be installed along with the package, in the same
|
| 275 |
+
location as the package. Note that globs are allowed to reference
|
| 276 |
+
the contents of non-package subdirectories, as long as you use '/' as
|
| 277 |
+
a path separator. (Globs are automatically converted to
|
| 278 |
+
platform-specific paths at runtime.)
|
| 279 |
+
|
| 280 |
+
In addition to these new keywords, this class also has several new methods
|
| 281 |
+
for manipulating the distribution's contents. For example, the 'include()'
|
| 282 |
+
and 'exclude()' methods can be thought of as in-place add and subtract
|
| 283 |
+
commands that add or remove packages, modules, extensions, and so on from
|
| 284 |
+
the distribution.
|
| 285 |
+
"""
|
| 286 |
+
|
| 287 |
+
_DISTUTILS_UNSUPPORTED_METADATA = {
|
| 288 |
+
'long_description_content_type': lambda: None,
|
| 289 |
+
'project_urls': dict,
|
| 290 |
+
'provides_extras': dict, # behaves like an ordered set
|
| 291 |
+
'license_file': lambda: None,
|
| 292 |
+
'license_files': lambda: None,
|
| 293 |
+
'install_requires': list,
|
| 294 |
+
'extras_require': dict,
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
# Used by build_py, editable_wheel and install_lib commands for legacy namespaces
|
| 298 |
+
namespace_packages: list[str] #: :meta private: DEPRECATED
|
| 299 |
+
|
| 300 |
+
# Any: Dynamic assignment results in Incompatible types in assignment
|
| 301 |
+
def __init__(self, attrs: MutableMapping[str, Any] | None = None) -> None:
|
| 302 |
+
have_package_data = hasattr(self, "package_data")
|
| 303 |
+
if not have_package_data:
|
| 304 |
+
self.package_data: dict[str, list[str]] = {}
|
| 305 |
+
attrs = attrs or {}
|
| 306 |
+
self.dist_files: list[tuple[str, str, str]] = []
|
| 307 |
+
self.include_package_data: bool | None = None
|
| 308 |
+
self.exclude_package_data: dict[str, list[str]] | None = None
|
| 309 |
+
# Filter-out setuptools' specific options.
|
| 310 |
+
self.src_root: str | None = attrs.pop("src_root", None)
|
| 311 |
+
self.dependency_links: list[str] = attrs.pop('dependency_links', [])
|
| 312 |
+
self.setup_requires: list[str] = attrs.pop('setup_requires', [])
|
| 313 |
+
for ep in metadata.entry_points(group='distutils.setup_keywords'):
|
| 314 |
+
vars(self).setdefault(ep.name, None)
|
| 315 |
+
|
| 316 |
+
metadata_only = set(self._DISTUTILS_UNSUPPORTED_METADATA)
|
| 317 |
+
metadata_only -= {"install_requires", "extras_require"}
|
| 318 |
+
dist_attrs = {k: v for k, v in attrs.items() if k not in metadata_only}
|
| 319 |
+
_Distribution.__init__(self, dist_attrs)
|
| 320 |
+
|
| 321 |
+
# Private API (setuptools-use only, not restricted to Distribution)
|
| 322 |
+
# Stores files that are referenced by the configuration and need to be in the
|
| 323 |
+
# sdist (e.g. `version = file: VERSION.txt`)
|
| 324 |
+
self._referenced_files = set[str]()
|
| 325 |
+
|
| 326 |
+
self.set_defaults = ConfigDiscovery(self)
|
| 327 |
+
|
| 328 |
+
self._set_metadata_defaults(attrs)
|
| 329 |
+
|
| 330 |
+
self.metadata.version = self._normalize_version(self.metadata.version)
|
| 331 |
+
self._finalize_requires()
|
| 332 |
+
|
| 333 |
+
def _validate_metadata(self):
|
| 334 |
+
required = {"name"}
|
| 335 |
+
provided = {
|
| 336 |
+
key
|
| 337 |
+
for key in vars(self.metadata)
|
| 338 |
+
if getattr(self.metadata, key, None) is not None
|
| 339 |
+
}
|
| 340 |
+
missing = required - provided
|
| 341 |
+
|
| 342 |
+
if missing:
|
| 343 |
+
msg = f"Required package metadata is missing: {missing}"
|
| 344 |
+
raise DistutilsSetupError(msg)
|
| 345 |
+
|
| 346 |
+
def _set_metadata_defaults(self, attrs):
|
| 347 |
+
"""
|
| 348 |
+
Fill-in missing metadata fields not supported by distutils.
|
| 349 |
+
Some fields may have been set by other tools (e.g. pbr).
|
| 350 |
+
Those fields (vars(self.metadata)) take precedence to
|
| 351 |
+
supplied attrs.
|
| 352 |
+
"""
|
| 353 |
+
for option, default in self._DISTUTILS_UNSUPPORTED_METADATA.items():
|
| 354 |
+
vars(self.metadata).setdefault(option, attrs.get(option, default()))
|
| 355 |
+
|
| 356 |
+
@staticmethod
|
| 357 |
+
def _normalize_version(version):
|
| 358 |
+
from . import sic
|
| 359 |
+
|
| 360 |
+
if isinstance(version, numbers.Number):
|
| 361 |
+
# Some people apparently take "version number" too literally :)
|
| 362 |
+
version = str(version)
|
| 363 |
+
elif isinstance(version, sic) or version is None:
|
| 364 |
+
return version
|
| 365 |
+
|
| 366 |
+
normalized = str(Version(version))
|
| 367 |
+
if version != normalized:
|
| 368 |
+
InformationOnly.emit(f"Normalizing '{version}' to '{normalized}'")
|
| 369 |
+
return normalized
|
| 370 |
+
return version
|
| 371 |
+
|
| 372 |
+
def _finalize_requires(self):
|
| 373 |
+
"""
|
| 374 |
+
Set `metadata.python_requires` and fix environment markers
|
| 375 |
+
in `install_requires` and `extras_require`.
|
| 376 |
+
"""
|
| 377 |
+
if getattr(self, 'python_requires', None):
|
| 378 |
+
self.metadata.python_requires = self.python_requires
|
| 379 |
+
|
| 380 |
+
self._normalize_requires()
|
| 381 |
+
self.metadata.install_requires = self.install_requires
|
| 382 |
+
self.metadata.extras_require = self.extras_require
|
| 383 |
+
|
| 384 |
+
if self.extras_require:
|
| 385 |
+
for extra in self.extras_require.keys():
|
| 386 |
+
# Setuptools allows a weird "<name>:<env markers> syntax for extras
|
| 387 |
+
extra = extra.split(':')[0]
|
| 388 |
+
if extra:
|
| 389 |
+
self.metadata.provides_extras.setdefault(extra)
|
| 390 |
+
|
| 391 |
+
def _normalize_requires(self):
|
| 392 |
+
"""Make sure requirement-related attributes exist and are normalized"""
|
| 393 |
+
install_requires = getattr(self, "install_requires", None) or []
|
| 394 |
+
extras_require = getattr(self, "extras_require", None) or {}
|
| 395 |
+
|
| 396 |
+
# Preserve the "static"-ness of values parsed from config files
|
| 397 |
+
list_ = _static.List if _static.is_static(install_requires) else list
|
| 398 |
+
self.install_requires = list_(map(str, _reqs.parse(install_requires)))
|
| 399 |
+
|
| 400 |
+
dict_ = _static.Dict if _static.is_static(extras_require) else dict
|
| 401 |
+
self.extras_require = dict_(
|
| 402 |
+
(k, list(map(str, _reqs.parse(v or [])))) for k, v in extras_require.items()
|
| 403 |
+
)
|
| 404 |
+
|
| 405 |
+
def _finalize_license_files(self) -> None:
|
| 406 |
+
"""Compute names of all license files which should be included."""
|
| 407 |
+
license_files: list[str] | None = self.metadata.license_files
|
| 408 |
+
patterns = license_files or []
|
| 409 |
+
|
| 410 |
+
license_file: str | None = self.metadata.license_file
|
| 411 |
+
if license_file and license_file not in patterns:
|
| 412 |
+
patterns.append(license_file)
|
| 413 |
+
|
| 414 |
+
if license_files is None and license_file is None:
|
| 415 |
+
# Default patterns match the ones wheel uses
|
| 416 |
+
# See https://wheel.readthedocs.io/en/stable/user_guide.html
|
| 417 |
+
# -> 'Including license files in the generated wheel file'
|
| 418 |
+
patterns = ['LICEN[CS]E*', 'COPYING*', 'NOTICE*', 'AUTHORS*']
|
| 419 |
+
|
| 420 |
+
self.metadata.license_files = list(
|
| 421 |
+
unique_everseen(self._expand_patterns(patterns))
|
| 422 |
+
)
|
| 423 |
+
|
| 424 |
+
@staticmethod
|
| 425 |
+
def _expand_patterns(patterns):
|
| 426 |
+
"""
|
| 427 |
+
>>> list(Distribution._expand_patterns(['LICENSE']))
|
| 428 |
+
['LICENSE']
|
| 429 |
+
>>> list(Distribution._expand_patterns(['pyproject.toml', 'LIC*']))
|
| 430 |
+
['pyproject.toml', 'LICENSE']
|
| 431 |
+
"""
|
| 432 |
+
return (
|
| 433 |
+
path
|
| 434 |
+
for pattern in patterns
|
| 435 |
+
for path in sorted(iglob(pattern))
|
| 436 |
+
if not path.endswith('~') and os.path.isfile(path)
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
# FIXME: 'Distribution._parse_config_files' is too complex (14)
|
| 440 |
+
def _parse_config_files(self, filenames=None): # noqa: C901
|
| 441 |
+
"""
|
| 442 |
+
Adapted from distutils.dist.Distribution.parse_config_files,
|
| 443 |
+
this method provides the same functionality in subtly-improved
|
| 444 |
+
ways.
|
| 445 |
+
"""
|
| 446 |
+
from configparser import ConfigParser
|
| 447 |
+
|
| 448 |
+
# Ignore install directory options if we have a venv
|
| 449 |
+
ignore_options = (
|
| 450 |
+
[]
|
| 451 |
+
if sys.prefix == sys.base_prefix
|
| 452 |
+
else [
|
| 453 |
+
'install-base',
|
| 454 |
+
'install-platbase',
|
| 455 |
+
'install-lib',
|
| 456 |
+
'install-platlib',
|
| 457 |
+
'install-purelib',
|
| 458 |
+
'install-headers',
|
| 459 |
+
'install-scripts',
|
| 460 |
+
'install-data',
|
| 461 |
+
'prefix',
|
| 462 |
+
'exec-prefix',
|
| 463 |
+
'home',
|
| 464 |
+
'user',
|
| 465 |
+
'root',
|
| 466 |
+
]
|
| 467 |
+
)
|
| 468 |
+
|
| 469 |
+
ignore_options = frozenset(ignore_options)
|
| 470 |
+
|
| 471 |
+
if filenames is None:
|
| 472 |
+
filenames = self.find_config_files()
|
| 473 |
+
|
| 474 |
+
if DEBUG:
|
| 475 |
+
self.announce("Distribution.parse_config_files():")
|
| 476 |
+
|
| 477 |
+
parser = ConfigParser()
|
| 478 |
+
parser.optionxform = str
|
| 479 |
+
for filename in filenames:
|
| 480 |
+
with open(filename, encoding='utf-8') as reader:
|
| 481 |
+
if DEBUG:
|
| 482 |
+
self.announce(" reading {filename}".format(**locals()))
|
| 483 |
+
parser.read_file(reader)
|
| 484 |
+
for section in parser.sections():
|
| 485 |
+
options = parser.options(section)
|
| 486 |
+
opt_dict = self.get_option_dict(section)
|
| 487 |
+
|
| 488 |
+
for opt in options:
|
| 489 |
+
if opt == '__name__' or opt in ignore_options:
|
| 490 |
+
continue
|
| 491 |
+
|
| 492 |
+
val = parser.get(section, opt)
|
| 493 |
+
opt = self.warn_dash_deprecation(opt, section)
|
| 494 |
+
opt = self.make_option_lowercase(opt, section)
|
| 495 |
+
opt_dict[opt] = (filename, val)
|
| 496 |
+
|
| 497 |
+
# Make the ConfigParser forget everything (so we retain
|
| 498 |
+
# the original filenames that options come from)
|
| 499 |
+
parser.__init__()
|
| 500 |
+
|
| 501 |
+
if 'global' not in self.command_options:
|
| 502 |
+
return
|
| 503 |
+
|
| 504 |
+
# If there was a "global" section in the config file, use it
|
| 505 |
+
# to set Distribution options.
|
| 506 |
+
|
| 507 |
+
for opt, (src, val) in self.command_options['global'].items():
|
| 508 |
+
alias = self.negative_opt.get(opt)
|
| 509 |
+
if alias:
|
| 510 |
+
val = not strtobool(val)
|
| 511 |
+
elif opt in ('verbose', 'dry_run'): # ugh!
|
| 512 |
+
val = strtobool(val)
|
| 513 |
+
|
| 514 |
+
try:
|
| 515 |
+
setattr(self, alias or opt, val)
|
| 516 |
+
except ValueError as e:
|
| 517 |
+
raise DistutilsOptionError(e) from e
|
| 518 |
+
|
| 519 |
+
def warn_dash_deprecation(self, opt: str, section: str) -> str:
|
| 520 |
+
if section in (
|
| 521 |
+
'options.extras_require',
|
| 522 |
+
'options.data_files',
|
| 523 |
+
):
|
| 524 |
+
return opt
|
| 525 |
+
|
| 526 |
+
underscore_opt = opt.replace('-', '_')
|
| 527 |
+
commands = list(
|
| 528 |
+
itertools.chain(
|
| 529 |
+
distutils.command.__all__,
|
| 530 |
+
self._setuptools_commands(),
|
| 531 |
+
)
|
| 532 |
+
)
|
| 533 |
+
if (
|
| 534 |
+
not section.startswith('options')
|
| 535 |
+
and section != 'metadata'
|
| 536 |
+
and section not in commands
|
| 537 |
+
):
|
| 538 |
+
return underscore_opt
|
| 539 |
+
|
| 540 |
+
if '-' in opt:
|
| 541 |
+
SetuptoolsDeprecationWarning.emit(
|
| 542 |
+
"Invalid dash-separated options",
|
| 543 |
+
f"""
|
| 544 |
+
Usage of dash-separated {opt!r} will not be supported in future
|
| 545 |
+
versions. Please use the underscore name {underscore_opt!r} instead.
|
| 546 |
+
""",
|
| 547 |
+
see_docs="userguide/declarative_config.html",
|
| 548 |
+
due_date=(2025, 3, 3),
|
| 549 |
+
# Warning initially introduced in 3 Mar 2021
|
| 550 |
+
)
|
| 551 |
+
return underscore_opt
|
| 552 |
+
|
| 553 |
+
def _setuptools_commands(self):
|
| 554 |
+
try:
|
| 555 |
+
entry_points = metadata.distribution('setuptools').entry_points
|
| 556 |
+
return {ep.name for ep in entry_points} # Avoid newer API for compatibility
|
| 557 |
+
except metadata.PackageNotFoundError:
|
| 558 |
+
# during bootstrapping, distribution doesn't exist
|
| 559 |
+
return []
|
| 560 |
+
|
| 561 |
+
def make_option_lowercase(self, opt: str, section: str) -> str:
|
| 562 |
+
if section != 'metadata' or opt.islower():
|
| 563 |
+
return opt
|
| 564 |
+
|
| 565 |
+
lowercase_opt = opt.lower()
|
| 566 |
+
SetuptoolsDeprecationWarning.emit(
|
| 567 |
+
"Invalid uppercase configuration",
|
| 568 |
+
f"""
|
| 569 |
+
Usage of uppercase key {opt!r} in {section!r} will not be supported in
|
| 570 |
+
future versions. Please use lowercase {lowercase_opt!r} instead.
|
| 571 |
+
""",
|
| 572 |
+
see_docs="userguide/declarative_config.html",
|
| 573 |
+
due_date=(2025, 3, 3),
|
| 574 |
+
# Warning initially introduced in 6 Mar 2021
|
| 575 |
+
)
|
| 576 |
+
return lowercase_opt
|
| 577 |
+
|
| 578 |
+
# FIXME: 'Distribution._set_command_options' is too complex (14)
|
| 579 |
+
def _set_command_options(self, command_obj, option_dict=None): # noqa: C901
|
| 580 |
+
"""
|
| 581 |
+
Set the options for 'command_obj' from 'option_dict'. Basically
|
| 582 |
+
this means copying elements of a dictionary ('option_dict') to
|
| 583 |
+
attributes of an instance ('command').
|
| 584 |
+
|
| 585 |
+
'command_obj' must be a Command instance. If 'option_dict' is not
|
| 586 |
+
supplied, uses the standard option dictionary for this command
|
| 587 |
+
(from 'self.command_options').
|
| 588 |
+
|
| 589 |
+
(Adopted from distutils.dist.Distribution._set_command_options)
|
| 590 |
+
"""
|
| 591 |
+
command_name = command_obj.get_command_name()
|
| 592 |
+
if option_dict is None:
|
| 593 |
+
option_dict = self.get_option_dict(command_name)
|
| 594 |
+
|
| 595 |
+
if DEBUG:
|
| 596 |
+
self.announce(f" setting options for '{command_name}' command:")
|
| 597 |
+
for option, (source, value) in option_dict.items():
|
| 598 |
+
if DEBUG:
|
| 599 |
+
self.announce(f" {option} = {value} (from {source})")
|
| 600 |
+
try:
|
| 601 |
+
bool_opts = [translate_longopt(o) for o in command_obj.boolean_options]
|
| 602 |
+
except AttributeError:
|
| 603 |
+
bool_opts = []
|
| 604 |
+
try:
|
| 605 |
+
neg_opt = command_obj.negative_opt
|
| 606 |
+
except AttributeError:
|
| 607 |
+
neg_opt = {}
|
| 608 |
+
|
| 609 |
+
try:
|
| 610 |
+
is_string = isinstance(value, str)
|
| 611 |
+
if option in neg_opt and is_string:
|
| 612 |
+
setattr(command_obj, neg_opt[option], not strtobool(value))
|
| 613 |
+
elif option in bool_opts and is_string:
|
| 614 |
+
setattr(command_obj, option, strtobool(value))
|
| 615 |
+
elif hasattr(command_obj, option):
|
| 616 |
+
setattr(command_obj, option, value)
|
| 617 |
+
else:
|
| 618 |
+
raise DistutilsOptionError(
|
| 619 |
+
f"error in {source}: command '{command_name}' has no such option '{option}'"
|
| 620 |
+
)
|
| 621 |
+
except ValueError as e:
|
| 622 |
+
raise DistutilsOptionError(e) from e
|
| 623 |
+
|
| 624 |
+
def _get_project_config_files(self, filenames: Iterable[StrPath] | None):
|
| 625 |
+
"""Add default file and split between INI and TOML"""
|
| 626 |
+
tomlfiles = []
|
| 627 |
+
standard_project_metadata = Path(self.src_root or os.curdir, "pyproject.toml")
|
| 628 |
+
if filenames is not None:
|
| 629 |
+
parts = partition(lambda f: Path(f).suffix == ".toml", filenames)
|
| 630 |
+
filenames = list(parts[0]) # 1st element => predicate is False
|
| 631 |
+
tomlfiles = list(parts[1]) # 2nd element => predicate is True
|
| 632 |
+
elif standard_project_metadata.exists():
|
| 633 |
+
tomlfiles = [standard_project_metadata]
|
| 634 |
+
return filenames, tomlfiles
|
| 635 |
+
|
| 636 |
+
def parse_config_files(
|
| 637 |
+
self,
|
| 638 |
+
filenames: Iterable[StrPath] | None = None,
|
| 639 |
+
ignore_option_errors: bool = False,
|
| 640 |
+
) -> None:
|
| 641 |
+
"""Parses configuration files from various levels
|
| 642 |
+
and loads configuration.
|
| 643 |
+
"""
|
| 644 |
+
inifiles, tomlfiles = self._get_project_config_files(filenames)
|
| 645 |
+
|
| 646 |
+
self._parse_config_files(filenames=inifiles)
|
| 647 |
+
|
| 648 |
+
setupcfg.parse_configuration(
|
| 649 |
+
self, self.command_options, ignore_option_errors=ignore_option_errors
|
| 650 |
+
)
|
| 651 |
+
for filename in tomlfiles:
|
| 652 |
+
pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
|
| 653 |
+
|
| 654 |
+
self._finalize_requires()
|
| 655 |
+
self._finalize_license_files()
|
| 656 |
+
|
| 657 |
+
def fetch_build_eggs(
|
| 658 |
+
self, requires: _StrOrIter
|
| 659 |
+
) -> list[_pkg_resources_Distribution]:
|
| 660 |
+
"""Resolve pre-setup requirements"""
|
| 661 |
+
from .installer import _fetch_build_eggs
|
| 662 |
+
|
| 663 |
+
return _fetch_build_eggs(self, requires)
|
| 664 |
+
|
| 665 |
+
def finalize_options(self) -> None:
|
| 666 |
+
"""
|
| 667 |
+
Allow plugins to apply arbitrary operations to the
|
| 668 |
+
distribution. Each hook may optionally define a 'order'
|
| 669 |
+
to influence the order of execution. Smaller numbers
|
| 670 |
+
go first and the default is 0.
|
| 671 |
+
"""
|
| 672 |
+
group = 'setuptools.finalize_distribution_options'
|
| 673 |
+
|
| 674 |
+
def by_order(hook):
|
| 675 |
+
return getattr(hook, 'order', 0)
|
| 676 |
+
|
| 677 |
+
defined = metadata.entry_points(group=group)
|
| 678 |
+
filtered = itertools.filterfalse(self._removed, defined)
|
| 679 |
+
loaded = map(lambda e: e.load(), filtered)
|
| 680 |
+
for ep in sorted(loaded, key=by_order):
|
| 681 |
+
ep(self)
|
| 682 |
+
|
| 683 |
+
@staticmethod
|
| 684 |
+
def _removed(ep):
|
| 685 |
+
"""
|
| 686 |
+
When removing an entry point, if metadata is loaded
|
| 687 |
+
from an older version of Setuptools, that removed
|
| 688 |
+
entry point will attempt to be loaded and will fail.
|
| 689 |
+
See #2765 for more details.
|
| 690 |
+
"""
|
| 691 |
+
removed = {
|
| 692 |
+
# removed 2021-09-05
|
| 693 |
+
'2to3_doctests',
|
| 694 |
+
}
|
| 695 |
+
return ep.name in removed
|
| 696 |
+
|
| 697 |
+
def _finalize_setup_keywords(self):
|
| 698 |
+
for ep in metadata.entry_points(group='distutils.setup_keywords'):
|
| 699 |
+
value = getattr(self, ep.name, None)
|
| 700 |
+
if value is not None:
|
| 701 |
+
ep.load()(self, ep.name, value)
|
| 702 |
+
|
| 703 |
+
def get_egg_cache_dir(self):
|
| 704 |
+
from . import windows_support
|
| 705 |
+
|
| 706 |
+
egg_cache_dir = os.path.join(os.curdir, '.eggs')
|
| 707 |
+
if not os.path.exists(egg_cache_dir):
|
| 708 |
+
os.mkdir(egg_cache_dir)
|
| 709 |
+
windows_support.hide_file(egg_cache_dir)
|
| 710 |
+
readme_txt_filename = os.path.join(egg_cache_dir, 'README.txt')
|
| 711 |
+
with open(readme_txt_filename, 'w', encoding="utf-8") as f:
|
| 712 |
+
f.write(
|
| 713 |
+
'This directory contains eggs that were downloaded '
|
| 714 |
+
'by setuptools to build, test, and run plug-ins.\n\n'
|
| 715 |
+
)
|
| 716 |
+
f.write(
|
| 717 |
+
'This directory caches those eggs to prevent '
|
| 718 |
+
'repeated downloads.\n\n'
|
| 719 |
+
)
|
| 720 |
+
f.write('However, it is safe to delete this directory.\n\n')
|
| 721 |
+
|
| 722 |
+
return egg_cache_dir
|
| 723 |
+
|
| 724 |
+
def fetch_build_egg(self, req):
|
| 725 |
+
"""Fetch an egg needed for building"""
|
| 726 |
+
from .installer import fetch_build_egg
|
| 727 |
+
|
| 728 |
+
return fetch_build_egg(self, req)
|
| 729 |
+
|
| 730 |
+
def get_command_class(self, command: str) -> type[distutils.cmd.Command]: # type: ignore[override] # Not doing complex overrides yet
|
| 731 |
+
"""Pluggable version of get_command_class()"""
|
| 732 |
+
if command in self.cmdclass:
|
| 733 |
+
return self.cmdclass[command]
|
| 734 |
+
|
| 735 |
+
# Special case bdist_wheel so it's never loaded from "wheel"
|
| 736 |
+
if command == 'bdist_wheel':
|
| 737 |
+
from .command.bdist_wheel import bdist_wheel
|
| 738 |
+
|
| 739 |
+
return bdist_wheel
|
| 740 |
+
|
| 741 |
+
eps = metadata.entry_points(group='distutils.commands', name=command)
|
| 742 |
+
for ep in eps:
|
| 743 |
+
self.cmdclass[command] = cmdclass = ep.load()
|
| 744 |
+
return cmdclass
|
| 745 |
+
else:
|
| 746 |
+
return _Distribution.get_command_class(self, command)
|
| 747 |
+
|
| 748 |
+
def print_commands(self):
|
| 749 |
+
for ep in metadata.entry_points(group='distutils.commands'):
|
| 750 |
+
if ep.name not in self.cmdclass:
|
| 751 |
+
cmdclass = ep.load()
|
| 752 |
+
self.cmdclass[ep.name] = cmdclass
|
| 753 |
+
return _Distribution.print_commands(self)
|
| 754 |
+
|
| 755 |
+
def get_command_list(self):
|
| 756 |
+
for ep in metadata.entry_points(group='distutils.commands'):
|
| 757 |
+
if ep.name not in self.cmdclass:
|
| 758 |
+
cmdclass = ep.load()
|
| 759 |
+
self.cmdclass[ep.name] = cmdclass
|
| 760 |
+
return _Distribution.get_command_list(self)
|
| 761 |
+
|
| 762 |
+
def include(self, **attrs) -> None:
|
| 763 |
+
"""Add items to distribution that are named in keyword arguments
|
| 764 |
+
|
| 765 |
+
For example, 'dist.include(py_modules=["x"])' would add 'x' to
|
| 766 |
+
the distribution's 'py_modules' attribute, if it was not already
|
| 767 |
+
there.
|
| 768 |
+
|
| 769 |
+
Currently, this method only supports inclusion for attributes that are
|
| 770 |
+
lists or tuples. If you need to add support for adding to other
|
| 771 |
+
attributes in this or a subclass, you can add an '_include_X' method,
|
| 772 |
+
where 'X' is the name of the attribute. The method will be called with
|
| 773 |
+
the value passed to 'include()'. So, 'dist.include(foo={"bar":"baz"})'
|
| 774 |
+
will try to call 'dist._include_foo({"bar":"baz"})', which can then
|
| 775 |
+
handle whatever special inclusion logic is needed.
|
| 776 |
+
"""
|
| 777 |
+
for k, v in attrs.items():
|
| 778 |
+
include = getattr(self, '_include_' + k, None)
|
| 779 |
+
if include:
|
| 780 |
+
include(v)
|
| 781 |
+
else:
|
| 782 |
+
self._include_misc(k, v)
|
| 783 |
+
|
| 784 |
+
def exclude_package(self, package: str) -> None:
|
| 785 |
+
"""Remove packages, modules, and extensions in named package"""
|
| 786 |
+
|
| 787 |
+
pfx = package + '.'
|
| 788 |
+
if self.packages:
|
| 789 |
+
self.packages = [
|
| 790 |
+
p for p in self.packages if p != package and not p.startswith(pfx)
|
| 791 |
+
]
|
| 792 |
+
|
| 793 |
+
if self.py_modules:
|
| 794 |
+
self.py_modules = [
|
| 795 |
+
p for p in self.py_modules if p != package and not p.startswith(pfx)
|
| 796 |
+
]
|
| 797 |
+
|
| 798 |
+
if self.ext_modules:
|
| 799 |
+
self.ext_modules = [
|
| 800 |
+
p
|
| 801 |
+
for p in self.ext_modules
|
| 802 |
+
if p.name != package and not p.name.startswith(pfx)
|
| 803 |
+
]
|
| 804 |
+
|
| 805 |
+
def has_contents_for(self, package: str) -> bool:
|
| 806 |
+
"""Return true if 'exclude_package(package)' would do something"""
|
| 807 |
+
|
| 808 |
+
pfx = package + '.'
|
| 809 |
+
|
| 810 |
+
for p in self.iter_distribution_names():
|
| 811 |
+
if p == package or p.startswith(pfx):
|
| 812 |
+
return True
|
| 813 |
+
|
| 814 |
+
return False
|
| 815 |
+
|
| 816 |
+
def _exclude_misc(self, name: str, value: _Sequence) -> None:
|
| 817 |
+
"""Handle 'exclude()' for list/tuple attrs without a special handler"""
|
| 818 |
+
if not isinstance(value, _sequence):
|
| 819 |
+
raise DistutilsSetupError(
|
| 820 |
+
f"{name}: setting must be of type <{_sequence_type_repr}> (got {value!r})"
|
| 821 |
+
)
|
| 822 |
+
try:
|
| 823 |
+
old = getattr(self, name)
|
| 824 |
+
except AttributeError as e:
|
| 825 |
+
raise DistutilsSetupError(f"{name}: No such distribution setting") from e
|
| 826 |
+
if old is not None and not isinstance(old, _sequence):
|
| 827 |
+
raise DistutilsSetupError(
|
| 828 |
+
name + ": this setting cannot be changed via include/exclude"
|
| 829 |
+
)
|
| 830 |
+
elif old:
|
| 831 |
+
setattr(self, name, [item for item in old if item not in value])
|
| 832 |
+
|
| 833 |
+
def _include_misc(self, name: str, value: _Sequence) -> None:
|
| 834 |
+
"""Handle 'include()' for list/tuple attrs without a special handler"""
|
| 835 |
+
|
| 836 |
+
if not isinstance(value, _sequence):
|
| 837 |
+
raise DistutilsSetupError(
|
| 838 |
+
f"{name}: setting must be of type <{_sequence_type_repr}> (got {value!r})"
|
| 839 |
+
)
|
| 840 |
+
try:
|
| 841 |
+
old = getattr(self, name)
|
| 842 |
+
except AttributeError as e:
|
| 843 |
+
raise DistutilsSetupError(f"{name}: No such distribution setting") from e
|
| 844 |
+
if old is None:
|
| 845 |
+
setattr(self, name, value)
|
| 846 |
+
elif not isinstance(old, _sequence):
|
| 847 |
+
raise DistutilsSetupError(
|
| 848 |
+
name + ": this setting cannot be changed via include/exclude"
|
| 849 |
+
)
|
| 850 |
+
else:
|
| 851 |
+
new = [item for item in value if item not in old]
|
| 852 |
+
setattr(self, name, list(old) + new)
|
| 853 |
+
|
| 854 |
+
def exclude(self, **attrs) -> None:
|
| 855 |
+
"""Remove items from distribution that are named in keyword arguments
|
| 856 |
+
|
| 857 |
+
For example, 'dist.exclude(py_modules=["x"])' would remove 'x' from
|
| 858 |
+
the distribution's 'py_modules' attribute. Excluding packages uses
|
| 859 |
+
the 'exclude_package()' method, so all of the package's contained
|
| 860 |
+
packages, modules, and extensions are also excluded.
|
| 861 |
+
|
| 862 |
+
Currently, this method only supports exclusion from attributes that are
|
| 863 |
+
lists or tuples. If you need to add support for excluding from other
|
| 864 |
+
attributes in this or a subclass, you can add an '_exclude_X' method,
|
| 865 |
+
where 'X' is the name of the attribute. The method will be called with
|
| 866 |
+
the value passed to 'exclude()'. So, 'dist.exclude(foo={"bar":"baz"})'
|
| 867 |
+
will try to call 'dist._exclude_foo({"bar":"baz"})', which can then
|
| 868 |
+
handle whatever special exclusion logic is needed.
|
| 869 |
+
"""
|
| 870 |
+
for k, v in attrs.items():
|
| 871 |
+
exclude = getattr(self, '_exclude_' + k, None)
|
| 872 |
+
if exclude:
|
| 873 |
+
exclude(v)
|
| 874 |
+
else:
|
| 875 |
+
self._exclude_misc(k, v)
|
| 876 |
+
|
| 877 |
+
def _exclude_packages(self, packages: _Sequence) -> None:
|
| 878 |
+
if not isinstance(packages, _sequence):
|
| 879 |
+
raise DistutilsSetupError(
|
| 880 |
+
f"packages: setting must be of type <{_sequence_type_repr}> (got {packages!r})"
|
| 881 |
+
)
|
| 882 |
+
list(map(self.exclude_package, packages))
|
| 883 |
+
|
| 884 |
+
def _parse_command_opts(self, parser, args):
|
| 885 |
+
# Remove --with-X/--without-X options when processing command args
|
| 886 |
+
self.global_options = self.__class__.global_options
|
| 887 |
+
self.negative_opt = self.__class__.negative_opt
|
| 888 |
+
|
| 889 |
+
# First, expand any aliases
|
| 890 |
+
command = args[0]
|
| 891 |
+
aliases = self.get_option_dict('aliases')
|
| 892 |
+
while command in aliases:
|
| 893 |
+
_src, alias = aliases[command]
|
| 894 |
+
del aliases[command] # ensure each alias can expand only once!
|
| 895 |
+
import shlex
|
| 896 |
+
|
| 897 |
+
args[:1] = shlex.split(alias, True)
|
| 898 |
+
command = args[0]
|
| 899 |
+
|
| 900 |
+
nargs = _Distribution._parse_command_opts(self, parser, args)
|
| 901 |
+
|
| 902 |
+
# Handle commands that want to consume all remaining arguments
|
| 903 |
+
cmd_class = self.get_command_class(command)
|
| 904 |
+
if getattr(cmd_class, 'command_consumes_arguments', None):
|
| 905 |
+
self.get_option_dict(command)['args'] = ("command line", nargs)
|
| 906 |
+
if nargs is not None:
|
| 907 |
+
return []
|
| 908 |
+
|
| 909 |
+
return nargs
|
| 910 |
+
|
| 911 |
+
def get_cmdline_options(self) -> dict[str, dict[str, str | None]]:
|
| 912 |
+
"""Return a '{cmd: {opt:val}}' map of all command-line options
|
| 913 |
+
|
| 914 |
+
Option names are all long, but do not include the leading '--', and
|
| 915 |
+
contain dashes rather than underscores. If the option doesn't take
|
| 916 |
+
an argument (e.g. '--quiet'), the 'val' is 'None'.
|
| 917 |
+
|
| 918 |
+
Note that options provided by config files are intentionally excluded.
|
| 919 |
+
"""
|
| 920 |
+
|
| 921 |
+
d: dict[str, dict[str, str | None]] = {}
|
| 922 |
+
|
| 923 |
+
for cmd, opts in self.command_options.items():
|
| 924 |
+
val: str | None
|
| 925 |
+
for opt, (src, val) in opts.items():
|
| 926 |
+
if src != "command line":
|
| 927 |
+
continue
|
| 928 |
+
|
| 929 |
+
opt = opt.replace('_', '-')
|
| 930 |
+
|
| 931 |
+
if val == 0:
|
| 932 |
+
cmdobj = self.get_command_obj(cmd)
|
| 933 |
+
neg_opt = self.negative_opt.copy()
|
| 934 |
+
neg_opt.update(getattr(cmdobj, 'negative_opt', {}))
|
| 935 |
+
for neg, pos in neg_opt.items():
|
| 936 |
+
if pos == opt:
|
| 937 |
+
opt = neg
|
| 938 |
+
val = None
|
| 939 |
+
break
|
| 940 |
+
else:
|
| 941 |
+
raise AssertionError("Shouldn't be able to get here")
|
| 942 |
+
|
| 943 |
+
elif val == 1:
|
| 944 |
+
val = None
|
| 945 |
+
|
| 946 |
+
d.setdefault(cmd, {})[opt] = val
|
| 947 |
+
|
| 948 |
+
return d
|
| 949 |
+
|
| 950 |
+
def iter_distribution_names(self):
|
| 951 |
+
"""Yield all packages, modules, and extension names in distribution"""
|
| 952 |
+
|
| 953 |
+
yield from self.packages or ()
|
| 954 |
+
|
| 955 |
+
yield from self.py_modules or ()
|
| 956 |
+
|
| 957 |
+
for ext in self.ext_modules or ():
|
| 958 |
+
if isinstance(ext, tuple):
|
| 959 |
+
name, _buildinfo = ext
|
| 960 |
+
else:
|
| 961 |
+
name = ext.name
|
| 962 |
+
if name.endswith('module'):
|
| 963 |
+
name = name[:-6]
|
| 964 |
+
yield name
|
| 965 |
+
|
| 966 |
+
def handle_display_options(self, option_order):
|
| 967 |
+
"""If there were any non-global "display-only" options
|
| 968 |
+
(--help-commands or the metadata display options) on the command
|
| 969 |
+
line, display the requested info and return true; else return
|
| 970 |
+
false.
|
| 971 |
+
"""
|
| 972 |
+
import sys
|
| 973 |
+
|
| 974 |
+
if self.help_commands:
|
| 975 |
+
return _Distribution.handle_display_options(self, option_order)
|
| 976 |
+
|
| 977 |
+
# Stdout may be StringIO (e.g. in tests)
|
| 978 |
+
if not isinstance(sys.stdout, io.TextIOWrapper):
|
| 979 |
+
return _Distribution.handle_display_options(self, option_order)
|
| 980 |
+
|
| 981 |
+
# Don't wrap stdout if utf-8 is already the encoding. Provides
|
| 982 |
+
# workaround for #334.
|
| 983 |
+
if sys.stdout.encoding.lower() in ('utf-8', 'utf8'):
|
| 984 |
+
return _Distribution.handle_display_options(self, option_order)
|
| 985 |
+
|
| 986 |
+
# Print metadata in UTF-8 no matter the platform
|
| 987 |
+
encoding = sys.stdout.encoding
|
| 988 |
+
sys.stdout.reconfigure(encoding='utf-8')
|
| 989 |
+
try:
|
| 990 |
+
return _Distribution.handle_display_options(self, option_order)
|
| 991 |
+
finally:
|
| 992 |
+
sys.stdout.reconfigure(encoding=encoding)
|
| 993 |
+
|
| 994 |
+
def run_command(self, command) -> None:
|
| 995 |
+
self.set_defaults()
|
| 996 |
+
# Postpone defaults until all explicit configuration is considered
|
| 997 |
+
# (setup() args, config files, command line and plugins)
|
| 998 |
+
|
| 999 |
+
super().run_command(command)
|
| 1000 |
+
|
| 1001 |
+
|
| 1002 |
+
class DistDeprecationWarning(SetuptoolsDeprecationWarning):
|
| 1003 |
+
"""Class for warning about deprecations in dist in
|
| 1004 |
+
setuptools. Not ignored by default, unlike DeprecationWarning."""
|
videollama2/lib/python3.10/site-packages/setuptools/extension.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import functools
|
| 4 |
+
import re
|
| 5 |
+
from typing import TYPE_CHECKING
|
| 6 |
+
|
| 7 |
+
from setuptools._path import StrPath
|
| 8 |
+
|
| 9 |
+
from .monkey import get_unpatched
|
| 10 |
+
|
| 11 |
+
import distutils.core
|
| 12 |
+
import distutils.errors
|
| 13 |
+
import distutils.extension
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _have_cython():
|
| 17 |
+
"""
|
| 18 |
+
Return True if Cython can be imported.
|
| 19 |
+
"""
|
| 20 |
+
cython_impl = 'Cython.Distutils.build_ext'
|
| 21 |
+
try:
|
| 22 |
+
# from (cython_impl) import build_ext
|
| 23 |
+
__import__(cython_impl, fromlist=['build_ext']).build_ext
|
| 24 |
+
except Exception:
|
| 25 |
+
return False
|
| 26 |
+
return True
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# for compatibility
|
| 30 |
+
have_pyrex = _have_cython
|
| 31 |
+
if TYPE_CHECKING:
|
| 32 |
+
# Work around a mypy issue where type[T] can't be used as a base: https://github.com/python/mypy/issues/10962
|
| 33 |
+
from distutils.core import Extension as _Extension
|
| 34 |
+
else:
|
| 35 |
+
_Extension = get_unpatched(distutils.core.Extension)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class Extension(_Extension):
|
| 39 |
+
"""
|
| 40 |
+
Describes a single extension module.
|
| 41 |
+
|
| 42 |
+
This means that all source files will be compiled into a single binary file
|
| 43 |
+
``<module path>.<suffix>`` (with ``<module path>`` derived from ``name`` and
|
| 44 |
+
``<suffix>`` defined by one of the values in
|
| 45 |
+
``importlib.machinery.EXTENSION_SUFFIXES``).
|
| 46 |
+
|
| 47 |
+
In the case ``.pyx`` files are passed as ``sources and`` ``Cython`` is **not**
|
| 48 |
+
installed in the build environment, ``setuptools`` may also try to look for the
|
| 49 |
+
equivalent ``.cpp`` or ``.c`` files.
|
| 50 |
+
|
| 51 |
+
:arg str name:
|
| 52 |
+
the full name of the extension, including any packages -- ie.
|
| 53 |
+
*not* a filename or pathname, but Python dotted name
|
| 54 |
+
|
| 55 |
+
:arg list[str|os.PathLike[str]] sources:
|
| 56 |
+
list of source filenames, relative to the distribution root
|
| 57 |
+
(where the setup script lives), in Unix form (slash-separated)
|
| 58 |
+
for portability. Source files may be C, C++, SWIG (.i),
|
| 59 |
+
platform-specific resource files, or whatever else is recognized
|
| 60 |
+
by the "build_ext" command as source for a Python extension.
|
| 61 |
+
|
| 62 |
+
:keyword list[str] include_dirs:
|
| 63 |
+
list of directories to search for C/C++ header files (in Unix
|
| 64 |
+
form for portability)
|
| 65 |
+
|
| 66 |
+
:keyword list[tuple[str, str|None]] define_macros:
|
| 67 |
+
list of macros to define; each macro is defined using a 2-tuple:
|
| 68 |
+
the first item corresponding to the name of the macro and the second
|
| 69 |
+
item either a string with its value or None to
|
| 70 |
+
define it without a particular value (equivalent of "#define
|
| 71 |
+
FOO" in source or -DFOO on Unix C compiler command line)
|
| 72 |
+
|
| 73 |
+
:keyword list[str] undef_macros:
|
| 74 |
+
list of macros to undefine explicitly
|
| 75 |
+
|
| 76 |
+
:keyword list[str] library_dirs:
|
| 77 |
+
list of directories to search for C/C++ libraries at link time
|
| 78 |
+
|
| 79 |
+
:keyword list[str] libraries:
|
| 80 |
+
list of library names (not filenames or paths) to link against
|
| 81 |
+
|
| 82 |
+
:keyword list[str] runtime_library_dirs:
|
| 83 |
+
list of directories to search for C/C++ libraries at run time
|
| 84 |
+
(for shared extensions, this is when the extension is loaded).
|
| 85 |
+
Setting this will cause an exception during build on Windows
|
| 86 |
+
platforms.
|
| 87 |
+
|
| 88 |
+
:keyword list[str] extra_objects:
|
| 89 |
+
list of extra files to link with (eg. object files not implied
|
| 90 |
+
by 'sources', static library that must be explicitly specified,
|
| 91 |
+
binary resource files, etc.)
|
| 92 |
+
|
| 93 |
+
:keyword list[str] extra_compile_args:
|
| 94 |
+
any extra platform- and compiler-specific information to use
|
| 95 |
+
when compiling the source files in 'sources'. For platforms and
|
| 96 |
+
compilers where "command line" makes sense, this is typically a
|
| 97 |
+
list of command-line arguments, but for other platforms it could
|
| 98 |
+
be anything.
|
| 99 |
+
|
| 100 |
+
:keyword list[str] extra_link_args:
|
| 101 |
+
any extra platform- and compiler-specific information to use
|
| 102 |
+
when linking object files together to create the extension (or
|
| 103 |
+
to create a new static Python interpreter). Similar
|
| 104 |
+
interpretation as for 'extra_compile_args'.
|
| 105 |
+
|
| 106 |
+
:keyword list[str] export_symbols:
|
| 107 |
+
list of symbols to be exported from a shared extension. Not
|
| 108 |
+
used on all platforms, and not generally necessary for Python
|
| 109 |
+
extensions, which typically export exactly one symbol: "init" +
|
| 110 |
+
extension_name.
|
| 111 |
+
|
| 112 |
+
:keyword list[str] swig_opts:
|
| 113 |
+
any extra options to pass to SWIG if a source file has the .i
|
| 114 |
+
extension.
|
| 115 |
+
|
| 116 |
+
:keyword list[str] depends:
|
| 117 |
+
list of files that the extension depends on
|
| 118 |
+
|
| 119 |
+
:keyword str language:
|
| 120 |
+
extension language (i.e. "c", "c++", "objc"). Will be detected
|
| 121 |
+
from the source extensions if not provided.
|
| 122 |
+
|
| 123 |
+
:keyword bool optional:
|
| 124 |
+
specifies that a build failure in the extension should not abort the
|
| 125 |
+
build process, but simply not install the failing extension.
|
| 126 |
+
|
| 127 |
+
:keyword bool py_limited_api:
|
| 128 |
+
opt-in flag for the usage of :doc:`Python's limited API <python:c-api/stable>`.
|
| 129 |
+
|
| 130 |
+
:raises setuptools.errors.PlatformError: if ``runtime_library_dirs`` is
|
| 131 |
+
specified on Windows. (since v63)
|
| 132 |
+
"""
|
| 133 |
+
|
| 134 |
+
# These 4 are set and used in setuptools/command/build_ext.py
|
| 135 |
+
# The lack of a default value and risk of `AttributeError` is purposeful
|
| 136 |
+
# to avoid people forgetting to call finalize_options if they modify the extension list.
|
| 137 |
+
# See example/rationale in https://github.com/pypa/setuptools/issues/4529.
|
| 138 |
+
_full_name: str #: Private API, internal use only.
|
| 139 |
+
_links_to_dynamic: bool #: Private API, internal use only.
|
| 140 |
+
_needs_stub: bool #: Private API, internal use only.
|
| 141 |
+
_file_name: str #: Private API, internal use only.
|
| 142 |
+
|
| 143 |
+
def __init__(
|
| 144 |
+
self,
|
| 145 |
+
name: str,
|
| 146 |
+
sources: list[StrPath],
|
| 147 |
+
*args,
|
| 148 |
+
py_limited_api: bool = False,
|
| 149 |
+
**kw,
|
| 150 |
+
) -> None:
|
| 151 |
+
# The *args is needed for compatibility as calls may use positional
|
| 152 |
+
# arguments. py_limited_api may be set only via keyword.
|
| 153 |
+
self.py_limited_api = py_limited_api
|
| 154 |
+
super().__init__(
|
| 155 |
+
name,
|
| 156 |
+
sources, # type: ignore[arg-type] # Vendored version of setuptools supports PathLike
|
| 157 |
+
*args,
|
| 158 |
+
**kw,
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
def _convert_pyx_sources_to_lang(self):
|
| 162 |
+
"""
|
| 163 |
+
Replace sources with .pyx extensions to sources with the target
|
| 164 |
+
language extension. This mechanism allows language authors to supply
|
| 165 |
+
pre-converted sources but to prefer the .pyx sources.
|
| 166 |
+
"""
|
| 167 |
+
if _have_cython():
|
| 168 |
+
# the build has Cython, so allow it to compile the .pyx files
|
| 169 |
+
return
|
| 170 |
+
lang = self.language or ''
|
| 171 |
+
target_ext = '.cpp' if lang.lower() == 'c++' else '.c'
|
| 172 |
+
sub = functools.partial(re.sub, '.pyx$', target_ext)
|
| 173 |
+
self.sources = list(map(sub, self.sources))
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
class Library(Extension):
|
| 177 |
+
"""Just like a regular Extension, but built as a library instead"""
|
videollama2/lib/python3.10/site-packages/setuptools/glob.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Filename globbing utility. Mostly a copy of `glob` from Python 3.5.
|
| 3 |
+
|
| 4 |
+
Changes include:
|
| 5 |
+
* `yield from` and PEP3102 `*` removed.
|
| 6 |
+
* Hidden files are not ignored.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import fnmatch
|
| 12 |
+
import os
|
| 13 |
+
import re
|
| 14 |
+
from collections.abc import Iterable, Iterator
|
| 15 |
+
from typing import TYPE_CHECKING, AnyStr, overload
|
| 16 |
+
|
| 17 |
+
if TYPE_CHECKING:
|
| 18 |
+
from _typeshed import BytesPath, StrOrBytesPath, StrPath
|
| 19 |
+
|
| 20 |
+
__all__ = ["glob", "iglob", "escape"]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def glob(pathname: AnyStr, recursive: bool = False) -> list[AnyStr]:
|
| 24 |
+
"""Return a list of paths matching a pathname pattern.
|
| 25 |
+
|
| 26 |
+
The pattern may contain simple shell-style wildcards a la
|
| 27 |
+
fnmatch. However, unlike fnmatch, filenames starting with a
|
| 28 |
+
dot are special cases that are not matched by '*' and '?'
|
| 29 |
+
patterns.
|
| 30 |
+
|
| 31 |
+
If recursive is true, the pattern '**' will match any files and
|
| 32 |
+
zero or more directories and subdirectories.
|
| 33 |
+
"""
|
| 34 |
+
return list(iglob(pathname, recursive=recursive))
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def iglob(pathname: AnyStr, recursive: bool = False) -> Iterator[AnyStr]:
|
| 38 |
+
"""Return an iterator which yields the paths matching a pathname pattern.
|
| 39 |
+
|
| 40 |
+
The pattern may contain simple shell-style wildcards a la
|
| 41 |
+
fnmatch. However, unlike fnmatch, filenames starting with a
|
| 42 |
+
dot are special cases that are not matched by '*' and '?'
|
| 43 |
+
patterns.
|
| 44 |
+
|
| 45 |
+
If recursive is true, the pattern '**' will match any files and
|
| 46 |
+
zero or more directories and subdirectories.
|
| 47 |
+
"""
|
| 48 |
+
it = _iglob(pathname, recursive)
|
| 49 |
+
if recursive and _isrecursive(pathname):
|
| 50 |
+
s = next(it) # skip empty string
|
| 51 |
+
assert not s
|
| 52 |
+
return it
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _iglob(pathname: AnyStr, recursive: bool) -> Iterator[AnyStr]:
|
| 56 |
+
dirname, basename = os.path.split(pathname)
|
| 57 |
+
glob_in_dir = glob2 if recursive and _isrecursive(basename) else glob1
|
| 58 |
+
|
| 59 |
+
if not has_magic(pathname):
|
| 60 |
+
if basename:
|
| 61 |
+
if os.path.lexists(pathname):
|
| 62 |
+
yield pathname
|
| 63 |
+
else:
|
| 64 |
+
# Patterns ending with a slash should match only directories
|
| 65 |
+
if os.path.isdir(dirname):
|
| 66 |
+
yield pathname
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
if not dirname:
|
| 70 |
+
yield from glob_in_dir(dirname, basename)
|
| 71 |
+
return
|
| 72 |
+
# `os.path.split()` returns the argument itself as a dirname if it is a
|
| 73 |
+
# drive or UNC path. Prevent an infinite recursion if a drive or UNC path
|
| 74 |
+
# contains magic characters (i.e. r'\\?\C:').
|
| 75 |
+
if dirname != pathname and has_magic(dirname):
|
| 76 |
+
dirs: Iterable[AnyStr] = _iglob(dirname, recursive)
|
| 77 |
+
else:
|
| 78 |
+
dirs = [dirname]
|
| 79 |
+
if not has_magic(basename):
|
| 80 |
+
glob_in_dir = glob0
|
| 81 |
+
for dirname in dirs:
|
| 82 |
+
for name in glob_in_dir(dirname, basename):
|
| 83 |
+
yield os.path.join(dirname, name)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
# These 2 helper functions non-recursively glob inside a literal directory.
|
| 87 |
+
# They return a list of basenames. `glob1` accepts a pattern while `glob0`
|
| 88 |
+
# takes a literal basename (so it only has to check for its existence).
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
@overload
|
| 92 |
+
def glob1(dirname: StrPath, pattern: str) -> list[str]: ...
|
| 93 |
+
@overload
|
| 94 |
+
def glob1(dirname: BytesPath, pattern: bytes) -> list[bytes]: ...
|
| 95 |
+
def glob1(dirname: StrOrBytesPath, pattern: str | bytes) -> list[str] | list[bytes]:
|
| 96 |
+
if not dirname:
|
| 97 |
+
if isinstance(pattern, bytes):
|
| 98 |
+
dirname = os.curdir.encode('ASCII')
|
| 99 |
+
else:
|
| 100 |
+
dirname = os.curdir
|
| 101 |
+
try:
|
| 102 |
+
names = os.listdir(dirname)
|
| 103 |
+
except OSError:
|
| 104 |
+
return []
|
| 105 |
+
# mypy false-positives: str or bytes type possibility is always kept in sync
|
| 106 |
+
return fnmatch.filter(names, pattern) # type: ignore[type-var, return-value]
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def glob0(dirname, basename):
|
| 110 |
+
if not basename:
|
| 111 |
+
# `os.path.split()` returns an empty basename for paths ending with a
|
| 112 |
+
# directory separator. 'q*x/' should match only directories.
|
| 113 |
+
if os.path.isdir(dirname):
|
| 114 |
+
return [basename]
|
| 115 |
+
else:
|
| 116 |
+
if os.path.lexists(os.path.join(dirname, basename)):
|
| 117 |
+
return [basename]
|
| 118 |
+
return []
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
# This helper function recursively yields relative pathnames inside a literal
|
| 122 |
+
# directory.
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
@overload
|
| 126 |
+
def glob2(dirname: StrPath, pattern: str) -> Iterator[str]: ...
|
| 127 |
+
@overload
|
| 128 |
+
def glob2(dirname: BytesPath, pattern: bytes) -> Iterator[bytes]: ...
|
| 129 |
+
def glob2(dirname: StrOrBytesPath, pattern: str | bytes) -> Iterator[str | bytes]:
|
| 130 |
+
assert _isrecursive(pattern)
|
| 131 |
+
yield pattern[:0]
|
| 132 |
+
yield from _rlistdir(dirname)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
# Recursively yields relative pathnames inside a literal directory.
|
| 136 |
+
@overload
|
| 137 |
+
def _rlistdir(dirname: StrPath) -> Iterator[str]: ...
|
| 138 |
+
@overload
|
| 139 |
+
def _rlistdir(dirname: BytesPath) -> Iterator[bytes]: ...
|
| 140 |
+
def _rlistdir(dirname: StrOrBytesPath) -> Iterator[str | bytes]:
|
| 141 |
+
if not dirname:
|
| 142 |
+
if isinstance(dirname, bytes):
|
| 143 |
+
dirname = os.curdir.encode('ASCII')
|
| 144 |
+
else:
|
| 145 |
+
dirname = os.curdir
|
| 146 |
+
try:
|
| 147 |
+
names = os.listdir(dirname)
|
| 148 |
+
except OSError:
|
| 149 |
+
return
|
| 150 |
+
for x in names:
|
| 151 |
+
yield x
|
| 152 |
+
# mypy false-positives: str or bytes type possibility is always kept in sync
|
| 153 |
+
path = os.path.join(dirname, x) if dirname else x # type: ignore[arg-type]
|
| 154 |
+
for y in _rlistdir(path):
|
| 155 |
+
yield os.path.join(x, y) # type: ignore[arg-type]
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
magic_check = re.compile('([*?[])')
|
| 159 |
+
magic_check_bytes = re.compile(b'([*?[])')
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def has_magic(s: str | bytes) -> bool:
|
| 163 |
+
if isinstance(s, bytes):
|
| 164 |
+
return magic_check_bytes.search(s) is not None
|
| 165 |
+
else:
|
| 166 |
+
return magic_check.search(s) is not None
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def _isrecursive(pattern: str | bytes) -> bool:
|
| 170 |
+
if isinstance(pattern, bytes):
|
| 171 |
+
return pattern == b'**'
|
| 172 |
+
else:
|
| 173 |
+
return pattern == '**'
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def escape(pathname):
|
| 177 |
+
"""Escape all special characters."""
|
| 178 |
+
# Escaping is done by wrapping any of "*?[" between square brackets.
|
| 179 |
+
# Metacharacters do not work in the drive part and shouldn't be escaped.
|
| 180 |
+
drive, pathname = os.path.splitdrive(pathname)
|
| 181 |
+
if isinstance(pathname, bytes):
|
| 182 |
+
pathname = magic_check_bytes.sub(rb'[\1]', pathname)
|
| 183 |
+
else:
|
| 184 |
+
pathname = magic_check.sub(r'[\1]', pathname)
|
| 185 |
+
return drive + pathname
|
videollama2/lib/python3.10/site-packages/setuptools/gui.exe
ADDED
|
Binary file (11.8 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/installer.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import glob
|
| 4 |
+
import os
|
| 5 |
+
import subprocess
|
| 6 |
+
import sys
|
| 7 |
+
import tempfile
|
| 8 |
+
from functools import partial
|
| 9 |
+
|
| 10 |
+
from pkg_resources import Distribution
|
| 11 |
+
|
| 12 |
+
from . import _reqs
|
| 13 |
+
from ._reqs import _StrOrIter
|
| 14 |
+
from .warnings import SetuptoolsDeprecationWarning
|
| 15 |
+
from .wheel import Wheel
|
| 16 |
+
|
| 17 |
+
from distutils import log
|
| 18 |
+
from distutils.errors import DistutilsError
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _fixup_find_links(find_links):
|
| 22 |
+
"""Ensure find-links option end-up being a list of strings."""
|
| 23 |
+
if isinstance(find_links, str):
|
| 24 |
+
return find_links.split()
|
| 25 |
+
assert isinstance(find_links, (tuple, list))
|
| 26 |
+
return find_links
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def fetch_build_egg(dist, req):
|
| 30 |
+
"""Fetch an egg needed for building.
|
| 31 |
+
|
| 32 |
+
Use pip/wheel to fetch/build a wheel."""
|
| 33 |
+
_DeprecatedInstaller.emit()
|
| 34 |
+
_warn_wheel_not_available(dist)
|
| 35 |
+
return _fetch_build_egg_no_warn(dist, req)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _fetch_build_eggs(dist, requires: _StrOrIter) -> list[Distribution]:
|
| 39 |
+
import pkg_resources # Delay import to avoid unnecessary side-effects
|
| 40 |
+
|
| 41 |
+
_DeprecatedInstaller.emit(stacklevel=3)
|
| 42 |
+
_warn_wheel_not_available(dist)
|
| 43 |
+
|
| 44 |
+
resolved_dists = pkg_resources.working_set.resolve(
|
| 45 |
+
_reqs.parse(requires, pkg_resources.Requirement), # required for compatibility
|
| 46 |
+
installer=partial(_fetch_build_egg_no_warn, dist), # avoid warning twice
|
| 47 |
+
replace_conflicting=True,
|
| 48 |
+
)
|
| 49 |
+
for dist in resolved_dists:
|
| 50 |
+
pkg_resources.working_set.add(dist, replace=True)
|
| 51 |
+
return resolved_dists
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _fetch_build_egg_no_warn(dist, req): # noqa: C901 # is too complex (16) # FIXME
|
| 55 |
+
import pkg_resources # Delay import to avoid unnecessary side-effects
|
| 56 |
+
|
| 57 |
+
# Ignore environment markers; if supplied, it is required.
|
| 58 |
+
req = strip_marker(req)
|
| 59 |
+
# Take easy_install options into account, but do not override relevant
|
| 60 |
+
# pip environment variables (like PIP_INDEX_URL or PIP_QUIET); they'll
|
| 61 |
+
# take precedence.
|
| 62 |
+
opts = dist.get_option_dict('easy_install')
|
| 63 |
+
if 'allow_hosts' in opts:
|
| 64 |
+
raise DistutilsError(
|
| 65 |
+
'the `allow-hosts` option is not supported '
|
| 66 |
+
'when using pip to install requirements.'
|
| 67 |
+
)
|
| 68 |
+
quiet = 'PIP_QUIET' not in os.environ and 'PIP_VERBOSE' not in os.environ
|
| 69 |
+
if 'PIP_INDEX_URL' in os.environ:
|
| 70 |
+
index_url = None
|
| 71 |
+
elif 'index_url' in opts:
|
| 72 |
+
index_url = opts['index_url'][1]
|
| 73 |
+
else:
|
| 74 |
+
index_url = None
|
| 75 |
+
find_links = (
|
| 76 |
+
_fixup_find_links(opts['find_links'][1])[:] if 'find_links' in opts else []
|
| 77 |
+
)
|
| 78 |
+
if dist.dependency_links:
|
| 79 |
+
find_links.extend(dist.dependency_links)
|
| 80 |
+
eggs_dir = os.path.realpath(dist.get_egg_cache_dir())
|
| 81 |
+
environment = pkg_resources.Environment()
|
| 82 |
+
for egg_dist in pkg_resources.find_distributions(eggs_dir):
|
| 83 |
+
if egg_dist in req and environment.can_add(egg_dist):
|
| 84 |
+
return egg_dist
|
| 85 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
| 86 |
+
cmd = [
|
| 87 |
+
sys.executable,
|
| 88 |
+
'-m',
|
| 89 |
+
'pip',
|
| 90 |
+
'--disable-pip-version-check',
|
| 91 |
+
'wheel',
|
| 92 |
+
'--no-deps',
|
| 93 |
+
'-w',
|
| 94 |
+
tmpdir,
|
| 95 |
+
]
|
| 96 |
+
if quiet:
|
| 97 |
+
cmd.append('--quiet')
|
| 98 |
+
if index_url is not None:
|
| 99 |
+
cmd.extend(('--index-url', index_url))
|
| 100 |
+
for link in find_links or []:
|
| 101 |
+
cmd.extend(('--find-links', link))
|
| 102 |
+
# If requirement is a PEP 508 direct URL, directly pass
|
| 103 |
+
# the URL to pip, as `req @ url` does not work on the
|
| 104 |
+
# command line.
|
| 105 |
+
cmd.append(req.url or str(req))
|
| 106 |
+
try:
|
| 107 |
+
subprocess.check_call(cmd)
|
| 108 |
+
except subprocess.CalledProcessError as e:
|
| 109 |
+
raise DistutilsError(str(e)) from e
|
| 110 |
+
wheel = Wheel(glob.glob(os.path.join(tmpdir, '*.whl'))[0])
|
| 111 |
+
dist_location = os.path.join(eggs_dir, wheel.egg_name())
|
| 112 |
+
wheel.install_as_egg(dist_location)
|
| 113 |
+
dist_metadata = pkg_resources.PathMetadata(
|
| 114 |
+
dist_location, os.path.join(dist_location, 'EGG-INFO')
|
| 115 |
+
)
|
| 116 |
+
return pkg_resources.Distribution.from_filename(
|
| 117 |
+
dist_location, metadata=dist_metadata
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def strip_marker(req):
|
| 122 |
+
"""
|
| 123 |
+
Return a new requirement without the environment marker to avoid
|
| 124 |
+
calling pip with something like `babel; extra == "i18n"`, which
|
| 125 |
+
would always be ignored.
|
| 126 |
+
"""
|
| 127 |
+
import pkg_resources # Delay import to avoid unnecessary side-effects
|
| 128 |
+
|
| 129 |
+
# create a copy to avoid mutating the input
|
| 130 |
+
req = pkg_resources.Requirement.parse(str(req))
|
| 131 |
+
req.marker = None
|
| 132 |
+
return req
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _warn_wheel_not_available(dist):
|
| 136 |
+
import pkg_resources # Delay import to avoid unnecessary side-effects
|
| 137 |
+
|
| 138 |
+
try:
|
| 139 |
+
pkg_resources.get_distribution('wheel')
|
| 140 |
+
except pkg_resources.DistributionNotFound:
|
| 141 |
+
dist.announce('WARNING: The wheel package is not available.', log.WARN)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class _DeprecatedInstaller(SetuptoolsDeprecationWarning):
|
| 145 |
+
_SUMMARY = "setuptools.installer and fetch_build_eggs are deprecated."
|
| 146 |
+
_DETAILS = """
|
| 147 |
+
Requirements should be satisfied by a PEP 517 installer.
|
| 148 |
+
If you are using pip, you can try `pip install --use-pep517`.
|
| 149 |
+
"""
|
| 150 |
+
# _DUE_DATE not decided yet
|
videollama2/lib/python3.10/site-packages/setuptools/launch.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Launch the Python script on the command line after
|
| 3 |
+
setuptools is bootstrapped via import.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
# Note that setuptools gets imported implicitly by the
|
| 7 |
+
# invocation of this script using python -m setuptools.launch
|
| 8 |
+
|
| 9 |
+
import sys
|
| 10 |
+
import tokenize
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def run() -> None:
|
| 14 |
+
"""
|
| 15 |
+
Run the script in sys.argv[1] as if it had
|
| 16 |
+
been invoked naturally.
|
| 17 |
+
"""
|
| 18 |
+
__builtins__
|
| 19 |
+
script_name = sys.argv[1]
|
| 20 |
+
namespace = dict(
|
| 21 |
+
__file__=script_name,
|
| 22 |
+
__name__='__main__',
|
| 23 |
+
__doc__=None,
|
| 24 |
+
)
|
| 25 |
+
sys.argv[:] = sys.argv[1:]
|
| 26 |
+
|
| 27 |
+
open_ = getattr(tokenize, 'open', open)
|
| 28 |
+
with open_(script_name) as fid:
|
| 29 |
+
script = fid.read()
|
| 30 |
+
norm_script = script.replace('\\r\\n', '\\n')
|
| 31 |
+
code = compile(norm_script, script_name, 'exec')
|
| 32 |
+
exec(code, namespace)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if __name__ == '__main__':
|
| 36 |
+
run()
|
videollama2/lib/python3.10/site-packages/setuptools/logging.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import inspect
|
| 2 |
+
import logging
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
from . import monkey
|
| 6 |
+
|
| 7 |
+
import distutils.log
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _not_warning(record):
|
| 11 |
+
return record.levelno < logging.WARNING
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def configure() -> None:
|
| 15 |
+
"""
|
| 16 |
+
Configure logging to emit warning and above to stderr
|
| 17 |
+
and everything else to stdout. This behavior is provided
|
| 18 |
+
for compatibility with distutils.log but may change in
|
| 19 |
+
the future.
|
| 20 |
+
"""
|
| 21 |
+
err_handler = logging.StreamHandler()
|
| 22 |
+
err_handler.setLevel(logging.WARNING)
|
| 23 |
+
out_handler = logging.StreamHandler(sys.stdout)
|
| 24 |
+
out_handler.addFilter(_not_warning)
|
| 25 |
+
handlers = err_handler, out_handler
|
| 26 |
+
logging.basicConfig(
|
| 27 |
+
format="{message}", style='{', handlers=handlers, level=logging.DEBUG
|
| 28 |
+
)
|
| 29 |
+
if inspect.ismodule(distutils.dist.log):
|
| 30 |
+
monkey.patch_func(set_threshold, distutils.log, 'set_threshold')
|
| 31 |
+
# For some reason `distutils.log` module is getting cached in `distutils.dist`
|
| 32 |
+
# and then loaded again when patched,
|
| 33 |
+
# implying: id(distutils.log) != id(distutils.dist.log).
|
| 34 |
+
# Make sure the same module object is used everywhere:
|
| 35 |
+
distutils.dist.log = distutils.log
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def set_threshold(level: int) -> int:
|
| 39 |
+
logging.root.setLevel(level * 10)
|
| 40 |
+
return set_threshold.unpatched(level)
|
videollama2/lib/python3.10/site-packages/setuptools/modified.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
# Ensure a DistutilsError raised by these methods is the same as distutils.errors.DistutilsError
|
| 3 |
+
from distutils._modified import (
|
| 4 |
+
newer,
|
| 5 |
+
newer_group,
|
| 6 |
+
newer_pairwise,
|
| 7 |
+
newer_pairwise_group,
|
| 8 |
+
)
|
| 9 |
+
except ImportError:
|
| 10 |
+
# fallback for SETUPTOOLS_USE_DISTUTILS=stdlib, because _modified never existed in stdlib
|
| 11 |
+
from ._distutils._modified import (
|
| 12 |
+
newer,
|
| 13 |
+
newer_group,
|
| 14 |
+
newer_pairwise,
|
| 15 |
+
newer_pairwise_group,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
__all__ = ['newer', 'newer_pairwise', 'newer_group', 'newer_pairwise_group']
|
videollama2/lib/python3.10/site-packages/setuptools/sandbox.py
ADDED
|
@@ -0,0 +1,536 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 4 |
+
import contextlib
|
| 5 |
+
import functools
|
| 6 |
+
import itertools
|
| 7 |
+
import operator
|
| 8 |
+
import os
|
| 9 |
+
import pickle
|
| 10 |
+
import re
|
| 11 |
+
import sys
|
| 12 |
+
import tempfile
|
| 13 |
+
import textwrap
|
| 14 |
+
from types import TracebackType
|
| 15 |
+
from typing import TYPE_CHECKING, Any, ClassVar
|
| 16 |
+
|
| 17 |
+
import pkg_resources
|
| 18 |
+
from pkg_resources import working_set
|
| 19 |
+
|
| 20 |
+
from distutils.errors import DistutilsError
|
| 21 |
+
|
| 22 |
+
if TYPE_CHECKING:
|
| 23 |
+
import os as _os
|
| 24 |
+
elif sys.platform.startswith('java'):
|
| 25 |
+
import org.python.modules.posix.PosixModule as _os # pyright: ignore[reportMissingImports]
|
| 26 |
+
else:
|
| 27 |
+
_os = sys.modules[os.name]
|
| 28 |
+
_open = open
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
if TYPE_CHECKING:
|
| 32 |
+
from typing_extensions import Self
|
| 33 |
+
|
| 34 |
+
__all__ = [
|
| 35 |
+
"AbstractSandbox",
|
| 36 |
+
"DirectorySandbox",
|
| 37 |
+
"SandboxViolation",
|
| 38 |
+
"run_setup",
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def _execfile(filename, globals, locals=None):
|
| 43 |
+
"""
|
| 44 |
+
Python 3 implementation of execfile.
|
| 45 |
+
"""
|
| 46 |
+
mode = 'rb'
|
| 47 |
+
with open(filename, mode) as stream:
|
| 48 |
+
script = stream.read()
|
| 49 |
+
if locals is None:
|
| 50 |
+
locals = globals
|
| 51 |
+
code = compile(script, filename, 'exec')
|
| 52 |
+
exec(code, globals, locals)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@contextlib.contextmanager
|
| 56 |
+
def save_argv(repl=None):
|
| 57 |
+
saved = sys.argv[:]
|
| 58 |
+
if repl is not None:
|
| 59 |
+
sys.argv[:] = repl
|
| 60 |
+
try:
|
| 61 |
+
yield saved
|
| 62 |
+
finally:
|
| 63 |
+
sys.argv[:] = saved
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@contextlib.contextmanager
|
| 67 |
+
def save_path():
|
| 68 |
+
saved = sys.path[:]
|
| 69 |
+
try:
|
| 70 |
+
yield saved
|
| 71 |
+
finally:
|
| 72 |
+
sys.path[:] = saved
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
@contextlib.contextmanager
|
| 76 |
+
def override_temp(replacement):
|
| 77 |
+
"""
|
| 78 |
+
Monkey-patch tempfile.tempdir with replacement, ensuring it exists
|
| 79 |
+
"""
|
| 80 |
+
os.makedirs(replacement, exist_ok=True)
|
| 81 |
+
|
| 82 |
+
saved = tempfile.tempdir
|
| 83 |
+
|
| 84 |
+
tempfile.tempdir = replacement
|
| 85 |
+
|
| 86 |
+
try:
|
| 87 |
+
yield
|
| 88 |
+
finally:
|
| 89 |
+
tempfile.tempdir = saved
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
@contextlib.contextmanager
|
| 93 |
+
def pushd(target):
|
| 94 |
+
saved = os.getcwd()
|
| 95 |
+
os.chdir(target)
|
| 96 |
+
try:
|
| 97 |
+
yield saved
|
| 98 |
+
finally:
|
| 99 |
+
os.chdir(saved)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class UnpickleableException(Exception):
|
| 103 |
+
"""
|
| 104 |
+
An exception representing another Exception that could not be pickled.
|
| 105 |
+
"""
|
| 106 |
+
|
| 107 |
+
@staticmethod
|
| 108 |
+
def dump(type, exc):
|
| 109 |
+
"""
|
| 110 |
+
Always return a dumped (pickled) type and exc. If exc can't be pickled,
|
| 111 |
+
wrap it in UnpickleableException first.
|
| 112 |
+
"""
|
| 113 |
+
try:
|
| 114 |
+
return pickle.dumps(type), pickle.dumps(exc)
|
| 115 |
+
except Exception:
|
| 116 |
+
# get UnpickleableException inside the sandbox
|
| 117 |
+
from setuptools.sandbox import UnpickleableException as cls
|
| 118 |
+
|
| 119 |
+
return cls.dump(cls, cls(repr(exc)))
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
class ExceptionSaver:
|
| 123 |
+
"""
|
| 124 |
+
A Context Manager that will save an exception, serialize, and restore it
|
| 125 |
+
later.
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
def __enter__(self) -> Self:
|
| 129 |
+
return self
|
| 130 |
+
|
| 131 |
+
def __exit__(
|
| 132 |
+
self,
|
| 133 |
+
type: type[BaseException] | None,
|
| 134 |
+
exc: BaseException | None,
|
| 135 |
+
tb: TracebackType | None,
|
| 136 |
+
) -> bool:
|
| 137 |
+
if not exc:
|
| 138 |
+
return False
|
| 139 |
+
|
| 140 |
+
# dump the exception
|
| 141 |
+
self._saved = UnpickleableException.dump(type, exc)
|
| 142 |
+
self._tb = tb
|
| 143 |
+
|
| 144 |
+
# suppress the exception
|
| 145 |
+
return True
|
| 146 |
+
|
| 147 |
+
def resume(self):
|
| 148 |
+
"restore and re-raise any exception"
|
| 149 |
+
|
| 150 |
+
if '_saved' not in vars(self):
|
| 151 |
+
return
|
| 152 |
+
|
| 153 |
+
_type, exc = map(pickle.loads, self._saved)
|
| 154 |
+
raise exc.with_traceback(self._tb)
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
@contextlib.contextmanager
|
| 158 |
+
def save_modules():
|
| 159 |
+
"""
|
| 160 |
+
Context in which imported modules are saved.
|
| 161 |
+
|
| 162 |
+
Translates exceptions internal to the context into the equivalent exception
|
| 163 |
+
outside the context.
|
| 164 |
+
"""
|
| 165 |
+
saved = sys.modules.copy()
|
| 166 |
+
with ExceptionSaver() as saved_exc:
|
| 167 |
+
yield saved
|
| 168 |
+
|
| 169 |
+
sys.modules.update(saved)
|
| 170 |
+
# remove any modules imported since
|
| 171 |
+
del_modules = (
|
| 172 |
+
mod_name
|
| 173 |
+
for mod_name in sys.modules
|
| 174 |
+
if mod_name not in saved
|
| 175 |
+
# exclude any encodings modules. See #285
|
| 176 |
+
and not mod_name.startswith('encodings.')
|
| 177 |
+
)
|
| 178 |
+
_clear_modules(del_modules)
|
| 179 |
+
|
| 180 |
+
saved_exc.resume()
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def _clear_modules(module_names):
|
| 184 |
+
for mod_name in list(module_names):
|
| 185 |
+
del sys.modules[mod_name]
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
@contextlib.contextmanager
|
| 189 |
+
def save_pkg_resources_state():
|
| 190 |
+
saved = pkg_resources.__getstate__()
|
| 191 |
+
try:
|
| 192 |
+
yield saved
|
| 193 |
+
finally:
|
| 194 |
+
pkg_resources.__setstate__(saved)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
@contextlib.contextmanager
|
| 198 |
+
def setup_context(setup_dir):
|
| 199 |
+
temp_dir = os.path.join(setup_dir, 'temp')
|
| 200 |
+
with save_pkg_resources_state():
|
| 201 |
+
with save_modules():
|
| 202 |
+
with save_path():
|
| 203 |
+
hide_setuptools()
|
| 204 |
+
with save_argv():
|
| 205 |
+
with override_temp(temp_dir):
|
| 206 |
+
with pushd(setup_dir):
|
| 207 |
+
# ensure setuptools commands are available
|
| 208 |
+
__import__('setuptools')
|
| 209 |
+
yield
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
_MODULES_TO_HIDE = {
|
| 213 |
+
'setuptools',
|
| 214 |
+
'distutils',
|
| 215 |
+
'pkg_resources',
|
| 216 |
+
'Cython',
|
| 217 |
+
'_distutils_hack',
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def _needs_hiding(mod_name):
|
| 222 |
+
"""
|
| 223 |
+
>>> _needs_hiding('setuptools')
|
| 224 |
+
True
|
| 225 |
+
>>> _needs_hiding('pkg_resources')
|
| 226 |
+
True
|
| 227 |
+
>>> _needs_hiding('setuptools_plugin')
|
| 228 |
+
False
|
| 229 |
+
>>> _needs_hiding('setuptools.__init__')
|
| 230 |
+
True
|
| 231 |
+
>>> _needs_hiding('distutils')
|
| 232 |
+
True
|
| 233 |
+
>>> _needs_hiding('os')
|
| 234 |
+
False
|
| 235 |
+
>>> _needs_hiding('Cython')
|
| 236 |
+
True
|
| 237 |
+
"""
|
| 238 |
+
base_module = mod_name.split('.', 1)[0]
|
| 239 |
+
return base_module in _MODULES_TO_HIDE
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def hide_setuptools():
|
| 243 |
+
"""
|
| 244 |
+
Remove references to setuptools' modules from sys.modules to allow the
|
| 245 |
+
invocation to import the most appropriate setuptools. This technique is
|
| 246 |
+
necessary to avoid issues such as #315 where setuptools upgrading itself
|
| 247 |
+
would fail to find a function declared in the metadata.
|
| 248 |
+
"""
|
| 249 |
+
_distutils_hack = sys.modules.get('_distutils_hack', None)
|
| 250 |
+
if _distutils_hack is not None:
|
| 251 |
+
_distutils_hack._remove_shim()
|
| 252 |
+
|
| 253 |
+
modules = filter(_needs_hiding, sys.modules)
|
| 254 |
+
_clear_modules(modules)
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def run_setup(setup_script, args):
|
| 258 |
+
"""Run a distutils setup script, sandboxed in its directory"""
|
| 259 |
+
setup_dir = os.path.abspath(os.path.dirname(setup_script))
|
| 260 |
+
with setup_context(setup_dir):
|
| 261 |
+
try:
|
| 262 |
+
sys.argv[:] = [setup_script] + list(args)
|
| 263 |
+
sys.path.insert(0, setup_dir)
|
| 264 |
+
# reset to include setup dir, w/clean callback list
|
| 265 |
+
working_set.__init__()
|
| 266 |
+
working_set.callbacks.append(lambda dist: dist.activate())
|
| 267 |
+
|
| 268 |
+
with DirectorySandbox(setup_dir):
|
| 269 |
+
ns = dict(__file__=setup_script, __name__='__main__')
|
| 270 |
+
_execfile(setup_script, ns)
|
| 271 |
+
except SystemExit as v:
|
| 272 |
+
if v.args and v.args[0]:
|
| 273 |
+
raise
|
| 274 |
+
# Normal exit, just return
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
class AbstractSandbox:
|
| 278 |
+
"""Wrap 'os' module and 'open()' builtin for virtualizing setup scripts"""
|
| 279 |
+
|
| 280 |
+
_active = False
|
| 281 |
+
|
| 282 |
+
def __init__(self) -> None:
|
| 283 |
+
self._attrs = [
|
| 284 |
+
name
|
| 285 |
+
for name in dir(_os)
|
| 286 |
+
if not name.startswith('_') and hasattr(self, name)
|
| 287 |
+
]
|
| 288 |
+
|
| 289 |
+
def _copy(self, source):
|
| 290 |
+
for name in self._attrs:
|
| 291 |
+
setattr(os, name, getattr(source, name))
|
| 292 |
+
|
| 293 |
+
def __enter__(self) -> None:
|
| 294 |
+
self._copy(self)
|
| 295 |
+
builtins.open = self._open
|
| 296 |
+
self._active = True
|
| 297 |
+
|
| 298 |
+
def __exit__(
|
| 299 |
+
self,
|
| 300 |
+
exc_type: type[BaseException] | None,
|
| 301 |
+
exc_value: BaseException | None,
|
| 302 |
+
traceback: TracebackType | None,
|
| 303 |
+
):
|
| 304 |
+
self._active = False
|
| 305 |
+
builtins.open = _open
|
| 306 |
+
self._copy(_os)
|
| 307 |
+
|
| 308 |
+
def run(self, func):
|
| 309 |
+
"""Run 'func' under os sandboxing"""
|
| 310 |
+
with self:
|
| 311 |
+
return func()
|
| 312 |
+
|
| 313 |
+
def _mk_dual_path_wrapper(name: str): # type: ignore[misc] # https://github.com/pypa/setuptools/pull/4099
|
| 314 |
+
original = getattr(_os, name)
|
| 315 |
+
|
| 316 |
+
def wrap(self, src, dst, *args, **kw):
|
| 317 |
+
if self._active:
|
| 318 |
+
src, dst = self._remap_pair(name, src, dst, *args, **kw)
|
| 319 |
+
return original(src, dst, *args, **kw)
|
| 320 |
+
|
| 321 |
+
return wrap
|
| 322 |
+
|
| 323 |
+
for __name in ["rename", "link", "symlink"]:
|
| 324 |
+
if hasattr(_os, __name):
|
| 325 |
+
locals()[__name] = _mk_dual_path_wrapper(__name)
|
| 326 |
+
|
| 327 |
+
def _mk_single_path_wrapper(name: str, original=None): # type: ignore[misc] # https://github.com/pypa/setuptools/pull/4099
|
| 328 |
+
original = original or getattr(_os, name)
|
| 329 |
+
|
| 330 |
+
def wrap(self, path, *args, **kw):
|
| 331 |
+
if self._active:
|
| 332 |
+
path = self._remap_input(name, path, *args, **kw)
|
| 333 |
+
return original(path, *args, **kw)
|
| 334 |
+
|
| 335 |
+
return wrap
|
| 336 |
+
|
| 337 |
+
_open = _mk_single_path_wrapper('open', _open)
|
| 338 |
+
for __name in [
|
| 339 |
+
"stat",
|
| 340 |
+
"listdir",
|
| 341 |
+
"chdir",
|
| 342 |
+
"open",
|
| 343 |
+
"chmod",
|
| 344 |
+
"chown",
|
| 345 |
+
"mkdir",
|
| 346 |
+
"remove",
|
| 347 |
+
"unlink",
|
| 348 |
+
"rmdir",
|
| 349 |
+
"utime",
|
| 350 |
+
"lchown",
|
| 351 |
+
"chroot",
|
| 352 |
+
"lstat",
|
| 353 |
+
"startfile",
|
| 354 |
+
"mkfifo",
|
| 355 |
+
"mknod",
|
| 356 |
+
"pathconf",
|
| 357 |
+
"access",
|
| 358 |
+
]:
|
| 359 |
+
if hasattr(_os, __name):
|
| 360 |
+
locals()[__name] = _mk_single_path_wrapper(__name)
|
| 361 |
+
|
| 362 |
+
def _mk_single_with_return(name: str): # type: ignore[misc] # https://github.com/pypa/setuptools/pull/4099
|
| 363 |
+
original = getattr(_os, name)
|
| 364 |
+
|
| 365 |
+
def wrap(self, path, *args, **kw):
|
| 366 |
+
if self._active:
|
| 367 |
+
path = self._remap_input(name, path, *args, **kw)
|
| 368 |
+
return self._remap_output(name, original(path, *args, **kw))
|
| 369 |
+
return original(path, *args, **kw)
|
| 370 |
+
|
| 371 |
+
return wrap
|
| 372 |
+
|
| 373 |
+
for __name in ['readlink', 'tempnam']:
|
| 374 |
+
if hasattr(_os, __name):
|
| 375 |
+
locals()[__name] = _mk_single_with_return(__name)
|
| 376 |
+
|
| 377 |
+
def _mk_query(name: str): # type: ignore[misc] # https://github.com/pypa/setuptools/pull/4099
|
| 378 |
+
original = getattr(_os, name)
|
| 379 |
+
|
| 380 |
+
def wrap(self, *args, **kw):
|
| 381 |
+
retval = original(*args, **kw)
|
| 382 |
+
if self._active:
|
| 383 |
+
return self._remap_output(name, retval)
|
| 384 |
+
return retval
|
| 385 |
+
|
| 386 |
+
return wrap
|
| 387 |
+
|
| 388 |
+
for __name in ['getcwd', 'tmpnam']:
|
| 389 |
+
if hasattr(_os, __name):
|
| 390 |
+
locals()[__name] = _mk_query(__name)
|
| 391 |
+
|
| 392 |
+
def _validate_path(self, path):
|
| 393 |
+
"""Called to remap or validate any path, whether input or output"""
|
| 394 |
+
return path
|
| 395 |
+
|
| 396 |
+
def _remap_input(self, operation, path, *args, **kw):
|
| 397 |
+
"""Called for path inputs"""
|
| 398 |
+
return self._validate_path(path)
|
| 399 |
+
|
| 400 |
+
def _remap_output(self, operation, path):
|
| 401 |
+
"""Called for path outputs"""
|
| 402 |
+
return self._validate_path(path)
|
| 403 |
+
|
| 404 |
+
def _remap_pair(self, operation, src, dst, *args, **kw):
|
| 405 |
+
"""Called for path pairs like rename, link, and symlink operations"""
|
| 406 |
+
return (
|
| 407 |
+
self._remap_input(operation + '-from', src, *args, **kw),
|
| 408 |
+
self._remap_input(operation + '-to', dst, *args, **kw),
|
| 409 |
+
)
|
| 410 |
+
|
| 411 |
+
if TYPE_CHECKING:
|
| 412 |
+
# This is a catch-all for all the dynamically created attributes.
|
| 413 |
+
# This isn't public API anyway
|
| 414 |
+
def __getattribute__(self, name: str) -> Any: ...
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
if hasattr(os, 'devnull'):
|
| 418 |
+
_EXCEPTIONS = [os.devnull]
|
| 419 |
+
else:
|
| 420 |
+
_EXCEPTIONS = []
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
class DirectorySandbox(AbstractSandbox):
|
| 424 |
+
"""Restrict operations to a single subdirectory - pseudo-chroot"""
|
| 425 |
+
|
| 426 |
+
write_ops: ClassVar[dict[str, None]] = dict.fromkeys([
|
| 427 |
+
"open",
|
| 428 |
+
"chmod",
|
| 429 |
+
"chown",
|
| 430 |
+
"mkdir",
|
| 431 |
+
"remove",
|
| 432 |
+
"unlink",
|
| 433 |
+
"rmdir",
|
| 434 |
+
"utime",
|
| 435 |
+
"lchown",
|
| 436 |
+
"chroot",
|
| 437 |
+
"mkfifo",
|
| 438 |
+
"mknod",
|
| 439 |
+
"tempnam",
|
| 440 |
+
])
|
| 441 |
+
|
| 442 |
+
_exception_patterns: list[str | re.Pattern] = []
|
| 443 |
+
"exempt writing to paths that match the pattern"
|
| 444 |
+
|
| 445 |
+
def __init__(self, sandbox, exceptions=_EXCEPTIONS) -> None:
|
| 446 |
+
self._sandbox = os.path.normcase(os.path.realpath(sandbox))
|
| 447 |
+
self._prefix = os.path.join(self._sandbox, '')
|
| 448 |
+
self._exceptions = [
|
| 449 |
+
os.path.normcase(os.path.realpath(path)) for path in exceptions
|
| 450 |
+
]
|
| 451 |
+
AbstractSandbox.__init__(self)
|
| 452 |
+
|
| 453 |
+
def _violation(self, operation, *args, **kw):
|
| 454 |
+
from setuptools.sandbox import SandboxViolation
|
| 455 |
+
|
| 456 |
+
raise SandboxViolation(operation, args, kw)
|
| 457 |
+
|
| 458 |
+
def _open(self, path, mode='r', *args, **kw):
|
| 459 |
+
if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
|
| 460 |
+
self._violation("open", path, mode, *args, **kw)
|
| 461 |
+
return _open(path, mode, *args, **kw)
|
| 462 |
+
|
| 463 |
+
def tmpnam(self) -> None:
|
| 464 |
+
self._violation("tmpnam")
|
| 465 |
+
|
| 466 |
+
def _ok(self, path):
|
| 467 |
+
active = self._active
|
| 468 |
+
try:
|
| 469 |
+
self._active = False
|
| 470 |
+
realpath = os.path.normcase(os.path.realpath(path))
|
| 471 |
+
return (
|
| 472 |
+
self._exempted(realpath)
|
| 473 |
+
or realpath == self._sandbox
|
| 474 |
+
or realpath.startswith(self._prefix)
|
| 475 |
+
)
|
| 476 |
+
finally:
|
| 477 |
+
self._active = active
|
| 478 |
+
|
| 479 |
+
def _exempted(self, filepath):
|
| 480 |
+
start_matches = (
|
| 481 |
+
filepath.startswith(exception) for exception in self._exceptions
|
| 482 |
+
)
|
| 483 |
+
pattern_matches = (
|
| 484 |
+
re.match(pattern, filepath) for pattern in self._exception_patterns
|
| 485 |
+
)
|
| 486 |
+
candidates = itertools.chain(start_matches, pattern_matches)
|
| 487 |
+
return any(candidates)
|
| 488 |
+
|
| 489 |
+
def _remap_input(self, operation, path, *args, **kw):
|
| 490 |
+
"""Called for path inputs"""
|
| 491 |
+
if operation in self.write_ops and not self._ok(path):
|
| 492 |
+
self._violation(operation, os.path.realpath(path), *args, **kw)
|
| 493 |
+
return path
|
| 494 |
+
|
| 495 |
+
def _remap_pair(self, operation, src, dst, *args, **kw):
|
| 496 |
+
"""Called for path pairs like rename, link, and symlink operations"""
|
| 497 |
+
if not self._ok(src) or not self._ok(dst):
|
| 498 |
+
self._violation(operation, src, dst, *args, **kw)
|
| 499 |
+
return (src, dst)
|
| 500 |
+
|
| 501 |
+
def open(self, file, flags, mode: int = 0o777, *args, **kw) -> int:
|
| 502 |
+
"""Called for low-level os.open()"""
|
| 503 |
+
if flags & WRITE_FLAGS and not self._ok(file):
|
| 504 |
+
self._violation("os.open", file, flags, mode, *args, **kw)
|
| 505 |
+
return _os.open(file, flags, mode, *args, **kw)
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
WRITE_FLAGS = functools.reduce(
|
| 509 |
+
operator.or_,
|
| 510 |
+
[
|
| 511 |
+
getattr(_os, a, 0)
|
| 512 |
+
for a in "O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARY".split()
|
| 513 |
+
],
|
| 514 |
+
)
|
| 515 |
+
|
| 516 |
+
|
| 517 |
+
class SandboxViolation(DistutilsError):
|
| 518 |
+
"""A setup script attempted to modify the filesystem outside the sandbox"""
|
| 519 |
+
|
| 520 |
+
tmpl = textwrap.dedent(
|
| 521 |
+
"""
|
| 522 |
+
SandboxViolation: {cmd}{args!r} {kwargs}
|
| 523 |
+
|
| 524 |
+
The package setup script has attempted to modify files on your system
|
| 525 |
+
that are not within the EasyInstall build area, and has been aborted.
|
| 526 |
+
|
| 527 |
+
This package cannot be safely installed by EasyInstall, and may not
|
| 528 |
+
support alternate installation locations even if you run its setup
|
| 529 |
+
script by hand. Please inform the package's author and the EasyInstall
|
| 530 |
+
maintainers to find out if a fix or workaround is available.
|
| 531 |
+
"""
|
| 532 |
+
).lstrip()
|
| 533 |
+
|
| 534 |
+
def __str__(self) -> str:
|
| 535 |
+
cmd, args, kwargs = self.args
|
| 536 |
+
return self.tmpl.format(**locals())
|