Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/conda_envs/evalclaw/lib/python3.11/__phello__/__init__.py +7 -0
- data/conda_envs/evalclaw/lib/python3.11/__phello__/spam.py +7 -0
- data/conda_envs/evalclaw/lib/python3.11/collections/__init__.py +1576 -0
- data/conda_envs/evalclaw/lib/python3.11/collections/abc.py +3 -0
- data/conda_envs/evalclaw/lib/python3.11/ctypes/__init__.py +566 -0
- data/conda_envs/evalclaw/lib/python3.11/ctypes/_aix.py +331 -0
- data/conda_envs/evalclaw/lib/python3.11/ctypes/_endian.py +78 -0
- data/conda_envs/evalclaw/lib/python3.11/ctypes/util.py +400 -0
- data/conda_envs/evalclaw/lib/python3.11/ctypes/wintypes.py +202 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/README +11 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/__init__.py +20 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/_msvccompiler.py +546 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/archive_util.py +256 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/bcppcompiler.py +393 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/ccompiler.py +1116 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/cmd.py +403 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/config.py +133 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/core.py +234 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/cygwinccompiler.py +406 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/debug.py +5 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/dep_util.py +92 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/dir_util.py +210 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/dist.py +1256 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/errors.py +97 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/extension.py +241 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/fancy_getopt.py +457 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/file_util.py +238 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/filelist.py +327 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/log.py +77 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/msvc9compiler.py +788 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/msvccompiler.py +642 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/spawn.py +129 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/sysconfig.py +348 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/text_file.py +286 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/unixccompiler.py +330 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/util.py +562 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/version.py +347 -0
- data/conda_envs/evalclaw/lib/python3.11/distutils/versionpredicate.py +166 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/CREDITS.txt +47 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/ChangeLog +1591 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/TODO.txt +210 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/__main__.py +8 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/autocomplete_w.py +498 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/colorizer.py +384 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/config-highlight.def +105 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/config-keys.def +309 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/config.py +916 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/debugger_r.py +390 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/debugobj.py +146 -0
- data/conda_envs/evalclaw/lib/python3.11/idlelib/debugobj_r.py +41 -0
data/conda_envs/evalclaw/lib/python3.11/__phello__/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
initialized = True
|
| 2 |
+
|
| 3 |
+
def main():
|
| 4 |
+
print("Hello world!")
|
| 5 |
+
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
main()
|
data/conda_envs/evalclaw/lib/python3.11/__phello__/spam.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
initialized = True
|
| 2 |
+
|
| 3 |
+
def main():
|
| 4 |
+
print("Hello world!")
|
| 5 |
+
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
main()
|
data/conda_envs/evalclaw/lib/python3.11/collections/__init__.py
ADDED
|
@@ -0,0 +1,1576 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''This module implements specialized container datatypes providing
|
| 2 |
+
alternatives to Python's general purpose built-in containers, dict,
|
| 3 |
+
list, set, and tuple.
|
| 4 |
+
|
| 5 |
+
* namedtuple factory function for creating tuple subclasses with named fields
|
| 6 |
+
* deque list-like container with fast appends and pops on either end
|
| 7 |
+
* ChainMap dict-like class for creating a single view of multiple mappings
|
| 8 |
+
* Counter dict subclass for counting hashable objects
|
| 9 |
+
* OrderedDict dict subclass that remembers the order entries were added
|
| 10 |
+
* defaultdict dict subclass that calls a factory function to supply missing values
|
| 11 |
+
* UserDict wrapper around dictionary objects for easier dict subclassing
|
| 12 |
+
* UserList wrapper around list objects for easier list subclassing
|
| 13 |
+
* UserString wrapper around string objects for easier string subclassing
|
| 14 |
+
|
| 15 |
+
'''
|
| 16 |
+
|
| 17 |
+
__all__ = [
|
| 18 |
+
'ChainMap',
|
| 19 |
+
'Counter',
|
| 20 |
+
'OrderedDict',
|
| 21 |
+
'UserDict',
|
| 22 |
+
'UserList',
|
| 23 |
+
'UserString',
|
| 24 |
+
'defaultdict',
|
| 25 |
+
'deque',
|
| 26 |
+
'namedtuple',
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
import _collections_abc
|
| 30 |
+
import sys as _sys
|
| 31 |
+
|
| 32 |
+
from itertools import chain as _chain
|
| 33 |
+
from itertools import repeat as _repeat
|
| 34 |
+
from itertools import starmap as _starmap
|
| 35 |
+
from keyword import iskeyword as _iskeyword
|
| 36 |
+
from operator import eq as _eq
|
| 37 |
+
from operator import itemgetter as _itemgetter
|
| 38 |
+
from reprlib import recursive_repr as _recursive_repr
|
| 39 |
+
from _weakref import proxy as _proxy
|
| 40 |
+
|
| 41 |
+
try:
|
| 42 |
+
from _collections import deque
|
| 43 |
+
except ImportError:
|
| 44 |
+
pass
|
| 45 |
+
else:
|
| 46 |
+
_collections_abc.MutableSequence.register(deque)
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
from _collections import defaultdict
|
| 50 |
+
except ImportError:
|
| 51 |
+
pass
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
################################################################################
|
| 55 |
+
### OrderedDict
|
| 56 |
+
################################################################################
|
| 57 |
+
|
| 58 |
+
class _OrderedDictKeysView(_collections_abc.KeysView):
|
| 59 |
+
|
| 60 |
+
def __reversed__(self):
|
| 61 |
+
yield from reversed(self._mapping)
|
| 62 |
+
|
| 63 |
+
class _OrderedDictItemsView(_collections_abc.ItemsView):
|
| 64 |
+
|
| 65 |
+
def __reversed__(self):
|
| 66 |
+
for key in reversed(self._mapping):
|
| 67 |
+
yield (key, self._mapping[key])
|
| 68 |
+
|
| 69 |
+
class _OrderedDictValuesView(_collections_abc.ValuesView):
|
| 70 |
+
|
| 71 |
+
def __reversed__(self):
|
| 72 |
+
for key in reversed(self._mapping):
|
| 73 |
+
yield self._mapping[key]
|
| 74 |
+
|
| 75 |
+
class _Link(object):
|
| 76 |
+
__slots__ = 'prev', 'next', 'key', '__weakref__'
|
| 77 |
+
|
| 78 |
+
class OrderedDict(dict):
|
| 79 |
+
'Dictionary that remembers insertion order'
|
| 80 |
+
# An inherited dict maps keys to values.
|
| 81 |
+
# The inherited dict provides __getitem__, __len__, __contains__, and get.
|
| 82 |
+
# The remaining methods are order-aware.
|
| 83 |
+
# Big-O running times for all methods are the same as regular dictionaries.
|
| 84 |
+
|
| 85 |
+
# The internal self.__map dict maps keys to links in a doubly linked list.
|
| 86 |
+
# The circular doubly linked list starts and ends with a sentinel element.
|
| 87 |
+
# The sentinel element never gets deleted (this simplifies the algorithm).
|
| 88 |
+
# The sentinel is in self.__hardroot with a weakref proxy in self.__root.
|
| 89 |
+
# The prev links are weakref proxies (to prevent circular references).
|
| 90 |
+
# Individual links are kept alive by the hard reference in self.__map.
|
| 91 |
+
# Those hard references disappear when a key is deleted from an OrderedDict.
|
| 92 |
+
|
| 93 |
+
def __new__(cls, /, *args, **kwds):
|
| 94 |
+
"Create the ordered dict object and set up the underlying structures."
|
| 95 |
+
self = dict.__new__(cls)
|
| 96 |
+
self.__hardroot = _Link()
|
| 97 |
+
self.__root = root = _proxy(self.__hardroot)
|
| 98 |
+
root.prev = root.next = root
|
| 99 |
+
self.__map = {}
|
| 100 |
+
return self
|
| 101 |
+
|
| 102 |
+
def __init__(self, other=(), /, **kwds):
|
| 103 |
+
'''Initialize an ordered dictionary. The signature is the same as
|
| 104 |
+
regular dictionaries. Keyword argument order is preserved.
|
| 105 |
+
'''
|
| 106 |
+
self.__update(other, **kwds)
|
| 107 |
+
|
| 108 |
+
def __setitem__(self, key, value,
|
| 109 |
+
dict_setitem=dict.__setitem__, proxy=_proxy, Link=_Link):
|
| 110 |
+
'od.__setitem__(i, y) <==> od[i]=y'
|
| 111 |
+
# Setting a new item creates a new link at the end of the linked list,
|
| 112 |
+
# and the inherited dictionary is updated with the new key/value pair.
|
| 113 |
+
if key not in self:
|
| 114 |
+
self.__map[key] = link = Link()
|
| 115 |
+
root = self.__root
|
| 116 |
+
last = root.prev
|
| 117 |
+
link.prev, link.next, link.key = last, root, key
|
| 118 |
+
last.next = link
|
| 119 |
+
root.prev = proxy(link)
|
| 120 |
+
dict_setitem(self, key, value)
|
| 121 |
+
|
| 122 |
+
def __delitem__(self, key, dict_delitem=dict.__delitem__):
|
| 123 |
+
'od.__delitem__(y) <==> del od[y]'
|
| 124 |
+
# Deleting an existing item uses self.__map to find the link which gets
|
| 125 |
+
# removed by updating the links in the predecessor and successor nodes.
|
| 126 |
+
dict_delitem(self, key)
|
| 127 |
+
link = self.__map.pop(key)
|
| 128 |
+
link_prev = link.prev
|
| 129 |
+
link_next = link.next
|
| 130 |
+
link_prev.next = link_next
|
| 131 |
+
link_next.prev = link_prev
|
| 132 |
+
link.prev = None
|
| 133 |
+
link.next = None
|
| 134 |
+
|
| 135 |
+
def __iter__(self):
|
| 136 |
+
'od.__iter__() <==> iter(od)'
|
| 137 |
+
# Traverse the linked list in order.
|
| 138 |
+
root = self.__root
|
| 139 |
+
curr = root.next
|
| 140 |
+
while curr is not root:
|
| 141 |
+
yield curr.key
|
| 142 |
+
curr = curr.next
|
| 143 |
+
|
| 144 |
+
def __reversed__(self):
|
| 145 |
+
'od.__reversed__() <==> reversed(od)'
|
| 146 |
+
# Traverse the linked list in reverse order.
|
| 147 |
+
root = self.__root
|
| 148 |
+
curr = root.prev
|
| 149 |
+
while curr is not root:
|
| 150 |
+
yield curr.key
|
| 151 |
+
curr = curr.prev
|
| 152 |
+
|
| 153 |
+
def clear(self):
|
| 154 |
+
'od.clear() -> None. Remove all items from od.'
|
| 155 |
+
root = self.__root
|
| 156 |
+
root.prev = root.next = root
|
| 157 |
+
self.__map.clear()
|
| 158 |
+
dict.clear(self)
|
| 159 |
+
|
| 160 |
+
def popitem(self, last=True):
|
| 161 |
+
'''Remove and return a (key, value) pair from the dictionary.
|
| 162 |
+
|
| 163 |
+
Pairs are returned in LIFO order if last is true or FIFO order if false.
|
| 164 |
+
'''
|
| 165 |
+
if not self:
|
| 166 |
+
raise KeyError('dictionary is empty')
|
| 167 |
+
root = self.__root
|
| 168 |
+
if last:
|
| 169 |
+
link = root.prev
|
| 170 |
+
link_prev = link.prev
|
| 171 |
+
link_prev.next = root
|
| 172 |
+
root.prev = link_prev
|
| 173 |
+
else:
|
| 174 |
+
link = root.next
|
| 175 |
+
link_next = link.next
|
| 176 |
+
root.next = link_next
|
| 177 |
+
link_next.prev = root
|
| 178 |
+
key = link.key
|
| 179 |
+
del self.__map[key]
|
| 180 |
+
value = dict.pop(self, key)
|
| 181 |
+
return key, value
|
| 182 |
+
|
| 183 |
+
def move_to_end(self, key, last=True):
|
| 184 |
+
'''Move an existing element to the end (or beginning if last is false).
|
| 185 |
+
|
| 186 |
+
Raise KeyError if the element does not exist.
|
| 187 |
+
'''
|
| 188 |
+
link = self.__map[key]
|
| 189 |
+
link_prev = link.prev
|
| 190 |
+
link_next = link.next
|
| 191 |
+
soft_link = link_next.prev
|
| 192 |
+
link_prev.next = link_next
|
| 193 |
+
link_next.prev = link_prev
|
| 194 |
+
root = self.__root
|
| 195 |
+
if last:
|
| 196 |
+
last = root.prev
|
| 197 |
+
link.prev = last
|
| 198 |
+
link.next = root
|
| 199 |
+
root.prev = soft_link
|
| 200 |
+
last.next = link
|
| 201 |
+
else:
|
| 202 |
+
first = root.next
|
| 203 |
+
link.prev = root
|
| 204 |
+
link.next = first
|
| 205 |
+
first.prev = soft_link
|
| 206 |
+
root.next = link
|
| 207 |
+
|
| 208 |
+
def __sizeof__(self):
|
| 209 |
+
sizeof = _sys.getsizeof
|
| 210 |
+
n = len(self) + 1 # number of links including root
|
| 211 |
+
size = sizeof(self.__dict__) # instance dictionary
|
| 212 |
+
size += sizeof(self.__map) * 2 # internal dict and inherited dict
|
| 213 |
+
size += sizeof(self.__hardroot) * n # link objects
|
| 214 |
+
size += sizeof(self.__root) * n # proxy objects
|
| 215 |
+
return size
|
| 216 |
+
|
| 217 |
+
update = __update = _collections_abc.MutableMapping.update
|
| 218 |
+
|
| 219 |
+
def keys(self):
|
| 220 |
+
"D.keys() -> a set-like object providing a view on D's keys"
|
| 221 |
+
return _OrderedDictKeysView(self)
|
| 222 |
+
|
| 223 |
+
def items(self):
|
| 224 |
+
"D.items() -> a set-like object providing a view on D's items"
|
| 225 |
+
return _OrderedDictItemsView(self)
|
| 226 |
+
|
| 227 |
+
def values(self):
|
| 228 |
+
"D.values() -> an object providing a view on D's values"
|
| 229 |
+
return _OrderedDictValuesView(self)
|
| 230 |
+
|
| 231 |
+
__ne__ = _collections_abc.MutableMapping.__ne__
|
| 232 |
+
|
| 233 |
+
__marker = object()
|
| 234 |
+
|
| 235 |
+
def pop(self, key, default=__marker):
|
| 236 |
+
'''od.pop(k[,d]) -> v, remove specified key and return the corresponding
|
| 237 |
+
value. If key is not found, d is returned if given, otherwise KeyError
|
| 238 |
+
is raised.
|
| 239 |
+
|
| 240 |
+
'''
|
| 241 |
+
marker = self.__marker
|
| 242 |
+
result = dict.pop(self, key, marker)
|
| 243 |
+
if result is not marker:
|
| 244 |
+
# The same as in __delitem__().
|
| 245 |
+
link = self.__map.pop(key)
|
| 246 |
+
link_prev = link.prev
|
| 247 |
+
link_next = link.next
|
| 248 |
+
link_prev.next = link_next
|
| 249 |
+
link_next.prev = link_prev
|
| 250 |
+
link.prev = None
|
| 251 |
+
link.next = None
|
| 252 |
+
return result
|
| 253 |
+
if default is marker:
|
| 254 |
+
raise KeyError(key)
|
| 255 |
+
return default
|
| 256 |
+
|
| 257 |
+
def setdefault(self, key, default=None):
|
| 258 |
+
'''Insert key with a value of default if key is not in the dictionary.
|
| 259 |
+
|
| 260 |
+
Return the value for key if key is in the dictionary, else default.
|
| 261 |
+
'''
|
| 262 |
+
if key in self:
|
| 263 |
+
return self[key]
|
| 264 |
+
self[key] = default
|
| 265 |
+
return default
|
| 266 |
+
|
| 267 |
+
@_recursive_repr()
|
| 268 |
+
def __repr__(self):
|
| 269 |
+
'od.__repr__() <==> repr(od)'
|
| 270 |
+
if not self:
|
| 271 |
+
return '%s()' % (self.__class__.__name__,)
|
| 272 |
+
return '%s(%r)' % (self.__class__.__name__, list(self.items()))
|
| 273 |
+
|
| 274 |
+
def __reduce__(self):
|
| 275 |
+
'Return state information for pickling'
|
| 276 |
+
state = self.__getstate__()
|
| 277 |
+
if state:
|
| 278 |
+
if isinstance(state, tuple):
|
| 279 |
+
state, slots = state
|
| 280 |
+
else:
|
| 281 |
+
slots = {}
|
| 282 |
+
state = state.copy()
|
| 283 |
+
slots = slots.copy()
|
| 284 |
+
for k in vars(OrderedDict()):
|
| 285 |
+
state.pop(k, None)
|
| 286 |
+
slots.pop(k, None)
|
| 287 |
+
if slots:
|
| 288 |
+
state = state, slots
|
| 289 |
+
else:
|
| 290 |
+
state = state or None
|
| 291 |
+
return self.__class__, (), state, None, iter(self.items())
|
| 292 |
+
|
| 293 |
+
def copy(self):
|
| 294 |
+
'od.copy() -> a shallow copy of od'
|
| 295 |
+
return self.__class__(self)
|
| 296 |
+
|
| 297 |
+
@classmethod
|
| 298 |
+
def fromkeys(cls, iterable, value=None):
|
| 299 |
+
'''Create a new ordered dictionary with keys from iterable and values set to value.
|
| 300 |
+
'''
|
| 301 |
+
self = cls()
|
| 302 |
+
for key in iterable:
|
| 303 |
+
self[key] = value
|
| 304 |
+
return self
|
| 305 |
+
|
| 306 |
+
def __eq__(self, other):
|
| 307 |
+
'''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive
|
| 308 |
+
while comparison to a regular mapping is order-insensitive.
|
| 309 |
+
|
| 310 |
+
'''
|
| 311 |
+
if isinstance(other, OrderedDict):
|
| 312 |
+
return dict.__eq__(self, other) and all(map(_eq, self, other))
|
| 313 |
+
return dict.__eq__(self, other)
|
| 314 |
+
|
| 315 |
+
def __ior__(self, other):
|
| 316 |
+
self.update(other)
|
| 317 |
+
return self
|
| 318 |
+
|
| 319 |
+
def __or__(self, other):
|
| 320 |
+
if not isinstance(other, dict):
|
| 321 |
+
return NotImplemented
|
| 322 |
+
new = self.__class__(self)
|
| 323 |
+
new.update(other)
|
| 324 |
+
return new
|
| 325 |
+
|
| 326 |
+
def __ror__(self, other):
|
| 327 |
+
if not isinstance(other, dict):
|
| 328 |
+
return NotImplemented
|
| 329 |
+
new = self.__class__(other)
|
| 330 |
+
new.update(self)
|
| 331 |
+
return new
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
try:
|
| 335 |
+
from _collections import OrderedDict
|
| 336 |
+
except ImportError:
|
| 337 |
+
# Leave the pure Python version in place.
|
| 338 |
+
pass
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
################################################################################
|
| 342 |
+
### namedtuple
|
| 343 |
+
################################################################################
|
| 344 |
+
|
| 345 |
+
try:
|
| 346 |
+
from _collections import _tuplegetter
|
| 347 |
+
except ImportError:
|
| 348 |
+
_tuplegetter = lambda index, doc: property(_itemgetter(index), doc=doc)
|
| 349 |
+
|
| 350 |
+
def namedtuple(typename, field_names, *, rename=False, defaults=None, module=None):
|
| 351 |
+
"""Returns a new subclass of tuple with named fields.
|
| 352 |
+
|
| 353 |
+
>>> Point = namedtuple('Point', ['x', 'y'])
|
| 354 |
+
>>> Point.__doc__ # docstring for the new class
|
| 355 |
+
'Point(x, y)'
|
| 356 |
+
>>> p = Point(11, y=22) # instantiate with positional args or keywords
|
| 357 |
+
>>> p[0] + p[1] # indexable like a plain tuple
|
| 358 |
+
33
|
| 359 |
+
>>> x, y = p # unpack like a regular tuple
|
| 360 |
+
>>> x, y
|
| 361 |
+
(11, 22)
|
| 362 |
+
>>> p.x + p.y # fields also accessible by name
|
| 363 |
+
33
|
| 364 |
+
>>> d = p._asdict() # convert to a dictionary
|
| 365 |
+
>>> d['x']
|
| 366 |
+
11
|
| 367 |
+
>>> Point(**d) # convert from a dictionary
|
| 368 |
+
Point(x=11, y=22)
|
| 369 |
+
>>> p._replace(x=100) # _replace() is like str.replace() but targets named fields
|
| 370 |
+
Point(x=100, y=22)
|
| 371 |
+
|
| 372 |
+
"""
|
| 373 |
+
|
| 374 |
+
# Validate the field names. At the user's option, either generate an error
|
| 375 |
+
# message or automatically replace the field name with a valid name.
|
| 376 |
+
if isinstance(field_names, str):
|
| 377 |
+
field_names = field_names.replace(',', ' ').split()
|
| 378 |
+
field_names = list(map(str, field_names))
|
| 379 |
+
typename = _sys.intern(str(typename))
|
| 380 |
+
|
| 381 |
+
if rename:
|
| 382 |
+
seen = set()
|
| 383 |
+
for index, name in enumerate(field_names):
|
| 384 |
+
if (not name.isidentifier()
|
| 385 |
+
or _iskeyword(name)
|
| 386 |
+
or name.startswith('_')
|
| 387 |
+
or name in seen):
|
| 388 |
+
field_names[index] = f'_{index}'
|
| 389 |
+
seen.add(name)
|
| 390 |
+
|
| 391 |
+
for name in [typename] + field_names:
|
| 392 |
+
if type(name) is not str:
|
| 393 |
+
raise TypeError('Type names and field names must be strings')
|
| 394 |
+
if not name.isidentifier():
|
| 395 |
+
raise ValueError('Type names and field names must be valid '
|
| 396 |
+
f'identifiers: {name!r}')
|
| 397 |
+
if _iskeyword(name):
|
| 398 |
+
raise ValueError('Type names and field names cannot be a '
|
| 399 |
+
f'keyword: {name!r}')
|
| 400 |
+
|
| 401 |
+
seen = set()
|
| 402 |
+
for name in field_names:
|
| 403 |
+
if name.startswith('_') and not rename:
|
| 404 |
+
raise ValueError('Field names cannot start with an underscore: '
|
| 405 |
+
f'{name!r}')
|
| 406 |
+
if name in seen:
|
| 407 |
+
raise ValueError(f'Encountered duplicate field name: {name!r}')
|
| 408 |
+
seen.add(name)
|
| 409 |
+
|
| 410 |
+
field_defaults = {}
|
| 411 |
+
if defaults is not None:
|
| 412 |
+
defaults = tuple(defaults)
|
| 413 |
+
if len(defaults) > len(field_names):
|
| 414 |
+
raise TypeError('Got more default values than field names')
|
| 415 |
+
field_defaults = dict(reversed(list(zip(reversed(field_names),
|
| 416 |
+
reversed(defaults)))))
|
| 417 |
+
|
| 418 |
+
# Variables used in the methods and docstrings
|
| 419 |
+
field_names = tuple(map(_sys.intern, field_names))
|
| 420 |
+
num_fields = len(field_names)
|
| 421 |
+
arg_list = ', '.join(field_names)
|
| 422 |
+
if num_fields == 1:
|
| 423 |
+
arg_list += ','
|
| 424 |
+
repr_fmt = '(' + ', '.join(f'{name}=%r' for name in field_names) + ')'
|
| 425 |
+
tuple_new = tuple.__new__
|
| 426 |
+
_dict, _tuple, _len, _map, _zip = dict, tuple, len, map, zip
|
| 427 |
+
|
| 428 |
+
# Create all the named tuple methods to be added to the class namespace
|
| 429 |
+
|
| 430 |
+
namespace = {
|
| 431 |
+
'_tuple_new': tuple_new,
|
| 432 |
+
'__builtins__': {},
|
| 433 |
+
'__name__': f'namedtuple_{typename}',
|
| 434 |
+
}
|
| 435 |
+
code = f'lambda _cls, {arg_list}: _tuple_new(_cls, ({arg_list}))'
|
| 436 |
+
__new__ = eval(code, namespace)
|
| 437 |
+
__new__.__name__ = '__new__'
|
| 438 |
+
__new__.__doc__ = f'Create new instance of {typename}({arg_list})'
|
| 439 |
+
if defaults is not None:
|
| 440 |
+
__new__.__defaults__ = defaults
|
| 441 |
+
|
| 442 |
+
@classmethod
|
| 443 |
+
def _make(cls, iterable):
|
| 444 |
+
result = tuple_new(cls, iterable)
|
| 445 |
+
if _len(result) != num_fields:
|
| 446 |
+
raise TypeError(f'Expected {num_fields} arguments, got {len(result)}')
|
| 447 |
+
return result
|
| 448 |
+
|
| 449 |
+
_make.__func__.__doc__ = (f'Make a new {typename} object from a sequence '
|
| 450 |
+
'or iterable')
|
| 451 |
+
|
| 452 |
+
def _replace(self, /, **kwds):
|
| 453 |
+
result = self._make(_map(kwds.pop, field_names, self))
|
| 454 |
+
if kwds:
|
| 455 |
+
raise ValueError(f'Got unexpected field names: {list(kwds)!r}')
|
| 456 |
+
return result
|
| 457 |
+
|
| 458 |
+
_replace.__doc__ = (f'Return a new {typename} object replacing specified '
|
| 459 |
+
'fields with new values')
|
| 460 |
+
|
| 461 |
+
def __repr__(self):
|
| 462 |
+
'Return a nicely formatted representation string'
|
| 463 |
+
return self.__class__.__name__ + repr_fmt % self
|
| 464 |
+
|
| 465 |
+
def _asdict(self):
|
| 466 |
+
'Return a new dict which maps field names to their values.'
|
| 467 |
+
return _dict(_zip(self._fields, self))
|
| 468 |
+
|
| 469 |
+
def __getnewargs__(self):
|
| 470 |
+
'Return self as a plain tuple. Used by copy and pickle.'
|
| 471 |
+
return _tuple(self)
|
| 472 |
+
|
| 473 |
+
# Modify function metadata to help with introspection and debugging
|
| 474 |
+
for method in (
|
| 475 |
+
__new__,
|
| 476 |
+
_make.__func__,
|
| 477 |
+
_replace,
|
| 478 |
+
__repr__,
|
| 479 |
+
_asdict,
|
| 480 |
+
__getnewargs__,
|
| 481 |
+
):
|
| 482 |
+
method.__qualname__ = f'{typename}.{method.__name__}'
|
| 483 |
+
|
| 484 |
+
# Build-up the class namespace dictionary
|
| 485 |
+
# and use type() to build the result class
|
| 486 |
+
class_namespace = {
|
| 487 |
+
'__doc__': f'{typename}({arg_list})',
|
| 488 |
+
'__slots__': (),
|
| 489 |
+
'_fields': field_names,
|
| 490 |
+
'_field_defaults': field_defaults,
|
| 491 |
+
'__new__': __new__,
|
| 492 |
+
'_make': _make,
|
| 493 |
+
'_replace': _replace,
|
| 494 |
+
'__repr__': __repr__,
|
| 495 |
+
'_asdict': _asdict,
|
| 496 |
+
'__getnewargs__': __getnewargs__,
|
| 497 |
+
'__match_args__': field_names,
|
| 498 |
+
}
|
| 499 |
+
for index, name in enumerate(field_names):
|
| 500 |
+
doc = _sys.intern(f'Alias for field number {index}')
|
| 501 |
+
class_namespace[name] = _tuplegetter(index, doc)
|
| 502 |
+
|
| 503 |
+
result = type(typename, (tuple,), class_namespace)
|
| 504 |
+
|
| 505 |
+
# For pickling to work, the __module__ variable needs to be set to the frame
|
| 506 |
+
# where the named tuple is created. Bypass this step in environments where
|
| 507 |
+
# sys._getframe is not defined (Jython for example) or sys._getframe is not
|
| 508 |
+
# defined for arguments greater than 0 (IronPython), or where the user has
|
| 509 |
+
# specified a particular module.
|
| 510 |
+
if module is None:
|
| 511 |
+
try:
|
| 512 |
+
module = _sys._getframe(1).f_globals.get('__name__', '__main__')
|
| 513 |
+
except (AttributeError, ValueError):
|
| 514 |
+
pass
|
| 515 |
+
if module is not None:
|
| 516 |
+
result.__module__ = module
|
| 517 |
+
|
| 518 |
+
return result
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
########################################################################
|
| 522 |
+
### Counter
|
| 523 |
+
########################################################################
|
| 524 |
+
|
| 525 |
+
def _count_elements(mapping, iterable):
|
| 526 |
+
'Tally elements from the iterable.'
|
| 527 |
+
mapping_get = mapping.get
|
| 528 |
+
for elem in iterable:
|
| 529 |
+
mapping[elem] = mapping_get(elem, 0) + 1
|
| 530 |
+
|
| 531 |
+
try: # Load C helper function if available
|
| 532 |
+
from _collections import _count_elements
|
| 533 |
+
except ImportError:
|
| 534 |
+
pass
|
| 535 |
+
|
| 536 |
+
class Counter(dict):
|
| 537 |
+
'''Dict subclass for counting hashable items. Sometimes called a bag
|
| 538 |
+
or multiset. Elements are stored as dictionary keys and their counts
|
| 539 |
+
are stored as dictionary values.
|
| 540 |
+
|
| 541 |
+
>>> c = Counter('abcdeabcdabcaba') # count elements from a string
|
| 542 |
+
|
| 543 |
+
>>> c.most_common(3) # three most common elements
|
| 544 |
+
[('a', 5), ('b', 4), ('c', 3)]
|
| 545 |
+
>>> sorted(c) # list all unique elements
|
| 546 |
+
['a', 'b', 'c', 'd', 'e']
|
| 547 |
+
>>> ''.join(sorted(c.elements())) # list elements with repetitions
|
| 548 |
+
'aaaaabbbbcccdde'
|
| 549 |
+
>>> sum(c.values()) # total of all counts
|
| 550 |
+
15
|
| 551 |
+
|
| 552 |
+
>>> c['a'] # count of letter 'a'
|
| 553 |
+
5
|
| 554 |
+
>>> for elem in 'shazam': # update counts from an iterable
|
| 555 |
+
... c[elem] += 1 # by adding 1 to each element's count
|
| 556 |
+
>>> c['a'] # now there are seven 'a'
|
| 557 |
+
7
|
| 558 |
+
>>> del c['b'] # remove all 'b'
|
| 559 |
+
>>> c['b'] # now there are zero 'b'
|
| 560 |
+
0
|
| 561 |
+
|
| 562 |
+
>>> d = Counter('simsalabim') # make another counter
|
| 563 |
+
>>> c.update(d) # add in the second counter
|
| 564 |
+
>>> c['a'] # now there are nine 'a'
|
| 565 |
+
9
|
| 566 |
+
|
| 567 |
+
>>> c.clear() # empty the counter
|
| 568 |
+
>>> c
|
| 569 |
+
Counter()
|
| 570 |
+
|
| 571 |
+
Note: If a count is set to zero or reduced to zero, it will remain
|
| 572 |
+
in the counter until the entry is deleted or the counter is cleared:
|
| 573 |
+
|
| 574 |
+
>>> c = Counter('aaabbc')
|
| 575 |
+
>>> c['b'] -= 2 # reduce the count of 'b' by two
|
| 576 |
+
>>> c.most_common() # 'b' is still in, but its count is zero
|
| 577 |
+
[('a', 3), ('c', 1), ('b', 0)]
|
| 578 |
+
|
| 579 |
+
'''
|
| 580 |
+
# References:
|
| 581 |
+
# http://en.wikipedia.org/wiki/Multiset
|
| 582 |
+
# http://www.gnu.org/software/smalltalk/manual-base/html_node/Bag.html
|
| 583 |
+
# http://www.demo2s.com/Tutorial/Cpp/0380__set-multiset/Catalog0380__set-multiset.htm
|
| 584 |
+
# http://code.activestate.com/recipes/259174/
|
| 585 |
+
# Knuth, TAOCP Vol. II section 4.6.3
|
| 586 |
+
|
| 587 |
+
def __init__(self, iterable=None, /, **kwds):
|
| 588 |
+
'''Create a new, empty Counter object. And if given, count elements
|
| 589 |
+
from an input iterable. Or, initialize the count from another mapping
|
| 590 |
+
of elements to their counts.
|
| 591 |
+
|
| 592 |
+
>>> c = Counter() # a new, empty counter
|
| 593 |
+
>>> c = Counter('gallahad') # a new counter from an iterable
|
| 594 |
+
>>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping
|
| 595 |
+
>>> c = Counter(a=4, b=2) # a new counter from keyword args
|
| 596 |
+
|
| 597 |
+
'''
|
| 598 |
+
super().__init__()
|
| 599 |
+
self.update(iterable, **kwds)
|
| 600 |
+
|
| 601 |
+
def __missing__(self, key):
|
| 602 |
+
'The count of elements not in the Counter is zero.'
|
| 603 |
+
# Needed so that self[missing_item] does not raise KeyError
|
| 604 |
+
return 0
|
| 605 |
+
|
| 606 |
+
def total(self):
|
| 607 |
+
'Sum of the counts'
|
| 608 |
+
return sum(self.values())
|
| 609 |
+
|
| 610 |
+
def most_common(self, n=None):
|
| 611 |
+
'''List the n most common elements and their counts from the most
|
| 612 |
+
common to the least. If n is None, then list all element counts.
|
| 613 |
+
|
| 614 |
+
>>> Counter('abracadabra').most_common(3)
|
| 615 |
+
[('a', 5), ('b', 2), ('r', 2)]
|
| 616 |
+
|
| 617 |
+
'''
|
| 618 |
+
# Emulate Bag.sortedByCount from Smalltalk
|
| 619 |
+
if n is None:
|
| 620 |
+
return sorted(self.items(), key=_itemgetter(1), reverse=True)
|
| 621 |
+
|
| 622 |
+
# Lazy import to speedup Python startup time
|
| 623 |
+
import heapq
|
| 624 |
+
return heapq.nlargest(n, self.items(), key=_itemgetter(1))
|
| 625 |
+
|
| 626 |
+
def elements(self):
|
| 627 |
+
'''Iterator over elements repeating each as many times as its count.
|
| 628 |
+
|
| 629 |
+
>>> c = Counter('ABCABC')
|
| 630 |
+
>>> sorted(c.elements())
|
| 631 |
+
['A', 'A', 'B', 'B', 'C', 'C']
|
| 632 |
+
|
| 633 |
+
# Knuth's example for prime factors of 1836: 2**2 * 3**3 * 17**1
|
| 634 |
+
>>> import math
|
| 635 |
+
>>> prime_factors = Counter({2: 2, 3: 3, 17: 1})
|
| 636 |
+
>>> math.prod(prime_factors.elements())
|
| 637 |
+
1836
|
| 638 |
+
|
| 639 |
+
Note, if an element's count has been set to zero or is a negative
|
| 640 |
+
number, elements() will ignore it.
|
| 641 |
+
|
| 642 |
+
'''
|
| 643 |
+
# Emulate Bag.do from Smalltalk and Multiset.begin from C++.
|
| 644 |
+
return _chain.from_iterable(_starmap(_repeat, self.items()))
|
| 645 |
+
|
| 646 |
+
# Override dict methods where necessary
|
| 647 |
+
|
| 648 |
+
@classmethod
|
| 649 |
+
def fromkeys(cls, iterable, v=None):
|
| 650 |
+
# There is no equivalent method for counters because the semantics
|
| 651 |
+
# would be ambiguous in cases such as Counter.fromkeys('aaabbc', v=2).
|
| 652 |
+
# Initializing counters to zero values isn't necessary because zero
|
| 653 |
+
# is already the default value for counter lookups. Initializing
|
| 654 |
+
# to one is easily accomplished with Counter(set(iterable)). For
|
| 655 |
+
# more exotic cases, create a dictionary first using a dictionary
|
| 656 |
+
# comprehension or dict.fromkeys().
|
| 657 |
+
raise NotImplementedError(
|
| 658 |
+
'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
|
| 659 |
+
|
| 660 |
+
def update(self, iterable=None, /, **kwds):
|
| 661 |
+
'''Like dict.update() but add counts instead of replacing them.
|
| 662 |
+
|
| 663 |
+
Source can be an iterable, a dictionary, or another Counter instance.
|
| 664 |
+
|
| 665 |
+
>>> c = Counter('which')
|
| 666 |
+
>>> c.update('witch') # add elements from another iterable
|
| 667 |
+
>>> d = Counter('watch')
|
| 668 |
+
>>> c.update(d) # add elements from another counter
|
| 669 |
+
>>> c['h'] # four 'h' in which, witch, and watch
|
| 670 |
+
4
|
| 671 |
+
|
| 672 |
+
'''
|
| 673 |
+
# The regular dict.update() operation makes no sense here because the
|
| 674 |
+
# replace behavior results in some of the original untouched counts
|
| 675 |
+
# being mixed-in with all of the other counts for a mismash that
|
| 676 |
+
# doesn't have a straight-forward interpretation in most counting
|
| 677 |
+
# contexts. Instead, we implement straight-addition. Both the inputs
|
| 678 |
+
# and outputs are allowed to contain zero and negative counts.
|
| 679 |
+
|
| 680 |
+
if iterable is not None:
|
| 681 |
+
if isinstance(iterable, _collections_abc.Mapping):
|
| 682 |
+
if self:
|
| 683 |
+
self_get = self.get
|
| 684 |
+
for elem, count in iterable.items():
|
| 685 |
+
self[elem] = count + self_get(elem, 0)
|
| 686 |
+
else:
|
| 687 |
+
# fast path when counter is empty
|
| 688 |
+
super().update(iterable)
|
| 689 |
+
else:
|
| 690 |
+
_count_elements(self, iterable)
|
| 691 |
+
if kwds:
|
| 692 |
+
self.update(kwds)
|
| 693 |
+
|
| 694 |
+
def subtract(self, iterable=None, /, **kwds):
|
| 695 |
+
'''Like dict.update() but subtracts counts instead of replacing them.
|
| 696 |
+
Counts can be reduced below zero. Both the inputs and outputs are
|
| 697 |
+
allowed to contain zero and negative counts.
|
| 698 |
+
|
| 699 |
+
Source can be an iterable, a dictionary, or another Counter instance.
|
| 700 |
+
|
| 701 |
+
>>> c = Counter('which')
|
| 702 |
+
>>> c.subtract('witch') # subtract elements from another iterable
|
| 703 |
+
>>> c.subtract(Counter('watch')) # subtract elements from another counter
|
| 704 |
+
>>> c['h'] # 2 in which, minus 1 in witch, minus 1 in watch
|
| 705 |
+
0
|
| 706 |
+
>>> c['w'] # 1 in which, minus 1 in witch, minus 1 in watch
|
| 707 |
+
-1
|
| 708 |
+
|
| 709 |
+
'''
|
| 710 |
+
if iterable is not None:
|
| 711 |
+
self_get = self.get
|
| 712 |
+
if isinstance(iterable, _collections_abc.Mapping):
|
| 713 |
+
for elem, count in iterable.items():
|
| 714 |
+
self[elem] = self_get(elem, 0) - count
|
| 715 |
+
else:
|
| 716 |
+
for elem in iterable:
|
| 717 |
+
self[elem] = self_get(elem, 0) - 1
|
| 718 |
+
if kwds:
|
| 719 |
+
self.subtract(kwds)
|
| 720 |
+
|
| 721 |
+
def copy(self):
|
| 722 |
+
'Return a shallow copy.'
|
| 723 |
+
return self.__class__(self)
|
| 724 |
+
|
| 725 |
+
def __reduce__(self):
|
| 726 |
+
return self.__class__, (dict(self),)
|
| 727 |
+
|
| 728 |
+
def __delitem__(self, elem):
|
| 729 |
+
'Like dict.__delitem__() but does not raise KeyError for missing values.'
|
| 730 |
+
if elem in self:
|
| 731 |
+
super().__delitem__(elem)
|
| 732 |
+
|
| 733 |
+
def __repr__(self):
|
| 734 |
+
if not self:
|
| 735 |
+
return f'{self.__class__.__name__}()'
|
| 736 |
+
try:
|
| 737 |
+
# dict() preserves the ordering returned by most_common()
|
| 738 |
+
d = dict(self.most_common())
|
| 739 |
+
except TypeError:
|
| 740 |
+
# handle case where values are not orderable
|
| 741 |
+
d = dict(self)
|
| 742 |
+
return f'{self.__class__.__name__}({d!r})'
|
| 743 |
+
|
| 744 |
+
# Multiset-style mathematical operations discussed in:
|
| 745 |
+
# Knuth TAOCP Volume II section 4.6.3 exercise 19
|
| 746 |
+
# and at http://en.wikipedia.org/wiki/Multiset
|
| 747 |
+
#
|
| 748 |
+
# Outputs guaranteed to only include positive counts.
|
| 749 |
+
#
|
| 750 |
+
# To strip negative and zero counts, add-in an empty counter:
|
| 751 |
+
# c += Counter()
|
| 752 |
+
#
|
| 753 |
+
# Results are ordered according to when an element is first
|
| 754 |
+
# encountered in the left operand and then by the order
|
| 755 |
+
# encountered in the right operand.
|
| 756 |
+
#
|
| 757 |
+
# When the multiplicities are all zero or one, multiset operations
|
| 758 |
+
# are guaranteed to be equivalent to the corresponding operations
|
| 759 |
+
# for regular sets.
|
| 760 |
+
# Given counter multisets such as:
|
| 761 |
+
# cp = Counter(a=1, b=0, c=1)
|
| 762 |
+
# cq = Counter(c=1, d=0, e=1)
|
| 763 |
+
# The corresponding regular sets would be:
|
| 764 |
+
# sp = {'a', 'c'}
|
| 765 |
+
# sq = {'c', 'e'}
|
| 766 |
+
# All of the following relations would hold:
|
| 767 |
+
# set(cp + cq) == sp | sq
|
| 768 |
+
# set(cp - cq) == sp - sq
|
| 769 |
+
# set(cp | cq) == sp | sq
|
| 770 |
+
# set(cp & cq) == sp & sq
|
| 771 |
+
# (cp == cq) == (sp == sq)
|
| 772 |
+
# (cp != cq) == (sp != sq)
|
| 773 |
+
# (cp <= cq) == (sp <= sq)
|
| 774 |
+
# (cp < cq) == (sp < sq)
|
| 775 |
+
# (cp >= cq) == (sp >= sq)
|
| 776 |
+
# (cp > cq) == (sp > sq)
|
| 777 |
+
|
| 778 |
+
def __eq__(self, other):
|
| 779 |
+
'True if all counts agree. Missing counts are treated as zero.'
|
| 780 |
+
if not isinstance(other, Counter):
|
| 781 |
+
return NotImplemented
|
| 782 |
+
return all(self[e] == other[e] for c in (self, other) for e in c)
|
| 783 |
+
|
| 784 |
+
def __ne__(self, other):
|
| 785 |
+
'True if any counts disagree. Missing counts are treated as zero.'
|
| 786 |
+
if not isinstance(other, Counter):
|
| 787 |
+
return NotImplemented
|
| 788 |
+
return not self == other
|
| 789 |
+
|
| 790 |
+
def __le__(self, other):
|
| 791 |
+
'True if all counts in self are a subset of those in other.'
|
| 792 |
+
if not isinstance(other, Counter):
|
| 793 |
+
return NotImplemented
|
| 794 |
+
return all(self[e] <= other[e] for c in (self, other) for e in c)
|
| 795 |
+
|
| 796 |
+
def __lt__(self, other):
|
| 797 |
+
'True if all counts in self are a proper subset of those in other.'
|
| 798 |
+
if not isinstance(other, Counter):
|
| 799 |
+
return NotImplemented
|
| 800 |
+
return self <= other and self != other
|
| 801 |
+
|
| 802 |
+
def __ge__(self, other):
|
| 803 |
+
'True if all counts in self are a superset of those in other.'
|
| 804 |
+
if not isinstance(other, Counter):
|
| 805 |
+
return NotImplemented
|
| 806 |
+
return all(self[e] >= other[e] for c in (self, other) for e in c)
|
| 807 |
+
|
| 808 |
+
def __gt__(self, other):
|
| 809 |
+
'True if all counts in self are a proper superset of those in other.'
|
| 810 |
+
if not isinstance(other, Counter):
|
| 811 |
+
return NotImplemented
|
| 812 |
+
return self >= other and self != other
|
| 813 |
+
|
| 814 |
+
def __add__(self, other):
|
| 815 |
+
'''Add counts from two counters.
|
| 816 |
+
|
| 817 |
+
>>> Counter('abbb') + Counter('bcc')
|
| 818 |
+
Counter({'b': 4, 'c': 2, 'a': 1})
|
| 819 |
+
|
| 820 |
+
'''
|
| 821 |
+
if not isinstance(other, Counter):
|
| 822 |
+
return NotImplemented
|
| 823 |
+
result = Counter()
|
| 824 |
+
for elem, count in self.items():
|
| 825 |
+
newcount = count + other[elem]
|
| 826 |
+
if newcount > 0:
|
| 827 |
+
result[elem] = newcount
|
| 828 |
+
for elem, count in other.items():
|
| 829 |
+
if elem not in self and count > 0:
|
| 830 |
+
result[elem] = count
|
| 831 |
+
return result
|
| 832 |
+
|
| 833 |
+
def __sub__(self, other):
|
| 834 |
+
''' Subtract count, but keep only results with positive counts.
|
| 835 |
+
|
| 836 |
+
>>> Counter('abbbc') - Counter('bccd')
|
| 837 |
+
Counter({'b': 2, 'a': 1})
|
| 838 |
+
|
| 839 |
+
'''
|
| 840 |
+
if not isinstance(other, Counter):
|
| 841 |
+
return NotImplemented
|
| 842 |
+
result = Counter()
|
| 843 |
+
for elem, count in self.items():
|
| 844 |
+
newcount = count - other[elem]
|
| 845 |
+
if newcount > 0:
|
| 846 |
+
result[elem] = newcount
|
| 847 |
+
for elem, count in other.items():
|
| 848 |
+
if elem not in self and count < 0:
|
| 849 |
+
result[elem] = 0 - count
|
| 850 |
+
return result
|
| 851 |
+
|
| 852 |
+
def __or__(self, other):
|
| 853 |
+
'''Union is the maximum of value in either of the input counters.
|
| 854 |
+
|
| 855 |
+
>>> Counter('abbb') | Counter('bcc')
|
| 856 |
+
Counter({'b': 3, 'c': 2, 'a': 1})
|
| 857 |
+
|
| 858 |
+
'''
|
| 859 |
+
if not isinstance(other, Counter):
|
| 860 |
+
return NotImplemented
|
| 861 |
+
result = Counter()
|
| 862 |
+
for elem, count in self.items():
|
| 863 |
+
other_count = other[elem]
|
| 864 |
+
newcount = other_count if count < other_count else count
|
| 865 |
+
if newcount > 0:
|
| 866 |
+
result[elem] = newcount
|
| 867 |
+
for elem, count in other.items():
|
| 868 |
+
if elem not in self and count > 0:
|
| 869 |
+
result[elem] = count
|
| 870 |
+
return result
|
| 871 |
+
|
| 872 |
+
def __and__(self, other):
|
| 873 |
+
''' Intersection is the minimum of corresponding counts.
|
| 874 |
+
|
| 875 |
+
>>> Counter('abbb') & Counter('bcc')
|
| 876 |
+
Counter({'b': 1})
|
| 877 |
+
|
| 878 |
+
'''
|
| 879 |
+
if not isinstance(other, Counter):
|
| 880 |
+
return NotImplemented
|
| 881 |
+
result = Counter()
|
| 882 |
+
for elem, count in self.items():
|
| 883 |
+
other_count = other[elem]
|
| 884 |
+
newcount = count if count < other_count else other_count
|
| 885 |
+
if newcount > 0:
|
| 886 |
+
result[elem] = newcount
|
| 887 |
+
return result
|
| 888 |
+
|
| 889 |
+
def __pos__(self):
|
| 890 |
+
'Adds an empty counter, effectively stripping negative and zero counts'
|
| 891 |
+
result = Counter()
|
| 892 |
+
for elem, count in self.items():
|
| 893 |
+
if count > 0:
|
| 894 |
+
result[elem] = count
|
| 895 |
+
return result
|
| 896 |
+
|
| 897 |
+
def __neg__(self):
|
| 898 |
+
'''Subtracts from an empty counter. Strips positive and zero counts,
|
| 899 |
+
and flips the sign on negative counts.
|
| 900 |
+
|
| 901 |
+
'''
|
| 902 |
+
result = Counter()
|
| 903 |
+
for elem, count in self.items():
|
| 904 |
+
if count < 0:
|
| 905 |
+
result[elem] = 0 - count
|
| 906 |
+
return result
|
| 907 |
+
|
| 908 |
+
def _keep_positive(self):
|
| 909 |
+
'''Internal method to strip elements with a negative or zero count'''
|
| 910 |
+
nonpositive = [elem for elem, count in self.items() if not count > 0]
|
| 911 |
+
for elem in nonpositive:
|
| 912 |
+
del self[elem]
|
| 913 |
+
return self
|
| 914 |
+
|
| 915 |
+
def __iadd__(self, other):
|
| 916 |
+
'''Inplace add from another counter, keeping only positive counts.
|
| 917 |
+
|
| 918 |
+
>>> c = Counter('abbb')
|
| 919 |
+
>>> c += Counter('bcc')
|
| 920 |
+
>>> c
|
| 921 |
+
Counter({'b': 4, 'c': 2, 'a': 1})
|
| 922 |
+
|
| 923 |
+
'''
|
| 924 |
+
for elem, count in other.items():
|
| 925 |
+
self[elem] += count
|
| 926 |
+
return self._keep_positive()
|
| 927 |
+
|
| 928 |
+
def __isub__(self, other):
|
| 929 |
+
'''Inplace subtract counter, but keep only results with positive counts.
|
| 930 |
+
|
| 931 |
+
>>> c = Counter('abbbc')
|
| 932 |
+
>>> c -= Counter('bccd')
|
| 933 |
+
>>> c
|
| 934 |
+
Counter({'b': 2, 'a': 1})
|
| 935 |
+
|
| 936 |
+
'''
|
| 937 |
+
for elem, count in other.items():
|
| 938 |
+
self[elem] -= count
|
| 939 |
+
return self._keep_positive()
|
| 940 |
+
|
| 941 |
+
def __ior__(self, other):
|
| 942 |
+
'''Inplace union is the maximum of value from either counter.
|
| 943 |
+
|
| 944 |
+
>>> c = Counter('abbb')
|
| 945 |
+
>>> c |= Counter('bcc')
|
| 946 |
+
>>> c
|
| 947 |
+
Counter({'b': 3, 'c': 2, 'a': 1})
|
| 948 |
+
|
| 949 |
+
'''
|
| 950 |
+
for elem, other_count in other.items():
|
| 951 |
+
count = self[elem]
|
| 952 |
+
if other_count > count:
|
| 953 |
+
self[elem] = other_count
|
| 954 |
+
return self._keep_positive()
|
| 955 |
+
|
| 956 |
+
def __iand__(self, other):
|
| 957 |
+
'''Inplace intersection is the minimum of corresponding counts.
|
| 958 |
+
|
| 959 |
+
>>> c = Counter('abbb')
|
| 960 |
+
>>> c &= Counter('bcc')
|
| 961 |
+
>>> c
|
| 962 |
+
Counter({'b': 1})
|
| 963 |
+
|
| 964 |
+
'''
|
| 965 |
+
for elem, count in self.items():
|
| 966 |
+
other_count = other[elem]
|
| 967 |
+
if other_count < count:
|
| 968 |
+
self[elem] = other_count
|
| 969 |
+
return self._keep_positive()
|
| 970 |
+
|
| 971 |
+
|
| 972 |
+
########################################################################
|
| 973 |
+
### ChainMap
|
| 974 |
+
########################################################################
|
| 975 |
+
|
| 976 |
+
class ChainMap(_collections_abc.MutableMapping):
|
| 977 |
+
''' A ChainMap groups multiple dicts (or other mappings) together
|
| 978 |
+
to create a single, updateable view.
|
| 979 |
+
|
| 980 |
+
The underlying mappings are stored in a list. That list is public and can
|
| 981 |
+
be accessed or updated using the *maps* attribute. There is no other
|
| 982 |
+
state.
|
| 983 |
+
|
| 984 |
+
Lookups search the underlying mappings successively until a key is found.
|
| 985 |
+
In contrast, writes, updates, and deletions only operate on the first
|
| 986 |
+
mapping.
|
| 987 |
+
|
| 988 |
+
'''
|
| 989 |
+
|
| 990 |
+
def __init__(self, *maps):
|
| 991 |
+
'''Initialize a ChainMap by setting *maps* to the given mappings.
|
| 992 |
+
If no mappings are provided, a single empty dictionary is used.
|
| 993 |
+
|
| 994 |
+
'''
|
| 995 |
+
self.maps = list(maps) or [{}] # always at least one map
|
| 996 |
+
|
| 997 |
+
def __missing__(self, key):
|
| 998 |
+
raise KeyError(key)
|
| 999 |
+
|
| 1000 |
+
def __getitem__(self, key):
|
| 1001 |
+
for mapping in self.maps:
|
| 1002 |
+
try:
|
| 1003 |
+
return mapping[key] # can't use 'key in mapping' with defaultdict
|
| 1004 |
+
except KeyError:
|
| 1005 |
+
pass
|
| 1006 |
+
return self.__missing__(key) # support subclasses that define __missing__
|
| 1007 |
+
|
| 1008 |
+
def get(self, key, default=None):
|
| 1009 |
+
return self[key] if key in self else default
|
| 1010 |
+
|
| 1011 |
+
def __len__(self):
|
| 1012 |
+
return len(set().union(*self.maps)) # reuses stored hash values if possible
|
| 1013 |
+
|
| 1014 |
+
def __iter__(self):
|
| 1015 |
+
d = {}
|
| 1016 |
+
for mapping in reversed(self.maps):
|
| 1017 |
+
d.update(dict.fromkeys(mapping)) # reuses stored hash values if possible
|
| 1018 |
+
return iter(d)
|
| 1019 |
+
|
| 1020 |
+
def __contains__(self, key):
|
| 1021 |
+
return any(key in m for m in self.maps)
|
| 1022 |
+
|
| 1023 |
+
def __bool__(self):
|
| 1024 |
+
return any(self.maps)
|
| 1025 |
+
|
| 1026 |
+
@_recursive_repr()
|
| 1027 |
+
def __repr__(self):
|
| 1028 |
+
return f'{self.__class__.__name__}({", ".join(map(repr, self.maps))})'
|
| 1029 |
+
|
| 1030 |
+
@classmethod
|
| 1031 |
+
def fromkeys(cls, iterable, *args):
|
| 1032 |
+
'Create a ChainMap with a single dict created from the iterable.'
|
| 1033 |
+
return cls(dict.fromkeys(iterable, *args))
|
| 1034 |
+
|
| 1035 |
+
def copy(self):
|
| 1036 |
+
'New ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]'
|
| 1037 |
+
return self.__class__(self.maps[0].copy(), *self.maps[1:])
|
| 1038 |
+
|
| 1039 |
+
__copy__ = copy
|
| 1040 |
+
|
| 1041 |
+
def new_child(self, m=None, **kwargs): # like Django's Context.push()
|
| 1042 |
+
'''New ChainMap with a new map followed by all previous maps.
|
| 1043 |
+
If no map is provided, an empty dict is used.
|
| 1044 |
+
Keyword arguments update the map or new empty dict.
|
| 1045 |
+
'''
|
| 1046 |
+
if m is None:
|
| 1047 |
+
m = kwargs
|
| 1048 |
+
elif kwargs:
|
| 1049 |
+
m.update(kwargs)
|
| 1050 |
+
return self.__class__(m, *self.maps)
|
| 1051 |
+
|
| 1052 |
+
@property
|
| 1053 |
+
def parents(self): # like Django's Context.pop()
|
| 1054 |
+
'New ChainMap from maps[1:].'
|
| 1055 |
+
return self.__class__(*self.maps[1:])
|
| 1056 |
+
|
| 1057 |
+
def __setitem__(self, key, value):
|
| 1058 |
+
self.maps[0][key] = value
|
| 1059 |
+
|
| 1060 |
+
def __delitem__(self, key):
|
| 1061 |
+
try:
|
| 1062 |
+
del self.maps[0][key]
|
| 1063 |
+
except KeyError:
|
| 1064 |
+
raise KeyError(f'Key not found in the first mapping: {key!r}')
|
| 1065 |
+
|
| 1066 |
+
def popitem(self):
|
| 1067 |
+
'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.'
|
| 1068 |
+
try:
|
| 1069 |
+
return self.maps[0].popitem()
|
| 1070 |
+
except KeyError:
|
| 1071 |
+
raise KeyError('No keys found in the first mapping.')
|
| 1072 |
+
|
| 1073 |
+
def pop(self, key, *args):
|
| 1074 |
+
'Remove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].'
|
| 1075 |
+
try:
|
| 1076 |
+
return self.maps[0].pop(key, *args)
|
| 1077 |
+
except KeyError:
|
| 1078 |
+
raise KeyError(f'Key not found in the first mapping: {key!r}')
|
| 1079 |
+
|
| 1080 |
+
def clear(self):
|
| 1081 |
+
'Clear maps[0], leaving maps[1:] intact.'
|
| 1082 |
+
self.maps[0].clear()
|
| 1083 |
+
|
| 1084 |
+
def __ior__(self, other):
|
| 1085 |
+
self.maps[0].update(other)
|
| 1086 |
+
return self
|
| 1087 |
+
|
| 1088 |
+
def __or__(self, other):
|
| 1089 |
+
if not isinstance(other, _collections_abc.Mapping):
|
| 1090 |
+
return NotImplemented
|
| 1091 |
+
m = self.copy()
|
| 1092 |
+
m.maps[0].update(other)
|
| 1093 |
+
return m
|
| 1094 |
+
|
| 1095 |
+
def __ror__(self, other):
|
| 1096 |
+
if not isinstance(other, _collections_abc.Mapping):
|
| 1097 |
+
return NotImplemented
|
| 1098 |
+
m = dict(other)
|
| 1099 |
+
for child in reversed(self.maps):
|
| 1100 |
+
m.update(child)
|
| 1101 |
+
return self.__class__(m)
|
| 1102 |
+
|
| 1103 |
+
|
| 1104 |
+
################################################################################
|
| 1105 |
+
### UserDict
|
| 1106 |
+
################################################################################
|
| 1107 |
+
|
| 1108 |
+
class UserDict(_collections_abc.MutableMapping):
|
| 1109 |
+
|
| 1110 |
+
# Start by filling-out the abstract methods
|
| 1111 |
+
def __init__(self, dict=None, /, **kwargs):
|
| 1112 |
+
self.data = {}
|
| 1113 |
+
if dict is not None:
|
| 1114 |
+
self.update(dict)
|
| 1115 |
+
if kwargs:
|
| 1116 |
+
self.update(kwargs)
|
| 1117 |
+
|
| 1118 |
+
def __len__(self):
|
| 1119 |
+
return len(self.data)
|
| 1120 |
+
|
| 1121 |
+
def __getitem__(self, key):
|
| 1122 |
+
if key in self.data:
|
| 1123 |
+
return self.data[key]
|
| 1124 |
+
if hasattr(self.__class__, "__missing__"):
|
| 1125 |
+
return self.__class__.__missing__(self, key)
|
| 1126 |
+
raise KeyError(key)
|
| 1127 |
+
|
| 1128 |
+
def __setitem__(self, key, item):
|
| 1129 |
+
self.data[key] = item
|
| 1130 |
+
|
| 1131 |
+
def __delitem__(self, key):
|
| 1132 |
+
del self.data[key]
|
| 1133 |
+
|
| 1134 |
+
def __iter__(self):
|
| 1135 |
+
return iter(self.data)
|
| 1136 |
+
|
| 1137 |
+
# Modify __contains__ to work correctly when __missing__ is present
|
| 1138 |
+
def __contains__(self, key):
|
| 1139 |
+
return key in self.data
|
| 1140 |
+
|
| 1141 |
+
# Now, add the methods in dicts but not in MutableMapping
|
| 1142 |
+
def __repr__(self):
|
| 1143 |
+
return repr(self.data)
|
| 1144 |
+
|
| 1145 |
+
def __or__(self, other):
|
| 1146 |
+
if isinstance(other, UserDict):
|
| 1147 |
+
return self.__class__(self.data | other.data)
|
| 1148 |
+
if isinstance(other, dict):
|
| 1149 |
+
return self.__class__(self.data | other)
|
| 1150 |
+
return NotImplemented
|
| 1151 |
+
|
| 1152 |
+
def __ror__(self, other):
|
| 1153 |
+
if isinstance(other, UserDict):
|
| 1154 |
+
return self.__class__(other.data | self.data)
|
| 1155 |
+
if isinstance(other, dict):
|
| 1156 |
+
return self.__class__(other | self.data)
|
| 1157 |
+
return NotImplemented
|
| 1158 |
+
|
| 1159 |
+
def __ior__(self, other):
|
| 1160 |
+
if isinstance(other, UserDict):
|
| 1161 |
+
self.data |= other.data
|
| 1162 |
+
else:
|
| 1163 |
+
self.data |= other
|
| 1164 |
+
return self
|
| 1165 |
+
|
| 1166 |
+
def __copy__(self):
|
| 1167 |
+
inst = self.__class__.__new__(self.__class__)
|
| 1168 |
+
inst.__dict__.update(self.__dict__)
|
| 1169 |
+
# Create a copy and avoid triggering descriptors
|
| 1170 |
+
inst.__dict__["data"] = self.__dict__["data"].copy()
|
| 1171 |
+
return inst
|
| 1172 |
+
|
| 1173 |
+
def copy(self):
|
| 1174 |
+
if self.__class__ is UserDict:
|
| 1175 |
+
return UserDict(self.data.copy())
|
| 1176 |
+
import copy
|
| 1177 |
+
data = self.data
|
| 1178 |
+
try:
|
| 1179 |
+
self.data = {}
|
| 1180 |
+
c = copy.copy(self)
|
| 1181 |
+
finally:
|
| 1182 |
+
self.data = data
|
| 1183 |
+
c.update(self)
|
| 1184 |
+
return c
|
| 1185 |
+
|
| 1186 |
+
@classmethod
|
| 1187 |
+
def fromkeys(cls, iterable, value=None):
|
| 1188 |
+
d = cls()
|
| 1189 |
+
for key in iterable:
|
| 1190 |
+
d[key] = value
|
| 1191 |
+
return d
|
| 1192 |
+
|
| 1193 |
+
|
| 1194 |
+
################################################################################
|
| 1195 |
+
### UserList
|
| 1196 |
+
################################################################################
|
| 1197 |
+
|
| 1198 |
+
class UserList(_collections_abc.MutableSequence):
|
| 1199 |
+
"""A more or less complete user-defined wrapper around list objects."""
|
| 1200 |
+
|
| 1201 |
+
def __init__(self, initlist=None):
|
| 1202 |
+
self.data = []
|
| 1203 |
+
if initlist is not None:
|
| 1204 |
+
# XXX should this accept an arbitrary sequence?
|
| 1205 |
+
if type(initlist) == type(self.data):
|
| 1206 |
+
self.data[:] = initlist
|
| 1207 |
+
elif isinstance(initlist, UserList):
|
| 1208 |
+
self.data[:] = initlist.data[:]
|
| 1209 |
+
else:
|
| 1210 |
+
self.data = list(initlist)
|
| 1211 |
+
|
| 1212 |
+
def __repr__(self):
|
| 1213 |
+
return repr(self.data)
|
| 1214 |
+
|
| 1215 |
+
def __lt__(self, other):
|
| 1216 |
+
return self.data < self.__cast(other)
|
| 1217 |
+
|
| 1218 |
+
def __le__(self, other):
|
| 1219 |
+
return self.data <= self.__cast(other)
|
| 1220 |
+
|
| 1221 |
+
def __eq__(self, other):
|
| 1222 |
+
return self.data == self.__cast(other)
|
| 1223 |
+
|
| 1224 |
+
def __gt__(self, other):
|
| 1225 |
+
return self.data > self.__cast(other)
|
| 1226 |
+
|
| 1227 |
+
def __ge__(self, other):
|
| 1228 |
+
return self.data >= self.__cast(other)
|
| 1229 |
+
|
| 1230 |
+
def __cast(self, other):
|
| 1231 |
+
return other.data if isinstance(other, UserList) else other
|
| 1232 |
+
|
| 1233 |
+
def __contains__(self, item):
|
| 1234 |
+
return item in self.data
|
| 1235 |
+
|
| 1236 |
+
def __len__(self):
|
| 1237 |
+
return len(self.data)
|
| 1238 |
+
|
| 1239 |
+
def __getitem__(self, i):
|
| 1240 |
+
if isinstance(i, slice):
|
| 1241 |
+
return self.__class__(self.data[i])
|
| 1242 |
+
else:
|
| 1243 |
+
return self.data[i]
|
| 1244 |
+
|
| 1245 |
+
def __setitem__(self, i, item):
|
| 1246 |
+
self.data[i] = item
|
| 1247 |
+
|
| 1248 |
+
def __delitem__(self, i):
|
| 1249 |
+
del self.data[i]
|
| 1250 |
+
|
| 1251 |
+
def __add__(self, other):
|
| 1252 |
+
if isinstance(other, UserList):
|
| 1253 |
+
return self.__class__(self.data + other.data)
|
| 1254 |
+
elif isinstance(other, type(self.data)):
|
| 1255 |
+
return self.__class__(self.data + other)
|
| 1256 |
+
return self.__class__(self.data + list(other))
|
| 1257 |
+
|
| 1258 |
+
def __radd__(self, other):
|
| 1259 |
+
if isinstance(other, UserList):
|
| 1260 |
+
return self.__class__(other.data + self.data)
|
| 1261 |
+
elif isinstance(other, type(self.data)):
|
| 1262 |
+
return self.__class__(other + self.data)
|
| 1263 |
+
return self.__class__(list(other) + self.data)
|
| 1264 |
+
|
| 1265 |
+
def __iadd__(self, other):
|
| 1266 |
+
if isinstance(other, UserList):
|
| 1267 |
+
self.data += other.data
|
| 1268 |
+
elif isinstance(other, type(self.data)):
|
| 1269 |
+
self.data += other
|
| 1270 |
+
else:
|
| 1271 |
+
self.data += list(other)
|
| 1272 |
+
return self
|
| 1273 |
+
|
| 1274 |
+
def __mul__(self, n):
|
| 1275 |
+
return self.__class__(self.data * n)
|
| 1276 |
+
|
| 1277 |
+
__rmul__ = __mul__
|
| 1278 |
+
|
| 1279 |
+
def __imul__(self, n):
|
| 1280 |
+
self.data *= n
|
| 1281 |
+
return self
|
| 1282 |
+
|
| 1283 |
+
def __copy__(self):
|
| 1284 |
+
inst = self.__class__.__new__(self.__class__)
|
| 1285 |
+
inst.__dict__.update(self.__dict__)
|
| 1286 |
+
# Create a copy and avoid triggering descriptors
|
| 1287 |
+
inst.__dict__["data"] = self.__dict__["data"][:]
|
| 1288 |
+
return inst
|
| 1289 |
+
|
| 1290 |
+
def append(self, item):
|
| 1291 |
+
self.data.append(item)
|
| 1292 |
+
|
| 1293 |
+
def insert(self, i, item):
|
| 1294 |
+
self.data.insert(i, item)
|
| 1295 |
+
|
| 1296 |
+
def pop(self, i=-1):
|
| 1297 |
+
return self.data.pop(i)
|
| 1298 |
+
|
| 1299 |
+
def remove(self, item):
|
| 1300 |
+
self.data.remove(item)
|
| 1301 |
+
|
| 1302 |
+
def clear(self):
|
| 1303 |
+
self.data.clear()
|
| 1304 |
+
|
| 1305 |
+
def copy(self):
|
| 1306 |
+
return self.__class__(self)
|
| 1307 |
+
|
| 1308 |
+
def count(self, item):
|
| 1309 |
+
return self.data.count(item)
|
| 1310 |
+
|
| 1311 |
+
def index(self, item, *args):
|
| 1312 |
+
return self.data.index(item, *args)
|
| 1313 |
+
|
| 1314 |
+
def reverse(self):
|
| 1315 |
+
self.data.reverse()
|
| 1316 |
+
|
| 1317 |
+
def sort(self, /, *args, **kwds):
|
| 1318 |
+
self.data.sort(*args, **kwds)
|
| 1319 |
+
|
| 1320 |
+
def extend(self, other):
|
| 1321 |
+
if isinstance(other, UserList):
|
| 1322 |
+
self.data.extend(other.data)
|
| 1323 |
+
else:
|
| 1324 |
+
self.data.extend(other)
|
| 1325 |
+
|
| 1326 |
+
|
| 1327 |
+
################################################################################
|
| 1328 |
+
### UserString
|
| 1329 |
+
################################################################################
|
| 1330 |
+
|
| 1331 |
+
class UserString(_collections_abc.Sequence):
|
| 1332 |
+
|
| 1333 |
+
def __init__(self, seq):
|
| 1334 |
+
if isinstance(seq, str):
|
| 1335 |
+
self.data = seq
|
| 1336 |
+
elif isinstance(seq, UserString):
|
| 1337 |
+
self.data = seq.data[:]
|
| 1338 |
+
else:
|
| 1339 |
+
self.data = str(seq)
|
| 1340 |
+
|
| 1341 |
+
def __str__(self):
|
| 1342 |
+
return str(self.data)
|
| 1343 |
+
|
| 1344 |
+
def __repr__(self):
|
| 1345 |
+
return repr(self.data)
|
| 1346 |
+
|
| 1347 |
+
def __int__(self):
|
| 1348 |
+
return int(self.data)
|
| 1349 |
+
|
| 1350 |
+
def __float__(self):
|
| 1351 |
+
return float(self.data)
|
| 1352 |
+
|
| 1353 |
+
def __complex__(self):
|
| 1354 |
+
return complex(self.data)
|
| 1355 |
+
|
| 1356 |
+
def __hash__(self):
|
| 1357 |
+
return hash(self.data)
|
| 1358 |
+
|
| 1359 |
+
def __getnewargs__(self):
|
| 1360 |
+
return (self.data[:],)
|
| 1361 |
+
|
| 1362 |
+
def __eq__(self, string):
|
| 1363 |
+
if isinstance(string, UserString):
|
| 1364 |
+
return self.data == string.data
|
| 1365 |
+
return self.data == string
|
| 1366 |
+
|
| 1367 |
+
def __lt__(self, string):
|
| 1368 |
+
if isinstance(string, UserString):
|
| 1369 |
+
return self.data < string.data
|
| 1370 |
+
return self.data < string
|
| 1371 |
+
|
| 1372 |
+
def __le__(self, string):
|
| 1373 |
+
if isinstance(string, UserString):
|
| 1374 |
+
return self.data <= string.data
|
| 1375 |
+
return self.data <= string
|
| 1376 |
+
|
| 1377 |
+
def __gt__(self, string):
|
| 1378 |
+
if isinstance(string, UserString):
|
| 1379 |
+
return self.data > string.data
|
| 1380 |
+
return self.data > string
|
| 1381 |
+
|
| 1382 |
+
def __ge__(self, string):
|
| 1383 |
+
if isinstance(string, UserString):
|
| 1384 |
+
return self.data >= string.data
|
| 1385 |
+
return self.data >= string
|
| 1386 |
+
|
| 1387 |
+
def __contains__(self, char):
|
| 1388 |
+
if isinstance(char, UserString):
|
| 1389 |
+
char = char.data
|
| 1390 |
+
return char in self.data
|
| 1391 |
+
|
| 1392 |
+
def __len__(self):
|
| 1393 |
+
return len(self.data)
|
| 1394 |
+
|
| 1395 |
+
def __getitem__(self, index):
|
| 1396 |
+
return self.__class__(self.data[index])
|
| 1397 |
+
|
| 1398 |
+
def __add__(self, other):
|
| 1399 |
+
if isinstance(other, UserString):
|
| 1400 |
+
return self.__class__(self.data + other.data)
|
| 1401 |
+
elif isinstance(other, str):
|
| 1402 |
+
return self.__class__(self.data + other)
|
| 1403 |
+
return self.__class__(self.data + str(other))
|
| 1404 |
+
|
| 1405 |
+
def __radd__(self, other):
|
| 1406 |
+
if isinstance(other, str):
|
| 1407 |
+
return self.__class__(other + self.data)
|
| 1408 |
+
return self.__class__(str(other) + self.data)
|
| 1409 |
+
|
| 1410 |
+
def __mul__(self, n):
|
| 1411 |
+
return self.__class__(self.data * n)
|
| 1412 |
+
|
| 1413 |
+
__rmul__ = __mul__
|
| 1414 |
+
|
| 1415 |
+
def __mod__(self, args):
|
| 1416 |
+
return self.__class__(self.data % args)
|
| 1417 |
+
|
| 1418 |
+
def __rmod__(self, template):
|
| 1419 |
+
return self.__class__(str(template) % self)
|
| 1420 |
+
|
| 1421 |
+
# the following methods are defined in alphabetical order:
|
| 1422 |
+
def capitalize(self):
|
| 1423 |
+
return self.__class__(self.data.capitalize())
|
| 1424 |
+
|
| 1425 |
+
def casefold(self):
|
| 1426 |
+
return self.__class__(self.data.casefold())
|
| 1427 |
+
|
| 1428 |
+
def center(self, width, *args):
|
| 1429 |
+
return self.__class__(self.data.center(width, *args))
|
| 1430 |
+
|
| 1431 |
+
def count(self, sub, start=0, end=_sys.maxsize):
|
| 1432 |
+
if isinstance(sub, UserString):
|
| 1433 |
+
sub = sub.data
|
| 1434 |
+
return self.data.count(sub, start, end)
|
| 1435 |
+
|
| 1436 |
+
def removeprefix(self, prefix, /):
|
| 1437 |
+
if isinstance(prefix, UserString):
|
| 1438 |
+
prefix = prefix.data
|
| 1439 |
+
return self.__class__(self.data.removeprefix(prefix))
|
| 1440 |
+
|
| 1441 |
+
def removesuffix(self, suffix, /):
|
| 1442 |
+
if isinstance(suffix, UserString):
|
| 1443 |
+
suffix = suffix.data
|
| 1444 |
+
return self.__class__(self.data.removesuffix(suffix))
|
| 1445 |
+
|
| 1446 |
+
def encode(self, encoding='utf-8', errors='strict'):
|
| 1447 |
+
encoding = 'utf-8' if encoding is None else encoding
|
| 1448 |
+
errors = 'strict' if errors is None else errors
|
| 1449 |
+
return self.data.encode(encoding, errors)
|
| 1450 |
+
|
| 1451 |
+
def endswith(self, suffix, start=0, end=_sys.maxsize):
|
| 1452 |
+
return self.data.endswith(suffix, start, end)
|
| 1453 |
+
|
| 1454 |
+
def expandtabs(self, tabsize=8):
|
| 1455 |
+
return self.__class__(self.data.expandtabs(tabsize))
|
| 1456 |
+
|
| 1457 |
+
def find(self, sub, start=0, end=_sys.maxsize):
|
| 1458 |
+
if isinstance(sub, UserString):
|
| 1459 |
+
sub = sub.data
|
| 1460 |
+
return self.data.find(sub, start, end)
|
| 1461 |
+
|
| 1462 |
+
def format(self, /, *args, **kwds):
|
| 1463 |
+
return self.data.format(*args, **kwds)
|
| 1464 |
+
|
| 1465 |
+
def format_map(self, mapping):
|
| 1466 |
+
return self.data.format_map(mapping)
|
| 1467 |
+
|
| 1468 |
+
def index(self, sub, start=0, end=_sys.maxsize):
|
| 1469 |
+
return self.data.index(sub, start, end)
|
| 1470 |
+
|
| 1471 |
+
def isalpha(self):
|
| 1472 |
+
return self.data.isalpha()
|
| 1473 |
+
|
| 1474 |
+
def isalnum(self):
|
| 1475 |
+
return self.data.isalnum()
|
| 1476 |
+
|
| 1477 |
+
def isascii(self):
|
| 1478 |
+
return self.data.isascii()
|
| 1479 |
+
|
| 1480 |
+
def isdecimal(self):
|
| 1481 |
+
return self.data.isdecimal()
|
| 1482 |
+
|
| 1483 |
+
def isdigit(self):
|
| 1484 |
+
return self.data.isdigit()
|
| 1485 |
+
|
| 1486 |
+
def isidentifier(self):
|
| 1487 |
+
return self.data.isidentifier()
|
| 1488 |
+
|
| 1489 |
+
def islower(self):
|
| 1490 |
+
return self.data.islower()
|
| 1491 |
+
|
| 1492 |
+
def isnumeric(self):
|
| 1493 |
+
return self.data.isnumeric()
|
| 1494 |
+
|
| 1495 |
+
def isprintable(self):
|
| 1496 |
+
return self.data.isprintable()
|
| 1497 |
+
|
| 1498 |
+
def isspace(self):
|
| 1499 |
+
return self.data.isspace()
|
| 1500 |
+
|
| 1501 |
+
def istitle(self):
|
| 1502 |
+
return self.data.istitle()
|
| 1503 |
+
|
| 1504 |
+
def isupper(self):
|
| 1505 |
+
return self.data.isupper()
|
| 1506 |
+
|
| 1507 |
+
def join(self, seq):
|
| 1508 |
+
return self.data.join(seq)
|
| 1509 |
+
|
| 1510 |
+
def ljust(self, width, *args):
|
| 1511 |
+
return self.__class__(self.data.ljust(width, *args))
|
| 1512 |
+
|
| 1513 |
+
def lower(self):
|
| 1514 |
+
return self.__class__(self.data.lower())
|
| 1515 |
+
|
| 1516 |
+
def lstrip(self, chars=None):
|
| 1517 |
+
return self.__class__(self.data.lstrip(chars))
|
| 1518 |
+
|
| 1519 |
+
maketrans = str.maketrans
|
| 1520 |
+
|
| 1521 |
+
def partition(self, sep):
|
| 1522 |
+
return self.data.partition(sep)
|
| 1523 |
+
|
| 1524 |
+
def replace(self, old, new, maxsplit=-1):
|
| 1525 |
+
if isinstance(old, UserString):
|
| 1526 |
+
old = old.data
|
| 1527 |
+
if isinstance(new, UserString):
|
| 1528 |
+
new = new.data
|
| 1529 |
+
return self.__class__(self.data.replace(old, new, maxsplit))
|
| 1530 |
+
|
| 1531 |
+
def rfind(self, sub, start=0, end=_sys.maxsize):
|
| 1532 |
+
if isinstance(sub, UserString):
|
| 1533 |
+
sub = sub.data
|
| 1534 |
+
return self.data.rfind(sub, start, end)
|
| 1535 |
+
|
| 1536 |
+
def rindex(self, sub, start=0, end=_sys.maxsize):
|
| 1537 |
+
return self.data.rindex(sub, start, end)
|
| 1538 |
+
|
| 1539 |
+
def rjust(self, width, *args):
|
| 1540 |
+
return self.__class__(self.data.rjust(width, *args))
|
| 1541 |
+
|
| 1542 |
+
def rpartition(self, sep):
|
| 1543 |
+
return self.data.rpartition(sep)
|
| 1544 |
+
|
| 1545 |
+
def rstrip(self, chars=None):
|
| 1546 |
+
return self.__class__(self.data.rstrip(chars))
|
| 1547 |
+
|
| 1548 |
+
def split(self, sep=None, maxsplit=-1):
|
| 1549 |
+
return self.data.split(sep, maxsplit)
|
| 1550 |
+
|
| 1551 |
+
def rsplit(self, sep=None, maxsplit=-1):
|
| 1552 |
+
return self.data.rsplit(sep, maxsplit)
|
| 1553 |
+
|
| 1554 |
+
def splitlines(self, keepends=False):
|
| 1555 |
+
return self.data.splitlines(keepends)
|
| 1556 |
+
|
| 1557 |
+
def startswith(self, prefix, start=0, end=_sys.maxsize):
|
| 1558 |
+
return self.data.startswith(prefix, start, end)
|
| 1559 |
+
|
| 1560 |
+
def strip(self, chars=None):
|
| 1561 |
+
return self.__class__(self.data.strip(chars))
|
| 1562 |
+
|
| 1563 |
+
def swapcase(self):
|
| 1564 |
+
return self.__class__(self.data.swapcase())
|
| 1565 |
+
|
| 1566 |
+
def title(self):
|
| 1567 |
+
return self.__class__(self.data.title())
|
| 1568 |
+
|
| 1569 |
+
def translate(self, *args):
|
| 1570 |
+
return self.__class__(self.data.translate(*args))
|
| 1571 |
+
|
| 1572 |
+
def upper(self):
|
| 1573 |
+
return self.__class__(self.data.upper())
|
| 1574 |
+
|
| 1575 |
+
def zfill(self, width):
|
| 1576 |
+
return self.__class__(self.data.zfill(width))
|
data/conda_envs/evalclaw/lib/python3.11/collections/abc.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from _collections_abc import *
|
| 2 |
+
from _collections_abc import __all__
|
| 3 |
+
from _collections_abc import _CallableGenericAlias
|
data/conda_envs/evalclaw/lib/python3.11/ctypes/__init__.py
ADDED
|
@@ -0,0 +1,566 @@
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""create and manipulate C data types in Python"""
|
| 2 |
+
|
| 3 |
+
import os as _os, sys as _sys
|
| 4 |
+
import types as _types
|
| 5 |
+
|
| 6 |
+
__version__ = "1.1.0"
|
| 7 |
+
|
| 8 |
+
from _ctypes import Union, Structure, Array
|
| 9 |
+
from _ctypes import _Pointer
|
| 10 |
+
from _ctypes import CFuncPtr as _CFuncPtr
|
| 11 |
+
from _ctypes import __version__ as _ctypes_version
|
| 12 |
+
from _ctypes import RTLD_LOCAL, RTLD_GLOBAL
|
| 13 |
+
from _ctypes import ArgumentError
|
| 14 |
+
|
| 15 |
+
from struct import calcsize as _calcsize
|
| 16 |
+
|
| 17 |
+
if __version__ != _ctypes_version:
|
| 18 |
+
raise Exception("Version number mismatch", __version__, _ctypes_version)
|
| 19 |
+
|
| 20 |
+
if _os.name == "nt":
|
| 21 |
+
from _ctypes import FormatError
|
| 22 |
+
|
| 23 |
+
DEFAULT_MODE = RTLD_LOCAL
|
| 24 |
+
if _os.name == "posix" and _sys.platform == "darwin":
|
| 25 |
+
# On OS X 10.3, we use RTLD_GLOBAL as default mode
|
| 26 |
+
# because RTLD_LOCAL does not work at least on some
|
| 27 |
+
# libraries. OS X 10.3 is Darwin 7, so we check for
|
| 28 |
+
# that.
|
| 29 |
+
|
| 30 |
+
if int(_os.uname().release.split('.')[0]) < 8:
|
| 31 |
+
DEFAULT_MODE = RTLD_GLOBAL
|
| 32 |
+
|
| 33 |
+
from _ctypes import FUNCFLAG_CDECL as _FUNCFLAG_CDECL, \
|
| 34 |
+
FUNCFLAG_PYTHONAPI as _FUNCFLAG_PYTHONAPI, \
|
| 35 |
+
FUNCFLAG_USE_ERRNO as _FUNCFLAG_USE_ERRNO, \
|
| 36 |
+
FUNCFLAG_USE_LASTERROR as _FUNCFLAG_USE_LASTERROR
|
| 37 |
+
|
| 38 |
+
# WINOLEAPI -> HRESULT
|
| 39 |
+
# WINOLEAPI_(type)
|
| 40 |
+
#
|
| 41 |
+
# STDMETHODCALLTYPE
|
| 42 |
+
#
|
| 43 |
+
# STDMETHOD(name)
|
| 44 |
+
# STDMETHOD_(type, name)
|
| 45 |
+
#
|
| 46 |
+
# STDAPICALLTYPE
|
| 47 |
+
|
| 48 |
+
def create_string_buffer(init, size=None):
|
| 49 |
+
"""create_string_buffer(aBytes) -> character array
|
| 50 |
+
create_string_buffer(anInteger) -> character array
|
| 51 |
+
create_string_buffer(aBytes, anInteger) -> character array
|
| 52 |
+
"""
|
| 53 |
+
if isinstance(init, bytes):
|
| 54 |
+
if size is None:
|
| 55 |
+
size = len(init)+1
|
| 56 |
+
_sys.audit("ctypes.create_string_buffer", init, size)
|
| 57 |
+
buftype = c_char * size
|
| 58 |
+
buf = buftype()
|
| 59 |
+
buf.value = init
|
| 60 |
+
return buf
|
| 61 |
+
elif isinstance(init, int):
|
| 62 |
+
_sys.audit("ctypes.create_string_buffer", None, init)
|
| 63 |
+
buftype = c_char * init
|
| 64 |
+
buf = buftype()
|
| 65 |
+
return buf
|
| 66 |
+
raise TypeError(init)
|
| 67 |
+
|
| 68 |
+
# Alias to create_string_buffer() for backward compatibility
|
| 69 |
+
c_buffer = create_string_buffer
|
| 70 |
+
|
| 71 |
+
_c_functype_cache = {}
|
| 72 |
+
def CFUNCTYPE(restype, *argtypes, **kw):
|
| 73 |
+
"""CFUNCTYPE(restype, *argtypes,
|
| 74 |
+
use_errno=False, use_last_error=False) -> function prototype.
|
| 75 |
+
|
| 76 |
+
restype: the result type
|
| 77 |
+
argtypes: a sequence specifying the argument types
|
| 78 |
+
|
| 79 |
+
The function prototype can be called in different ways to create a
|
| 80 |
+
callable object:
|
| 81 |
+
|
| 82 |
+
prototype(integer address) -> foreign function
|
| 83 |
+
prototype(callable) -> create and return a C callable function from callable
|
| 84 |
+
prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method
|
| 85 |
+
prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal
|
| 86 |
+
prototype((function name, dll object)[, paramflags]) -> foreign function exported by name
|
| 87 |
+
"""
|
| 88 |
+
flags = _FUNCFLAG_CDECL
|
| 89 |
+
if kw.pop("use_errno", False):
|
| 90 |
+
flags |= _FUNCFLAG_USE_ERRNO
|
| 91 |
+
if kw.pop("use_last_error", False):
|
| 92 |
+
flags |= _FUNCFLAG_USE_LASTERROR
|
| 93 |
+
if kw:
|
| 94 |
+
raise ValueError("unexpected keyword argument(s) %s" % kw.keys())
|
| 95 |
+
|
| 96 |
+
try:
|
| 97 |
+
return _c_functype_cache[(restype, argtypes, flags)]
|
| 98 |
+
except KeyError:
|
| 99 |
+
pass
|
| 100 |
+
|
| 101 |
+
class CFunctionType(_CFuncPtr):
|
| 102 |
+
_argtypes_ = argtypes
|
| 103 |
+
_restype_ = restype
|
| 104 |
+
_flags_ = flags
|
| 105 |
+
_c_functype_cache[(restype, argtypes, flags)] = CFunctionType
|
| 106 |
+
return CFunctionType
|
| 107 |
+
|
| 108 |
+
if _os.name == "nt":
|
| 109 |
+
from _ctypes import LoadLibrary as _dlopen
|
| 110 |
+
from _ctypes import FUNCFLAG_STDCALL as _FUNCFLAG_STDCALL
|
| 111 |
+
|
| 112 |
+
_win_functype_cache = {}
|
| 113 |
+
def WINFUNCTYPE(restype, *argtypes, **kw):
|
| 114 |
+
# docstring set later (very similar to CFUNCTYPE.__doc__)
|
| 115 |
+
flags = _FUNCFLAG_STDCALL
|
| 116 |
+
if kw.pop("use_errno", False):
|
| 117 |
+
flags |= _FUNCFLAG_USE_ERRNO
|
| 118 |
+
if kw.pop("use_last_error", False):
|
| 119 |
+
flags |= _FUNCFLAG_USE_LASTERROR
|
| 120 |
+
if kw:
|
| 121 |
+
raise ValueError("unexpected keyword argument(s) %s" % kw.keys())
|
| 122 |
+
|
| 123 |
+
try:
|
| 124 |
+
return _win_functype_cache[(restype, argtypes, flags)]
|
| 125 |
+
except KeyError:
|
| 126 |
+
pass
|
| 127 |
+
|
| 128 |
+
class WinFunctionType(_CFuncPtr):
|
| 129 |
+
_argtypes_ = argtypes
|
| 130 |
+
_restype_ = restype
|
| 131 |
+
_flags_ = flags
|
| 132 |
+
_win_functype_cache[(restype, argtypes, flags)] = WinFunctionType
|
| 133 |
+
return WinFunctionType
|
| 134 |
+
if WINFUNCTYPE.__doc__:
|
| 135 |
+
WINFUNCTYPE.__doc__ = CFUNCTYPE.__doc__.replace("CFUNCTYPE", "WINFUNCTYPE")
|
| 136 |
+
|
| 137 |
+
elif _os.name == "posix":
|
| 138 |
+
from _ctypes import dlopen as _dlopen
|
| 139 |
+
|
| 140 |
+
from _ctypes import sizeof, byref, addressof, alignment, resize
|
| 141 |
+
from _ctypes import get_errno, set_errno
|
| 142 |
+
from _ctypes import _SimpleCData
|
| 143 |
+
|
| 144 |
+
def _check_size(typ, typecode=None):
|
| 145 |
+
# Check if sizeof(ctypes_type) against struct.calcsize. This
|
| 146 |
+
# should protect somewhat against a misconfigured libffi.
|
| 147 |
+
from struct import calcsize
|
| 148 |
+
if typecode is None:
|
| 149 |
+
# Most _type_ codes are the same as used in struct
|
| 150 |
+
typecode = typ._type_
|
| 151 |
+
actual, required = sizeof(typ), calcsize(typecode)
|
| 152 |
+
if actual != required:
|
| 153 |
+
raise SystemError("sizeof(%s) wrong: %d instead of %d" % \
|
| 154 |
+
(typ, actual, required))
|
| 155 |
+
|
| 156 |
+
class py_object(_SimpleCData):
|
| 157 |
+
_type_ = "O"
|
| 158 |
+
def __repr__(self):
|
| 159 |
+
try:
|
| 160 |
+
return super().__repr__()
|
| 161 |
+
except ValueError:
|
| 162 |
+
return "%s(<NULL>)" % type(self).__name__
|
| 163 |
+
_check_size(py_object, "P")
|
| 164 |
+
|
| 165 |
+
class c_short(_SimpleCData):
|
| 166 |
+
_type_ = "h"
|
| 167 |
+
_check_size(c_short)
|
| 168 |
+
|
| 169 |
+
class c_ushort(_SimpleCData):
|
| 170 |
+
_type_ = "H"
|
| 171 |
+
_check_size(c_ushort)
|
| 172 |
+
|
| 173 |
+
class c_long(_SimpleCData):
|
| 174 |
+
_type_ = "l"
|
| 175 |
+
_check_size(c_long)
|
| 176 |
+
|
| 177 |
+
class c_ulong(_SimpleCData):
|
| 178 |
+
_type_ = "L"
|
| 179 |
+
_check_size(c_ulong)
|
| 180 |
+
|
| 181 |
+
if _calcsize("i") == _calcsize("l"):
|
| 182 |
+
# if int and long have the same size, make c_int an alias for c_long
|
| 183 |
+
c_int = c_long
|
| 184 |
+
c_uint = c_ulong
|
| 185 |
+
else:
|
| 186 |
+
class c_int(_SimpleCData):
|
| 187 |
+
_type_ = "i"
|
| 188 |
+
_check_size(c_int)
|
| 189 |
+
|
| 190 |
+
class c_uint(_SimpleCData):
|
| 191 |
+
_type_ = "I"
|
| 192 |
+
_check_size(c_uint)
|
| 193 |
+
|
| 194 |
+
class c_float(_SimpleCData):
|
| 195 |
+
_type_ = "f"
|
| 196 |
+
_check_size(c_float)
|
| 197 |
+
|
| 198 |
+
class c_double(_SimpleCData):
|
| 199 |
+
_type_ = "d"
|
| 200 |
+
_check_size(c_double)
|
| 201 |
+
|
| 202 |
+
class c_longdouble(_SimpleCData):
|
| 203 |
+
_type_ = "g"
|
| 204 |
+
if sizeof(c_longdouble) == sizeof(c_double):
|
| 205 |
+
c_longdouble = c_double
|
| 206 |
+
|
| 207 |
+
if _calcsize("l") == _calcsize("q"):
|
| 208 |
+
# if long and long long have the same size, make c_longlong an alias for c_long
|
| 209 |
+
c_longlong = c_long
|
| 210 |
+
c_ulonglong = c_ulong
|
| 211 |
+
else:
|
| 212 |
+
class c_longlong(_SimpleCData):
|
| 213 |
+
_type_ = "q"
|
| 214 |
+
_check_size(c_longlong)
|
| 215 |
+
|
| 216 |
+
class c_ulonglong(_SimpleCData):
|
| 217 |
+
_type_ = "Q"
|
| 218 |
+
## def from_param(cls, val):
|
| 219 |
+
## return ('d', float(val), val)
|
| 220 |
+
## from_param = classmethod(from_param)
|
| 221 |
+
_check_size(c_ulonglong)
|
| 222 |
+
|
| 223 |
+
class c_ubyte(_SimpleCData):
|
| 224 |
+
_type_ = "B"
|
| 225 |
+
c_ubyte.__ctype_le__ = c_ubyte.__ctype_be__ = c_ubyte
|
| 226 |
+
# backward compatibility:
|
| 227 |
+
##c_uchar = c_ubyte
|
| 228 |
+
_check_size(c_ubyte)
|
| 229 |
+
|
| 230 |
+
class c_byte(_SimpleCData):
|
| 231 |
+
_type_ = "b"
|
| 232 |
+
c_byte.__ctype_le__ = c_byte.__ctype_be__ = c_byte
|
| 233 |
+
_check_size(c_byte)
|
| 234 |
+
|
| 235 |
+
class c_char(_SimpleCData):
|
| 236 |
+
_type_ = "c"
|
| 237 |
+
c_char.__ctype_le__ = c_char.__ctype_be__ = c_char
|
| 238 |
+
_check_size(c_char)
|
| 239 |
+
|
| 240 |
+
class c_char_p(_SimpleCData):
|
| 241 |
+
_type_ = "z"
|
| 242 |
+
def __repr__(self):
|
| 243 |
+
return "%s(%s)" % (self.__class__.__name__, c_void_p.from_buffer(self).value)
|
| 244 |
+
_check_size(c_char_p, "P")
|
| 245 |
+
|
| 246 |
+
class c_void_p(_SimpleCData):
|
| 247 |
+
_type_ = "P"
|
| 248 |
+
c_voidp = c_void_p # backwards compatibility (to a bug)
|
| 249 |
+
_check_size(c_void_p)
|
| 250 |
+
|
| 251 |
+
class c_bool(_SimpleCData):
|
| 252 |
+
_type_ = "?"
|
| 253 |
+
|
| 254 |
+
from _ctypes import POINTER, pointer, _pointer_type_cache
|
| 255 |
+
|
| 256 |
+
class c_wchar_p(_SimpleCData):
|
| 257 |
+
_type_ = "Z"
|
| 258 |
+
def __repr__(self):
|
| 259 |
+
return "%s(%s)" % (self.__class__.__name__, c_void_p.from_buffer(self).value)
|
| 260 |
+
|
| 261 |
+
class c_wchar(_SimpleCData):
|
| 262 |
+
_type_ = "u"
|
| 263 |
+
|
| 264 |
+
def _reset_cache():
|
| 265 |
+
_pointer_type_cache.clear()
|
| 266 |
+
_c_functype_cache.clear()
|
| 267 |
+
if _os.name == "nt":
|
| 268 |
+
_win_functype_cache.clear()
|
| 269 |
+
# _SimpleCData.c_wchar_p_from_param
|
| 270 |
+
POINTER(c_wchar).from_param = c_wchar_p.from_param
|
| 271 |
+
# _SimpleCData.c_char_p_from_param
|
| 272 |
+
POINTER(c_char).from_param = c_char_p.from_param
|
| 273 |
+
_pointer_type_cache[None] = c_void_p
|
| 274 |
+
|
| 275 |
+
def create_unicode_buffer(init, size=None):
|
| 276 |
+
"""create_unicode_buffer(aString) -> character array
|
| 277 |
+
create_unicode_buffer(anInteger) -> character array
|
| 278 |
+
create_unicode_buffer(aString, anInteger) -> character array
|
| 279 |
+
"""
|
| 280 |
+
if isinstance(init, str):
|
| 281 |
+
if size is None:
|
| 282 |
+
if sizeof(c_wchar) == 2:
|
| 283 |
+
# UTF-16 requires a surrogate pair (2 wchar_t) for non-BMP
|
| 284 |
+
# characters (outside [U+0000; U+FFFF] range). +1 for trailing
|
| 285 |
+
# NUL character.
|
| 286 |
+
size = sum(2 if ord(c) > 0xFFFF else 1 for c in init) + 1
|
| 287 |
+
else:
|
| 288 |
+
# 32-bit wchar_t (1 wchar_t per Unicode character). +1 for
|
| 289 |
+
# trailing NUL character.
|
| 290 |
+
size = len(init) + 1
|
| 291 |
+
_sys.audit("ctypes.create_unicode_buffer", init, size)
|
| 292 |
+
buftype = c_wchar * size
|
| 293 |
+
buf = buftype()
|
| 294 |
+
buf.value = init
|
| 295 |
+
return buf
|
| 296 |
+
elif isinstance(init, int):
|
| 297 |
+
_sys.audit("ctypes.create_unicode_buffer", None, init)
|
| 298 |
+
buftype = c_wchar * init
|
| 299 |
+
buf = buftype()
|
| 300 |
+
return buf
|
| 301 |
+
raise TypeError(init)
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
# XXX Deprecated
|
| 305 |
+
def SetPointerType(pointer, cls):
|
| 306 |
+
if _pointer_type_cache.get(cls, None) is not None:
|
| 307 |
+
raise RuntimeError("This type already exists in the cache")
|
| 308 |
+
if id(pointer) not in _pointer_type_cache:
|
| 309 |
+
raise RuntimeError("What's this???")
|
| 310 |
+
pointer.set_type(cls)
|
| 311 |
+
_pointer_type_cache[cls] = pointer
|
| 312 |
+
del _pointer_type_cache[id(pointer)]
|
| 313 |
+
|
| 314 |
+
# XXX Deprecated
|
| 315 |
+
def ARRAY(typ, len):
|
| 316 |
+
return typ * len
|
| 317 |
+
|
| 318 |
+
################################################################
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
class CDLL(object):
|
| 322 |
+
"""An instance of this class represents a loaded dll/shared
|
| 323 |
+
library, exporting functions using the standard C calling
|
| 324 |
+
convention (named 'cdecl' on Windows).
|
| 325 |
+
|
| 326 |
+
The exported functions can be accessed as attributes, or by
|
| 327 |
+
indexing with the function name. Examples:
|
| 328 |
+
|
| 329 |
+
<obj>.qsort -> callable object
|
| 330 |
+
<obj>['qsort'] -> callable object
|
| 331 |
+
|
| 332 |
+
Calling the functions releases the Python GIL during the call and
|
| 333 |
+
reacquires it afterwards.
|
| 334 |
+
"""
|
| 335 |
+
_func_flags_ = _FUNCFLAG_CDECL
|
| 336 |
+
_func_restype_ = c_int
|
| 337 |
+
# default values for repr
|
| 338 |
+
_name = '<uninitialized>'
|
| 339 |
+
_handle = 0
|
| 340 |
+
_FuncPtr = None
|
| 341 |
+
|
| 342 |
+
def __init__(self, name, mode=DEFAULT_MODE, handle=None,
|
| 343 |
+
use_errno=False,
|
| 344 |
+
use_last_error=False,
|
| 345 |
+
winmode=None):
|
| 346 |
+
self._name = name
|
| 347 |
+
flags = self._func_flags_
|
| 348 |
+
if use_errno:
|
| 349 |
+
flags |= _FUNCFLAG_USE_ERRNO
|
| 350 |
+
if use_last_error:
|
| 351 |
+
flags |= _FUNCFLAG_USE_LASTERROR
|
| 352 |
+
if _sys.platform.startswith("aix"):
|
| 353 |
+
"""When the name contains ".a(" and ends with ")",
|
| 354 |
+
e.g., "libFOO.a(libFOO.so)" - this is taken to be an
|
| 355 |
+
archive(member) syntax for dlopen(), and the mode is adjusted.
|
| 356 |
+
Otherwise, name is presented to dlopen() as a file argument.
|
| 357 |
+
"""
|
| 358 |
+
if name and name.endswith(")") and ".a(" in name:
|
| 359 |
+
mode |= ( _os.RTLD_MEMBER | _os.RTLD_NOW )
|
| 360 |
+
if _os.name == "nt":
|
| 361 |
+
if winmode is not None:
|
| 362 |
+
mode = winmode
|
| 363 |
+
else:
|
| 364 |
+
import nt
|
| 365 |
+
mode = nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
|
| 366 |
+
if '/' in name or '\\' in name:
|
| 367 |
+
self._name = nt._getfullpathname(self._name)
|
| 368 |
+
mode |= nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
|
| 369 |
+
|
| 370 |
+
class _FuncPtr(_CFuncPtr):
|
| 371 |
+
_flags_ = flags
|
| 372 |
+
_restype_ = self._func_restype_
|
| 373 |
+
self._FuncPtr = _FuncPtr
|
| 374 |
+
|
| 375 |
+
if handle is None:
|
| 376 |
+
self._handle = _dlopen(self._name, mode)
|
| 377 |
+
else:
|
| 378 |
+
self._handle = handle
|
| 379 |
+
|
| 380 |
+
def __repr__(self):
|
| 381 |
+
return "<%s '%s', handle %x at %#x>" % \
|
| 382 |
+
(self.__class__.__name__, self._name,
|
| 383 |
+
(self._handle & (_sys.maxsize*2 + 1)),
|
| 384 |
+
id(self) & (_sys.maxsize*2 + 1))
|
| 385 |
+
|
| 386 |
+
def __getattr__(self, name):
|
| 387 |
+
if name.startswith('__') and name.endswith('__'):
|
| 388 |
+
raise AttributeError(name)
|
| 389 |
+
func = self.__getitem__(name)
|
| 390 |
+
setattr(self, name, func)
|
| 391 |
+
return func
|
| 392 |
+
|
| 393 |
+
def __getitem__(self, name_or_ordinal):
|
| 394 |
+
func = self._FuncPtr((name_or_ordinal, self))
|
| 395 |
+
if not isinstance(name_or_ordinal, int):
|
| 396 |
+
func.__name__ = name_or_ordinal
|
| 397 |
+
return func
|
| 398 |
+
|
| 399 |
+
class PyDLL(CDLL):
|
| 400 |
+
"""This class represents the Python library itself. It allows
|
| 401 |
+
accessing Python API functions. The GIL is not released, and
|
| 402 |
+
Python exceptions are handled correctly.
|
| 403 |
+
"""
|
| 404 |
+
_func_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
|
| 405 |
+
|
| 406 |
+
if _os.name == "nt":
|
| 407 |
+
|
| 408 |
+
class WinDLL(CDLL):
|
| 409 |
+
"""This class represents a dll exporting functions using the
|
| 410 |
+
Windows stdcall calling convention.
|
| 411 |
+
"""
|
| 412 |
+
_func_flags_ = _FUNCFLAG_STDCALL
|
| 413 |
+
|
| 414 |
+
# XXX Hm, what about HRESULT as normal parameter?
|
| 415 |
+
# Mustn't it derive from c_long then?
|
| 416 |
+
from _ctypes import _check_HRESULT, _SimpleCData
|
| 417 |
+
class HRESULT(_SimpleCData):
|
| 418 |
+
_type_ = "l"
|
| 419 |
+
# _check_retval_ is called with the function's result when it
|
| 420 |
+
# is used as restype. It checks for the FAILED bit, and
|
| 421 |
+
# raises an OSError if it is set.
|
| 422 |
+
#
|
| 423 |
+
# The _check_retval_ method is implemented in C, so that the
|
| 424 |
+
# method definition itself is not included in the traceback
|
| 425 |
+
# when it raises an error - that is what we want (and Python
|
| 426 |
+
# doesn't have a way to raise an exception in the caller's
|
| 427 |
+
# frame).
|
| 428 |
+
_check_retval_ = _check_HRESULT
|
| 429 |
+
|
| 430 |
+
class OleDLL(CDLL):
|
| 431 |
+
"""This class represents a dll exporting functions using the
|
| 432 |
+
Windows stdcall calling convention, and returning HRESULT.
|
| 433 |
+
HRESULT error values are automatically raised as OSError
|
| 434 |
+
exceptions.
|
| 435 |
+
"""
|
| 436 |
+
_func_flags_ = _FUNCFLAG_STDCALL
|
| 437 |
+
_func_restype_ = HRESULT
|
| 438 |
+
|
| 439 |
+
class LibraryLoader(object):
|
| 440 |
+
def __init__(self, dlltype):
|
| 441 |
+
self._dlltype = dlltype
|
| 442 |
+
|
| 443 |
+
def __getattr__(self, name):
|
| 444 |
+
if name[0] == '_':
|
| 445 |
+
raise AttributeError(name)
|
| 446 |
+
dll = self._dlltype(name)
|
| 447 |
+
setattr(self, name, dll)
|
| 448 |
+
return dll
|
| 449 |
+
|
| 450 |
+
def __getitem__(self, name):
|
| 451 |
+
return getattr(self, name)
|
| 452 |
+
|
| 453 |
+
def LoadLibrary(self, name):
|
| 454 |
+
return self._dlltype(name)
|
| 455 |
+
|
| 456 |
+
__class_getitem__ = classmethod(_types.GenericAlias)
|
| 457 |
+
|
| 458 |
+
cdll = LibraryLoader(CDLL)
|
| 459 |
+
pydll = LibraryLoader(PyDLL)
|
| 460 |
+
|
| 461 |
+
if _os.name == "nt":
|
| 462 |
+
pythonapi = PyDLL("python dll", None, _sys.dllhandle)
|
| 463 |
+
elif _sys.platform == "cygwin":
|
| 464 |
+
pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2])
|
| 465 |
+
else:
|
| 466 |
+
pythonapi = PyDLL(None)
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
if _os.name == "nt":
|
| 470 |
+
windll = LibraryLoader(WinDLL)
|
| 471 |
+
oledll = LibraryLoader(OleDLL)
|
| 472 |
+
|
| 473 |
+
GetLastError = windll.kernel32.GetLastError
|
| 474 |
+
from _ctypes import get_last_error, set_last_error
|
| 475 |
+
|
| 476 |
+
def WinError(code=None, descr=None):
|
| 477 |
+
if code is None:
|
| 478 |
+
code = GetLastError()
|
| 479 |
+
if descr is None:
|
| 480 |
+
descr = FormatError(code).strip()
|
| 481 |
+
return OSError(None, descr, None, code)
|
| 482 |
+
|
| 483 |
+
if sizeof(c_uint) == sizeof(c_void_p):
|
| 484 |
+
c_size_t = c_uint
|
| 485 |
+
c_ssize_t = c_int
|
| 486 |
+
elif sizeof(c_ulong) == sizeof(c_void_p):
|
| 487 |
+
c_size_t = c_ulong
|
| 488 |
+
c_ssize_t = c_long
|
| 489 |
+
elif sizeof(c_ulonglong) == sizeof(c_void_p):
|
| 490 |
+
c_size_t = c_ulonglong
|
| 491 |
+
c_ssize_t = c_longlong
|
| 492 |
+
|
| 493 |
+
# functions
|
| 494 |
+
|
| 495 |
+
from _ctypes import _memmove_addr, _memset_addr, _string_at_addr, _cast_addr
|
| 496 |
+
|
| 497 |
+
## void *memmove(void *, const void *, size_t);
|
| 498 |
+
memmove = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)(_memmove_addr)
|
| 499 |
+
|
| 500 |
+
## void *memset(void *, int, size_t)
|
| 501 |
+
memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)(_memset_addr)
|
| 502 |
+
|
| 503 |
+
def PYFUNCTYPE(restype, *argtypes):
|
| 504 |
+
class CFunctionType(_CFuncPtr):
|
| 505 |
+
_argtypes_ = argtypes
|
| 506 |
+
_restype_ = restype
|
| 507 |
+
_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
|
| 508 |
+
return CFunctionType
|
| 509 |
+
|
| 510 |
+
_cast = PYFUNCTYPE(py_object, c_void_p, py_object, py_object)(_cast_addr)
|
| 511 |
+
def cast(obj, typ):
|
| 512 |
+
return _cast(obj, obj, typ)
|
| 513 |
+
|
| 514 |
+
_string_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)
|
| 515 |
+
def string_at(ptr, size=-1):
|
| 516 |
+
"""string_at(addr[, size]) -> string
|
| 517 |
+
|
| 518 |
+
Return the string at addr."""
|
| 519 |
+
return _string_at(ptr, size)
|
| 520 |
+
|
| 521 |
+
try:
|
| 522 |
+
from _ctypes import _wstring_at_addr
|
| 523 |
+
except ImportError:
|
| 524 |
+
pass
|
| 525 |
+
else:
|
| 526 |
+
_wstring_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr)
|
| 527 |
+
def wstring_at(ptr, size=-1):
|
| 528 |
+
"""wstring_at(addr[, size]) -> string
|
| 529 |
+
|
| 530 |
+
Return the string at addr."""
|
| 531 |
+
return _wstring_at(ptr, size)
|
| 532 |
+
|
| 533 |
+
|
| 534 |
+
if _os.name == "nt": # COM stuff
|
| 535 |
+
def DllGetClassObject(rclsid, riid, ppv):
|
| 536 |
+
try:
|
| 537 |
+
ccom = __import__("comtypes.server.inprocserver", globals(), locals(), ['*'])
|
| 538 |
+
except ImportError:
|
| 539 |
+
return -2147221231 # CLASS_E_CLASSNOTAVAILABLE
|
| 540 |
+
else:
|
| 541 |
+
return ccom.DllGetClassObject(rclsid, riid, ppv)
|
| 542 |
+
|
| 543 |
+
def DllCanUnloadNow():
|
| 544 |
+
try:
|
| 545 |
+
ccom = __import__("comtypes.server.inprocserver", globals(), locals(), ['*'])
|
| 546 |
+
except ImportError:
|
| 547 |
+
return 0 # S_OK
|
| 548 |
+
return ccom.DllCanUnloadNow()
|
| 549 |
+
|
| 550 |
+
from ctypes._endian import BigEndianStructure, LittleEndianStructure
|
| 551 |
+
from ctypes._endian import BigEndianUnion, LittleEndianUnion
|
| 552 |
+
|
| 553 |
+
# Fill in specifically-sized types
|
| 554 |
+
c_int8 = c_byte
|
| 555 |
+
c_uint8 = c_ubyte
|
| 556 |
+
for kind in [c_short, c_int, c_long, c_longlong]:
|
| 557 |
+
if sizeof(kind) == 2: c_int16 = kind
|
| 558 |
+
elif sizeof(kind) == 4: c_int32 = kind
|
| 559 |
+
elif sizeof(kind) == 8: c_int64 = kind
|
| 560 |
+
for kind in [c_ushort, c_uint, c_ulong, c_ulonglong]:
|
| 561 |
+
if sizeof(kind) == 2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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Lib/ctypes.util.find_library() support for AIX
|
| 3 |
+
Similar approach as done for Darwin support by using separate files
|
| 4 |
+
but unlike Darwin - no extension such as ctypes.macholib.*
|
| 5 |
+
|
| 6 |
+
dlopen() is an interface to AIX initAndLoad() - primary documentation at:
|
| 7 |
+
https://www.ibm.com/support/knowledgecenter/en/ssw_aix_61/com.ibm.aix.basetrf1/dlopen.htm
|
| 8 |
+
https://www.ibm.com/support/knowledgecenter/en/ssw_aix_61/com.ibm.aix.basetrf1/load.htm
|
| 9 |
+
|
| 10 |
+
AIX supports two styles for dlopen(): svr4 (System V Release 4) which is common on posix
|
| 11 |
+
platforms, but also a BSD style - aka SVR3.
|
| 12 |
+
|
| 13 |
+
From AIX 5.3 Difference Addendum (December 2004)
|
| 14 |
+
2.9 SVR4 linking affinity
|
| 15 |
+
Nowadays, there are two major object file formats used by the operating systems:
|
| 16 |
+
XCOFF: The COFF enhanced by IBM and others. The original COFF (Common
|
| 17 |
+
Object File Format) was the base of SVR3 and BSD 4.2 systems.
|
| 18 |
+
ELF: Executable and Linking Format that was developed by AT&T and is a
|
| 19 |
+
base for SVR4 UNIX.
|
| 20 |
+
|
| 21 |
+
While the shared library content is identical on AIX - one is located as a filepath name
|
| 22 |
+
(svr4 style) and the other is located as a member of an archive (and the archive
|
| 23 |
+
is located as a filepath name).
|
| 24 |
+
|
| 25 |
+
The key difference arises when supporting multiple abi formats (i.e., 32 and 64 bit).
|
| 26 |
+
For svr4 either only one ABI is supported, or there are two directories, or there
|
| 27 |
+
are different file names. The most common solution for multiple ABI is multiple
|
| 28 |
+
directories.
|
| 29 |
+
|
| 30 |
+
For the XCOFF (aka AIX) style - one directory (one archive file) is sufficient
|
| 31 |
+
as multiple shared libraries can be in the archive - even sharing the same name.
|
| 32 |
+
In documentation the archive is also referred to as the "base" and the shared
|
| 33 |
+
library object is referred to as the "member".
|
| 34 |
+
|
| 35 |
+
For dlopen() on AIX (read initAndLoad()) the calls are similar.
|
| 36 |
+
Default activity occurs when no path information is provided. When path
|
| 37 |
+
information is provided dlopen() does not search any other directories.
|
| 38 |
+
|
| 39 |
+
For SVR4 - the shared library name is the name of the file expected: libFOO.so
|
| 40 |
+
For AIX - the shared library is expressed as base(member). The search is for the
|
| 41 |
+
base (e.g., libFOO.a) and once the base is found the shared library - identified by
|
| 42 |
+
member (e.g., libFOO.so, or shr.o) is located and loaded.
|
| 43 |
+
|
| 44 |
+
The mode bit RTLD_MEMBER tells initAndLoad() that it needs to use the AIX (SVR3)
|
| 45 |
+
naming style.
|
| 46 |
+
"""
|
| 47 |
+
__author__ = "Michael Felt <aixtools@felt.demon.nl>"
|
| 48 |
+
|
| 49 |
+
import re
|
| 50 |
+
from os import environ, path
|
| 51 |
+
from sys import executable
|
| 52 |
+
from ctypes import c_void_p, sizeof
|
| 53 |
+
from subprocess import Popen, PIPE, DEVNULL
|
| 54 |
+
|
| 55 |
+
# Executable bit size - 32 or 64
|
| 56 |
+
# Used to filter the search in an archive by size, e.g., -X64
|
| 57 |
+
AIX_ABI = sizeof(c_void_p) * 8
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
from sys import maxsize
|
| 61 |
+
def _last_version(libnames, sep):
|
| 62 |
+
def _num_version(libname):
|
| 63 |
+
# "libxyz.so.MAJOR.MINOR" => [MAJOR, MINOR]
|
| 64 |
+
parts = libname.split(sep)
|
| 65 |
+
nums = []
|
| 66 |
+
try:
|
| 67 |
+
while parts:
|
| 68 |
+
nums.insert(0, int(parts.pop()))
|
| 69 |
+
except ValueError:
|
| 70 |
+
pass
|
| 71 |
+
return nums or [maxsize]
|
| 72 |
+
return max(reversed(libnames), key=_num_version)
|
| 73 |
+
|
| 74 |
+
def get_ld_header(p):
|
| 75 |
+
# "nested-function, but placed at module level
|
| 76 |
+
ld_header = None
|
| 77 |
+
for line in p.stdout:
|
| 78 |
+
if line.startswith(('/', './', '../')):
|
| 79 |
+
ld_header = line
|
| 80 |
+
elif "INDEX" in line:
|
| 81 |
+
return ld_header.rstrip('\n')
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
+
def get_ld_header_info(p):
|
| 85 |
+
# "nested-function, but placed at module level
|
| 86 |
+
# as an ld_header was found, return known paths, archives and members
|
| 87 |
+
# these lines start with a digit
|
| 88 |
+
info = []
|
| 89 |
+
for line in p.stdout:
|
| 90 |
+
if re.match("[0-9]", line):
|
| 91 |
+
info.append(line)
|
| 92 |
+
else:
|
| 93 |
+
# blank line (separator), consume line and end for loop
|
| 94 |
+
break
|
| 95 |
+
return info
|
| 96 |
+
|
| 97 |
+
def get_ld_headers(file):
|
| 98 |
+
"""
|
| 99 |
+
Parse the header of the loader section of executable and archives
|
| 100 |
+
This function calls /usr/bin/dump -H as a subprocess
|
| 101 |
+
and returns a list of (ld_header, ld_header_info) tuples.
|
| 102 |
+
"""
|
| 103 |
+
# get_ld_headers parsing:
|
| 104 |
+
# 1. Find a line that starts with /, ./, or ../ - set as ld_header
|
| 105 |
+
# 2. If "INDEX" in occurs in a following line - return ld_header
|
| 106 |
+
# 3. get info (lines starting with [0-9])
|
| 107 |
+
ldr_headers = []
|
| 108 |
+
p = Popen(["/usr/bin/dump", f"-X{AIX_ABI}", "-H", file],
|
| 109 |
+
universal_newlines=True, stdout=PIPE, stderr=DEVNULL)
|
| 110 |
+
# be sure to read to the end-of-file - getting all entries
|
| 111 |
+
while True:
|
| 112 |
+
ld_header = get_ld_header(p)
|
| 113 |
+
if ld_header:
|
| 114 |
+
ldr_headers.append((ld_header, get_ld_header_info(p)))
|
| 115 |
+
else:
|
| 116 |
+
break
|
| 117 |
+
p.stdout.close()
|
| 118 |
+
p.wait()
|
| 119 |
+
return ldr_headers
|
| 120 |
+
|
| 121 |
+
def get_shared(ld_headers):
|
| 122 |
+
"""
|
| 123 |
+
extract the shareable objects from ld_headers
|
| 124 |
+
character "[" is used to strip off the path information.
|
| 125 |
+
Note: the "[" and "]" characters that are part of dump -H output
|
| 126 |
+
are not removed here.
|
| 127 |
+
"""
|
| 128 |
+
shared = []
|
| 129 |
+
for (line, _) in ld_headers:
|
| 130 |
+
# potential member lines contain "["
|
| 131 |
+
# otherwise, no processing needed
|
| 132 |
+
if "[" in line:
|
| 133 |
+
# Strip off trailing colon (:)
|
| 134 |
+
shared.append(line[line.index("["):-1])
|
| 135 |
+
return shared
|
| 136 |
+
|
| 137 |
+
def get_one_match(expr, lines):
|
| 138 |
+
"""
|
| 139 |
+
Must be only one match, otherwise result is None.
|
| 140 |
+
When there is a match, strip leading "[" and trailing "]"
|
| 141 |
+
"""
|
| 142 |
+
# member names in the ld_headers output are between square brackets
|
| 143 |
+
expr = rf'\[({expr})\]'
|
| 144 |
+
matches = list(filter(None, (re.search(expr, line) for line in lines)))
|
| 145 |
+
if len(matches) == 1:
|
| 146 |
+
return matches[0].group(1)
|
| 147 |
+
else:
|
| 148 |
+
return None
|
| 149 |
+
|
| 150 |
+
# additional processing to deal with AIX legacy names for 64-bit members
|
| 151 |
+
def get_legacy(members):
|
| 152 |
+
"""
|
| 153 |
+
This routine provides historical aka legacy naming schemes started
|
| 154 |
+
in AIX4 shared library support for library members names.
|
| 155 |
+
e.g., in /usr/lib/libc.a the member name shr.o for 32-bit binary and
|
| 156 |
+
shr_64.o for 64-bit binary.
|
| 157 |
+
"""
|
| 158 |
+
if AIX_ABI == 64:
|
| 159 |
+
# AIX 64-bit member is one of shr64.o, shr_64.o, or shr4_64.o
|
| 160 |
+
expr = r'shr4?_?64\.o'
|
| 161 |
+
member = get_one_match(expr, members)
|
| 162 |
+
if member:
|
| 163 |
+
return member
|
| 164 |
+
else:
|
| 165 |
+
# 32-bit legacy names - both shr.o and shr4.o exist.
|
| 166 |
+
# shr.o is the preferred name so we look for shr.o first
|
| 167 |
+
# i.e., shr4.o is returned only when shr.o does not exist
|
| 168 |
+
for name in ['shr.o', 'shr4.o']:
|
| 169 |
+
member = get_one_match(re.escape(name), members)
|
| 170 |
+
if member:
|
| 171 |
+
return member
|
| 172 |
+
return None
|
| 173 |
+
|
| 174 |
+
def get_version(name, members):
|
| 175 |
+
"""
|
| 176 |
+
Sort list of members and return highest numbered version - if it exists.
|
| 177 |
+
This function is called when an unversioned libFOO.a(libFOO.so) has
|
| 178 |
+
not been found.
|
| 179 |
+
|
| 180 |
+
Versioning for the member name is expected to follow
|
| 181 |
+
GNU LIBTOOL conventions: the highest version (x, then X.y, then X.Y.z)
|
| 182 |
+
* find [libFoo.so.X]
|
| 183 |
+
* find [libFoo.so.X.Y]
|
| 184 |
+
* find [libFoo.so.X.Y.Z]
|
| 185 |
+
|
| 186 |
+
Before the GNU convention became the standard scheme regardless of
|
| 187 |
+
binary size AIX packagers used GNU convention "as-is" for 32-bit
|
| 188 |
+
archive members but used an "distinguishing" name for 64-bit members.
|
| 189 |
+
This scheme inserted either 64 or _64 between libFOO and .so
|
| 190 |
+
- generally libFOO_64.so, but occasionally libFOO64.so
|
| 191 |
+
"""
|
| 192 |
+
# the expression ending for versions must start as
|
| 193 |
+
# '.so.[0-9]', i.e., *.so.[at least one digit]
|
| 194 |
+
# while multiple, more specific expressions could be specified
|
| 195 |
+
# to search for .so.X, .so.X.Y and .so.X.Y.Z
|
| 196 |
+
# after the first required 'dot' digit
|
| 197 |
+
# any combination of additional 'dot' digits pairs are accepted
|
| 198 |
+
# anything more than libFOO.so.digits.digits.digits
|
| 199 |
+
# should be seen as a member name outside normal expectations
|
| 200 |
+
exprs = [rf'lib{name}\.so\.[0-9]+[0-9.]*',
|
| 201 |
+
rf'lib{name}_?64\.so\.[0-9]+[0-9.]*']
|
| 202 |
+
for expr in exprs:
|
| 203 |
+
versions = []
|
| 204 |
+
for line in members:
|
| 205 |
+
m = re.search(expr, line)
|
| 206 |
+
if m:
|
| 207 |
+
versions.append(m.group(0))
|
| 208 |
+
if versions:
|
| 209 |
+
return _last_version(versions, '.')
|
| 210 |
+
return None
|
| 211 |
+
|
| 212 |
+
def get_member(name, members):
|
| 213 |
+
"""
|
| 214 |
+
Return an archive member matching the request in name.
|
| 215 |
+
Name is the library name without any prefix like lib, suffix like .so,
|
| 216 |
+
or version number.
|
| 217 |
+
Given a list of members find and return the most appropriate result
|
| 218 |
+
Priority is given to generic libXXX.so, then a versioned libXXX.so.a.b.c
|
| 219 |
+
and finally, legacy AIX naming scheme.
|
| 220 |
+
"""
|
| 221 |
+
# look first for a generic match - prepend lib and append .so
|
| 222 |
+
expr = rf'lib{name}\.so'
|
| 223 |
+
member = get_one_match(expr, members)
|
| 224 |
+
if member:
|
| 225 |
+
return member
|
| 226 |
+
elif AIX_ABI == 64:
|
| 227 |
+
expr = rf'lib{name}64\.so'
|
| 228 |
+
member = get_one_match(expr, members)
|
| 229 |
+
if member:
|
| 230 |
+
return member
|
| 231 |
+
# since an exact match with .so as suffix was not found
|
| 232 |
+
# look for a versioned name
|
| 233 |
+
# If a versioned name is not found, look for AIX legacy member name
|
| 234 |
+
member = get_version(name, members)
|
| 235 |
+
if member:
|
| 236 |
+
return member
|
| 237 |
+
else:
|
| 238 |
+
return get_legacy(members)
|
| 239 |
+
|
| 240 |
+
def get_libpaths():
|
| 241 |
+
"""
|
| 242 |
+
On AIX, the buildtime searchpath is stored in the executable.
|
| 243 |
+
as "loader header information".
|
| 244 |
+
The command /usr/bin/dump -H extracts this info.
|
| 245 |
+
Prefix searched libraries with LD_LIBRARY_PATH (preferred),
|
| 246 |
+
or LIBPATH if defined. These paths are appended to the paths
|
| 247 |
+
to libraries the python executable is linked with.
|
| 248 |
+
This mimics AIX dlopen() behavior.
|
| 249 |
+
"""
|
| 250 |
+
libpaths = environ.get("LD_LIBRARY_PATH")
|
| 251 |
+
if libpaths is None:
|
| 252 |
+
libpaths = environ.get("LIBPATH")
|
| 253 |
+
if libpaths is None:
|
| 254 |
+
libpaths = []
|
| 255 |
+
else:
|
| 256 |
+
libpaths = libpaths.split(":")
|
| 257 |
+
objects = get_ld_headers(executable)
|
| 258 |
+
for (_, lines) in objects:
|
| 259 |
+
for line in lines:
|
| 260 |
+
# the second (optional) argument is PATH if it includes a /
|
| 261 |
+
path = line.split()[1]
|
| 262 |
+
if "/" in path:
|
| 263 |
+
libpaths.extend(path.split(":"))
|
| 264 |
+
return libpaths
|
| 265 |
+
|
| 266 |
+
def find_shared(paths, name):
|
| 267 |
+
"""
|
| 268 |
+
paths is a list of directories to search for an archive.
|
| 269 |
+
name is the abbreviated name given to find_library().
|
| 270 |
+
Process: search "paths" for archive, and if an archive is found
|
| 271 |
+
return the result of get_member().
|
| 272 |
+
If an archive is not found then return None
|
| 273 |
+
"""
|
| 274 |
+
for dir in paths:
|
| 275 |
+
# /lib is a symbolic link to /usr/lib, skip it
|
| 276 |
+
if dir == "/lib":
|
| 277 |
+
continue
|
| 278 |
+
# "lib" is prefixed to emulate compiler name resolution,
|
| 279 |
+
# e.g., -lc to libc
|
| 280 |
+
base = f'lib{name}.a'
|
| 281 |
+
archive = path.join(dir, base)
|
| 282 |
+
if path.exists(archive):
|
| 283 |
+
members = get_shared(get_ld_headers(archive))
|
| 284 |
+
member = get_member(re.escape(name), members)
|
| 285 |
+
if member is not None:
|
| 286 |
+
return (base, member)
|
| 287 |
+
else:
|
| 288 |
+
return (None, None)
|
| 289 |
+
return (None, None)
|
| 290 |
+
|
| 291 |
+
def find_library(name):
|
| 292 |
+
"""AIX implementation of ctypes.util.find_library()
|
| 293 |
+
Find an archive member that will dlopen(). If not available,
|
| 294 |
+
also search for a file (or link) with a .so suffix.
|
| 295 |
+
|
| 296 |
+
AIX supports two types of schemes that can be used with dlopen().
|
| 297 |
+
The so-called SystemV Release4 (svr4) format is commonly suffixed
|
| 298 |
+
with .so while the (default) AIX scheme has the library (archive)
|
| 299 |
+
ending with the suffix .a
|
| 300 |
+
As an archive has multiple members (e.g., 32-bit and 64-bit) in one file
|
| 301 |
+
the argument passed to dlopen must include both the library and
|
| 302 |
+
the member names in a single string.
|
| 303 |
+
|
| 304 |
+
find_library() looks first for an archive (.a) with a suitable member.
|
| 305 |
+
If no archive+member pair is found, look for a .so file.
|
| 306 |
+
"""
|
| 307 |
+
|
| 308 |
+
libpaths = get_libpaths()
|
| 309 |
+
(base, member) = find_shared(libpaths, name)
|
| 310 |
+
if base is not None:
|
| 311 |
+
return f"{base}({member})"
|
| 312 |
+
|
| 313 |
+
# To get here, a member in an archive has not been found
|
| 314 |
+
# In other words, either:
|
| 315 |
+
# a) a .a file was not found
|
| 316 |
+
# b) a .a file did not have a suitable member
|
| 317 |
+
# So, look for a .so file
|
| 318 |
+
# Check libpaths for .so file
|
| 319 |
+
# Note, the installation must prepare a link from a .so
|
| 320 |
+
# to a versioned file
|
| 321 |
+
# This is common practice by GNU libtool on other platforms
|
| 322 |
+
soname = f"lib{name}.so"
|
| 323 |
+
for dir in libpaths:
|
| 324 |
+
# /lib is a symbolic link to /usr/lib, skip it
|
| 325 |
+
if dir == "/lib":
|
| 326 |
+
continue
|
| 327 |
+
shlib = path.join(dir, soname)
|
| 328 |
+
if path.exists(shlib):
|
| 329 |
+
return soname
|
| 330 |
+
# if we are here, we have not found anything plausible
|
| 331 |
+
return None
|
data/conda_envs/evalclaw/lib/python3.11/ctypes/_endian.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from ctypes import *
|
| 3 |
+
|
| 4 |
+
_array_type = type(Array)
|
| 5 |
+
|
| 6 |
+
def _other_endian(typ):
|
| 7 |
+
"""Return the type with the 'other' byte order. Simple types like
|
| 8 |
+
c_int and so on already have __ctype_be__ and __ctype_le__
|
| 9 |
+
attributes which contain the types, for more complicated types
|
| 10 |
+
arrays and structures are supported.
|
| 11 |
+
"""
|
| 12 |
+
# check _OTHER_ENDIAN attribute (present if typ is primitive type)
|
| 13 |
+
if hasattr(typ, _OTHER_ENDIAN):
|
| 14 |
+
return getattr(typ, _OTHER_ENDIAN)
|
| 15 |
+
# if typ is array
|
| 16 |
+
if isinstance(typ, _array_type):
|
| 17 |
+
return _other_endian(typ._type_) * typ._length_
|
| 18 |
+
# if typ is structure or union
|
| 19 |
+
if issubclass(typ, (Structure, Union)):
|
| 20 |
+
return typ
|
| 21 |
+
raise TypeError("This type does not support other endian: %s" % typ)
|
| 22 |
+
|
| 23 |
+
class _swapped_meta:
|
| 24 |
+
def __setattr__(self, attrname, value):
|
| 25 |
+
if attrname == "_fields_":
|
| 26 |
+
fields = []
|
| 27 |
+
for desc in value:
|
| 28 |
+
name = desc[0]
|
| 29 |
+
typ = desc[1]
|
| 30 |
+
rest = desc[2:]
|
| 31 |
+
fields.append((name, _other_endian(typ)) + rest)
|
| 32 |
+
value = fields
|
| 33 |
+
super().__setattr__(attrname, value)
|
| 34 |
+
class _swapped_struct_meta(_swapped_meta, type(Structure)): pass
|
| 35 |
+
class _swapped_union_meta(_swapped_meta, type(Union)): pass
|
| 36 |
+
|
| 37 |
+
################################################################
|
| 38 |
+
|
| 39 |
+
# Note: The Structure metaclass checks for the *presence* (not the
|
| 40 |
+
# value!) of a _swapped_bytes_ attribute to determine the bit order in
|
| 41 |
+
# structures containing bit fields.
|
| 42 |
+
|
| 43 |
+
if sys.byteorder == "little":
|
| 44 |
+
_OTHER_ENDIAN = "__ctype_be__"
|
| 45 |
+
|
| 46 |
+
LittleEndianStructure = Structure
|
| 47 |
+
|
| 48 |
+
class BigEndianStructure(Structure, metaclass=_swapped_struct_meta):
|
| 49 |
+
"""Structure with big endian byte order"""
|
| 50 |
+
__slots__ = ()
|
| 51 |
+
_swappedbytes_ = None
|
| 52 |
+
|
| 53 |
+
LittleEndianUnion = Union
|
| 54 |
+
|
| 55 |
+
class BigEndianUnion(Union, metaclass=_swapped_union_meta):
|
| 56 |
+
"""Union with big endian byte order"""
|
| 57 |
+
__slots__ = ()
|
| 58 |
+
_swappedbytes_ = None
|
| 59 |
+
|
| 60 |
+
elif sys.byteorder == "big":
|
| 61 |
+
_OTHER_ENDIAN = "__ctype_le__"
|
| 62 |
+
|
| 63 |
+
BigEndianStructure = Structure
|
| 64 |
+
|
| 65 |
+
class LittleEndianStructure(Structure, metaclass=_swapped_struct_meta):
|
| 66 |
+
"""Structure with little endian byte order"""
|
| 67 |
+
__slots__ = ()
|
| 68 |
+
_swappedbytes_ = None
|
| 69 |
+
|
| 70 |
+
BigEndianUnion = Union
|
| 71 |
+
|
| 72 |
+
class LittleEndianUnion(Union, metaclass=_swapped_union_meta):
|
| 73 |
+
"""Union with little endian byte order"""
|
| 74 |
+
__slots__ = ()
|
| 75 |
+
_swappedbytes_ = None
|
| 76 |
+
|
| 77 |
+
else:
|
| 78 |
+
raise RuntimeError("Invalid byteorder")
|
data/conda_envs/evalclaw/lib/python3.11/ctypes/util.py
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import subprocess
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
# find_library(name) returns the pathname of a library, or None.
|
| 7 |
+
if os.name == "nt":
|
| 8 |
+
|
| 9 |
+
def _get_build_version():
|
| 10 |
+
"""Return the version of MSVC that was used to build Python.
|
| 11 |
+
|
| 12 |
+
For Python 2.3 and up, the version number is included in
|
| 13 |
+
sys.version. For earlier versions, assume the compiler is MSVC 6.
|
| 14 |
+
"""
|
| 15 |
+
# This function was copied from Lib/distutils/msvccompiler.py
|
| 16 |
+
prefix = "MSC v."
|
| 17 |
+
i = sys.version.find(prefix)
|
| 18 |
+
if i == -1:
|
| 19 |
+
return 6
|
| 20 |
+
i = i + len(prefix)
|
| 21 |
+
s, rest = sys.version[i:].split(" ", 1)
|
| 22 |
+
majorVersion = int(s[:-2]) - 6
|
| 23 |
+
if majorVersion >= 13:
|
| 24 |
+
majorVersion += 1
|
| 25 |
+
minorVersion = int(s[2:3]) / 10.0
|
| 26 |
+
# I don't think paths are affected by minor version in version 6
|
| 27 |
+
if majorVersion == 6:
|
| 28 |
+
minorVersion = 0
|
| 29 |
+
if majorVersion >= 6:
|
| 30 |
+
return majorVersion + minorVersion
|
| 31 |
+
# else we don't know what version of the compiler this is
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
def find_msvcrt():
|
| 35 |
+
"""Return the name of the VC runtime dll"""
|
| 36 |
+
version = _get_build_version()
|
| 37 |
+
if version is None:
|
| 38 |
+
# better be safe than sorry
|
| 39 |
+
return None
|
| 40 |
+
if version <= 6:
|
| 41 |
+
clibname = 'msvcrt'
|
| 42 |
+
elif version <= 13:
|
| 43 |
+
clibname = 'msvcr%d' % (version * 10)
|
| 44 |
+
else:
|
| 45 |
+
# CRT is no longer directly loadable. See issue23606 for the
|
| 46 |
+
# discussion about alternative approaches.
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
# If python was built with in debug mode
|
| 50 |
+
import importlib.machinery
|
| 51 |
+
if '_d.pyd' in importlib.machinery.EXTENSION_SUFFIXES:
|
| 52 |
+
clibname += 'd'
|
| 53 |
+
return clibname+'.dll'
|
| 54 |
+
|
| 55 |
+
def find_library(name):
|
| 56 |
+
if name in ('c', 'm'):
|
| 57 |
+
return find_msvcrt()
|
| 58 |
+
# See MSDN for the REAL search order.
|
| 59 |
+
for directory in os.environ['PATH'].split(os.pathsep):
|
| 60 |
+
fname = os.path.join(directory, name)
|
| 61 |
+
if os.path.isfile(fname):
|
| 62 |
+
return fname
|
| 63 |
+
if fname.lower().endswith(".dll"):
|
| 64 |
+
continue
|
| 65 |
+
fname = fname + ".dll"
|
| 66 |
+
if os.path.isfile(fname):
|
| 67 |
+
return fname
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
elif os.name == "posix" and sys.platform == "darwin":
|
| 71 |
+
from ctypes.macholib.dyld import dyld_find as _dyld_find
|
| 72 |
+
def find_library(name):
|
| 73 |
+
possible = ['@executable_path/../lib/lib%s.dylib' % name,
|
| 74 |
+
'lib%s.dylib' % name,
|
| 75 |
+
'%s.dylib' % name,
|
| 76 |
+
'%s.framework/%s' % (name, name)]
|
| 77 |
+
for name in possible:
|
| 78 |
+
try:
|
| 79 |
+
return _dyld_find(name)
|
| 80 |
+
except ValueError:
|
| 81 |
+
continue
|
| 82 |
+
return None
|
| 83 |
+
|
| 84 |
+
elif sys.platform.startswith("aix"):
|
| 85 |
+
# AIX has two styles of storing shared libraries
|
| 86 |
+
# GNU auto_tools refer to these as svr4 and aix
|
| 87 |
+
# svr4 (System V Release 4) is a regular file, often with .so as suffix
|
| 88 |
+
# AIX style uses an archive (suffix .a) with members (e.g., shr.o, libssl.so)
|
| 89 |
+
# see issue#26439 and _aix.py for more details
|
| 90 |
+
|
| 91 |
+
from ctypes._aix import find_library
|
| 92 |
+
|
| 93 |
+
elif os.name == "posix":
|
| 94 |
+
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
|
| 95 |
+
import re, tempfile
|
| 96 |
+
|
| 97 |
+
def _is_elf(filename):
|
| 98 |
+
"Return True if the given file is an ELF file"
|
| 99 |
+
elf_header = b'\x7fELF'
|
| 100 |
+
try:
|
| 101 |
+
with open(filename, 'br') as thefile:
|
| 102 |
+
return thefile.read(4) == elf_header
|
| 103 |
+
except FileNotFoundError:
|
| 104 |
+
return False
|
| 105 |
+
|
| 106 |
+
def _findLib_gcc(name):
|
| 107 |
+
# Run GCC's linker with the -t (aka --trace) option and examine the
|
| 108 |
+
# library name it prints out. The GCC command will fail because we
|
| 109 |
+
# haven't supplied a proper program with main(), but that does not
|
| 110 |
+
# matter.
|
| 111 |
+
expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name))
|
| 112 |
+
|
| 113 |
+
c_compiler = shutil.which('gcc')
|
| 114 |
+
if not c_compiler:
|
| 115 |
+
c_compiler = shutil.which('cc')
|
| 116 |
+
if not c_compiler:
|
| 117 |
+
# No C compiler available, give up
|
| 118 |
+
return None
|
| 119 |
+
|
| 120 |
+
temp = tempfile.NamedTemporaryFile()
|
| 121 |
+
try:
|
| 122 |
+
args = [c_compiler, '-Wl,-t', '-o', temp.name, '-l' + name]
|
| 123 |
+
|
| 124 |
+
env = dict(os.environ)
|
| 125 |
+
env['LC_ALL'] = 'C'
|
| 126 |
+
env['LANG'] = 'C'
|
| 127 |
+
try:
|
| 128 |
+
proc = subprocess.Popen(args,
|
| 129 |
+
stdout=subprocess.PIPE,
|
| 130 |
+
stderr=subprocess.STDOUT,
|
| 131 |
+
env=env)
|
| 132 |
+
except OSError: # E.g. bad executable
|
| 133 |
+
return None
|
| 134 |
+
with proc:
|
| 135 |
+
trace = proc.stdout.read()
|
| 136 |
+
finally:
|
| 137 |
+
try:
|
| 138 |
+
temp.close()
|
| 139 |
+
except FileNotFoundError:
|
| 140 |
+
# Raised if the file was already removed, which is the normal
|
| 141 |
+
# behaviour of GCC if linking fails
|
| 142 |
+
pass
|
| 143 |
+
res = re.findall(expr, trace)
|
| 144 |
+
if not res:
|
| 145 |
+
return None
|
| 146 |
+
|
| 147 |
+
for file in res:
|
| 148 |
+
# Check if the given file is an elf file: gcc can report
|
| 149 |
+
# some files that are linker scripts and not actual
|
| 150 |
+
# shared objects. See bpo-41976 for more details
|
| 151 |
+
if not _is_elf(file):
|
| 152 |
+
continue
|
| 153 |
+
return os.fsdecode(file)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
if sys.platform == "sunos5":
|
| 157 |
+
# use /usr/ccs/bin/dump on solaris
|
| 158 |
+
def _get_soname(f):
|
| 159 |
+
if not f:
|
| 160 |
+
return None
|
| 161 |
+
|
| 162 |
+
try:
|
| 163 |
+
proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f),
|
| 164 |
+
stdout=subprocess.PIPE,
|
| 165 |
+
stderr=subprocess.DEVNULL)
|
| 166 |
+
except OSError: # E.g. command not found
|
| 167 |
+
return None
|
| 168 |
+
with proc:
|
| 169 |
+
data = proc.stdout.read()
|
| 170 |
+
res = re.search(br'\[.*\]\sSONAME\s+([^\s]+)', data)
|
| 171 |
+
if not res:
|
| 172 |
+
return None
|
| 173 |
+
return os.fsdecode(res.group(1))
|
| 174 |
+
else:
|
| 175 |
+
def _get_soname(f):
|
| 176 |
+
# assuming GNU binutils / ELF
|
| 177 |
+
if not f:
|
| 178 |
+
return None
|
| 179 |
+
objdump = shutil.which('objdump')
|
| 180 |
+
if not objdump:
|
| 181 |
+
# objdump is not available, give up
|
| 182 |
+
return None
|
| 183 |
+
|
| 184 |
+
try:
|
| 185 |
+
proc = subprocess.Popen((objdump, '-p', '-j', '.dynamic', f),
|
| 186 |
+
stdout=subprocess.PIPE,
|
| 187 |
+
stderr=subprocess.DEVNULL)
|
| 188 |
+
except OSError: # E.g. bad executable
|
| 189 |
+
return None
|
| 190 |
+
with proc:
|
| 191 |
+
dump = proc.stdout.read()
|
| 192 |
+
res = re.search(br'\sSONAME\s+([^\s]+)', dump)
|
| 193 |
+
if not res:
|
| 194 |
+
return None
|
| 195 |
+
return os.fsdecode(res.group(1))
|
| 196 |
+
|
| 197 |
+
if sys.platform.startswith(("freebsd", "openbsd", "dragonfly")):
|
| 198 |
+
|
| 199 |
+
def _num_version(libname):
|
| 200 |
+
# "libxyz.so.MAJOR.MINOR" => [ MAJOR, MINOR ]
|
| 201 |
+
parts = libname.split(b".")
|
| 202 |
+
nums = []
|
| 203 |
+
try:
|
| 204 |
+
while parts:
|
| 205 |
+
nums.insert(0, int(parts.pop()))
|
| 206 |
+
except ValueError:
|
| 207 |
+
pass
|
| 208 |
+
return nums or [sys.maxsize]
|
| 209 |
+
|
| 210 |
+
def find_library(name):
|
| 211 |
+
ename = re.escape(name)
|
| 212 |
+
expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
|
| 213 |
+
expr = os.fsencode(expr)
|
| 214 |
+
|
| 215 |
+
try:
|
| 216 |
+
proc = subprocess.Popen(('/sbin/ldconfig', '-r'),
|
| 217 |
+
stdout=subprocess.PIPE,
|
| 218 |
+
stderr=subprocess.DEVNULL)
|
| 219 |
+
except OSError: # E.g. command not found
|
| 220 |
+
data = b''
|
| 221 |
+
else:
|
| 222 |
+
with proc:
|
| 223 |
+
data = proc.stdout.read()
|
| 224 |
+
|
| 225 |
+
res = re.findall(expr, data)
|
| 226 |
+
if not res:
|
| 227 |
+
return _get_soname(_findLib_gcc(name))
|
| 228 |
+
res.sort(key=_num_version)
|
| 229 |
+
return os.fsdecode(res[-1])
|
| 230 |
+
|
| 231 |
+
elif sys.platform == "sunos5":
|
| 232 |
+
|
| 233 |
+
def _findLib_crle(name, is64):
|
| 234 |
+
if not os.path.exists('/usr/bin/crle'):
|
| 235 |
+
return None
|
| 236 |
+
|
| 237 |
+
env = dict(os.environ)
|
| 238 |
+
env['LC_ALL'] = 'C'
|
| 239 |
+
|
| 240 |
+
if is64:
|
| 241 |
+
args = ('/usr/bin/crle', '-64')
|
| 242 |
+
else:
|
| 243 |
+
args = ('/usr/bin/crle',)
|
| 244 |
+
|
| 245 |
+
paths = None
|
| 246 |
+
try:
|
| 247 |
+
proc = subprocess.Popen(args,
|
| 248 |
+
stdout=subprocess.PIPE,
|
| 249 |
+
stderr=subprocess.DEVNULL,
|
| 250 |
+
env=env)
|
| 251 |
+
except OSError: # E.g. bad executable
|
| 252 |
+
return None
|
| 253 |
+
with proc:
|
| 254 |
+
for line in proc.stdout:
|
| 255 |
+
line = line.strip()
|
| 256 |
+
if line.startswith(b'Default Library Path (ELF):'):
|
| 257 |
+
paths = os.fsdecode(line).split()[4]
|
| 258 |
+
|
| 259 |
+
if not paths:
|
| 260 |
+
return None
|
| 261 |
+
|
| 262 |
+
for dir in paths.split(":"):
|
| 263 |
+
libfile = os.path.join(dir, "lib%s.so" % name)
|
| 264 |
+
if os.path.exists(libfile):
|
| 265 |
+
return libfile
|
| 266 |
+
|
| 267 |
+
return None
|
| 268 |
+
|
| 269 |
+
def find_library(name, is64 = False):
|
| 270 |
+
return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name))
|
| 271 |
+
|
| 272 |
+
else:
|
| 273 |
+
|
| 274 |
+
def _findSoname_ldconfig(name):
|
| 275 |
+
import struct
|
| 276 |
+
if struct.calcsize('l') == 4:
|
| 277 |
+
machine = os.uname().machine + '-32'
|
| 278 |
+
else:
|
| 279 |
+
machine = os.uname().machine + '-64'
|
| 280 |
+
mach_map = {
|
| 281 |
+
'x86_64-64': 'libc6,x86-64',
|
| 282 |
+
'ppc64-64': 'libc6,64bit',
|
| 283 |
+
'sparc64-64': 'libc6,64bit',
|
| 284 |
+
's390x-64': 'libc6,64bit',
|
| 285 |
+
'ia64-64': 'libc6,IA-64',
|
| 286 |
+
}
|
| 287 |
+
abi_type = mach_map.get(machine, 'libc6')
|
| 288 |
+
|
| 289 |
+
# XXX assuming GLIBC's ldconfig (with option -p)
|
| 290 |
+
regex = r'\s+(lib%s\.[^\s]+)\s+\(%s'
|
| 291 |
+
regex = os.fsencode(regex % (re.escape(name), abi_type))
|
| 292 |
+
try:
|
| 293 |
+
with subprocess.Popen(['/sbin/ldconfig', '-p'],
|
| 294 |
+
stdin=subprocess.DEVNULL,
|
| 295 |
+
stderr=subprocess.DEVNULL,
|
| 296 |
+
stdout=subprocess.PIPE,
|
| 297 |
+
env={'LC_ALL': 'C', 'LANG': 'C'}) as p:
|
| 298 |
+
res = re.search(regex, p.stdout.read())
|
| 299 |
+
if res:
|
| 300 |
+
return os.fsdecode(res.group(1))
|
| 301 |
+
except OSError:
|
| 302 |
+
pass
|
| 303 |
+
|
| 304 |
+
def _findLib_ld(name):
|
| 305 |
+
# See issue #9998 for why this is needed
|
| 306 |
+
expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
|
| 307 |
+
cmd = ['ld', '-t']
|
| 308 |
+
libpath = os.environ.get('LD_LIBRARY_PATH')
|
| 309 |
+
if libpath:
|
| 310 |
+
for d in libpath.split(':'):
|
| 311 |
+
cmd.extend(['-L', d])
|
| 312 |
+
cmd.extend(['-o', os.devnull, '-l%s' % name])
|
| 313 |
+
result = None
|
| 314 |
+
try:
|
| 315 |
+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
| 316 |
+
stderr=subprocess.PIPE,
|
| 317 |
+
universal_newlines=True)
|
| 318 |
+
out, _ = p.communicate()
|
| 319 |
+
res = re.findall(expr, os.fsdecode(out))
|
| 320 |
+
for file in res:
|
| 321 |
+
# Check if the given file is an elf file: gcc can report
|
| 322 |
+
# some files that are linker scripts and not actual
|
| 323 |
+
# shared objects. See bpo-41976 for more details
|
| 324 |
+
if not _is_elf(file):
|
| 325 |
+
continue
|
| 326 |
+
return os.fsdecode(file)
|
| 327 |
+
except Exception:
|
| 328 |
+
pass # result will be None
|
| 329 |
+
return result
|
| 330 |
+
|
| 331 |
+
def _findLib_prefix(name):
|
| 332 |
+
if not name:
|
| 333 |
+
return None
|
| 334 |
+
for fullname in (name, "lib%s.so" % (name)):
|
| 335 |
+
path = os.path.join(sys.prefix, 'lib', fullname)
|
| 336 |
+
if os.path.exists(path):
|
| 337 |
+
return path
|
| 338 |
+
return None
|
| 339 |
+
|
| 340 |
+
def find_library(name):
|
| 341 |
+
# See issue #9998
|
| 342 |
+
# Yes calling _findLib_prefix twice is deliberate, because _get_soname ditches
|
| 343 |
+
# the full path.
|
| 344 |
+
# When objdump is unavailable this returns None
|
| 345 |
+
so_name = _get_soname(_findLib_prefix(name)) or name
|
| 346 |
+
if so_name != name:
|
| 347 |
+
return _findLib_prefix(so_name) or \
|
| 348 |
+
_findLib_prefix(name) or \
|
| 349 |
+
_findSoname_ldconfig(name) or \
|
| 350 |
+
_get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
|
| 351 |
+
else:
|
| 352 |
+
return _findLib_prefix(name) or \
|
| 353 |
+
_findSoname_ldconfig(name) or \
|
| 354 |
+
_get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
|
| 355 |
+
|
| 356 |
+
################################################################
|
| 357 |
+
# test code
|
| 358 |
+
|
| 359 |
+
def test():
|
| 360 |
+
from ctypes import cdll
|
| 361 |
+
if os.name == "nt":
|
| 362 |
+
print(cdll.msvcrt)
|
| 363 |
+
print(cdll.load("msvcrt"))
|
| 364 |
+
print(find_library("msvcrt"))
|
| 365 |
+
|
| 366 |
+
if os.name == "posix":
|
| 367 |
+
# find and load_version
|
| 368 |
+
print(find_library("m"))
|
| 369 |
+
print(find_library("c"))
|
| 370 |
+
print(find_library("bz2"))
|
| 371 |
+
|
| 372 |
+
# load
|
| 373 |
+
if sys.platform == "darwin":
|
| 374 |
+
print(cdll.LoadLibrary("libm.dylib"))
|
| 375 |
+
print(cdll.LoadLibrary("libcrypto.dylib"))
|
| 376 |
+
print(cdll.LoadLibrary("libSystem.dylib"))
|
| 377 |
+
print(cdll.LoadLibrary("System.framework/System"))
|
| 378 |
+
# issue-26439 - fix broken test call for AIX
|
| 379 |
+
elif sys.platform.startswith("aix"):
|
| 380 |
+
from ctypes import CDLL
|
| 381 |
+
if sys.maxsize < 2**32:
|
| 382 |
+
print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr.o)', os.RTLD_MEMBER)}")
|
| 383 |
+
print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr.o)')}")
|
| 384 |
+
# librpm.so is only available as 32-bit shared library
|
| 385 |
+
print(find_library("rpm"))
|
| 386 |
+
print(cdll.LoadLibrary("librpm.so"))
|
| 387 |
+
else:
|
| 388 |
+
print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr_64.o)', os.RTLD_MEMBER)}")
|
| 389 |
+
print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr_64.o)')}")
|
| 390 |
+
print(f"crypt\t:: {find_library('crypt')}")
|
| 391 |
+
print(f"crypt\t:: {cdll.LoadLibrary(find_library('crypt'))}")
|
| 392 |
+
print(f"crypto\t:: {find_library('crypto')}")
|
| 393 |
+
print(f"crypto\t:: {cdll.LoadLibrary(find_library('crypto'))}")
|
| 394 |
+
else:
|
| 395 |
+
print(cdll.LoadLibrary("libm.so"))
|
| 396 |
+
print(cdll.LoadLibrary("libcrypt.so"))
|
| 397 |
+
print(find_library("crypt"))
|
| 398 |
+
|
| 399 |
+
if __name__ == "__main__":
|
| 400 |
+
test()
|
data/conda_envs/evalclaw/lib/python3.11/ctypes/wintypes.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The most useful windows datatypes
|
| 2 |
+
import ctypes
|
| 3 |
+
|
| 4 |
+
BYTE = ctypes.c_byte
|
| 5 |
+
WORD = ctypes.c_ushort
|
| 6 |
+
DWORD = ctypes.c_ulong
|
| 7 |
+
|
| 8 |
+
#UCHAR = ctypes.c_uchar
|
| 9 |
+
CHAR = ctypes.c_char
|
| 10 |
+
WCHAR = ctypes.c_wchar
|
| 11 |
+
UINT = ctypes.c_uint
|
| 12 |
+
INT = ctypes.c_int
|
| 13 |
+
|
| 14 |
+
DOUBLE = ctypes.c_double
|
| 15 |
+
FLOAT = ctypes.c_float
|
| 16 |
+
|
| 17 |
+
BOOLEAN = BYTE
|
| 18 |
+
BOOL = ctypes.c_long
|
| 19 |
+
|
| 20 |
+
class VARIANT_BOOL(ctypes._SimpleCData):
|
| 21 |
+
_type_ = "v"
|
| 22 |
+
def __repr__(self):
|
| 23 |
+
return "%s(%r)" % (self.__class__.__name__, self.value)
|
| 24 |
+
|
| 25 |
+
ULONG = ctypes.c_ulong
|
| 26 |
+
LONG = ctypes.c_long
|
| 27 |
+
|
| 28 |
+
USHORT = ctypes.c_ushort
|
| 29 |
+
SHORT = ctypes.c_short
|
| 30 |
+
|
| 31 |
+
# in the windows header files, these are structures.
|
| 32 |
+
_LARGE_INTEGER = LARGE_INTEGER = ctypes.c_longlong
|
| 33 |
+
_ULARGE_INTEGER = ULARGE_INTEGER = ctypes.c_ulonglong
|
| 34 |
+
|
| 35 |
+
LPCOLESTR = LPOLESTR = OLESTR = ctypes.c_wchar_p
|
| 36 |
+
LPCWSTR = LPWSTR = ctypes.c_wchar_p
|
| 37 |
+
LPCSTR = LPSTR = ctypes.c_char_p
|
| 38 |
+
LPCVOID = LPVOID = ctypes.c_void_p
|
| 39 |
+
|
| 40 |
+
# WPARAM is defined as UINT_PTR (unsigned type)
|
| 41 |
+
# LPARAM is defined as LONG_PTR (signed type)
|
| 42 |
+
if ctypes.sizeof(ctypes.c_long) == ctypes.sizeof(ctypes.c_void_p):
|
| 43 |
+
WPARAM = ctypes.c_ulong
|
| 44 |
+
LPARAM = ctypes.c_long
|
| 45 |
+
elif ctypes.sizeof(ctypes.c_longlong) == ctypes.sizeof(ctypes.c_void_p):
|
| 46 |
+
WPARAM = ctypes.c_ulonglong
|
| 47 |
+
LPARAM = ctypes.c_longlong
|
| 48 |
+
|
| 49 |
+
ATOM = WORD
|
| 50 |
+
LANGID = WORD
|
| 51 |
+
|
| 52 |
+
COLORREF = DWORD
|
| 53 |
+
LGRPID = DWORD
|
| 54 |
+
LCTYPE = DWORD
|
| 55 |
+
|
| 56 |
+
LCID = DWORD
|
| 57 |
+
|
| 58 |
+
################################################################
|
| 59 |
+
# HANDLE types
|
| 60 |
+
HANDLE = ctypes.c_void_p # in the header files: void *
|
| 61 |
+
|
| 62 |
+
HACCEL = HANDLE
|
| 63 |
+
HBITMAP = HANDLE
|
| 64 |
+
HBRUSH = HANDLE
|
| 65 |
+
HCOLORSPACE = HANDLE
|
| 66 |
+
HDC = HANDLE
|
| 67 |
+
HDESK = HANDLE
|
| 68 |
+
HDWP = HANDLE
|
| 69 |
+
HENHMETAFILE = HANDLE
|
| 70 |
+
HFONT = HANDLE
|
| 71 |
+
HGDIOBJ = HANDLE
|
| 72 |
+
HGLOBAL = HANDLE
|
| 73 |
+
HHOOK = HANDLE
|
| 74 |
+
HICON = HANDLE
|
| 75 |
+
HINSTANCE = HANDLE
|
| 76 |
+
HKEY = HANDLE
|
| 77 |
+
HKL = HANDLE
|
| 78 |
+
HLOCAL = HANDLE
|
| 79 |
+
HMENU = HANDLE
|
| 80 |
+
HMETAFILE = HANDLE
|
| 81 |
+
HMODULE = HANDLE
|
| 82 |
+
HMONITOR = HANDLE
|
| 83 |
+
HPALETTE = HANDLE
|
| 84 |
+
HPEN = HANDLE
|
| 85 |
+
HRGN = HANDLE
|
| 86 |
+
HRSRC = HANDLE
|
| 87 |
+
HSTR = HANDLE
|
| 88 |
+
HTASK = HANDLE
|
| 89 |
+
HWINSTA = HANDLE
|
| 90 |
+
HWND = HANDLE
|
| 91 |
+
SC_HANDLE = HANDLE
|
| 92 |
+
SERVICE_STATUS_HANDLE = HANDLE
|
| 93 |
+
|
| 94 |
+
################################################################
|
| 95 |
+
# Some important structure definitions
|
| 96 |
+
|
| 97 |
+
class RECT(ctypes.Structure):
|
| 98 |
+
_fields_ = [("left", LONG),
|
| 99 |
+
("top", LONG),
|
| 100 |
+
("right", LONG),
|
| 101 |
+
("bottom", LONG)]
|
| 102 |
+
tagRECT = _RECTL = RECTL = RECT
|
| 103 |
+
|
| 104 |
+
class _SMALL_RECT(ctypes.Structure):
|
| 105 |
+
_fields_ = [('Left', SHORT),
|
| 106 |
+
('Top', SHORT),
|
| 107 |
+
('Right', SHORT),
|
| 108 |
+
('Bottom', SHORT)]
|
| 109 |
+
SMALL_RECT = _SMALL_RECT
|
| 110 |
+
|
| 111 |
+
class _COORD(ctypes.Structure):
|
| 112 |
+
_fields_ = [('X', SHORT),
|
| 113 |
+
('Y', SHORT)]
|
| 114 |
+
|
| 115 |
+
class POINT(ctypes.Structure):
|
| 116 |
+
_fields_ = [("x", LONG),
|
| 117 |
+
("y", LONG)]
|
| 118 |
+
tagPOINT = _POINTL = POINTL = POINT
|
| 119 |
+
|
| 120 |
+
class SIZE(ctypes.Structure):
|
| 121 |
+
_fields_ = [("cx", LONG),
|
| 122 |
+
("cy", LONG)]
|
| 123 |
+
tagSIZE = SIZEL = SIZE
|
| 124 |
+
|
| 125 |
+
def RGB(red, green, blue):
|
| 126 |
+
return red + (green << 8) + (blue << 16)
|
| 127 |
+
|
| 128 |
+
class FILETIME(ctypes.Structure):
|
| 129 |
+
_fields_ = [("dwLowDateTime", DWORD),
|
| 130 |
+
("dwHighDateTime", DWORD)]
|
| 131 |
+
_FILETIME = FILETIME
|
| 132 |
+
|
| 133 |
+
class MSG(ctypes.Structure):
|
| 134 |
+
_fields_ = [("hWnd", HWND),
|
| 135 |
+
("message", UINT),
|
| 136 |
+
("wParam", WPARAM),
|
| 137 |
+
("lParam", LPARAM),
|
| 138 |
+
("time", DWORD),
|
| 139 |
+
("pt", POINT)]
|
| 140 |
+
tagMSG = MSG
|
| 141 |
+
MAX_PATH = 260
|
| 142 |
+
|
| 143 |
+
class WIN32_FIND_DATAA(ctypes.Structure):
|
| 144 |
+
_fields_ = [("dwFileAttributes", DWORD),
|
| 145 |
+
("ftCreationTime", FILETIME),
|
| 146 |
+
("ftLastAccessTime", FILETIME),
|
| 147 |
+
("ftLastWriteTime", FILETIME),
|
| 148 |
+
("nFileSizeHigh", DWORD),
|
| 149 |
+
("nFileSizeLow", DWORD),
|
| 150 |
+
("dwReserved0", DWORD),
|
| 151 |
+
("dwReserved1", DWORD),
|
| 152 |
+
("cFileName", CHAR * MAX_PATH),
|
| 153 |
+
("cAlternateFileName", CHAR * 14)]
|
| 154 |
+
|
| 155 |
+
class WIN32_FIND_DATAW(ctypes.Structure):
|
| 156 |
+
_fields_ = [("dwFileAttributes", DWORD),
|
| 157 |
+
("ftCreationTime", FILETIME),
|
| 158 |
+
("ftLastAccessTime", FILETIME),
|
| 159 |
+
("ftLastWriteTime", FILETIME),
|
| 160 |
+
("nFileSizeHigh", DWORD),
|
| 161 |
+
("nFileSizeLow", DWORD),
|
| 162 |
+
("dwReserved0", DWORD),
|
| 163 |
+
("dwReserved1", DWORD),
|
| 164 |
+
("cFileName", WCHAR * MAX_PATH),
|
| 165 |
+
("cAlternateFileName", WCHAR * 14)]
|
| 166 |
+
|
| 167 |
+
################################################################
|
| 168 |
+
# Pointer types
|
| 169 |
+
|
| 170 |
+
LPBOOL = PBOOL = ctypes.POINTER(BOOL)
|
| 171 |
+
PBOOLEAN = ctypes.POINTER(BOOLEAN)
|
| 172 |
+
LPBYTE = PBYTE = ctypes.POINTER(BYTE)
|
| 173 |
+
PCHAR = ctypes.POINTER(CHAR)
|
| 174 |
+
LPCOLORREF = ctypes.POINTER(COLORREF)
|
| 175 |
+
LPDWORD = PDWORD = ctypes.POINTER(DWORD)
|
| 176 |
+
LPFILETIME = PFILETIME = ctypes.POINTER(FILETIME)
|
| 177 |
+
PFLOAT = ctypes.POINTER(FLOAT)
|
| 178 |
+
LPHANDLE = PHANDLE = ctypes.POINTER(HANDLE)
|
| 179 |
+
PHKEY = ctypes.POINTER(HKEY)
|
| 180 |
+
LPHKL = ctypes.POINTER(HKL)
|
| 181 |
+
LPINT = PINT = ctypes.POINTER(INT)
|
| 182 |
+
PLARGE_INTEGER = ctypes.POINTER(LARGE_INTEGER)
|
| 183 |
+
PLCID = ctypes.POINTER(LCID)
|
| 184 |
+
LPLONG = PLONG = ctypes.POINTER(LONG)
|
| 185 |
+
LPMSG = PMSG = ctypes.POINTER(MSG)
|
| 186 |
+
LPPOINT = PPOINT = ctypes.POINTER(POINT)
|
| 187 |
+
PPOINTL = ctypes.POINTER(POINTL)
|
| 188 |
+
LPRECT = PRECT = ctypes.POINTER(RECT)
|
| 189 |
+
LPRECTL = PRECTL = ctypes.POINTER(RECTL)
|
| 190 |
+
LPSC_HANDLE = ctypes.POINTER(SC_HANDLE)
|
| 191 |
+
PSHORT = ctypes.POINTER(SHORT)
|
| 192 |
+
LPSIZE = PSIZE = ctypes.POINTER(SIZE)
|
| 193 |
+
LPSIZEL = PSIZEL = ctypes.POINTER(SIZEL)
|
| 194 |
+
PSMALL_RECT = ctypes.POINTER(SMALL_RECT)
|
| 195 |
+
LPUINT = PUINT = ctypes.POINTER(UINT)
|
| 196 |
+
PULARGE_INTEGER = ctypes.POINTER(ULARGE_INTEGER)
|
| 197 |
+
PULONG = ctypes.POINTER(ULONG)
|
| 198 |
+
PUSHORT = ctypes.POINTER(USHORT)
|
| 199 |
+
PWCHAR = ctypes.POINTER(WCHAR)
|
| 200 |
+
LPWIN32_FIND_DATAA = PWIN32_FIND_DATAA = ctypes.POINTER(WIN32_FIND_DATAA)
|
| 201 |
+
LPWIN32_FIND_DATAW = PWIN32_FIND_DATAW = ctypes.POINTER(WIN32_FIND_DATAW)
|
| 202 |
+
LPWORD = PWORD = ctypes.POINTER(WORD)
|
data/conda_envs/evalclaw/lib/python3.11/distutils/README
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This directory contains the Distutils package.
|
| 2 |
+
|
| 3 |
+
There's a full documentation available at:
|
| 4 |
+
|
| 5 |
+
https://docs.python.org/distutils/
|
| 6 |
+
|
| 7 |
+
The Distutils-SIG web page is also a good starting point:
|
| 8 |
+
|
| 9 |
+
https://www.python.org/sigs/distutils-sig/
|
| 10 |
+
|
| 11 |
+
$Id$
|
data/conda_envs/evalclaw/lib/python3.11/distutils/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils
|
| 2 |
+
|
| 3 |
+
The main package for the Python Module Distribution Utilities. Normally
|
| 4 |
+
used from a setup script as
|
| 5 |
+
|
| 6 |
+
from distutils.core import setup
|
| 7 |
+
|
| 8 |
+
setup (...)
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import sys
|
| 12 |
+
import warnings
|
| 13 |
+
|
| 14 |
+
__version__ = sys.version[:sys.version.index(' ')]
|
| 15 |
+
|
| 16 |
+
_DEPRECATION_MESSAGE = ("The distutils package is deprecated and slated for "
|
| 17 |
+
"removal in Python 3.12. Use setuptools or check "
|
| 18 |
+
"PEP 632 for potential alternatives")
|
| 19 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils._msvccompiler
|
| 2 |
+
|
| 3 |
+
Contains MSVCCompiler, an implementation of the abstract CCompiler class
|
| 4 |
+
for Microsoft Visual Studio 2015.
|
| 5 |
+
|
| 6 |
+
The module is compatible with VS 2015 and later. You can find legacy support
|
| 7 |
+
for older versions in distutils.msvc9compiler and distutils.msvccompiler.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
# Written by Perry Stoll
|
| 11 |
+
# hacked by Robin Becker and Thomas Heller to do a better job of
|
| 12 |
+
# finding DevStudio (through the registry)
|
| 13 |
+
# ported to VS 2005 and VS 2008 by Christian Heimes
|
| 14 |
+
# ported to VS 2015 by Steve Dower
|
| 15 |
+
|
| 16 |
+
import os
|
| 17 |
+
import subprocess
|
| 18 |
+
import winreg
|
| 19 |
+
|
| 20 |
+
from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
|
| 21 |
+
CompileError, LibError, LinkError
|
| 22 |
+
from distutils.ccompiler import CCompiler, gen_lib_options
|
| 23 |
+
from distutils import log
|
| 24 |
+
from distutils.util import get_platform
|
| 25 |
+
|
| 26 |
+
from itertools import count
|
| 27 |
+
|
| 28 |
+
def _find_vc2015():
|
| 29 |
+
try:
|
| 30 |
+
key = winreg.OpenKeyEx(
|
| 31 |
+
winreg.HKEY_LOCAL_MACHINE,
|
| 32 |
+
r"Software\Microsoft\VisualStudio\SxS\VC7",
|
| 33 |
+
access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
|
| 34 |
+
)
|
| 35 |
+
except OSError:
|
| 36 |
+
log.debug("Visual C++ is not registered")
|
| 37 |
+
return None, None
|
| 38 |
+
|
| 39 |
+
best_version = 0
|
| 40 |
+
best_dir = None
|
| 41 |
+
with key:
|
| 42 |
+
for i in count():
|
| 43 |
+
try:
|
| 44 |
+
v, vc_dir, vt = winreg.EnumValue(key, i)
|
| 45 |
+
except OSError:
|
| 46 |
+
break
|
| 47 |
+
if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
|
| 48 |
+
try:
|
| 49 |
+
version = int(float(v))
|
| 50 |
+
except (ValueError, TypeError):
|
| 51 |
+
continue
|
| 52 |
+
if version >= 14 and version > best_version:
|
| 53 |
+
best_version, best_dir = version, vc_dir
|
| 54 |
+
return best_version, best_dir
|
| 55 |
+
|
| 56 |
+
def _find_vc2017():
|
| 57 |
+
"""Returns "15, path" based on the result of invoking vswhere.exe
|
| 58 |
+
If no install is found, returns "None, None"
|
| 59 |
+
|
| 60 |
+
The version is returned to avoid unnecessarily changing the function
|
| 61 |
+
result. It may be ignored when the path is not None.
|
| 62 |
+
|
| 63 |
+
If vswhere.exe is not available, by definition, VS 2017 is not
|
| 64 |
+
installed.
|
| 65 |
+
"""
|
| 66 |
+
root = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")
|
| 67 |
+
if not root:
|
| 68 |
+
return None, None
|
| 69 |
+
|
| 70 |
+
try:
|
| 71 |
+
path = subprocess.check_output([
|
| 72 |
+
os.path.join(root, "Microsoft Visual Studio", "Installer", "vswhere.exe"),
|
| 73 |
+
"-latest",
|
| 74 |
+
"-prerelease",
|
| 75 |
+
"-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
|
| 76 |
+
"-property", "installationPath",
|
| 77 |
+
"-products", "*",
|
| 78 |
+
], encoding="mbcs", errors="strict").strip()
|
| 79 |
+
except (subprocess.CalledProcessError, OSError, UnicodeDecodeError):
|
| 80 |
+
return None, None
|
| 81 |
+
|
| 82 |
+
path = os.path.join(path, "VC", "Auxiliary", "Build")
|
| 83 |
+
if os.path.isdir(path):
|
| 84 |
+
return 15, path
|
| 85 |
+
|
| 86 |
+
return None, None
|
| 87 |
+
|
| 88 |
+
PLAT_SPEC_TO_RUNTIME = {
|
| 89 |
+
'x86' : 'x86',
|
| 90 |
+
'x86_amd64' : 'x64',
|
| 91 |
+
'x86_arm' : 'arm',
|
| 92 |
+
'x86_arm64' : 'arm64'
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
def _find_vcvarsall(plat_spec):
|
| 96 |
+
# bpo-38597: Removed vcruntime return value
|
| 97 |
+
_, best_dir = _find_vc2017()
|
| 98 |
+
|
| 99 |
+
if not best_dir:
|
| 100 |
+
best_version, best_dir = _find_vc2015()
|
| 101 |
+
|
| 102 |
+
if not best_dir:
|
| 103 |
+
log.debug("No suitable Visual C++ version found")
|
| 104 |
+
return None, None
|
| 105 |
+
|
| 106 |
+
vcvarsall = os.path.join(best_dir, "vcvarsall.bat")
|
| 107 |
+
if not os.path.isfile(vcvarsall):
|
| 108 |
+
log.debug("%s cannot be found", vcvarsall)
|
| 109 |
+
return None, None
|
| 110 |
+
|
| 111 |
+
return vcvarsall, None
|
| 112 |
+
|
| 113 |
+
def _get_vc_env(plat_spec):
|
| 114 |
+
if os.getenv("DISTUTILS_USE_SDK"):
|
| 115 |
+
return {
|
| 116 |
+
key.lower(): value
|
| 117 |
+
for key, value in os.environ.items()
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
vcvarsall, _ = _find_vcvarsall(plat_spec)
|
| 121 |
+
if not vcvarsall:
|
| 122 |
+
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
|
| 123 |
+
|
| 124 |
+
try:
|
| 125 |
+
out = subprocess.check_output(
|
| 126 |
+
'cmd /u /c "{}" {} && set'.format(vcvarsall, plat_spec),
|
| 127 |
+
stderr=subprocess.STDOUT,
|
| 128 |
+
).decode('utf-16le', errors='replace')
|
| 129 |
+
except subprocess.CalledProcessError as exc:
|
| 130 |
+
log.error(exc.output)
|
| 131 |
+
raise DistutilsPlatformError("Error executing {}"
|
| 132 |
+
.format(exc.cmd))
|
| 133 |
+
|
| 134 |
+
env = {
|
| 135 |
+
key.lower(): value
|
| 136 |
+
for key, _, value in
|
| 137 |
+
(line.partition('=') for line in out.splitlines())
|
| 138 |
+
if key and value
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
return env
|
| 142 |
+
|
| 143 |
+
def _find_exe(exe, paths=None):
|
| 144 |
+
"""Return path to an MSVC executable program.
|
| 145 |
+
|
| 146 |
+
Tries to find the program in several places: first, one of the
|
| 147 |
+
MSVC program search paths from the registry; next, the directories
|
| 148 |
+
in the PATH environment variable. If any of those work, return an
|
| 149 |
+
absolute path that is known to exist. If none of them work, just
|
| 150 |
+
return the original program name, 'exe'.
|
| 151 |
+
"""
|
| 152 |
+
if not paths:
|
| 153 |
+
paths = os.getenv('path').split(os.pathsep)
|
| 154 |
+
for p in paths:
|
| 155 |
+
fn = os.path.join(os.path.abspath(p), exe)
|
| 156 |
+
if os.path.isfile(fn):
|
| 157 |
+
return fn
|
| 158 |
+
return exe
|
| 159 |
+
|
| 160 |
+
# A map keyed by get_platform() return values to values accepted by
|
| 161 |
+
# 'vcvarsall.bat'. Always cross-compile from x86 to work with the
|
| 162 |
+
# lighter-weight MSVC installs that do not include native 64-bit tools.
|
| 163 |
+
PLAT_TO_VCVARS = {
|
| 164 |
+
'win32' : 'x86',
|
| 165 |
+
'win-amd64' : 'x86_amd64',
|
| 166 |
+
'win-arm32' : 'x86_arm',
|
| 167 |
+
'win-arm64' : 'x86_arm64'
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
class MSVCCompiler(CCompiler) :
|
| 171 |
+
"""Concrete class that implements an interface to Microsoft Visual C++,
|
| 172 |
+
as defined by the CCompiler abstract class."""
|
| 173 |
+
|
| 174 |
+
compiler_type = 'msvc'
|
| 175 |
+
|
| 176 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
| 177 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
| 178 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
| 179 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
| 180 |
+
# though, so it's worth thinking about.
|
| 181 |
+
executables = {}
|
| 182 |
+
|
| 183 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
| 184 |
+
_c_extensions = ['.c']
|
| 185 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
| 186 |
+
_rc_extensions = ['.rc']
|
| 187 |
+
_mc_extensions = ['.mc']
|
| 188 |
+
|
| 189 |
+
# Needed for the filename generation methods provided by the
|
| 190 |
+
# base class, CCompiler.
|
| 191 |
+
src_extensions = (_c_extensions + _cpp_extensions +
|
| 192 |
+
_rc_extensions + _mc_extensions)
|
| 193 |
+
res_extension = '.res'
|
| 194 |
+
obj_extension = '.obj'
|
| 195 |
+
static_lib_extension = '.lib'
|
| 196 |
+
shared_lib_extension = '.dll'
|
| 197 |
+
static_lib_format = shared_lib_format = '%s%s'
|
| 198 |
+
exe_extension = '.exe'
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
| 202 |
+
CCompiler.__init__ (self, verbose, dry_run, force)
|
| 203 |
+
# target platform (.plat_name is consistent with 'bdist')
|
| 204 |
+
self.plat_name = None
|
| 205 |
+
self.initialized = False
|
| 206 |
+
|
| 207 |
+
def initialize(self, plat_name=None):
|
| 208 |
+
# multi-init means we would need to check platform same each time...
|
| 209 |
+
assert not self.initialized, "don't init multiple times"
|
| 210 |
+
if plat_name is None:
|
| 211 |
+
plat_name = get_platform()
|
| 212 |
+
# sanity check for platforms to prevent obscure errors later.
|
| 213 |
+
if plat_name not in PLAT_TO_VCVARS:
|
| 214 |
+
raise DistutilsPlatformError("--plat-name must be one of {}"
|
| 215 |
+
.format(tuple(PLAT_TO_VCVARS)))
|
| 216 |
+
|
| 217 |
+
# Get the vcvarsall.bat spec for the requested platform.
|
| 218 |
+
plat_spec = PLAT_TO_VCVARS[plat_name]
|
| 219 |
+
|
| 220 |
+
vc_env = _get_vc_env(plat_spec)
|
| 221 |
+
if not vc_env:
|
| 222 |
+
raise DistutilsPlatformError("Unable to find a compatible "
|
| 223 |
+
"Visual Studio installation.")
|
| 224 |
+
|
| 225 |
+
self._paths = vc_env.get('path', '')
|
| 226 |
+
paths = self._paths.split(os.pathsep)
|
| 227 |
+
self.cc = _find_exe("cl.exe", paths)
|
| 228 |
+
self.linker = _find_exe("link.exe", paths)
|
| 229 |
+
self.lib = _find_exe("lib.exe", paths)
|
| 230 |
+
self.rc = _find_exe("rc.exe", paths) # resource compiler
|
| 231 |
+
self.mc = _find_exe("mc.exe", paths) # message compiler
|
| 232 |
+
self.mt = _find_exe("mt.exe", paths) # message compiler
|
| 233 |
+
|
| 234 |
+
for dir in vc_env.get('include', '').split(os.pathsep):
|
| 235 |
+
if dir:
|
| 236 |
+
self.add_include_dir(dir.rstrip(os.sep))
|
| 237 |
+
|
| 238 |
+
for dir in vc_env.get('lib', '').split(os.pathsep):
|
| 239 |
+
if dir:
|
| 240 |
+
self.add_library_dir(dir.rstrip(os.sep))
|
| 241 |
+
|
| 242 |
+
self.preprocess_options = None
|
| 243 |
+
# bpo-38597: Always compile with dynamic linking
|
| 244 |
+
# Future releases of Python 3.x will include all past
|
| 245 |
+
# versions of vcruntime*.dll for compatibility.
|
| 246 |
+
self.compile_options = [
|
| 247 |
+
'/nologo', '/Ox', '/W3', '/GL', '/DNDEBUG', '/MD'
|
| 248 |
+
]
|
| 249 |
+
|
| 250 |
+
self.compile_options_debug = [
|
| 251 |
+
'/nologo', '/Od', '/MDd', '/Zi', '/W3', '/D_DEBUG'
|
| 252 |
+
]
|
| 253 |
+
|
| 254 |
+
ldflags = [
|
| 255 |
+
'/nologo', '/INCREMENTAL:NO', '/LTCG'
|
| 256 |
+
]
|
| 257 |
+
|
| 258 |
+
ldflags_debug = [
|
| 259 |
+
'/nologo', '/INCREMENTAL:NO', '/LTCG', '/DEBUG:FULL'
|
| 260 |
+
]
|
| 261 |
+
|
| 262 |
+
self.ldflags_exe = [*ldflags, '/MANIFEST:EMBED,ID=1']
|
| 263 |
+
self.ldflags_exe_debug = [*ldflags_debug, '/MANIFEST:EMBED,ID=1']
|
| 264 |
+
self.ldflags_shared = [*ldflags, '/DLL', '/MANIFEST:EMBED,ID=2', '/MANIFESTUAC:NO']
|
| 265 |
+
self.ldflags_shared_debug = [*ldflags_debug, '/DLL', '/MANIFEST:EMBED,ID=2', '/MANIFESTUAC:NO']
|
| 266 |
+
self.ldflags_static = [*ldflags]
|
| 267 |
+
self.ldflags_static_debug = [*ldflags_debug]
|
| 268 |
+
|
| 269 |
+
self._ldflags = {
|
| 270 |
+
(CCompiler.EXECUTABLE, None): self.ldflags_exe,
|
| 271 |
+
(CCompiler.EXECUTABLE, False): self.ldflags_exe,
|
| 272 |
+
(CCompiler.EXECUTABLE, True): self.ldflags_exe_debug,
|
| 273 |
+
(CCompiler.SHARED_OBJECT, None): self.ldflags_shared,
|
| 274 |
+
(CCompiler.SHARED_OBJECT, False): self.ldflags_shared,
|
| 275 |
+
(CCompiler.SHARED_OBJECT, True): self.ldflags_shared_debug,
|
| 276 |
+
(CCompiler.SHARED_LIBRARY, None): self.ldflags_static,
|
| 277 |
+
(CCompiler.SHARED_LIBRARY, False): self.ldflags_static,
|
| 278 |
+
(CCompiler.SHARED_LIBRARY, True): self.ldflags_static_debug,
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
self.initialized = True
|
| 282 |
+
|
| 283 |
+
# -- Worker methods ------------------------------------------------
|
| 284 |
+
|
| 285 |
+
def object_filenames(self,
|
| 286 |
+
source_filenames,
|
| 287 |
+
strip_dir=0,
|
| 288 |
+
output_dir=''):
|
| 289 |
+
ext_map = {
|
| 290 |
+
**{ext: self.obj_extension for ext in self.src_extensions},
|
| 291 |
+
**{ext: self.res_extension for ext in self._rc_extensions + self._mc_extensions},
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
output_dir = output_dir or ''
|
| 295 |
+
|
| 296 |
+
def make_out_path(p):
|
| 297 |
+
base, ext = os.path.splitext(p)
|
| 298 |
+
if strip_dir:
|
| 299 |
+
base = os.path.basename(base)
|
| 300 |
+
else:
|
| 301 |
+
_, base = os.path.splitdrive(base)
|
| 302 |
+
if base.startswith((os.path.sep, os.path.altsep)):
|
| 303 |
+
base = base[1:]
|
| 304 |
+
try:
|
| 305 |
+
# XXX: This may produce absurdly long paths. We should check
|
| 306 |
+
# the length of the result and trim base until we fit within
|
| 307 |
+
# 260 characters.
|
| 308 |
+
return os.path.join(output_dir, base + ext_map[ext])
|
| 309 |
+
except LookupError:
|
| 310 |
+
# Better to raise an exception instead of silently continuing
|
| 311 |
+
# and later complain about sources and targets having
|
| 312 |
+
# different lengths
|
| 313 |
+
raise CompileError("Don't know how to compile {}".format(p))
|
| 314 |
+
|
| 315 |
+
return list(map(make_out_path, source_filenames))
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def compile(self, sources,
|
| 319 |
+
output_dir=None, macros=None, include_dirs=None, debug=0,
|
| 320 |
+
extra_preargs=None, extra_postargs=None, depends=None):
|
| 321 |
+
|
| 322 |
+
if not self.initialized:
|
| 323 |
+
self.initialize()
|
| 324 |
+
compile_info = self._setup_compile(output_dir, macros, include_dirs,
|
| 325 |
+
sources, depends, extra_postargs)
|
| 326 |
+
macros, objects, extra_postargs, pp_opts, build = compile_info
|
| 327 |
+
|
| 328 |
+
compile_opts = extra_preargs or []
|
| 329 |
+
compile_opts.append('/c')
|
| 330 |
+
if debug:
|
| 331 |
+
compile_opts.extend(self.compile_options_debug)
|
| 332 |
+
else:
|
| 333 |
+
compile_opts.extend(self.compile_options)
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
add_cpp_opts = False
|
| 337 |
+
|
| 338 |
+
for obj in objects:
|
| 339 |
+
try:
|
| 340 |
+
src, ext = build[obj]
|
| 341 |
+
except KeyError:
|
| 342 |
+
continue
|
| 343 |
+
if debug:
|
| 344 |
+
# pass the full pathname to MSVC in debug mode,
|
| 345 |
+
# this allows the debugger to find the source file
|
| 346 |
+
# without asking the user to browse for it
|
| 347 |
+
src = os.path.abspath(src)
|
| 348 |
+
|
| 349 |
+
# Anaconda/conda-forge customisation, we want our pdbs to be
|
| 350 |
+
# relocatable:
|
| 351 |
+
# https://developercommunity.visualstudio.com/comments/623156/view.html
|
| 352 |
+
d1trimfile_opts = []
|
| 353 |
+
if 'SRC_DIR' in os.environ and os.path.basename(self.cc) == "cl.exe":
|
| 354 |
+
d1trimfile_opts.append("/d1trimfile:" + os.environ['SRC_DIR'])
|
| 355 |
+
|
| 356 |
+
if ext in self._c_extensions:
|
| 357 |
+
input_opt = "/Tc" + src
|
| 358 |
+
elif ext in self._cpp_extensions:
|
| 359 |
+
input_opt = "/Tp" + src
|
| 360 |
+
add_cpp_opts = True
|
| 361 |
+
elif ext in self._rc_extensions:
|
| 362 |
+
# compile .RC to .RES file
|
| 363 |
+
input_opt = src
|
| 364 |
+
output_opt = "/fo" + obj
|
| 365 |
+
try:
|
| 366 |
+
self.spawn([self.rc] + pp_opts + [output_opt, input_opt])
|
| 367 |
+
except DistutilsExecError as msg:
|
| 368 |
+
raise CompileError(msg)
|
| 369 |
+
continue
|
| 370 |
+
elif ext in self._mc_extensions:
|
| 371 |
+
# Compile .MC to .RC file to .RES file.
|
| 372 |
+
# * '-h dir' specifies the directory for the
|
| 373 |
+
# generated include file
|
| 374 |
+
# * '-r dir' specifies the target directory of the
|
| 375 |
+
# generated RC file and the binary message resource
|
| 376 |
+
# it includes
|
| 377 |
+
#
|
| 378 |
+
# For now (since there are no options to change this),
|
| 379 |
+
# we use the source-directory for the include file and
|
| 380 |
+
# the build directory for the RC file and message
|
| 381 |
+
# resources. This works at least for win32all.
|
| 382 |
+
h_dir = os.path.dirname(src)
|
| 383 |
+
rc_dir = os.path.dirname(obj)
|
| 384 |
+
try:
|
| 385 |
+
# first compile .MC to .RC and .H file
|
| 386 |
+
self.spawn([self.mc, '-h', h_dir, '-r', rc_dir, src])
|
| 387 |
+
base, _ = os.path.splitext(os.path.basename (src))
|
| 388 |
+
rc_file = os.path.join(rc_dir, base + '.rc')
|
| 389 |
+
# then compile .RC to .RES file
|
| 390 |
+
self.spawn([self.rc, "/fo" + obj, rc_file])
|
| 391 |
+
|
| 392 |
+
except DistutilsExecError as msg:
|
| 393 |
+
raise CompileError(msg)
|
| 394 |
+
continue
|
| 395 |
+
else:
|
| 396 |
+
# how to handle this file?
|
| 397 |
+
raise CompileError("Don't know how to compile {} to {}"
|
| 398 |
+
.format(src, obj))
|
| 399 |
+
|
| 400 |
+
args = [self.cc] + compile_opts + pp_opts + d1trimfile_opts
|
| 401 |
+
if add_cpp_opts:
|
| 402 |
+
args.append('/EHsc')
|
| 403 |
+
args.append(input_opt)
|
| 404 |
+
args.append("/Fo" + obj)
|
| 405 |
+
args.extend(extra_postargs)
|
| 406 |
+
|
| 407 |
+
try:
|
| 408 |
+
self.spawn(args)
|
| 409 |
+
except DistutilsExecError as msg:
|
| 410 |
+
raise CompileError(msg)
|
| 411 |
+
|
| 412 |
+
return objects
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
def create_static_lib(self,
|
| 416 |
+
objects,
|
| 417 |
+
output_libname,
|
| 418 |
+
output_dir=None,
|
| 419 |
+
debug=0,
|
| 420 |
+
target_lang=None):
|
| 421 |
+
|
| 422 |
+
if not self.initialized:
|
| 423 |
+
self.initialize()
|
| 424 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
| 425 |
+
output_filename = self.library_filename(output_libname,
|
| 426 |
+
output_dir=output_dir)
|
| 427 |
+
|
| 428 |
+
if self._need_link(objects, output_filename):
|
| 429 |
+
lib_args = objects + ['/OUT:' + output_filename]
|
| 430 |
+
if debug:
|
| 431 |
+
pass # XXX what goes here?
|
| 432 |
+
try:
|
| 433 |
+
log.debug('Executing "%s" %s', self.lib, ' '.join(lib_args))
|
| 434 |
+
self.spawn([self.lib] + lib_args)
|
| 435 |
+
except DistutilsExecError as msg:
|
| 436 |
+
raise LibError(msg)
|
| 437 |
+
else:
|
| 438 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
def link(self,
|
| 442 |
+
target_desc,
|
| 443 |
+
objects,
|
| 444 |
+
output_filename,
|
| 445 |
+
output_dir=None,
|
| 446 |
+
libraries=None,
|
| 447 |
+
library_dirs=None,
|
| 448 |
+
runtime_library_dirs=None,
|
| 449 |
+
export_symbols=None,
|
| 450 |
+
debug=0,
|
| 451 |
+
extra_preargs=None,
|
| 452 |
+
extra_postargs=None,
|
| 453 |
+
build_temp=None,
|
| 454 |
+
target_lang=None):
|
| 455 |
+
|
| 456 |
+
if not self.initialized:
|
| 457 |
+
self.initialize()
|
| 458 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
| 459 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs,
|
| 460 |
+
runtime_library_dirs)
|
| 461 |
+
libraries, library_dirs, runtime_library_dirs = fixed_args
|
| 462 |
+
|
| 463 |
+
if runtime_library_dirs:
|
| 464 |
+
self.warn("I don't know what to do with 'runtime_library_dirs': "
|
| 465 |
+
+ str(runtime_library_dirs))
|
| 466 |
+
|
| 467 |
+
lib_opts = gen_lib_options(self,
|
| 468 |
+
library_dirs, runtime_library_dirs,
|
| 469 |
+
libraries)
|
| 470 |
+
if output_dir is not None:
|
| 471 |
+
output_filename = os.path.join(output_dir, output_filename)
|
| 472 |
+
|
| 473 |
+
if self._need_link(objects, output_filename):
|
| 474 |
+
ldflags = self._ldflags[target_desc, debug]
|
| 475 |
+
|
| 476 |
+
export_opts = ["/EXPORT:" + sym for sym in (export_symbols or [])]
|
| 477 |
+
|
| 478 |
+
ld_args = (ldflags + lib_opts + export_opts +
|
| 479 |
+
objects + ['/OUT:' + output_filename])
|
| 480 |
+
|
| 481 |
+
# The MSVC linker generates .lib and .exp files, which cannot be
|
| 482 |
+
# suppressed by any linker switches. The .lib files may even be
|
| 483 |
+
# needed! Make sure they are generated in the temporary build
|
| 484 |
+
# directory. Since they have different names for debug and release
|
| 485 |
+
# builds, they can go into the same directory.
|
| 486 |
+
build_temp = os.path.dirname(objects[0])
|
| 487 |
+
if export_symbols is not None:
|
| 488 |
+
(dll_name, dll_ext) = os.path.splitext(
|
| 489 |
+
os.path.basename(output_filename))
|
| 490 |
+
implib_file = os.path.join(
|
| 491 |
+
build_temp,
|
| 492 |
+
self.library_filename(dll_name))
|
| 493 |
+
ld_args.append ('/IMPLIB:' + implib_file)
|
| 494 |
+
|
| 495 |
+
if extra_preargs:
|
| 496 |
+
ld_args[:0] = extra_preargs
|
| 497 |
+
if extra_postargs:
|
| 498 |
+
ld_args.extend(extra_postargs)
|
| 499 |
+
|
| 500 |
+
output_dir = os.path.dirname(os.path.abspath(output_filename))
|
| 501 |
+
self.mkpath(output_dir)
|
| 502 |
+
try:
|
| 503 |
+
log.debug('Executing "%s" %s', self.linker, ' '.join(ld_args))
|
| 504 |
+
self.spawn([self.linker] + ld_args)
|
| 505 |
+
except DistutilsExecError as msg:
|
| 506 |
+
raise LinkError(msg)
|
| 507 |
+
else:
|
| 508 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 509 |
+
|
| 510 |
+
def spawn(self, cmd):
|
| 511 |
+
old_path = os.getenv('path')
|
| 512 |
+
try:
|
| 513 |
+
os.environ['path'] = self._paths
|
| 514 |
+
return super().spawn(cmd)
|
| 515 |
+
finally:
|
| 516 |
+
os.environ['path'] = old_path
|
| 517 |
+
|
| 518 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 519 |
+
# These are all used by the 'gen_lib_options() function, in
|
| 520 |
+
# ccompiler.py.
|
| 521 |
+
|
| 522 |
+
def library_dir_option(self, dir):
|
| 523 |
+
return "/LIBPATH:" + dir
|
| 524 |
+
|
| 525 |
+
def runtime_library_dir_option(self, dir):
|
| 526 |
+
raise DistutilsPlatformError(
|
| 527 |
+
"don't know how to set runtime library search path for MSVC")
|
| 528 |
+
|
| 529 |
+
def library_option(self, lib):
|
| 530 |
+
return self.library_filename(lib)
|
| 531 |
+
|
| 532 |
+
def find_library_file(self, dirs, lib, debug=0):
|
| 533 |
+
# Prefer a debugging library if found (and requested), but deal
|
| 534 |
+
# with it if we don't have one.
|
| 535 |
+
if debug:
|
| 536 |
+
try_names = [lib + "_d", lib]
|
| 537 |
+
else:
|
| 538 |
+
try_names = [lib]
|
| 539 |
+
for dir in dirs:
|
| 540 |
+
for name in try_names:
|
| 541 |
+
libfile = os.path.join(dir, self.library_filename(name))
|
| 542 |
+
if os.path.isfile(libfile):
|
| 543 |
+
return libfile
|
| 544 |
+
else:
|
| 545 |
+
# Oops, didn't find it in *any* of 'dirs'
|
| 546 |
+
return None
|
data/conda_envs/evalclaw/lib/python3.11/distutils/archive_util.py
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
| 1 |
+
"""distutils.archive_util
|
| 2 |
+
|
| 3 |
+
Utility functions for creating archive files (tarballs, zip files,
|
| 4 |
+
that sort of thing)."""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
from warnings import warn
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
try:
|
| 11 |
+
import zipfile
|
| 12 |
+
except ImportError:
|
| 13 |
+
zipfile = None
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
from distutils.errors import DistutilsExecError
|
| 17 |
+
from distutils.spawn import spawn
|
| 18 |
+
from distutils.dir_util import mkpath
|
| 19 |
+
from distutils import log
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
from pwd import getpwnam
|
| 23 |
+
except ImportError:
|
| 24 |
+
getpwnam = None
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
from grp import getgrnam
|
| 28 |
+
except ImportError:
|
| 29 |
+
getgrnam = None
|
| 30 |
+
|
| 31 |
+
def _get_gid(name):
|
| 32 |
+
"""Returns a gid, given a group name."""
|
| 33 |
+
if getgrnam is None or name is None:
|
| 34 |
+
return None
|
| 35 |
+
try:
|
| 36 |
+
result = getgrnam(name)
|
| 37 |
+
except KeyError:
|
| 38 |
+
result = None
|
| 39 |
+
if result is not None:
|
| 40 |
+
return result[2]
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
def _get_uid(name):
|
| 44 |
+
"""Returns an uid, given a user name."""
|
| 45 |
+
if getpwnam is None or name is None:
|
| 46 |
+
return None
|
| 47 |
+
try:
|
| 48 |
+
result = getpwnam(name)
|
| 49 |
+
except KeyError:
|
| 50 |
+
result = None
|
| 51 |
+
if result is not None:
|
| 52 |
+
return result[2]
|
| 53 |
+
return None
|
| 54 |
+
|
| 55 |
+
def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
|
| 56 |
+
owner=None, group=None):
|
| 57 |
+
"""Create a (possibly compressed) tar file from all the files under
|
| 58 |
+
'base_dir'.
|
| 59 |
+
|
| 60 |
+
'compress' must be "gzip" (the default), "bzip2", "xz", "compress", or
|
| 61 |
+
None. ("compress" will be deprecated in Python 3.2)
|
| 62 |
+
|
| 63 |
+
'owner' and 'group' can be used to define an owner and a group for the
|
| 64 |
+
archive that is being built. If not provided, the current owner and group
|
| 65 |
+
will be used.
|
| 66 |
+
|
| 67 |
+
The output tar file will be named 'base_dir' + ".tar", possibly plus
|
| 68 |
+
the appropriate compression extension (".gz", ".bz2", ".xz" or ".Z").
|
| 69 |
+
|
| 70 |
+
Returns the output filename.
|
| 71 |
+
"""
|
| 72 |
+
tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', 'xz': 'xz', None: '',
|
| 73 |
+
'compress': ''}
|
| 74 |
+
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'xz': '.xz',
|
| 75 |
+
'compress': '.Z'}
|
| 76 |
+
|
| 77 |
+
# flags for compression program, each element of list will be an argument
|
| 78 |
+
if compress is not None and compress not in compress_ext.keys():
|
| 79 |
+
raise ValueError(
|
| 80 |
+
"bad value for 'compress': must be None, 'gzip', 'bzip2', "
|
| 81 |
+
"'xz' or 'compress'")
|
| 82 |
+
|
| 83 |
+
archive_name = base_name + '.tar'
|
| 84 |
+
if compress != 'compress':
|
| 85 |
+
archive_name += compress_ext.get(compress, '')
|
| 86 |
+
|
| 87 |
+
mkpath(os.path.dirname(archive_name), dry_run=dry_run)
|
| 88 |
+
|
| 89 |
+
# creating the tarball
|
| 90 |
+
import tarfile # late import so Python build itself doesn't break
|
| 91 |
+
|
| 92 |
+
log.info('Creating tar archive')
|
| 93 |
+
|
| 94 |
+
uid = _get_uid(owner)
|
| 95 |
+
gid = _get_gid(group)
|
| 96 |
+
|
| 97 |
+
def _set_uid_gid(tarinfo):
|
| 98 |
+
if gid is not None:
|
| 99 |
+
tarinfo.gid = gid
|
| 100 |
+
tarinfo.gname = group
|
| 101 |
+
if uid is not None:
|
| 102 |
+
tarinfo.uid = uid
|
| 103 |
+
tarinfo.uname = owner
|
| 104 |
+
return tarinfo
|
| 105 |
+
|
| 106 |
+
if not dry_run:
|
| 107 |
+
tar = tarfile.open(archive_name, 'w|%s' % tar_compression[compress])
|
| 108 |
+
try:
|
| 109 |
+
tar.add(base_dir, filter=_set_uid_gid)
|
| 110 |
+
finally:
|
| 111 |
+
tar.close()
|
| 112 |
+
|
| 113 |
+
# compression using `compress`
|
| 114 |
+
if compress == 'compress':
|
| 115 |
+
warn("'compress' will be deprecated.", PendingDeprecationWarning)
|
| 116 |
+
# the option varies depending on the platform
|
| 117 |
+
compressed_name = archive_name + compress_ext[compress]
|
| 118 |
+
if sys.platform == 'win32':
|
| 119 |
+
cmd = [compress, archive_name, compressed_name]
|
| 120 |
+
else:
|
| 121 |
+
cmd = [compress, '-f', archive_name]
|
| 122 |
+
spawn(cmd, dry_run=dry_run)
|
| 123 |
+
return compressed_name
|
| 124 |
+
|
| 125 |
+
return archive_name
|
| 126 |
+
|
| 127 |
+
def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
|
| 128 |
+
"""Create a zip file from all the files under 'base_dir'.
|
| 129 |
+
|
| 130 |
+
The output zip file will be named 'base_name' + ".zip". Uses either the
|
| 131 |
+
"zipfile" Python module (if available) or the InfoZIP "zip" utility
|
| 132 |
+
(if installed and found on the default search path). If neither tool is
|
| 133 |
+
available, raises DistutilsExecError. Returns the name of the output zip
|
| 134 |
+
file.
|
| 135 |
+
"""
|
| 136 |
+
zip_filename = base_name + ".zip"
|
| 137 |
+
mkpath(os.path.dirname(zip_filename), dry_run=dry_run)
|
| 138 |
+
|
| 139 |
+
# If zipfile module is not available, try spawning an external
|
| 140 |
+
# 'zip' command.
|
| 141 |
+
if zipfile is None:
|
| 142 |
+
if verbose:
|
| 143 |
+
zipoptions = "-r"
|
| 144 |
+
else:
|
| 145 |
+
zipoptions = "-rq"
|
| 146 |
+
|
| 147 |
+
try:
|
| 148 |
+
spawn(["zip", zipoptions, zip_filename, base_dir],
|
| 149 |
+
dry_run=dry_run)
|
| 150 |
+
except DistutilsExecError:
|
| 151 |
+
# XXX really should distinguish between "couldn't find
|
| 152 |
+
# external 'zip' command" and "zip failed".
|
| 153 |
+
raise DistutilsExecError(("unable to create zip file '%s': "
|
| 154 |
+
"could neither import the 'zipfile' module nor "
|
| 155 |
+
"find a standalone zip utility") % zip_filename)
|
| 156 |
+
|
| 157 |
+
else:
|
| 158 |
+
log.info("creating '%s' and adding '%s' to it",
|
| 159 |
+
zip_filename, base_dir)
|
| 160 |
+
|
| 161 |
+
if not dry_run:
|
| 162 |
+
try:
|
| 163 |
+
zip = zipfile.ZipFile(zip_filename, "w",
|
| 164 |
+
compression=zipfile.ZIP_DEFLATED)
|
| 165 |
+
except RuntimeError:
|
| 166 |
+
zip = zipfile.ZipFile(zip_filename, "w",
|
| 167 |
+
compression=zipfile.ZIP_STORED)
|
| 168 |
+
|
| 169 |
+
with zip:
|
| 170 |
+
if base_dir != os.curdir:
|
| 171 |
+
path = os.path.normpath(os.path.join(base_dir, ''))
|
| 172 |
+
zip.write(path, path)
|
| 173 |
+
log.info("adding '%s'", path)
|
| 174 |
+
for dirpath, dirnames, filenames in os.walk(base_dir):
|
| 175 |
+
for name in dirnames:
|
| 176 |
+
path = os.path.normpath(os.path.join(dirpath, name, ''))
|
| 177 |
+
zip.write(path, path)
|
| 178 |
+
log.info("adding '%s'", path)
|
| 179 |
+
for name in filenames:
|
| 180 |
+
path = os.path.normpath(os.path.join(dirpath, name))
|
| 181 |
+
if os.path.isfile(path):
|
| 182 |
+
zip.write(path, path)
|
| 183 |
+
log.info("adding '%s'", path)
|
| 184 |
+
|
| 185 |
+
return zip_filename
|
| 186 |
+
|
| 187 |
+
ARCHIVE_FORMATS = {
|
| 188 |
+
'gztar': (make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
|
| 189 |
+
'bztar': (make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
|
| 190 |
+
'xztar': (make_tarball, [('compress', 'xz')], "xz'ed tar-file"),
|
| 191 |
+
'ztar': (make_tarball, [('compress', 'compress')], "compressed tar file"),
|
| 192 |
+
'tar': (make_tarball, [('compress', None)], "uncompressed tar file"),
|
| 193 |
+
'zip': (make_zipfile, [],"ZIP file")
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
def check_archive_formats(formats):
|
| 197 |
+
"""Returns the first format from the 'format' list that is unknown.
|
| 198 |
+
|
| 199 |
+
If all formats are known, returns None
|
| 200 |
+
"""
|
| 201 |
+
for format in formats:
|
| 202 |
+
if format not in ARCHIVE_FORMATS:
|
| 203 |
+
return format
|
| 204 |
+
return None
|
| 205 |
+
|
| 206 |
+
def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
|
| 207 |
+
dry_run=0, owner=None, group=None):
|
| 208 |
+
"""Create an archive file (eg. zip or tar).
|
| 209 |
+
|
| 210 |
+
'base_name' is the name of the file to create, minus any format-specific
|
| 211 |
+
extension; 'format' is the archive format: one of "zip", "tar", "gztar",
|
| 212 |
+
"bztar", "xztar", or "ztar".
|
| 213 |
+
|
| 214 |
+
'root_dir' is a directory that will be the root directory of the
|
| 215 |
+
archive; ie. we typically chdir into 'root_dir' before creating the
|
| 216 |
+
archive. 'base_dir' is the directory where we start archiving from;
|
| 217 |
+
ie. 'base_dir' will be the common prefix of all files and
|
| 218 |
+
directories in the archive. 'root_dir' and 'base_dir' both default
|
| 219 |
+
to the current directory. Returns the name of the archive file.
|
| 220 |
+
|
| 221 |
+
'owner' and 'group' are used when creating a tar archive. By default,
|
| 222 |
+
uses the current owner and group.
|
| 223 |
+
"""
|
| 224 |
+
save_cwd = os.getcwd()
|
| 225 |
+
if root_dir is not None:
|
| 226 |
+
log.debug("changing into '%s'", root_dir)
|
| 227 |
+
base_name = os.path.abspath(base_name)
|
| 228 |
+
if not dry_run:
|
| 229 |
+
os.chdir(root_dir)
|
| 230 |
+
|
| 231 |
+
if base_dir is None:
|
| 232 |
+
base_dir = os.curdir
|
| 233 |
+
|
| 234 |
+
kwargs = {'dry_run': dry_run}
|
| 235 |
+
|
| 236 |
+
try:
|
| 237 |
+
format_info = ARCHIVE_FORMATS[format]
|
| 238 |
+
except KeyError:
|
| 239 |
+
raise ValueError("unknown archive format '%s'" % format)
|
| 240 |
+
|
| 241 |
+
func = format_info[0]
|
| 242 |
+
for arg, val in format_info[1]:
|
| 243 |
+
kwargs[arg] = val
|
| 244 |
+
|
| 245 |
+
if format != 'zip':
|
| 246 |
+
kwargs['owner'] = owner
|
| 247 |
+
kwargs['group'] = group
|
| 248 |
+
|
| 249 |
+
try:
|
| 250 |
+
filename = func(base_name, base_dir, **kwargs)
|
| 251 |
+
finally:
|
| 252 |
+
if root_dir is not None:
|
| 253 |
+
log.debug("changing back to '%s'", save_cwd)
|
| 254 |
+
os.chdir(save_cwd)
|
| 255 |
+
|
| 256 |
+
return filename
|
data/conda_envs/evalclaw/lib/python3.11/distutils/bcppcompiler.py
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.bcppcompiler
|
| 2 |
+
|
| 3 |
+
Contains BorlandCCompiler, an implementation of the abstract CCompiler class
|
| 4 |
+
for the Borland C++ compiler.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
# This implementation by Lyle Johnson, based on the original msvccompiler.py
|
| 8 |
+
# module and using the directions originally published by Gordon Williams.
|
| 9 |
+
|
| 10 |
+
# XXX looks like there's a LOT of overlap between these two classes:
|
| 11 |
+
# someone should sit down and factor out the common code as
|
| 12 |
+
# WindowsCCompiler! --GPW
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
from distutils.errors import \
|
| 17 |
+
DistutilsExecError, \
|
| 18 |
+
CompileError, LibError, LinkError, UnknownFileError
|
| 19 |
+
from distutils.ccompiler import \
|
| 20 |
+
CCompiler, gen_preprocess_options
|
| 21 |
+
from distutils.file_util import write_file
|
| 22 |
+
from distutils.dep_util import newer
|
| 23 |
+
from distutils import log
|
| 24 |
+
|
| 25 |
+
class BCPPCompiler(CCompiler) :
|
| 26 |
+
"""Concrete class that implements an interface to the Borland C/C++
|
| 27 |
+
compiler, as defined by the CCompiler abstract class.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
compiler_type = 'bcpp'
|
| 31 |
+
|
| 32 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
| 33 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
| 34 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
| 35 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
| 36 |
+
# though, so it's worth thinking about.
|
| 37 |
+
executables = {}
|
| 38 |
+
|
| 39 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
| 40 |
+
_c_extensions = ['.c']
|
| 41 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
| 42 |
+
|
| 43 |
+
# Needed for the filename generation methods provided by the
|
| 44 |
+
# base class, CCompiler.
|
| 45 |
+
src_extensions = _c_extensions + _cpp_extensions
|
| 46 |
+
obj_extension = '.obj'
|
| 47 |
+
static_lib_extension = '.lib'
|
| 48 |
+
shared_lib_extension = '.dll'
|
| 49 |
+
static_lib_format = shared_lib_format = '%s%s'
|
| 50 |
+
exe_extension = '.exe'
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def __init__ (self,
|
| 54 |
+
verbose=0,
|
| 55 |
+
dry_run=0,
|
| 56 |
+
force=0):
|
| 57 |
+
|
| 58 |
+
CCompiler.__init__ (self, verbose, dry_run, force)
|
| 59 |
+
|
| 60 |
+
# These executables are assumed to all be in the path.
|
| 61 |
+
# Borland doesn't seem to use any special registry settings to
|
| 62 |
+
# indicate their installation locations.
|
| 63 |
+
|
| 64 |
+
self.cc = "bcc32.exe"
|
| 65 |
+
self.linker = "ilink32.exe"
|
| 66 |
+
self.lib = "tlib.exe"
|
| 67 |
+
|
| 68 |
+
self.preprocess_options = None
|
| 69 |
+
self.compile_options = ['/tWM', '/O2', '/q', '/g0']
|
| 70 |
+
self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0']
|
| 71 |
+
|
| 72 |
+
self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x']
|
| 73 |
+
self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x']
|
| 74 |
+
self.ldflags_static = []
|
| 75 |
+
self.ldflags_exe = ['/Gn', '/q', '/x']
|
| 76 |
+
self.ldflags_exe_debug = ['/Gn', '/q', '/x','/r']
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
# -- Worker methods ------------------------------------------------
|
| 80 |
+
|
| 81 |
+
def compile(self, sources,
|
| 82 |
+
output_dir=None, macros=None, include_dirs=None, debug=0,
|
| 83 |
+
extra_preargs=None, extra_postargs=None, depends=None):
|
| 84 |
+
|
| 85 |
+
macros, objects, extra_postargs, pp_opts, build = \
|
| 86 |
+
self._setup_compile(output_dir, macros, include_dirs, sources,
|
| 87 |
+
depends, extra_postargs)
|
| 88 |
+
compile_opts = extra_preargs or []
|
| 89 |
+
compile_opts.append ('-c')
|
| 90 |
+
if debug:
|
| 91 |
+
compile_opts.extend (self.compile_options_debug)
|
| 92 |
+
else:
|
| 93 |
+
compile_opts.extend (self.compile_options)
|
| 94 |
+
|
| 95 |
+
for obj in objects:
|
| 96 |
+
try:
|
| 97 |
+
src, ext = build[obj]
|
| 98 |
+
except KeyError:
|
| 99 |
+
continue
|
| 100 |
+
# XXX why do the normpath here?
|
| 101 |
+
src = os.path.normpath(src)
|
| 102 |
+
obj = os.path.normpath(obj)
|
| 103 |
+
# XXX _setup_compile() did a mkpath() too but before the normpath.
|
| 104 |
+
# Is it possible to skip the normpath?
|
| 105 |
+
self.mkpath(os.path.dirname(obj))
|
| 106 |
+
|
| 107 |
+
if ext == '.res':
|
| 108 |
+
# This is already a binary file -- skip it.
|
| 109 |
+
continue # the 'for' loop
|
| 110 |
+
if ext == '.rc':
|
| 111 |
+
# This needs to be compiled to a .res file -- do it now.
|
| 112 |
+
try:
|
| 113 |
+
self.spawn (["brcc32", "-fo", obj, src])
|
| 114 |
+
except DistutilsExecError as msg:
|
| 115 |
+
raise CompileError(msg)
|
| 116 |
+
continue # the 'for' loop
|
| 117 |
+
|
| 118 |
+
# The next two are both for the real compiler.
|
| 119 |
+
if ext in self._c_extensions:
|
| 120 |
+
input_opt = ""
|
| 121 |
+
elif ext in self._cpp_extensions:
|
| 122 |
+
input_opt = "-P"
|
| 123 |
+
else:
|
| 124 |
+
# Unknown file type -- no extra options. The compiler
|
| 125 |
+
# will probably fail, but let it just in case this is a
|
| 126 |
+
# file the compiler recognizes even if we don't.
|
| 127 |
+
input_opt = ""
|
| 128 |
+
|
| 129 |
+
output_opt = "-o" + obj
|
| 130 |
+
|
| 131 |
+
# Compiler command line syntax is: "bcc32 [options] file(s)".
|
| 132 |
+
# Note that the source file names must appear at the end of
|
| 133 |
+
# the command line.
|
| 134 |
+
try:
|
| 135 |
+
self.spawn ([self.cc] + compile_opts + pp_opts +
|
| 136 |
+
[input_opt, output_opt] +
|
| 137 |
+
extra_postargs + [src])
|
| 138 |
+
except DistutilsExecError as msg:
|
| 139 |
+
raise CompileError(msg)
|
| 140 |
+
|
| 141 |
+
return objects
|
| 142 |
+
|
| 143 |
+
# compile ()
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def create_static_lib (self,
|
| 147 |
+
objects,
|
| 148 |
+
output_libname,
|
| 149 |
+
output_dir=None,
|
| 150 |
+
debug=0,
|
| 151 |
+
target_lang=None):
|
| 152 |
+
|
| 153 |
+
(objects, output_dir) = self._fix_object_args (objects, output_dir)
|
| 154 |
+
output_filename = \
|
| 155 |
+
self.library_filename (output_libname, output_dir=output_dir)
|
| 156 |
+
|
| 157 |
+
if self._need_link (objects, output_filename):
|
| 158 |
+
lib_args = [output_filename, '/u'] + objects
|
| 159 |
+
if debug:
|
| 160 |
+
pass # XXX what goes here?
|
| 161 |
+
try:
|
| 162 |
+
self.spawn ([self.lib] + lib_args)
|
| 163 |
+
except DistutilsExecError as msg:
|
| 164 |
+
raise LibError(msg)
|
| 165 |
+
else:
|
| 166 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 167 |
+
|
| 168 |
+
# create_static_lib ()
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def link (self,
|
| 172 |
+
target_desc,
|
| 173 |
+
objects,
|
| 174 |
+
output_filename,
|
| 175 |
+
output_dir=None,
|
| 176 |
+
libraries=None,
|
| 177 |
+
library_dirs=None,
|
| 178 |
+
runtime_library_dirs=None,
|
| 179 |
+
export_symbols=None,
|
| 180 |
+
debug=0,
|
| 181 |
+
extra_preargs=None,
|
| 182 |
+
extra_postargs=None,
|
| 183 |
+
build_temp=None,
|
| 184 |
+
target_lang=None):
|
| 185 |
+
|
| 186 |
+
# XXX this ignores 'build_temp'! should follow the lead of
|
| 187 |
+
# msvccompiler.py
|
| 188 |
+
|
| 189 |
+
(objects, output_dir) = self._fix_object_args (objects, output_dir)
|
| 190 |
+
(libraries, library_dirs, runtime_library_dirs) = \
|
| 191 |
+
self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
|
| 192 |
+
|
| 193 |
+
if runtime_library_dirs:
|
| 194 |
+
log.warn("I don't know what to do with 'runtime_library_dirs': %s",
|
| 195 |
+
str(runtime_library_dirs))
|
| 196 |
+
|
| 197 |
+
if output_dir is not None:
|
| 198 |
+
output_filename = os.path.join (output_dir, output_filename)
|
| 199 |
+
|
| 200 |
+
if self._need_link (objects, output_filename):
|
| 201 |
+
|
| 202 |
+
# Figure out linker args based on type of target.
|
| 203 |
+
if target_desc == CCompiler.EXECUTABLE:
|
| 204 |
+
startup_obj = 'c0w32'
|
| 205 |
+
if debug:
|
| 206 |
+
ld_args = self.ldflags_exe_debug[:]
|
| 207 |
+
else:
|
| 208 |
+
ld_args = self.ldflags_exe[:]
|
| 209 |
+
else:
|
| 210 |
+
startup_obj = 'c0d32'
|
| 211 |
+
if debug:
|
| 212 |
+
ld_args = self.ldflags_shared_debug[:]
|
| 213 |
+
else:
|
| 214 |
+
ld_args = self.ldflags_shared[:]
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
# Create a temporary exports file for use by the linker
|
| 218 |
+
if export_symbols is None:
|
| 219 |
+
def_file = ''
|
| 220 |
+
else:
|
| 221 |
+
head, tail = os.path.split (output_filename)
|
| 222 |
+
modname, ext = os.path.splitext (tail)
|
| 223 |
+
temp_dir = os.path.dirname(objects[0]) # preserve tree structure
|
| 224 |
+
def_file = os.path.join (temp_dir, '%s.def' % modname)
|
| 225 |
+
contents = ['EXPORTS']
|
| 226 |
+
for sym in (export_symbols or []):
|
| 227 |
+
contents.append(' %s=_%s' % (sym, sym))
|
| 228 |
+
self.execute(write_file, (def_file, contents),
|
| 229 |
+
"writing %s" % def_file)
|
| 230 |
+
|
| 231 |
+
# Borland C++ has problems with '/' in paths
|
| 232 |
+
objects2 = map(os.path.normpath, objects)
|
| 233 |
+
# split objects in .obj and .res files
|
| 234 |
+
# Borland C++ needs them at different positions in the command line
|
| 235 |
+
objects = [startup_obj]
|
| 236 |
+
resources = []
|
| 237 |
+
for file in objects2:
|
| 238 |
+
(base, ext) = os.path.splitext(os.path.normcase(file))
|
| 239 |
+
if ext == '.res':
|
| 240 |
+
resources.append(file)
|
| 241 |
+
else:
|
| 242 |
+
objects.append(file)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
for l in library_dirs:
|
| 246 |
+
ld_args.append("/L%s" % os.path.normpath(l))
|
| 247 |
+
ld_args.append("/L.") # we sometimes use relative paths
|
| 248 |
+
|
| 249 |
+
# list of object files
|
| 250 |
+
ld_args.extend(objects)
|
| 251 |
+
|
| 252 |
+
# XXX the command-line syntax for Borland C++ is a bit wonky;
|
| 253 |
+
# certain filenames are jammed together in one big string, but
|
| 254 |
+
# comma-delimited. This doesn't mesh too well with the
|
| 255 |
+
# Unix-centric attitude (with a DOS/Windows quoting hack) of
|
| 256 |
+
# 'spawn()', so constructing the argument list is a bit
|
| 257 |
+
# awkward. Note that doing the obvious thing and jamming all
|
| 258 |
+
# the filenames and commas into one argument would be wrong,
|
| 259 |
+
# because 'spawn()' would quote any filenames with spaces in
|
| 260 |
+
# them. Arghghh!. Apparently it works fine as coded...
|
| 261 |
+
|
| 262 |
+
# name of dll/exe file
|
| 263 |
+
ld_args.extend([',',output_filename])
|
| 264 |
+
# no map file and start libraries
|
| 265 |
+
ld_args.append(',,')
|
| 266 |
+
|
| 267 |
+
for lib in libraries:
|
| 268 |
+
# see if we find it and if there is a bcpp specific lib
|
| 269 |
+
# (xxx_bcpp.lib)
|
| 270 |
+
libfile = self.find_library_file(library_dirs, lib, debug)
|
| 271 |
+
if libfile is None:
|
| 272 |
+
ld_args.append(lib)
|
| 273 |
+
# probably a BCPP internal library -- don't warn
|
| 274 |
+
else:
|
| 275 |
+
# full name which prefers bcpp_xxx.lib over xxx.lib
|
| 276 |
+
ld_args.append(libfile)
|
| 277 |
+
|
| 278 |
+
# some default libraries
|
| 279 |
+
ld_args.append ('import32')
|
| 280 |
+
ld_args.append ('cw32mt')
|
| 281 |
+
|
| 282 |
+
# def file for export symbols
|
| 283 |
+
ld_args.extend([',',def_file])
|
| 284 |
+
# add resource files
|
| 285 |
+
ld_args.append(',')
|
| 286 |
+
ld_args.extend(resources)
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
if extra_preargs:
|
| 290 |
+
ld_args[:0] = extra_preargs
|
| 291 |
+
if extra_postargs:
|
| 292 |
+
ld_args.extend(extra_postargs)
|
| 293 |
+
|
| 294 |
+
self.mkpath (os.path.dirname (output_filename))
|
| 295 |
+
try:
|
| 296 |
+
self.spawn ([self.linker] + ld_args)
|
| 297 |
+
except DistutilsExecError as msg:
|
| 298 |
+
raise LinkError(msg)
|
| 299 |
+
|
| 300 |
+
else:
|
| 301 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 302 |
+
|
| 303 |
+
# link ()
|
| 304 |
+
|
| 305 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def find_library_file (self, dirs, lib, debug=0):
|
| 309 |
+
# List of effective library names to try, in order of preference:
|
| 310 |
+
# xxx_bcpp.lib is better than xxx.lib
|
| 311 |
+
# and xxx_d.lib is better than xxx.lib if debug is set
|
| 312 |
+
#
|
| 313 |
+
# The "_bcpp" suffix is to handle a Python installation for people
|
| 314 |
+
# with multiple compilers (primarily Distutils hackers, I suspect
|
| 315 |
+
# ;-). The idea is they'd have one static library for each
|
| 316 |
+
# compiler they care about, since (almost?) every Windows compiler
|
| 317 |
+
# seems to have a different format for static libraries.
|
| 318 |
+
if debug:
|
| 319 |
+
dlib = (lib + "_d")
|
| 320 |
+
try_names = (dlib + "_bcpp", lib + "_bcpp", dlib, lib)
|
| 321 |
+
else:
|
| 322 |
+
try_names = (lib + "_bcpp", lib)
|
| 323 |
+
|
| 324 |
+
for dir in dirs:
|
| 325 |
+
for name in try_names:
|
| 326 |
+
libfile = os.path.join(dir, self.library_filename(name))
|
| 327 |
+
if os.path.exists(libfile):
|
| 328 |
+
return libfile
|
| 329 |
+
else:
|
| 330 |
+
# Oops, didn't find it in *any* of 'dirs'
|
| 331 |
+
return None
|
| 332 |
+
|
| 333 |
+
# overwrite the one from CCompiler to support rc and res-files
|
| 334 |
+
def object_filenames (self,
|
| 335 |
+
source_filenames,
|
| 336 |
+
strip_dir=0,
|
| 337 |
+
output_dir=''):
|
| 338 |
+
if output_dir is None: output_dir = ''
|
| 339 |
+
obj_names = []
|
| 340 |
+
for src_name in source_filenames:
|
| 341 |
+
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
|
| 342 |
+
(base, ext) = os.path.splitext (os.path.normcase(src_name))
|
| 343 |
+
if ext not in (self.src_extensions + ['.rc','.res']):
|
| 344 |
+
raise UnknownFileError("unknown file type '%s' (from '%s')" % \
|
| 345 |
+
(ext, src_name))
|
| 346 |
+
if strip_dir:
|
| 347 |
+
base = os.path.basename (base)
|
| 348 |
+
if ext == '.res':
|
| 349 |
+
# these can go unchanged
|
| 350 |
+
obj_names.append (os.path.join (output_dir, base + ext))
|
| 351 |
+
elif ext == '.rc':
|
| 352 |
+
# these need to be compiled to .res-files
|
| 353 |
+
obj_names.append (os.path.join (output_dir, base + '.res'))
|
| 354 |
+
else:
|
| 355 |
+
obj_names.append (os.path.join (output_dir,
|
| 356 |
+
base + self.obj_extension))
|
| 357 |
+
return obj_names
|
| 358 |
+
|
| 359 |
+
# object_filenames ()
|
| 360 |
+
|
| 361 |
+
def preprocess (self,
|
| 362 |
+
source,
|
| 363 |
+
output_file=None,
|
| 364 |
+
macros=None,
|
| 365 |
+
include_dirs=None,
|
| 366 |
+
extra_preargs=None,
|
| 367 |
+
extra_postargs=None):
|
| 368 |
+
|
| 369 |
+
(_, macros, include_dirs) = \
|
| 370 |
+
self._fix_compile_args(None, macros, include_dirs)
|
| 371 |
+
pp_opts = gen_preprocess_options(macros, include_dirs)
|
| 372 |
+
pp_args = ['cpp32.exe'] + pp_opts
|
| 373 |
+
if output_file is not None:
|
| 374 |
+
pp_args.append('-o' + output_file)
|
| 375 |
+
if extra_preargs:
|
| 376 |
+
pp_args[:0] = extra_preargs
|
| 377 |
+
if extra_postargs:
|
| 378 |
+
pp_args.extend(extra_postargs)
|
| 379 |
+
pp_args.append(source)
|
| 380 |
+
|
| 381 |
+
# We need to preprocess: either we're being forced to, or the
|
| 382 |
+
# source file is newer than the target (or the target doesn't
|
| 383 |
+
# exist).
|
| 384 |
+
if self.force or output_file is None or newer(source, output_file):
|
| 385 |
+
if output_file:
|
| 386 |
+
self.mkpath(os.path.dirname(output_file))
|
| 387 |
+
try:
|
| 388 |
+
self.spawn(pp_args)
|
| 389 |
+
except DistutilsExecError as msg:
|
| 390 |
+
print(msg)
|
| 391 |
+
raise CompileError(msg)
|
| 392 |
+
|
| 393 |
+
# preprocess()
|
data/conda_envs/evalclaw/lib/python3.11/distutils/ccompiler.py
ADDED
|
@@ -0,0 +1,1116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.ccompiler
|
| 2 |
+
|
| 3 |
+
Contains CCompiler, an abstract base class that defines the interface
|
| 4 |
+
for the Distutils compiler abstraction model."""
|
| 5 |
+
|
| 6 |
+
import sys, os, re
|
| 7 |
+
from distutils.errors import *
|
| 8 |
+
from distutils.spawn import spawn
|
| 9 |
+
from distutils.file_util import move_file
|
| 10 |
+
from distutils.dir_util import mkpath
|
| 11 |
+
from distutils.dep_util import newer_group
|
| 12 |
+
from distutils.util import split_quoted, execute
|
| 13 |
+
from distutils import log
|
| 14 |
+
|
| 15 |
+
class CCompiler:
|
| 16 |
+
"""Abstract base class to define the interface that must be implemented
|
| 17 |
+
by real compiler classes. Also has some utility methods used by
|
| 18 |
+
several compiler classes.
|
| 19 |
+
|
| 20 |
+
The basic idea behind a compiler abstraction class is that each
|
| 21 |
+
instance can be used for all the compile/link steps in building a
|
| 22 |
+
single project. Thus, attributes common to all of those compile and
|
| 23 |
+
link steps -- include directories, macros to define, libraries to link
|
| 24 |
+
against, etc. -- are attributes of the compiler instance. To allow for
|
| 25 |
+
variability in how individual files are treated, most of those
|
| 26 |
+
attributes may be varied on a per-compilation or per-link basis.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
# 'compiler_type' is a class attribute that identifies this class. It
|
| 30 |
+
# keeps code that wants to know what kind of compiler it's dealing with
|
| 31 |
+
# from having to import all possible compiler classes just to do an
|
| 32 |
+
# 'isinstance'. In concrete CCompiler subclasses, 'compiler_type'
|
| 33 |
+
# should really, really be one of the keys of the 'compiler_class'
|
| 34 |
+
# dictionary (see below -- used by the 'new_compiler()' factory
|
| 35 |
+
# function) -- authors of new compiler interface classes are
|
| 36 |
+
# responsible for updating 'compiler_class'!
|
| 37 |
+
compiler_type = None
|
| 38 |
+
|
| 39 |
+
# XXX things not handled by this compiler abstraction model:
|
| 40 |
+
# * client can't provide additional options for a compiler,
|
| 41 |
+
# e.g. warning, optimization, debugging flags. Perhaps this
|
| 42 |
+
# should be the domain of concrete compiler abstraction classes
|
| 43 |
+
# (UnixCCompiler, MSVCCompiler, etc.) -- or perhaps the base
|
| 44 |
+
# class should have methods for the common ones.
|
| 45 |
+
# * can't completely override the include or library searchg
|
| 46 |
+
# path, ie. no "cc -I -Idir1 -Idir2" or "cc -L -Ldir1 -Ldir2".
|
| 47 |
+
# I'm not sure how widely supported this is even by Unix
|
| 48 |
+
# compilers, much less on other platforms. And I'm even less
|
| 49 |
+
# sure how useful it is; maybe for cross-compiling, but
|
| 50 |
+
# support for that is a ways off. (And anyways, cross
|
| 51 |
+
# compilers probably have a dedicated binary with the
|
| 52 |
+
# right paths compiled in. I hope.)
|
| 53 |
+
# * can't do really freaky things with the library list/library
|
| 54 |
+
# dirs, e.g. "-Ldir1 -lfoo -Ldir2 -lfoo" to link against
|
| 55 |
+
# different versions of libfoo.a in different locations. I
|
| 56 |
+
# think this is useless without the ability to null out the
|
| 57 |
+
# library search path anyways.
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# Subclasses that rely on the standard filename generation methods
|
| 61 |
+
# implemented below should override these; see the comment near
|
| 62 |
+
# those methods ('object_filenames()' et. al.) for details:
|
| 63 |
+
src_extensions = None # list of strings
|
| 64 |
+
obj_extension = None # string
|
| 65 |
+
static_lib_extension = None
|
| 66 |
+
shared_lib_extension = None # string
|
| 67 |
+
static_lib_format = None # format string
|
| 68 |
+
shared_lib_format = None # prob. same as static_lib_format
|
| 69 |
+
exe_extension = None # string
|
| 70 |
+
|
| 71 |
+
# Default language settings. language_map is used to detect a source
|
| 72 |
+
# file or Extension target language, checking source filenames.
|
| 73 |
+
# language_order is used to detect the language precedence, when deciding
|
| 74 |
+
# what language to use when mixing source types. For example, if some
|
| 75 |
+
# extension has two files with ".c" extension, and one with ".cpp", it
|
| 76 |
+
# is still linked as c++.
|
| 77 |
+
language_map = {".c" : "c",
|
| 78 |
+
".cc" : "c++",
|
| 79 |
+
".cpp" : "c++",
|
| 80 |
+
".cxx" : "c++",
|
| 81 |
+
".m" : "objc",
|
| 82 |
+
}
|
| 83 |
+
language_order = ["c++", "objc", "c"]
|
| 84 |
+
|
| 85 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
| 86 |
+
self.dry_run = dry_run
|
| 87 |
+
self.force = force
|
| 88 |
+
self.verbose = verbose
|
| 89 |
+
|
| 90 |
+
# 'output_dir': a common output directory for object, library,
|
| 91 |
+
# shared object, and shared library files
|
| 92 |
+
self.output_dir = None
|
| 93 |
+
|
| 94 |
+
# 'macros': a list of macro definitions (or undefinitions). A
|
| 95 |
+
# macro definition is a 2-tuple (name, value), where the value is
|
| 96 |
+
# either a string or None (no explicit value). A macro
|
| 97 |
+
# undefinition is a 1-tuple (name,).
|
| 98 |
+
self.macros = []
|
| 99 |
+
|
| 100 |
+
# 'include_dirs': a list of directories to search for include files
|
| 101 |
+
self.include_dirs = []
|
| 102 |
+
|
| 103 |
+
# 'libraries': a list of libraries to include in any link
|
| 104 |
+
# (library names, not filenames: eg. "foo" not "libfoo.a")
|
| 105 |
+
self.libraries = []
|
| 106 |
+
|
| 107 |
+
# 'library_dirs': a list of directories to search for libraries
|
| 108 |
+
self.library_dirs = []
|
| 109 |
+
|
| 110 |
+
# 'runtime_library_dirs': a list of directories to search for
|
| 111 |
+
# shared libraries/objects at runtime
|
| 112 |
+
self.runtime_library_dirs = []
|
| 113 |
+
|
| 114 |
+
# 'objects': a list of object files (or similar, such as explicitly
|
| 115 |
+
# named library files) to include on any link
|
| 116 |
+
self.objects = []
|
| 117 |
+
|
| 118 |
+
for key in self.executables.keys():
|
| 119 |
+
self.set_executable(key, self.executables[key])
|
| 120 |
+
|
| 121 |
+
def set_executables(self, **kwargs):
|
| 122 |
+
"""Define the executables (and options for them) that will be run
|
| 123 |
+
to perform the various stages of compilation. The exact set of
|
| 124 |
+
executables that may be specified here depends on the compiler
|
| 125 |
+
class (via the 'executables' class attribute), but most will have:
|
| 126 |
+
compiler the C/C++ compiler
|
| 127 |
+
linker_so linker used to create shared objects and libraries
|
| 128 |
+
linker_exe linker used to create binary executables
|
| 129 |
+
archiver static library creator
|
| 130 |
+
|
| 131 |
+
On platforms with a command-line (Unix, DOS/Windows), each of these
|
| 132 |
+
is a string that will be split into executable name and (optional)
|
| 133 |
+
list of arguments. (Splitting the string is done similarly to how
|
| 134 |
+
Unix shells operate: words are delimited by spaces, but quotes and
|
| 135 |
+
backslashes can override this. See
|
| 136 |
+
'distutils.util.split_quoted()'.)
|
| 137 |
+
"""
|
| 138 |
+
|
| 139 |
+
# Note that some CCompiler implementation classes will define class
|
| 140 |
+
# attributes 'cpp', 'cc', etc. with hard-coded executable names;
|
| 141 |
+
# this is appropriate when a compiler class is for exactly one
|
| 142 |
+
# compiler/OS combination (eg. MSVCCompiler). Other compiler
|
| 143 |
+
# classes (UnixCCompiler, in particular) are driven by information
|
| 144 |
+
# discovered at run-time, since there are many different ways to do
|
| 145 |
+
# basically the same things with Unix C compilers.
|
| 146 |
+
|
| 147 |
+
for key in kwargs:
|
| 148 |
+
if key not in self.executables:
|
| 149 |
+
raise ValueError("unknown executable '%s' for class %s" %
|
| 150 |
+
(key, self.__class__.__name__))
|
| 151 |
+
self.set_executable(key, kwargs[key])
|
| 152 |
+
|
| 153 |
+
def set_executable(self, key, value):
|
| 154 |
+
if isinstance(value, str):
|
| 155 |
+
setattr(self, key, split_quoted(value))
|
| 156 |
+
else:
|
| 157 |
+
setattr(self, key, value)
|
| 158 |
+
|
| 159 |
+
def _find_macro(self, name):
|
| 160 |
+
i = 0
|
| 161 |
+
for defn in self.macros:
|
| 162 |
+
if defn[0] == name:
|
| 163 |
+
return i
|
| 164 |
+
i += 1
|
| 165 |
+
return None
|
| 166 |
+
|
| 167 |
+
def _check_macro_definitions(self, definitions):
|
| 168 |
+
"""Ensures that every element of 'definitions' is a valid macro
|
| 169 |
+
definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do
|
| 170 |
+
nothing if all definitions are OK, raise TypeError otherwise.
|
| 171 |
+
"""
|
| 172 |
+
for defn in definitions:
|
| 173 |
+
if not (isinstance(defn, tuple) and
|
| 174 |
+
(len(defn) in (1, 2) and
|
| 175 |
+
(isinstance (defn[1], str) or defn[1] is None)) and
|
| 176 |
+
isinstance (defn[0], str)):
|
| 177 |
+
raise TypeError(("invalid macro definition '%s': " % defn) + \
|
| 178 |
+
"must be tuple (string,), (string, string), or " + \
|
| 179 |
+
"(string, None)")
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
# -- Bookkeeping methods -------------------------------------------
|
| 183 |
+
|
| 184 |
+
def define_macro(self, name, value=None):
|
| 185 |
+
"""Define a preprocessor macro for all compilations driven by this
|
| 186 |
+
compiler object. The optional parameter 'value' should be a
|
| 187 |
+
string; if it is not supplied, then the macro will be defined
|
| 188 |
+
without an explicit value and the exact outcome depends on the
|
| 189 |
+
compiler used (XXX true? does ANSI say anything about this?)
|
| 190 |
+
"""
|
| 191 |
+
# Delete from the list of macro definitions/undefinitions if
|
| 192 |
+
# already there (so that this one will take precedence).
|
| 193 |
+
i = self._find_macro (name)
|
| 194 |
+
if i is not None:
|
| 195 |
+
del self.macros[i]
|
| 196 |
+
|
| 197 |
+
self.macros.append((name, value))
|
| 198 |
+
|
| 199 |
+
def undefine_macro(self, name):
|
| 200 |
+
"""Undefine a preprocessor macro for all compilations driven by
|
| 201 |
+
this compiler object. If the same macro is defined by
|
| 202 |
+
'define_macro()' and undefined by 'undefine_macro()' the last call
|
| 203 |
+
takes precedence (including multiple redefinitions or
|
| 204 |
+
undefinitions). If the macro is redefined/undefined on a
|
| 205 |
+
per-compilation basis (ie. in the call to 'compile()'), then that
|
| 206 |
+
takes precedence.
|
| 207 |
+
"""
|
| 208 |
+
# Delete from the list of macro definitions/undefinitions if
|
| 209 |
+
# already there (so that this one will take precedence).
|
| 210 |
+
i = self._find_macro (name)
|
| 211 |
+
if i is not None:
|
| 212 |
+
del self.macros[i]
|
| 213 |
+
|
| 214 |
+
undefn = (name,)
|
| 215 |
+
self.macros.append(undefn)
|
| 216 |
+
|
| 217 |
+
def add_include_dir(self, dir):
|
| 218 |
+
"""Add 'dir' to the list of directories that will be searched for
|
| 219 |
+
header files. The compiler is instructed to search directories in
|
| 220 |
+
the order in which they are supplied by successive calls to
|
| 221 |
+
'add_include_dir()'.
|
| 222 |
+
"""
|
| 223 |
+
self.include_dirs.append(dir)
|
| 224 |
+
|
| 225 |
+
def set_include_dirs(self, dirs):
|
| 226 |
+
"""Set the list of directories that will be searched to 'dirs' (a
|
| 227 |
+
list of strings). Overrides any preceding calls to
|
| 228 |
+
'add_include_dir()'; subsequence calls to 'add_include_dir()' add
|
| 229 |
+
to the list passed to 'set_include_dirs()'. This does not affect
|
| 230 |
+
any list of standard include directories that the compiler may
|
| 231 |
+
search by default.
|
| 232 |
+
"""
|
| 233 |
+
self.include_dirs = dirs[:]
|
| 234 |
+
|
| 235 |
+
def add_library(self, libname):
|
| 236 |
+
"""Add 'libname' to the list of libraries that will be included in
|
| 237 |
+
all links driven by this compiler object. Note that 'libname'
|
| 238 |
+
should *not* be the name of a file containing a library, but the
|
| 239 |
+
name of the library itself: the actual filename will be inferred by
|
| 240 |
+
the linker, the compiler, or the compiler class (depending on the
|
| 241 |
+
platform).
|
| 242 |
+
|
| 243 |
+
The linker will be instructed to link against libraries in the
|
| 244 |
+
order they were supplied to 'add_library()' and/or
|
| 245 |
+
'set_libraries()'. It is perfectly valid to duplicate library
|
| 246 |
+
names; the linker will be instructed to link against libraries as
|
| 247 |
+
many times as they are mentioned.
|
| 248 |
+
"""
|
| 249 |
+
self.libraries.append(libname)
|
| 250 |
+
|
| 251 |
+
def set_libraries(self, libnames):
|
| 252 |
+
"""Set the list of libraries to be included in all links driven by
|
| 253 |
+
this compiler object to 'libnames' (a list of strings). This does
|
| 254 |
+
not affect any standard system libraries that the linker may
|
| 255 |
+
include by default.
|
| 256 |
+
"""
|
| 257 |
+
self.libraries = libnames[:]
|
| 258 |
+
|
| 259 |
+
def add_library_dir(self, dir):
|
| 260 |
+
"""Add 'dir' to the list of directories that will be searched for
|
| 261 |
+
libraries specified to 'add_library()' and 'set_libraries()'. The
|
| 262 |
+
linker will be instructed to search for libraries in the order they
|
| 263 |
+
are supplied to 'add_library_dir()' and/or 'set_library_dirs()'.
|
| 264 |
+
"""
|
| 265 |
+
self.library_dirs.append(dir)
|
| 266 |
+
|
| 267 |
+
def set_library_dirs(self, dirs):
|
| 268 |
+
"""Set the list of library search directories to 'dirs' (a list of
|
| 269 |
+
strings). This does not affect any standard library search path
|
| 270 |
+
that the linker may search by default.
|
| 271 |
+
"""
|
| 272 |
+
self.library_dirs = dirs[:]
|
| 273 |
+
|
| 274 |
+
def add_runtime_library_dir(self, dir):
|
| 275 |
+
"""Add 'dir' to the list of directories that will be searched for
|
| 276 |
+
shared libraries at runtime.
|
| 277 |
+
"""
|
| 278 |
+
self.runtime_library_dirs.append(dir)
|
| 279 |
+
|
| 280 |
+
def set_runtime_library_dirs(self, dirs):
|
| 281 |
+
"""Set the list of directories to search for shared libraries at
|
| 282 |
+
runtime to 'dirs' (a list of strings). This does not affect any
|
| 283 |
+
standard search path that the runtime linker may search by
|
| 284 |
+
default.
|
| 285 |
+
"""
|
| 286 |
+
self.runtime_library_dirs = dirs[:]
|
| 287 |
+
|
| 288 |
+
def add_link_object(self, object):
|
| 289 |
+
"""Add 'object' to the list of object files (or analogues, such as
|
| 290 |
+
explicitly named library files or the output of "resource
|
| 291 |
+
compilers") to be included in every link driven by this compiler
|
| 292 |
+
object.
|
| 293 |
+
"""
|
| 294 |
+
self.objects.append(object)
|
| 295 |
+
|
| 296 |
+
def set_link_objects(self, objects):
|
| 297 |
+
"""Set the list of object files (or analogues) to be included in
|
| 298 |
+
every link to 'objects'. This does not affect any standard object
|
| 299 |
+
files that the linker may include by default (such as system
|
| 300 |
+
libraries).
|
| 301 |
+
"""
|
| 302 |
+
self.objects = objects[:]
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
# -- Private utility methods --------------------------------------
|
| 306 |
+
# (here for the convenience of subclasses)
|
| 307 |
+
|
| 308 |
+
# Helper method to prep compiler in subclass compile() methods
|
| 309 |
+
|
| 310 |
+
def _setup_compile(self, outdir, macros, incdirs, sources, depends,
|
| 311 |
+
extra):
|
| 312 |
+
"""Process arguments and decide which source files to compile."""
|
| 313 |
+
if outdir is None:
|
| 314 |
+
outdir = self.output_dir
|
| 315 |
+
elif not isinstance(outdir, str):
|
| 316 |
+
raise TypeError("'output_dir' must be a string or None")
|
| 317 |
+
|
| 318 |
+
if macros is None:
|
| 319 |
+
macros = self.macros
|
| 320 |
+
elif isinstance(macros, list):
|
| 321 |
+
macros = macros + (self.macros or [])
|
| 322 |
+
else:
|
| 323 |
+
raise TypeError("'macros' (if supplied) must be a list of tuples")
|
| 324 |
+
|
| 325 |
+
if incdirs is None:
|
| 326 |
+
incdirs = self.include_dirs
|
| 327 |
+
elif isinstance(incdirs, (list, tuple)):
|
| 328 |
+
incdirs = list(incdirs) + (self.include_dirs or [])
|
| 329 |
+
else:
|
| 330 |
+
raise TypeError(
|
| 331 |
+
"'include_dirs' (if supplied) must be a list of strings")
|
| 332 |
+
|
| 333 |
+
if extra is None:
|
| 334 |
+
extra = []
|
| 335 |
+
|
| 336 |
+
# Get the list of expected output (object) files
|
| 337 |
+
objects = self.object_filenames(sources, strip_dir=0,
|
| 338 |
+
output_dir=outdir)
|
| 339 |
+
assert len(objects) == len(sources)
|
| 340 |
+
|
| 341 |
+
pp_opts = gen_preprocess_options(macros, incdirs)
|
| 342 |
+
|
| 343 |
+
build = {}
|
| 344 |
+
for i in range(len(sources)):
|
| 345 |
+
src = sources[i]
|
| 346 |
+
obj = objects[i]
|
| 347 |
+
ext = os.path.splitext(src)[1]
|
| 348 |
+
self.mkpath(os.path.dirname(obj))
|
| 349 |
+
build[obj] = (src, ext)
|
| 350 |
+
|
| 351 |
+
return macros, objects, extra, pp_opts, build
|
| 352 |
+
|
| 353 |
+
def _get_cc_args(self, pp_opts, debug, before):
|
| 354 |
+
# works for unixccompiler, cygwinccompiler
|
| 355 |
+
cc_args = pp_opts + ['-c']
|
| 356 |
+
if debug:
|
| 357 |
+
cc_args[:0] = ['-g']
|
| 358 |
+
if before:
|
| 359 |
+
cc_args[:0] = before
|
| 360 |
+
return cc_args
|
| 361 |
+
|
| 362 |
+
def _fix_compile_args(self, output_dir, macros, include_dirs):
|
| 363 |
+
"""Typecheck and fix-up some of the arguments to the 'compile()'
|
| 364 |
+
method, and return fixed-up values. Specifically: if 'output_dir'
|
| 365 |
+
is None, replaces it with 'self.output_dir'; ensures that 'macros'
|
| 366 |
+
is a list, and augments it with 'self.macros'; ensures that
|
| 367 |
+
'include_dirs' is a list, and augments it with 'self.include_dirs'.
|
| 368 |
+
Guarantees that the returned values are of the correct type,
|
| 369 |
+
i.e. for 'output_dir' either string or None, and for 'macros' and
|
| 370 |
+
'include_dirs' either list or None.
|
| 371 |
+
"""
|
| 372 |
+
if output_dir is None:
|
| 373 |
+
output_dir = self.output_dir
|
| 374 |
+
elif not isinstance(output_dir, str):
|
| 375 |
+
raise TypeError("'output_dir' must be a string or None")
|
| 376 |
+
|
| 377 |
+
if macros is None:
|
| 378 |
+
macros = self.macros
|
| 379 |
+
elif isinstance(macros, list):
|
| 380 |
+
macros = macros + (self.macros or [])
|
| 381 |
+
else:
|
| 382 |
+
raise TypeError("'macros' (if supplied) must be a list of tuples")
|
| 383 |
+
|
| 384 |
+
if include_dirs is None:
|
| 385 |
+
include_dirs = self.include_dirs
|
| 386 |
+
elif isinstance(include_dirs, (list, tuple)):
|
| 387 |
+
include_dirs = list(include_dirs) + (self.include_dirs or [])
|
| 388 |
+
else:
|
| 389 |
+
raise TypeError(
|
| 390 |
+
"'include_dirs' (if supplied) must be a list of strings")
|
| 391 |
+
|
| 392 |
+
return output_dir, macros, include_dirs
|
| 393 |
+
|
| 394 |
+
def _prep_compile(self, sources, output_dir, depends=None):
|
| 395 |
+
"""Decide which source files must be recompiled.
|
| 396 |
+
|
| 397 |
+
Determine the list of object files corresponding to 'sources',
|
| 398 |
+
and figure out which ones really need to be recompiled.
|
| 399 |
+
Return a list of all object files and a dictionary telling
|
| 400 |
+
which source files can be skipped.
|
| 401 |
+
"""
|
| 402 |
+
# Get the list of expected output (object) files
|
| 403 |
+
objects = self.object_filenames(sources, output_dir=output_dir)
|
| 404 |
+
assert len(objects) == len(sources)
|
| 405 |
+
|
| 406 |
+
# Return an empty dict for the "which source files can be skipped"
|
| 407 |
+
# return value to preserve API compatibility.
|
| 408 |
+
return objects, {}
|
| 409 |
+
|
| 410 |
+
def _fix_object_args(self, objects, output_dir):
|
| 411 |
+
"""Typecheck and fix up some arguments supplied to various methods.
|
| 412 |
+
Specifically: ensure that 'objects' is a list; if output_dir is
|
| 413 |
+
None, replace with self.output_dir. Return fixed versions of
|
| 414 |
+
'objects' and 'output_dir'.
|
| 415 |
+
"""
|
| 416 |
+
if not isinstance(objects, (list, tuple)):
|
| 417 |
+
raise TypeError("'objects' must be a list or tuple of strings")
|
| 418 |
+
objects = list(objects)
|
| 419 |
+
|
| 420 |
+
if output_dir is None:
|
| 421 |
+
output_dir = self.output_dir
|
| 422 |
+
elif not isinstance(output_dir, str):
|
| 423 |
+
raise TypeError("'output_dir' must be a string or None")
|
| 424 |
+
|
| 425 |
+
return (objects, output_dir)
|
| 426 |
+
|
| 427 |
+
def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs):
|
| 428 |
+
"""Typecheck and fix up some of the arguments supplied to the
|
| 429 |
+
'link_*' methods. Specifically: ensure that all arguments are
|
| 430 |
+
lists, and augment them with their permanent versions
|
| 431 |
+
(eg. 'self.libraries' augments 'libraries'). Return a tuple with
|
| 432 |
+
fixed versions of all arguments.
|
| 433 |
+
"""
|
| 434 |
+
if libraries is None:
|
| 435 |
+
libraries = self.libraries
|
| 436 |
+
elif isinstance(libraries, (list, tuple)):
|
| 437 |
+
libraries = list (libraries) + (self.libraries or [])
|
| 438 |
+
else:
|
| 439 |
+
raise TypeError(
|
| 440 |
+
"'libraries' (if supplied) must be a list of strings")
|
| 441 |
+
|
| 442 |
+
if library_dirs is None:
|
| 443 |
+
library_dirs = self.library_dirs
|
| 444 |
+
elif isinstance(library_dirs, (list, tuple)):
|
| 445 |
+
library_dirs = list (library_dirs) + (self.library_dirs or [])
|
| 446 |
+
else:
|
| 447 |
+
raise TypeError(
|
| 448 |
+
"'library_dirs' (if supplied) must be a list of strings")
|
| 449 |
+
|
| 450 |
+
if runtime_library_dirs is None:
|
| 451 |
+
runtime_library_dirs = self.runtime_library_dirs
|
| 452 |
+
elif isinstance(runtime_library_dirs, (list, tuple)):
|
| 453 |
+
runtime_library_dirs = (list(runtime_library_dirs) +
|
| 454 |
+
(self.runtime_library_dirs or []))
|
| 455 |
+
else:
|
| 456 |
+
raise TypeError("'runtime_library_dirs' (if supplied) "
|
| 457 |
+
"must be a list of strings")
|
| 458 |
+
|
| 459 |
+
return (libraries, library_dirs, runtime_library_dirs)
|
| 460 |
+
|
| 461 |
+
def _need_link(self, objects, output_file):
|
| 462 |
+
"""Return true if we need to relink the files listed in 'objects'
|
| 463 |
+
to recreate 'output_file'.
|
| 464 |
+
"""
|
| 465 |
+
if self.force:
|
| 466 |
+
return True
|
| 467 |
+
else:
|
| 468 |
+
if self.dry_run:
|
| 469 |
+
newer = newer_group (objects, output_file, missing='newer')
|
| 470 |
+
else:
|
| 471 |
+
newer = newer_group (objects, output_file)
|
| 472 |
+
return newer
|
| 473 |
+
|
| 474 |
+
def detect_language(self, sources):
|
| 475 |
+
"""Detect the language of a given file, or list of files. Uses
|
| 476 |
+
language_map, and language_order to do the job.
|
| 477 |
+
"""
|
| 478 |
+
if not isinstance(sources, list):
|
| 479 |
+
sources = [sources]
|
| 480 |
+
lang = None
|
| 481 |
+
index = len(self.language_order)
|
| 482 |
+
for source in sources:
|
| 483 |
+
base, ext = os.path.splitext(source)
|
| 484 |
+
extlang = self.language_map.get(ext)
|
| 485 |
+
try:
|
| 486 |
+
extindex = self.language_order.index(extlang)
|
| 487 |
+
if extindex < index:
|
| 488 |
+
lang = extlang
|
| 489 |
+
index = extindex
|
| 490 |
+
except ValueError:
|
| 491 |
+
pass
|
| 492 |
+
return lang
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
# -- Worker methods ------------------------------------------------
|
| 496 |
+
# (must be implemented by subclasses)
|
| 497 |
+
|
| 498 |
+
def preprocess(self, source, output_file=None, macros=None,
|
| 499 |
+
include_dirs=None, extra_preargs=None, extra_postargs=None):
|
| 500 |
+
"""Preprocess a single C/C++ source file, named in 'source'.
|
| 501 |
+
Output will be written to file named 'output_file', or stdout if
|
| 502 |
+
'output_file' not supplied. 'macros' is a list of macro
|
| 503 |
+
definitions as for 'compile()', which will augment the macros set
|
| 504 |
+
with 'define_macro()' and 'undefine_macro()'. 'include_dirs' is a
|
| 505 |
+
list of directory names that will be added to the default list.
|
| 506 |
+
|
| 507 |
+
Raises PreprocessError on failure.
|
| 508 |
+
"""
|
| 509 |
+
pass
|
| 510 |
+
|
| 511 |
+
def compile(self, sources, output_dir=None, macros=None,
|
| 512 |
+
include_dirs=None, debug=0, extra_preargs=None,
|
| 513 |
+
extra_postargs=None, depends=None):
|
| 514 |
+
"""Compile one or more source files.
|
| 515 |
+
|
| 516 |
+
'sources' must be a list of filenames, most likely C/C++
|
| 517 |
+
files, but in reality anything that can be handled by a
|
| 518 |
+
particular compiler and compiler class (eg. MSVCCompiler can
|
| 519 |
+
handle resource files in 'sources'). Return a list of object
|
| 520 |
+
filenames, one per source filename in 'sources'. Depending on
|
| 521 |
+
the implementation, not all source files will necessarily be
|
| 522 |
+
compiled, but all corresponding object filenames will be
|
| 523 |
+
returned.
|
| 524 |
+
|
| 525 |
+
If 'output_dir' is given, object files will be put under it, while
|
| 526 |
+
retaining their original path component. That is, "foo/bar.c"
|
| 527 |
+
normally compiles to "foo/bar.o" (for a Unix implementation); if
|
| 528 |
+
'output_dir' is "build", then it would compile to
|
| 529 |
+
"build/foo/bar.o".
|
| 530 |
+
|
| 531 |
+
'macros', if given, must be a list of macro definitions. A macro
|
| 532 |
+
definition is either a (name, value) 2-tuple or a (name,) 1-tuple.
|
| 533 |
+
The former defines a macro; if the value is None, the macro is
|
| 534 |
+
defined without an explicit value. The 1-tuple case undefines a
|
| 535 |
+
macro. Later definitions/redefinitions/ undefinitions take
|
| 536 |
+
precedence.
|
| 537 |
+
|
| 538 |
+
'include_dirs', if given, must be a list of strings, the
|
| 539 |
+
directories to add to the default include file search path for this
|
| 540 |
+
compilation only.
|
| 541 |
+
|
| 542 |
+
'debug' is a boolean; if true, the compiler will be instructed to
|
| 543 |
+
output debug symbols in (or alongside) the object file(s).
|
| 544 |
+
|
| 545 |
+
'extra_preargs' and 'extra_postargs' are implementation- dependent.
|
| 546 |
+
On platforms that have the notion of a command-line (e.g. Unix,
|
| 547 |
+
DOS/Windows), they are most likely lists of strings: extra
|
| 548 |
+
command-line arguments to prepend/append to the compiler command
|
| 549 |
+
line. On other platforms, consult the implementation class
|
| 550 |
+
documentation. In any event, they are intended as an escape hatch
|
| 551 |
+
for those occasions when the abstract compiler framework doesn't
|
| 552 |
+
cut the mustard.
|
| 553 |
+
|
| 554 |
+
'depends', if given, is a list of filenames that all targets
|
| 555 |
+
depend on. If a source file is older than any file in
|
| 556 |
+
depends, then the source file will be recompiled. This
|
| 557 |
+
supports dependency tracking, but only at a coarse
|
| 558 |
+
granularity.
|
| 559 |
+
|
| 560 |
+
Raises CompileError on failure.
|
| 561 |
+
"""
|
| 562 |
+
# A concrete compiler class can either override this method
|
| 563 |
+
# entirely or implement _compile().
|
| 564 |
+
macros, objects, extra_postargs, pp_opts, build = \
|
| 565 |
+
self._setup_compile(output_dir, macros, include_dirs, sources,
|
| 566 |
+
depends, extra_postargs)
|
| 567 |
+
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
|
| 568 |
+
|
| 569 |
+
for obj in objects:
|
| 570 |
+
try:
|
| 571 |
+
src, ext = build[obj]
|
| 572 |
+
except KeyError:
|
| 573 |
+
continue
|
| 574 |
+
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
|
| 575 |
+
|
| 576 |
+
# Return *all* object filenames, not just the ones we just built.
|
| 577 |
+
return objects
|
| 578 |
+
|
| 579 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
| 580 |
+
"""Compile 'src' to product 'obj'."""
|
| 581 |
+
# A concrete compiler class that does not override compile()
|
| 582 |
+
# should implement _compile().
|
| 583 |
+
pass
|
| 584 |
+
|
| 585 |
+
def create_static_lib(self, objects, output_libname, output_dir=None,
|
| 586 |
+
debug=0, target_lang=None):
|
| 587 |
+
"""Link a bunch of stuff together to create a static library file.
|
| 588 |
+
The "bunch of stuff" consists of the list of object files supplied
|
| 589 |
+
as 'objects', the extra object files supplied to
|
| 590 |
+
'add_link_object()' and/or 'set_link_objects()', the libraries
|
| 591 |
+
supplied to 'add_library()' and/or 'set_libraries()', and the
|
| 592 |
+
libraries supplied as 'libraries' (if any).
|
| 593 |
+
|
| 594 |
+
'output_libname' should be a library name, not a filename; the
|
| 595 |
+
filename will be inferred from the library name. 'output_dir' is
|
| 596 |
+
the directory where the library file will be put.
|
| 597 |
+
|
| 598 |
+
'debug' is a boolean; if true, debugging information will be
|
| 599 |
+
included in the library (note that on most platforms, it is the
|
| 600 |
+
compile step where this matters: the 'debug' flag is included here
|
| 601 |
+
just for consistency).
|
| 602 |
+
|
| 603 |
+
'target_lang' is the target language for which the given objects
|
| 604 |
+
are being compiled. This allows specific linkage time treatment of
|
| 605 |
+
certain languages.
|
| 606 |
+
|
| 607 |
+
Raises LibError on failure.
|
| 608 |
+
"""
|
| 609 |
+
pass
|
| 610 |
+
|
| 611 |
+
|
| 612 |
+
# values for target_desc parameter in link()
|
| 613 |
+
SHARED_OBJECT = "shared_object"
|
| 614 |
+
SHARED_LIBRARY = "shared_library"
|
| 615 |
+
EXECUTABLE = "executable"
|
| 616 |
+
|
| 617 |
+
def link(self,
|
| 618 |
+
target_desc,
|
| 619 |
+
objects,
|
| 620 |
+
output_filename,
|
| 621 |
+
output_dir=None,
|
| 622 |
+
libraries=None,
|
| 623 |
+
library_dirs=None,
|
| 624 |
+
runtime_library_dirs=None,
|
| 625 |
+
export_symbols=None,
|
| 626 |
+
debug=0,
|
| 627 |
+
extra_preargs=None,
|
| 628 |
+
extra_postargs=None,
|
| 629 |
+
build_temp=None,
|
| 630 |
+
target_lang=None):
|
| 631 |
+
"""Link a bunch of stuff together to create an executable or
|
| 632 |
+
shared library file.
|
| 633 |
+
|
| 634 |
+
The "bunch of stuff" consists of the list of object files supplied
|
| 635 |
+
as 'objects'. 'output_filename' should be a filename. If
|
| 636 |
+
'output_dir' is supplied, 'output_filename' is relative to it
|
| 637 |
+
(i.e. 'output_filename' can provide directory components if
|
| 638 |
+
needed).
|
| 639 |
+
|
| 640 |
+
'libraries' is a list of libraries to link against. These are
|
| 641 |
+
library names, not filenames, since they're translated into
|
| 642 |
+
filenames in a platform-specific way (eg. "foo" becomes "libfoo.a"
|
| 643 |
+
on Unix and "foo.lib" on DOS/Windows). However, they can include a
|
| 644 |
+
directory component, which means the linker will look in that
|
| 645 |
+
specific directory rather than searching all the normal locations.
|
| 646 |
+
|
| 647 |
+
'library_dirs', if supplied, should be a list of directories to
|
| 648 |
+
search for libraries that were specified as bare library names
|
| 649 |
+
(ie. no directory component). These are on top of the system
|
| 650 |
+
default and those supplied to 'add_library_dir()' and/or
|
| 651 |
+
'set_library_dirs()'. 'runtime_library_dirs' is a list of
|
| 652 |
+
directories that will be embedded into the shared library and used
|
| 653 |
+
to search for other shared libraries that *it* depends on at
|
| 654 |
+
run-time. (This may only be relevant on Unix.)
|
| 655 |
+
|
| 656 |
+
'export_symbols' is a list of symbols that the shared library will
|
| 657 |
+
export. (This appears to be relevant only on Windows.)
|
| 658 |
+
|
| 659 |
+
'debug' is as for 'compile()' and 'create_static_lib()', with the
|
| 660 |
+
slight distinction that it actually matters on most platforms (as
|
| 661 |
+
opposed to 'create_static_lib()', which includes a 'debug' flag
|
| 662 |
+
mostly for form's sake).
|
| 663 |
+
|
| 664 |
+
'extra_preargs' and 'extra_postargs' are as for 'compile()' (except
|
| 665 |
+
of course that they supply command-line arguments for the
|
| 666 |
+
particular linker being used).
|
| 667 |
+
|
| 668 |
+
'target_lang' is the target language for which the given objects
|
| 669 |
+
are being compiled. This allows specific linkage time treatment of
|
| 670 |
+
certain languages.
|
| 671 |
+
|
| 672 |
+
Raises LinkError on failure.
|
| 673 |
+
"""
|
| 674 |
+
raise NotImplementedError
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
# Old 'link_*()' methods, rewritten to use the new 'link()' method.
|
| 678 |
+
|
| 679 |
+
def link_shared_lib(self,
|
| 680 |
+
objects,
|
| 681 |
+
output_libname,
|
| 682 |
+
output_dir=None,
|
| 683 |
+
libraries=None,
|
| 684 |
+
library_dirs=None,
|
| 685 |
+
runtime_library_dirs=None,
|
| 686 |
+
export_symbols=None,
|
| 687 |
+
debug=0,
|
| 688 |
+
extra_preargs=None,
|
| 689 |
+
extra_postargs=None,
|
| 690 |
+
build_temp=None,
|
| 691 |
+
target_lang=None):
|
| 692 |
+
self.link(CCompiler.SHARED_LIBRARY, objects,
|
| 693 |
+
self.library_filename(output_libname, lib_type='shared'),
|
| 694 |
+
output_dir,
|
| 695 |
+
libraries, library_dirs, runtime_library_dirs,
|
| 696 |
+
export_symbols, debug,
|
| 697 |
+
extra_preargs, extra_postargs, build_temp, target_lang)
|
| 698 |
+
|
| 699 |
+
|
| 700 |
+
def link_shared_object(self,
|
| 701 |
+
objects,
|
| 702 |
+
output_filename,
|
| 703 |
+
output_dir=None,
|
| 704 |
+
libraries=None,
|
| 705 |
+
library_dirs=None,
|
| 706 |
+
runtime_library_dirs=None,
|
| 707 |
+
export_symbols=None,
|
| 708 |
+
debug=0,
|
| 709 |
+
extra_preargs=None,
|
| 710 |
+
extra_postargs=None,
|
| 711 |
+
build_temp=None,
|
| 712 |
+
target_lang=None):
|
| 713 |
+
self.link(CCompiler.SHARED_OBJECT, objects,
|
| 714 |
+
output_filename, output_dir,
|
| 715 |
+
libraries, library_dirs, runtime_library_dirs,
|
| 716 |
+
export_symbols, debug,
|
| 717 |
+
extra_preargs, extra_postargs, build_temp, target_lang)
|
| 718 |
+
|
| 719 |
+
|
| 720 |
+
def link_executable(self,
|
| 721 |
+
objects,
|
| 722 |
+
output_progname,
|
| 723 |
+
output_dir=None,
|
| 724 |
+
libraries=None,
|
| 725 |
+
library_dirs=None,
|
| 726 |
+
runtime_library_dirs=None,
|
| 727 |
+
debug=0,
|
| 728 |
+
extra_preargs=None,
|
| 729 |
+
extra_postargs=None,
|
| 730 |
+
target_lang=None):
|
| 731 |
+
self.link(CCompiler.EXECUTABLE, objects,
|
| 732 |
+
self.executable_filename(output_progname), output_dir,
|
| 733 |
+
libraries, library_dirs, runtime_library_dirs, None,
|
| 734 |
+
debug, extra_preargs, extra_postargs, None, target_lang)
|
| 735 |
+
|
| 736 |
+
|
| 737 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 738 |
+
# These are all used by the 'gen_lib_options() function; there is
|
| 739 |
+
# no appropriate default implementation so subclasses should
|
| 740 |
+
# implement all of these.
|
| 741 |
+
|
| 742 |
+
def library_dir_option(self, dir):
|
| 743 |
+
"""Return the compiler option to add 'dir' to the list of
|
| 744 |
+
directories searched for libraries.
|
| 745 |
+
"""
|
| 746 |
+
raise NotImplementedError
|
| 747 |
+
|
| 748 |
+
def runtime_library_dir_option(self, dir):
|
| 749 |
+
"""Return the compiler option to add 'dir' to the list of
|
| 750 |
+
directories searched for runtime libraries.
|
| 751 |
+
"""
|
| 752 |
+
raise NotImplementedError
|
| 753 |
+
|
| 754 |
+
def library_option(self, lib):
|
| 755 |
+
"""Return the compiler option to add 'lib' to the list of libraries
|
| 756 |
+
linked into the shared library or executable.
|
| 757 |
+
"""
|
| 758 |
+
raise NotImplementedError
|
| 759 |
+
|
| 760 |
+
def has_function(self, funcname, includes=None, include_dirs=None,
|
| 761 |
+
libraries=None, library_dirs=None):
|
| 762 |
+
"""Return a boolean indicating whether funcname is supported on
|
| 763 |
+
the current platform. The optional arguments can be used to
|
| 764 |
+
augment the compilation environment.
|
| 765 |
+
"""
|
| 766 |
+
# this can't be included at module scope because it tries to
|
| 767 |
+
# import math which might not be available at that point - maybe
|
| 768 |
+
# the necessary logic should just be inlined?
|
| 769 |
+
import tempfile
|
| 770 |
+
if includes is None:
|
| 771 |
+
includes = []
|
| 772 |
+
if include_dirs is None:
|
| 773 |
+
include_dirs = []
|
| 774 |
+
if libraries is None:
|
| 775 |
+
libraries = []
|
| 776 |
+
if library_dirs is None:
|
| 777 |
+
library_dirs = []
|
| 778 |
+
fd, fname = tempfile.mkstemp(".c", funcname, text=True)
|
| 779 |
+
f = os.fdopen(fd, "w")
|
| 780 |
+
try:
|
| 781 |
+
for incl in includes:
|
| 782 |
+
f.write("""#include "%s"\n""" % incl)
|
| 783 |
+
f.write("""\
|
| 784 |
+
int main (int argc, char **argv) {
|
| 785 |
+
%s();
|
| 786 |
+
return 0;
|
| 787 |
+
}
|
| 788 |
+
""" % funcname)
|
| 789 |
+
finally:
|
| 790 |
+
f.close()
|
| 791 |
+
try:
|
| 792 |
+
objects = self.compile([fname], include_dirs=include_dirs)
|
| 793 |
+
except CompileError:
|
| 794 |
+
return False
|
| 795 |
+
|
| 796 |
+
try:
|
| 797 |
+
self.link_executable(objects, "a.out",
|
| 798 |
+
libraries=libraries,
|
| 799 |
+
library_dirs=library_dirs)
|
| 800 |
+
except (LinkError, TypeError):
|
| 801 |
+
return False
|
| 802 |
+
return True
|
| 803 |
+
|
| 804 |
+
def find_library_file (self, dirs, lib, debug=0):
|
| 805 |
+
"""Search the specified list of directories for a static or shared
|
| 806 |
+
library file 'lib' and return the full path to that file. If
|
| 807 |
+
'debug' true, look for a debugging version (if that makes sense on
|
| 808 |
+
the current platform). Return None if 'lib' wasn't found in any of
|
| 809 |
+
the specified directories.
|
| 810 |
+
"""
|
| 811 |
+
raise NotImplementedError
|
| 812 |
+
|
| 813 |
+
# -- Filename generation methods -----------------------------------
|
| 814 |
+
|
| 815 |
+
# The default implementation of the filename generating methods are
|
| 816 |
+
# prejudiced towards the Unix/DOS/Windows view of the world:
|
| 817 |
+
# * object files are named by replacing the source file extension
|
| 818 |
+
# (eg. .c/.cpp -> .o/.obj)
|
| 819 |
+
# * library files (shared or static) are named by plugging the
|
| 820 |
+
# library name and extension into a format string, eg.
|
| 821 |
+
# "lib%s.%s" % (lib_name, ".a") for Unix static libraries
|
| 822 |
+
# * executables are named by appending an extension (possibly
|
| 823 |
+
# empty) to the program name: eg. progname + ".exe" for
|
| 824 |
+
# Windows
|
| 825 |
+
#
|
| 826 |
+
# To reduce redundant code, these methods expect to find
|
| 827 |
+
# several attributes in the current object (presumably defined
|
| 828 |
+
# as class attributes):
|
| 829 |
+
# * src_extensions -
|
| 830 |
+
# list of C/C++ source file extensions, eg. ['.c', '.cpp']
|
| 831 |
+
# * obj_extension -
|
| 832 |
+
# object file extension, eg. '.o' or '.obj'
|
| 833 |
+
# * static_lib_extension -
|
| 834 |
+
# extension for static library files, eg. '.a' or '.lib'
|
| 835 |
+
# * shared_lib_extension -
|
| 836 |
+
# extension for shared library/object files, eg. '.so', '.dll'
|
| 837 |
+
# * static_lib_format -
|
| 838 |
+
# format string for generating static library filenames,
|
| 839 |
+
# eg. 'lib%s.%s' or '%s.%s'
|
| 840 |
+
# * shared_lib_format
|
| 841 |
+
# format string for generating shared library filenames
|
| 842 |
+
# (probably same as static_lib_format, since the extension
|
| 843 |
+
# is one of the intended parameters to the format string)
|
| 844 |
+
# * exe_extension -
|
| 845 |
+
# extension for executable files, eg. '' or '.exe'
|
| 846 |
+
|
| 847 |
+
def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
|
| 848 |
+
if output_dir is None:
|
| 849 |
+
output_dir = ''
|
| 850 |
+
obj_names = []
|
| 851 |
+
for src_name in source_filenames:
|
| 852 |
+
base, ext = os.path.splitext(src_name)
|
| 853 |
+
base = os.path.splitdrive(base)[1] # Chop off the drive
|
| 854 |
+
base = base[os.path.isabs(base):] # If abs, chop off leading /
|
| 855 |
+
if ext not in self.src_extensions:
|
| 856 |
+
raise UnknownFileError(
|
| 857 |
+
"unknown file type '%s' (from '%s')" % (ext, src_name))
|
| 858 |
+
if strip_dir:
|
| 859 |
+
base = os.path.basename(base)
|
| 860 |
+
obj_names.append(os.path.join(output_dir,
|
| 861 |
+
base + self.obj_extension))
|
| 862 |
+
return obj_names
|
| 863 |
+
|
| 864 |
+
def shared_object_filename(self, basename, strip_dir=0, output_dir=''):
|
| 865 |
+
assert output_dir is not None
|
| 866 |
+
if strip_dir:
|
| 867 |
+
basename = os.path.basename(basename)
|
| 868 |
+
return os.path.join(output_dir, basename + self.shared_lib_extension)
|
| 869 |
+
|
| 870 |
+
def executable_filename(self, basename, strip_dir=0, output_dir=''):
|
| 871 |
+
assert output_dir is not None
|
| 872 |
+
if strip_dir:
|
| 873 |
+
basename = os.path.basename(basename)
|
| 874 |
+
return os.path.join(output_dir, basename + (self.exe_extension or ''))
|
| 875 |
+
|
| 876 |
+
def library_filename(self, libname, lib_type='static', # or 'shared'
|
| 877 |
+
strip_dir=0, output_dir=''):
|
| 878 |
+
assert output_dir is not None
|
| 879 |
+
if lib_type not in ("static", "shared", "dylib", "xcode_stub"):
|
| 880 |
+
raise ValueError(
|
| 881 |
+
"'lib_type' must be \"static\", \"shared\", \"dylib\", or \"xcode_stub\"")
|
| 882 |
+
fmt = getattr(self, lib_type + "_lib_format")
|
| 883 |
+
ext = getattr(self, lib_type + "_lib_extension")
|
| 884 |
+
|
| 885 |
+
dir, base = os.path.split(libname)
|
| 886 |
+
filename = fmt % (base, ext)
|
| 887 |
+
if strip_dir:
|
| 888 |
+
dir = ''
|
| 889 |
+
|
| 890 |
+
return os.path.join(output_dir, dir, filename)
|
| 891 |
+
|
| 892 |
+
|
| 893 |
+
# -- Utility methods -----------------------------------------------
|
| 894 |
+
|
| 895 |
+
def announce(self, msg, level=1):
|
| 896 |
+
log.debug(msg)
|
| 897 |
+
|
| 898 |
+
def debug_print(self, msg):
|
| 899 |
+
from distutils.debug import DEBUG
|
| 900 |
+
if DEBUG:
|
| 901 |
+
print(msg)
|
| 902 |
+
|
| 903 |
+
def warn(self, msg):
|
| 904 |
+
sys.stderr.write("warning: %s\n" % msg)
|
| 905 |
+
|
| 906 |
+
def execute(self, func, args, msg=None, level=1):
|
| 907 |
+
execute(func, args, msg, self.dry_run)
|
| 908 |
+
|
| 909 |
+
def spawn(self, cmd):
|
| 910 |
+
spawn(cmd, dry_run=self.dry_run)
|
| 911 |
+
|
| 912 |
+
def move_file(self, src, dst):
|
| 913 |
+
return move_file(src, dst, dry_run=self.dry_run)
|
| 914 |
+
|
| 915 |
+
def mkpath (self, name, mode=0o777):
|
| 916 |
+
mkpath(name, mode, dry_run=self.dry_run)
|
| 917 |
+
|
| 918 |
+
|
| 919 |
+
# Map a sys.platform/os.name ('posix', 'nt') to the default compiler
|
| 920 |
+
# type for that platform. Keys are interpreted as re match
|
| 921 |
+
# patterns. Order is important; platform mappings are preferred over
|
| 922 |
+
# OS names.
|
| 923 |
+
_default_compilers = (
|
| 924 |
+
|
| 925 |
+
# Platform string mappings
|
| 926 |
+
|
| 927 |
+
# on a cygwin built python we can use gcc like an ordinary UNIXish
|
| 928 |
+
# compiler
|
| 929 |
+
('cygwin.*', 'unix'),
|
| 930 |
+
|
| 931 |
+
# OS name mappings
|
| 932 |
+
('posix', 'unix'),
|
| 933 |
+
('nt', 'msvc'),
|
| 934 |
+
|
| 935 |
+
)
|
| 936 |
+
|
| 937 |
+
def get_default_compiler(osname=None, platform=None):
|
| 938 |
+
"""Determine the default compiler to use for the given platform.
|
| 939 |
+
|
| 940 |
+
osname should be one of the standard Python OS names (i.e. the
|
| 941 |
+
ones returned by os.name) and platform the common value
|
| 942 |
+
returned by sys.platform for the platform in question.
|
| 943 |
+
|
| 944 |
+
The default values are os.name and sys.platform in case the
|
| 945 |
+
parameters are not given.
|
| 946 |
+
"""
|
| 947 |
+
if osname is None:
|
| 948 |
+
osname = os.name
|
| 949 |
+
if platform is None:
|
| 950 |
+
platform = sys.platform
|
| 951 |
+
for pattern, compiler in _default_compilers:
|
| 952 |
+
if re.match(pattern, platform) is not None or \
|
| 953 |
+
re.match(pattern, osname) is not None:
|
| 954 |
+
return compiler
|
| 955 |
+
# Default to Unix compiler
|
| 956 |
+
return 'unix'
|
| 957 |
+
|
| 958 |
+
# Map compiler types to (module_name, class_name) pairs -- ie. where to
|
| 959 |
+
# find the code that implements an interface to this compiler. (The module
|
| 960 |
+
# is assumed to be in the 'distutils' package.)
|
| 961 |
+
compiler_class = { 'unix': ('unixccompiler', 'UnixCCompiler',
|
| 962 |
+
"standard UNIX-style compiler"),
|
| 963 |
+
'msvc': ('_msvccompiler', 'MSVCCompiler',
|
| 964 |
+
"Microsoft Visual C++"),
|
| 965 |
+
'cygwin': ('cygwinccompiler', 'CygwinCCompiler',
|
| 966 |
+
"Cygwin port of GNU C Compiler for Win32"),
|
| 967 |
+
'mingw32': ('cygwinccompiler', 'Mingw32CCompiler',
|
| 968 |
+
"Mingw32 port of GNU C Compiler for Win32"),
|
| 969 |
+
'bcpp': ('bcppcompiler', 'BCPPCompiler',
|
| 970 |
+
"Borland C++ Compiler"),
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
def show_compilers():
|
| 974 |
+
"""Print list of available compilers (used by the "--help-compiler"
|
| 975 |
+
options to "build", "build_ext", "build_clib").
|
| 976 |
+
"""
|
| 977 |
+
# XXX this "knows" that the compiler option it's describing is
|
| 978 |
+
# "--compiler", which just happens to be the case for the three
|
| 979 |
+
# commands that use it.
|
| 980 |
+
from distutils.fancy_getopt import FancyGetopt
|
| 981 |
+
compilers = []
|
| 982 |
+
for compiler in compiler_class.keys():
|
| 983 |
+
compilers.append(("compiler="+compiler, None,
|
| 984 |
+
compiler_class[compiler][2]))
|
| 985 |
+
compilers.sort()
|
| 986 |
+
pretty_printer = FancyGetopt(compilers)
|
| 987 |
+
pretty_printer.print_help("List of available compilers:")
|
| 988 |
+
|
| 989 |
+
|
| 990 |
+
def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
|
| 991 |
+
"""Generate an instance of some CCompiler subclass for the supplied
|
| 992 |
+
platform/compiler combination. 'plat' defaults to 'os.name'
|
| 993 |
+
(eg. 'posix', 'nt'), and 'compiler' defaults to the default compiler
|
| 994 |
+
for that platform. Currently only 'posix' and 'nt' are supported, and
|
| 995 |
+
the default compilers are "traditional Unix interface" (UnixCCompiler
|
| 996 |
+
class) and Visual C++ (MSVCCompiler class). Note that it's perfectly
|
| 997 |
+
possible to ask for a Unix compiler object under Windows, and a
|
| 998 |
+
Microsoft compiler object under Unix -- if you supply a value for
|
| 999 |
+
'compiler', 'plat' is ignored.
|
| 1000 |
+
"""
|
| 1001 |
+
if plat is None:
|
| 1002 |
+
plat = os.name
|
| 1003 |
+
|
| 1004 |
+
try:
|
| 1005 |
+
if compiler is None:
|
| 1006 |
+
compiler = get_default_compiler(plat)
|
| 1007 |
+
|
| 1008 |
+
(module_name, class_name, long_description) = compiler_class[compiler]
|
| 1009 |
+
except KeyError:
|
| 1010 |
+
msg = "don't know how to compile C/C++ code on platform '%s'" % plat
|
| 1011 |
+
if compiler is not None:
|
| 1012 |
+
msg = msg + " with '%s' compiler" % compiler
|
| 1013 |
+
raise DistutilsPlatformError(msg)
|
| 1014 |
+
|
| 1015 |
+
try:
|
| 1016 |
+
module_name = "distutils." + module_name
|
| 1017 |
+
__import__ (module_name)
|
| 1018 |
+
module = sys.modules[module_name]
|
| 1019 |
+
klass = vars(module)[class_name]
|
| 1020 |
+
except ImportError:
|
| 1021 |
+
raise DistutilsModuleError(
|
| 1022 |
+
"can't compile C/C++ code: unable to load module '%s'" % \
|
| 1023 |
+
module_name)
|
| 1024 |
+
except KeyError:
|
| 1025 |
+
raise DistutilsModuleError(
|
| 1026 |
+
"can't compile C/C++ code: unable to find class '%s' "
|
| 1027 |
+
"in module '%s'" % (class_name, module_name))
|
| 1028 |
+
|
| 1029 |
+
# XXX The None is necessary to preserve backwards compatibility
|
| 1030 |
+
# with classes that expect verbose to be the first positional
|
| 1031 |
+
# argument.
|
| 1032 |
+
return klass(None, dry_run, force)
|
| 1033 |
+
|
| 1034 |
+
|
| 1035 |
+
def gen_preprocess_options(macros, include_dirs):
|
| 1036 |
+
"""Generate C pre-processor options (-D, -U, -I) as used by at least
|
| 1037 |
+
two types of compilers: the typical Unix compiler and Visual C++.
|
| 1038 |
+
'macros' is the usual thing, a list of 1- or 2-tuples, where (name,)
|
| 1039 |
+
means undefine (-U) macro 'name', and (name,value) means define (-D)
|
| 1040 |
+
macro 'name' to 'value'. 'include_dirs' is just a list of directory
|
| 1041 |
+
names to be added to the header file search path (-I). Returns a list
|
| 1042 |
+
of command-line options suitable for either Unix compilers or Visual
|
| 1043 |
+
C++.
|
| 1044 |
+
"""
|
| 1045 |
+
# XXX it would be nice (mainly aesthetic, and so we don't generate
|
| 1046 |
+
# stupid-looking command lines) to go over 'macros' and eliminate
|
| 1047 |
+
# redundant definitions/undefinitions (ie. ensure that only the
|
| 1048 |
+
# latest mention of a particular macro winds up on the command
|
| 1049 |
+
# line). I don't think it's essential, though, since most (all?)
|
| 1050 |
+
# Unix C compilers only pay attention to the latest -D or -U
|
| 1051 |
+
# mention of a macro on their command line. Similar situation for
|
| 1052 |
+
# 'include_dirs'. I'm punting on both for now. Anyways, weeding out
|
| 1053 |
+
# redundancies like this should probably be the province of
|
| 1054 |
+
# CCompiler, since the data structures used are inherited from it
|
| 1055 |
+
# and therefore common to all CCompiler classes.
|
| 1056 |
+
pp_opts = []
|
| 1057 |
+
for macro in macros:
|
| 1058 |
+
if not (isinstance(macro, tuple) and 1 <= len(macro) <= 2):
|
| 1059 |
+
raise TypeError(
|
| 1060 |
+
"bad macro definition '%s': "
|
| 1061 |
+
"each element of 'macros' list must be a 1- or 2-tuple"
|
| 1062 |
+
% macro)
|
| 1063 |
+
|
| 1064 |
+
if len(macro) == 1: # undefine this macro
|
| 1065 |
+
pp_opts.append("-U%s" % macro[0])
|
| 1066 |
+
elif len(macro) == 2:
|
| 1067 |
+
if macro[1] is None: # define with no explicit value
|
| 1068 |
+
pp_opts.append("-D%s" % macro[0])
|
| 1069 |
+
else:
|
| 1070 |
+
# XXX *don't* need to be clever about quoting the
|
| 1071 |
+
# macro value here, because we're going to avoid the
|
| 1072 |
+
# shell at all costs when we spawn the command!
|
| 1073 |
+
pp_opts.append("-D%s=%s" % macro)
|
| 1074 |
+
|
| 1075 |
+
for dir in include_dirs:
|
| 1076 |
+
pp_opts.append("-I%s" % dir)
|
| 1077 |
+
return pp_opts
|
| 1078 |
+
|
| 1079 |
+
|
| 1080 |
+
def gen_lib_options (compiler, library_dirs, runtime_library_dirs, libraries):
|
| 1081 |
+
"""Generate linker options for searching library directories and
|
| 1082 |
+
linking with specific libraries. 'libraries' and 'library_dirs' are,
|
| 1083 |
+
respectively, lists of library names (not filenames!) and search
|
| 1084 |
+
directories. Returns a list of command-line options suitable for use
|
| 1085 |
+
with some compiler (depending on the two format strings passed in).
|
| 1086 |
+
"""
|
| 1087 |
+
lib_opts = []
|
| 1088 |
+
|
| 1089 |
+
for dir in library_dirs:
|
| 1090 |
+
lib_opts.append(compiler.library_dir_option(dir))
|
| 1091 |
+
|
| 1092 |
+
for dir in runtime_library_dirs:
|
| 1093 |
+
opt = compiler.runtime_library_dir_option(dir)
|
| 1094 |
+
if isinstance(opt, list):
|
| 1095 |
+
lib_opts = lib_opts + opt
|
| 1096 |
+
else:
|
| 1097 |
+
lib_opts.append(opt)
|
| 1098 |
+
|
| 1099 |
+
# XXX it's important that we *not* remove redundant library mentions!
|
| 1100 |
+
# sometimes you really do have to say "-lfoo -lbar -lfoo" in order to
|
| 1101 |
+
# resolve all symbols. I just hope we never have to say "-lfoo obj.o
|
| 1102 |
+
# -lbar" to get things to work -- that's certainly a possibility, but a
|
| 1103 |
+
# pretty nasty way to arrange your C code.
|
| 1104 |
+
|
| 1105 |
+
for lib in libraries:
|
| 1106 |
+
(lib_dir, lib_name) = os.path.split(lib)
|
| 1107 |
+
if lib_dir:
|
| 1108 |
+
lib_file = compiler.find_library_file([lib_dir], lib_name)
|
| 1109 |
+
if lib_file:
|
| 1110 |
+
lib_opts.append(lib_file)
|
| 1111 |
+
else:
|
| 1112 |
+
compiler.warn("no library file corresponding to "
|
| 1113 |
+
"'%s' found (skipping)" % lib)
|
| 1114 |
+
else:
|
| 1115 |
+
lib_opts.append(compiler.library_option (lib))
|
| 1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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.cmd
|
| 2 |
+
|
| 3 |
+
Provides the Command class, the base class for the command classes
|
| 4 |
+
in the distutils.command package.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys, os, re
|
| 8 |
+
from distutils.errors import DistutilsOptionError
|
| 9 |
+
from distutils import util, dir_util, file_util, archive_util, dep_util
|
| 10 |
+
from distutils import log
|
| 11 |
+
|
| 12 |
+
class Command:
|
| 13 |
+
"""Abstract base class for defining command classes, the "worker bees"
|
| 14 |
+
of the Distutils. A useful analogy for command classes is to think of
|
| 15 |
+
them as subroutines with local variables called "options". The options
|
| 16 |
+
are "declared" in 'initialize_options()' and "defined" (given their
|
| 17 |
+
final values, aka "finalized") in 'finalize_options()', both of which
|
| 18 |
+
must be defined by every command class. The distinction between the
|
| 19 |
+
two is necessary because option values might come from the outside
|
| 20 |
+
world (command line, config file, ...), and any options dependent on
|
| 21 |
+
other options must be computed *after* these outside influences have
|
| 22 |
+
been processed -- hence 'finalize_options()'. The "body" of the
|
| 23 |
+
subroutine, where it does all its work based on the values of its
|
| 24 |
+
options, is the 'run()' method, which must also be implemented by every
|
| 25 |
+
command class.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
# 'sub_commands' formalizes the notion of a "family" of commands,
|
| 29 |
+
# eg. "install" as the parent with sub-commands "install_lib",
|
| 30 |
+
# "install_headers", etc. The parent of a family of commands
|
| 31 |
+
# defines 'sub_commands' as a class attribute; it's a list of
|
| 32 |
+
# (command_name : string, predicate : unbound_method | string | None)
|
| 33 |
+
# tuples, where 'predicate' is a method of the parent command that
|
| 34 |
+
# determines whether the corresponding command is applicable in the
|
| 35 |
+
# current situation. (Eg. we "install_headers" is only applicable if
|
| 36 |
+
# we have any C header files to install.) If 'predicate' is None,
|
| 37 |
+
# that command is always applicable.
|
| 38 |
+
#
|
| 39 |
+
# 'sub_commands' is usually defined at the *end* of a class, because
|
| 40 |
+
# predicates can be unbound methods, so they must already have been
|
| 41 |
+
# defined. The canonical example is the "install" command.
|
| 42 |
+
sub_commands = []
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# -- Creation/initialization methods -------------------------------
|
| 46 |
+
|
| 47 |
+
def __init__(self, dist):
|
| 48 |
+
"""Create and initialize a new Command object. Most importantly,
|
| 49 |
+
invokes the 'initialize_options()' method, which is the real
|
| 50 |
+
initializer and depends on the actual command being
|
| 51 |
+
instantiated.
|
| 52 |
+
"""
|
| 53 |
+
# late import because of mutual dependence between these classes
|
| 54 |
+
from distutils.dist import Distribution
|
| 55 |
+
|
| 56 |
+
if not isinstance(dist, Distribution):
|
| 57 |
+
raise TypeError("dist must be a Distribution instance")
|
| 58 |
+
if self.__class__ is Command:
|
| 59 |
+
raise RuntimeError("Command is an abstract class")
|
| 60 |
+
|
| 61 |
+
self.distribution = dist
|
| 62 |
+
self.initialize_options()
|
| 63 |
+
|
| 64 |
+
# Per-command versions of the global flags, so that the user can
|
| 65 |
+
# customize Distutils' behaviour command-by-command and let some
|
| 66 |
+
# commands fall back on the Distribution's behaviour. None means
|
| 67 |
+
# "not defined, check self.distribution's copy", while 0 or 1 mean
|
| 68 |
+
# false and true (duh). Note that this means figuring out the real
|
| 69 |
+
# value of each flag is a touch complicated -- hence "self._dry_run"
|
| 70 |
+
# will be handled by __getattr__, below.
|
| 71 |
+
# XXX This needs to be fixed.
|
| 72 |
+
self._dry_run = None
|
| 73 |
+
|
| 74 |
+
# verbose is largely ignored, but needs to be set for
|
| 75 |
+
# backwards compatibility (I think)?
|
| 76 |
+
self.verbose = dist.verbose
|
| 77 |
+
|
| 78 |
+
# Some commands define a 'self.force' option to ignore file
|
| 79 |
+
# timestamps, but methods defined *here* assume that
|
| 80 |
+
# 'self.force' exists for all commands. So define it here
|
| 81 |
+
# just to be safe.
|
| 82 |
+
self.force = None
|
| 83 |
+
|
| 84 |
+
# The 'help' flag is just used for command-line parsing, so
|
| 85 |
+
# none of that complicated bureaucracy is needed.
|
| 86 |
+
self.help = 0
|
| 87 |
+
|
| 88 |
+
# 'finalized' records whether or not 'finalize_options()' has been
|
| 89 |
+
# called. 'finalize_options()' itself should not pay attention to
|
| 90 |
+
# this flag: it is the business of 'ensure_finalized()', which
|
| 91 |
+
# always calls 'finalize_options()', to respect/update it.
|
| 92 |
+
self.finalized = 0
|
| 93 |
+
|
| 94 |
+
# XXX A more explicit way to customize dry_run would be better.
|
| 95 |
+
def __getattr__(self, attr):
|
| 96 |
+
if attr == 'dry_run':
|
| 97 |
+
myval = getattr(self, "_" + attr)
|
| 98 |
+
if myval is None:
|
| 99 |
+
return getattr(self.distribution, attr)
|
| 100 |
+
else:
|
| 101 |
+
return myval
|
| 102 |
+
else:
|
| 103 |
+
raise AttributeError(attr)
|
| 104 |
+
|
| 105 |
+
def ensure_finalized(self):
|
| 106 |
+
if not self.finalized:
|
| 107 |
+
self.finalize_options()
|
| 108 |
+
self.finalized = 1
|
| 109 |
+
|
| 110 |
+
# Subclasses must define:
|
| 111 |
+
# initialize_options()
|
| 112 |
+
# provide default values for all options; may be customized by
|
| 113 |
+
# setup script, by options from config file(s), or by command-line
|
| 114 |
+
# options
|
| 115 |
+
# finalize_options()
|
| 116 |
+
# decide on the final values for all options; this is called
|
| 117 |
+
# after all possible intervention from the outside world
|
| 118 |
+
# (command-line, option file, etc.) has been processed
|
| 119 |
+
# run()
|
| 120 |
+
# run the command: do whatever it is we're here to do,
|
| 121 |
+
# controlled by the command's various option values
|
| 122 |
+
|
| 123 |
+
def initialize_options(self):
|
| 124 |
+
"""Set default values for all the options that this command
|
| 125 |
+
supports. Note that these defaults may be overridden by other
|
| 126 |
+
commands, by the setup script, by config files, or by the
|
| 127 |
+
command-line. Thus, this is not the place to code dependencies
|
| 128 |
+
between options; generally, 'initialize_options()' implementations
|
| 129 |
+
are just a bunch of "self.foo = None" assignments.
|
| 130 |
+
|
| 131 |
+
This method must be implemented by all command classes.
|
| 132 |
+
"""
|
| 133 |
+
raise RuntimeError("abstract method -- subclass %s must override"
|
| 134 |
+
% self.__class__)
|
| 135 |
+
|
| 136 |
+
def finalize_options(self):
|
| 137 |
+
"""Set final values for all the options that this command supports.
|
| 138 |
+
This is always called as late as possible, ie. after any option
|
| 139 |
+
assignments from the command-line or from other commands have been
|
| 140 |
+
done. Thus, this is the place to code option dependencies: if
|
| 141 |
+
'foo' depends on 'bar', then it is safe to set 'foo' from 'bar' as
|
| 142 |
+
long as 'foo' still has the same value it was assigned in
|
| 143 |
+
'initialize_options()'.
|
| 144 |
+
|
| 145 |
+
This method must be implemented by all command classes.
|
| 146 |
+
"""
|
| 147 |
+
raise RuntimeError("abstract method -- subclass %s must override"
|
| 148 |
+
% self.__class__)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def dump_options(self, header=None, indent=""):
|
| 152 |
+
from distutils.fancy_getopt import longopt_xlate
|
| 153 |
+
if header is None:
|
| 154 |
+
header = "command options for '%s':" % self.get_command_name()
|
| 155 |
+
self.announce(indent + header, level=log.INFO)
|
| 156 |
+
indent = indent + " "
|
| 157 |
+
for (option, _, _) in self.user_options:
|
| 158 |
+
option = option.translate(longopt_xlate)
|
| 159 |
+
if option[-1] == "=":
|
| 160 |
+
option = option[:-1]
|
| 161 |
+
value = getattr(self, option)
|
| 162 |
+
self.announce(indent + "%s = %s" % (option, value),
|
| 163 |
+
level=log.INFO)
|
| 164 |
+
|
| 165 |
+
def run(self):
|
| 166 |
+
"""A command's raison d'etre: carry out the action it exists to
|
| 167 |
+
perform, controlled by the options initialized in
|
| 168 |
+
'initialize_options()', customized by other commands, the setup
|
| 169 |
+
script, the command-line, and config files, and finalized in
|
| 170 |
+
'finalize_options()'. All terminal output and filesystem
|
| 171 |
+
interaction should be done by 'run()'.
|
| 172 |
+
|
| 173 |
+
This method must be implemented by all command classes.
|
| 174 |
+
"""
|
| 175 |
+
raise RuntimeError("abstract method -- subclass %s must override"
|
| 176 |
+
% self.__class__)
|
| 177 |
+
|
| 178 |
+
def announce(self, msg, level=1):
|
| 179 |
+
"""If the current verbosity level is of greater than or equal to
|
| 180 |
+
'level' print 'msg' to stdout.
|
| 181 |
+
"""
|
| 182 |
+
log.log(level, msg)
|
| 183 |
+
|
| 184 |
+
def debug_print(self, msg):
|
| 185 |
+
"""Print 'msg' to stdout if the global DEBUG (taken from the
|
| 186 |
+
DISTUTILS_DEBUG environment variable) flag is true.
|
| 187 |
+
"""
|
| 188 |
+
from distutils.debug import DEBUG
|
| 189 |
+
if DEBUG:
|
| 190 |
+
print(msg)
|
| 191 |
+
sys.stdout.flush()
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
# -- Option validation methods -------------------------------------
|
| 195 |
+
# (these are very handy in writing the 'finalize_options()' method)
|
| 196 |
+
#
|
| 197 |
+
# NB. the general philosophy here is to ensure that a particular option
|
| 198 |
+
# value meets certain type and value constraints. If not, we try to
|
| 199 |
+
# force it into conformance (eg. if we expect a list but have a string,
|
| 200 |
+
# split the string on comma and/or whitespace). If we can't force the
|
| 201 |
+
# option into conformance, raise DistutilsOptionError. Thus, command
|
| 202 |
+
# classes need do nothing more than (eg.)
|
| 203 |
+
# self.ensure_string_list('foo')
|
| 204 |
+
# and they can be guaranteed that thereafter, self.foo will be
|
| 205 |
+
# a list of strings.
|
| 206 |
+
|
| 207 |
+
def _ensure_stringlike(self, option, what, default=None):
|
| 208 |
+
val = getattr(self, option)
|
| 209 |
+
if val is None:
|
| 210 |
+
setattr(self, option, default)
|
| 211 |
+
return default
|
| 212 |
+
elif not isinstance(val, str):
|
| 213 |
+
raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
|
| 214 |
+
% (option, what, val))
|
| 215 |
+
return val
|
| 216 |
+
|
| 217 |
+
def ensure_string(self, option, default=None):
|
| 218 |
+
"""Ensure that 'option' is a string; if not defined, set it to
|
| 219 |
+
'default'.
|
| 220 |
+
"""
|
| 221 |
+
self._ensure_stringlike(option, "string", default)
|
| 222 |
+
|
| 223 |
+
def ensure_string_list(self, option):
|
| 224 |
+
r"""Ensure that 'option' is a list of strings. If 'option' is
|
| 225 |
+
currently a string, we split it either on /,\s*/ or /\s+/, so
|
| 226 |
+
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
|
| 227 |
+
["foo", "bar", "baz"].
|
| 228 |
+
"""
|
| 229 |
+
val = getattr(self, option)
|
| 230 |
+
if val is None:
|
| 231 |
+
return
|
| 232 |
+
elif isinstance(val, str):
|
| 233 |
+
setattr(self, option, re.split(r',\s*|\s+', val))
|
| 234 |
+
else:
|
| 235 |
+
if isinstance(val, list):
|
| 236 |
+
ok = all(isinstance(v, str) for v in val)
|
| 237 |
+
else:
|
| 238 |
+
ok = False
|
| 239 |
+
if not ok:
|
| 240 |
+
raise DistutilsOptionError(
|
| 241 |
+
"'%s' must be a list of strings (got %r)"
|
| 242 |
+
% (option, val))
|
| 243 |
+
|
| 244 |
+
def _ensure_tested_string(self, option, tester, what, error_fmt,
|
| 245 |
+
default=None):
|
| 246 |
+
val = self._ensure_stringlike(option, what, default)
|
| 247 |
+
if val is not None and not tester(val):
|
| 248 |
+
raise DistutilsOptionError(("error in '%s' option: " + error_fmt)
|
| 249 |
+
% (option, val))
|
| 250 |
+
|
| 251 |
+
def ensure_filename(self, option):
|
| 252 |
+
"""Ensure that 'option' is the name of an existing file."""
|
| 253 |
+
self._ensure_tested_string(option, os.path.isfile,
|
| 254 |
+
"filename",
|
| 255 |
+
"'%s' does not exist or is not a file")
|
| 256 |
+
|
| 257 |
+
def ensure_dirname(self, option):
|
| 258 |
+
self._ensure_tested_string(option, os.path.isdir,
|
| 259 |
+
"directory name",
|
| 260 |
+
"'%s' does not exist or is not a directory")
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
# -- Convenience methods for commands ------------------------------
|
| 264 |
+
|
| 265 |
+
def get_command_name(self):
|
| 266 |
+
if hasattr(self, 'command_name'):
|
| 267 |
+
return self.command_name
|
| 268 |
+
else:
|
| 269 |
+
return self.__class__.__name__
|
| 270 |
+
|
| 271 |
+
def set_undefined_options(self, src_cmd, *option_pairs):
|
| 272 |
+
"""Set the values of any "undefined" options from corresponding
|
| 273 |
+
option values in some other command object. "Undefined" here means
|
| 274 |
+
"is None", which is the convention used to indicate that an option
|
| 275 |
+
has not been changed between 'initialize_options()' and
|
| 276 |
+
'finalize_options()'. Usually called from 'finalize_options()' for
|
| 277 |
+
options that depend on some other command rather than another
|
| 278 |
+
option of the same command. 'src_cmd' is the other command from
|
| 279 |
+
which option values will be taken (a command object will be created
|
| 280 |
+
for it if necessary); the remaining arguments are
|
| 281 |
+
'(src_option,dst_option)' tuples which mean "take the value of
|
| 282 |
+
'src_option' in the 'src_cmd' command object, and copy it to
|
| 283 |
+
'dst_option' in the current command object".
|
| 284 |
+
"""
|
| 285 |
+
# Option_pairs: list of (src_option, dst_option) tuples
|
| 286 |
+
src_cmd_obj = self.distribution.get_command_obj(src_cmd)
|
| 287 |
+
src_cmd_obj.ensure_finalized()
|
| 288 |
+
for (src_option, dst_option) in option_pairs:
|
| 289 |
+
if getattr(self, dst_option) is None:
|
| 290 |
+
setattr(self, dst_option, getattr(src_cmd_obj, src_option))
|
| 291 |
+
|
| 292 |
+
def get_finalized_command(self, command, create=1):
|
| 293 |
+
"""Wrapper around Distribution's 'get_command_obj()' method: find
|
| 294 |
+
(create if necessary and 'create' is true) the command object for
|
| 295 |
+
'command', call its 'ensure_finalized()' method, and return the
|
| 296 |
+
finalized command object.
|
| 297 |
+
"""
|
| 298 |
+
cmd_obj = self.distribution.get_command_obj(command, create)
|
| 299 |
+
cmd_obj.ensure_finalized()
|
| 300 |
+
return cmd_obj
|
| 301 |
+
|
| 302 |
+
# XXX rename to 'get_reinitialized_command()'? (should do the
|
| 303 |
+
# same in dist.py, if so)
|
| 304 |
+
def reinitialize_command(self, command, reinit_subcommands=0):
|
| 305 |
+
return self.distribution.reinitialize_command(command,
|
| 306 |
+
reinit_subcommands)
|
| 307 |
+
|
| 308 |
+
def run_command(self, command):
|
| 309 |
+
"""Run some other command: uses the 'run_command()' method of
|
| 310 |
+
Distribution, which creates and finalizes the command object if
|
| 311 |
+
necessary and then invokes its 'run()' method.
|
| 312 |
+
"""
|
| 313 |
+
self.distribution.run_command(command)
|
| 314 |
+
|
| 315 |
+
def get_sub_commands(self):
|
| 316 |
+
"""Determine the sub-commands that are relevant in the current
|
| 317 |
+
distribution (ie., that need to be run). This is based on the
|
| 318 |
+
'sub_commands' class attribute: each tuple in that list may include
|
| 319 |
+
a method that we call to determine if the subcommand needs to be
|
| 320 |
+
run for the current distribution. Return a list of command names.
|
| 321 |
+
"""
|
| 322 |
+
commands = []
|
| 323 |
+
for (cmd_name, method) in self.sub_commands:
|
| 324 |
+
if method is None or method(self):
|
| 325 |
+
commands.append(cmd_name)
|
| 326 |
+
return commands
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
# -- External world manipulation -----------------------------------
|
| 330 |
+
|
| 331 |
+
def warn(self, msg):
|
| 332 |
+
log.warn("warning: %s: %s\n", self.get_command_name(), msg)
|
| 333 |
+
|
| 334 |
+
def execute(self, func, args, msg=None, level=1):
|
| 335 |
+
util.execute(func, args, msg, dry_run=self.dry_run)
|
| 336 |
+
|
| 337 |
+
def mkpath(self, name, mode=0o777):
|
| 338 |
+
dir_util.mkpath(name, mode, dry_run=self.dry_run)
|
| 339 |
+
|
| 340 |
+
def copy_file(self, infile, outfile, preserve_mode=1, preserve_times=1,
|
| 341 |
+
link=None, level=1):
|
| 342 |
+
"""Copy a file respecting verbose, dry-run and force flags. (The
|
| 343 |
+
former two default to whatever is in the Distribution object, and
|
| 344 |
+
the latter defaults to false for commands that don't define it.)"""
|
| 345 |
+
return file_util.copy_file(infile, outfile, preserve_mode,
|
| 346 |
+
preserve_times, not self.force, link,
|
| 347 |
+
dry_run=self.dry_run)
|
| 348 |
+
|
| 349 |
+
def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1,
|
| 350 |
+
preserve_symlinks=0, level=1):
|
| 351 |
+
"""Copy an entire directory tree respecting verbose, dry-run,
|
| 352 |
+
and force flags.
|
| 353 |
+
"""
|
| 354 |
+
return dir_util.copy_tree(infile, outfile, preserve_mode,
|
| 355 |
+
preserve_times, preserve_symlinks,
|
| 356 |
+
not self.force, dry_run=self.dry_run)
|
| 357 |
+
|
| 358 |
+
def move_file (self, src, dst, level=1):
|
| 359 |
+
"""Move a file respecting dry-run flag."""
|
| 360 |
+
return file_util.move_file(src, dst, dry_run=self.dry_run)
|
| 361 |
+
|
| 362 |
+
def spawn(self, cmd, search_path=1, level=1):
|
| 363 |
+
"""Spawn an external command respecting dry-run flag."""
|
| 364 |
+
from distutils.spawn import spawn
|
| 365 |
+
spawn(cmd, search_path, dry_run=self.dry_run)
|
| 366 |
+
|
| 367 |
+
def make_archive(self, base_name, format, root_dir=None, base_dir=None,
|
| 368 |
+
owner=None, group=None):
|
| 369 |
+
return archive_util.make_archive(base_name, format, root_dir, base_dir,
|
| 370 |
+
dry_run=self.dry_run,
|
| 371 |
+
owner=owner, group=group)
|
| 372 |
+
|
| 373 |
+
def make_file(self, infiles, outfile, func, args,
|
| 374 |
+
exec_msg=None, skip_msg=None, level=1):
|
| 375 |
+
"""Special case of 'execute()' for operations that process one or
|
| 376 |
+
more input files and generate one output file. Works just like
|
| 377 |
+
'execute()', except the operation is skipped and a different
|
| 378 |
+
message printed if 'outfile' already exists and is newer than all
|
| 379 |
+
files listed in 'infiles'. If the command defined 'self.force',
|
| 380 |
+
and it is true, then the command is unconditionally run -- does no
|
| 381 |
+
timestamp checks.
|
| 382 |
+
"""
|
| 383 |
+
if skip_msg is None:
|
| 384 |
+
skip_msg = "skipping %s (inputs unchanged)" % outfile
|
| 385 |
+
|
| 386 |
+
# Allow 'infiles' to be a single string
|
| 387 |
+
if isinstance(infiles, str):
|
| 388 |
+
infiles = (infiles,)
|
| 389 |
+
elif not isinstance(infiles, (list, tuple)):
|
| 390 |
+
raise TypeError(
|
| 391 |
+
"'infiles' must be a string, or a list or tuple of strings")
|
| 392 |
+
|
| 393 |
+
if exec_msg is None:
|
| 394 |
+
exec_msg = "generating %s from %s" % (outfile, ', '.join(infiles))
|
| 395 |
+
|
| 396 |
+
# If 'outfile' must be regenerated (either because it doesn't
|
| 397 |
+
# exist, is out-of-date, or the 'force' flag is true) then
|
| 398 |
+
# perform the action that presumably regenerates it
|
| 399 |
+
if self.force or dep_util.newer_group(infiles, outfile):
|
| 400 |
+
self.execute(func, args, exec_msg, level)
|
| 401 |
+
# Otherwise, print the "skip" message
|
| 402 |
+
else:
|
| 403 |
+
log.debug(skip_msg)
|
data/conda_envs/evalclaw/lib/python3.11/distutils/config.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.pypirc
|
| 2 |
+
|
| 3 |
+
Provides the PyPIRCCommand class, the base class for the command classes
|
| 4 |
+
that uses .pypirc in the distutils.command package.
|
| 5 |
+
"""
|
| 6 |
+
import os
|
| 7 |
+
from configparser import RawConfigParser
|
| 8 |
+
import warnings
|
| 9 |
+
|
| 10 |
+
from distutils.cmd import Command
|
| 11 |
+
|
| 12 |
+
DEFAULT_PYPIRC = """\
|
| 13 |
+
[distutils]
|
| 14 |
+
index-servers =
|
| 15 |
+
pypi
|
| 16 |
+
|
| 17 |
+
[pypi]
|
| 18 |
+
username:%s
|
| 19 |
+
password:%s
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
class PyPIRCCommand(Command):
|
| 23 |
+
"""Base command that knows how to handle the .pypirc file
|
| 24 |
+
"""
|
| 25 |
+
DEFAULT_REPOSITORY = 'https://upload.pypi.org/legacy/'
|
| 26 |
+
DEFAULT_REALM = 'pypi'
|
| 27 |
+
repository = None
|
| 28 |
+
realm = None
|
| 29 |
+
|
| 30 |
+
user_options = [
|
| 31 |
+
('repository=', 'r',
|
| 32 |
+
"url of repository [default: %s]" % \
|
| 33 |
+
DEFAULT_REPOSITORY),
|
| 34 |
+
('show-response', None,
|
| 35 |
+
'display full response text from server')]
|
| 36 |
+
|
| 37 |
+
boolean_options = ['show-response']
|
| 38 |
+
|
| 39 |
+
def _get_rc_file(self):
|
| 40 |
+
"""Returns rc file path."""
|
| 41 |
+
return os.path.join(os.path.expanduser('~'), '.pypirc')
|
| 42 |
+
|
| 43 |
+
def _store_pypirc(self, username, password):
|
| 44 |
+
"""Creates a default .pypirc file."""
|
| 45 |
+
rc = self._get_rc_file()
|
| 46 |
+
with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
|
| 47 |
+
f.write(DEFAULT_PYPIRC % (username, password))
|
| 48 |
+
|
| 49 |
+
def _read_pypirc(self):
|
| 50 |
+
"""Reads the .pypirc file."""
|
| 51 |
+
rc = self._get_rc_file()
|
| 52 |
+
if os.path.exists(rc):
|
| 53 |
+
self.announce('Using PyPI login from %s' % rc)
|
| 54 |
+
repository = self.repository or self.DEFAULT_REPOSITORY
|
| 55 |
+
|
| 56 |
+
config = RawConfigParser()
|
| 57 |
+
config.read(rc)
|
| 58 |
+
sections = config.sections()
|
| 59 |
+
if 'distutils' in sections:
|
| 60 |
+
# let's get the list of servers
|
| 61 |
+
index_servers = config.get('distutils', 'index-servers')
|
| 62 |
+
_servers = [server.strip() for server in
|
| 63 |
+
index_servers.split('\n')
|
| 64 |
+
if server.strip() != '']
|
| 65 |
+
if _servers == []:
|
| 66 |
+
# nothing set, let's try to get the default pypi
|
| 67 |
+
if 'pypi' in sections:
|
| 68 |
+
_servers = ['pypi']
|
| 69 |
+
else:
|
| 70 |
+
# the file is not properly defined, returning
|
| 71 |
+
# an empty dict
|
| 72 |
+
return {}
|
| 73 |
+
for server in _servers:
|
| 74 |
+
current = {'server': server}
|
| 75 |
+
current['username'] = config.get(server, 'username')
|
| 76 |
+
|
| 77 |
+
# optional params
|
| 78 |
+
for key, default in (('repository',
|
| 79 |
+
self.DEFAULT_REPOSITORY),
|
| 80 |
+
('realm', self.DEFAULT_REALM),
|
| 81 |
+
('password', None)):
|
| 82 |
+
if config.has_option(server, key):
|
| 83 |
+
current[key] = config.get(server, key)
|
| 84 |
+
else:
|
| 85 |
+
current[key] = default
|
| 86 |
+
|
| 87 |
+
# work around people having "repository" for the "pypi"
|
| 88 |
+
# section of their config set to the HTTP (rather than
|
| 89 |
+
# HTTPS) URL
|
| 90 |
+
if (server == 'pypi' and
|
| 91 |
+
repository in (self.DEFAULT_REPOSITORY, 'pypi')):
|
| 92 |
+
current['repository'] = self.DEFAULT_REPOSITORY
|
| 93 |
+
return current
|
| 94 |
+
|
| 95 |
+
if (current['server'] == repository or
|
| 96 |
+
current['repository'] == repository):
|
| 97 |
+
return current
|
| 98 |
+
elif 'server-login' in sections:
|
| 99 |
+
# old format
|
| 100 |
+
server = 'server-login'
|
| 101 |
+
if config.has_option(server, 'repository'):
|
| 102 |
+
repository = config.get(server, 'repository')
|
| 103 |
+
else:
|
| 104 |
+
repository = self.DEFAULT_REPOSITORY
|
| 105 |
+
return {'username': config.get(server, 'username'),
|
| 106 |
+
'password': config.get(server, 'password'),
|
| 107 |
+
'repository': repository,
|
| 108 |
+
'server': server,
|
| 109 |
+
'realm': self.DEFAULT_REALM}
|
| 110 |
+
|
| 111 |
+
return {}
|
| 112 |
+
|
| 113 |
+
def _read_pypi_response(self, response):
|
| 114 |
+
"""Read and decode a PyPI HTTP response."""
|
| 115 |
+
with warnings.catch_warnings():
|
| 116 |
+
warnings.simplefilter("ignore", DeprecationWarning)
|
| 117 |
+
import cgi
|
| 118 |
+
content_type = response.getheader('content-type', 'text/plain')
|
| 119 |
+
encoding = cgi.parse_header(content_type)[1].get('charset', 'ascii')
|
| 120 |
+
return response.read().decode(encoding)
|
| 121 |
+
|
| 122 |
+
def initialize_options(self):
|
| 123 |
+
"""Initialize options."""
|
| 124 |
+
self.repository = None
|
| 125 |
+
self.realm = None
|
| 126 |
+
self.show_response = 0
|
| 127 |
+
|
| 128 |
+
def finalize_options(self):
|
| 129 |
+
"""Finalizes options."""
|
| 130 |
+
if self.repository is None:
|
| 131 |
+
self.repository = self.DEFAULT_REPOSITORY
|
| 132 |
+
if self.realm is None:
|
| 133 |
+
self.realm = self.DEFAULT_REALM
|
data/conda_envs/evalclaw/lib/python3.11/distutils/core.py
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.core
|
| 2 |
+
|
| 3 |
+
The only module that needs to be imported to use the Distutils; provides
|
| 4 |
+
the 'setup' function (which is to be called from the setup script). Also
|
| 5 |
+
indirectly provides the Distribution and Command classes, although they are
|
| 6 |
+
really defined in distutils.dist and distutils.cmd.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
|
| 12 |
+
from distutils.debug import DEBUG
|
| 13 |
+
from distutils.errors import *
|
| 14 |
+
|
| 15 |
+
# Mainly import these so setup scripts can "from distutils.core import" them.
|
| 16 |
+
from distutils.dist import Distribution
|
| 17 |
+
from distutils.cmd import Command
|
| 18 |
+
from distutils.config import PyPIRCCommand
|
| 19 |
+
from distutils.extension import Extension
|
| 20 |
+
|
| 21 |
+
# This is a barebones help message generated displayed when the user
|
| 22 |
+
# runs the setup script with no arguments at all. More useful help
|
| 23 |
+
# is generated with various --help options: global help, list commands,
|
| 24 |
+
# and per-command help.
|
| 25 |
+
USAGE = """\
|
| 26 |
+
usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
|
| 27 |
+
or: %(script)s --help [cmd1 cmd2 ...]
|
| 28 |
+
or: %(script)s --help-commands
|
| 29 |
+
or: %(script)s cmd --help
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
def gen_usage (script_name):
|
| 33 |
+
script = os.path.basename(script_name)
|
| 34 |
+
return USAGE % vars()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
|
| 38 |
+
_setup_stop_after = None
|
| 39 |
+
_setup_distribution = None
|
| 40 |
+
|
| 41 |
+
# Legal keyword arguments for the setup() function
|
| 42 |
+
setup_keywords = ('distclass', 'script_name', 'script_args', 'options',
|
| 43 |
+
'name', 'version', 'author', 'author_email',
|
| 44 |
+
'maintainer', 'maintainer_email', 'url', 'license',
|
| 45 |
+
'description', 'long_description', 'keywords',
|
| 46 |
+
'platforms', 'classifiers', 'download_url',
|
| 47 |
+
'requires', 'provides', 'obsoletes',
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
# Legal keyword arguments for the Extension constructor
|
| 51 |
+
extension_keywords = ('name', 'sources', 'include_dirs',
|
| 52 |
+
'define_macros', 'undef_macros',
|
| 53 |
+
'library_dirs', 'libraries', 'runtime_library_dirs',
|
| 54 |
+
'extra_objects', 'extra_compile_args', 'extra_link_args',
|
| 55 |
+
'swig_opts', 'export_symbols', 'depends', 'language')
|
| 56 |
+
|
| 57 |
+
def setup (**attrs):
|
| 58 |
+
"""The gateway to the Distutils: do everything your setup script needs
|
| 59 |
+
to do, in a highly flexible and user-driven way. Briefly: create a
|
| 60 |
+
Distribution instance; find and parse config files; parse the command
|
| 61 |
+
line; run each Distutils command found there, customized by the options
|
| 62 |
+
supplied to 'setup()' (as keyword arguments), in config files, and on
|
| 63 |
+
the command line.
|
| 64 |
+
|
| 65 |
+
The Distribution instance might be an instance of a class supplied via
|
| 66 |
+
the 'distclass' keyword argument to 'setup'; if no such class is
|
| 67 |
+
supplied, then the Distribution class (in dist.py) is instantiated.
|
| 68 |
+
All other arguments to 'setup' (except for 'cmdclass') are used to set
|
| 69 |
+
attributes of the Distribution instance.
|
| 70 |
+
|
| 71 |
+
The 'cmdclass' argument, if supplied, is a dictionary mapping command
|
| 72 |
+
names to command classes. Each command encountered on the command line
|
| 73 |
+
will be turned into a command class, which is in turn instantiated; any
|
| 74 |
+
class found in 'cmdclass' is used in place of the default, which is
|
| 75 |
+
(for command 'foo_bar') class 'foo_bar' in module
|
| 76 |
+
'distutils.command.foo_bar'. The command class must provide a
|
| 77 |
+
'user_options' attribute which is a list of option specifiers for
|
| 78 |
+
'distutils.fancy_getopt'. Any command-line options between the current
|
| 79 |
+
and the next command are used to set attributes of the current command
|
| 80 |
+
object.
|
| 81 |
+
|
| 82 |
+
When the entire command-line has been successfully parsed, calls the
|
| 83 |
+
'run()' method on each command object in turn. This method will be
|
| 84 |
+
driven entirely by the Distribution object (which each command object
|
| 85 |
+
has a reference to, thanks to its constructor), and the
|
| 86 |
+
command-specific options that became attributes of each command
|
| 87 |
+
object.
|
| 88 |
+
"""
|
| 89 |
+
|
| 90 |
+
global _setup_stop_after, _setup_distribution
|
| 91 |
+
|
| 92 |
+
# Determine the distribution class -- either caller-supplied or
|
| 93 |
+
# our Distribution (see below).
|
| 94 |
+
klass = attrs.get('distclass')
|
| 95 |
+
if klass:
|
| 96 |
+
del attrs['distclass']
|
| 97 |
+
else:
|
| 98 |
+
klass = Distribution
|
| 99 |
+
|
| 100 |
+
if 'script_name' not in attrs:
|
| 101 |
+
attrs['script_name'] = os.path.basename(sys.argv[0])
|
| 102 |
+
if 'script_args' not in attrs:
|
| 103 |
+
attrs['script_args'] = sys.argv[1:]
|
| 104 |
+
|
| 105 |
+
# Create the Distribution instance, using the remaining arguments
|
| 106 |
+
# (ie. everything except distclass) to initialize it
|
| 107 |
+
try:
|
| 108 |
+
_setup_distribution = dist = klass(attrs)
|
| 109 |
+
except DistutilsSetupError as msg:
|
| 110 |
+
if 'name' not in attrs:
|
| 111 |
+
raise SystemExit("error in setup command: %s" % msg)
|
| 112 |
+
else:
|
| 113 |
+
raise SystemExit("error in %s setup command: %s" % \
|
| 114 |
+
(attrs['name'], msg))
|
| 115 |
+
|
| 116 |
+
if _setup_stop_after == "init":
|
| 117 |
+
return dist
|
| 118 |
+
|
| 119 |
+
# Find and parse the config file(s): they will override options from
|
| 120 |
+
# the setup script, but be overridden by the command line.
|
| 121 |
+
dist.parse_config_files()
|
| 122 |
+
|
| 123 |
+
if DEBUG:
|
| 124 |
+
print("options (after parsing config files):")
|
| 125 |
+
dist.dump_option_dicts()
|
| 126 |
+
|
| 127 |
+
if _setup_stop_after == "config":
|
| 128 |
+
return dist
|
| 129 |
+
|
| 130 |
+
# Parse the command line and override config files; any
|
| 131 |
+
# command-line errors are the end user's fault, so turn them into
|
| 132 |
+
# SystemExit to suppress tracebacks.
|
| 133 |
+
try:
|
| 134 |
+
ok = dist.parse_command_line()
|
| 135 |
+
except DistutilsArgError as msg:
|
| 136 |
+
raise SystemExit(gen_usage(dist.script_name) + "\nerror: %s" % msg)
|
| 137 |
+
|
| 138 |
+
if DEBUG:
|
| 139 |
+
print("options (after parsing command line):")
|
| 140 |
+
dist.dump_option_dicts()
|
| 141 |
+
|
| 142 |
+
if _setup_stop_after == "commandline":
|
| 143 |
+
return dist
|
| 144 |
+
|
| 145 |
+
# And finally, run all the commands found on the command line.
|
| 146 |
+
if ok:
|
| 147 |
+
try:
|
| 148 |
+
dist.run_commands()
|
| 149 |
+
except KeyboardInterrupt:
|
| 150 |
+
raise SystemExit("interrupted")
|
| 151 |
+
except OSError as exc:
|
| 152 |
+
if DEBUG:
|
| 153 |
+
sys.stderr.write("error: %s\n" % (exc,))
|
| 154 |
+
raise
|
| 155 |
+
else:
|
| 156 |
+
raise SystemExit("error: %s" % (exc,))
|
| 157 |
+
|
| 158 |
+
except (DistutilsError,
|
| 159 |
+
CCompilerError) as msg:
|
| 160 |
+
if DEBUG:
|
| 161 |
+
raise
|
| 162 |
+
else:
|
| 163 |
+
raise SystemExit("error: " + str(msg))
|
| 164 |
+
|
| 165 |
+
return dist
|
| 166 |
+
|
| 167 |
+
# setup ()
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def run_setup (script_name, script_args=None, stop_after="run"):
|
| 171 |
+
"""Run a setup script in a somewhat controlled environment, and
|
| 172 |
+
return the Distribution instance that drives things. This is useful
|
| 173 |
+
if you need to find out the distribution meta-data (passed as
|
| 174 |
+
keyword args from 'script' to 'setup()', or the contents of the
|
| 175 |
+
config files or command-line.
|
| 176 |
+
|
| 177 |
+
'script_name' is a file that will be read and run with 'exec()';
|
| 178 |
+
'sys.argv[0]' will be replaced with 'script' for the duration of the
|
| 179 |
+
call. 'script_args' is a list of strings; if supplied,
|
| 180 |
+
'sys.argv[1:]' will be replaced by 'script_args' for the duration of
|
| 181 |
+
the call.
|
| 182 |
+
|
| 183 |
+
'stop_after' tells 'setup()' when to stop processing; possible
|
| 184 |
+
values:
|
| 185 |
+
init
|
| 186 |
+
stop after the Distribution instance has been created and
|
| 187 |
+
populated with the keyword arguments to 'setup()'
|
| 188 |
+
config
|
| 189 |
+
stop after config files have been parsed (and their data
|
| 190 |
+
stored in the Distribution instance)
|
| 191 |
+
commandline
|
| 192 |
+
stop after the command-line ('sys.argv[1:]' or 'script_args')
|
| 193 |
+
have been parsed (and the data stored in the Distribution)
|
| 194 |
+
run [default]
|
| 195 |
+
stop after all commands have been run (the same as if 'setup()'
|
| 196 |
+
had been called in the usual way
|
| 197 |
+
|
| 198 |
+
Returns the Distribution instance, which provides all information
|
| 199 |
+
used to drive the Distutils.
|
| 200 |
+
"""
|
| 201 |
+
if stop_after not in ('init', 'config', 'commandline', 'run'):
|
| 202 |
+
raise ValueError("invalid value for 'stop_after': %r" % (stop_after,))
|
| 203 |
+
|
| 204 |
+
global _setup_stop_after, _setup_distribution
|
| 205 |
+
_setup_stop_after = stop_after
|
| 206 |
+
|
| 207 |
+
save_argv = sys.argv.copy()
|
| 208 |
+
g = {'__file__': script_name}
|
| 209 |
+
try:
|
| 210 |
+
try:
|
| 211 |
+
sys.argv[0] = script_name
|
| 212 |
+
if script_args is not None:
|
| 213 |
+
sys.argv[1:] = script_args
|
| 214 |
+
with open(script_name, 'rb') as f:
|
| 215 |
+
exec(f.read(), g)
|
| 216 |
+
finally:
|
| 217 |
+
sys.argv = save_argv
|
| 218 |
+
_setup_stop_after = None
|
| 219 |
+
except SystemExit:
|
| 220 |
+
# Hmm, should we do something if exiting with a non-zero code
|
| 221 |
+
# (ie. error)?
|
| 222 |
+
pass
|
| 223 |
+
|
| 224 |
+
if _setup_distribution is None:
|
| 225 |
+
raise RuntimeError(("'distutils.core.setup()' was never called -- "
|
| 226 |
+
"perhaps '%s' is not a Distutils setup script?") % \
|
| 227 |
+
script_name)
|
| 228 |
+
|
| 229 |
+
# I wonder if the setup script's namespace -- g and l -- would be of
|
| 230 |
+
# any interest to callers?
|
| 231 |
+
#print "_setup_distribution:", _setup_distribution
|
| 232 |
+
return _setup_distribution
|
| 233 |
+
|
| 234 |
+
# run_setup ()
|
data/conda_envs/evalclaw/lib/python3.11/distutils/cygwinccompiler.py
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.cygwinccompiler
|
| 2 |
+
|
| 3 |
+
Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
|
| 4 |
+
handles the Cygwin port of the GNU C compiler to Windows. It also contains
|
| 5 |
+
the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
|
| 6 |
+
cygwin in no-cygwin mode).
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
# problems:
|
| 10 |
+
#
|
| 11 |
+
# * if you use a msvc compiled python version (1.5.2)
|
| 12 |
+
# 1. you have to insert a __GNUC__ section in its config.h
|
| 13 |
+
# 2. you have to generate an import library for its dll
|
| 14 |
+
# - create a def-file for python??.dll
|
| 15 |
+
# - create an import library using
|
| 16 |
+
# dlltool --dllname python15.dll --def python15.def \
|
| 17 |
+
# --output-lib libpython15.a
|
| 18 |
+
#
|
| 19 |
+
# see also http://starship.python.net/crew/kernr/mingw32/Notes.html
|
| 20 |
+
#
|
| 21 |
+
# * We put export_symbols in a def-file, and don't use
|
| 22 |
+
# --export-all-symbols because it doesn't worked reliable in some
|
| 23 |
+
# tested configurations. And because other windows compilers also
|
| 24 |
+
# need their symbols specified this no serious problem.
|
| 25 |
+
#
|
| 26 |
+
# tested configurations:
|
| 27 |
+
#
|
| 28 |
+
# * cygwin gcc 2.91.57/ld 2.9.4/dllwrap 0.2.4 works
|
| 29 |
+
# (after patching python's config.h and for C++ some other include files)
|
| 30 |
+
# see also http://starship.python.net/crew/kernr/mingw32/Notes.html
|
| 31 |
+
# * mingw32 gcc 2.95.2/ld 2.9.4/dllwrap 0.2.4 works
|
| 32 |
+
# (ld doesn't support -shared, so we use dllwrap)
|
| 33 |
+
# * cygwin gcc 2.95.2/ld 2.10.90/dllwrap 2.10.90 works now
|
| 34 |
+
# - its dllwrap doesn't work, there is a bug in binutils 2.10.90
|
| 35 |
+
# see also http://sources.redhat.com/ml/cygwin/2000-06/msg01274.html
|
| 36 |
+
# - using gcc -mdll instead dllwrap doesn't work without -static because
|
| 37 |
+
# it tries to link against dlls instead their import libraries. (If
|
| 38 |
+
# it finds the dll first.)
|
| 39 |
+
# By specifying -static we force ld to link against the import libraries,
|
| 40 |
+
# this is windows standard and there are normally not the necessary symbols
|
| 41 |
+
# in the dlls.
|
| 42 |
+
# *** only the version of June 2000 shows these problems
|
| 43 |
+
# * cygwin gcc 3.2/ld 2.13.90 works
|
| 44 |
+
# (ld supports -shared)
|
| 45 |
+
# * mingw gcc 3.2/ld 2.13 works
|
| 46 |
+
# (ld supports -shared)
|
| 47 |
+
|
| 48 |
+
import os
|
| 49 |
+
import sys
|
| 50 |
+
import copy
|
| 51 |
+
from subprocess import Popen, PIPE, check_output
|
| 52 |
+
import re
|
| 53 |
+
|
| 54 |
+
from distutils.unixccompiler import UnixCCompiler
|
| 55 |
+
from distutils.file_util import write_file
|
| 56 |
+
from distutils.errors import (DistutilsExecError, CCompilerError,
|
| 57 |
+
CompileError, UnknownFileError)
|
| 58 |
+
from distutils.version import LooseVersion
|
| 59 |
+
from distutils.spawn import find_executable
|
| 60 |
+
|
| 61 |
+
def get_msvcr():
|
| 62 |
+
"""Include the appropriate MSVC runtime library if Python was built
|
| 63 |
+
with MSVC 7.0 or later.
|
| 64 |
+
"""
|
| 65 |
+
msc_pos = sys.version.find('MSC v.')
|
| 66 |
+
if msc_pos != -1:
|
| 67 |
+
msc_ver = sys.version[msc_pos+6:msc_pos+10]
|
| 68 |
+
if msc_ver == '1300':
|
| 69 |
+
# MSVC 7.0
|
| 70 |
+
return ['msvcr70']
|
| 71 |
+
elif msc_ver == '1310':
|
| 72 |
+
# MSVC 7.1
|
| 73 |
+
return ['msvcr71']
|
| 74 |
+
elif msc_ver == '1400':
|
| 75 |
+
# VS2005 / MSVC 8.0
|
| 76 |
+
return ['msvcr80']
|
| 77 |
+
elif msc_ver == '1500':
|
| 78 |
+
# VS2008 / MSVC 9.0
|
| 79 |
+
return ['msvcr90']
|
| 80 |
+
elif msc_ver == '1600':
|
| 81 |
+
# VS2010 / MSVC 10.0
|
| 82 |
+
return ['msvcr100']
|
| 83 |
+
elif int(msc_ver) >= 1900:
|
| 84 |
+
# VS2015 / MSVC 14.0
|
| 85 |
+
return ['msvcr140']
|
| 86 |
+
else:
|
| 87 |
+
raise ValueError("Unknown MS Compiler version %s " % msc_ver)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class CygwinCCompiler(UnixCCompiler):
|
| 91 |
+
""" Handles the Cygwin port of the GNU C compiler to Windows.
|
| 92 |
+
"""
|
| 93 |
+
compiler_type = 'cygwin'
|
| 94 |
+
obj_extension = ".o"
|
| 95 |
+
static_lib_extension = ".a"
|
| 96 |
+
shared_lib_extension = ".dll"
|
| 97 |
+
static_lib_format = "lib%s%s"
|
| 98 |
+
shared_lib_format = "%s%s"
|
| 99 |
+
exe_extension = ".exe"
|
| 100 |
+
|
| 101 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
| 102 |
+
|
| 103 |
+
UnixCCompiler.__init__(self, verbose, dry_run, force)
|
| 104 |
+
|
| 105 |
+
status, details = check_config_h()
|
| 106 |
+
self.debug_print("Python's GCC status: %s (details: %s)" %
|
| 107 |
+
(status, details))
|
| 108 |
+
if status is not CONFIG_H_OK:
|
| 109 |
+
self.warn(
|
| 110 |
+
"Python's pyconfig.h doesn't seem to support your compiler. "
|
| 111 |
+
"Reason: %s. "
|
| 112 |
+
"Compiling may fail because of undefined preprocessor macros."
|
| 113 |
+
% details)
|
| 114 |
+
|
| 115 |
+
self.gcc_version, self.ld_version, self.dllwrap_version = \
|
| 116 |
+
get_versions()
|
| 117 |
+
self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
|
| 118 |
+
(self.gcc_version,
|
| 119 |
+
self.ld_version,
|
| 120 |
+
self.dllwrap_version) )
|
| 121 |
+
|
| 122 |
+
# ld_version >= "2.10.90" and < "2.13" should also be able to use
|
| 123 |
+
# gcc -mdll instead of dllwrap
|
| 124 |
+
# Older dllwraps had own version numbers, newer ones use the
|
| 125 |
+
# same as the rest of binutils ( also ld )
|
| 126 |
+
# dllwrap 2.10.90 is buggy
|
| 127 |
+
if self.ld_version >= "2.10.90":
|
| 128 |
+
self.linker_dll = "gcc"
|
| 129 |
+
else:
|
| 130 |
+
self.linker_dll = "dllwrap"
|
| 131 |
+
|
| 132 |
+
# ld_version >= "2.13" support -shared so use it instead of
|
| 133 |
+
# -mdll -static
|
| 134 |
+
if self.ld_version >= "2.13":
|
| 135 |
+
shared_option = "-shared"
|
| 136 |
+
else:
|
| 137 |
+
shared_option = "-mdll -static"
|
| 138 |
+
|
| 139 |
+
# Hard-code GCC because that's what this is all about.
|
| 140 |
+
# XXX optimization, warnings etc. should be customizable.
|
| 141 |
+
self.set_executables(compiler='gcc -mcygwin -O -Wall',
|
| 142 |
+
compiler_so='gcc -mcygwin -mdll -O -Wall',
|
| 143 |
+
compiler_cxx='g++ -mcygwin -O -Wall',
|
| 144 |
+
linker_exe='gcc -mcygwin',
|
| 145 |
+
linker_so=('%s -mcygwin %s' %
|
| 146 |
+
(self.linker_dll, shared_option)))
|
| 147 |
+
|
| 148 |
+
# cygwin and mingw32 need different sets of libraries
|
| 149 |
+
if self.gcc_version == "2.91.57":
|
| 150 |
+
# cygwin shouldn't need msvcrt, but without the dlls will crash
|
| 151 |
+
# (gcc version 2.91.57) -- perhaps something about initialization
|
| 152 |
+
self.dll_libraries=["msvcrt"]
|
| 153 |
+
self.warn(
|
| 154 |
+
"Consider upgrading to a newer version of gcc")
|
| 155 |
+
else:
|
| 156 |
+
# Include the appropriate MSVC runtime library if Python was built
|
| 157 |
+
# with MSVC 7.0 or later.
|
| 158 |
+
self.dll_libraries = get_msvcr()
|
| 159 |
+
|
| 160 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
| 161 |
+
"""Compiles the source by spawning GCC and windres if needed."""
|
| 162 |
+
if ext == '.rc' or ext == '.res':
|
| 163 |
+
# gcc needs '.res' and '.rc' compiled to object files !!!
|
| 164 |
+
try:
|
| 165 |
+
self.spawn(["windres", "-i", src, "-o", obj])
|
| 166 |
+
except DistutilsExecError as msg:
|
| 167 |
+
raise CompileError(msg)
|
| 168 |
+
else: # for other files use the C-compiler
|
| 169 |
+
try:
|
| 170 |
+
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
|
| 171 |
+
extra_postargs)
|
| 172 |
+
except DistutilsExecError as msg:
|
| 173 |
+
raise CompileError(msg)
|
| 174 |
+
|
| 175 |
+
def link(self, target_desc, objects, output_filename, output_dir=None,
|
| 176 |
+
libraries=None, library_dirs=None, runtime_library_dirs=None,
|
| 177 |
+
export_symbols=None, debug=0, extra_preargs=None,
|
| 178 |
+
extra_postargs=None, build_temp=None, target_lang=None):
|
| 179 |
+
"""Link the objects."""
|
| 180 |
+
# use separate copies, so we can modify the lists
|
| 181 |
+
extra_preargs = copy.copy(extra_preargs or [])
|
| 182 |
+
libraries = copy.copy(libraries or [])
|
| 183 |
+
objects = copy.copy(objects or [])
|
| 184 |
+
|
| 185 |
+
# Additional libraries
|
| 186 |
+
libraries.extend(self.dll_libraries)
|
| 187 |
+
|
| 188 |
+
# handle export symbols by creating a def-file
|
| 189 |
+
# with executables this only works with gcc/ld as linker
|
| 190 |
+
if ((export_symbols is not None) and
|
| 191 |
+
(target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
| 192 |
+
# (The linker doesn't do anything if output is up-to-date.
|
| 193 |
+
# So it would probably better to check if we really need this,
|
| 194 |
+
# but for this we had to insert some unchanged parts of
|
| 195 |
+
# UnixCCompiler, and this is not what we want.)
|
| 196 |
+
|
| 197 |
+
# we want to put some files in the same directory as the
|
| 198 |
+
# object files are, build_temp doesn't help much
|
| 199 |
+
# where are the object files
|
| 200 |
+
temp_dir = os.path.dirname(objects[0])
|
| 201 |
+
# name of dll to give the helper files the same base name
|
| 202 |
+
(dll_name, dll_extension) = os.path.splitext(
|
| 203 |
+
os.path.basename(output_filename))
|
| 204 |
+
|
| 205 |
+
# generate the filenames for these files
|
| 206 |
+
def_file = os.path.join(temp_dir, dll_name + ".def")
|
| 207 |
+
lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
|
| 208 |
+
|
| 209 |
+
# Generate .def file
|
| 210 |
+
contents = [
|
| 211 |
+
"LIBRARY %s" % os.path.basename(output_filename),
|
| 212 |
+
"EXPORTS"]
|
| 213 |
+
for sym in export_symbols:
|
| 214 |
+
contents.append(sym)
|
| 215 |
+
self.execute(write_file, (def_file, contents),
|
| 216 |
+
"writing %s" % def_file)
|
| 217 |
+
|
| 218 |
+
# next add options for def-file and to creating import libraries
|
| 219 |
+
|
| 220 |
+
# dllwrap uses different options than gcc/ld
|
| 221 |
+
if self.linker_dll == "dllwrap":
|
| 222 |
+
extra_preargs.extend(["--output-lib", lib_file])
|
| 223 |
+
# for dllwrap we have to use a special option
|
| 224 |
+
extra_preargs.extend(["--def", def_file])
|
| 225 |
+
# we use gcc/ld here and can be sure ld is >= 2.9.10
|
| 226 |
+
else:
|
| 227 |
+
# doesn't work: bfd_close build\...\libfoo.a: Invalid operation
|
| 228 |
+
#extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
|
| 229 |
+
# for gcc/ld the def-file is specified as any object files
|
| 230 |
+
objects.append(def_file)
|
| 231 |
+
|
| 232 |
+
#end: if ((export_symbols is not None) and
|
| 233 |
+
# (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
| 234 |
+
|
| 235 |
+
# who wants symbols and a many times larger output file
|
| 236 |
+
# should explicitly switch the debug mode on
|
| 237 |
+
# otherwise we let dllwrap/ld strip the output file
|
| 238 |
+
# (On my machine: 10KiB < stripped_file < ??100KiB
|
| 239 |
+
# unstripped_file = stripped_file + XXX KiB
|
| 240 |
+
# ( XXX=254 for a typical python extension))
|
| 241 |
+
if not debug:
|
| 242 |
+
extra_preargs.append("-s")
|
| 243 |
+
|
| 244 |
+
UnixCCompiler.link(self, target_desc, objects, output_filename,
|
| 245 |
+
output_dir, libraries, library_dirs,
|
| 246 |
+
runtime_library_dirs,
|
| 247 |
+
None, # export_symbols, we do this in our def-file
|
| 248 |
+
debug, extra_preargs, extra_postargs, build_temp,
|
| 249 |
+
target_lang)
|
| 250 |
+
|
| 251 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 252 |
+
|
| 253 |
+
def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
|
| 254 |
+
"""Adds supports for rc and res files."""
|
| 255 |
+
if output_dir is None:
|
| 256 |
+
output_dir = ''
|
| 257 |
+
obj_names = []
|
| 258 |
+
for src_name in source_filenames:
|
| 259 |
+
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
|
| 260 |
+
base, ext = os.path.splitext(os.path.normcase(src_name))
|
| 261 |
+
if ext not in (self.src_extensions + ['.rc','.res']):
|
| 262 |
+
raise UnknownFileError("unknown file type '%s' (from '%s')" % \
|
| 263 |
+
(ext, src_name))
|
| 264 |
+
if strip_dir:
|
| 265 |
+
base = os.path.basename (base)
|
| 266 |
+
if ext in ('.res', '.rc'):
|
| 267 |
+
# these need to be compiled to object files
|
| 268 |
+
obj_names.append (os.path.join(output_dir,
|
| 269 |
+
base + ext + self.obj_extension))
|
| 270 |
+
else:
|
| 271 |
+
obj_names.append (os.path.join(output_dir,
|
| 272 |
+
base + self.obj_extension))
|
| 273 |
+
return obj_names
|
| 274 |
+
|
| 275 |
+
# the same as cygwin plus some additional parameters
|
| 276 |
+
class Mingw32CCompiler(CygwinCCompiler):
|
| 277 |
+
""" Handles the Mingw32 port of the GNU C compiler to Windows.
|
| 278 |
+
"""
|
| 279 |
+
compiler_type = 'mingw32'
|
| 280 |
+
|
| 281 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
| 282 |
+
|
| 283 |
+
CygwinCCompiler.__init__ (self, verbose, dry_run, force)
|
| 284 |
+
|
| 285 |
+
# ld_version >= "2.13" support -shared so use it instead of
|
| 286 |
+
# -mdll -static
|
| 287 |
+
if self.ld_version >= "2.13":
|
| 288 |
+
shared_option = "-shared"
|
| 289 |
+
else:
|
| 290 |
+
shared_option = "-mdll -static"
|
| 291 |
+
|
| 292 |
+
# A real mingw32 doesn't need to specify a different entry point,
|
| 293 |
+
# but cygwin 2.91.57 in no-cygwin-mode needs it.
|
| 294 |
+
if self.gcc_version <= "2.91.57":
|
| 295 |
+
entry_point = '--entry _DllMain@12'
|
| 296 |
+
else:
|
| 297 |
+
entry_point = ''
|
| 298 |
+
|
| 299 |
+
if is_cygwingcc():
|
| 300 |
+
raise CCompilerError(
|
| 301 |
+
'Cygwin gcc cannot be used with --compiler=mingw32')
|
| 302 |
+
|
| 303 |
+
self.set_executables(compiler='gcc -O -Wall',
|
| 304 |
+
compiler_so='gcc -mdll -O -Wall',
|
| 305 |
+
compiler_cxx='g++ -O -Wall',
|
| 306 |
+
linker_exe='gcc',
|
| 307 |
+
linker_so='%s %s %s'
|
| 308 |
+
% (self.linker_dll, shared_option,
|
| 309 |
+
entry_point))
|
| 310 |
+
# Maybe we should also append -mthreads, but then the finished
|
| 311 |
+
# dlls need another dll (mingwm10.dll see Mingw32 docs)
|
| 312 |
+
# (-mthreads: Support thread-safe exception handling on `Mingw32')
|
| 313 |
+
|
| 314 |
+
# no additional libraries needed
|
| 315 |
+
self.dll_libraries=[]
|
| 316 |
+
|
| 317 |
+
# Include the appropriate MSVC runtime library if Python was built
|
| 318 |
+
# with MSVC 7.0 or later.
|
| 319 |
+
self.dll_libraries = get_msvcr()
|
| 320 |
+
|
| 321 |
+
# Because these compilers aren't configured in Python's pyconfig.h file by
|
| 322 |
+
# default, we should at least warn the user if he is using an unmodified
|
| 323 |
+
# version.
|
| 324 |
+
|
| 325 |
+
CONFIG_H_OK = "ok"
|
| 326 |
+
CONFIG_H_NOTOK = "not ok"
|
| 327 |
+
CONFIG_H_UNCERTAIN = "uncertain"
|
| 328 |
+
|
| 329 |
+
def check_config_h():
|
| 330 |
+
"""Check if the current Python installation appears amenable to building
|
| 331 |
+
extensions with GCC.
|
| 332 |
+
|
| 333 |
+
Returns a tuple (status, details), where 'status' is one of the following
|
| 334 |
+
constants:
|
| 335 |
+
|
| 336 |
+
- CONFIG_H_OK: all is well, go ahead and compile
|
| 337 |
+
- CONFIG_H_NOTOK: doesn't look good
|
| 338 |
+
- CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h
|
| 339 |
+
|
| 340 |
+
'details' is a human-readable string explaining the situation.
|
| 341 |
+
|
| 342 |
+
Note there are two ways to conclude "OK": either 'sys.version' contains
|
| 343 |
+
the string "GCC" (implying that this Python was built with GCC), or the
|
| 344 |
+
installed "pyconfig.h" contains the string "__GNUC__".
|
| 345 |
+
"""
|
| 346 |
+
|
| 347 |
+
# XXX since this function also checks sys.version, it's not strictly a
|
| 348 |
+
# "pyconfig.h" check -- should probably be renamed...
|
| 349 |
+
|
| 350 |
+
from distutils import sysconfig
|
| 351 |
+
|
| 352 |
+
# if sys.version contains GCC then python was compiled with GCC, and the
|
| 353 |
+
# pyconfig.h file should be OK
|
| 354 |
+
if "GCC" in sys.version:
|
| 355 |
+
return CONFIG_H_OK, "sys.version mentions 'GCC'"
|
| 356 |
+
|
| 357 |
+
# let's see if __GNUC__ is mentioned in python.h
|
| 358 |
+
fn = sysconfig.get_config_h_filename()
|
| 359 |
+
try:
|
| 360 |
+
config_h = open(fn)
|
| 361 |
+
try:
|
| 362 |
+
if "__GNUC__" in config_h.read():
|
| 363 |
+
return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn
|
| 364 |
+
else:
|
| 365 |
+
return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn
|
| 366 |
+
finally:
|
| 367 |
+
config_h.close()
|
| 368 |
+
except OSError as exc:
|
| 369 |
+
return (CONFIG_H_UNCERTAIN,
|
| 370 |
+
"couldn't read '%s': %s" % (fn, exc.strerror))
|
| 371 |
+
|
| 372 |
+
RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)')
|
| 373 |
+
|
| 374 |
+
def _find_exe_version(cmd):
|
| 375 |
+
"""Find the version of an executable by running `cmd` in the shell.
|
| 376 |
+
|
| 377 |
+
If the command is not found, or the output does not match
|
| 378 |
+
`RE_VERSION`, returns None.
|
| 379 |
+
"""
|
| 380 |
+
executable = cmd.split()[0]
|
| 381 |
+
if find_executable(executable) is None:
|
| 382 |
+
return None
|
| 383 |
+
out = Popen(cmd, shell=True, stdout=PIPE).stdout
|
| 384 |
+
try:
|
| 385 |
+
out_string = out.read()
|
| 386 |
+
finally:
|
| 387 |
+
out.close()
|
| 388 |
+
result = RE_VERSION.search(out_string)
|
| 389 |
+
if result is None:
|
| 390 |
+
return None
|
| 391 |
+
# LooseVersion works with strings
|
| 392 |
+
# so we need to decode our bytes
|
| 393 |
+
return LooseVersion(result.group(1).decode())
|
| 394 |
+
|
| 395 |
+
def get_versions():
|
| 396 |
+
""" Try to find out the versions of gcc, ld and dllwrap.
|
| 397 |
+
|
| 398 |
+
If not possible it returns None for it.
|
| 399 |
+
"""
|
| 400 |
+
commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
|
| 401 |
+
return tuple([_find_exe_version(cmd) for cmd in commands])
|
| 402 |
+
|
| 403 |
+
def is_cygwingcc():
|
| 404 |
+
'''Try to determine if the gcc that would be used is from cygwin.'''
|
| 405 |
+
out_string = check_output(['gcc', '-dumpmachine'])
|
| 406 |
+
return out_string.strip().endswith(b'cygwin')
|
data/conda_envs/evalclaw/lib/python3.11/distutils/debug.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
# If DISTUTILS_DEBUG is anything other than the empty string, we run in
|
| 4 |
+
# debug mode.
|
| 5 |
+
DEBUG = os.environ.get('DISTUTILS_DEBUG')
|
data/conda_envs/evalclaw/lib/python3.11/distutils/dep_util.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.dep_util
|
| 2 |
+
|
| 3 |
+
Utility functions for simple, timestamp-based dependency of files
|
| 4 |
+
and groups of files; also, function based entirely on such
|
| 5 |
+
timestamp dependency analysis."""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
from distutils.errors import DistutilsFileError
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def newer (source, target):
|
| 12 |
+
"""Return true if 'source' exists and is more recently modified than
|
| 13 |
+
'target', or if 'source' exists and 'target' doesn't. Return false if
|
| 14 |
+
both exist and 'target' is the same age or younger than 'source'.
|
| 15 |
+
Raise DistutilsFileError if 'source' does not exist.
|
| 16 |
+
"""
|
| 17 |
+
if not os.path.exists(source):
|
| 18 |
+
raise DistutilsFileError("file '%s' does not exist" %
|
| 19 |
+
os.path.abspath(source))
|
| 20 |
+
if not os.path.exists(target):
|
| 21 |
+
return 1
|
| 22 |
+
|
| 23 |
+
from stat import ST_MTIME
|
| 24 |
+
mtime1 = os.stat(source)[ST_MTIME]
|
| 25 |
+
mtime2 = os.stat(target)[ST_MTIME]
|
| 26 |
+
|
| 27 |
+
return mtime1 > mtime2
|
| 28 |
+
|
| 29 |
+
# newer ()
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def newer_pairwise (sources, targets):
|
| 33 |
+
"""Walk two filename lists in parallel, testing if each source is newer
|
| 34 |
+
than its corresponding target. Return a pair of lists (sources,
|
| 35 |
+
targets) where source is newer than target, according to the semantics
|
| 36 |
+
of 'newer()'.
|
| 37 |
+
"""
|
| 38 |
+
if len(sources) != len(targets):
|
| 39 |
+
raise ValueError("'sources' and 'targets' must be same length")
|
| 40 |
+
|
| 41 |
+
# build a pair of lists (sources, targets) where source is newer
|
| 42 |
+
n_sources = []
|
| 43 |
+
n_targets = []
|
| 44 |
+
for i in range(len(sources)):
|
| 45 |
+
if newer(sources[i], targets[i]):
|
| 46 |
+
n_sources.append(sources[i])
|
| 47 |
+
n_targets.append(targets[i])
|
| 48 |
+
|
| 49 |
+
return (n_sources, n_targets)
|
| 50 |
+
|
| 51 |
+
# newer_pairwise ()
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def newer_group (sources, target, missing='error'):
|
| 55 |
+
"""Return true if 'target' is out-of-date with respect to any file
|
| 56 |
+
listed in 'sources'. In other words, if 'target' exists and is newer
|
| 57 |
+
than every file in 'sources', return false; otherwise return true.
|
| 58 |
+
'missing' controls what we do when a source file is missing; the
|
| 59 |
+
default ("error") is to blow up with an OSError from inside 'stat()';
|
| 60 |
+
if it is "ignore", we silently drop any missing source files; if it is
|
| 61 |
+
"newer", any missing source files make us assume that 'target' is
|
| 62 |
+
out-of-date (this is handy in "dry-run" mode: it'll make you pretend to
|
| 63 |
+
carry out commands that wouldn't work because inputs are missing, but
|
| 64 |
+
that doesn't matter because you're not actually going to run the
|
| 65 |
+
commands).
|
| 66 |
+
"""
|
| 67 |
+
# If the target doesn't even exist, then it's definitely out-of-date.
|
| 68 |
+
if not os.path.exists(target):
|
| 69 |
+
return 1
|
| 70 |
+
|
| 71 |
+
# Otherwise we have to find out the hard way: if *any* source file
|
| 72 |
+
# is more recent than 'target', then 'target' is out-of-date and
|
| 73 |
+
# we can immediately return true. If we fall through to the end
|
| 74 |
+
# of the loop, then 'target' is up-to-date and we return false.
|
| 75 |
+
from stat import ST_MTIME
|
| 76 |
+
target_mtime = os.stat(target)[ST_MTIME]
|
| 77 |
+
for source in sources:
|
| 78 |
+
if not os.path.exists(source):
|
| 79 |
+
if missing == 'error': # blow up when we stat() the file
|
| 80 |
+
pass
|
| 81 |
+
elif missing == 'ignore': # missing source dropped from
|
| 82 |
+
continue # target's dependency list
|
| 83 |
+
elif missing == 'newer': # missing source means target is
|
| 84 |
+
return 1 # out-of-date
|
| 85 |
+
|
| 86 |
+
source_mtime = os.stat(source)[ST_MTIME]
|
| 87 |
+
if source_mtime > target_mtime:
|
| 88 |
+
return 1
|
| 89 |
+
else:
|
| 90 |
+
return 0
|
| 91 |
+
|
| 92 |
+
# newer_group ()
|
data/conda_envs/evalclaw/lib/python3.11/distutils/dir_util.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import errno
|
| 7 |
+
from distutils.errors import DistutilsFileError, DistutilsInternalError
|
| 8 |
+
from distutils import log
|
| 9 |
+
|
| 10 |
+
# cache for by mkpath() -- in addition to cheapening redundant calls,
|
| 11 |
+
# eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
|
| 12 |
+
_path_created = {}
|
| 13 |
+
|
| 14 |
+
# I don't use os.makedirs because a) it's new to Python 1.5.2, and
|
| 15 |
+
# b) it blows up if the directory already exists (I want to silently
|
| 16 |
+
# succeed in that case).
|
| 17 |
+
def mkpath(name, mode=0o777, verbose=1, dry_run=0):
|
| 18 |
+
"""Create a directory and any missing ancestor directories.
|
| 19 |
+
|
| 20 |
+
If the directory already exists (or if 'name' is the empty string, which
|
| 21 |
+
means the current directory, which of course exists), then do nothing.
|
| 22 |
+
Raise DistutilsFileError if unable to create some directory along the way
|
| 23 |
+
(eg. some sub-path exists, but is a file rather than a directory).
|
| 24 |
+
If 'verbose' is true, print a one-line summary of each mkdir to stdout.
|
| 25 |
+
Return the list of directories actually created.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
global _path_created
|
| 29 |
+
|
| 30 |
+
# Detect a common bug -- name is None
|
| 31 |
+
if not isinstance(name, str):
|
| 32 |
+
raise DistutilsInternalError(
|
| 33 |
+
"mkpath: 'name' must be a string (got %r)" % (name,))
|
| 34 |
+
|
| 35 |
+
# XXX what's the better way to handle verbosity? print as we create
|
| 36 |
+
# each directory in the path (the current behaviour), or only announce
|
| 37 |
+
# the creation of the whole path? (quite easy to do the latter since
|
| 38 |
+
# we're not using a recursive algorithm)
|
| 39 |
+
|
| 40 |
+
name = os.path.normpath(name)
|
| 41 |
+
created_dirs = []
|
| 42 |
+
if os.path.isdir(name) or name == '':
|
| 43 |
+
return created_dirs
|
| 44 |
+
if _path_created.get(os.path.abspath(name)):
|
| 45 |
+
return created_dirs
|
| 46 |
+
|
| 47 |
+
(head, tail) = os.path.split(name)
|
| 48 |
+
tails = [tail] # stack of lone dirs to create
|
| 49 |
+
|
| 50 |
+
while head and tail and not os.path.isdir(head):
|
| 51 |
+
(head, tail) = os.path.split(head)
|
| 52 |
+
tails.insert(0, tail) # push next higher dir onto stack
|
| 53 |
+
|
| 54 |
+
# now 'head' contains the deepest directory that already exists
|
| 55 |
+
# (that is, the child of 'head' in 'name' is the highest directory
|
| 56 |
+
# that does *not* exist)
|
| 57 |
+
for d in tails:
|
| 58 |
+
#print "head = %s, d = %s: " % (head, d),
|
| 59 |
+
head = os.path.join(head, d)
|
| 60 |
+
abs_head = os.path.abspath(head)
|
| 61 |
+
|
| 62 |
+
if _path_created.get(abs_head):
|
| 63 |
+
continue
|
| 64 |
+
|
| 65 |
+
if verbose >= 1:
|
| 66 |
+
log.info("creating %s", head)
|
| 67 |
+
|
| 68 |
+
if not dry_run:
|
| 69 |
+
try:
|
| 70 |
+
os.mkdir(head, mode)
|
| 71 |
+
except OSError as exc:
|
| 72 |
+
if not (exc.errno == errno.EEXIST and os.path.isdir(head)):
|
| 73 |
+
raise DistutilsFileError(
|
| 74 |
+
"could not create '%s': %s" % (head, exc.args[-1]))
|
| 75 |
+
created_dirs.append(head)
|
| 76 |
+
|
| 77 |
+
_path_created[abs_head] = 1
|
| 78 |
+
return created_dirs
|
| 79 |
+
|
| 80 |
+
def create_tree(base_dir, files, mode=0o777, verbose=1, dry_run=0):
|
| 81 |
+
"""Create all the empty directories under 'base_dir' needed to put 'files'
|
| 82 |
+
there.
|
| 83 |
+
|
| 84 |
+
'base_dir' is just the name of a directory which doesn't necessarily
|
| 85 |
+
exist yet; 'files' is a list of filenames to be interpreted relative to
|
| 86 |
+
'base_dir'. 'base_dir' + the directory portion of every file in 'files'
|
| 87 |
+
will be created if it doesn't already exist. 'mode', 'verbose' and
|
| 88 |
+
'dry_run' flags are as for 'mkpath()'.
|
| 89 |
+
"""
|
| 90 |
+
# First get the list of directories to create
|
| 91 |
+
need_dir = set()
|
| 92 |
+
for file in files:
|
| 93 |
+
need_dir.add(os.path.join(base_dir, os.path.dirname(file)))
|
| 94 |
+
|
| 95 |
+
# Now create them
|
| 96 |
+
for dir in sorted(need_dir):
|
| 97 |
+
mkpath(dir, mode, verbose=verbose, dry_run=dry_run)
|
| 98 |
+
|
| 99 |
+
def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
|
| 100 |
+
preserve_symlinks=0, update=0, verbose=1, dry_run=0):
|
| 101 |
+
"""Copy an entire directory tree 'src' to a new location 'dst'.
|
| 102 |
+
|
| 103 |
+
Both 'src' and 'dst' must be directory names. If 'src' is not a
|
| 104 |
+
directory, raise DistutilsFileError. If 'dst' does not exist, it is
|
| 105 |
+
created with 'mkpath()'. The end result of the copy is that every
|
| 106 |
+
file in 'src' is copied to 'dst', and directories under 'src' are
|
| 107 |
+
recursively copied to 'dst'. Return the list of files that were
|
| 108 |
+
copied or might have been copied, using their output name. The
|
| 109 |
+
return value is unaffected by 'update' or 'dry_run': it is simply
|
| 110 |
+
the list of all files under 'src', with the names changed to be
|
| 111 |
+
under 'dst'.
|
| 112 |
+
|
| 113 |
+
'preserve_mode' and 'preserve_times' are the same as for
|
| 114 |
+
'copy_file'; note that they only apply to regular files, not to
|
| 115 |
+
directories. If 'preserve_symlinks' is true, symlinks will be
|
| 116 |
+
copied as symlinks (on platforms that support them!); otherwise
|
| 117 |
+
(the default), the destination of the symlink will be copied.
|
| 118 |
+
'update' and 'verbose' are the same as for 'copy_file'.
|
| 119 |
+
"""
|
| 120 |
+
from distutils.file_util import copy_file
|
| 121 |
+
|
| 122 |
+
if not dry_run and not os.path.isdir(src):
|
| 123 |
+
raise DistutilsFileError(
|
| 124 |
+
"cannot copy tree '%s': not a directory" % src)
|
| 125 |
+
try:
|
| 126 |
+
names = os.listdir(src)
|
| 127 |
+
except OSError as e:
|
| 128 |
+
if dry_run:
|
| 129 |
+
names = []
|
| 130 |
+
else:
|
| 131 |
+
raise DistutilsFileError(
|
| 132 |
+
"error listing files in '%s': %s" % (src, e.strerror))
|
| 133 |
+
|
| 134 |
+
if not dry_run:
|
| 135 |
+
mkpath(dst, verbose=verbose)
|
| 136 |
+
|
| 137 |
+
outputs = []
|
| 138 |
+
|
| 139 |
+
for n in names:
|
| 140 |
+
src_name = os.path.join(src, n)
|
| 141 |
+
dst_name = os.path.join(dst, n)
|
| 142 |
+
|
| 143 |
+
if n.startswith('.nfs'):
|
| 144 |
+
# skip NFS rename files
|
| 145 |
+
continue
|
| 146 |
+
|
| 147 |
+
if preserve_symlinks and os.path.islink(src_name):
|
| 148 |
+
link_dest = os.readlink(src_name)
|
| 149 |
+
if verbose >= 1:
|
| 150 |
+
log.info("linking %s -> %s", dst_name, link_dest)
|
| 151 |
+
if not dry_run:
|
| 152 |
+
os.symlink(link_dest, dst_name)
|
| 153 |
+
outputs.append(dst_name)
|
| 154 |
+
|
| 155 |
+
elif os.path.isdir(src_name):
|
| 156 |
+
outputs.extend(
|
| 157 |
+
copy_tree(src_name, dst_name, preserve_mode,
|
| 158 |
+
preserve_times, preserve_symlinks, update,
|
| 159 |
+
verbose=verbose, dry_run=dry_run))
|
| 160 |
+
else:
|
| 161 |
+
copy_file(src_name, dst_name, preserve_mode,
|
| 162 |
+
preserve_times, update, verbose=verbose,
|
| 163 |
+
dry_run=dry_run)
|
| 164 |
+
outputs.append(dst_name)
|
| 165 |
+
|
| 166 |
+
return outputs
|
| 167 |
+
|
| 168 |
+
def _build_cmdtuple(path, cmdtuples):
|
| 169 |
+
"""Helper for remove_tree()."""
|
| 170 |
+
for f in os.listdir(path):
|
| 171 |
+
real_f = os.path.join(path,f)
|
| 172 |
+
if os.path.isdir(real_f) and not os.path.islink(real_f):
|
| 173 |
+
_build_cmdtuple(real_f, cmdtuples)
|
| 174 |
+
else:
|
| 175 |
+
cmdtuples.append((os.remove, real_f))
|
| 176 |
+
cmdtuples.append((os.rmdir, path))
|
| 177 |
+
|
| 178 |
+
def remove_tree(directory, verbose=1, dry_run=0):
|
| 179 |
+
"""Recursively remove an entire directory tree.
|
| 180 |
+
|
| 181 |
+
Any errors are ignored (apart from being reported to stdout if 'verbose'
|
| 182 |
+
is true).
|
| 183 |
+
"""
|
| 184 |
+
global _path_created
|
| 185 |
+
|
| 186 |
+
if verbose >= 1:
|
| 187 |
+
log.info("removing '%s' (and everything under it)", directory)
|
| 188 |
+
if dry_run:
|
| 189 |
+
return
|
| 190 |
+
cmdtuples = []
|
| 191 |
+
_build_cmdtuple(directory, cmdtuples)
|
| 192 |
+
for cmd in cmdtuples:
|
| 193 |
+
try:
|
| 194 |
+
cmd[0](cmd[1])
|
| 195 |
+
# remove dir from cache if it's already there
|
| 196 |
+
abspath = os.path.abspath(cmd[1])
|
| 197 |
+
if abspath in _path_created:
|
| 198 |
+
del _path_created[abspath]
|
| 199 |
+
except OSError as exc:
|
| 200 |
+
log.warn("error removing %s: %s", directory, exc)
|
| 201 |
+
|
| 202 |
+
def ensure_relative(path):
|
| 203 |
+
"""Take the full path 'path', and make it a relative path.
|
| 204 |
+
|
| 205 |
+
This is useful to make 'path' the second argument to os.path.join().
|
| 206 |
+
"""
|
| 207 |
+
drive, path = os.path.splitdrive(path)
|
| 208 |
+
if path[0:1] == os.sep:
|
| 209 |
+
path = drive + path[1:]
|
| 210 |
+
return path
|
data/conda_envs/evalclaw/lib/python3.11/distutils/dist.py
ADDED
|
@@ -0,0 +1,1256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.dist
|
| 2 |
+
|
| 3 |
+
Provides the Distribution class, which represents the module distribution
|
| 4 |
+
being built/installed/distributed.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
import re
|
| 10 |
+
from email import message_from_file
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
import warnings
|
| 14 |
+
except ImportError:
|
| 15 |
+
warnings = None
|
| 16 |
+
|
| 17 |
+
from distutils.errors import *
|
| 18 |
+
from distutils.fancy_getopt import FancyGetopt, translate_longopt
|
| 19 |
+
from distutils.util import check_environ, strtobool, rfc822_escape
|
| 20 |
+
from distutils import log
|
| 21 |
+
from distutils.debug import DEBUG
|
| 22 |
+
|
| 23 |
+
# Regex to define acceptable Distutils command names. This is not *quite*
|
| 24 |
+
# the same as a Python NAME -- I don't allow leading underscores. The fact
|
| 25 |
+
# that they're very similar is no coincidence; the default naming scheme is
|
| 26 |
+
# to look for a Python module named after the command.
|
| 27 |
+
command_re = re.compile(r'^[a-zA-Z]([a-zA-Z0-9_]*)$')
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _ensure_list(value, fieldname):
|
| 31 |
+
if isinstance(value, str):
|
| 32 |
+
# a string containing comma separated values is okay. It will
|
| 33 |
+
# be converted to a list by Distribution.finalize_options().
|
| 34 |
+
pass
|
| 35 |
+
elif not isinstance(value, list):
|
| 36 |
+
# passing a tuple or an iterator perhaps, warn and convert
|
| 37 |
+
typename = type(value).__name__
|
| 38 |
+
msg = f"Warning: '{fieldname}' should be a list, got type '{typename}'"
|
| 39 |
+
log.log(log.WARN, msg)
|
| 40 |
+
value = list(value)
|
| 41 |
+
return value
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class Distribution:
|
| 45 |
+
"""The core of the Distutils. Most of the work hiding behind 'setup'
|
| 46 |
+
is really done within a Distribution instance, which farms the work out
|
| 47 |
+
to the Distutils commands specified on the command line.
|
| 48 |
+
|
| 49 |
+
Setup scripts will almost never instantiate Distribution directly,
|
| 50 |
+
unless the 'setup()' function is totally inadequate to their needs.
|
| 51 |
+
However, it is conceivable that a setup script might wish to subclass
|
| 52 |
+
Distribution for some specialized purpose, and then pass the subclass
|
| 53 |
+
to 'setup()' as the 'distclass' keyword argument. If so, it is
|
| 54 |
+
necessary to respect the expectations that 'setup' has of Distribution.
|
| 55 |
+
See the code for 'setup()', in core.py, for details.
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
# 'global_options' describes the command-line options that may be
|
| 59 |
+
# supplied to the setup script prior to any actual commands.
|
| 60 |
+
# Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of
|
| 61 |
+
# these global options. This list should be kept to a bare minimum,
|
| 62 |
+
# since every global option is also valid as a command option -- and we
|
| 63 |
+
# don't want to pollute the commands with too many options that they
|
| 64 |
+
# have minimal control over.
|
| 65 |
+
# The fourth entry for verbose means that it can be repeated.
|
| 66 |
+
global_options = [
|
| 67 |
+
('verbose', 'v', "run verbosely (default)", 1),
|
| 68 |
+
('quiet', 'q', "run quietly (turns verbosity off)"),
|
| 69 |
+
('dry-run', 'n', "don't actually do anything"),
|
| 70 |
+
('help', 'h', "show detailed help message"),
|
| 71 |
+
('no-user-cfg', None,
|
| 72 |
+
'ignore pydistutils.cfg in your home directory'),
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
# 'common_usage' is a short (2-3 line) string describing the common
|
| 76 |
+
# usage of the setup script.
|
| 77 |
+
common_usage = """\
|
| 78 |
+
Common commands: (see '--help-commands' for more)
|
| 79 |
+
|
| 80 |
+
setup.py build will build the package underneath 'build/'
|
| 81 |
+
setup.py install will install the package
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
# options that are not propagated to the commands
|
| 85 |
+
display_options = [
|
| 86 |
+
('help-commands', None,
|
| 87 |
+
"list all available commands"),
|
| 88 |
+
('name', None,
|
| 89 |
+
"print package name"),
|
| 90 |
+
('version', 'V',
|
| 91 |
+
"print package version"),
|
| 92 |
+
('fullname', None,
|
| 93 |
+
"print <package name>-<version>"),
|
| 94 |
+
('author', None,
|
| 95 |
+
"print the author's name"),
|
| 96 |
+
('author-email', None,
|
| 97 |
+
"print the author's email address"),
|
| 98 |
+
('maintainer', None,
|
| 99 |
+
"print the maintainer's name"),
|
| 100 |
+
('maintainer-email', None,
|
| 101 |
+
"print the maintainer's email address"),
|
| 102 |
+
('contact', None,
|
| 103 |
+
"print the maintainer's name if known, else the author's"),
|
| 104 |
+
('contact-email', None,
|
| 105 |
+
"print the maintainer's email address if known, else the author's"),
|
| 106 |
+
('url', None,
|
| 107 |
+
"print the URL for this package"),
|
| 108 |
+
('license', None,
|
| 109 |
+
"print the license of the package"),
|
| 110 |
+
('licence', None,
|
| 111 |
+
"alias for --license"),
|
| 112 |
+
('description', None,
|
| 113 |
+
"print the package description"),
|
| 114 |
+
('long-description', None,
|
| 115 |
+
"print the long package description"),
|
| 116 |
+
('platforms', None,
|
| 117 |
+
"print the list of platforms"),
|
| 118 |
+
('classifiers', None,
|
| 119 |
+
"print the list of classifiers"),
|
| 120 |
+
('keywords', None,
|
| 121 |
+
"print the list of keywords"),
|
| 122 |
+
('provides', None,
|
| 123 |
+
"print the list of packages/modules provided"),
|
| 124 |
+
('requires', None,
|
| 125 |
+
"print the list of packages/modules required"),
|
| 126 |
+
('obsoletes', None,
|
| 127 |
+
"print the list of packages/modules made obsolete")
|
| 128 |
+
]
|
| 129 |
+
display_option_names = [translate_longopt(x[0]) for x in display_options]
|
| 130 |
+
|
| 131 |
+
# negative options are options that exclude other options
|
| 132 |
+
negative_opt = {'quiet': 'verbose'}
|
| 133 |
+
|
| 134 |
+
# -- Creation/initialization methods -------------------------------
|
| 135 |
+
|
| 136 |
+
def __init__(self, attrs=None):
|
| 137 |
+
"""Construct a new Distribution instance: initialize all the
|
| 138 |
+
attributes of a Distribution, and then use 'attrs' (a dictionary
|
| 139 |
+
mapping attribute names to values) to assign some of those
|
| 140 |
+
attributes their "real" values. (Any attributes not mentioned in
|
| 141 |
+
'attrs' will be assigned to some null value: 0, None, an empty list
|
| 142 |
+
or dictionary, etc.) Most importantly, initialize the
|
| 143 |
+
'command_obj' attribute to the empty dictionary; this will be
|
| 144 |
+
filled in with real command objects by 'parse_command_line()'.
|
| 145 |
+
"""
|
| 146 |
+
|
| 147 |
+
# Default values for our command-line options
|
| 148 |
+
self.verbose = 1
|
| 149 |
+
self.dry_run = 0
|
| 150 |
+
self.help = 0
|
| 151 |
+
for attr in self.display_option_names:
|
| 152 |
+
setattr(self, attr, 0)
|
| 153 |
+
|
| 154 |
+
# Store the distribution meta-data (name, version, author, and so
|
| 155 |
+
# forth) in a separate object -- we're getting to have enough
|
| 156 |
+
# information here (and enough command-line options) that it's
|
| 157 |
+
# worth it. Also delegate 'get_XXX()' methods to the 'metadata'
|
| 158 |
+
# object in a sneaky and underhanded (but efficient!) way.
|
| 159 |
+
self.metadata = DistributionMetadata()
|
| 160 |
+
for basename in self.metadata._METHOD_BASENAMES:
|
| 161 |
+
method_name = "get_" + basename
|
| 162 |
+
setattr(self, method_name, getattr(self.metadata, method_name))
|
| 163 |
+
|
| 164 |
+
# 'cmdclass' maps command names to class objects, so we
|
| 165 |
+
# can 1) quickly figure out which class to instantiate when
|
| 166 |
+
# we need to create a new command object, and 2) have a way
|
| 167 |
+
# for the setup script to override command classes
|
| 168 |
+
self.cmdclass = {}
|
| 169 |
+
|
| 170 |
+
# 'command_packages' is a list of packages in which commands
|
| 171 |
+
# are searched for. The factory for command 'foo' is expected
|
| 172 |
+
# to be named 'foo' in the module 'foo' in one of the packages
|
| 173 |
+
# named here. This list is searched from the left; an error
|
| 174 |
+
# is raised if no named package provides the command being
|
| 175 |
+
# searched for. (Always access using get_command_packages().)
|
| 176 |
+
self.command_packages = None
|
| 177 |
+
|
| 178 |
+
# 'script_name' and 'script_args' are usually set to sys.argv[0]
|
| 179 |
+
# and sys.argv[1:], but they can be overridden when the caller is
|
| 180 |
+
# not necessarily a setup script run from the command-line.
|
| 181 |
+
self.script_name = None
|
| 182 |
+
self.script_args = None
|
| 183 |
+
|
| 184 |
+
# 'command_options' is where we store command options between
|
| 185 |
+
# parsing them (from config files, the command-line, etc.) and when
|
| 186 |
+
# they are actually needed -- ie. when the command in question is
|
| 187 |
+
# instantiated. It is a dictionary of dictionaries of 2-tuples:
|
| 188 |
+
# command_options = { command_name : { option : (source, value) } }
|
| 189 |
+
self.command_options = {}
|
| 190 |
+
|
| 191 |
+
# 'dist_files' is the list of (command, pyversion, file) that
|
| 192 |
+
# have been created by any dist commands run so far. This is
|
| 193 |
+
# filled regardless of whether the run is dry or not. pyversion
|
| 194 |
+
# gives sysconfig.get_python_version() if the dist file is
|
| 195 |
+
# specific to a Python version, 'any' if it is good for all
|
| 196 |
+
# Python versions on the target platform, and '' for a source
|
| 197 |
+
# file. pyversion should not be used to specify minimum or
|
| 198 |
+
# maximum required Python versions; use the metainfo for that
|
| 199 |
+
# instead.
|
| 200 |
+
self.dist_files = []
|
| 201 |
+
|
| 202 |
+
# These options are really the business of various commands, rather
|
| 203 |
+
# than of the Distribution itself. We provide aliases for them in
|
| 204 |
+
# Distribution as a convenience to the developer.
|
| 205 |
+
self.packages = None
|
| 206 |
+
self.package_data = {}
|
| 207 |
+
self.package_dir = None
|
| 208 |
+
self.py_modules = None
|
| 209 |
+
self.libraries = None
|
| 210 |
+
self.headers = None
|
| 211 |
+
self.ext_modules = None
|
| 212 |
+
self.ext_package = None
|
| 213 |
+
self.include_dirs = None
|
| 214 |
+
self.extra_path = None
|
| 215 |
+
self.scripts = None
|
| 216 |
+
self.data_files = None
|
| 217 |
+
self.password = ''
|
| 218 |
+
|
| 219 |
+
# And now initialize bookkeeping stuff that can't be supplied by
|
| 220 |
+
# the caller at all. 'command_obj' maps command names to
|
| 221 |
+
# Command instances -- that's how we enforce that every command
|
| 222 |
+
# class is a singleton.
|
| 223 |
+
self.command_obj = {}
|
| 224 |
+
|
| 225 |
+
# 'have_run' maps command names to boolean values; it keeps track
|
| 226 |
+
# of whether we have actually run a particular command, to make it
|
| 227 |
+
# cheap to "run" a command whenever we think we might need to -- if
|
| 228 |
+
# it's already been done, no need for expensive filesystem
|
| 229 |
+
# operations, we just check the 'have_run' dictionary and carry on.
|
| 230 |
+
# It's only safe to query 'have_run' for a command class that has
|
| 231 |
+
# been instantiated -- a false value will be inserted when the
|
| 232 |
+
# command object is created, and replaced with a true value when
|
| 233 |
+
# the command is successfully run. Thus it's probably best to use
|
| 234 |
+
# '.get()' rather than a straight lookup.
|
| 235 |
+
self.have_run = {}
|
| 236 |
+
|
| 237 |
+
# Now we'll use the attrs dictionary (ultimately, keyword args from
|
| 238 |
+
# the setup script) to possibly override any or all of these
|
| 239 |
+
# distribution options.
|
| 240 |
+
|
| 241 |
+
if attrs:
|
| 242 |
+
# Pull out the set of command options and work on them
|
| 243 |
+
# specifically. Note that this order guarantees that aliased
|
| 244 |
+
# command options will override any supplied redundantly
|
| 245 |
+
# through the general options dictionary.
|
| 246 |
+
options = attrs.get('options')
|
| 247 |
+
if options is not None:
|
| 248 |
+
del attrs['options']
|
| 249 |
+
for (command, cmd_options) in options.items():
|
| 250 |
+
opt_dict = self.get_option_dict(command)
|
| 251 |
+
for (opt, val) in cmd_options.items():
|
| 252 |
+
opt_dict[opt] = ("setup script", val)
|
| 253 |
+
|
| 254 |
+
if 'licence' in attrs:
|
| 255 |
+
attrs['license'] = attrs['licence']
|
| 256 |
+
del attrs['licence']
|
| 257 |
+
msg = "'licence' distribution option is deprecated; use 'license'"
|
| 258 |
+
if warnings is not None:
|
| 259 |
+
warnings.warn(msg)
|
| 260 |
+
else:
|
| 261 |
+
sys.stderr.write(msg + "\n")
|
| 262 |
+
|
| 263 |
+
# Now work on the rest of the attributes. Any attribute that's
|
| 264 |
+
# not already defined is invalid!
|
| 265 |
+
for (key, val) in attrs.items():
|
| 266 |
+
if hasattr(self.metadata, "set_" + key):
|
| 267 |
+
getattr(self.metadata, "set_" + key)(val)
|
| 268 |
+
elif hasattr(self.metadata, key):
|
| 269 |
+
setattr(self.metadata, key, val)
|
| 270 |
+
elif hasattr(self, key):
|
| 271 |
+
setattr(self, key, val)
|
| 272 |
+
else:
|
| 273 |
+
msg = "Unknown distribution option: %s" % repr(key)
|
| 274 |
+
warnings.warn(msg)
|
| 275 |
+
|
| 276 |
+
# no-user-cfg is handled before other command line args
|
| 277 |
+
# because other args override the config files, and this
|
| 278 |
+
# one is needed before we can load the config files.
|
| 279 |
+
# If attrs['script_args'] wasn't passed, assume false.
|
| 280 |
+
#
|
| 281 |
+
# This also make sure we just look at the global options
|
| 282 |
+
self.want_user_cfg = True
|
| 283 |
+
|
| 284 |
+
if self.script_args is not None:
|
| 285 |
+
for arg in self.script_args:
|
| 286 |
+
if not arg.startswith('-'):
|
| 287 |
+
break
|
| 288 |
+
if arg == '--no-user-cfg':
|
| 289 |
+
self.want_user_cfg = False
|
| 290 |
+
break
|
| 291 |
+
|
| 292 |
+
self.finalize_options()
|
| 293 |
+
|
| 294 |
+
def get_option_dict(self, command):
|
| 295 |
+
"""Get the option dictionary for a given command. If that
|
| 296 |
+
command's option dictionary hasn't been created yet, then create it
|
| 297 |
+
and return the new dictionary; otherwise, return the existing
|
| 298 |
+
option dictionary.
|
| 299 |
+
"""
|
| 300 |
+
dict = self.command_options.get(command)
|
| 301 |
+
if dict is None:
|
| 302 |
+
dict = self.command_options[command] = {}
|
| 303 |
+
return dict
|
| 304 |
+
|
| 305 |
+
def dump_option_dicts(self, header=None, commands=None, indent=""):
|
| 306 |
+
from pprint import pformat
|
| 307 |
+
|
| 308 |
+
if commands is None: # dump all command option dicts
|
| 309 |
+
commands = sorted(self.command_options.keys())
|
| 310 |
+
|
| 311 |
+
if header is not None:
|
| 312 |
+
self.announce(indent + header)
|
| 313 |
+
indent = indent + " "
|
| 314 |
+
|
| 315 |
+
if not commands:
|
| 316 |
+
self.announce(indent + "no commands known yet")
|
| 317 |
+
return
|
| 318 |
+
|
| 319 |
+
for cmd_name in commands:
|
| 320 |
+
opt_dict = self.command_options.get(cmd_name)
|
| 321 |
+
if opt_dict is None:
|
| 322 |
+
self.announce(indent +
|
| 323 |
+
"no option dict for '%s' command" % cmd_name)
|
| 324 |
+
else:
|
| 325 |
+
self.announce(indent +
|
| 326 |
+
"option dict for '%s' command:" % cmd_name)
|
| 327 |
+
out = pformat(opt_dict)
|
| 328 |
+
for line in out.split('\n'):
|
| 329 |
+
self.announce(indent + " " + line)
|
| 330 |
+
|
| 331 |
+
# -- Config file finding/parsing methods ---------------------------
|
| 332 |
+
|
| 333 |
+
def find_config_files(self):
|
| 334 |
+
"""Find as many configuration files as should be processed for this
|
| 335 |
+
platform, and return a list of filenames in the order in which they
|
| 336 |
+
should be parsed. The filenames returned are guaranteed to exist
|
| 337 |
+
(modulo nasty race conditions).
|
| 338 |
+
|
| 339 |
+
There are three possible config files: distutils.cfg in the
|
| 340 |
+
Distutils installation directory (ie. where the top-level
|
| 341 |
+
Distutils __inst__.py file lives), a file in the user's home
|
| 342 |
+
directory named .pydistutils.cfg on Unix and pydistutils.cfg
|
| 343 |
+
on Windows/Mac; and setup.cfg in the current directory.
|
| 344 |
+
|
| 345 |
+
The file in the user's home directory can be disabled with the
|
| 346 |
+
--no-user-cfg option.
|
| 347 |
+
"""
|
| 348 |
+
files = []
|
| 349 |
+
check_environ()
|
| 350 |
+
|
| 351 |
+
# Where to look for the system-wide Distutils config file
|
| 352 |
+
sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
|
| 353 |
+
|
| 354 |
+
# Look for the system config file
|
| 355 |
+
sys_file = os.path.join(sys_dir, "distutils.cfg")
|
| 356 |
+
if os.path.isfile(sys_file):
|
| 357 |
+
files.append(sys_file)
|
| 358 |
+
|
| 359 |
+
# What to call the per-user config file
|
| 360 |
+
if os.name == 'posix':
|
| 361 |
+
user_filename = ".pydistutils.cfg"
|
| 362 |
+
else:
|
| 363 |
+
user_filename = "pydistutils.cfg"
|
| 364 |
+
|
| 365 |
+
# And look for the user config file
|
| 366 |
+
if self.want_user_cfg:
|
| 367 |
+
user_file = os.path.join(os.path.expanduser('~'), user_filename)
|
| 368 |
+
if os.path.isfile(user_file):
|
| 369 |
+
files.append(user_file)
|
| 370 |
+
|
| 371 |
+
# All platforms support local setup.cfg
|
| 372 |
+
local_file = "setup.cfg"
|
| 373 |
+
if os.path.isfile(local_file):
|
| 374 |
+
files.append(local_file)
|
| 375 |
+
|
| 376 |
+
if DEBUG:
|
| 377 |
+
self.announce("using config files: %s" % ', '.join(files))
|
| 378 |
+
|
| 379 |
+
return files
|
| 380 |
+
|
| 381 |
+
def parse_config_files(self, filenames=None):
|
| 382 |
+
from configparser import ConfigParser
|
| 383 |
+
|
| 384 |
+
# Ignore install directory options if we have a venv
|
| 385 |
+
if sys.prefix != sys.base_prefix:
|
| 386 |
+
ignore_options = [
|
| 387 |
+
'install-base', 'install-platbase', 'install-lib',
|
| 388 |
+
'install-platlib', 'install-purelib', 'install-headers',
|
| 389 |
+
'install-scripts', 'install-data', 'prefix', 'exec-prefix',
|
| 390 |
+
'home', 'user', 'root']
|
| 391 |
+
else:
|
| 392 |
+
ignore_options = []
|
| 393 |
+
|
| 394 |
+
ignore_options = frozenset(ignore_options)
|
| 395 |
+
|
| 396 |
+
if filenames is None:
|
| 397 |
+
filenames = self.find_config_files()
|
| 398 |
+
|
| 399 |
+
if DEBUG:
|
| 400 |
+
self.announce("Distribution.parse_config_files():")
|
| 401 |
+
|
| 402 |
+
parser = ConfigParser()
|
| 403 |
+
for filename in filenames:
|
| 404 |
+
if DEBUG:
|
| 405 |
+
self.announce(" reading %s" % filename)
|
| 406 |
+
parser.read(filename)
|
| 407 |
+
for section in parser.sections():
|
| 408 |
+
options = parser.options(section)
|
| 409 |
+
opt_dict = self.get_option_dict(section)
|
| 410 |
+
|
| 411 |
+
for opt in options:
|
| 412 |
+
if opt != '__name__' and opt not in ignore_options:
|
| 413 |
+
val = parser.get(section,opt)
|
| 414 |
+
opt = opt.replace('-', '_')
|
| 415 |
+
opt_dict[opt] = (filename, val)
|
| 416 |
+
|
| 417 |
+
# Make the ConfigParser forget everything (so we retain
|
| 418 |
+
# the original filenames that options come from)
|
| 419 |
+
parser.__init__()
|
| 420 |
+
|
| 421 |
+
# If there was a "global" section in the config file, use it
|
| 422 |
+
# to set Distribution options.
|
| 423 |
+
|
| 424 |
+
if 'global' in self.command_options:
|
| 425 |
+
for (opt, (src, val)) in self.command_options['global'].items():
|
| 426 |
+
alias = self.negative_opt.get(opt)
|
| 427 |
+
try:
|
| 428 |
+
if alias:
|
| 429 |
+
setattr(self, alias, not strtobool(val))
|
| 430 |
+
elif opt in ('verbose', 'dry_run'): # ugh!
|
| 431 |
+
setattr(self, opt, strtobool(val))
|
| 432 |
+
else:
|
| 433 |
+
setattr(self, opt, val)
|
| 434 |
+
except ValueError as msg:
|
| 435 |
+
raise DistutilsOptionError(msg)
|
| 436 |
+
|
| 437 |
+
# -- Command-line parsing methods ----------------------------------
|
| 438 |
+
|
| 439 |
+
def parse_command_line(self):
|
| 440 |
+
"""Parse the setup script's command line, taken from the
|
| 441 |
+
'script_args' instance attribute (which defaults to 'sys.argv[1:]'
|
| 442 |
+
-- see 'setup()' in core.py). This list is first processed for
|
| 443 |
+
"global options" -- options that set attributes of the Distribution
|
| 444 |
+
instance. Then, it is alternately scanned for Distutils commands
|
| 445 |
+
and options for that command. Each new command terminates the
|
| 446 |
+
options for the previous command. The allowed options for a
|
| 447 |
+
command are determined by the 'user_options' attribute of the
|
| 448 |
+
command class -- thus, we have to be able to load command classes
|
| 449 |
+
in order to parse the command line. Any error in that 'options'
|
| 450 |
+
attribute raises DistutilsGetoptError; any error on the
|
| 451 |
+
command-line raises DistutilsArgError. If no Distutils commands
|
| 452 |
+
were found on the command line, raises DistutilsArgError. Return
|
| 453 |
+
true if command-line was successfully parsed and we should carry
|
| 454 |
+
on with executing commands; false if no errors but we shouldn't
|
| 455 |
+
execute commands (currently, this only happens if user asks for
|
| 456 |
+
help).
|
| 457 |
+
"""
|
| 458 |
+
#
|
| 459 |
+
# We now have enough information to show the Macintosh dialog
|
| 460 |
+
# that allows the user to interactively specify the "command line".
|
| 461 |
+
#
|
| 462 |
+
toplevel_options = self._get_toplevel_options()
|
| 463 |
+
|
| 464 |
+
# We have to parse the command line a bit at a time -- global
|
| 465 |
+
# options, then the first command, then its options, and so on --
|
| 466 |
+
# because each command will be handled by a different class, and
|
| 467 |
+
# the options that are valid for a particular class aren't known
|
| 468 |
+
# until we have loaded the command class, which doesn't happen
|
| 469 |
+
# until we know what the command is.
|
| 470 |
+
|
| 471 |
+
self.commands = []
|
| 472 |
+
parser = FancyGetopt(toplevel_options + self.display_options)
|
| 473 |
+
parser.set_negative_aliases(self.negative_opt)
|
| 474 |
+
parser.set_aliases({'licence': 'license'})
|
| 475 |
+
args = parser.getopt(args=self.script_args, object=self)
|
| 476 |
+
option_order = parser.get_option_order()
|
| 477 |
+
log.set_verbosity(self.verbose)
|
| 478 |
+
|
| 479 |
+
# for display options we return immediately
|
| 480 |
+
if self.handle_display_options(option_order):
|
| 481 |
+
return
|
| 482 |
+
while args:
|
| 483 |
+
args = self._parse_command_opts(parser, args)
|
| 484 |
+
if args is None: # user asked for help (and got it)
|
| 485 |
+
return
|
| 486 |
+
|
| 487 |
+
# Handle the cases of --help as a "global" option, ie.
|
| 488 |
+
# "setup.py --help" and "setup.py --help command ...". For the
|
| 489 |
+
# former, we show global options (--verbose, --dry-run, etc.)
|
| 490 |
+
# and display-only options (--name, --version, etc.); for the
|
| 491 |
+
# latter, we omit the display-only options and show help for
|
| 492 |
+
# each command listed on the command line.
|
| 493 |
+
if self.help:
|
| 494 |
+
self._show_help(parser,
|
| 495 |
+
display_options=len(self.commands) == 0,
|
| 496 |
+
commands=self.commands)
|
| 497 |
+
return
|
| 498 |
+
|
| 499 |
+
# Oops, no commands found -- an end-user error
|
| 500 |
+
if not self.commands:
|
| 501 |
+
raise DistutilsArgError("no commands supplied")
|
| 502 |
+
|
| 503 |
+
# All is well: return true
|
| 504 |
+
return True
|
| 505 |
+
|
| 506 |
+
def _get_toplevel_options(self):
|
| 507 |
+
"""Return the non-display options recognized at the top level.
|
| 508 |
+
|
| 509 |
+
This includes options that are recognized *only* at the top
|
| 510 |
+
level as well as options recognized for commands.
|
| 511 |
+
"""
|
| 512 |
+
return self.global_options + [
|
| 513 |
+
("command-packages=", None,
|
| 514 |
+
"list of packages that provide distutils commands"),
|
| 515 |
+
]
|
| 516 |
+
|
| 517 |
+
def _parse_command_opts(self, parser, args):
|
| 518 |
+
"""Parse the command-line options for a single command.
|
| 519 |
+
'parser' must be a FancyGetopt instance; 'args' must be the list
|
| 520 |
+
of arguments, starting with the current command (whose options
|
| 521 |
+
we are about to parse). Returns a new version of 'args' with
|
| 522 |
+
the next command at the front of the list; will be the empty
|
| 523 |
+
list if there are no more commands on the command line. Returns
|
| 524 |
+
None if the user asked for help on this command.
|
| 525 |
+
"""
|
| 526 |
+
# late import because of mutual dependence between these modules
|
| 527 |
+
from distutils.cmd import Command
|
| 528 |
+
|
| 529 |
+
# Pull the current command from the head of the command line
|
| 530 |
+
command = args[0]
|
| 531 |
+
if not command_re.match(command):
|
| 532 |
+
raise SystemExit("invalid command name '%s'" % command)
|
| 533 |
+
self.commands.append(command)
|
| 534 |
+
|
| 535 |
+
# Dig up the command class that implements this command, so we
|
| 536 |
+
# 1) know that it's a valid command, and 2) know which options
|
| 537 |
+
# it takes.
|
| 538 |
+
try:
|
| 539 |
+
cmd_class = self.get_command_class(command)
|
| 540 |
+
except DistutilsModuleError as msg:
|
| 541 |
+
raise DistutilsArgError(msg)
|
| 542 |
+
|
| 543 |
+
# Require that the command class be derived from Command -- want
|
| 544 |
+
# to be sure that the basic "command" interface is implemented.
|
| 545 |
+
if not issubclass(cmd_class, Command):
|
| 546 |
+
raise DistutilsClassError(
|
| 547 |
+
"command class %s must subclass Command" % cmd_class)
|
| 548 |
+
|
| 549 |
+
# Also make sure that the command object provides a list of its
|
| 550 |
+
# known options.
|
| 551 |
+
if not (hasattr(cmd_class, 'user_options') and
|
| 552 |
+
isinstance(cmd_class.user_options, list)):
|
| 553 |
+
msg = ("command class %s must provide "
|
| 554 |
+
"'user_options' attribute (a list of tuples)")
|
| 555 |
+
raise DistutilsClassError(msg % cmd_class)
|
| 556 |
+
|
| 557 |
+
# If the command class has a list of negative alias options,
|
| 558 |
+
# merge it in with the global negative aliases.
|
| 559 |
+
negative_opt = self.negative_opt
|
| 560 |
+
if hasattr(cmd_class, 'negative_opt'):
|
| 561 |
+
negative_opt = negative_opt.copy()
|
| 562 |
+
negative_opt.update(cmd_class.negative_opt)
|
| 563 |
+
|
| 564 |
+
# Check for help_options in command class. They have a different
|
| 565 |
+
# format (tuple of four) so we need to preprocess them here.
|
| 566 |
+
if (hasattr(cmd_class, 'help_options') and
|
| 567 |
+
isinstance(cmd_class.help_options, list)):
|
| 568 |
+
help_options = fix_help_options(cmd_class.help_options)
|
| 569 |
+
else:
|
| 570 |
+
help_options = []
|
| 571 |
+
|
| 572 |
+
# All commands support the global options too, just by adding
|
| 573 |
+
# in 'global_options'.
|
| 574 |
+
parser.set_option_table(self.global_options +
|
| 575 |
+
cmd_class.user_options +
|
| 576 |
+
help_options)
|
| 577 |
+
parser.set_negative_aliases(negative_opt)
|
| 578 |
+
(args, opts) = parser.getopt(args[1:])
|
| 579 |
+
if hasattr(opts, 'help') and opts.help:
|
| 580 |
+
self._show_help(parser, display_options=0, commands=[cmd_class])
|
| 581 |
+
return
|
| 582 |
+
|
| 583 |
+
if (hasattr(cmd_class, 'help_options') and
|
| 584 |
+
isinstance(cmd_class.help_options, list)):
|
| 585 |
+
help_option_found=0
|
| 586 |
+
for (help_option, short, desc, func) in cmd_class.help_options:
|
| 587 |
+
if hasattr(opts, parser.get_attr_name(help_option)):
|
| 588 |
+
help_option_found=1
|
| 589 |
+
if callable(func):
|
| 590 |
+
func()
|
| 591 |
+
else:
|
| 592 |
+
raise DistutilsClassError(
|
| 593 |
+
"invalid help function %r for help option '%s': "
|
| 594 |
+
"must be a callable object (function, etc.)"
|
| 595 |
+
% (func, help_option))
|
| 596 |
+
|
| 597 |
+
if help_option_found:
|
| 598 |
+
return
|
| 599 |
+
|
| 600 |
+
# Put the options from the command-line into their official
|
| 601 |
+
# holding pen, the 'command_options' dictionary.
|
| 602 |
+
opt_dict = self.get_option_dict(command)
|
| 603 |
+
for (name, value) in vars(opts).items():
|
| 604 |
+
opt_dict[name] = ("command line", value)
|
| 605 |
+
|
| 606 |
+
return args
|
| 607 |
+
|
| 608 |
+
def finalize_options(self):
|
| 609 |
+
"""Set final values for all the options on the Distribution
|
| 610 |
+
instance, analogous to the .finalize_options() method of Command
|
| 611 |
+
objects.
|
| 612 |
+
"""
|
| 613 |
+
for attr in ('keywords', 'platforms'):
|
| 614 |
+
value = getattr(self.metadata, attr)
|
| 615 |
+
if value is None:
|
| 616 |
+
continue
|
| 617 |
+
if isinstance(value, str):
|
| 618 |
+
value = [elm.strip() for elm in value.split(',')]
|
| 619 |
+
setattr(self.metadata, attr, value)
|
| 620 |
+
|
| 621 |
+
def _show_help(self, parser, global_options=1, display_options=1,
|
| 622 |
+
commands=[]):
|
| 623 |
+
"""Show help for the setup script command-line in the form of
|
| 624 |
+
several lists of command-line options. 'parser' should be a
|
| 625 |
+
FancyGetopt instance; do not expect it to be returned in the
|
| 626 |
+
same state, as its option table will be reset to make it
|
| 627 |
+
generate the correct help text.
|
| 628 |
+
|
| 629 |
+
If 'global_options' is true, lists the global options:
|
| 630 |
+
--verbose, --dry-run, etc. If 'display_options' is true, lists
|
| 631 |
+
the "display-only" options: --name, --version, etc. Finally,
|
| 632 |
+
lists per-command help for every command name or command class
|
| 633 |
+
in 'commands'.
|
| 634 |
+
"""
|
| 635 |
+
# late import because of mutual dependence between these modules
|
| 636 |
+
from distutils.core import gen_usage
|
| 637 |
+
from distutils.cmd import Command
|
| 638 |
+
|
| 639 |
+
if global_options:
|
| 640 |
+
if display_options:
|
| 641 |
+
options = self._get_toplevel_options()
|
| 642 |
+
else:
|
| 643 |
+
options = self.global_options
|
| 644 |
+
parser.set_option_table(options)
|
| 645 |
+
parser.print_help(self.common_usage + "\nGlobal options:")
|
| 646 |
+
print('')
|
| 647 |
+
|
| 648 |
+
if display_options:
|
| 649 |
+
parser.set_option_table(self.display_options)
|
| 650 |
+
parser.print_help(
|
| 651 |
+
"Information display options (just display " +
|
| 652 |
+
"information, ignore any commands)")
|
| 653 |
+
print('')
|
| 654 |
+
|
| 655 |
+
for command in self.commands:
|
| 656 |
+
if isinstance(command, type) and issubclass(command, Command):
|
| 657 |
+
klass = command
|
| 658 |
+
else:
|
| 659 |
+
klass = self.get_command_class(command)
|
| 660 |
+
if (hasattr(klass, 'help_options') and
|
| 661 |
+
isinstance(klass.help_options, list)):
|
| 662 |
+
parser.set_option_table(klass.user_options +
|
| 663 |
+
fix_help_options(klass.help_options))
|
| 664 |
+
else:
|
| 665 |
+
parser.set_option_table(klass.user_options)
|
| 666 |
+
parser.print_help("Options for '%s' command:" % klass.__name__)
|
| 667 |
+
print('')
|
| 668 |
+
|
| 669 |
+
print(gen_usage(self.script_name))
|
| 670 |
+
|
| 671 |
+
def handle_display_options(self, option_order):
|
| 672 |
+
"""If there were any non-global "display-only" options
|
| 673 |
+
(--help-commands or the metadata display options) on the command
|
| 674 |
+
line, display the requested info and return true; else return
|
| 675 |
+
false.
|
| 676 |
+
"""
|
| 677 |
+
from distutils.core import gen_usage
|
| 678 |
+
|
| 679 |
+
# User just wants a list of commands -- we'll print it out and stop
|
| 680 |
+
# processing now (ie. if they ran "setup --help-commands foo bar",
|
| 681 |
+
# we ignore "foo bar").
|
| 682 |
+
if self.help_commands:
|
| 683 |
+
self.print_commands()
|
| 684 |
+
print('')
|
| 685 |
+
print(gen_usage(self.script_name))
|
| 686 |
+
return 1
|
| 687 |
+
|
| 688 |
+
# If user supplied any of the "display metadata" options, then
|
| 689 |
+
# display that metadata in the order in which the user supplied the
|
| 690 |
+
# metadata options.
|
| 691 |
+
any_display_options = 0
|
| 692 |
+
is_display_option = {}
|
| 693 |
+
for option in self.display_options:
|
| 694 |
+
is_display_option[option[0]] = 1
|
| 695 |
+
|
| 696 |
+
for (opt, val) in option_order:
|
| 697 |
+
if val and is_display_option.get(opt):
|
| 698 |
+
opt = translate_longopt(opt)
|
| 699 |
+
value = getattr(self.metadata, "get_"+opt)()
|
| 700 |
+
if opt in ['keywords', 'platforms']:
|
| 701 |
+
print(','.join(value))
|
| 702 |
+
elif opt in ('classifiers', 'provides', 'requires',
|
| 703 |
+
'obsoletes'):
|
| 704 |
+
print('\n'.join(value))
|
| 705 |
+
else:
|
| 706 |
+
print(value)
|
| 707 |
+
any_display_options = 1
|
| 708 |
+
|
| 709 |
+
return any_display_options
|
| 710 |
+
|
| 711 |
+
def print_command_list(self, commands, header, max_length):
|
| 712 |
+
"""Print a subset of the list of all commands -- used by
|
| 713 |
+
'print_commands()'.
|
| 714 |
+
"""
|
| 715 |
+
print(header + ":")
|
| 716 |
+
|
| 717 |
+
for cmd in commands:
|
| 718 |
+
klass = self.cmdclass.get(cmd)
|
| 719 |
+
if not klass:
|
| 720 |
+
klass = self.get_command_class(cmd)
|
| 721 |
+
try:
|
| 722 |
+
description = klass.description
|
| 723 |
+
except AttributeError:
|
| 724 |
+
description = "(no description available)"
|
| 725 |
+
|
| 726 |
+
print(" %-*s %s" % (max_length, cmd, description))
|
| 727 |
+
|
| 728 |
+
def print_commands(self):
|
| 729 |
+
"""Print out a help message listing all available commands with a
|
| 730 |
+
description of each. The list is divided into "standard commands"
|
| 731 |
+
(listed in distutils.command.__all__) and "extra commands"
|
| 732 |
+
(mentioned in self.cmdclass, but not a standard command). The
|
| 733 |
+
descriptions come from the command class attribute
|
| 734 |
+
'description'.
|
| 735 |
+
"""
|
| 736 |
+
import distutils.command
|
| 737 |
+
std_commands = distutils.command.__all__
|
| 738 |
+
is_std = {}
|
| 739 |
+
for cmd in std_commands:
|
| 740 |
+
is_std[cmd] = 1
|
| 741 |
+
|
| 742 |
+
extra_commands = []
|
| 743 |
+
for cmd in self.cmdclass.keys():
|
| 744 |
+
if not is_std.get(cmd):
|
| 745 |
+
extra_commands.append(cmd)
|
| 746 |
+
|
| 747 |
+
max_length = 0
|
| 748 |
+
for cmd in (std_commands + extra_commands):
|
| 749 |
+
if len(cmd) > max_length:
|
| 750 |
+
max_length = len(cmd)
|
| 751 |
+
|
| 752 |
+
self.print_command_list(std_commands,
|
| 753 |
+
"Standard commands",
|
| 754 |
+
max_length)
|
| 755 |
+
if extra_commands:
|
| 756 |
+
print()
|
| 757 |
+
self.print_command_list(extra_commands,
|
| 758 |
+
"Extra commands",
|
| 759 |
+
max_length)
|
| 760 |
+
|
| 761 |
+
def get_command_list(self):
|
| 762 |
+
"""Get a list of (command, description) tuples.
|
| 763 |
+
The list is divided into "standard commands" (listed in
|
| 764 |
+
distutils.command.__all__) and "extra commands" (mentioned in
|
| 765 |
+
self.cmdclass, but not a standard command). The descriptions come
|
| 766 |
+
from the command class attribute 'description'.
|
| 767 |
+
"""
|
| 768 |
+
# Currently this is only used on Mac OS, for the Mac-only GUI
|
| 769 |
+
# Distutils interface (by Jack Jansen)
|
| 770 |
+
import distutils.command
|
| 771 |
+
std_commands = distutils.command.__all__
|
| 772 |
+
is_std = {}
|
| 773 |
+
for cmd in std_commands:
|
| 774 |
+
is_std[cmd] = 1
|
| 775 |
+
|
| 776 |
+
extra_commands = []
|
| 777 |
+
for cmd in self.cmdclass.keys():
|
| 778 |
+
if not is_std.get(cmd):
|
| 779 |
+
extra_commands.append(cmd)
|
| 780 |
+
|
| 781 |
+
rv = []
|
| 782 |
+
for cmd in (std_commands + extra_commands):
|
| 783 |
+
klass = self.cmdclass.get(cmd)
|
| 784 |
+
if not klass:
|
| 785 |
+
klass = self.get_command_class(cmd)
|
| 786 |
+
try:
|
| 787 |
+
description = klass.description
|
| 788 |
+
except AttributeError:
|
| 789 |
+
description = "(no description available)"
|
| 790 |
+
rv.append((cmd, description))
|
| 791 |
+
return rv
|
| 792 |
+
|
| 793 |
+
# -- Command class/object methods ----------------------------------
|
| 794 |
+
|
| 795 |
+
def get_command_packages(self):
|
| 796 |
+
"""Return a list of packages from which commands are loaded."""
|
| 797 |
+
pkgs = self.command_packages
|
| 798 |
+
if not isinstance(pkgs, list):
|
| 799 |
+
if pkgs is None:
|
| 800 |
+
pkgs = ''
|
| 801 |
+
pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != '']
|
| 802 |
+
if "distutils.command" not in pkgs:
|
| 803 |
+
pkgs.insert(0, "distutils.command")
|
| 804 |
+
self.command_packages = pkgs
|
| 805 |
+
return pkgs
|
| 806 |
+
|
| 807 |
+
def get_command_class(self, command):
|
| 808 |
+
"""Return the class that implements the Distutils command named by
|
| 809 |
+
'command'. First we check the 'cmdclass' dictionary; if the
|
| 810 |
+
command is mentioned there, we fetch the class object from the
|
| 811 |
+
dictionary and return it. Otherwise we load the command module
|
| 812 |
+
("distutils.command." + command) and fetch the command class from
|
| 813 |
+
the module. The loaded class is also stored in 'cmdclass'
|
| 814 |
+
to speed future calls to 'get_command_class()'.
|
| 815 |
+
|
| 816 |
+
Raises DistutilsModuleError if the expected module could not be
|
| 817 |
+
found, or if that module does not define the expected class.
|
| 818 |
+
"""
|
| 819 |
+
klass = self.cmdclass.get(command)
|
| 820 |
+
if klass:
|
| 821 |
+
return klass
|
| 822 |
+
|
| 823 |
+
for pkgname in self.get_command_packages():
|
| 824 |
+
module_name = "%s.%s" % (pkgname, command)
|
| 825 |
+
klass_name = command
|
| 826 |
+
|
| 827 |
+
try:
|
| 828 |
+
__import__(module_name)
|
| 829 |
+
module = sys.modules[module_name]
|
| 830 |
+
except ImportError:
|
| 831 |
+
continue
|
| 832 |
+
|
| 833 |
+
try:
|
| 834 |
+
klass = getattr(module, klass_name)
|
| 835 |
+
except AttributeError:
|
| 836 |
+
raise DistutilsModuleError(
|
| 837 |
+
"invalid command '%s' (no class '%s' in module '%s')"
|
| 838 |
+
% (command, klass_name, module_name))
|
| 839 |
+
|
| 840 |
+
self.cmdclass[command] = klass
|
| 841 |
+
return klass
|
| 842 |
+
|
| 843 |
+
raise DistutilsModuleError("invalid command '%s'" % command)
|
| 844 |
+
|
| 845 |
+
def get_command_obj(self, command, create=1):
|
| 846 |
+
"""Return the command object for 'command'. Normally this object
|
| 847 |
+
is cached on a previous call to 'get_command_obj()'; if no command
|
| 848 |
+
object for 'command' is in the cache, then we either create and
|
| 849 |
+
return it (if 'create' is true) or return None.
|
| 850 |
+
"""
|
| 851 |
+
cmd_obj = self.command_obj.get(command)
|
| 852 |
+
if not cmd_obj and create:
|
| 853 |
+
if DEBUG:
|
| 854 |
+
self.announce("Distribution.get_command_obj(): "
|
| 855 |
+
"creating '%s' command object" % command)
|
| 856 |
+
|
| 857 |
+
klass = self.get_command_class(command)
|
| 858 |
+
cmd_obj = self.command_obj[command] = klass(self)
|
| 859 |
+
self.have_run[command] = 0
|
| 860 |
+
|
| 861 |
+
# Set any options that were supplied in config files
|
| 862 |
+
# or on the command line. (NB. support for error
|
| 863 |
+
# reporting is lame here: any errors aren't reported
|
| 864 |
+
# until 'finalize_options()' is called, which means
|
| 865 |
+
# we won't report the source of the error.)
|
| 866 |
+
options = self.command_options.get(command)
|
| 867 |
+
if options:
|
| 868 |
+
self._set_command_options(cmd_obj, options)
|
| 869 |
+
|
| 870 |
+
return cmd_obj
|
| 871 |
+
|
| 872 |
+
def _set_command_options(self, command_obj, option_dict=None):
|
| 873 |
+
"""Set the options for 'command_obj' from 'option_dict'. Basically
|
| 874 |
+
this means copying elements of a dictionary ('option_dict') to
|
| 875 |
+
attributes of an instance ('command').
|
| 876 |
+
|
| 877 |
+
'command_obj' must be a Command instance. If 'option_dict' is not
|
| 878 |
+
supplied, uses the standard option dictionary for this command
|
| 879 |
+
(from 'self.command_options').
|
| 880 |
+
"""
|
| 881 |
+
command_name = command_obj.get_command_name()
|
| 882 |
+
if option_dict is None:
|
| 883 |
+
option_dict = self.get_option_dict(command_name)
|
| 884 |
+
|
| 885 |
+
if DEBUG:
|
| 886 |
+
self.announce(" setting options for '%s' command:" % command_name)
|
| 887 |
+
for (option, (source, value)) in option_dict.items():
|
| 888 |
+
if DEBUG:
|
| 889 |
+
self.announce(" %s = %s (from %s)" % (option, value,
|
| 890 |
+
source))
|
| 891 |
+
try:
|
| 892 |
+
bool_opts = [translate_longopt(o)
|
| 893 |
+
for o in command_obj.boolean_options]
|
| 894 |
+
except AttributeError:
|
| 895 |
+
bool_opts = []
|
| 896 |
+
try:
|
| 897 |
+
neg_opt = command_obj.negative_opt
|
| 898 |
+
except AttributeError:
|
| 899 |
+
neg_opt = {}
|
| 900 |
+
|
| 901 |
+
try:
|
| 902 |
+
is_string = isinstance(value, str)
|
| 903 |
+
if option in neg_opt and is_string:
|
| 904 |
+
setattr(command_obj, neg_opt[option], not strtobool(value))
|
| 905 |
+
elif option in bool_opts and is_string:
|
| 906 |
+
setattr(command_obj, option, strtobool(value))
|
| 907 |
+
elif hasattr(command_obj, option):
|
| 908 |
+
setattr(command_obj, option, value)
|
| 909 |
+
else:
|
| 910 |
+
raise DistutilsOptionError(
|
| 911 |
+
"error in %s: command '%s' has no such option '%s'"
|
| 912 |
+
% (source, command_name, option))
|
| 913 |
+
except ValueError as msg:
|
| 914 |
+
raise DistutilsOptionError(msg)
|
| 915 |
+
|
| 916 |
+
def reinitialize_command(self, command, reinit_subcommands=0):
|
| 917 |
+
"""Reinitializes a command to the state it was in when first
|
| 918 |
+
returned by 'get_command_obj()': ie., initialized but not yet
|
| 919 |
+
finalized. This provides the opportunity to sneak option
|
| 920 |
+
values in programmatically, overriding or supplementing
|
| 921 |
+
user-supplied values from the config files and command line.
|
| 922 |
+
You'll have to re-finalize the command object (by calling
|
| 923 |
+
'finalize_options()' or 'ensure_finalized()') before using it for
|
| 924 |
+
real.
|
| 925 |
+
|
| 926 |
+
'command' should be a command name (string) or command object. If
|
| 927 |
+
'reinit_subcommands' is true, also reinitializes the command's
|
| 928 |
+
sub-commands, as declared by the 'sub_commands' class attribute (if
|
| 929 |
+
it has one). See the "install" command for an example. Only
|
| 930 |
+
reinitializes the sub-commands that actually matter, ie. those
|
| 931 |
+
whose test predicates return true.
|
| 932 |
+
|
| 933 |
+
Returns the reinitialized command object.
|
| 934 |
+
"""
|
| 935 |
+
from distutils.cmd import Command
|
| 936 |
+
if not isinstance(command, Command):
|
| 937 |
+
command_name = command
|
| 938 |
+
command = self.get_command_obj(command_name)
|
| 939 |
+
else:
|
| 940 |
+
command_name = command.get_command_name()
|
| 941 |
+
|
| 942 |
+
if not command.finalized:
|
| 943 |
+
return command
|
| 944 |
+
command.initialize_options()
|
| 945 |
+
command.finalized = 0
|
| 946 |
+
self.have_run[command_name] = 0
|
| 947 |
+
self._set_command_options(command)
|
| 948 |
+
|
| 949 |
+
if reinit_subcommands:
|
| 950 |
+
for sub in command.get_sub_commands():
|
| 951 |
+
self.reinitialize_command(sub, reinit_subcommands)
|
| 952 |
+
|
| 953 |
+
return command
|
| 954 |
+
|
| 955 |
+
# -- Methods that operate on the Distribution ----------------------
|
| 956 |
+
|
| 957 |
+
def announce(self, msg, level=log.INFO):
|
| 958 |
+
log.log(level, msg)
|
| 959 |
+
|
| 960 |
+
def run_commands(self):
|
| 961 |
+
"""Run each command that was seen on the setup script command line.
|
| 962 |
+
Uses the list of commands found and cache of command objects
|
| 963 |
+
created by 'get_command_obj()'.
|
| 964 |
+
"""
|
| 965 |
+
for cmd in self.commands:
|
| 966 |
+
self.run_command(cmd)
|
| 967 |
+
|
| 968 |
+
# -- Methods that operate on its Commands --------------------------
|
| 969 |
+
|
| 970 |
+
def run_command(self, command):
|
| 971 |
+
"""Do whatever it takes to run a command (including nothing at all,
|
| 972 |
+
if the command has already been run). Specifically: if we have
|
| 973 |
+
already created and run the command named by 'command', return
|
| 974 |
+
silently without doing anything. If the command named by 'command'
|
| 975 |
+
doesn't even have a command object yet, create one. Then invoke
|
| 976 |
+
'run()' on that command object (or an existing one).
|
| 977 |
+
"""
|
| 978 |
+
# Already been here, done that? then return silently.
|
| 979 |
+
if self.have_run.get(command):
|
| 980 |
+
return
|
| 981 |
+
|
| 982 |
+
log.info("running %s", command)
|
| 983 |
+
cmd_obj = self.get_command_obj(command)
|
| 984 |
+
cmd_obj.ensure_finalized()
|
| 985 |
+
cmd_obj.run()
|
| 986 |
+
self.have_run[command] = 1
|
| 987 |
+
|
| 988 |
+
# -- Distribution query methods ------------------------------------
|
| 989 |
+
|
| 990 |
+
def has_pure_modules(self):
|
| 991 |
+
return len(self.packages or self.py_modules or []) > 0
|
| 992 |
+
|
| 993 |
+
def has_ext_modules(self):
|
| 994 |
+
return self.ext_modules and len(self.ext_modules) > 0
|
| 995 |
+
|
| 996 |
+
def has_c_libraries(self):
|
| 997 |
+
return self.libraries and len(self.libraries) > 0
|
| 998 |
+
|
| 999 |
+
def has_modules(self):
|
| 1000 |
+
return self.has_pure_modules() or self.has_ext_modules()
|
| 1001 |
+
|
| 1002 |
+
def has_headers(self):
|
| 1003 |
+
return self.headers and len(self.headers) > 0
|
| 1004 |
+
|
| 1005 |
+
def has_scripts(self):
|
| 1006 |
+
return self.scripts and len(self.scripts) > 0
|
| 1007 |
+
|
| 1008 |
+
def has_data_files(self):
|
| 1009 |
+
return self.data_files and len(self.data_files) > 0
|
| 1010 |
+
|
| 1011 |
+
def is_pure(self):
|
| 1012 |
+
return (self.has_pure_modules() and
|
| 1013 |
+
not self.has_ext_modules() and
|
| 1014 |
+
not self.has_c_libraries())
|
| 1015 |
+
|
| 1016 |
+
# -- Metadata query methods ----------------------------------------
|
| 1017 |
+
|
| 1018 |
+
# If you're looking for 'get_name()', 'get_version()', and so forth,
|
| 1019 |
+
# they are defined in a sneaky way: the constructor binds self.get_XXX
|
| 1020 |
+
# to self.metadata.get_XXX. The actual code is in the
|
| 1021 |
+
# DistributionMetadata class, below.
|
| 1022 |
+
|
| 1023 |
+
class DistributionMetadata:
|
| 1024 |
+
"""Dummy class to hold the distribution meta-data: name, version,
|
| 1025 |
+
author, and so forth.
|
| 1026 |
+
"""
|
| 1027 |
+
|
| 1028 |
+
_METHOD_BASENAMES = ("name", "version", "author", "author_email",
|
| 1029 |
+
"maintainer", "maintainer_email", "url",
|
| 1030 |
+
"license", "description", "long_description",
|
| 1031 |
+
"keywords", "platforms", "fullname", "contact",
|
| 1032 |
+
"contact_email", "classifiers", "download_url",
|
| 1033 |
+
# PEP 314
|
| 1034 |
+
"provides", "requires", "obsoletes",
|
| 1035 |
+
)
|
| 1036 |
+
|
| 1037 |
+
def __init__(self, path=None):
|
| 1038 |
+
if path is not None:
|
| 1039 |
+
self.read_pkg_file(open(path))
|
| 1040 |
+
else:
|
| 1041 |
+
self.name = None
|
| 1042 |
+
self.version = None
|
| 1043 |
+
self.author = None
|
| 1044 |
+
self.author_email = None
|
| 1045 |
+
self.maintainer = None
|
| 1046 |
+
self.maintainer_email = None
|
| 1047 |
+
self.url = None
|
| 1048 |
+
self.license = None
|
| 1049 |
+
self.description = None
|
| 1050 |
+
self.long_description = None
|
| 1051 |
+
self.keywords = None
|
| 1052 |
+
self.platforms = None
|
| 1053 |
+
self.classifiers = None
|
| 1054 |
+
self.download_url = None
|
| 1055 |
+
# PEP 314
|
| 1056 |
+
self.provides = None
|
| 1057 |
+
self.requires = None
|
| 1058 |
+
self.obsoletes = None
|
| 1059 |
+
|
| 1060 |
+
def read_pkg_file(self, file):
|
| 1061 |
+
"""Reads the metadata values from a file object."""
|
| 1062 |
+
msg = message_from_file(file)
|
| 1063 |
+
|
| 1064 |
+
def _read_field(name):
|
| 1065 |
+
value = msg[name]
|
| 1066 |
+
if value == 'UNKNOWN':
|
| 1067 |
+
return None
|
| 1068 |
+
return value
|
| 1069 |
+
|
| 1070 |
+
def _read_list(name):
|
| 1071 |
+
values = msg.get_all(name, None)
|
| 1072 |
+
if values == []:
|
| 1073 |
+
return None
|
| 1074 |
+
return values
|
| 1075 |
+
|
| 1076 |
+
metadata_version = msg['metadata-version']
|
| 1077 |
+
self.name = _read_field('name')
|
| 1078 |
+
self.version = _read_field('version')
|
| 1079 |
+
self.description = _read_field('summary')
|
| 1080 |
+
# we are filling author only.
|
| 1081 |
+
self.author = _read_field('author')
|
| 1082 |
+
self.maintainer = None
|
| 1083 |
+
self.author_email = _read_field('author-email')
|
| 1084 |
+
self.maintainer_email = None
|
| 1085 |
+
self.url = _read_field('home-page')
|
| 1086 |
+
self.license = _read_field('license')
|
| 1087 |
+
|
| 1088 |
+
if 'download-url' in msg:
|
| 1089 |
+
self.download_url = _read_field('download-url')
|
| 1090 |
+
else:
|
| 1091 |
+
self.download_url = None
|
| 1092 |
+
|
| 1093 |
+
self.long_description = _read_field('description')
|
| 1094 |
+
self.description = _read_field('summary')
|
| 1095 |
+
|
| 1096 |
+
if 'keywords' in msg:
|
| 1097 |
+
self.keywords = _read_field('keywords').split(',')
|
| 1098 |
+
|
| 1099 |
+
self.platforms = _read_list('platform')
|
| 1100 |
+
self.classifiers = _read_list('classifier')
|
| 1101 |
+
|
| 1102 |
+
# PEP 314 - these fields only exist in 1.1
|
| 1103 |
+
if metadata_version == '1.1':
|
| 1104 |
+
self.requires = _read_list('requires')
|
| 1105 |
+
self.provides = _read_list('provides')
|
| 1106 |
+
self.obsoletes = _read_list('obsoletes')
|
| 1107 |
+
else:
|
| 1108 |
+
self.requires = None
|
| 1109 |
+
self.provides = None
|
| 1110 |
+
self.obsoletes = None
|
| 1111 |
+
|
| 1112 |
+
def write_pkg_info(self, base_dir):
|
| 1113 |
+
"""Write the PKG-INFO file into the release tree.
|
| 1114 |
+
"""
|
| 1115 |
+
with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
|
| 1116 |
+
encoding='UTF-8') as pkg_info:
|
| 1117 |
+
self.write_pkg_file(pkg_info)
|
| 1118 |
+
|
| 1119 |
+
def write_pkg_file(self, file):
|
| 1120 |
+
"""Write the PKG-INFO format data to a file object.
|
| 1121 |
+
"""
|
| 1122 |
+
version = '1.0'
|
| 1123 |
+
if (self.provides or self.requires or self.obsoletes or
|
| 1124 |
+
self.classifiers or self.download_url):
|
| 1125 |
+
version = '1.1'
|
| 1126 |
+
|
| 1127 |
+
file.write('Metadata-Version: %s\n' % version)
|
| 1128 |
+
file.write('Name: %s\n' % self.get_name())
|
| 1129 |
+
file.write('Version: %s\n' % self.get_version())
|
| 1130 |
+
file.write('Summary: %s\n' % self.get_description())
|
| 1131 |
+
file.write('Home-page: %s\n' % self.get_url())
|
| 1132 |
+
file.write('Author: %s\n' % self.get_contact())
|
| 1133 |
+
file.write('Author-email: %s\n' % self.get_contact_email())
|
| 1134 |
+
file.write('License: %s\n' % self.get_license())
|
| 1135 |
+
if self.download_url:
|
| 1136 |
+
file.write('Download-URL: %s\n' % self.download_url)
|
| 1137 |
+
|
| 1138 |
+
long_desc = rfc822_escape(self.get_long_description())
|
| 1139 |
+
file.write('Description: %s\n' % long_desc)
|
| 1140 |
+
|
| 1141 |
+
keywords = ','.join(self.get_keywords())
|
| 1142 |
+
if keywords:
|
| 1143 |
+
file.write('Keywords: %s\n' % keywords)
|
| 1144 |
+
|
| 1145 |
+
self._write_list(file, 'Platform', self.get_platforms())
|
| 1146 |
+
self._write_list(file, 'Classifier', self.get_classifiers())
|
| 1147 |
+
|
| 1148 |
+
# PEP 314
|
| 1149 |
+
self._write_list(file, 'Requires', self.get_requires())
|
| 1150 |
+
self._write_list(file, 'Provides', self.get_provides())
|
| 1151 |
+
self._write_list(file, 'Obsoletes', self.get_obsoletes())
|
| 1152 |
+
|
| 1153 |
+
def _write_list(self, file, name, values):
|
| 1154 |
+
for value in values:
|
| 1155 |
+
file.write('%s: %s\n' % (name, value))
|
| 1156 |
+
|
| 1157 |
+
# -- Metadata query methods ----------------------------------------
|
| 1158 |
+
|
| 1159 |
+
def get_name(self):
|
| 1160 |
+
return self.name or "UNKNOWN"
|
| 1161 |
+
|
| 1162 |
+
def get_version(self):
|
| 1163 |
+
return self.version or "0.0.0"
|
| 1164 |
+
|
| 1165 |
+
def get_fullname(self):
|
| 1166 |
+
return "%s-%s" % (self.get_name(), self.get_version())
|
| 1167 |
+
|
| 1168 |
+
def get_author(self):
|
| 1169 |
+
return self.author or "UNKNOWN"
|
| 1170 |
+
|
| 1171 |
+
def get_author_email(self):
|
| 1172 |
+
return self.author_email or "UNKNOWN"
|
| 1173 |
+
|
| 1174 |
+
def get_maintainer(self):
|
| 1175 |
+
return self.maintainer or "UNKNOWN"
|
| 1176 |
+
|
| 1177 |
+
def get_maintainer_email(self):
|
| 1178 |
+
return self.maintainer_email or "UNKNOWN"
|
| 1179 |
+
|
| 1180 |
+
def get_contact(self):
|
| 1181 |
+
return self.maintainer or self.author or "UNKNOWN"
|
| 1182 |
+
|
| 1183 |
+
def get_contact_email(self):
|
| 1184 |
+
return self.maintainer_email or self.author_email or "UNKNOWN"
|
| 1185 |
+
|
| 1186 |
+
def get_url(self):
|
| 1187 |
+
return self.url or "UNKNOWN"
|
| 1188 |
+
|
| 1189 |
+
def get_license(self):
|
| 1190 |
+
return self.license or "UNKNOWN"
|
| 1191 |
+
get_licence = get_license
|
| 1192 |
+
|
| 1193 |
+
def get_description(self):
|
| 1194 |
+
return self.description or "UNKNOWN"
|
| 1195 |
+
|
| 1196 |
+
def get_long_description(self):
|
| 1197 |
+
return self.long_description or "UNKNOWN"
|
| 1198 |
+
|
| 1199 |
+
def get_keywords(self):
|
| 1200 |
+
return self.keywords or []
|
| 1201 |
+
|
| 1202 |
+
def set_keywords(self, value):
|
| 1203 |
+
self.keywords = _ensure_list(value, 'keywords')
|
| 1204 |
+
|
| 1205 |
+
def get_platforms(self):
|
| 1206 |
+
return self.platforms or ["UNKNOWN"]
|
| 1207 |
+
|
| 1208 |
+
def set_platforms(self, value):
|
| 1209 |
+
self.platforms = _ensure_list(value, 'platforms')
|
| 1210 |
+
|
| 1211 |
+
def get_classifiers(self):
|
| 1212 |
+
return self.classifiers or []
|
| 1213 |
+
|
| 1214 |
+
def set_classifiers(self, value):
|
| 1215 |
+
self.classifiers = _ensure_list(value, 'classifiers')
|
| 1216 |
+
|
| 1217 |
+
def get_download_url(self):
|
| 1218 |
+
return self.download_url or "UNKNOWN"
|
| 1219 |
+
|
| 1220 |
+
# PEP 314
|
| 1221 |
+
def get_requires(self):
|
| 1222 |
+
return self.requires or []
|
| 1223 |
+
|
| 1224 |
+
def set_requires(self, value):
|
| 1225 |
+
import distutils.versionpredicate
|
| 1226 |
+
for v in value:
|
| 1227 |
+
distutils.versionpredicate.VersionPredicate(v)
|
| 1228 |
+
self.requires = list(value)
|
| 1229 |
+
|
| 1230 |
+
def get_provides(self):
|
| 1231 |
+
return self.provides or []
|
| 1232 |
+
|
| 1233 |
+
def set_provides(self, value):
|
| 1234 |
+
value = [v.strip() for v in value]
|
| 1235 |
+
for v in value:
|
| 1236 |
+
import distutils.versionpredicate
|
| 1237 |
+
distutils.versionpredicate.split_provision(v)
|
| 1238 |
+
self.provides = value
|
| 1239 |
+
|
| 1240 |
+
def get_obsoletes(self):
|
| 1241 |
+
return self.obsoletes or []
|
| 1242 |
+
|
| 1243 |
+
def set_obsoletes(self, value):
|
| 1244 |
+
import distutils.versionpredicate
|
| 1245 |
+
for v in value:
|
| 1246 |
+
distutils.versionpredicate.VersionPredicate(v)
|
| 1247 |
+
self.obsoletes = list(value)
|
| 1248 |
+
|
| 1249 |
+
def fix_help_options(options):
|
| 1250 |
+
"""Convert a 4-tuple 'help_options' list as found in various command
|
| 1251 |
+
classes to the 3-tuple form required by FancyGetopt.
|
| 1252 |
+
"""
|
| 1253 |
+
new_options = []
|
| 1254 |
+
for help_tuple in options:
|
| 1255 |
+
new_options.append(help_tuple[0:3])
|
| 1256 |
+
return new_options
|
data/conda_envs/evalclaw/lib/python3.11/distutils/errors.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.errors
|
| 2 |
+
|
| 3 |
+
Provides exceptions used by the Distutils modules. Note that Distutils
|
| 4 |
+
modules may raise standard exceptions; in particular, SystemExit is
|
| 5 |
+
usually raised for errors that are obviously the end-user's fault
|
| 6 |
+
(eg. bad command-line arguments).
|
| 7 |
+
|
| 8 |
+
This module is safe to use in "from ... import *" mode; it only exports
|
| 9 |
+
symbols whose names start with "Distutils" and end with "Error"."""
|
| 10 |
+
|
| 11 |
+
class DistutilsError (Exception):
|
| 12 |
+
"""The root of all Distutils evil."""
|
| 13 |
+
pass
|
| 14 |
+
|
| 15 |
+
class DistutilsModuleError (DistutilsError):
|
| 16 |
+
"""Unable to load an expected module, or to find an expected class
|
| 17 |
+
within some module (in particular, command modules and classes)."""
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
class DistutilsClassError (DistutilsError):
|
| 21 |
+
"""Some command class (or possibly distribution class, if anyone
|
| 22 |
+
feels a need to subclass Distribution) is found not to be holding
|
| 23 |
+
up its end of the bargain, ie. implementing some part of the
|
| 24 |
+
"command "interface."""
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
class DistutilsGetoptError (DistutilsError):
|
| 28 |
+
"""The option table provided to 'fancy_getopt()' is bogus."""
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
+
class DistutilsArgError (DistutilsError):
|
| 32 |
+
"""Raised by fancy_getopt in response to getopt.error -- ie. an
|
| 33 |
+
error in the command line usage."""
|
| 34 |
+
pass
|
| 35 |
+
|
| 36 |
+
class DistutilsFileError (DistutilsError):
|
| 37 |
+
"""Any problems in the filesystem: expected file not found, etc.
|
| 38 |
+
Typically this is for problems that we detect before OSError
|
| 39 |
+
could be raised."""
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
class DistutilsOptionError (DistutilsError):
|
| 43 |
+
"""Syntactic/semantic errors in command options, such as use of
|
| 44 |
+
mutually conflicting options, or inconsistent options,
|
| 45 |
+
badly-spelled values, etc. No distinction is made between option
|
| 46 |
+
values originating in the setup script, the command line, config
|
| 47 |
+
files, or what-have-you -- but if we *know* something originated in
|
| 48 |
+
the setup script, we'll raise DistutilsSetupError instead."""
|
| 49 |
+
pass
|
| 50 |
+
|
| 51 |
+
class DistutilsSetupError (DistutilsError):
|
| 52 |
+
"""For errors that can be definitely blamed on the setup script,
|
| 53 |
+
such as invalid keyword arguments to 'setup()'."""
|
| 54 |
+
pass
|
| 55 |
+
|
| 56 |
+
class DistutilsPlatformError (DistutilsError):
|
| 57 |
+
"""We don't know how to do something on the current platform (but
|
| 58 |
+
we do know how to do it on some platform) -- eg. trying to compile
|
| 59 |
+
C files on a platform not supported by a CCompiler subclass."""
|
| 60 |
+
pass
|
| 61 |
+
|
| 62 |
+
class DistutilsExecError (DistutilsError):
|
| 63 |
+
"""Any problems executing an external program (such as the C
|
| 64 |
+
compiler, when compiling C files)."""
|
| 65 |
+
pass
|
| 66 |
+
|
| 67 |
+
class DistutilsInternalError (DistutilsError):
|
| 68 |
+
"""Internal inconsistencies or impossibilities (obviously, this
|
| 69 |
+
should never be seen if the code is working!)."""
|
| 70 |
+
pass
|
| 71 |
+
|
| 72 |
+
class DistutilsTemplateError (DistutilsError):
|
| 73 |
+
"""Syntax error in a file list template."""
|
| 74 |
+
|
| 75 |
+
class DistutilsByteCompileError(DistutilsError):
|
| 76 |
+
"""Byte compile error."""
|
| 77 |
+
|
| 78 |
+
# Exception classes used by the CCompiler implementation classes
|
| 79 |
+
class CCompilerError (Exception):
|
| 80 |
+
"""Some compile/link operation failed."""
|
| 81 |
+
|
| 82 |
+
class PreprocessError (CCompilerError):
|
| 83 |
+
"""Failure to preprocess one or more C/C++ files."""
|
| 84 |
+
|
| 85 |
+
class CompileError (CCompilerError):
|
| 86 |
+
"""Failure to compile one or more C/C++ source files."""
|
| 87 |
+
|
| 88 |
+
class LibError (CCompilerError):
|
| 89 |
+
"""Failure to create a static library from one or more C/C++ object
|
| 90 |
+
files."""
|
| 91 |
+
|
| 92 |
+
class LinkError (CCompilerError):
|
| 93 |
+
"""Failure to link one or more C/C++ object files into an executable
|
| 94 |
+
or shared library file."""
|
| 95 |
+
|
| 96 |
+
class UnknownFileError (CCompilerError):
|
| 97 |
+
"""Attempt to process an unknown file type."""
|
data/conda_envs/evalclaw/lib/python3.11/distutils/extension.py
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.extension
|
| 2 |
+
|
| 3 |
+
Provides the Extension class, used to describe C/C++ extension
|
| 4 |
+
modules in setup scripts."""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import re
|
| 8 |
+
import warnings
|
| 9 |
+
|
| 10 |
+
# This class is really only used by the "build_ext" command, so it might
|
| 11 |
+
# make sense to put it in distutils.command.build_ext. However, that
|
| 12 |
+
# module is already big enough, and I want to make this class a bit more
|
| 13 |
+
# complex to simplify some common cases ("foo" module in "foo.c") and do
|
| 14 |
+
# better error-checking ("foo.c" actually exists).
|
| 15 |
+
#
|
| 16 |
+
# Also, putting this in build_ext.py means every setup script would have to
|
| 17 |
+
# import that large-ish module (indirectly, through distutils.core) in
|
| 18 |
+
# order to do anything.
|
| 19 |
+
|
| 20 |
+
class Extension:
|
| 21 |
+
"""Just a collection of attributes that describes an extension
|
| 22 |
+
module and everything needed to build it (hopefully in a portable
|
| 23 |
+
way, but there are hooks that let you be as unportable as you need).
|
| 24 |
+
|
| 25 |
+
Instance attributes:
|
| 26 |
+
name : string
|
| 27 |
+
the full name of the extension, including any packages -- ie.
|
| 28 |
+
*not* a filename or pathname, but Python dotted name
|
| 29 |
+
sources : [string]
|
| 30 |
+
list of source filenames, relative to the distribution root
|
| 31 |
+
(where the setup script lives), in Unix form (slash-separated)
|
| 32 |
+
for portability. Source files may be C, C++, SWIG (.i),
|
| 33 |
+
platform-specific resource files, or whatever else is recognized
|
| 34 |
+
by the "build_ext" command as source for a Python extension.
|
| 35 |
+
include_dirs : [string]
|
| 36 |
+
list of directories to search for C/C++ header files (in Unix
|
| 37 |
+
form for portability)
|
| 38 |
+
define_macros : [(name : string, value : string|None)]
|
| 39 |
+
list of macros to define; each macro is defined using a 2-tuple,
|
| 40 |
+
where 'value' is either the string to define it to or None to
|
| 41 |
+
define it without a particular value (equivalent of "#define
|
| 42 |
+
FOO" in source or -DFOO on Unix C compiler command line)
|
| 43 |
+
undef_macros : [string]
|
| 44 |
+
list of macros to undefine explicitly
|
| 45 |
+
library_dirs : [string]
|
| 46 |
+
list of directories to search for C/C++ libraries at link time
|
| 47 |
+
libraries : [string]
|
| 48 |
+
list of library names (not filenames or paths) to link against
|
| 49 |
+
runtime_library_dirs : [string]
|
| 50 |
+
list of directories to search for C/C++ libraries at run time
|
| 51 |
+
(for shared extensions, this is when the extension is loaded)
|
| 52 |
+
extra_objects : [string]
|
| 53 |
+
list of extra files to link with (eg. object files not implied
|
| 54 |
+
by 'sources', static library that must be explicitly specified,
|
| 55 |
+
binary resource files, etc.)
|
| 56 |
+
extra_compile_args : [string]
|
| 57 |
+
any extra platform- and compiler-specific information to use
|
| 58 |
+
when compiling the source files in 'sources'. For platforms and
|
| 59 |
+
compilers where "command line" makes sense, this is typically a
|
| 60 |
+
list of command-line arguments, but for other platforms it could
|
| 61 |
+
be anything.
|
| 62 |
+
extra_link_args : [string]
|
| 63 |
+
any extra platform- and compiler-specific information to use
|
| 64 |
+
when linking object files together to create the extension (or
|
| 65 |
+
to create a new static Python interpreter). Similar
|
| 66 |
+
interpretation as for 'extra_compile_args'.
|
| 67 |
+
export_symbols : [string]
|
| 68 |
+
list of symbols to be exported from a shared extension. Not
|
| 69 |
+
used on all platforms, and not generally necessary for Python
|
| 70 |
+
extensions, which typically export exactly one symbol: "init" +
|
| 71 |
+
extension_name.
|
| 72 |
+
swig_opts : [string]
|
| 73 |
+
any extra options to pass to SWIG if a source file has the .i
|
| 74 |
+
extension.
|
| 75 |
+
depends : [string]
|
| 76 |
+
list of files that the extension depends on
|
| 77 |
+
language : string
|
| 78 |
+
extension language (i.e. "c", "c++", "objc"). Will be detected
|
| 79 |
+
from the source extensions if not provided.
|
| 80 |
+
optional : boolean
|
| 81 |
+
specifies that a build failure in the extension should not abort the
|
| 82 |
+
build process, but simply not install the failing extension.
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
# When adding arguments to this constructor, be sure to update
|
| 86 |
+
# setup_keywords in core.py.
|
| 87 |
+
def __init__(self, name, sources,
|
| 88 |
+
include_dirs=None,
|
| 89 |
+
define_macros=None,
|
| 90 |
+
undef_macros=None,
|
| 91 |
+
library_dirs=None,
|
| 92 |
+
libraries=None,
|
| 93 |
+
runtime_library_dirs=None,
|
| 94 |
+
extra_objects=None,
|
| 95 |
+
extra_compile_args=None,
|
| 96 |
+
extra_link_args=None,
|
| 97 |
+
export_symbols=None,
|
| 98 |
+
swig_opts = None,
|
| 99 |
+
depends=None,
|
| 100 |
+
language=None,
|
| 101 |
+
optional=None,
|
| 102 |
+
**kw # To catch unknown keywords
|
| 103 |
+
):
|
| 104 |
+
if not isinstance(name, str):
|
| 105 |
+
raise AssertionError("'name' must be a string")
|
| 106 |
+
if not (isinstance(sources, list) and
|
| 107 |
+
all(isinstance(v, str) for v in sources)):
|
| 108 |
+
raise AssertionError("'sources' must be a list of strings")
|
| 109 |
+
|
| 110 |
+
self.name = name
|
| 111 |
+
self.sources = sources
|
| 112 |
+
self.include_dirs = include_dirs or []
|
| 113 |
+
self.define_macros = define_macros or []
|
| 114 |
+
self.undef_macros = undef_macros or []
|
| 115 |
+
self.library_dirs = library_dirs or []
|
| 116 |
+
self.libraries = libraries or []
|
| 117 |
+
self.runtime_library_dirs = runtime_library_dirs or []
|
| 118 |
+
self.extra_objects = extra_objects or []
|
| 119 |
+
self.extra_compile_args = extra_compile_args or []
|
| 120 |
+
self.extra_link_args = extra_link_args or []
|
| 121 |
+
self.export_symbols = export_symbols or []
|
| 122 |
+
self.swig_opts = swig_opts or []
|
| 123 |
+
self.depends = depends or []
|
| 124 |
+
self.language = language
|
| 125 |
+
self.optional = optional
|
| 126 |
+
|
| 127 |
+
# If there are unknown keyword options, warn about them
|
| 128 |
+
if len(kw) > 0:
|
| 129 |
+
options = [repr(option) for option in kw]
|
| 130 |
+
options = ', '.join(sorted(options))
|
| 131 |
+
msg = "Unknown Extension options: %s" % options
|
| 132 |
+
warnings.warn(msg)
|
| 133 |
+
|
| 134 |
+
def __repr__(self):
|
| 135 |
+
return '<%s.%s(%r) at %#x>' % (
|
| 136 |
+
self.__class__.__module__,
|
| 137 |
+
self.__class__.__qualname__,
|
| 138 |
+
self.name,
|
| 139 |
+
id(self))
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def read_setup_file(filename):
|
| 143 |
+
"""Reads a Setup file and returns Extension instances."""
|
| 144 |
+
from distutils.sysconfig import (parse_makefile, expand_makefile_vars,
|
| 145 |
+
_variable_rx)
|
| 146 |
+
|
| 147 |
+
from distutils.text_file import TextFile
|
| 148 |
+
from distutils.util import split_quoted
|
| 149 |
+
|
| 150 |
+
# First pass over the file to gather "VAR = VALUE" assignments.
|
| 151 |
+
vars = parse_makefile(filename)
|
| 152 |
+
|
| 153 |
+
# Second pass to gobble up the real content: lines of the form
|
| 154 |
+
# <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
|
| 155 |
+
file = TextFile(filename,
|
| 156 |
+
strip_comments=1, skip_blanks=1, join_lines=1,
|
| 157 |
+
lstrip_ws=1, rstrip_ws=1)
|
| 158 |
+
try:
|
| 159 |
+
extensions = []
|
| 160 |
+
|
| 161 |
+
while True:
|
| 162 |
+
line = file.readline()
|
| 163 |
+
if line is None: # eof
|
| 164 |
+
break
|
| 165 |
+
if re.match(_variable_rx, line): # VAR=VALUE, handled in first pass
|
| 166 |
+
continue
|
| 167 |
+
|
| 168 |
+
if line[0] == line[-1] == "*":
|
| 169 |
+
file.warn("'%s' lines not handled yet" % line)
|
| 170 |
+
continue
|
| 171 |
+
|
| 172 |
+
line = expand_makefile_vars(line, vars)
|
| 173 |
+
words = split_quoted(line)
|
| 174 |
+
|
| 175 |
+
# NB. this parses a slightly different syntax than the old
|
| 176 |
+
# makesetup script: here, there must be exactly one extension per
|
| 177 |
+
# line, and it must be the first word of the line. I have no idea
|
| 178 |
+
# why the old syntax supported multiple extensions per line, as
|
| 179 |
+
# they all wind up being the same.
|
| 180 |
+
|
| 181 |
+
module = words[0]
|
| 182 |
+
ext = Extension(module, [])
|
| 183 |
+
append_next_word = None
|
| 184 |
+
|
| 185 |
+
for word in words[1:]:
|
| 186 |
+
if append_next_word is not None:
|
| 187 |
+
append_next_word.append(word)
|
| 188 |
+
append_next_word = None
|
| 189 |
+
continue
|
| 190 |
+
|
| 191 |
+
suffix = os.path.splitext(word)[1]
|
| 192 |
+
switch = word[0:2] ; value = word[2:]
|
| 193 |
+
|
| 194 |
+
if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"):
|
| 195 |
+
# hmm, should we do something about C vs. C++ sources?
|
| 196 |
+
# or leave it up to the CCompiler implementation to
|
| 197 |
+
# worry about?
|
| 198 |
+
ext.sources.append(word)
|
| 199 |
+
elif switch == "-I":
|
| 200 |
+
ext.include_dirs.append(value)
|
| 201 |
+
elif switch == "-D":
|
| 202 |
+
equals = value.find("=")
|
| 203 |
+
if equals == -1: # bare "-DFOO" -- no value
|
| 204 |
+
ext.define_macros.append((value, None))
|
| 205 |
+
else: # "-DFOO=blah"
|
| 206 |
+
ext.define_macros.append((value[0:equals],
|
| 207 |
+
value[equals+2:]))
|
| 208 |
+
elif switch == "-U":
|
| 209 |
+
ext.undef_macros.append(value)
|
| 210 |
+
elif switch == "-C": # only here 'cause makesetup has it!
|
| 211 |
+
ext.extra_compile_args.append(word)
|
| 212 |
+
elif switch == "-l":
|
| 213 |
+
ext.libraries.append(value)
|
| 214 |
+
elif switch == "-L":
|
| 215 |
+
ext.library_dirs.append(value)
|
| 216 |
+
elif switch == "-R":
|
| 217 |
+
ext.runtime_library_dirs.append(value)
|
| 218 |
+
elif word == "-rpath":
|
| 219 |
+
append_next_word = ext.runtime_library_dirs
|
| 220 |
+
elif word == "-Xlinker":
|
| 221 |
+
append_next_word = ext.extra_link_args
|
| 222 |
+
elif word == "-Xcompiler":
|
| 223 |
+
append_next_word = ext.extra_compile_args
|
| 224 |
+
elif switch == "-u":
|
| 225 |
+
ext.extra_link_args.append(word)
|
| 226 |
+
if not value:
|
| 227 |
+
append_next_word = ext.extra_link_args
|
| 228 |
+
elif suffix in (".a", ".so", ".sl", ".o", ".dylib"):
|
| 229 |
+
# NB. a really faithful emulation of makesetup would
|
| 230 |
+
# append a .o file to extra_objects only if it
|
| 231 |
+
# had a slash in it; otherwise, it would s/.o/.c/
|
| 232 |
+
# and append it to sources. Hmmmm.
|
| 233 |
+
ext.extra_objects.append(word)
|
| 234 |
+
else:
|
| 235 |
+
file.warn("unrecognized argument '%s'" % word)
|
| 236 |
+
|
| 237 |
+
extensions.append(ext)
|
| 238 |
+
finally:
|
| 239 |
+
file.close()
|
| 240 |
+
|
| 241 |
+
return extensions
|
data/conda_envs/evalclaw/lib/python3.11/distutils/fancy_getopt.py
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.fancy_getopt
|
| 2 |
+
|
| 3 |
+
Wrapper around the standard getopt module that provides the following
|
| 4 |
+
additional features:
|
| 5 |
+
* short and long options are tied together
|
| 6 |
+
* options have help strings, so fancy_getopt could potentially
|
| 7 |
+
create a complete usage summary
|
| 8 |
+
* options set attributes of a passed-in object
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import sys, string, re
|
| 12 |
+
import getopt
|
| 13 |
+
from distutils.errors import *
|
| 14 |
+
|
| 15 |
+
# Much like command_re in distutils.core, this is close to but not quite
|
| 16 |
+
# the same as a Python NAME -- except, in the spirit of most GNU
|
| 17 |
+
# utilities, we use '-' in place of '_'. (The spirit of LISP lives on!)
|
| 18 |
+
# The similarities to NAME are again not a coincidence...
|
| 19 |
+
longopt_pat = r'[a-zA-Z](?:[a-zA-Z0-9-]*)'
|
| 20 |
+
longopt_re = re.compile(r'^%s$' % longopt_pat)
|
| 21 |
+
|
| 22 |
+
# For recognizing "negative alias" options, eg. "quiet=!verbose"
|
| 23 |
+
neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat))
|
| 24 |
+
|
| 25 |
+
# This is used to translate long options to legitimate Python identifiers
|
| 26 |
+
# (for use as attributes of some object).
|
| 27 |
+
longopt_xlate = str.maketrans('-', '_')
|
| 28 |
+
|
| 29 |
+
class FancyGetopt:
|
| 30 |
+
"""Wrapper around the standard 'getopt()' module that provides some
|
| 31 |
+
handy extra functionality:
|
| 32 |
+
* short and long options are tied together
|
| 33 |
+
* options have help strings, and help text can be assembled
|
| 34 |
+
from them
|
| 35 |
+
* options set attributes of a passed-in object
|
| 36 |
+
* boolean options can have "negative aliases" -- eg. if
|
| 37 |
+
--quiet is the "negative alias" of --verbose, then "--quiet"
|
| 38 |
+
on the command line sets 'verbose' to false
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
def __init__(self, option_table=None):
|
| 42 |
+
# The option table is (currently) a list of tuples. The
|
| 43 |
+
# tuples may have 3 or four values:
|
| 44 |
+
# (long_option, short_option, help_string [, repeatable])
|
| 45 |
+
# if an option takes an argument, its long_option should have '='
|
| 46 |
+
# appended; short_option should just be a single character, no ':'
|
| 47 |
+
# in any case. If a long_option doesn't have a corresponding
|
| 48 |
+
# short_option, short_option should be None. All option tuples
|
| 49 |
+
# must have long options.
|
| 50 |
+
self.option_table = option_table
|
| 51 |
+
|
| 52 |
+
# 'option_index' maps long option names to entries in the option
|
| 53 |
+
# table (ie. those 3-tuples).
|
| 54 |
+
self.option_index = {}
|
| 55 |
+
if self.option_table:
|
| 56 |
+
self._build_index()
|
| 57 |
+
|
| 58 |
+
# 'alias' records (duh) alias options; {'foo': 'bar'} means
|
| 59 |
+
# --foo is an alias for --bar
|
| 60 |
+
self.alias = {}
|
| 61 |
+
|
| 62 |
+
# 'negative_alias' keeps track of options that are the boolean
|
| 63 |
+
# opposite of some other option
|
| 64 |
+
self.negative_alias = {}
|
| 65 |
+
|
| 66 |
+
# These keep track of the information in the option table. We
|
| 67 |
+
# don't actually populate these structures until we're ready to
|
| 68 |
+
# parse the command-line, since the 'option_table' passed in here
|
| 69 |
+
# isn't necessarily the final word.
|
| 70 |
+
self.short_opts = []
|
| 71 |
+
self.long_opts = []
|
| 72 |
+
self.short2long = {}
|
| 73 |
+
self.attr_name = {}
|
| 74 |
+
self.takes_arg = {}
|
| 75 |
+
|
| 76 |
+
# And 'option_order' is filled up in 'getopt()'; it records the
|
| 77 |
+
# original order of options (and their values) on the command-line,
|
| 78 |
+
# but expands short options, converts aliases, etc.
|
| 79 |
+
self.option_order = []
|
| 80 |
+
|
| 81 |
+
def _build_index(self):
|
| 82 |
+
self.option_index.clear()
|
| 83 |
+
for option in self.option_table:
|
| 84 |
+
self.option_index[option[0]] = option
|
| 85 |
+
|
| 86 |
+
def set_option_table(self, option_table):
|
| 87 |
+
self.option_table = option_table
|
| 88 |
+
self._build_index()
|
| 89 |
+
|
| 90 |
+
def add_option(self, long_option, short_option=None, help_string=None):
|
| 91 |
+
if long_option in self.option_index:
|
| 92 |
+
raise DistutilsGetoptError(
|
| 93 |
+
"option conflict: already an option '%s'" % long_option)
|
| 94 |
+
else:
|
| 95 |
+
option = (long_option, short_option, help_string)
|
| 96 |
+
self.option_table.append(option)
|
| 97 |
+
self.option_index[long_option] = option
|
| 98 |
+
|
| 99 |
+
def has_option(self, long_option):
|
| 100 |
+
"""Return true if the option table for this parser has an
|
| 101 |
+
option with long name 'long_option'."""
|
| 102 |
+
return long_option in self.option_index
|
| 103 |
+
|
| 104 |
+
def get_attr_name(self, long_option):
|
| 105 |
+
"""Translate long option name 'long_option' to the form it
|
| 106 |
+
has as an attribute of some object: ie., translate hyphens
|
| 107 |
+
to underscores."""
|
| 108 |
+
return long_option.translate(longopt_xlate)
|
| 109 |
+
|
| 110 |
+
def _check_alias_dict(self, aliases, what):
|
| 111 |
+
assert isinstance(aliases, dict)
|
| 112 |
+
for (alias, opt) in aliases.items():
|
| 113 |
+
if alias not in self.option_index:
|
| 114 |
+
raise DistutilsGetoptError(("invalid %s '%s': "
|
| 115 |
+
"option '%s' not defined") % (what, alias, alias))
|
| 116 |
+
if opt not in self.option_index:
|
| 117 |
+
raise DistutilsGetoptError(("invalid %s '%s': "
|
| 118 |
+
"aliased option '%s' not defined") % (what, alias, opt))
|
| 119 |
+
|
| 120 |
+
def set_aliases(self, alias):
|
| 121 |
+
"""Set the aliases for this option parser."""
|
| 122 |
+
self._check_alias_dict(alias, "alias")
|
| 123 |
+
self.alias = alias
|
| 124 |
+
|
| 125 |
+
def set_negative_aliases(self, negative_alias):
|
| 126 |
+
"""Set the negative aliases for this option parser.
|
| 127 |
+
'negative_alias' should be a dictionary mapping option names to
|
| 128 |
+
option names, both the key and value must already be defined
|
| 129 |
+
in the option table."""
|
| 130 |
+
self._check_alias_dict(negative_alias, "negative alias")
|
| 131 |
+
self.negative_alias = negative_alias
|
| 132 |
+
|
| 133 |
+
def _grok_option_table(self):
|
| 134 |
+
"""Populate the various data structures that keep tabs on the
|
| 135 |
+
option table. Called by 'getopt()' before it can do anything
|
| 136 |
+
worthwhile.
|
| 137 |
+
"""
|
| 138 |
+
self.long_opts = []
|
| 139 |
+
self.short_opts = []
|
| 140 |
+
self.short2long.clear()
|
| 141 |
+
self.repeat = {}
|
| 142 |
+
|
| 143 |
+
for option in self.option_table:
|
| 144 |
+
if len(option) == 3:
|
| 145 |
+
long, short, help = option
|
| 146 |
+
repeat = 0
|
| 147 |
+
elif len(option) == 4:
|
| 148 |
+
long, short, help, repeat = option
|
| 149 |
+
else:
|
| 150 |
+
# the option table is part of the code, so simply
|
| 151 |
+
# assert that it is correct
|
| 152 |
+
raise ValueError("invalid option tuple: %r" % (option,))
|
| 153 |
+
|
| 154 |
+
# Type- and value-check the option names
|
| 155 |
+
if not isinstance(long, str) or len(long) < 2:
|
| 156 |
+
raise DistutilsGetoptError(("invalid long option '%s': "
|
| 157 |
+
"must be a string of length >= 2") % long)
|
| 158 |
+
|
| 159 |
+
if (not ((short is None) or
|
| 160 |
+
(isinstance(short, str) and len(short) == 1))):
|
| 161 |
+
raise DistutilsGetoptError("invalid short option '%s': "
|
| 162 |
+
"must a single character or None" % short)
|
| 163 |
+
|
| 164 |
+
self.repeat[long] = repeat
|
| 165 |
+
self.long_opts.append(long)
|
| 166 |
+
|
| 167 |
+
if long[-1] == '=': # option takes an argument?
|
| 168 |
+
if short: short = short + ':'
|
| 169 |
+
long = long[0:-1]
|
| 170 |
+
self.takes_arg[long] = 1
|
| 171 |
+
else:
|
| 172 |
+
# Is option is a "negative alias" for some other option (eg.
|
| 173 |
+
# "quiet" == "!verbose")?
|
| 174 |
+
alias_to = self.negative_alias.get(long)
|
| 175 |
+
if alias_to is not None:
|
| 176 |
+
if self.takes_arg[alias_to]:
|
| 177 |
+
raise DistutilsGetoptError(
|
| 178 |
+
"invalid negative alias '%s': "
|
| 179 |
+
"aliased option '%s' takes a value"
|
| 180 |
+
% (long, alias_to))
|
| 181 |
+
|
| 182 |
+
self.long_opts[-1] = long # XXX redundant?!
|
| 183 |
+
self.takes_arg[long] = 0
|
| 184 |
+
|
| 185 |
+
# If this is an alias option, make sure its "takes arg" flag is
|
| 186 |
+
# the same as the option it's aliased to.
|
| 187 |
+
alias_to = self.alias.get(long)
|
| 188 |
+
if alias_to is not None:
|
| 189 |
+
if self.takes_arg[long] != self.takes_arg[alias_to]:
|
| 190 |
+
raise DistutilsGetoptError(
|
| 191 |
+
"invalid alias '%s': inconsistent with "
|
| 192 |
+
"aliased option '%s' (one of them takes a value, "
|
| 193 |
+
"the other doesn't"
|
| 194 |
+
% (long, alias_to))
|
| 195 |
+
|
| 196 |
+
# Now enforce some bondage on the long option name, so we can
|
| 197 |
+
# later translate it to an attribute name on some object. Have
|
| 198 |
+
# to do this a bit late to make sure we've removed any trailing
|
| 199 |
+
# '='.
|
| 200 |
+
if not longopt_re.match(long):
|
| 201 |
+
raise DistutilsGetoptError(
|
| 202 |
+
"invalid long option name '%s' "
|
| 203 |
+
"(must be letters, numbers, hyphens only" % long)
|
| 204 |
+
|
| 205 |
+
self.attr_name[long] = self.get_attr_name(long)
|
| 206 |
+
if short:
|
| 207 |
+
self.short_opts.append(short)
|
| 208 |
+
self.short2long[short[0]] = long
|
| 209 |
+
|
| 210 |
+
def getopt(self, args=None, object=None):
|
| 211 |
+
"""Parse command-line options in args. Store as attributes on object.
|
| 212 |
+
|
| 213 |
+
If 'args' is None or not supplied, uses 'sys.argv[1:]'. If
|
| 214 |
+
'object' is None or not supplied, creates a new OptionDummy
|
| 215 |
+
object, stores option values there, and returns a tuple (args,
|
| 216 |
+
object). If 'object' is supplied, it is modified in place and
|
| 217 |
+
'getopt()' just returns 'args'; in both cases, the returned
|
| 218 |
+
'args' is a modified copy of the passed-in 'args' list, which
|
| 219 |
+
is left untouched.
|
| 220 |
+
"""
|
| 221 |
+
if args is None:
|
| 222 |
+
args = sys.argv[1:]
|
| 223 |
+
if object is None:
|
| 224 |
+
object = OptionDummy()
|
| 225 |
+
created_object = True
|
| 226 |
+
else:
|
| 227 |
+
created_object = False
|
| 228 |
+
|
| 229 |
+
self._grok_option_table()
|
| 230 |
+
|
| 231 |
+
short_opts = ' '.join(self.short_opts)
|
| 232 |
+
try:
|
| 233 |
+
opts, args = getopt.getopt(args, short_opts, self.long_opts)
|
| 234 |
+
except getopt.error as msg:
|
| 235 |
+
raise DistutilsArgError(msg)
|
| 236 |
+
|
| 237 |
+
for opt, val in opts:
|
| 238 |
+
if len(opt) == 2 and opt[0] == '-': # it's a short option
|
| 239 |
+
opt = self.short2long[opt[1]]
|
| 240 |
+
else:
|
| 241 |
+
assert len(opt) > 2 and opt[:2] == '--'
|
| 242 |
+
opt = opt[2:]
|
| 243 |
+
|
| 244 |
+
alias = self.alias.get(opt)
|
| 245 |
+
if alias:
|
| 246 |
+
opt = alias
|
| 247 |
+
|
| 248 |
+
if not self.takes_arg[opt]: # boolean option?
|
| 249 |
+
assert val == '', "boolean option can't have value"
|
| 250 |
+
alias = self.negative_alias.get(opt)
|
| 251 |
+
if alias:
|
| 252 |
+
opt = alias
|
| 253 |
+
val = 0
|
| 254 |
+
else:
|
| 255 |
+
val = 1
|
| 256 |
+
|
| 257 |
+
attr = self.attr_name[opt]
|
| 258 |
+
# The only repeating option at the moment is 'verbose'.
|
| 259 |
+
# It has a negative option -q quiet, which should set verbose = 0.
|
| 260 |
+
if val and self.repeat.get(attr) is not None:
|
| 261 |
+
val = getattr(object, attr, 0) + 1
|
| 262 |
+
setattr(object, attr, val)
|
| 263 |
+
self.option_order.append((opt, val))
|
| 264 |
+
|
| 265 |
+
# for opts
|
| 266 |
+
if created_object:
|
| 267 |
+
return args, object
|
| 268 |
+
else:
|
| 269 |
+
return args
|
| 270 |
+
|
| 271 |
+
def get_option_order(self):
|
| 272 |
+
"""Returns the list of (option, value) tuples processed by the
|
| 273 |
+
previous run of 'getopt()'. Raises RuntimeError if
|
| 274 |
+
'getopt()' hasn't been called yet.
|
| 275 |
+
"""
|
| 276 |
+
if self.option_order is None:
|
| 277 |
+
raise RuntimeError("'getopt()' hasn't been called yet")
|
| 278 |
+
else:
|
| 279 |
+
return self.option_order
|
| 280 |
+
|
| 281 |
+
def generate_help(self, header=None):
|
| 282 |
+
"""Generate help text (a list of strings, one per suggested line of
|
| 283 |
+
output) from the option table for this FancyGetopt object.
|
| 284 |
+
"""
|
| 285 |
+
# Blithely assume the option table is good: probably wouldn't call
|
| 286 |
+
# 'generate_help()' unless you've already called 'getopt()'.
|
| 287 |
+
|
| 288 |
+
# First pass: determine maximum length of long option names
|
| 289 |
+
max_opt = 0
|
| 290 |
+
for option in self.option_table:
|
| 291 |
+
long = option[0]
|
| 292 |
+
short = option[1]
|
| 293 |
+
l = len(long)
|
| 294 |
+
if long[-1] == '=':
|
| 295 |
+
l = l - 1
|
| 296 |
+
if short is not None:
|
| 297 |
+
l = l + 5 # " (-x)" where short == 'x'
|
| 298 |
+
if l > max_opt:
|
| 299 |
+
max_opt = l
|
| 300 |
+
|
| 301 |
+
opt_width = max_opt + 2 + 2 + 2 # room for indent + dashes + gutter
|
| 302 |
+
|
| 303 |
+
# Typical help block looks like this:
|
| 304 |
+
# --foo controls foonabulation
|
| 305 |
+
# Help block for longest option looks like this:
|
| 306 |
+
# --flimflam set the flim-flam level
|
| 307 |
+
# and with wrapped text:
|
| 308 |
+
# --flimflam set the flim-flam level (must be between
|
| 309 |
+
# 0 and 100, except on Tuesdays)
|
| 310 |
+
# Options with short names will have the short name shown (but
|
| 311 |
+
# it doesn't contribute to max_opt):
|
| 312 |
+
# --foo (-f) controls foonabulation
|
| 313 |
+
# If adding the short option would make the left column too wide,
|
| 314 |
+
# we push the explanation off to the next line
|
| 315 |
+
# --flimflam (-l)
|
| 316 |
+
# set the flim-flam level
|
| 317 |
+
# Important parameters:
|
| 318 |
+
# - 2 spaces before option block start lines
|
| 319 |
+
# - 2 dashes for each long option name
|
| 320 |
+
# - min. 2 spaces between option and explanation (gutter)
|
| 321 |
+
# - 5 characters (incl. space) for short option name
|
| 322 |
+
|
| 323 |
+
# Now generate lines of help text. (If 80 columns were good enough
|
| 324 |
+
# for Jesus, then 78 columns are good enough for me!)
|
| 325 |
+
line_width = 78
|
| 326 |
+
text_width = line_width - opt_width
|
| 327 |
+
big_indent = ' ' * opt_width
|
| 328 |
+
if header:
|
| 329 |
+
lines = [header]
|
| 330 |
+
else:
|
| 331 |
+
lines = ['Option summary:']
|
| 332 |
+
|
| 333 |
+
for option in self.option_table:
|
| 334 |
+
long, short, help = option[:3]
|
| 335 |
+
text = wrap_text(help, text_width)
|
| 336 |
+
if long[-1] == '=':
|
| 337 |
+
long = long[0:-1]
|
| 338 |
+
|
| 339 |
+
# Case 1: no short option at all (makes life easy)
|
| 340 |
+
if short is None:
|
| 341 |
+
if text:
|
| 342 |
+
lines.append(" --%-*s %s" % (max_opt, long, text[0]))
|
| 343 |
+
else:
|
| 344 |
+
lines.append(" --%-*s " % (max_opt, long))
|
| 345 |
+
|
| 346 |
+
# Case 2: we have a short option, so we have to include it
|
| 347 |
+
# just after the long option
|
| 348 |
+
else:
|
| 349 |
+
opt_names = "%s (-%s)" % (long, short)
|
| 350 |
+
if text:
|
| 351 |
+
lines.append(" --%-*s %s" %
|
| 352 |
+
(max_opt, opt_names, text[0]))
|
| 353 |
+
else:
|
| 354 |
+
lines.append(" --%-*s" % opt_names)
|
| 355 |
+
|
| 356 |
+
for l in text[1:]:
|
| 357 |
+
lines.append(big_indent + l)
|
| 358 |
+
return lines
|
| 359 |
+
|
| 360 |
+
def print_help(self, header=None, file=None):
|
| 361 |
+
if file is None:
|
| 362 |
+
file = sys.stdout
|
| 363 |
+
for line in self.generate_help(header):
|
| 364 |
+
file.write(line + "\n")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def fancy_getopt(options, negative_opt, object, args):
|
| 368 |
+
parser = FancyGetopt(options)
|
| 369 |
+
parser.set_negative_aliases(negative_opt)
|
| 370 |
+
return parser.getopt(args, object)
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
WS_TRANS = {ord(_wschar) : ' ' for _wschar in string.whitespace}
|
| 374 |
+
|
| 375 |
+
def wrap_text(text, width):
|
| 376 |
+
"""wrap_text(text : string, width : int) -> [string]
|
| 377 |
+
|
| 378 |
+
Split 'text' into multiple lines of no more than 'width' characters
|
| 379 |
+
each, and return the list of strings that results.
|
| 380 |
+
"""
|
| 381 |
+
if text is None:
|
| 382 |
+
return []
|
| 383 |
+
if len(text) <= width:
|
| 384 |
+
return [text]
|
| 385 |
+
|
| 386 |
+
text = text.expandtabs()
|
| 387 |
+
text = text.translate(WS_TRANS)
|
| 388 |
+
chunks = re.split(r'( +|-+)', text)
|
| 389 |
+
chunks = [ch for ch in chunks if ch] # ' - ' results in empty strings
|
| 390 |
+
lines = []
|
| 391 |
+
|
| 392 |
+
while chunks:
|
| 393 |
+
cur_line = [] # list of chunks (to-be-joined)
|
| 394 |
+
cur_len = 0 # length of current line
|
| 395 |
+
|
| 396 |
+
while chunks:
|
| 397 |
+
l = len(chunks[0])
|
| 398 |
+
if cur_len + l <= width: # can squeeze (at least) this chunk in
|
| 399 |
+
cur_line.append(chunks[0])
|
| 400 |
+
del chunks[0]
|
| 401 |
+
cur_len = cur_len + l
|
| 402 |
+
else: # this line is full
|
| 403 |
+
# drop last chunk if all space
|
| 404 |
+
if cur_line and cur_line[-1][0] == ' ':
|
| 405 |
+
del cur_line[-1]
|
| 406 |
+
break
|
| 407 |
+
|
| 408 |
+
if chunks: # any chunks left to process?
|
| 409 |
+
# if the current line is still empty, then we had a single
|
| 410 |
+
# chunk that's too big too fit on a line -- so we break
|
| 411 |
+
# down and break it up at the line width
|
| 412 |
+
if cur_len == 0:
|
| 413 |
+
cur_line.append(chunks[0][0:width])
|
| 414 |
+
chunks[0] = chunks[0][width:]
|
| 415 |
+
|
| 416 |
+
# all-whitespace chunks at the end of a line can be discarded
|
| 417 |
+
# (and we know from the re.split above that if a chunk has
|
| 418 |
+
# *any* whitespace, it is *all* whitespace)
|
| 419 |
+
if chunks[0][0] == ' ':
|
| 420 |
+
del chunks[0]
|
| 421 |
+
|
| 422 |
+
# and store this line in the list-of-all-lines -- as a single
|
| 423 |
+
# string, of course!
|
| 424 |
+
lines.append(''.join(cur_line))
|
| 425 |
+
|
| 426 |
+
return lines
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
def translate_longopt(opt):
|
| 430 |
+
"""Convert a long option name to a valid Python identifier by
|
| 431 |
+
changing "-" to "_".
|
| 432 |
+
"""
|
| 433 |
+
return opt.translate(longopt_xlate)
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
class OptionDummy:
|
| 437 |
+
"""Dummy class just used as a place to hold command-line option
|
| 438 |
+
values as instance attributes."""
|
| 439 |
+
|
| 440 |
+
def __init__(self, options=[]):
|
| 441 |
+
"""Create a new OptionDummy instance. The attributes listed in
|
| 442 |
+
'options' will be initialized to None."""
|
| 443 |
+
for opt in options:
|
| 444 |
+
setattr(self, opt, None)
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
if __name__ == "__main__":
|
| 448 |
+
text = """\
|
| 449 |
+
Tra-la-la, supercalifragilisticexpialidocious.
|
| 450 |
+
How *do* you spell that odd word, anyways?
|
| 451 |
+
(Someone ask Mary -- she'll know [or she'll
|
| 452 |
+
say, "How should I know?"].)"""
|
| 453 |
+
|
| 454 |
+
for w in (10, 20, 30, 40):
|
| 455 |
+
print("width: %d" % w)
|
| 456 |
+
print("\n".join(wrap_text(text, w)))
|
| 457 |
+
print()
|
data/conda_envs/evalclaw/lib/python3.11/distutils/file_util.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.file_util
|
| 2 |
+
|
| 3 |
+
Utility functions for operating on single files.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
from distutils.errors import DistutilsFileError
|
| 8 |
+
from distutils import log
|
| 9 |
+
|
| 10 |
+
# for generating verbose output in 'copy_file()'
|
| 11 |
+
_copy_action = { None: 'copying',
|
| 12 |
+
'hard': 'hard linking',
|
| 13 |
+
'sym': 'symbolically linking' }
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _copy_file_contents(src, dst, buffer_size=16*1024):
|
| 17 |
+
"""Copy the file 'src' to 'dst'; both must be filenames. Any error
|
| 18 |
+
opening either file, reading from 'src', or writing to 'dst', raises
|
| 19 |
+
DistutilsFileError. Data is read/written in chunks of 'buffer_size'
|
| 20 |
+
bytes (default 16k). No attempt is made to handle anything apart from
|
| 21 |
+
regular files.
|
| 22 |
+
"""
|
| 23 |
+
# Stolen from shutil module in the standard library, but with
|
| 24 |
+
# custom error-handling added.
|
| 25 |
+
fsrc = None
|
| 26 |
+
fdst = None
|
| 27 |
+
try:
|
| 28 |
+
try:
|
| 29 |
+
fsrc = open(src, 'rb')
|
| 30 |
+
except OSError as e:
|
| 31 |
+
raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror))
|
| 32 |
+
|
| 33 |
+
if os.path.exists(dst):
|
| 34 |
+
try:
|
| 35 |
+
os.unlink(dst)
|
| 36 |
+
except OSError as e:
|
| 37 |
+
raise DistutilsFileError(
|
| 38 |
+
"could not delete '%s': %s" % (dst, e.strerror))
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
fdst = open(dst, 'wb')
|
| 42 |
+
except OSError as e:
|
| 43 |
+
raise DistutilsFileError(
|
| 44 |
+
"could not create '%s': %s" % (dst, e.strerror))
|
| 45 |
+
|
| 46 |
+
while True:
|
| 47 |
+
try:
|
| 48 |
+
buf = fsrc.read(buffer_size)
|
| 49 |
+
except OSError as e:
|
| 50 |
+
raise DistutilsFileError(
|
| 51 |
+
"could not read from '%s': %s" % (src, e.strerror))
|
| 52 |
+
|
| 53 |
+
if not buf:
|
| 54 |
+
break
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
fdst.write(buf)
|
| 58 |
+
except OSError as e:
|
| 59 |
+
raise DistutilsFileError(
|
| 60 |
+
"could not write to '%s': %s" % (dst, e.strerror))
|
| 61 |
+
finally:
|
| 62 |
+
if fdst:
|
| 63 |
+
fdst.close()
|
| 64 |
+
if fsrc:
|
| 65 |
+
fsrc.close()
|
| 66 |
+
|
| 67 |
+
def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0,
|
| 68 |
+
link=None, verbose=1, dry_run=0):
|
| 69 |
+
"""Copy a file 'src' to 'dst'. If 'dst' is a directory, then 'src' is
|
| 70 |
+
copied there with the same name; otherwise, it must be a filename. (If
|
| 71 |
+
the file exists, it will be ruthlessly clobbered.) If 'preserve_mode'
|
| 72 |
+
is true (the default), the file's mode (type and permission bits, or
|
| 73 |
+
whatever is analogous on the current platform) is copied. If
|
| 74 |
+
'preserve_times' is true (the default), the last-modified and
|
| 75 |
+
last-access times are copied as well. If 'update' is true, 'src' will
|
| 76 |
+
only be copied if 'dst' does not exist, or if 'dst' does exist but is
|
| 77 |
+
older than 'src'.
|
| 78 |
+
|
| 79 |
+
'link' allows you to make hard links (os.link) or symbolic links
|
| 80 |
+
(os.symlink) instead of copying: set it to "hard" or "sym"; if it is
|
| 81 |
+
None (the default), files are copied. Don't set 'link' on systems that
|
| 82 |
+
don't support it: 'copy_file()' doesn't check if hard or symbolic
|
| 83 |
+
linking is available. If hardlink fails, falls back to
|
| 84 |
+
_copy_file_contents().
|
| 85 |
+
|
| 86 |
+
Under Mac OS, uses the native file copy function in macostools; on
|
| 87 |
+
other systems, uses '_copy_file_contents()' to copy file contents.
|
| 88 |
+
|
| 89 |
+
Return a tuple (dest_name, copied): 'dest_name' is the actual name of
|
| 90 |
+
the output file, and 'copied' is true if the file was copied (or would
|
| 91 |
+
have been copied, if 'dry_run' true).
|
| 92 |
+
"""
|
| 93 |
+
# XXX if the destination file already exists, we clobber it if
|
| 94 |
+
# copying, but blow up if linking. Hmmm. And I don't know what
|
| 95 |
+
# macostools.copyfile() does. Should definitely be consistent, and
|
| 96 |
+
# should probably blow up if destination exists and we would be
|
| 97 |
+
# changing it (ie. it's not already a hard/soft link to src OR
|
| 98 |
+
# (not update) and (src newer than dst).
|
| 99 |
+
|
| 100 |
+
from distutils.dep_util import newer
|
| 101 |
+
from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE
|
| 102 |
+
|
| 103 |
+
if not os.path.isfile(src):
|
| 104 |
+
raise DistutilsFileError(
|
| 105 |
+
"can't copy '%s': doesn't exist or not a regular file" % src)
|
| 106 |
+
|
| 107 |
+
if os.path.isdir(dst):
|
| 108 |
+
dir = dst
|
| 109 |
+
dst = os.path.join(dst, os.path.basename(src))
|
| 110 |
+
else:
|
| 111 |
+
dir = os.path.dirname(dst)
|
| 112 |
+
|
| 113 |
+
if update and not newer(src, dst):
|
| 114 |
+
if verbose >= 1:
|
| 115 |
+
log.debug("not copying %s (output up-to-date)", src)
|
| 116 |
+
return (dst, 0)
|
| 117 |
+
|
| 118 |
+
try:
|
| 119 |
+
action = _copy_action[link]
|
| 120 |
+
except KeyError:
|
| 121 |
+
raise ValueError("invalid value '%s' for 'link' argument" % link)
|
| 122 |
+
|
| 123 |
+
if verbose >= 1:
|
| 124 |
+
if os.path.basename(dst) == os.path.basename(src):
|
| 125 |
+
log.info("%s %s -> %s", action, src, dir)
|
| 126 |
+
else:
|
| 127 |
+
log.info("%s %s -> %s", action, src, dst)
|
| 128 |
+
|
| 129 |
+
if dry_run:
|
| 130 |
+
return (dst, 1)
|
| 131 |
+
|
| 132 |
+
# If linking (hard or symbolic), use the appropriate system call
|
| 133 |
+
# (Unix only, of course, but that's the caller's responsibility)
|
| 134 |
+
elif link == 'hard':
|
| 135 |
+
if not (os.path.exists(dst) and os.path.samefile(src, dst)):
|
| 136 |
+
try:
|
| 137 |
+
os.link(src, dst)
|
| 138 |
+
return (dst, 1)
|
| 139 |
+
except OSError:
|
| 140 |
+
# If hard linking fails, fall back on copying file
|
| 141 |
+
# (some special filesystems don't support hard linking
|
| 142 |
+
# even under Unix, see issue #8876).
|
| 143 |
+
pass
|
| 144 |
+
elif link == 'sym':
|
| 145 |
+
if not (os.path.exists(dst) and os.path.samefile(src, dst)):
|
| 146 |
+
os.symlink(src, dst)
|
| 147 |
+
return (dst, 1)
|
| 148 |
+
|
| 149 |
+
# Otherwise (non-Mac, not linking), copy the file contents and
|
| 150 |
+
# (optionally) copy the times and mode.
|
| 151 |
+
_copy_file_contents(src, dst)
|
| 152 |
+
if preserve_mode or preserve_times:
|
| 153 |
+
st = os.stat(src)
|
| 154 |
+
|
| 155 |
+
# According to David Ascher <da@ski.org>, utime() should be done
|
| 156 |
+
# before chmod() (at least under NT).
|
| 157 |
+
if preserve_times:
|
| 158 |
+
os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))
|
| 159 |
+
if preserve_mode:
|
| 160 |
+
os.chmod(dst, S_IMODE(st[ST_MODE]))
|
| 161 |
+
|
| 162 |
+
return (dst, 1)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
# XXX I suspect this is Unix-specific -- need porting help!
|
| 166 |
+
def move_file (src, dst,
|
| 167 |
+
verbose=1,
|
| 168 |
+
dry_run=0):
|
| 169 |
+
|
| 170 |
+
"""Move a file 'src' to 'dst'. If 'dst' is a directory, the file will
|
| 171 |
+
be moved into it with the same name; otherwise, 'src' is just renamed
|
| 172 |
+
to 'dst'. Return the new full name of the file.
|
| 173 |
+
|
| 174 |
+
Handles cross-device moves on Unix using 'copy_file()'. What about
|
| 175 |
+
other systems???
|
| 176 |
+
"""
|
| 177 |
+
from os.path import exists, isfile, isdir, basename, dirname
|
| 178 |
+
import errno
|
| 179 |
+
|
| 180 |
+
if verbose >= 1:
|
| 181 |
+
log.info("moving %s -> %s", src, dst)
|
| 182 |
+
|
| 183 |
+
if dry_run:
|
| 184 |
+
return dst
|
| 185 |
+
|
| 186 |
+
if not isfile(src):
|
| 187 |
+
raise DistutilsFileError("can't move '%s': not a regular file" % src)
|
| 188 |
+
|
| 189 |
+
if isdir(dst):
|
| 190 |
+
dst = os.path.join(dst, basename(src))
|
| 191 |
+
elif exists(dst):
|
| 192 |
+
raise DistutilsFileError(
|
| 193 |
+
"can't move '%s': destination '%s' already exists" %
|
| 194 |
+
(src, dst))
|
| 195 |
+
|
| 196 |
+
if not isdir(dirname(dst)):
|
| 197 |
+
raise DistutilsFileError(
|
| 198 |
+
"can't move '%s': destination '%s' not a valid path" %
|
| 199 |
+
(src, dst))
|
| 200 |
+
|
| 201 |
+
copy_it = False
|
| 202 |
+
try:
|
| 203 |
+
os.rename(src, dst)
|
| 204 |
+
except OSError as e:
|
| 205 |
+
(num, msg) = e.args
|
| 206 |
+
if num == errno.EXDEV:
|
| 207 |
+
copy_it = True
|
| 208 |
+
else:
|
| 209 |
+
raise DistutilsFileError(
|
| 210 |
+
"couldn't move '%s' to '%s': %s" % (src, dst, msg))
|
| 211 |
+
|
| 212 |
+
if copy_it:
|
| 213 |
+
copy_file(src, dst, verbose=verbose)
|
| 214 |
+
try:
|
| 215 |
+
os.unlink(src)
|
| 216 |
+
except OSError as e:
|
| 217 |
+
(num, msg) = e.args
|
| 218 |
+
try:
|
| 219 |
+
os.unlink(dst)
|
| 220 |
+
except OSError:
|
| 221 |
+
pass
|
| 222 |
+
raise DistutilsFileError(
|
| 223 |
+
"couldn't move '%s' to '%s' by copy/delete: "
|
| 224 |
+
"delete '%s' failed: %s"
|
| 225 |
+
% (src, dst, src, msg))
|
| 226 |
+
return dst
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def write_file (filename, contents):
|
| 230 |
+
"""Create a file with the specified name and write 'contents' (a
|
| 231 |
+
sequence of strings without line terminators) to it.
|
| 232 |
+
"""
|
| 233 |
+
f = open(filename, "w")
|
| 234 |
+
try:
|
| 235 |
+
for line in contents:
|
| 236 |
+
f.write(line + "\n")
|
| 237 |
+
finally:
|
| 238 |
+
f.close()
|
data/conda_envs/evalclaw/lib/python3.11/distutils/filelist.py
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.filelist
|
| 2 |
+
|
| 3 |
+
Provides the FileList class, used for poking about the filesystem
|
| 4 |
+
and building lists of files.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os, re
|
| 8 |
+
import fnmatch
|
| 9 |
+
import functools
|
| 10 |
+
from distutils.util import convert_path
|
| 11 |
+
from distutils.errors import DistutilsTemplateError, DistutilsInternalError
|
| 12 |
+
from distutils import log
|
| 13 |
+
|
| 14 |
+
class FileList:
|
| 15 |
+
"""A list of files built by on exploring the filesystem and filtered by
|
| 16 |
+
applying various patterns to what we find there.
|
| 17 |
+
|
| 18 |
+
Instance attributes:
|
| 19 |
+
dir
|
| 20 |
+
directory from which files will be taken -- only used if
|
| 21 |
+
'allfiles' not supplied to constructor
|
| 22 |
+
files
|
| 23 |
+
list of filenames currently being built/filtered/manipulated
|
| 24 |
+
allfiles
|
| 25 |
+
complete list of files under consideration (ie. without any
|
| 26 |
+
filtering applied)
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
def __init__(self, warn=None, debug_print=None):
|
| 30 |
+
# ignore argument to FileList, but keep them for backwards
|
| 31 |
+
# compatibility
|
| 32 |
+
self.allfiles = None
|
| 33 |
+
self.files = []
|
| 34 |
+
|
| 35 |
+
def set_allfiles(self, allfiles):
|
| 36 |
+
self.allfiles = allfiles
|
| 37 |
+
|
| 38 |
+
def findall(self, dir=os.curdir):
|
| 39 |
+
self.allfiles = findall(dir)
|
| 40 |
+
|
| 41 |
+
def debug_print(self, msg):
|
| 42 |
+
"""Print 'msg' to stdout if the global DEBUG (taken from the
|
| 43 |
+
DISTUTILS_DEBUG environment variable) flag is true.
|
| 44 |
+
"""
|
| 45 |
+
from distutils.debug import DEBUG
|
| 46 |
+
if DEBUG:
|
| 47 |
+
print(msg)
|
| 48 |
+
|
| 49 |
+
# -- List-like methods ---------------------------------------------
|
| 50 |
+
|
| 51 |
+
def append(self, item):
|
| 52 |
+
self.files.append(item)
|
| 53 |
+
|
| 54 |
+
def extend(self, items):
|
| 55 |
+
self.files.extend(items)
|
| 56 |
+
|
| 57 |
+
def sort(self):
|
| 58 |
+
# Not a strict lexical sort!
|
| 59 |
+
sortable_files = sorted(map(os.path.split, self.files))
|
| 60 |
+
self.files = []
|
| 61 |
+
for sort_tuple in sortable_files:
|
| 62 |
+
self.files.append(os.path.join(*sort_tuple))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# -- Other miscellaneous utility methods ---------------------------
|
| 66 |
+
|
| 67 |
+
def remove_duplicates(self):
|
| 68 |
+
# Assumes list has been sorted!
|
| 69 |
+
for i in range(len(self.files) - 1, 0, -1):
|
| 70 |
+
if self.files[i] == self.files[i - 1]:
|
| 71 |
+
del self.files[i]
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
# -- "File template" methods ---------------------------------------
|
| 75 |
+
|
| 76 |
+
def _parse_template_line(self, line):
|
| 77 |
+
words = line.split()
|
| 78 |
+
action = words[0]
|
| 79 |
+
|
| 80 |
+
patterns = dir = dir_pattern = None
|
| 81 |
+
|
| 82 |
+
if action in ('include', 'exclude',
|
| 83 |
+
'global-include', 'global-exclude'):
|
| 84 |
+
if len(words) < 2:
|
| 85 |
+
raise DistutilsTemplateError(
|
| 86 |
+
"'%s' expects <pattern1> <pattern2> ..." % action)
|
| 87 |
+
patterns = [convert_path(w) for w in words[1:]]
|
| 88 |
+
elif action in ('recursive-include', 'recursive-exclude'):
|
| 89 |
+
if len(words) < 3:
|
| 90 |
+
raise DistutilsTemplateError(
|
| 91 |
+
"'%s' expects <dir> <pattern1> <pattern2> ..." % action)
|
| 92 |
+
dir = convert_path(words[1])
|
| 93 |
+
patterns = [convert_path(w) for w in words[2:]]
|
| 94 |
+
elif action in ('graft', 'prune'):
|
| 95 |
+
if len(words) != 2:
|
| 96 |
+
raise DistutilsTemplateError(
|
| 97 |
+
"'%s' expects a single <dir_pattern>" % action)
|
| 98 |
+
dir_pattern = convert_path(words[1])
|
| 99 |
+
else:
|
| 100 |
+
raise DistutilsTemplateError("unknown action '%s'" % action)
|
| 101 |
+
|
| 102 |
+
return (action, patterns, dir, dir_pattern)
|
| 103 |
+
|
| 104 |
+
def process_template_line(self, line):
|
| 105 |
+
# Parse the line: split it up, make sure the right number of words
|
| 106 |
+
# is there, and return the relevant words. 'action' is always
|
| 107 |
+
# defined: it's the first word of the line. Which of the other
|
| 108 |
+
# three are defined depends on the action; it'll be either
|
| 109 |
+
# patterns, (dir and patterns), or (dir_pattern).
|
| 110 |
+
(action, patterns, dir, dir_pattern) = self._parse_template_line(line)
|
| 111 |
+
|
| 112 |
+
# OK, now we know that the action is valid and we have the
|
| 113 |
+
# right number of words on the line for that action -- so we
|
| 114 |
+
# can proceed with minimal error-checking.
|
| 115 |
+
if action == 'include':
|
| 116 |
+
self.debug_print("include " + ' '.join(patterns))
|
| 117 |
+
for pattern in patterns:
|
| 118 |
+
if not self.include_pattern(pattern, anchor=1):
|
| 119 |
+
log.warn("warning: no files found matching '%s'",
|
| 120 |
+
pattern)
|
| 121 |
+
|
| 122 |
+
elif action == 'exclude':
|
| 123 |
+
self.debug_print("exclude " + ' '.join(patterns))
|
| 124 |
+
for pattern in patterns:
|
| 125 |
+
if not self.exclude_pattern(pattern, anchor=1):
|
| 126 |
+
log.warn(("warning: no previously-included files "
|
| 127 |
+
"found matching '%s'"), pattern)
|
| 128 |
+
|
| 129 |
+
elif action == 'global-include':
|
| 130 |
+
self.debug_print("global-include " + ' '.join(patterns))
|
| 131 |
+
for pattern in patterns:
|
| 132 |
+
if not self.include_pattern(pattern, anchor=0):
|
| 133 |
+
log.warn(("warning: no files found matching '%s' "
|
| 134 |
+
"anywhere in distribution"), pattern)
|
| 135 |
+
|
| 136 |
+
elif action == 'global-exclude':
|
| 137 |
+
self.debug_print("global-exclude " + ' '.join(patterns))
|
| 138 |
+
for pattern in patterns:
|
| 139 |
+
if not self.exclude_pattern(pattern, anchor=0):
|
| 140 |
+
log.warn(("warning: no previously-included files matching "
|
| 141 |
+
"'%s' found anywhere in distribution"),
|
| 142 |
+
pattern)
|
| 143 |
+
|
| 144 |
+
elif action == 'recursive-include':
|
| 145 |
+
self.debug_print("recursive-include %s %s" %
|
| 146 |
+
(dir, ' '.join(patterns)))
|
| 147 |
+
for pattern in patterns:
|
| 148 |
+
if not self.include_pattern(pattern, prefix=dir):
|
| 149 |
+
log.warn(("warning: no files found matching '%s' "
|
| 150 |
+
"under directory '%s'"),
|
| 151 |
+
pattern, dir)
|
| 152 |
+
|
| 153 |
+
elif action == 'recursive-exclude':
|
| 154 |
+
self.debug_print("recursive-exclude %s %s" %
|
| 155 |
+
(dir, ' '.join(patterns)))
|
| 156 |
+
for pattern in patterns:
|
| 157 |
+
if not self.exclude_pattern(pattern, prefix=dir):
|
| 158 |
+
log.warn(("warning: no previously-included files matching "
|
| 159 |
+
"'%s' found under directory '%s'"),
|
| 160 |
+
pattern, dir)
|
| 161 |
+
|
| 162 |
+
elif action == 'graft':
|
| 163 |
+
self.debug_print("graft " + dir_pattern)
|
| 164 |
+
if not self.include_pattern(None, prefix=dir_pattern):
|
| 165 |
+
log.warn("warning: no directories found matching '%s'",
|
| 166 |
+
dir_pattern)
|
| 167 |
+
|
| 168 |
+
elif action == 'prune':
|
| 169 |
+
self.debug_print("prune " + dir_pattern)
|
| 170 |
+
if not self.exclude_pattern(None, prefix=dir_pattern):
|
| 171 |
+
log.warn(("no previously-included directories found "
|
| 172 |
+
"matching '%s'"), dir_pattern)
|
| 173 |
+
else:
|
| 174 |
+
raise DistutilsInternalError(
|
| 175 |
+
"this cannot happen: invalid action '%s'" % action)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
# -- Filtering/selection methods -----------------------------------
|
| 179 |
+
|
| 180 |
+
def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
|
| 181 |
+
"""Select strings (presumably filenames) from 'self.files' that
|
| 182 |
+
match 'pattern', a Unix-style wildcard (glob) pattern. Patterns
|
| 183 |
+
are not quite the same as implemented by the 'fnmatch' module: '*'
|
| 184 |
+
and '?' match non-special characters, where "special" is platform-
|
| 185 |
+
dependent: slash on Unix; colon, slash, and backslash on
|
| 186 |
+
DOS/Windows; and colon on Mac OS.
|
| 187 |
+
|
| 188 |
+
If 'anchor' is true (the default), then the pattern match is more
|
| 189 |
+
stringent: "*.py" will match "foo.py" but not "foo/bar.py". If
|
| 190 |
+
'anchor' is false, both of these will match.
|
| 191 |
+
|
| 192 |
+
If 'prefix' is supplied, then only filenames starting with 'prefix'
|
| 193 |
+
(itself a pattern) and ending with 'pattern', with anything in between
|
| 194 |
+
them, will match. 'anchor' is ignored in this case.
|
| 195 |
+
|
| 196 |
+
If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and
|
| 197 |
+
'pattern' is assumed to be either a string containing a regex or a
|
| 198 |
+
regex object -- no translation is done, the regex is just compiled
|
| 199 |
+
and used as-is.
|
| 200 |
+
|
| 201 |
+
Selected strings will be added to self.files.
|
| 202 |
+
|
| 203 |
+
Return True if files are found, False otherwise.
|
| 204 |
+
"""
|
| 205 |
+
# XXX docstring lying about what the special chars are?
|
| 206 |
+
files_found = False
|
| 207 |
+
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
|
| 208 |
+
self.debug_print("include_pattern: applying regex r'%s'" %
|
| 209 |
+
pattern_re.pattern)
|
| 210 |
+
|
| 211 |
+
# delayed loading of allfiles list
|
| 212 |
+
if self.allfiles is None:
|
| 213 |
+
self.findall()
|
| 214 |
+
|
| 215 |
+
for name in self.allfiles:
|
| 216 |
+
if pattern_re.search(name):
|
| 217 |
+
self.debug_print(" adding " + name)
|
| 218 |
+
self.files.append(name)
|
| 219 |
+
files_found = True
|
| 220 |
+
return files_found
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def exclude_pattern (self, pattern,
|
| 224 |
+
anchor=1, prefix=None, is_regex=0):
|
| 225 |
+
"""Remove strings (presumably filenames) from 'files' that match
|
| 226 |
+
'pattern'. Other parameters are the same as for
|
| 227 |
+
'include_pattern()', above.
|
| 228 |
+
The list 'self.files' is modified in place.
|
| 229 |
+
Return True if files are found, False otherwise.
|
| 230 |
+
"""
|
| 231 |
+
files_found = False
|
| 232 |
+
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
|
| 233 |
+
self.debug_print("exclude_pattern: applying regex r'%s'" %
|
| 234 |
+
pattern_re.pattern)
|
| 235 |
+
for i in range(len(self.files)-1, -1, -1):
|
| 236 |
+
if pattern_re.search(self.files[i]):
|
| 237 |
+
self.debug_print(" removing " + self.files[i])
|
| 238 |
+
del self.files[i]
|
| 239 |
+
files_found = True
|
| 240 |
+
return files_found
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
# ----------------------------------------------------------------------
|
| 244 |
+
# Utility functions
|
| 245 |
+
|
| 246 |
+
def _find_all_simple(path):
|
| 247 |
+
"""
|
| 248 |
+
Find all files under 'path'
|
| 249 |
+
"""
|
| 250 |
+
results = (
|
| 251 |
+
os.path.join(base, file)
|
| 252 |
+
for base, dirs, files in os.walk(path, followlinks=True)
|
| 253 |
+
for file in files
|
| 254 |
+
)
|
| 255 |
+
return filter(os.path.isfile, results)
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def findall(dir=os.curdir):
|
| 259 |
+
"""
|
| 260 |
+
Find all files under 'dir' and return the list of full filenames.
|
| 261 |
+
Unless dir is '.', return full filenames with dir prepended.
|
| 262 |
+
"""
|
| 263 |
+
files = _find_all_simple(dir)
|
| 264 |
+
if dir == os.curdir:
|
| 265 |
+
make_rel = functools.partial(os.path.relpath, start=dir)
|
| 266 |
+
files = map(make_rel, files)
|
| 267 |
+
return list(files)
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def glob_to_re(pattern):
|
| 271 |
+
"""Translate a shell-like glob pattern to a regular expression; return
|
| 272 |
+
a string containing the regex. Differs from 'fnmatch.translate()' in
|
| 273 |
+
that '*' does not match "special characters" (which are
|
| 274 |
+
platform-specific).
|
| 275 |
+
"""
|
| 276 |
+
pattern_re = fnmatch.translate(pattern)
|
| 277 |
+
|
| 278 |
+
# '?' and '*' in the glob pattern become '.' and '.*' in the RE, which
|
| 279 |
+
# IMHO is wrong -- '?' and '*' aren't supposed to match slash in Unix,
|
| 280 |
+
# and by extension they shouldn't match such "special characters" under
|
| 281 |
+
# any OS. So change all non-escaped dots in the RE to match any
|
| 282 |
+
# character except the special characters (currently: just os.sep).
|
| 283 |
+
sep = os.sep
|
| 284 |
+
if os.sep == '\\':
|
| 285 |
+
# we're using a regex to manipulate a regex, so we need
|
| 286 |
+
# to escape the backslash twice
|
| 287 |
+
sep = r'\\\\'
|
| 288 |
+
escaped = r'\1[^%s]' % sep
|
| 289 |
+
pattern_re = re.sub(r'((?<!\\)(\\\\)*)\.', escaped, pattern_re)
|
| 290 |
+
return pattern_re
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
|
| 294 |
+
"""Translate a shell-like wildcard pattern to a compiled regular
|
| 295 |
+
expression. Return the compiled regex. If 'is_regex' true,
|
| 296 |
+
then 'pattern' is directly compiled to a regex (if it's a string)
|
| 297 |
+
or just returned as-is (assumes it's a regex object).
|
| 298 |
+
"""
|
| 299 |
+
if is_regex:
|
| 300 |
+
if isinstance(pattern, str):
|
| 301 |
+
return re.compile(pattern)
|
| 302 |
+
else:
|
| 303 |
+
return pattern
|
| 304 |
+
|
| 305 |
+
# ditch start and end characters
|
| 306 |
+
start, _, end = glob_to_re('_').partition('_')
|
| 307 |
+
|
| 308 |
+
if pattern:
|
| 309 |
+
pattern_re = glob_to_re(pattern)
|
| 310 |
+
assert pattern_re.startswith(start) and pattern_re.endswith(end)
|
| 311 |
+
else:
|
| 312 |
+
pattern_re = ''
|
| 313 |
+
|
| 314 |
+
if prefix is not None:
|
| 315 |
+
prefix_re = glob_to_re(prefix)
|
| 316 |
+
assert prefix_re.startswith(start) and prefix_re.endswith(end)
|
| 317 |
+
prefix_re = prefix_re[len(start): len(prefix_re) - len(end)]
|
| 318 |
+
sep = os.sep
|
| 319 |
+
if os.sep == '\\':
|
| 320 |
+
sep = r'\\'
|
| 321 |
+
pattern_re = pattern_re[len(start): len(pattern_re) - len(end)]
|
| 322 |
+
pattern_re = r'%s\A%s%s.*%s%s' % (start, prefix_re, sep, pattern_re, end)
|
| 323 |
+
else: # no prefix -- respect anchor flag
|
| 324 |
+
if anchor:
|
| 325 |
+
pattern_re = r'%s\A%s' % (start, pattern_re[len(start):])
|
| 326 |
+
|
| 327 |
+
return re.compile(pattern_re)
|
data/conda_envs/evalclaw/lib/python3.11/distutils/log.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A simple log mechanism styled after PEP 282."""
|
| 2 |
+
|
| 3 |
+
# The class here is styled after PEP 282 so that it could later be
|
| 4 |
+
# replaced with a standard Python logging implementation.
|
| 5 |
+
|
| 6 |
+
DEBUG = 1
|
| 7 |
+
INFO = 2
|
| 8 |
+
WARN = 3
|
| 9 |
+
ERROR = 4
|
| 10 |
+
FATAL = 5
|
| 11 |
+
|
| 12 |
+
import sys
|
| 13 |
+
|
| 14 |
+
class Log:
|
| 15 |
+
|
| 16 |
+
def __init__(self, threshold=WARN):
|
| 17 |
+
self.threshold = threshold
|
| 18 |
+
|
| 19 |
+
def _log(self, level, msg, args):
|
| 20 |
+
if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
|
| 21 |
+
raise ValueError('%s wrong log level' % str(level))
|
| 22 |
+
|
| 23 |
+
if level >= self.threshold:
|
| 24 |
+
if args:
|
| 25 |
+
msg = msg % args
|
| 26 |
+
if level in (WARN, ERROR, FATAL):
|
| 27 |
+
stream = sys.stderr
|
| 28 |
+
else:
|
| 29 |
+
stream = sys.stdout
|
| 30 |
+
try:
|
| 31 |
+
stream.write('%s\n' % msg)
|
| 32 |
+
except UnicodeEncodeError:
|
| 33 |
+
# emulate backslashreplace error handler
|
| 34 |
+
encoding = stream.encoding
|
| 35 |
+
msg = msg.encode(encoding, "backslashreplace").decode(encoding)
|
| 36 |
+
stream.write('%s\n' % msg)
|
| 37 |
+
stream.flush()
|
| 38 |
+
|
| 39 |
+
def log(self, level, msg, *args):
|
| 40 |
+
self._log(level, msg, args)
|
| 41 |
+
|
| 42 |
+
def debug(self, msg, *args):
|
| 43 |
+
self._log(DEBUG, msg, args)
|
| 44 |
+
|
| 45 |
+
def info(self, msg, *args):
|
| 46 |
+
self._log(INFO, msg, args)
|
| 47 |
+
|
| 48 |
+
def warn(self, msg, *args):
|
| 49 |
+
self._log(WARN, msg, args)
|
| 50 |
+
|
| 51 |
+
def error(self, msg, *args):
|
| 52 |
+
self._log(ERROR, msg, args)
|
| 53 |
+
|
| 54 |
+
def fatal(self, msg, *args):
|
| 55 |
+
self._log(FATAL, msg, args)
|
| 56 |
+
|
| 57 |
+
_global_log = Log()
|
| 58 |
+
log = _global_log.log
|
| 59 |
+
debug = _global_log.debug
|
| 60 |
+
info = _global_log.info
|
| 61 |
+
warn = _global_log.warn
|
| 62 |
+
error = _global_log.error
|
| 63 |
+
fatal = _global_log.fatal
|
| 64 |
+
|
| 65 |
+
def set_threshold(level):
|
| 66 |
+
# return the old threshold for use from tests
|
| 67 |
+
old = _global_log.threshold
|
| 68 |
+
_global_log.threshold = level
|
| 69 |
+
return old
|
| 70 |
+
|
| 71 |
+
def set_verbosity(v):
|
| 72 |
+
if v <= 0:
|
| 73 |
+
set_threshold(WARN)
|
| 74 |
+
elif v == 1:
|
| 75 |
+
set_threshold(INFO)
|
| 76 |
+
elif v >= 2:
|
| 77 |
+
set_threshold(DEBUG)
|
data/conda_envs/evalclaw/lib/python3.11/distutils/msvc9compiler.py
ADDED
|
@@ -0,0 +1,788 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.msvc9compiler
|
| 2 |
+
|
| 3 |
+
Contains MSVCCompiler, an implementation of the abstract CCompiler class
|
| 4 |
+
for the Microsoft Visual Studio 2008.
|
| 5 |
+
|
| 6 |
+
The module is compatible with VS 2005 and VS 2008. You can find legacy support
|
| 7 |
+
for older versions of VS in distutils.msvccompiler.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
# Written by Perry Stoll
|
| 11 |
+
# hacked by Robin Becker and Thomas Heller to do a better job of
|
| 12 |
+
# finding DevStudio (through the registry)
|
| 13 |
+
# ported to VS2005 and VS 2008 by Christian Heimes
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
import re
|
| 19 |
+
|
| 20 |
+
from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
|
| 21 |
+
CompileError, LibError, LinkError
|
| 22 |
+
from distutils.ccompiler import CCompiler, gen_lib_options
|
| 23 |
+
from distutils import log
|
| 24 |
+
from distutils.util import get_platform
|
| 25 |
+
|
| 26 |
+
import winreg
|
| 27 |
+
|
| 28 |
+
RegOpenKeyEx = winreg.OpenKeyEx
|
| 29 |
+
RegEnumKey = winreg.EnumKey
|
| 30 |
+
RegEnumValue = winreg.EnumValue
|
| 31 |
+
RegError = winreg.error
|
| 32 |
+
|
| 33 |
+
HKEYS = (winreg.HKEY_USERS,
|
| 34 |
+
winreg.HKEY_CURRENT_USER,
|
| 35 |
+
winreg.HKEY_LOCAL_MACHINE,
|
| 36 |
+
winreg.HKEY_CLASSES_ROOT)
|
| 37 |
+
|
| 38 |
+
NATIVE_WIN64 = (sys.platform == 'win32' and sys.maxsize > 2**32)
|
| 39 |
+
if NATIVE_WIN64:
|
| 40 |
+
# Visual C++ is a 32-bit application, so we need to look in
|
| 41 |
+
# the corresponding registry branch, if we're running a
|
| 42 |
+
# 64-bit Python on Win64
|
| 43 |
+
VS_BASE = r"Software\Wow6432Node\Microsoft\VisualStudio\%0.1f"
|
| 44 |
+
WINSDK_BASE = r"Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows"
|
| 45 |
+
NET_BASE = r"Software\Wow6432Node\Microsoft\.NETFramework"
|
| 46 |
+
else:
|
| 47 |
+
VS_BASE = r"Software\Microsoft\VisualStudio\%0.1f"
|
| 48 |
+
WINSDK_BASE = r"Software\Microsoft\Microsoft SDKs\Windows"
|
| 49 |
+
NET_BASE = r"Software\Microsoft\.NETFramework"
|
| 50 |
+
|
| 51 |
+
# A map keyed by get_platform() return values to values accepted by
|
| 52 |
+
# 'vcvarsall.bat'. Note a cross-compile may combine these (eg, 'x86_amd64' is
|
| 53 |
+
# the param to cross-compile on x86 targeting amd64.)
|
| 54 |
+
PLAT_TO_VCVARS = {
|
| 55 |
+
'win32' : 'x86',
|
| 56 |
+
'win-amd64' : 'amd64',
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
class Reg:
|
| 60 |
+
"""Helper class to read values from the registry
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
def get_value(cls, path, key):
|
| 64 |
+
for base in HKEYS:
|
| 65 |
+
d = cls.read_values(base, path)
|
| 66 |
+
if d and key in d:
|
| 67 |
+
return d[key]
|
| 68 |
+
raise KeyError(key)
|
| 69 |
+
get_value = classmethod(get_value)
|
| 70 |
+
|
| 71 |
+
def read_keys(cls, base, key):
|
| 72 |
+
"""Return list of registry keys."""
|
| 73 |
+
try:
|
| 74 |
+
handle = RegOpenKeyEx(base, key)
|
| 75 |
+
except RegError:
|
| 76 |
+
return None
|
| 77 |
+
L = []
|
| 78 |
+
i = 0
|
| 79 |
+
while True:
|
| 80 |
+
try:
|
| 81 |
+
k = RegEnumKey(handle, i)
|
| 82 |
+
except RegError:
|
| 83 |
+
break
|
| 84 |
+
L.append(k)
|
| 85 |
+
i += 1
|
| 86 |
+
return L
|
| 87 |
+
read_keys = classmethod(read_keys)
|
| 88 |
+
|
| 89 |
+
def read_values(cls, base, key):
|
| 90 |
+
"""Return dict of registry keys and values.
|
| 91 |
+
|
| 92 |
+
All names are converted to lowercase.
|
| 93 |
+
"""
|
| 94 |
+
try:
|
| 95 |
+
handle = RegOpenKeyEx(base, key)
|
| 96 |
+
except RegError:
|
| 97 |
+
return None
|
| 98 |
+
d = {}
|
| 99 |
+
i = 0
|
| 100 |
+
while True:
|
| 101 |
+
try:
|
| 102 |
+
name, value, type = RegEnumValue(handle, i)
|
| 103 |
+
except RegError:
|
| 104 |
+
break
|
| 105 |
+
name = name.lower()
|
| 106 |
+
d[cls.convert_mbcs(name)] = cls.convert_mbcs(value)
|
| 107 |
+
i += 1
|
| 108 |
+
return d
|
| 109 |
+
read_values = classmethod(read_values)
|
| 110 |
+
|
| 111 |
+
def convert_mbcs(s):
|
| 112 |
+
dec = getattr(s, "decode", None)
|
| 113 |
+
if dec is not None:
|
| 114 |
+
try:
|
| 115 |
+
s = dec("mbcs")
|
| 116 |
+
except UnicodeError:
|
| 117 |
+
pass
|
| 118 |
+
return s
|
| 119 |
+
convert_mbcs = staticmethod(convert_mbcs)
|
| 120 |
+
|
| 121 |
+
class MacroExpander:
|
| 122 |
+
|
| 123 |
+
def __init__(self, version):
|
| 124 |
+
self.macros = {}
|
| 125 |
+
self.vsbase = VS_BASE % version
|
| 126 |
+
self.load_macros(version)
|
| 127 |
+
|
| 128 |
+
def set_macro(self, macro, path, key):
|
| 129 |
+
self.macros["$(%s)" % macro] = Reg.get_value(path, key)
|
| 130 |
+
|
| 131 |
+
def load_macros(self, version):
|
| 132 |
+
self.set_macro("VCInstallDir", self.vsbase + r"\Setup\VC", "productdir")
|
| 133 |
+
self.set_macro("VSInstallDir", self.vsbase + r"\Setup\VS", "productdir")
|
| 134 |
+
self.set_macro("FrameworkDir", NET_BASE, "installroot")
|
| 135 |
+
try:
|
| 136 |
+
if version >= 8.0:
|
| 137 |
+
self.set_macro("FrameworkSDKDir", NET_BASE,
|
| 138 |
+
"sdkinstallrootv2.0")
|
| 139 |
+
else:
|
| 140 |
+
raise KeyError("sdkinstallrootv2.0")
|
| 141 |
+
except KeyError:
|
| 142 |
+
raise DistutilsPlatformError(
|
| 143 |
+
"""Python was built with Visual Studio 2008;
|
| 144 |
+
extensions must be built with a compiler than can generate compatible binaries.
|
| 145 |
+
Visual Studio 2008 was not found on this system. If you have Cygwin installed,
|
| 146 |
+
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")
|
| 147 |
+
|
| 148 |
+
if version >= 9.0:
|
| 149 |
+
self.set_macro("FrameworkVersion", self.vsbase, "clr version")
|
| 150 |
+
self.set_macro("WindowsSdkDir", WINSDK_BASE, "currentinstallfolder")
|
| 151 |
+
else:
|
| 152 |
+
p = r"Software\Microsoft\NET Framework Setup\Product"
|
| 153 |
+
for base in HKEYS:
|
| 154 |
+
try:
|
| 155 |
+
h = RegOpenKeyEx(base, p)
|
| 156 |
+
except RegError:
|
| 157 |
+
continue
|
| 158 |
+
key = RegEnumKey(h, 0)
|
| 159 |
+
d = Reg.get_value(base, r"%s\%s" % (p, key))
|
| 160 |
+
self.macros["$(FrameworkVersion)"] = d["version"]
|
| 161 |
+
|
| 162 |
+
def sub(self, s):
|
| 163 |
+
for k, v in self.macros.items():
|
| 164 |
+
s = s.replace(k, v)
|
| 165 |
+
return s
|
| 166 |
+
|
| 167 |
+
def get_build_version():
|
| 168 |
+
"""Return the version of MSVC that was used to build Python.
|
| 169 |
+
|
| 170 |
+
For Python 2.3 and up, the version number is included in
|
| 171 |
+
sys.version. For earlier versions, assume the compiler is MSVC 6.
|
| 172 |
+
"""
|
| 173 |
+
prefix = "MSC v."
|
| 174 |
+
i = sys.version.find(prefix)
|
| 175 |
+
if i == -1:
|
| 176 |
+
return 6
|
| 177 |
+
i = i + len(prefix)
|
| 178 |
+
s, rest = sys.version[i:].split(" ", 1)
|
| 179 |
+
majorVersion = int(s[:-2]) - 6
|
| 180 |
+
if majorVersion >= 13:
|
| 181 |
+
# v13 was skipped and should be v14
|
| 182 |
+
majorVersion += 1
|
| 183 |
+
minorVersion = int(s[2:3]) / 10.0
|
| 184 |
+
# I don't think paths are affected by minor version in version 6
|
| 185 |
+
if majorVersion == 6:
|
| 186 |
+
minorVersion = 0
|
| 187 |
+
if majorVersion >= 6:
|
| 188 |
+
return majorVersion + minorVersion
|
| 189 |
+
# else we don't know what version of the compiler this is
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
def normalize_and_reduce_paths(paths):
|
| 193 |
+
"""Return a list of normalized paths with duplicates removed.
|
| 194 |
+
|
| 195 |
+
The current order of paths is maintained.
|
| 196 |
+
"""
|
| 197 |
+
# Paths are normalized so things like: /a and /a/ aren't both preserved.
|
| 198 |
+
reduced_paths = []
|
| 199 |
+
for p in paths:
|
| 200 |
+
np = os.path.normpath(p)
|
| 201 |
+
# XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set.
|
| 202 |
+
if np not in reduced_paths:
|
| 203 |
+
reduced_paths.append(np)
|
| 204 |
+
return reduced_paths
|
| 205 |
+
|
| 206 |
+
def removeDuplicates(variable):
|
| 207 |
+
"""Remove duplicate values of an environment variable.
|
| 208 |
+
"""
|
| 209 |
+
oldList = variable.split(os.pathsep)
|
| 210 |
+
newList = []
|
| 211 |
+
for i in oldList:
|
| 212 |
+
if i not in newList:
|
| 213 |
+
newList.append(i)
|
| 214 |
+
newVariable = os.pathsep.join(newList)
|
| 215 |
+
return newVariable
|
| 216 |
+
|
| 217 |
+
def find_vcvarsall(version):
|
| 218 |
+
"""Find the vcvarsall.bat file
|
| 219 |
+
|
| 220 |
+
At first it tries to find the productdir of VS 2008 in the registry. If
|
| 221 |
+
that fails it falls back to the VS90COMNTOOLS env var.
|
| 222 |
+
"""
|
| 223 |
+
vsbase = VS_BASE % version
|
| 224 |
+
try:
|
| 225 |
+
productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
|
| 226 |
+
"productdir")
|
| 227 |
+
except KeyError:
|
| 228 |
+
log.debug("Unable to find productdir in registry")
|
| 229 |
+
productdir = None
|
| 230 |
+
|
| 231 |
+
if not productdir or not os.path.isdir(productdir):
|
| 232 |
+
toolskey = "VS%0.f0COMNTOOLS" % version
|
| 233 |
+
toolsdir = os.environ.get(toolskey, None)
|
| 234 |
+
|
| 235 |
+
if toolsdir and os.path.isdir(toolsdir):
|
| 236 |
+
productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
|
| 237 |
+
productdir = os.path.abspath(productdir)
|
| 238 |
+
if not os.path.isdir(productdir):
|
| 239 |
+
log.debug("%s is not a valid directory" % productdir)
|
| 240 |
+
return None
|
| 241 |
+
else:
|
| 242 |
+
log.debug("Env var %s is not set or invalid" % toolskey)
|
| 243 |
+
if not productdir:
|
| 244 |
+
log.debug("No productdir found")
|
| 245 |
+
return None
|
| 246 |
+
vcvarsall = os.path.join(productdir, "vcvarsall.bat")
|
| 247 |
+
if os.path.isfile(vcvarsall):
|
| 248 |
+
return vcvarsall
|
| 249 |
+
log.debug("Unable to find vcvarsall.bat")
|
| 250 |
+
return None
|
| 251 |
+
|
| 252 |
+
def query_vcvarsall(version, arch="x86"):
|
| 253 |
+
"""Launch vcvarsall.bat and read the settings from its environment
|
| 254 |
+
"""
|
| 255 |
+
vcvarsall = find_vcvarsall(version)
|
| 256 |
+
interesting = {"include", "lib", "libpath", "path"}
|
| 257 |
+
result = {}
|
| 258 |
+
|
| 259 |
+
if vcvarsall is None:
|
| 260 |
+
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
|
| 261 |
+
log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version)
|
| 262 |
+
popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
|
| 263 |
+
stdout=subprocess.PIPE,
|
| 264 |
+
stderr=subprocess.PIPE)
|
| 265 |
+
try:
|
| 266 |
+
stdout, stderr = popen.communicate()
|
| 267 |
+
if popen.wait() != 0:
|
| 268 |
+
raise DistutilsPlatformError(stderr.decode("mbcs"))
|
| 269 |
+
|
| 270 |
+
stdout = stdout.decode("mbcs")
|
| 271 |
+
for line in stdout.split("\n"):
|
| 272 |
+
line = Reg.convert_mbcs(line)
|
| 273 |
+
if '=' not in line:
|
| 274 |
+
continue
|
| 275 |
+
line = line.strip()
|
| 276 |
+
key, value = line.split('=', 1)
|
| 277 |
+
key = key.lower()
|
| 278 |
+
if key in interesting:
|
| 279 |
+
if value.endswith(os.pathsep):
|
| 280 |
+
value = value[:-1]
|
| 281 |
+
result[key] = removeDuplicates(value)
|
| 282 |
+
|
| 283 |
+
finally:
|
| 284 |
+
popen.stdout.close()
|
| 285 |
+
popen.stderr.close()
|
| 286 |
+
|
| 287 |
+
if len(result) != len(interesting):
|
| 288 |
+
raise ValueError(str(list(result.keys())))
|
| 289 |
+
|
| 290 |
+
return result
|
| 291 |
+
|
| 292 |
+
# More globals
|
| 293 |
+
VERSION = get_build_version()
|
| 294 |
+
if VERSION < 8.0:
|
| 295 |
+
raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION)
|
| 296 |
+
# MACROS = MacroExpander(VERSION)
|
| 297 |
+
|
| 298 |
+
class MSVCCompiler(CCompiler) :
|
| 299 |
+
"""Concrete class that implements an interface to Microsoft Visual C++,
|
| 300 |
+
as defined by the CCompiler abstract class."""
|
| 301 |
+
|
| 302 |
+
compiler_type = 'msvc'
|
| 303 |
+
|
| 304 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
| 305 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
| 306 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
| 307 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
| 308 |
+
# though, so it's worth thinking about.
|
| 309 |
+
executables = {}
|
| 310 |
+
|
| 311 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
| 312 |
+
_c_extensions = ['.c']
|
| 313 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
| 314 |
+
_rc_extensions = ['.rc']
|
| 315 |
+
_mc_extensions = ['.mc']
|
| 316 |
+
|
| 317 |
+
# Needed for the filename generation methods provided by the
|
| 318 |
+
# base class, CCompiler.
|
| 319 |
+
src_extensions = (_c_extensions + _cpp_extensions +
|
| 320 |
+
_rc_extensions + _mc_extensions)
|
| 321 |
+
res_extension = '.res'
|
| 322 |
+
obj_extension = '.obj'
|
| 323 |
+
static_lib_extension = '.lib'
|
| 324 |
+
shared_lib_extension = '.dll'
|
| 325 |
+
static_lib_format = shared_lib_format = '%s%s'
|
| 326 |
+
exe_extension = '.exe'
|
| 327 |
+
|
| 328 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
| 329 |
+
CCompiler.__init__ (self, verbose, dry_run, force)
|
| 330 |
+
self.__version = VERSION
|
| 331 |
+
self.__root = r"Software\Microsoft\VisualStudio"
|
| 332 |
+
# self.__macros = MACROS
|
| 333 |
+
self.__paths = []
|
| 334 |
+
# target platform (.plat_name is consistent with 'bdist')
|
| 335 |
+
self.plat_name = None
|
| 336 |
+
self.__arch = None # deprecated name
|
| 337 |
+
self.initialized = False
|
| 338 |
+
|
| 339 |
+
def initialize(self, plat_name=None):
|
| 340 |
+
# multi-init means we would need to check platform same each time...
|
| 341 |
+
assert not self.initialized, "don't init multiple times"
|
| 342 |
+
if plat_name is None:
|
| 343 |
+
plat_name = get_platform()
|
| 344 |
+
# sanity check for platforms to prevent obscure errors later.
|
| 345 |
+
ok_plats = 'win32', 'win-amd64'
|
| 346 |
+
if plat_name not in ok_plats:
|
| 347 |
+
raise DistutilsPlatformError("--plat-name must be one of %s" %
|
| 348 |
+
(ok_plats,))
|
| 349 |
+
|
| 350 |
+
if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"):
|
| 351 |
+
# Assume that the SDK set up everything alright; don't try to be
|
| 352 |
+
# smarter
|
| 353 |
+
self.cc = "cl.exe"
|
| 354 |
+
self.linker = "link.exe"
|
| 355 |
+
self.lib = "lib.exe"
|
| 356 |
+
self.rc = "rc.exe"
|
| 357 |
+
self.mc = "mc.exe"
|
| 358 |
+
else:
|
| 359 |
+
# On x86, 'vcvars32.bat amd64' creates an env that doesn't work;
|
| 360 |
+
# to cross compile, you use 'x86_amd64'.
|
| 361 |
+
# On AMD64, 'vcvars32.bat amd64' is a native build env; to cross
|
| 362 |
+
# compile use 'x86' (ie, it runs the x86 compiler directly)
|
| 363 |
+
if plat_name == get_platform() or plat_name == 'win32':
|
| 364 |
+
# native build or cross-compile to win32
|
| 365 |
+
plat_spec = PLAT_TO_VCVARS[plat_name]
|
| 366 |
+
else:
|
| 367 |
+
# cross compile from win32 -> some 64bit
|
| 368 |
+
plat_spec = PLAT_TO_VCVARS[get_platform()] + '_' + \
|
| 369 |
+
PLAT_TO_VCVARS[plat_name]
|
| 370 |
+
|
| 371 |
+
vc_env = query_vcvarsall(VERSION, plat_spec)
|
| 372 |
+
|
| 373 |
+
self.__paths = vc_env['path'].split(os.pathsep)
|
| 374 |
+
os.environ['lib'] = vc_env['lib']
|
| 375 |
+
os.environ['include'] = vc_env['include']
|
| 376 |
+
|
| 377 |
+
if len(self.__paths) == 0:
|
| 378 |
+
raise DistutilsPlatformError("Python was built with %s, "
|
| 379 |
+
"and extensions need to be built with the same "
|
| 380 |
+
"version of the compiler, but it isn't installed."
|
| 381 |
+
% self.__product)
|
| 382 |
+
|
| 383 |
+
self.cc = self.find_exe("cl.exe")
|
| 384 |
+
self.linker = self.find_exe("link.exe")
|
| 385 |
+
self.lib = self.find_exe("lib.exe")
|
| 386 |
+
self.rc = self.find_exe("rc.exe") # resource compiler
|
| 387 |
+
self.mc = self.find_exe("mc.exe") # message compiler
|
| 388 |
+
#self.set_path_env_var('lib')
|
| 389 |
+
#self.set_path_env_var('include')
|
| 390 |
+
|
| 391 |
+
# extend the MSVC path with the current path
|
| 392 |
+
try:
|
| 393 |
+
for p in os.environ['path'].split(';'):
|
| 394 |
+
self.__paths.append(p)
|
| 395 |
+
except KeyError:
|
| 396 |
+
pass
|
| 397 |
+
self.__paths = normalize_and_reduce_paths(self.__paths)
|
| 398 |
+
os.environ['path'] = ";".join(self.__paths)
|
| 399 |
+
|
| 400 |
+
self.preprocess_options = None
|
| 401 |
+
if self.__arch == "x86":
|
| 402 |
+
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3',
|
| 403 |
+
'/DNDEBUG']
|
| 404 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3',
|
| 405 |
+
'/Z7', '/D_DEBUG']
|
| 406 |
+
else:
|
| 407 |
+
# Win64
|
| 408 |
+
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GS-' ,
|
| 409 |
+
'/DNDEBUG']
|
| 410 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
|
| 411 |
+
'/Z7', '/D_DEBUG']
|
| 412 |
+
|
| 413 |
+
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
|
| 414 |
+
if self.__version >= 7:
|
| 415 |
+
self.ldflags_shared_debug = [
|
| 416 |
+
'/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG'
|
| 417 |
+
]
|
| 418 |
+
self.ldflags_static = [ '/nologo']
|
| 419 |
+
|
| 420 |
+
self.initialized = True
|
| 421 |
+
|
| 422 |
+
# -- Worker methods ------------------------------------------------
|
| 423 |
+
|
| 424 |
+
def object_filenames(self,
|
| 425 |
+
source_filenames,
|
| 426 |
+
strip_dir=0,
|
| 427 |
+
output_dir=''):
|
| 428 |
+
# Copied from ccompiler.py, extended to return .res as 'object'-file
|
| 429 |
+
# for .rc input file
|
| 430 |
+
if output_dir is None: output_dir = ''
|
| 431 |
+
obj_names = []
|
| 432 |
+
for src_name in source_filenames:
|
| 433 |
+
(base, ext) = os.path.splitext (src_name)
|
| 434 |
+
base = os.path.splitdrive(base)[1] # Chop off the drive
|
| 435 |
+
base = base[os.path.isabs(base):] # If abs, chop off leading /
|
| 436 |
+
if ext not in self.src_extensions:
|
| 437 |
+
# Better to raise an exception instead of silently continuing
|
| 438 |
+
# and later complain about sources and targets having
|
| 439 |
+
# different lengths
|
| 440 |
+
raise CompileError ("Don't know how to compile %s" % src_name)
|
| 441 |
+
if strip_dir:
|
| 442 |
+
base = os.path.basename (base)
|
| 443 |
+
if ext in self._rc_extensions:
|
| 444 |
+
obj_names.append (os.path.join (output_dir,
|
| 445 |
+
base + self.res_extension))
|
| 446 |
+
elif ext in self._mc_extensions:
|
| 447 |
+
obj_names.append (os.path.join (output_dir,
|
| 448 |
+
base + self.res_extension))
|
| 449 |
+
else:
|
| 450 |
+
obj_names.append (os.path.join (output_dir,
|
| 451 |
+
base + self.obj_extension))
|
| 452 |
+
return obj_names
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
def compile(self, sources,
|
| 456 |
+
output_dir=None, macros=None, include_dirs=None, debug=0,
|
| 457 |
+
extra_preargs=None, extra_postargs=None, depends=None):
|
| 458 |
+
|
| 459 |
+
if not self.initialized:
|
| 460 |
+
self.initialize()
|
| 461 |
+
compile_info = self._setup_compile(output_dir, macros, include_dirs,
|
| 462 |
+
sources, depends, extra_postargs)
|
| 463 |
+
macros, objects, extra_postargs, pp_opts, build = compile_info
|
| 464 |
+
|
| 465 |
+
compile_opts = extra_preargs or []
|
| 466 |
+
compile_opts.append ('/c')
|
| 467 |
+
if debug:
|
| 468 |
+
compile_opts.extend(self.compile_options_debug)
|
| 469 |
+
else:
|
| 470 |
+
compile_opts.extend(self.compile_options)
|
| 471 |
+
|
| 472 |
+
for obj in objects:
|
| 473 |
+
try:
|
| 474 |
+
src, ext = build[obj]
|
| 475 |
+
except KeyError:
|
| 476 |
+
continue
|
| 477 |
+
if debug:
|
| 478 |
+
# pass the full pathname to MSVC in debug mode,
|
| 479 |
+
# this allows the debugger to find the source file
|
| 480 |
+
# without asking the user to browse for it
|
| 481 |
+
src = os.path.abspath(src)
|
| 482 |
+
|
| 483 |
+
if ext in self._c_extensions:
|
| 484 |
+
input_opt = "/Tc" + src
|
| 485 |
+
elif ext in self._cpp_extensions:
|
| 486 |
+
input_opt = "/Tp" + src
|
| 487 |
+
elif ext in self._rc_extensions:
|
| 488 |
+
# compile .RC to .RES file
|
| 489 |
+
input_opt = src
|
| 490 |
+
output_opt = "/fo" + obj
|
| 491 |
+
try:
|
| 492 |
+
self.spawn([self.rc] + pp_opts +
|
| 493 |
+
[output_opt] + [input_opt])
|
| 494 |
+
except DistutilsExecError as msg:
|
| 495 |
+
raise CompileError(msg)
|
| 496 |
+
continue
|
| 497 |
+
elif ext in self._mc_extensions:
|
| 498 |
+
# Compile .MC to .RC file to .RES file.
|
| 499 |
+
# * '-h dir' specifies the directory for the
|
| 500 |
+
# generated include file
|
| 501 |
+
# * '-r dir' specifies the target directory of the
|
| 502 |
+
# generated RC file and the binary message resource
|
| 503 |
+
# it includes
|
| 504 |
+
#
|
| 505 |
+
# For now (since there are no options to change this),
|
| 506 |
+
# we use the source-directory for the include file and
|
| 507 |
+
# the build directory for the RC file and message
|
| 508 |
+
# resources. This works at least for win32all.
|
| 509 |
+
h_dir = os.path.dirname(src)
|
| 510 |
+
rc_dir = os.path.dirname(obj)
|
| 511 |
+
try:
|
| 512 |
+
# first compile .MC to .RC and .H file
|
| 513 |
+
self.spawn([self.mc] +
|
| 514 |
+
['-h', h_dir, '-r', rc_dir] + [src])
|
| 515 |
+
base, _ = os.path.splitext (os.path.basename (src))
|
| 516 |
+
rc_file = os.path.join (rc_dir, base + '.rc')
|
| 517 |
+
# then compile .RC to .RES file
|
| 518 |
+
self.spawn([self.rc] +
|
| 519 |
+
["/fo" + obj] + [rc_file])
|
| 520 |
+
|
| 521 |
+
except DistutilsExecError as msg:
|
| 522 |
+
raise CompileError(msg)
|
| 523 |
+
continue
|
| 524 |
+
else:
|
| 525 |
+
# how to handle this file?
|
| 526 |
+
raise CompileError("Don't know how to compile %s to %s"
|
| 527 |
+
% (src, obj))
|
| 528 |
+
|
| 529 |
+
output_opt = "/Fo" + obj
|
| 530 |
+
try:
|
| 531 |
+
self.spawn([self.cc] + compile_opts + pp_opts +
|
| 532 |
+
[input_opt, output_opt] +
|
| 533 |
+
extra_postargs)
|
| 534 |
+
except DistutilsExecError as msg:
|
| 535 |
+
raise CompileError(msg)
|
| 536 |
+
|
| 537 |
+
return objects
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
def create_static_lib(self,
|
| 541 |
+
objects,
|
| 542 |
+
output_libname,
|
| 543 |
+
output_dir=None,
|
| 544 |
+
debug=0,
|
| 545 |
+
target_lang=None):
|
| 546 |
+
|
| 547 |
+
if not self.initialized:
|
| 548 |
+
self.initialize()
|
| 549 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
| 550 |
+
output_filename = self.library_filename(output_libname,
|
| 551 |
+
output_dir=output_dir)
|
| 552 |
+
|
| 553 |
+
if self._need_link(objects, output_filename):
|
| 554 |
+
lib_args = objects + ['/OUT:' + output_filename]
|
| 555 |
+
if debug:
|
| 556 |
+
pass # XXX what goes here?
|
| 557 |
+
try:
|
| 558 |
+
self.spawn([self.lib] + lib_args)
|
| 559 |
+
except DistutilsExecError as msg:
|
| 560 |
+
raise LibError(msg)
|
| 561 |
+
else:
|
| 562 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
def link(self,
|
| 566 |
+
target_desc,
|
| 567 |
+
objects,
|
| 568 |
+
output_filename,
|
| 569 |
+
output_dir=None,
|
| 570 |
+
libraries=None,
|
| 571 |
+
library_dirs=None,
|
| 572 |
+
runtime_library_dirs=None,
|
| 573 |
+
export_symbols=None,
|
| 574 |
+
debug=0,
|
| 575 |
+
extra_preargs=None,
|
| 576 |
+
extra_postargs=None,
|
| 577 |
+
build_temp=None,
|
| 578 |
+
target_lang=None):
|
| 579 |
+
|
| 580 |
+
if not self.initialized:
|
| 581 |
+
self.initialize()
|
| 582 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
| 583 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs,
|
| 584 |
+
runtime_library_dirs)
|
| 585 |
+
(libraries, library_dirs, runtime_library_dirs) = fixed_args
|
| 586 |
+
|
| 587 |
+
if runtime_library_dirs:
|
| 588 |
+
self.warn ("I don't know what to do with 'runtime_library_dirs': "
|
| 589 |
+
+ str (runtime_library_dirs))
|
| 590 |
+
|
| 591 |
+
lib_opts = gen_lib_options(self,
|
| 592 |
+
library_dirs, runtime_library_dirs,
|
| 593 |
+
libraries)
|
| 594 |
+
if output_dir is not None:
|
| 595 |
+
output_filename = os.path.join(output_dir, output_filename)
|
| 596 |
+
|
| 597 |
+
if self._need_link(objects, output_filename):
|
| 598 |
+
if target_desc == CCompiler.EXECUTABLE:
|
| 599 |
+
if debug:
|
| 600 |
+
ldflags = self.ldflags_shared_debug[1:]
|
| 601 |
+
else:
|
| 602 |
+
ldflags = self.ldflags_shared[1:]
|
| 603 |
+
else:
|
| 604 |
+
if debug:
|
| 605 |
+
ldflags = self.ldflags_shared_debug
|
| 606 |
+
else:
|
| 607 |
+
ldflags = self.ldflags_shared
|
| 608 |
+
|
| 609 |
+
export_opts = []
|
| 610 |
+
for sym in (export_symbols or []):
|
| 611 |
+
export_opts.append("/EXPORT:" + sym)
|
| 612 |
+
|
| 613 |
+
ld_args = (ldflags + lib_opts + export_opts +
|
| 614 |
+
objects + ['/OUT:' + output_filename])
|
| 615 |
+
|
| 616 |
+
# The MSVC linker generates .lib and .exp files, which cannot be
|
| 617 |
+
# suppressed by any linker switches. The .lib files may even be
|
| 618 |
+
# needed! Make sure they are generated in the temporary build
|
| 619 |
+
# directory. Since they have different names for debug and release
|
| 620 |
+
# builds, they can go into the same directory.
|
| 621 |
+
build_temp = os.path.dirname(objects[0])
|
| 622 |
+
if export_symbols is not None:
|
| 623 |
+
(dll_name, dll_ext) = os.path.splitext(
|
| 624 |
+
os.path.basename(output_filename))
|
| 625 |
+
implib_file = os.path.join(
|
| 626 |
+
build_temp,
|
| 627 |
+
self.library_filename(dll_name))
|
| 628 |
+
ld_args.append ('/IMPLIB:' + implib_file)
|
| 629 |
+
|
| 630 |
+
self.manifest_setup_ldargs(output_filename, build_temp, ld_args)
|
| 631 |
+
|
| 632 |
+
if extra_preargs:
|
| 633 |
+
ld_args[:0] = extra_preargs
|
| 634 |
+
if extra_postargs:
|
| 635 |
+
ld_args.extend(extra_postargs)
|
| 636 |
+
|
| 637 |
+
self.mkpath(os.path.dirname(output_filename))
|
| 638 |
+
try:
|
| 639 |
+
self.spawn([self.linker] + ld_args)
|
| 640 |
+
except DistutilsExecError as msg:
|
| 641 |
+
raise LinkError(msg)
|
| 642 |
+
|
| 643 |
+
# embed the manifest
|
| 644 |
+
# XXX - this is somewhat fragile - if mt.exe fails, distutils
|
| 645 |
+
# will still consider the DLL up-to-date, but it will not have a
|
| 646 |
+
# manifest. Maybe we should link to a temp file? OTOH, that
|
| 647 |
+
# implies a build environment error that shouldn't go undetected.
|
| 648 |
+
mfinfo = self.manifest_get_embed_info(target_desc, ld_args)
|
| 649 |
+
if mfinfo is not None:
|
| 650 |
+
mffilename, mfid = mfinfo
|
| 651 |
+
out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
|
| 652 |
+
try:
|
| 653 |
+
self.spawn(['mt.exe', '-nologo', '-manifest',
|
| 654 |
+
mffilename, out_arg])
|
| 655 |
+
except DistutilsExecError as msg:
|
| 656 |
+
raise LinkError(msg)
|
| 657 |
+
else:
|
| 658 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 659 |
+
|
| 660 |
+
def manifest_setup_ldargs(self, output_filename, build_temp, ld_args):
|
| 661 |
+
# If we need a manifest at all, an embedded manifest is recommended.
|
| 662 |
+
# See MSDN article titled
|
| 663 |
+
# "How to: Embed a Manifest Inside a C/C++ Application"
|
| 664 |
+
# (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
|
| 665 |
+
# Ask the linker to generate the manifest in the temp dir, so
|
| 666 |
+
# we can check it, and possibly embed it, later.
|
| 667 |
+
temp_manifest = os.path.join(
|
| 668 |
+
build_temp,
|
| 669 |
+
os.path.basename(output_filename) + ".manifest")
|
| 670 |
+
ld_args.append('/MANIFESTFILE:' + temp_manifest)
|
| 671 |
+
|
| 672 |
+
def manifest_get_embed_info(self, target_desc, ld_args):
|
| 673 |
+
# If a manifest should be embedded, return a tuple of
|
| 674 |
+
# (manifest_filename, resource_id). Returns None if no manifest
|
| 675 |
+
# should be embedded. See http://bugs.python.org/issue7833 for why
|
| 676 |
+
# we want to avoid any manifest for extension modules if we can.
|
| 677 |
+
for arg in ld_args:
|
| 678 |
+
if arg.startswith("/MANIFESTFILE:"):
|
| 679 |
+
temp_manifest = arg.split(":", 1)[1]
|
| 680 |
+
break
|
| 681 |
+
else:
|
| 682 |
+
# no /MANIFESTFILE so nothing to do.
|
| 683 |
+
return None
|
| 684 |
+
if target_desc == CCompiler.EXECUTABLE:
|
| 685 |
+
# by default, executables always get the manifest with the
|
| 686 |
+
# CRT referenced.
|
| 687 |
+
mfid = 1
|
| 688 |
+
else:
|
| 689 |
+
# Extension modules try and avoid any manifest if possible.
|
| 690 |
+
mfid = 2
|
| 691 |
+
temp_manifest = self._remove_visual_c_ref(temp_manifest)
|
| 692 |
+
if temp_manifest is None:
|
| 693 |
+
return None
|
| 694 |
+
return temp_manifest, mfid
|
| 695 |
+
|
| 696 |
+
def _remove_visual_c_ref(self, manifest_file):
|
| 697 |
+
try:
|
| 698 |
+
# Remove references to the Visual C runtime, so they will
|
| 699 |
+
# fall through to the Visual C dependency of Python.exe.
|
| 700 |
+
# This way, when installed for a restricted user (e.g.
|
| 701 |
+
# runtimes are not in WinSxS folder, but in Python's own
|
| 702 |
+
# folder), the runtimes do not need to be in every folder
|
| 703 |
+
# with .pyd's.
|
| 704 |
+
# Returns either the filename of the modified manifest or
|
| 705 |
+
# None if no manifest should be embedded.
|
| 706 |
+
manifest_f = open(manifest_file)
|
| 707 |
+
try:
|
| 708 |
+
manifest_buf = manifest_f.read()
|
| 709 |
+
finally:
|
| 710 |
+
manifest_f.close()
|
| 711 |
+
pattern = re.compile(
|
| 712 |
+
r"""<assemblyIdentity.*?name=("|')Microsoft\."""\
|
| 713 |
+
r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
|
| 714 |
+
re.DOTALL)
|
| 715 |
+
manifest_buf = re.sub(pattern, "", manifest_buf)
|
| 716 |
+
pattern = r"<dependentAssembly>\s*</dependentAssembly>"
|
| 717 |
+
manifest_buf = re.sub(pattern, "", manifest_buf)
|
| 718 |
+
# Now see if any other assemblies are referenced - if not, we
|
| 719 |
+
# don't want a manifest embedded.
|
| 720 |
+
pattern = re.compile(
|
| 721 |
+
r"""<assemblyIdentity.*?name=(?:"|')(.+?)(?:"|')"""
|
| 722 |
+
r""".*?(?:/>|</assemblyIdentity>)""", re.DOTALL)
|
| 723 |
+
if re.search(pattern, manifest_buf) is None:
|
| 724 |
+
return None
|
| 725 |
+
|
| 726 |
+
manifest_f = open(manifest_file, 'w')
|
| 727 |
+
try:
|
| 728 |
+
manifest_f.write(manifest_buf)
|
| 729 |
+
return manifest_file
|
| 730 |
+
finally:
|
| 731 |
+
manifest_f.close()
|
| 732 |
+
except OSError:
|
| 733 |
+
pass
|
| 734 |
+
|
| 735 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 736 |
+
# These are all used by the 'gen_lib_options() function, in
|
| 737 |
+
# ccompiler.py.
|
| 738 |
+
|
| 739 |
+
def library_dir_option(self, dir):
|
| 740 |
+
return "/LIBPATH:" + dir
|
| 741 |
+
|
| 742 |
+
def runtime_library_dir_option(self, dir):
|
| 743 |
+
raise DistutilsPlatformError(
|
| 744 |
+
"don't know how to set runtime library search path for MSVC++")
|
| 745 |
+
|
| 746 |
+
def library_option(self, lib):
|
| 747 |
+
return self.library_filename(lib)
|
| 748 |
+
|
| 749 |
+
|
| 750 |
+
def find_library_file(self, dirs, lib, debug=0):
|
| 751 |
+
# Prefer a debugging library if found (and requested), but deal
|
| 752 |
+
# with it if we don't have one.
|
| 753 |
+
if debug:
|
| 754 |
+
try_names = [lib + "_d", lib]
|
| 755 |
+
else:
|
| 756 |
+
try_names = [lib]
|
| 757 |
+
for dir in dirs:
|
| 758 |
+
for name in try_names:
|
| 759 |
+
libfile = os.path.join(dir, self.library_filename (name))
|
| 760 |
+
if os.path.exists(libfile):
|
| 761 |
+
return libfile
|
| 762 |
+
else:
|
| 763 |
+
# Oops, didn't find it in *any* of 'dirs'
|
| 764 |
+
return None
|
| 765 |
+
|
| 766 |
+
# Helper methods for using the MSVC registry settings
|
| 767 |
+
|
| 768 |
+
def find_exe(self, exe):
|
| 769 |
+
"""Return path to an MSVC executable program.
|
| 770 |
+
|
| 771 |
+
Tries to find the program in several places: first, one of the
|
| 772 |
+
MSVC program search paths from the registry; next, the directories
|
| 773 |
+
in the PATH environment variable. If any of those work, return an
|
| 774 |
+
absolute path that is known to exist. If none of them work, just
|
| 775 |
+
return the original program name, 'exe'.
|
| 776 |
+
"""
|
| 777 |
+
for p in self.__paths:
|
| 778 |
+
fn = os.path.join(os.path.abspath(p), exe)
|
| 779 |
+
if os.path.isfile(fn):
|
| 780 |
+
return fn
|
| 781 |
+
|
| 782 |
+
# didn't find it; try existing path
|
| 783 |
+
for p in os.environ['Path'].split(';'):
|
| 784 |
+
fn = os.path.join(os.path.abspath(p),exe)
|
| 785 |
+
if os.path.isfile(fn):
|
| 786 |
+
return fn
|
| 787 |
+
|
| 788 |
+
return exe
|
data/conda_envs/evalclaw/lib/python3.11/distutils/msvccompiler.py
ADDED
|
@@ -0,0 +1,642 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.msvccompiler
|
| 2 |
+
|
| 3 |
+
Contains MSVCCompiler, an implementation of the abstract CCompiler class
|
| 4 |
+
for the Microsoft Visual Studio.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
# Written by Perry Stoll
|
| 8 |
+
# hacked by Robin Becker and Thomas Heller to do a better job of
|
| 9 |
+
# finding DevStudio (through the registry)
|
| 10 |
+
|
| 11 |
+
import sys, os
|
| 12 |
+
from distutils.errors import \
|
| 13 |
+
DistutilsExecError, DistutilsPlatformError, \
|
| 14 |
+
CompileError, LibError, LinkError
|
| 15 |
+
from distutils.ccompiler import \
|
| 16 |
+
CCompiler, gen_lib_options
|
| 17 |
+
from distutils import log
|
| 18 |
+
|
| 19 |
+
_can_read_reg = False
|
| 20 |
+
try:
|
| 21 |
+
import winreg
|
| 22 |
+
|
| 23 |
+
_can_read_reg = True
|
| 24 |
+
hkey_mod = winreg
|
| 25 |
+
|
| 26 |
+
RegOpenKeyEx = winreg.OpenKeyEx
|
| 27 |
+
RegEnumKey = winreg.EnumKey
|
| 28 |
+
RegEnumValue = winreg.EnumValue
|
| 29 |
+
RegError = winreg.error
|
| 30 |
+
|
| 31 |
+
except ImportError:
|
| 32 |
+
try:
|
| 33 |
+
import win32api
|
| 34 |
+
import win32con
|
| 35 |
+
_can_read_reg = True
|
| 36 |
+
hkey_mod = win32con
|
| 37 |
+
|
| 38 |
+
RegOpenKeyEx = win32api.RegOpenKeyEx
|
| 39 |
+
RegEnumKey = win32api.RegEnumKey
|
| 40 |
+
RegEnumValue = win32api.RegEnumValue
|
| 41 |
+
RegError = win32api.error
|
| 42 |
+
except ImportError:
|
| 43 |
+
log.info("Warning: Can't read registry to find the "
|
| 44 |
+
"necessary compiler setting\n"
|
| 45 |
+
"Make sure that Python modules winreg, "
|
| 46 |
+
"win32api or win32con are installed.")
|
| 47 |
+
|
| 48 |
+
if _can_read_reg:
|
| 49 |
+
HKEYS = (hkey_mod.HKEY_USERS,
|
| 50 |
+
hkey_mod.HKEY_CURRENT_USER,
|
| 51 |
+
hkey_mod.HKEY_LOCAL_MACHINE,
|
| 52 |
+
hkey_mod.HKEY_CLASSES_ROOT)
|
| 53 |
+
|
| 54 |
+
def read_keys(base, key):
|
| 55 |
+
"""Return list of registry keys."""
|
| 56 |
+
try:
|
| 57 |
+
handle = RegOpenKeyEx(base, key)
|
| 58 |
+
except RegError:
|
| 59 |
+
return None
|
| 60 |
+
L = []
|
| 61 |
+
i = 0
|
| 62 |
+
while True:
|
| 63 |
+
try:
|
| 64 |
+
k = RegEnumKey(handle, i)
|
| 65 |
+
except RegError:
|
| 66 |
+
break
|
| 67 |
+
L.append(k)
|
| 68 |
+
i += 1
|
| 69 |
+
return L
|
| 70 |
+
|
| 71 |
+
def read_values(base, key):
|
| 72 |
+
"""Return dict of registry keys and values.
|
| 73 |
+
|
| 74 |
+
All names are converted to lowercase.
|
| 75 |
+
"""
|
| 76 |
+
try:
|
| 77 |
+
handle = RegOpenKeyEx(base, key)
|
| 78 |
+
except RegError:
|
| 79 |
+
return None
|
| 80 |
+
d = {}
|
| 81 |
+
i = 0
|
| 82 |
+
while True:
|
| 83 |
+
try:
|
| 84 |
+
name, value, type = RegEnumValue(handle, i)
|
| 85 |
+
except RegError:
|
| 86 |
+
break
|
| 87 |
+
name = name.lower()
|
| 88 |
+
d[convert_mbcs(name)] = convert_mbcs(value)
|
| 89 |
+
i += 1
|
| 90 |
+
return d
|
| 91 |
+
|
| 92 |
+
def convert_mbcs(s):
|
| 93 |
+
dec = getattr(s, "decode", None)
|
| 94 |
+
if dec is not None:
|
| 95 |
+
try:
|
| 96 |
+
s = dec("mbcs")
|
| 97 |
+
except UnicodeError:
|
| 98 |
+
pass
|
| 99 |
+
return s
|
| 100 |
+
|
| 101 |
+
class MacroExpander:
|
| 102 |
+
def __init__(self, version):
|
| 103 |
+
self.macros = {}
|
| 104 |
+
self.load_macros(version)
|
| 105 |
+
|
| 106 |
+
def set_macro(self, macro, path, key):
|
| 107 |
+
for base in HKEYS:
|
| 108 |
+
d = read_values(base, path)
|
| 109 |
+
if d:
|
| 110 |
+
self.macros["$(%s)" % macro] = d[key]
|
| 111 |
+
break
|
| 112 |
+
|
| 113 |
+
def load_macros(self, version):
|
| 114 |
+
vsbase = r"Software\Microsoft\VisualStudio\%0.1f" % version
|
| 115 |
+
self.set_macro("VCInstallDir", vsbase + r"\Setup\VC", "productdir")
|
| 116 |
+
self.set_macro("VSInstallDir", vsbase + r"\Setup\VS", "productdir")
|
| 117 |
+
net = r"Software\Microsoft\.NETFramework"
|
| 118 |
+
self.set_macro("FrameworkDir", net, "installroot")
|
| 119 |
+
try:
|
| 120 |
+
if version > 7.0:
|
| 121 |
+
self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv1.1")
|
| 122 |
+
else:
|
| 123 |
+
self.set_macro("FrameworkSDKDir", net, "sdkinstallroot")
|
| 124 |
+
except KeyError as exc: #
|
| 125 |
+
raise DistutilsPlatformError(
|
| 126 |
+
"""Python was built with Visual Studio 2003;
|
| 127 |
+
extensions must be built with a compiler than can generate compatible binaries.
|
| 128 |
+
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
|
| 129 |
+
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")
|
| 130 |
+
|
| 131 |
+
p = r"Software\Microsoft\NET Framework Setup\Product"
|
| 132 |
+
for base in HKEYS:
|
| 133 |
+
try:
|
| 134 |
+
h = RegOpenKeyEx(base, p)
|
| 135 |
+
except RegError:
|
| 136 |
+
continue
|
| 137 |
+
key = RegEnumKey(h, 0)
|
| 138 |
+
d = read_values(base, r"%s\%s" % (p, key))
|
| 139 |
+
self.macros["$(FrameworkVersion)"] = d["version"]
|
| 140 |
+
|
| 141 |
+
def sub(self, s):
|
| 142 |
+
for k, v in self.macros.items():
|
| 143 |
+
s = s.replace(k, v)
|
| 144 |
+
return s
|
| 145 |
+
|
| 146 |
+
def get_build_version():
|
| 147 |
+
"""Return the version of MSVC that was used to build Python.
|
| 148 |
+
|
| 149 |
+
For Python 2.3 and up, the version number is included in
|
| 150 |
+
sys.version. For earlier versions, assume the compiler is MSVC 6.
|
| 151 |
+
"""
|
| 152 |
+
prefix = "MSC v."
|
| 153 |
+
i = sys.version.find(prefix)
|
| 154 |
+
if i == -1:
|
| 155 |
+
return 6
|
| 156 |
+
i = i + len(prefix)
|
| 157 |
+
s, rest = sys.version[i:].split(" ", 1)
|
| 158 |
+
majorVersion = int(s[:-2]) - 6
|
| 159 |
+
if majorVersion >= 13:
|
| 160 |
+
# v13 was skipped and should be v14
|
| 161 |
+
majorVersion += 1
|
| 162 |
+
minorVersion = int(s[2:3]) / 10.0
|
| 163 |
+
# I don't think paths are affected by minor version in version 6
|
| 164 |
+
if majorVersion == 6:
|
| 165 |
+
minorVersion = 0
|
| 166 |
+
if majorVersion >= 6:
|
| 167 |
+
return majorVersion + minorVersion
|
| 168 |
+
# else we don't know what version of the compiler this is
|
| 169 |
+
return None
|
| 170 |
+
|
| 171 |
+
def get_build_architecture():
|
| 172 |
+
"""Return the processor architecture.
|
| 173 |
+
|
| 174 |
+
Possible results are "Intel" or "AMD64".
|
| 175 |
+
"""
|
| 176 |
+
|
| 177 |
+
prefix = " bit ("
|
| 178 |
+
i = sys.version.find(prefix)
|
| 179 |
+
if i == -1:
|
| 180 |
+
return "Intel"
|
| 181 |
+
j = sys.version.find(")", i)
|
| 182 |
+
return sys.version[i+len(prefix):j]
|
| 183 |
+
|
| 184 |
+
def normalize_and_reduce_paths(paths):
|
| 185 |
+
"""Return a list of normalized paths with duplicates removed.
|
| 186 |
+
|
| 187 |
+
The current order of paths is maintained.
|
| 188 |
+
"""
|
| 189 |
+
# Paths are normalized so things like: /a and /a/ aren't both preserved.
|
| 190 |
+
reduced_paths = []
|
| 191 |
+
for p in paths:
|
| 192 |
+
np = os.path.normpath(p)
|
| 193 |
+
# XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set.
|
| 194 |
+
if np not in reduced_paths:
|
| 195 |
+
reduced_paths.append(np)
|
| 196 |
+
return reduced_paths
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
class MSVCCompiler(CCompiler) :
|
| 200 |
+
"""Concrete class that implements an interface to Microsoft Visual C++,
|
| 201 |
+
as defined by the CCompiler abstract class."""
|
| 202 |
+
|
| 203 |
+
compiler_type = 'msvc'
|
| 204 |
+
|
| 205 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
| 206 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
| 207 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
| 208 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
| 209 |
+
# though, so it's worth thinking about.
|
| 210 |
+
executables = {}
|
| 211 |
+
|
| 212 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
| 213 |
+
_c_extensions = ['.c']
|
| 214 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
| 215 |
+
_rc_extensions = ['.rc']
|
| 216 |
+
_mc_extensions = ['.mc']
|
| 217 |
+
|
| 218 |
+
# Needed for the filename generation methods provided by the
|
| 219 |
+
# base class, CCompiler.
|
| 220 |
+
src_extensions = (_c_extensions + _cpp_extensions +
|
| 221 |
+
_rc_extensions + _mc_extensions)
|
| 222 |
+
res_extension = '.res'
|
| 223 |
+
obj_extension = '.obj'
|
| 224 |
+
static_lib_extension = '.lib'
|
| 225 |
+
shared_lib_extension = '.dll'
|
| 226 |
+
static_lib_format = shared_lib_format = '%s%s'
|
| 227 |
+
exe_extension = '.exe'
|
| 228 |
+
|
| 229 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
| 230 |
+
CCompiler.__init__ (self, verbose, dry_run, force)
|
| 231 |
+
self.__version = get_build_version()
|
| 232 |
+
self.__arch = get_build_architecture()
|
| 233 |
+
if self.__arch == "Intel":
|
| 234 |
+
# x86
|
| 235 |
+
if self.__version >= 7:
|
| 236 |
+
self.__root = r"Software\Microsoft\VisualStudio"
|
| 237 |
+
self.__macros = MacroExpander(self.__version)
|
| 238 |
+
else:
|
| 239 |
+
self.__root = r"Software\Microsoft\Devstudio"
|
| 240 |
+
self.__product = "Visual Studio version %s" % self.__version
|
| 241 |
+
else:
|
| 242 |
+
# Win64. Assume this was built with the platform SDK
|
| 243 |
+
self.__product = "Microsoft SDK compiler %s" % (self.__version + 6)
|
| 244 |
+
|
| 245 |
+
self.initialized = False
|
| 246 |
+
|
| 247 |
+
def initialize(self):
|
| 248 |
+
self.__paths = []
|
| 249 |
+
if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"):
|
| 250 |
+
# Assume that the SDK set up everything alright; don't try to be
|
| 251 |
+
# smarter
|
| 252 |
+
self.cc = "cl.exe"
|
| 253 |
+
self.linker = "link.exe"
|
| 254 |
+
self.lib = "lib.exe"
|
| 255 |
+
self.rc = "rc.exe"
|
| 256 |
+
self.mc = "mc.exe"
|
| 257 |
+
else:
|
| 258 |
+
self.__paths = self.get_msvc_paths("path")
|
| 259 |
+
|
| 260 |
+
if len(self.__paths) == 0:
|
| 261 |
+
raise DistutilsPlatformError("Python was built with %s, "
|
| 262 |
+
"and extensions need to be built with the same "
|
| 263 |
+
"version of the compiler, but it isn't installed."
|
| 264 |
+
% self.__product)
|
| 265 |
+
|
| 266 |
+
self.cc = self.find_exe("cl.exe")
|
| 267 |
+
self.linker = self.find_exe("link.exe")
|
| 268 |
+
self.lib = self.find_exe("lib.exe")
|
| 269 |
+
self.rc = self.find_exe("rc.exe") # resource compiler
|
| 270 |
+
self.mc = self.find_exe("mc.exe") # message compiler
|
| 271 |
+
self.set_path_env_var('lib')
|
| 272 |
+
self.set_path_env_var('include')
|
| 273 |
+
|
| 274 |
+
# extend the MSVC path with the current path
|
| 275 |
+
try:
|
| 276 |
+
for p in os.environ['path'].split(';'):
|
| 277 |
+
self.__paths.append(p)
|
| 278 |
+
except KeyError:
|
| 279 |
+
pass
|
| 280 |
+
self.__paths = normalize_and_reduce_paths(self.__paths)
|
| 281 |
+
os.environ['path'] = ";".join(self.__paths)
|
| 282 |
+
|
| 283 |
+
self.preprocess_options = None
|
| 284 |
+
if self.__arch == "Intel":
|
| 285 |
+
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GX' ,
|
| 286 |
+
'/DNDEBUG']
|
| 287 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GX',
|
| 288 |
+
'/Z7', '/D_DEBUG']
|
| 289 |
+
else:
|
| 290 |
+
# Win64
|
| 291 |
+
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3', '/GS-' ,
|
| 292 |
+
'/DNDEBUG']
|
| 293 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
|
| 294 |
+
'/Z7', '/D_DEBUG']
|
| 295 |
+
|
| 296 |
+
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
|
| 297 |
+
if self.__version >= 7:
|
| 298 |
+
self.ldflags_shared_debug = [
|
| 299 |
+
'/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG'
|
| 300 |
+
]
|
| 301 |
+
else:
|
| 302 |
+
self.ldflags_shared_debug = [
|
| 303 |
+
'/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None', '/DEBUG'
|
| 304 |
+
]
|
| 305 |
+
self.ldflags_static = [ '/nologo']
|
| 306 |
+
|
| 307 |
+
self.initialized = True
|
| 308 |
+
|
| 309 |
+
# -- Worker methods ------------------------------------------------
|
| 310 |
+
|
| 311 |
+
def object_filenames(self,
|
| 312 |
+
source_filenames,
|
| 313 |
+
strip_dir=0,
|
| 314 |
+
output_dir=''):
|
| 315 |
+
# Copied from ccompiler.py, extended to return .res as 'object'-file
|
| 316 |
+
# for .rc input file
|
| 317 |
+
if output_dir is None: output_dir = ''
|
| 318 |
+
obj_names = []
|
| 319 |
+
for src_name in source_filenames:
|
| 320 |
+
(base, ext) = os.path.splitext (src_name)
|
| 321 |
+
base = os.path.splitdrive(base)[1] # Chop off the drive
|
| 322 |
+
base = base[os.path.isabs(base):] # If abs, chop off leading /
|
| 323 |
+
if ext not in self.src_extensions:
|
| 324 |
+
# Better to raise an exception instead of silently continuing
|
| 325 |
+
# and later complain about sources and targets having
|
| 326 |
+
# different lengths
|
| 327 |
+
raise CompileError ("Don't know how to compile %s" % src_name)
|
| 328 |
+
if strip_dir:
|
| 329 |
+
base = os.path.basename (base)
|
| 330 |
+
if ext in self._rc_extensions:
|
| 331 |
+
obj_names.append (os.path.join (output_dir,
|
| 332 |
+
base + self.res_extension))
|
| 333 |
+
elif ext in self._mc_extensions:
|
| 334 |
+
obj_names.append (os.path.join (output_dir,
|
| 335 |
+
base + self.res_extension))
|
| 336 |
+
else:
|
| 337 |
+
obj_names.append (os.path.join (output_dir,
|
| 338 |
+
base + self.obj_extension))
|
| 339 |
+
return obj_names
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def compile(self, sources,
|
| 343 |
+
output_dir=None, macros=None, include_dirs=None, debug=0,
|
| 344 |
+
extra_preargs=None, extra_postargs=None, depends=None):
|
| 345 |
+
|
| 346 |
+
if not self.initialized:
|
| 347 |
+
self.initialize()
|
| 348 |
+
compile_info = self._setup_compile(output_dir, macros, include_dirs,
|
| 349 |
+
sources, depends, extra_postargs)
|
| 350 |
+
macros, objects, extra_postargs, pp_opts, build = compile_info
|
| 351 |
+
|
| 352 |
+
compile_opts = extra_preargs or []
|
| 353 |
+
compile_opts.append ('/c')
|
| 354 |
+
if debug:
|
| 355 |
+
compile_opts.extend(self.compile_options_debug)
|
| 356 |
+
else:
|
| 357 |
+
compile_opts.extend(self.compile_options)
|
| 358 |
+
|
| 359 |
+
for obj in objects:
|
| 360 |
+
try:
|
| 361 |
+
src, ext = build[obj]
|
| 362 |
+
except KeyError:
|
| 363 |
+
continue
|
| 364 |
+
if debug:
|
| 365 |
+
# pass the full pathname to MSVC in debug mode,
|
| 366 |
+
# this allows the debugger to find the source file
|
| 367 |
+
# without asking the user to browse for it
|
| 368 |
+
src = os.path.abspath(src)
|
| 369 |
+
|
| 370 |
+
if ext in self._c_extensions:
|
| 371 |
+
input_opt = "/Tc" + src
|
| 372 |
+
elif ext in self._cpp_extensions:
|
| 373 |
+
input_opt = "/Tp" + src
|
| 374 |
+
elif ext in self._rc_extensions:
|
| 375 |
+
# compile .RC to .RES file
|
| 376 |
+
input_opt = src
|
| 377 |
+
output_opt = "/fo" + obj
|
| 378 |
+
try:
|
| 379 |
+
self.spawn([self.rc] + pp_opts +
|
| 380 |
+
[output_opt] + [input_opt])
|
| 381 |
+
except DistutilsExecError as msg:
|
| 382 |
+
raise CompileError(msg)
|
| 383 |
+
continue
|
| 384 |
+
elif ext in self._mc_extensions:
|
| 385 |
+
# Compile .MC to .RC file to .RES file.
|
| 386 |
+
# * '-h dir' specifies the directory for the
|
| 387 |
+
# generated include file
|
| 388 |
+
# * '-r dir' specifies the target directory of the
|
| 389 |
+
# generated RC file and the binary message resource
|
| 390 |
+
# it includes
|
| 391 |
+
#
|
| 392 |
+
# For now (since there are no options to change this),
|
| 393 |
+
# we use the source-directory for the include file and
|
| 394 |
+
# the build directory for the RC file and message
|
| 395 |
+
# resources. This works at least for win32all.
|
| 396 |
+
h_dir = os.path.dirname(src)
|
| 397 |
+
rc_dir = os.path.dirname(obj)
|
| 398 |
+
try:
|
| 399 |
+
# first compile .MC to .RC and .H file
|
| 400 |
+
self.spawn([self.mc] +
|
| 401 |
+
['-h', h_dir, '-r', rc_dir] + [src])
|
| 402 |
+
base, _ = os.path.splitext (os.path.basename (src))
|
| 403 |
+
rc_file = os.path.join (rc_dir, base + '.rc')
|
| 404 |
+
# then compile .RC to .RES file
|
| 405 |
+
self.spawn([self.rc] +
|
| 406 |
+
["/fo" + obj] + [rc_file])
|
| 407 |
+
|
| 408 |
+
except DistutilsExecError as msg:
|
| 409 |
+
raise CompileError(msg)
|
| 410 |
+
continue
|
| 411 |
+
else:
|
| 412 |
+
# how to handle this file?
|
| 413 |
+
raise CompileError("Don't know how to compile %s to %s"
|
| 414 |
+
% (src, obj))
|
| 415 |
+
|
| 416 |
+
output_opt = "/Fo" + obj
|
| 417 |
+
try:
|
| 418 |
+
self.spawn([self.cc] + compile_opts + pp_opts +
|
| 419 |
+
[input_opt, output_opt] +
|
| 420 |
+
extra_postargs)
|
| 421 |
+
except DistutilsExecError as msg:
|
| 422 |
+
raise CompileError(msg)
|
| 423 |
+
|
| 424 |
+
return objects
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
def create_static_lib(self,
|
| 428 |
+
objects,
|
| 429 |
+
output_libname,
|
| 430 |
+
output_dir=None,
|
| 431 |
+
debug=0,
|
| 432 |
+
target_lang=None):
|
| 433 |
+
|
| 434 |
+
if not self.initialized:
|
| 435 |
+
self.initialize()
|
| 436 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
| 437 |
+
output_filename = self.library_filename(output_libname,
|
| 438 |
+
output_dir=output_dir)
|
| 439 |
+
|
| 440 |
+
if self._need_link(objects, output_filename):
|
| 441 |
+
lib_args = objects + ['/OUT:' + output_filename]
|
| 442 |
+
if debug:
|
| 443 |
+
pass # XXX what goes here?
|
| 444 |
+
try:
|
| 445 |
+
self.spawn([self.lib] + lib_args)
|
| 446 |
+
except DistutilsExecError as msg:
|
| 447 |
+
raise LibError(msg)
|
| 448 |
+
else:
|
| 449 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
def link(self,
|
| 453 |
+
target_desc,
|
| 454 |
+
objects,
|
| 455 |
+
output_filename,
|
| 456 |
+
output_dir=None,
|
| 457 |
+
libraries=None,
|
| 458 |
+
library_dirs=None,
|
| 459 |
+
runtime_library_dirs=None,
|
| 460 |
+
export_symbols=None,
|
| 461 |
+
debug=0,
|
| 462 |
+
extra_preargs=None,
|
| 463 |
+
extra_postargs=None,
|
| 464 |
+
build_temp=None,
|
| 465 |
+
target_lang=None):
|
| 466 |
+
|
| 467 |
+
if not self.initialized:
|
| 468 |
+
self.initialize()
|
| 469 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
| 470 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs,
|
| 471 |
+
runtime_library_dirs)
|
| 472 |
+
(libraries, library_dirs, runtime_library_dirs) = fixed_args
|
| 473 |
+
|
| 474 |
+
if runtime_library_dirs:
|
| 475 |
+
self.warn ("I don't know what to do with 'runtime_library_dirs': "
|
| 476 |
+
+ str (runtime_library_dirs))
|
| 477 |
+
|
| 478 |
+
lib_opts = gen_lib_options(self,
|
| 479 |
+
library_dirs, runtime_library_dirs,
|
| 480 |
+
libraries)
|
| 481 |
+
if output_dir is not None:
|
| 482 |
+
output_filename = os.path.join(output_dir, output_filename)
|
| 483 |
+
|
| 484 |
+
if self._need_link(objects, output_filename):
|
| 485 |
+
if target_desc == CCompiler.EXECUTABLE:
|
| 486 |
+
if debug:
|
| 487 |
+
ldflags = self.ldflags_shared_debug[1:]
|
| 488 |
+
else:
|
| 489 |
+
ldflags = self.ldflags_shared[1:]
|
| 490 |
+
else:
|
| 491 |
+
if debug:
|
| 492 |
+
ldflags = self.ldflags_shared_debug
|
| 493 |
+
else:
|
| 494 |
+
ldflags = self.ldflags_shared
|
| 495 |
+
|
| 496 |
+
export_opts = []
|
| 497 |
+
for sym in (export_symbols or []):
|
| 498 |
+
export_opts.append("/EXPORT:" + sym)
|
| 499 |
+
|
| 500 |
+
ld_args = (ldflags + lib_opts + export_opts +
|
| 501 |
+
objects + ['/OUT:' + output_filename])
|
| 502 |
+
|
| 503 |
+
# The MSVC linker generates .lib and .exp files, which cannot be
|
| 504 |
+
# suppressed by any linker switches. The .lib files may even be
|
| 505 |
+
# needed! Make sure they are generated in the temporary build
|
| 506 |
+
# directory. Since they have different names for debug and release
|
| 507 |
+
# builds, they can go into the same directory.
|
| 508 |
+
if export_symbols is not None:
|
| 509 |
+
(dll_name, dll_ext) = os.path.splitext(
|
| 510 |
+
os.path.basename(output_filename))
|
| 511 |
+
implib_file = os.path.join(
|
| 512 |
+
os.path.dirname(objects[0]),
|
| 513 |
+
self.library_filename(dll_name))
|
| 514 |
+
ld_args.append ('/IMPLIB:' + implib_file)
|
| 515 |
+
|
| 516 |
+
if extra_preargs:
|
| 517 |
+
ld_args[:0] = extra_preargs
|
| 518 |
+
if extra_postargs:
|
| 519 |
+
ld_args.extend(extra_postargs)
|
| 520 |
+
|
| 521 |
+
self.mkpath(os.path.dirname(output_filename))
|
| 522 |
+
try:
|
| 523 |
+
self.spawn([self.linker] + ld_args)
|
| 524 |
+
except DistutilsExecError as msg:
|
| 525 |
+
raise LinkError(msg)
|
| 526 |
+
|
| 527 |
+
else:
|
| 528 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 532 |
+
# These are all used by the 'gen_lib_options() function, in
|
| 533 |
+
# ccompiler.py.
|
| 534 |
+
|
| 535 |
+
def library_dir_option(self, dir):
|
| 536 |
+
return "/LIBPATH:" + dir
|
| 537 |
+
|
| 538 |
+
def runtime_library_dir_option(self, dir):
|
| 539 |
+
raise DistutilsPlatformError(
|
| 540 |
+
"don't know how to set runtime library search path for MSVC++")
|
| 541 |
+
|
| 542 |
+
def library_option(self, lib):
|
| 543 |
+
return self.library_filename(lib)
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
def find_library_file(self, dirs, lib, debug=0):
|
| 547 |
+
# Prefer a debugging library if found (and requested), but deal
|
| 548 |
+
# with it if we don't have one.
|
| 549 |
+
if debug:
|
| 550 |
+
try_names = [lib + "_d", lib]
|
| 551 |
+
else:
|
| 552 |
+
try_names = [lib]
|
| 553 |
+
for dir in dirs:
|
| 554 |
+
for name in try_names:
|
| 555 |
+
libfile = os.path.join(dir, self.library_filename (name))
|
| 556 |
+
if os.path.exists(libfile):
|
| 557 |
+
return libfile
|
| 558 |
+
else:
|
| 559 |
+
# Oops, didn't find it in *any* of 'dirs'
|
| 560 |
+
return None
|
| 561 |
+
|
| 562 |
+
# Helper methods for using the MSVC registry settings
|
| 563 |
+
|
| 564 |
+
def find_exe(self, exe):
|
| 565 |
+
"""Return path to an MSVC executable program.
|
| 566 |
+
|
| 567 |
+
Tries to find the program in several places: first, one of the
|
| 568 |
+
MSVC program search paths from the registry; next, the directories
|
| 569 |
+
in the PATH environment variable. If any of those work, return an
|
| 570 |
+
absolute path that is known to exist. If none of them work, just
|
| 571 |
+
return the original program name, 'exe'.
|
| 572 |
+
"""
|
| 573 |
+
for p in self.__paths:
|
| 574 |
+
fn = os.path.join(os.path.abspath(p), exe)
|
| 575 |
+
if os.path.isfile(fn):
|
| 576 |
+
return fn
|
| 577 |
+
|
| 578 |
+
# didn't find it; try existing path
|
| 579 |
+
for p in os.environ['Path'].split(';'):
|
| 580 |
+
fn = os.path.join(os.path.abspath(p),exe)
|
| 581 |
+
if os.path.isfile(fn):
|
| 582 |
+
return fn
|
| 583 |
+
|
| 584 |
+
return exe
|
| 585 |
+
|
| 586 |
+
def get_msvc_paths(self, path, platform='x86'):
|
| 587 |
+
"""Get a list of devstudio directories (include, lib or path).
|
| 588 |
+
|
| 589 |
+
Return a list of strings. The list will be empty if unable to
|
| 590 |
+
access the registry or appropriate registry keys not found.
|
| 591 |
+
"""
|
| 592 |
+
if not _can_read_reg:
|
| 593 |
+
return []
|
| 594 |
+
|
| 595 |
+
path = path + " dirs"
|
| 596 |
+
if self.__version >= 7:
|
| 597 |
+
key = (r"%s\%0.1f\VC\VC_OBJECTS_PLATFORM_INFO\Win32\Directories"
|
| 598 |
+
% (self.__root, self.__version))
|
| 599 |
+
else:
|
| 600 |
+
key = (r"%s\6.0\Build System\Components\Platforms"
|
| 601 |
+
r"\Win32 (%s)\Directories" % (self.__root, platform))
|
| 602 |
+
|
| 603 |
+
for base in HKEYS:
|
| 604 |
+
d = read_values(base, key)
|
| 605 |
+
if d:
|
| 606 |
+
if self.__version >= 7:
|
| 607 |
+
return self.__macros.sub(d[path]).split(";")
|
| 608 |
+
else:
|
| 609 |
+
return d[path].split(";")
|
| 610 |
+
# MSVC 6 seems to create the registry entries we need only when
|
| 611 |
+
# the GUI is run.
|
| 612 |
+
if self.__version == 6:
|
| 613 |
+
for base in HKEYS:
|
| 614 |
+
if read_values(base, r"%s\6.0" % self.__root) is not None:
|
| 615 |
+
self.warn("It seems you have Visual Studio 6 installed, "
|
| 616 |
+
"but the expected registry settings are not present.\n"
|
| 617 |
+
"You must at least run the Visual Studio GUI once "
|
| 618 |
+
"so that these entries are created.")
|
| 619 |
+
break
|
| 620 |
+
return []
|
| 621 |
+
|
| 622 |
+
def set_path_env_var(self, name):
|
| 623 |
+
"""Set environment variable 'name' to an MSVC path type value.
|
| 624 |
+
|
| 625 |
+
This is equivalent to a SET command prior to execution of spawned
|
| 626 |
+
commands.
|
| 627 |
+
"""
|
| 628 |
+
|
| 629 |
+
if name == "lib":
|
| 630 |
+
p = self.get_msvc_paths("library")
|
| 631 |
+
else:
|
| 632 |
+
p = self.get_msvc_paths(name)
|
| 633 |
+
if p:
|
| 634 |
+
os.environ[name] = ';'.join(p)
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
if get_build_version() >= 8.0:
|
| 638 |
+
log.debug("Importing new compiler from distutils.msvc9compiler")
|
| 639 |
+
OldMSVCCompiler = MSVCCompiler
|
| 640 |
+
from distutils.msvc9compiler import MSVCCompiler
|
| 641 |
+
# get_build_architecture not really relevant now we support cross-compile
|
| 642 |
+
from distutils.msvc9compiler import MacroExpander
|
data/conda_envs/evalclaw/lib/python3.11/distutils/spawn.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.spawn
|
| 2 |
+
|
| 3 |
+
Provides the 'spawn()' function, a front-end to various platform-
|
| 4 |
+
specific functions for launching another program in a sub-process.
|
| 5 |
+
Also provides the 'find_executable()' to search the path for a given
|
| 6 |
+
executable name.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import sys
|
| 10 |
+
import os
|
| 11 |
+
import subprocess
|
| 12 |
+
|
| 13 |
+
from distutils.errors import DistutilsPlatformError, DistutilsExecError
|
| 14 |
+
from distutils.debug import DEBUG
|
| 15 |
+
from distutils import log
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
if sys.platform == 'darwin':
|
| 19 |
+
_cfg_target = None
|
| 20 |
+
_cfg_target_split = None
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def spawn(cmd, search_path=1, verbose=0, dry_run=0):
|
| 24 |
+
"""Run another program, specified as a command list 'cmd', in a new process.
|
| 25 |
+
|
| 26 |
+
'cmd' is just the argument list for the new process, ie.
|
| 27 |
+
cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
|
| 28 |
+
There is no way to run a program with a name different from that of its
|
| 29 |
+
executable.
|
| 30 |
+
|
| 31 |
+
If 'search_path' is true (the default), the system's executable
|
| 32 |
+
search path will be used to find the program; otherwise, cmd[0]
|
| 33 |
+
must be the exact path to the executable. If 'dry_run' is true,
|
| 34 |
+
the command will not actually be run.
|
| 35 |
+
|
| 36 |
+
Raise DistutilsExecError if running the program fails in any way; just
|
| 37 |
+
return on success.
|
| 38 |
+
"""
|
| 39 |
+
# cmd is documented as a list, but just in case some code passes a tuple
|
| 40 |
+
# in, protect our %-formatting code against horrible death
|
| 41 |
+
cmd = list(cmd)
|
| 42 |
+
|
| 43 |
+
log.info(' '.join(cmd))
|
| 44 |
+
if dry_run:
|
| 45 |
+
return
|
| 46 |
+
|
| 47 |
+
if search_path:
|
| 48 |
+
executable = find_executable(cmd[0])
|
| 49 |
+
if executable is not None:
|
| 50 |
+
cmd[0] = executable
|
| 51 |
+
|
| 52 |
+
env = None
|
| 53 |
+
if sys.platform == 'darwin':
|
| 54 |
+
global _cfg_target, _cfg_target_split
|
| 55 |
+
if _cfg_target is None:
|
| 56 |
+
from distutils import sysconfig
|
| 57 |
+
_cfg_target = sysconfig.get_config_var(
|
| 58 |
+
'MACOSX_DEPLOYMENT_TARGET') or ''
|
| 59 |
+
if _cfg_target:
|
| 60 |
+
_cfg_target_split = [int(x) for x in _cfg_target.split('.')]
|
| 61 |
+
if _cfg_target:
|
| 62 |
+
# Ensure that the deployment target of the build process is not
|
| 63 |
+
# less than 10.3 if the interpreter was built for 10.3 or later.
|
| 64 |
+
# This ensures extension modules are built with correct
|
| 65 |
+
# compatibility values, specifically LDSHARED which can use
|
| 66 |
+
# '-undefined dynamic_lookup' which only works on >= 10.3.
|
| 67 |
+
cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target)
|
| 68 |
+
cur_target_split = [int(x) for x in cur_target.split('.')]
|
| 69 |
+
if _cfg_target_split[:2] >= [10, 3] and cur_target_split[:2] < [10, 3]:
|
| 70 |
+
my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: '
|
| 71 |
+
'now "%s" but "%s" during configure;'
|
| 72 |
+
'must use 10.3 or later'
|
| 73 |
+
% (cur_target, _cfg_target))
|
| 74 |
+
raise DistutilsPlatformError(my_msg)
|
| 75 |
+
env = dict(os.environ,
|
| 76 |
+
MACOSX_DEPLOYMENT_TARGET=cur_target)
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
proc = subprocess.Popen(cmd, env=env)
|
| 80 |
+
proc.wait()
|
| 81 |
+
exitcode = proc.returncode
|
| 82 |
+
except OSError as exc:
|
| 83 |
+
if not DEBUG:
|
| 84 |
+
cmd = cmd[0]
|
| 85 |
+
raise DistutilsExecError(
|
| 86 |
+
"command %r failed: %s" % (cmd, exc.args[-1])) from exc
|
| 87 |
+
|
| 88 |
+
if exitcode:
|
| 89 |
+
if not DEBUG:
|
| 90 |
+
cmd = cmd[0]
|
| 91 |
+
raise DistutilsExecError(
|
| 92 |
+
"command %r failed with exit code %s" % (cmd, exitcode))
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def find_executable(executable, path=None):
|
| 96 |
+
"""Tries to find 'executable' in the directories listed in 'path'.
|
| 97 |
+
|
| 98 |
+
A string listing directories separated by 'os.pathsep'; defaults to
|
| 99 |
+
os.environ['PATH']. Returns the complete filename or None if not found.
|
| 100 |
+
"""
|
| 101 |
+
_, ext = os.path.splitext(executable)
|
| 102 |
+
if (sys.platform == 'win32') and (ext != '.exe'):
|
| 103 |
+
executable = executable + '.exe'
|
| 104 |
+
|
| 105 |
+
if os.path.isfile(executable):
|
| 106 |
+
return executable
|
| 107 |
+
|
| 108 |
+
if path is None:
|
| 109 |
+
path = os.environ.get('PATH', None)
|
| 110 |
+
if path is None:
|
| 111 |
+
try:
|
| 112 |
+
path = os.confstr("CS_PATH")
|
| 113 |
+
except (AttributeError, ValueError):
|
| 114 |
+
# os.confstr() or CS_PATH is not available
|
| 115 |
+
path = os.defpath
|
| 116 |
+
# bpo-35755: Don't use os.defpath if the PATH environment variable is
|
| 117 |
+
# set to an empty string
|
| 118 |
+
|
| 119 |
+
# PATH='' doesn't match, whereas PATH=':' looks in the current directory
|
| 120 |
+
if not path:
|
| 121 |
+
return None
|
| 122 |
+
|
| 123 |
+
paths = path.split(os.pathsep)
|
| 124 |
+
for p in paths:
|
| 125 |
+
f = os.path.join(p, executable)
|
| 126 |
+
if os.path.isfile(f):
|
| 127 |
+
# the file exists, we have a shot at spawn working
|
| 128 |
+
return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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Provide access to Python's configuration information. The specific
|
| 2 |
+
configuration variables available depend heavily on the platform and
|
| 3 |
+
configuration. The values may be retrieved using
|
| 4 |
+
get_config_var(name), and the list of variables is available via
|
| 5 |
+
get_config_vars().keys(). Additional convenience functions are also
|
| 6 |
+
available.
|
| 7 |
+
|
| 8 |
+
Written by: Fred L. Drake, Jr.
|
| 9 |
+
Email: <fdrake@acm.org>
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import _imp
|
| 13 |
+
import os
|
| 14 |
+
import re
|
| 15 |
+
import sys
|
| 16 |
+
import warnings
|
| 17 |
+
|
| 18 |
+
from functools import partial
|
| 19 |
+
|
| 20 |
+
from .errors import DistutilsPlatformError
|
| 21 |
+
|
| 22 |
+
from sysconfig import (
|
| 23 |
+
_PREFIX as PREFIX,
|
| 24 |
+
_BASE_PREFIX as BASE_PREFIX,
|
| 25 |
+
_EXEC_PREFIX as EXEC_PREFIX,
|
| 26 |
+
_BASE_EXEC_PREFIX as BASE_EXEC_PREFIX,
|
| 27 |
+
_PROJECT_BASE as project_base,
|
| 28 |
+
_PYTHON_BUILD as python_build,
|
| 29 |
+
_init_posix as sysconfig_init_posix,
|
| 30 |
+
parse_config_h as sysconfig_parse_config_h,
|
| 31 |
+
|
| 32 |
+
_init_non_posix,
|
| 33 |
+
|
| 34 |
+
_variable_rx,
|
| 35 |
+
_findvar1_rx,
|
| 36 |
+
_findvar2_rx,
|
| 37 |
+
|
| 38 |
+
expand_makefile_vars,
|
| 39 |
+
is_python_build,
|
| 40 |
+
get_config_h_filename,
|
| 41 |
+
get_config_var,
|
| 42 |
+
get_config_vars,
|
| 43 |
+
get_makefile_filename,
|
| 44 |
+
get_python_version,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# This is better than
|
| 48 |
+
# from sysconfig import _CONFIG_VARS as _config_vars
|
| 49 |
+
# because it makes sure that the global dictionary is initialized
|
| 50 |
+
# which might not be true in the time of import.
|
| 51 |
+
_config_vars = get_config_vars()
|
| 52 |
+
|
| 53 |
+
warnings.warn(
|
| 54 |
+
'The distutils.sysconfig module is deprecated, use sysconfig instead',
|
| 55 |
+
DeprecationWarning,
|
| 56 |
+
stacklevel=2
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# Following functions are the same as in sysconfig but with different API
|
| 61 |
+
def parse_config_h(fp, g=None):
|
| 62 |
+
return sysconfig_parse_config_h(fp, vars=g)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
_python_build = partial(is_python_build, check_home=True)
|
| 66 |
+
_init_posix = partial(sysconfig_init_posix, _config_vars)
|
| 67 |
+
_init_nt = partial(_init_non_posix, _config_vars)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# Similar function is also implemented in sysconfig as _parse_makefile
|
| 71 |
+
# but without the parsing capabilities of distutils.text_file.TextFile.
|
| 72 |
+
def parse_makefile(fn, g=None):
|
| 73 |
+
"""Parse a Makefile-style file.
|
| 74 |
+
A dictionary containing name/value pairs is returned. If an
|
| 75 |
+
optional dictionary is passed in as the second argument, it is
|
| 76 |
+
used instead of a new dictionary.
|
| 77 |
+
"""
|
| 78 |
+
from distutils.text_file import TextFile
|
| 79 |
+
fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
|
| 80 |
+
|
| 81 |
+
if g is None:
|
| 82 |
+
g = {}
|
| 83 |
+
done = {}
|
| 84 |
+
notdone = {}
|
| 85 |
+
|
| 86 |
+
while True:
|
| 87 |
+
line = fp.readline()
|
| 88 |
+
if line is None: # eof
|
| 89 |
+
break
|
| 90 |
+
m = re.match(_variable_rx, line)
|
| 91 |
+
if m:
|
| 92 |
+
n, v = m.group(1, 2)
|
| 93 |
+
v = v.strip()
|
| 94 |
+
# `$$' is a literal `$' in make
|
| 95 |
+
tmpv = v.replace('$$', '')
|
| 96 |
+
|
| 97 |
+
if "$" in tmpv:
|
| 98 |
+
notdone[n] = v
|
| 99 |
+
else:
|
| 100 |
+
try:
|
| 101 |
+
v = int(v)
|
| 102 |
+
except ValueError:
|
| 103 |
+
# insert literal `$'
|
| 104 |
+
done[n] = v.replace('$$', '$')
|
| 105 |
+
else:
|
| 106 |
+
done[n] = v
|
| 107 |
+
|
| 108 |
+
# Variables with a 'PY_' prefix in the makefile. These need to
|
| 109 |
+
# be made available without that prefix through sysconfig.
|
| 110 |
+
# Special care is needed to ensure that variable expansion works, even
|
| 111 |
+
# if the expansion uses the name without a prefix.
|
| 112 |
+
renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
|
| 113 |
+
|
| 114 |
+
# do variable interpolation here
|
| 115 |
+
while notdone:
|
| 116 |
+
for name in list(notdone):
|
| 117 |
+
value = notdone[name]
|
| 118 |
+
m = re.search(_findvar1_rx, value) or re.search(_findvar2_rx, value)
|
| 119 |
+
if m:
|
| 120 |
+
n = m.group(1)
|
| 121 |
+
found = True
|
| 122 |
+
if n in done:
|
| 123 |
+
item = str(done[n])
|
| 124 |
+
elif n in notdone:
|
| 125 |
+
# get it on a subsequent round
|
| 126 |
+
found = False
|
| 127 |
+
elif n in os.environ:
|
| 128 |
+
# do it like make: fall back to environment
|
| 129 |
+
item = os.environ[n]
|
| 130 |
+
|
| 131 |
+
elif n in renamed_variables:
|
| 132 |
+
if name.startswith('PY_') and name[3:] in renamed_variables:
|
| 133 |
+
item = ""
|
| 134 |
+
|
| 135 |
+
elif 'PY_' + n in notdone:
|
| 136 |
+
found = False
|
| 137 |
+
|
| 138 |
+
else:
|
| 139 |
+
item = str(done['PY_' + n])
|
| 140 |
+
else:
|
| 141 |
+
done[n] = item = ""
|
| 142 |
+
if found:
|
| 143 |
+
after = value[m.end():]
|
| 144 |
+
value = value[:m.start()] + item + after
|
| 145 |
+
if "$" in after:
|
| 146 |
+
notdone[name] = value
|
| 147 |
+
else:
|
| 148 |
+
try: value = int(value)
|
| 149 |
+
except ValueError:
|
| 150 |
+
done[name] = value.strip()
|
| 151 |
+
else:
|
| 152 |
+
done[name] = value
|
| 153 |
+
del notdone[name]
|
| 154 |
+
|
| 155 |
+
if name.startswith('PY_') \
|
| 156 |
+
and name[3:] in renamed_variables:
|
| 157 |
+
|
| 158 |
+
name = name[3:]
|
| 159 |
+
if name not in done:
|
| 160 |
+
done[name] = value
|
| 161 |
+
else:
|
| 162 |
+
# bogus variable reference; just drop it since we can't deal
|
| 163 |
+
del notdone[name]
|
| 164 |
+
|
| 165 |
+
fp.close()
|
| 166 |
+
|
| 167 |
+
# strip spurious spaces
|
| 168 |
+
for k, v in done.items():
|
| 169 |
+
if isinstance(v, str):
|
| 170 |
+
done[k] = v.strip()
|
| 171 |
+
|
| 172 |
+
# save the results in the global dictionary
|
| 173 |
+
g.update(done)
|
| 174 |
+
return g
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
# Following functions are deprecated together with this module and they
|
| 178 |
+
# have no direct replacement
|
| 179 |
+
|
| 180 |
+
# Calculate the build qualifier flags if they are defined. Adding the flags
|
| 181 |
+
# to the include and lib directories only makes sense for an installation, not
|
| 182 |
+
# an in-source build.
|
| 183 |
+
build_flags = ''
|
| 184 |
+
try:
|
| 185 |
+
if not python_build:
|
| 186 |
+
build_flags = sys.abiflags
|
| 187 |
+
except AttributeError:
|
| 188 |
+
# It's not a configure-based build, so the sys module doesn't have
|
| 189 |
+
# this attribute, which is fine.
|
| 190 |
+
pass
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def customize_compiler(compiler):
|
| 194 |
+
"""Do any platform-specific customization of a CCompiler instance.
|
| 195 |
+
|
| 196 |
+
Mainly needed on Unix, so we can plug in the information that
|
| 197 |
+
varies across Unices and is stored in Python's Makefile.
|
| 198 |
+
"""
|
| 199 |
+
if compiler.compiler_type == "unix":
|
| 200 |
+
if sys.platform == "darwin":
|
| 201 |
+
# Perform first-time customization of compiler-related
|
| 202 |
+
# config vars on OS X now that we know we need a compiler.
|
| 203 |
+
# This is primarily to support Pythons from binary
|
| 204 |
+
# installers. The kind and paths to build tools on
|
| 205 |
+
# the user system may vary significantly from the system
|
| 206 |
+
# that Python itself was built on. Also the user OS
|
| 207 |
+
# version and build tools may not support the same set
|
| 208 |
+
# of CPU architectures for universal builds.
|
| 209 |
+
if not _config_vars.get('CUSTOMIZED_OSX_COMPILER'):
|
| 210 |
+
import _osx_support
|
| 211 |
+
_osx_support.customize_compiler(_config_vars)
|
| 212 |
+
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
|
| 213 |
+
|
| 214 |
+
(cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
|
| 215 |
+
get_config_vars('CC', 'CXX', 'CFLAGS',
|
| 216 |
+
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
|
| 217 |
+
|
| 218 |
+
if 'CC' in os.environ:
|
| 219 |
+
newcc = os.environ['CC']
|
| 220 |
+
if ('LDSHARED' not in os.environ
|
| 221 |
+
and ldshared.startswith(cc)):
|
| 222 |
+
# If CC is overridden, use that as the default
|
| 223 |
+
# command for LDSHARED as well
|
| 224 |
+
ldshared = newcc + ldshared[len(cc):]
|
| 225 |
+
cc = newcc
|
| 226 |
+
if 'CXX' in os.environ:
|
| 227 |
+
cxx = os.environ['CXX']
|
| 228 |
+
if 'LDSHARED' in os.environ:
|
| 229 |
+
ldshared = os.environ['LDSHARED']
|
| 230 |
+
if 'CPP' in os.environ:
|
| 231 |
+
cpp = os.environ['CPP']
|
| 232 |
+
else:
|
| 233 |
+
cpp = cc + " -E" # not always
|
| 234 |
+
if 'LDFLAGS' in os.environ:
|
| 235 |
+
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
|
| 236 |
+
if 'CFLAGS' in os.environ:
|
| 237 |
+
cflags = cflags + ' ' + os.environ['CFLAGS']
|
| 238 |
+
ldshared = ldshared + ' ' + os.environ['CFLAGS']
|
| 239 |
+
if 'CPPFLAGS' in os.environ:
|
| 240 |
+
cpp = cpp + ' ' + os.environ['CPPFLAGS']
|
| 241 |
+
cflags = cflags + ' ' + os.environ['CPPFLAGS']
|
| 242 |
+
ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
|
| 243 |
+
if 'AR' in os.environ:
|
| 244 |
+
ar = os.environ['AR']
|
| 245 |
+
if 'ARFLAGS' in os.environ:
|
| 246 |
+
archiver = ar + ' ' + os.environ['ARFLAGS']
|
| 247 |
+
else:
|
| 248 |
+
archiver = ar + ' ' + ar_flags
|
| 249 |
+
|
| 250 |
+
cc_cmd = cc + ' ' + cflags
|
| 251 |
+
compiler.set_executables(
|
| 252 |
+
preprocessor=cpp,
|
| 253 |
+
compiler=cc_cmd,
|
| 254 |
+
compiler_so=cc_cmd + ' ' + ccshared,
|
| 255 |
+
compiler_cxx=cxx,
|
| 256 |
+
linker_so=ldshared,
|
| 257 |
+
linker_exe=cc,
|
| 258 |
+
archiver=archiver)
|
| 259 |
+
|
| 260 |
+
if 'RANLIB' in os.environ and 'ranlib' in compiler.executables:
|
| 261 |
+
compiler.set_executables(ranlib=os.environ['RANLIB'])
|
| 262 |
+
|
| 263 |
+
compiler.shared_lib_extension = shlib_suffix
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def get_python_inc(plat_specific=0, prefix=None):
|
| 267 |
+
"""Return the directory containing installed Python header files.
|
| 268 |
+
|
| 269 |
+
If 'plat_specific' is false (the default), this is the path to the
|
| 270 |
+
non-platform-specific header files, i.e. Python.h and so on;
|
| 271 |
+
otherwise, this is the path to platform-specific header files
|
| 272 |
+
(namely pyconfig.h).
|
| 273 |
+
|
| 274 |
+
If 'prefix' is supplied, use it instead of sys.base_prefix or
|
| 275 |
+
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
|
| 276 |
+
"""
|
| 277 |
+
if prefix is None:
|
| 278 |
+
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
|
| 279 |
+
if os.name == "posix":
|
| 280 |
+
if python_build:
|
| 281 |
+
# Assume the executable is in the build directory. The
|
| 282 |
+
# pyconfig.h file should be in the same directory. Since
|
| 283 |
+
# the build directory may not be the source directory, we
|
| 284 |
+
# must use "srcdir" from the makefile to find the "Include"
|
| 285 |
+
# directory.
|
| 286 |
+
if plat_specific:
|
| 287 |
+
return project_base
|
| 288 |
+
else:
|
| 289 |
+
incdir = os.path.join(get_config_var('srcdir'), 'Include')
|
| 290 |
+
return os.path.normpath(incdir)
|
| 291 |
+
python_dir = 'python' + get_python_version() + build_flags
|
| 292 |
+
return os.path.join(prefix, "include", python_dir)
|
| 293 |
+
elif os.name == "nt":
|
| 294 |
+
if python_build:
|
| 295 |
+
# Include both the include and PC dir to ensure we can find
|
| 296 |
+
# pyconfig.h
|
| 297 |
+
return (os.path.join(prefix, "include") + os.path.pathsep +
|
| 298 |
+
os.path.join(prefix, "PC"))
|
| 299 |
+
return os.path.join(prefix, "include")
|
| 300 |
+
else:
|
| 301 |
+
raise DistutilsPlatformError(
|
| 302 |
+
"I don't know where Python installs its C header files "
|
| 303 |
+
"on platform '%s'" % os.name)
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
| 307 |
+
"""Return the directory containing the Python library (standard or
|
| 308 |
+
site additions).
|
| 309 |
+
|
| 310 |
+
If 'plat_specific' is true, return the directory containing
|
| 311 |
+
platform-specific modules, i.e. any module from a non-pure-Python
|
| 312 |
+
module distribution; otherwise, return the platform-shared library
|
| 313 |
+
directory. If 'standard_lib' is true, return the directory
|
| 314 |
+
containing standard Python library modules; otherwise, return the
|
| 315 |
+
directory for site-specific modules.
|
| 316 |
+
|
| 317 |
+
If 'prefix' is supplied, use it instead of sys.base_prefix or
|
| 318 |
+
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
|
| 319 |
+
"""
|
| 320 |
+
if prefix is None:
|
| 321 |
+
if standard_lib:
|
| 322 |
+
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
|
| 323 |
+
else:
|
| 324 |
+
prefix = plat_specific and EXEC_PREFIX or PREFIX
|
| 325 |
+
|
| 326 |
+
if os.name == "posix":
|
| 327 |
+
if plat_specific or standard_lib:
|
| 328 |
+
# Platform-specific modules (any module from a non-pure-Python
|
| 329 |
+
# module distribution) or standard Python library modules.
|
| 330 |
+
libdir = sys.platlibdir
|
| 331 |
+
else:
|
| 332 |
+
# Pure Python
|
| 333 |
+
libdir = "lib"
|
| 334 |
+
libpython = os.path.join(prefix, libdir,
|
| 335 |
+
"python" + get_python_version())
|
| 336 |
+
if standard_lib:
|
| 337 |
+
return libpython
|
| 338 |
+
else:
|
| 339 |
+
return os.path.join(libpython, "site-packages")
|
| 340 |
+
elif os.name == "nt":
|
| 341 |
+
if standard_lib:
|
| 342 |
+
return os.path.join(prefix, "Lib")
|
| 343 |
+
else:
|
| 344 |
+
return os.path.join(prefix, "Lib", "site-packages")
|
| 345 |
+
else:
|
| 346 |
+
raise DistutilsPlatformError(
|
| 347 |
+
"I don't know where Python installs its library "
|
| 348 |
+
"on platform '%s'" % os.name)
|
data/conda_envs/evalclaw/lib/python3.11/distutils/text_file.py
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""text_file
|
| 2 |
+
|
| 3 |
+
provides the TextFile class, which gives an interface to text files
|
| 4 |
+
that (optionally) takes care of stripping comments, ignoring blank
|
| 5 |
+
lines, and joining lines with backslashes."""
|
| 6 |
+
|
| 7 |
+
import sys, io
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TextFile:
|
| 11 |
+
"""Provides a file-like object that takes care of all the things you
|
| 12 |
+
commonly want to do when processing a text file that has some
|
| 13 |
+
line-by-line syntax: strip comments (as long as "#" is your
|
| 14 |
+
comment character), skip blank lines, join adjacent lines by
|
| 15 |
+
escaping the newline (ie. backslash at end of line), strip
|
| 16 |
+
leading and/or trailing whitespace. All of these are optional
|
| 17 |
+
and independently controllable.
|
| 18 |
+
|
| 19 |
+
Provides a 'warn()' method so you can generate warning messages that
|
| 20 |
+
report physical line number, even if the logical line in question
|
| 21 |
+
spans multiple physical lines. Also provides 'unreadline()' for
|
| 22 |
+
implementing line-at-a-time lookahead.
|
| 23 |
+
|
| 24 |
+
Constructor is called as:
|
| 25 |
+
|
| 26 |
+
TextFile (filename=None, file=None, **options)
|
| 27 |
+
|
| 28 |
+
It bombs (RuntimeError) if both 'filename' and 'file' are None;
|
| 29 |
+
'filename' should be a string, and 'file' a file object (or
|
| 30 |
+
something that provides 'readline()' and 'close()' methods). It is
|
| 31 |
+
recommended that you supply at least 'filename', so that TextFile
|
| 32 |
+
can include it in warning messages. If 'file' is not supplied,
|
| 33 |
+
TextFile creates its own using 'io.open()'.
|
| 34 |
+
|
| 35 |
+
The options are all boolean, and affect the value returned by
|
| 36 |
+
'readline()':
|
| 37 |
+
strip_comments [default: true]
|
| 38 |
+
strip from "#" to end-of-line, as well as any whitespace
|
| 39 |
+
leading up to the "#" -- unless it is escaped by a backslash
|
| 40 |
+
lstrip_ws [default: false]
|
| 41 |
+
strip leading whitespace from each line before returning it
|
| 42 |
+
rstrip_ws [default: true]
|
| 43 |
+
strip trailing whitespace (including line terminator!) from
|
| 44 |
+
each line before returning it
|
| 45 |
+
skip_blanks [default: true}
|
| 46 |
+
skip lines that are empty *after* stripping comments and
|
| 47 |
+
whitespace. (If both lstrip_ws and rstrip_ws are false,
|
| 48 |
+
then some lines may consist of solely whitespace: these will
|
| 49 |
+
*not* be skipped, even if 'skip_blanks' is true.)
|
| 50 |
+
join_lines [default: false]
|
| 51 |
+
if a backslash is the last non-newline character on a line
|
| 52 |
+
after stripping comments and whitespace, join the following line
|
| 53 |
+
to it to form one "logical line"; if N consecutive lines end
|
| 54 |
+
with a backslash, then N+1 physical lines will be joined to
|
| 55 |
+
form one logical line.
|
| 56 |
+
collapse_join [default: false]
|
| 57 |
+
strip leading whitespace from lines that are joined to their
|
| 58 |
+
predecessor; only matters if (join_lines and not lstrip_ws)
|
| 59 |
+
errors [default: 'strict']
|
| 60 |
+
error handler used to decode the file content
|
| 61 |
+
|
| 62 |
+
Note that since 'rstrip_ws' can strip the trailing newline, the
|
| 63 |
+
semantics of 'readline()' must differ from those of the builtin file
|
| 64 |
+
object's 'readline()' method! In particular, 'readline()' returns
|
| 65 |
+
None for end-of-file: an empty string might just be a blank line (or
|
| 66 |
+
an all-whitespace line), if 'rstrip_ws' is true but 'skip_blanks' is
|
| 67 |
+
not."""
|
| 68 |
+
|
| 69 |
+
default_options = { 'strip_comments': 1,
|
| 70 |
+
'skip_blanks': 1,
|
| 71 |
+
'lstrip_ws': 0,
|
| 72 |
+
'rstrip_ws': 1,
|
| 73 |
+
'join_lines': 0,
|
| 74 |
+
'collapse_join': 0,
|
| 75 |
+
'errors': 'strict',
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
def __init__(self, filename=None, file=None, **options):
|
| 79 |
+
"""Construct a new TextFile object. At least one of 'filename'
|
| 80 |
+
(a string) and 'file' (a file-like object) must be supplied.
|
| 81 |
+
They keyword argument options are described above and affect
|
| 82 |
+
the values returned by 'readline()'."""
|
| 83 |
+
if filename is None and file is None:
|
| 84 |
+
raise RuntimeError("you must supply either or both of 'filename' and 'file'")
|
| 85 |
+
|
| 86 |
+
# set values for all options -- either from client option hash
|
| 87 |
+
# or fallback to default_options
|
| 88 |
+
for opt in self.default_options.keys():
|
| 89 |
+
if opt in options:
|
| 90 |
+
setattr(self, opt, options[opt])
|
| 91 |
+
else:
|
| 92 |
+
setattr(self, opt, self.default_options[opt])
|
| 93 |
+
|
| 94 |
+
# sanity check client option hash
|
| 95 |
+
for opt in options.keys():
|
| 96 |
+
if opt not in self.default_options:
|
| 97 |
+
raise KeyError("invalid TextFile option '%s'" % opt)
|
| 98 |
+
|
| 99 |
+
if file is None:
|
| 100 |
+
self.open(filename)
|
| 101 |
+
else:
|
| 102 |
+
self.filename = filename
|
| 103 |
+
self.file = file
|
| 104 |
+
self.current_line = 0 # assuming that file is at BOF!
|
| 105 |
+
|
| 106 |
+
# 'linebuf' is a stack of lines that will be emptied before we
|
| 107 |
+
# actually read from the file; it's only populated by an
|
| 108 |
+
# 'unreadline()' operation
|
| 109 |
+
self.linebuf = []
|
| 110 |
+
|
| 111 |
+
def open(self, filename):
|
| 112 |
+
"""Open a new file named 'filename'. This overrides both the
|
| 113 |
+
'filename' and 'file' arguments to the constructor."""
|
| 114 |
+
self.filename = filename
|
| 115 |
+
self.file = io.open(self.filename, 'r', errors=self.errors)
|
| 116 |
+
self.current_line = 0
|
| 117 |
+
|
| 118 |
+
def close(self):
|
| 119 |
+
"""Close the current file and forget everything we know about it
|
| 120 |
+
(filename, current line number)."""
|
| 121 |
+
file = self.file
|
| 122 |
+
self.file = None
|
| 123 |
+
self.filename = None
|
| 124 |
+
self.current_line = None
|
| 125 |
+
file.close()
|
| 126 |
+
|
| 127 |
+
def gen_error(self, msg, line=None):
|
| 128 |
+
outmsg = []
|
| 129 |
+
if line is None:
|
| 130 |
+
line = self.current_line
|
| 131 |
+
outmsg.append(self.filename + ", ")
|
| 132 |
+
if isinstance(line, (list, tuple)):
|
| 133 |
+
outmsg.append("lines %d-%d: " % tuple(line))
|
| 134 |
+
else:
|
| 135 |
+
outmsg.append("line %d: " % line)
|
| 136 |
+
outmsg.append(str(msg))
|
| 137 |
+
return "".join(outmsg)
|
| 138 |
+
|
| 139 |
+
def error(self, msg, line=None):
|
| 140 |
+
raise ValueError("error: " + self.gen_error(msg, line))
|
| 141 |
+
|
| 142 |
+
def warn(self, msg, line=None):
|
| 143 |
+
"""Print (to stderr) a warning message tied to the current logical
|
| 144 |
+
line in the current file. If the current logical line in the
|
| 145 |
+
file spans multiple physical lines, the warning refers to the
|
| 146 |
+
whole range, eg. "lines 3-5". If 'line' supplied, it overrides
|
| 147 |
+
the current line number; it may be a list or tuple to indicate a
|
| 148 |
+
range of physical lines, or an integer for a single physical
|
| 149 |
+
line."""
|
| 150 |
+
sys.stderr.write("warning: " + self.gen_error(msg, line) + "\n")
|
| 151 |
+
|
| 152 |
+
def readline(self):
|
| 153 |
+
"""Read and return a single logical line from the current file (or
|
| 154 |
+
from an internal buffer if lines have previously been "unread"
|
| 155 |
+
with 'unreadline()'). If the 'join_lines' option is true, this
|
| 156 |
+
may involve reading multiple physical lines concatenated into a
|
| 157 |
+
single string. Updates the current line number, so calling
|
| 158 |
+
'warn()' after 'readline()' emits a warning about the physical
|
| 159 |
+
line(s) just read. Returns None on end-of-file, since the empty
|
| 160 |
+
string can occur if 'rstrip_ws' is true but 'strip_blanks' is
|
| 161 |
+
not."""
|
| 162 |
+
# If any "unread" lines waiting in 'linebuf', return the top
|
| 163 |
+
# one. (We don't actually buffer read-ahead data -- lines only
|
| 164 |
+
# get put in 'linebuf' if the client explicitly does an
|
| 165 |
+
# 'unreadline()'.
|
| 166 |
+
if self.linebuf:
|
| 167 |
+
line = self.linebuf[-1]
|
| 168 |
+
del self.linebuf[-1]
|
| 169 |
+
return line
|
| 170 |
+
|
| 171 |
+
buildup_line = ''
|
| 172 |
+
|
| 173 |
+
while True:
|
| 174 |
+
# read the line, make it None if EOF
|
| 175 |
+
line = self.file.readline()
|
| 176 |
+
if line == '':
|
| 177 |
+
line = None
|
| 178 |
+
|
| 179 |
+
if self.strip_comments and line:
|
| 180 |
+
|
| 181 |
+
# Look for the first "#" in the line. If none, never
|
| 182 |
+
# mind. If we find one and it's the first character, or
|
| 183 |
+
# is not preceded by "\", then it starts a comment --
|
| 184 |
+
# strip the comment, strip whitespace before it, and
|
| 185 |
+
# carry on. Otherwise, it's just an escaped "#", so
|
| 186 |
+
# unescape it (and any other escaped "#"'s that might be
|
| 187 |
+
# lurking in there) and otherwise leave the line alone.
|
| 188 |
+
|
| 189 |
+
pos = line.find("#")
|
| 190 |
+
if pos == -1: # no "#" -- no comments
|
| 191 |
+
pass
|
| 192 |
+
|
| 193 |
+
# It's definitely a comment -- either "#" is the first
|
| 194 |
+
# character, or it's elsewhere and unescaped.
|
| 195 |
+
elif pos == 0 or line[pos-1] != "\\":
|
| 196 |
+
# Have to preserve the trailing newline, because it's
|
| 197 |
+
# the job of a later step (rstrip_ws) to remove it --
|
| 198 |
+
# and if rstrip_ws is false, we'd better preserve it!
|
| 199 |
+
# (NB. this means that if the final line is all comment
|
| 200 |
+
# and has no trailing newline, we will think that it's
|
| 201 |
+
# EOF; I think that's OK.)
|
| 202 |
+
eol = (line[-1] == '\n') and '\n' or ''
|
| 203 |
+
line = line[0:pos] + eol
|
| 204 |
+
|
| 205 |
+
# If all that's left is whitespace, then skip line
|
| 206 |
+
# *now*, before we try to join it to 'buildup_line' --
|
| 207 |
+
# that way constructs like
|
| 208 |
+
# hello \\
|
| 209 |
+
# # comment that should be ignored
|
| 210 |
+
# there
|
| 211 |
+
# result in "hello there".
|
| 212 |
+
if line.strip() == "":
|
| 213 |
+
continue
|
| 214 |
+
else: # it's an escaped "#"
|
| 215 |
+
line = line.replace("\\#", "#")
|
| 216 |
+
|
| 217 |
+
# did previous line end with a backslash? then accumulate
|
| 218 |
+
if self.join_lines and buildup_line:
|
| 219 |
+
# oops: end of file
|
| 220 |
+
if line is None:
|
| 221 |
+
self.warn("continuation line immediately precedes "
|
| 222 |
+
"end-of-file")
|
| 223 |
+
return buildup_line
|
| 224 |
+
|
| 225 |
+
if self.collapse_join:
|
| 226 |
+
line = line.lstrip()
|
| 227 |
+
line = buildup_line + line
|
| 228 |
+
|
| 229 |
+
# careful: pay attention to line number when incrementing it
|
| 230 |
+
if isinstance(self.current_line, list):
|
| 231 |
+
self.current_line[1] = self.current_line[1] + 1
|
| 232 |
+
else:
|
| 233 |
+
self.current_line = [self.current_line,
|
| 234 |
+
self.current_line + 1]
|
| 235 |
+
# just an ordinary line, read it as usual
|
| 236 |
+
else:
|
| 237 |
+
if line is None: # eof
|
| 238 |
+
return None
|
| 239 |
+
|
| 240 |
+
# still have to be careful about incrementing the line number!
|
| 241 |
+
if isinstance(self.current_line, list):
|
| 242 |
+
self.current_line = self.current_line[1] + 1
|
| 243 |
+
else:
|
| 244 |
+
self.current_line = self.current_line + 1
|
| 245 |
+
|
| 246 |
+
# strip whitespace however the client wants (leading and
|
| 247 |
+
# trailing, or one or the other, or neither)
|
| 248 |
+
if self.lstrip_ws and self.rstrip_ws:
|
| 249 |
+
line = line.strip()
|
| 250 |
+
elif self.lstrip_ws:
|
| 251 |
+
line = line.lstrip()
|
| 252 |
+
elif self.rstrip_ws:
|
| 253 |
+
line = line.rstrip()
|
| 254 |
+
|
| 255 |
+
# blank line (whether we rstrip'ed or not)? skip to next line
|
| 256 |
+
# if appropriate
|
| 257 |
+
if (line == '' or line == '\n') and self.skip_blanks:
|
| 258 |
+
continue
|
| 259 |
+
|
| 260 |
+
if self.join_lines:
|
| 261 |
+
if line[-1] == '\\':
|
| 262 |
+
buildup_line = line[:-1]
|
| 263 |
+
continue
|
| 264 |
+
|
| 265 |
+
if line[-2:] == '\\\n':
|
| 266 |
+
buildup_line = line[0:-2] + '\n'
|
| 267 |
+
continue
|
| 268 |
+
|
| 269 |
+
# well, I guess there's some actual content there: return it
|
| 270 |
+
return line
|
| 271 |
+
|
| 272 |
+
def readlines(self):
|
| 273 |
+
"""Read and return the list of all logical lines remaining in the
|
| 274 |
+
current file."""
|
| 275 |
+
lines = []
|
| 276 |
+
while True:
|
| 277 |
+
line = self.readline()
|
| 278 |
+
if line is None:
|
| 279 |
+
return lines
|
| 280 |
+
lines.append(line)
|
| 281 |
+
|
| 282 |
+
def unreadline(self, line):
|
| 283 |
+
"""Push 'line' (a string) onto an internal buffer that will be
|
| 284 |
+
checked by future 'readline()' calls. Handy for implementing
|
| 285 |
+
a parser with line-at-a-time lookahead."""
|
| 286 |
+
self.linebuf.append(line)
|
data/conda_envs/evalclaw/lib/python3.11/distutils/unixccompiler.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.unixccompiler
|
| 2 |
+
|
| 3 |
+
Contains the UnixCCompiler class, a subclass of CCompiler that handles
|
| 4 |
+
the "typical" Unix-style command-line C compiler:
|
| 5 |
+
* macros defined with -Dname[=value]
|
| 6 |
+
* macros undefined with -Uname
|
| 7 |
+
* include search directories specified with -Idir
|
| 8 |
+
* libraries specified with -lllib
|
| 9 |
+
* library search directories specified with -Ldir
|
| 10 |
+
* compile handled by 'cc' (or similar) executable with -c option:
|
| 11 |
+
compiles .c to .o
|
| 12 |
+
* link static library handled by 'ar' command (possibly with 'ranlib')
|
| 13 |
+
* link shared library handled by 'cc -shared'
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
import os, sys, re
|
| 17 |
+
|
| 18 |
+
from distutils import sysconfig
|
| 19 |
+
from distutils.dep_util import newer
|
| 20 |
+
from distutils.ccompiler import \
|
| 21 |
+
CCompiler, gen_preprocess_options, gen_lib_options
|
| 22 |
+
from distutils.errors import \
|
| 23 |
+
DistutilsExecError, CompileError, LibError, LinkError
|
| 24 |
+
from distutils import log
|
| 25 |
+
|
| 26 |
+
if sys.platform == 'darwin':
|
| 27 |
+
import _osx_support
|
| 28 |
+
|
| 29 |
+
# XXX Things not currently handled:
|
| 30 |
+
# * optimization/debug/warning flags; we just use whatever's in Python's
|
| 31 |
+
# Makefile and live with it. Is this adequate? If not, we might
|
| 32 |
+
# have to have a bunch of subclasses GNUCCompiler, SGICCompiler,
|
| 33 |
+
# SunCCompiler, and I suspect down that road lies madness.
|
| 34 |
+
# * even if we don't know a warning flag from an optimization flag,
|
| 35 |
+
# we need some way for outsiders to feed preprocessor/compiler/linker
|
| 36 |
+
# flags in to us -- eg. a sysadmin might want to mandate certain flags
|
| 37 |
+
# via a site config file, or a user might want to set something for
|
| 38 |
+
# compiling this module distribution only via the setup.py command
|
| 39 |
+
# line, whatever. As long as these options come from something on the
|
| 40 |
+
# current system, they can be as system-dependent as they like, and we
|
| 41 |
+
# should just happily stuff them into the preprocessor/compiler/linker
|
| 42 |
+
# options and carry on.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class UnixCCompiler(CCompiler):
|
| 46 |
+
|
| 47 |
+
compiler_type = 'unix'
|
| 48 |
+
|
| 49 |
+
# These are used by CCompiler in two places: the constructor sets
|
| 50 |
+
# instance attributes 'preprocessor', 'compiler', etc. from them, and
|
| 51 |
+
# 'set_executable()' allows any of these to be set. The defaults here
|
| 52 |
+
# are pretty generic; they will probably have to be set by an outsider
|
| 53 |
+
# (eg. using information discovered by the sysconfig about building
|
| 54 |
+
# Python extensions).
|
| 55 |
+
executables = {'preprocessor' : None,
|
| 56 |
+
'compiler' : ["cc"],
|
| 57 |
+
'compiler_so' : ["cc"],
|
| 58 |
+
'compiler_cxx' : ["cc"],
|
| 59 |
+
'linker_so' : ["cc", "-shared"],
|
| 60 |
+
'linker_exe' : ["cc"],
|
| 61 |
+
'archiver' : ["ar", "-cr"],
|
| 62 |
+
'ranlib' : None,
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
if sys.platform[:6] == "darwin":
|
| 66 |
+
executables['ranlib'] = ["ranlib"]
|
| 67 |
+
|
| 68 |
+
# Needed for the filename generation methods provided by the base
|
| 69 |
+
# class, CCompiler. NB. whoever instantiates/uses a particular
|
| 70 |
+
# UnixCCompiler instance should set 'shared_lib_ext' -- we set a
|
| 71 |
+
# reasonable common default here, but it's not necessarily used on all
|
| 72 |
+
# Unices!
|
| 73 |
+
|
| 74 |
+
src_extensions = [".c",".C",".cc",".cxx",".cpp",".m"]
|
| 75 |
+
obj_extension = ".o"
|
| 76 |
+
static_lib_extension = ".a"
|
| 77 |
+
shared_lib_extension = ".so"
|
| 78 |
+
dylib_lib_extension = ".dylib"
|
| 79 |
+
xcode_stub_lib_extension = ".tbd"
|
| 80 |
+
static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
|
| 81 |
+
xcode_stub_lib_format = dylib_lib_format
|
| 82 |
+
if sys.platform == "cygwin":
|
| 83 |
+
exe_extension = ".exe"
|
| 84 |
+
|
| 85 |
+
def preprocess(self, source, output_file=None, macros=None,
|
| 86 |
+
include_dirs=None, extra_preargs=None, extra_postargs=None):
|
| 87 |
+
fixed_args = self._fix_compile_args(None, macros, include_dirs)
|
| 88 |
+
ignore, macros, include_dirs = fixed_args
|
| 89 |
+
pp_opts = gen_preprocess_options(macros, include_dirs)
|
| 90 |
+
pp_args = self.preprocessor + pp_opts
|
| 91 |
+
if output_file:
|
| 92 |
+
pp_args.extend(['-o', output_file])
|
| 93 |
+
if extra_preargs:
|
| 94 |
+
pp_args[:0] = extra_preargs
|
| 95 |
+
if extra_postargs:
|
| 96 |
+
pp_args.extend(extra_postargs)
|
| 97 |
+
pp_args.append(source)
|
| 98 |
+
|
| 99 |
+
# We need to preprocess: either we're being forced to, or we're
|
| 100 |
+
# generating output to stdout, or there's a target output file and
|
| 101 |
+
# the source file is newer than the target (or the target doesn't
|
| 102 |
+
# exist).
|
| 103 |
+
if self.force or output_file is None or newer(source, output_file):
|
| 104 |
+
if output_file:
|
| 105 |
+
self.mkpath(os.path.dirname(output_file))
|
| 106 |
+
try:
|
| 107 |
+
self.spawn(pp_args)
|
| 108 |
+
except DistutilsExecError as msg:
|
| 109 |
+
raise CompileError(msg)
|
| 110 |
+
|
| 111 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
| 112 |
+
compiler_so = self.compiler_so
|
| 113 |
+
if sys.platform == 'darwin':
|
| 114 |
+
compiler_so = _osx_support.compiler_fixup(compiler_so,
|
| 115 |
+
cc_args + extra_postargs)
|
| 116 |
+
try:
|
| 117 |
+
self.spawn(compiler_so + cc_args + [src, '-o', obj] +
|
| 118 |
+
extra_postargs)
|
| 119 |
+
except DistutilsExecError as msg:
|
| 120 |
+
raise CompileError(msg)
|
| 121 |
+
|
| 122 |
+
def create_static_lib(self, objects, output_libname,
|
| 123 |
+
output_dir=None, debug=0, target_lang=None):
|
| 124 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
| 125 |
+
|
| 126 |
+
output_filename = \
|
| 127 |
+
self.library_filename(output_libname, output_dir=output_dir)
|
| 128 |
+
|
| 129 |
+
if self._need_link(objects, output_filename):
|
| 130 |
+
self.mkpath(os.path.dirname(output_filename))
|
| 131 |
+
self.spawn(self.archiver +
|
| 132 |
+
[output_filename] +
|
| 133 |
+
objects + self.objects)
|
| 134 |
+
|
| 135 |
+
# Not many Unices required ranlib anymore -- SunOS 4.x is, I
|
| 136 |
+
# think the only major Unix that does. Maybe we need some
|
| 137 |
+
# platform intelligence here to skip ranlib if it's not
|
| 138 |
+
# needed -- or maybe Python's configure script took care of
|
| 139 |
+
# it for us, hence the check for leading colon.
|
| 140 |
+
if self.ranlib:
|
| 141 |
+
try:
|
| 142 |
+
self.spawn(self.ranlib + [output_filename])
|
| 143 |
+
except DistutilsExecError as msg:
|
| 144 |
+
raise LibError(msg)
|
| 145 |
+
else:
|
| 146 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 147 |
+
|
| 148 |
+
def link(self, target_desc, objects,
|
| 149 |
+
output_filename, output_dir=None, libraries=None,
|
| 150 |
+
library_dirs=None, runtime_library_dirs=None,
|
| 151 |
+
export_symbols=None, debug=0, extra_preargs=None,
|
| 152 |
+
extra_postargs=None, build_temp=None, target_lang=None):
|
| 153 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
| 154 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs,
|
| 155 |
+
runtime_library_dirs)
|
| 156 |
+
libraries, library_dirs, runtime_library_dirs = fixed_args
|
| 157 |
+
|
| 158 |
+
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
|
| 159 |
+
libraries)
|
| 160 |
+
if not isinstance(output_dir, (str, type(None))):
|
| 161 |
+
raise TypeError("'output_dir' must be a string or None")
|
| 162 |
+
if output_dir is not None:
|
| 163 |
+
output_filename = os.path.join(output_dir, output_filename)
|
| 164 |
+
|
| 165 |
+
if self._need_link(objects, output_filename):
|
| 166 |
+
ld_args = (objects + self.objects +
|
| 167 |
+
lib_opts + ['-o', output_filename])
|
| 168 |
+
if debug:
|
| 169 |
+
ld_args[:0] = ['-g']
|
| 170 |
+
if extra_preargs:
|
| 171 |
+
ld_args[:0] = extra_preargs
|
| 172 |
+
if extra_postargs:
|
| 173 |
+
ld_args.extend(extra_postargs)
|
| 174 |
+
self.mkpath(os.path.dirname(output_filename))
|
| 175 |
+
try:
|
| 176 |
+
if target_desc == CCompiler.EXECUTABLE:
|
| 177 |
+
linker = self.linker_exe[:]
|
| 178 |
+
else:
|
| 179 |
+
linker = self.linker_so[:]
|
| 180 |
+
if target_lang == "c++" and self.compiler_cxx:
|
| 181 |
+
# skip over environment variable settings if /usr/bin/env
|
| 182 |
+
# is used to set up the linker's environment.
|
| 183 |
+
# This is needed on OSX. Note: this assumes that the
|
| 184 |
+
# normal and C++ compiler have the same environment
|
| 185 |
+
# settings.
|
| 186 |
+
i = 0
|
| 187 |
+
if os.path.basename(linker[0]) == "env":
|
| 188 |
+
i = 1
|
| 189 |
+
while '=' in linker[i]:
|
| 190 |
+
i += 1
|
| 191 |
+
|
| 192 |
+
if os.path.basename(linker[i]) == 'ld_so_aix':
|
| 193 |
+
# AIX platforms prefix the compiler with the ld_so_aix
|
| 194 |
+
# script, so we need to adjust our linker index
|
| 195 |
+
offset = 1
|
| 196 |
+
else:
|
| 197 |
+
offset = 0
|
| 198 |
+
|
| 199 |
+
linker[i+offset] = self.compiler_cxx[i]
|
| 200 |
+
|
| 201 |
+
if sys.platform == 'darwin':
|
| 202 |
+
linker = _osx_support.compiler_fixup(linker, ld_args)
|
| 203 |
+
|
| 204 |
+
self.spawn(linker + ld_args)
|
| 205 |
+
except DistutilsExecError as msg:
|
| 206 |
+
raise LinkError(msg)
|
| 207 |
+
else:
|
| 208 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 209 |
+
|
| 210 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 211 |
+
# These are all used by the 'gen_lib_options() function, in
|
| 212 |
+
# ccompiler.py.
|
| 213 |
+
|
| 214 |
+
def library_dir_option(self, dir):
|
| 215 |
+
return "-L" + dir
|
| 216 |
+
|
| 217 |
+
def _is_gcc(self, compiler_name):
|
| 218 |
+
# clang uses same syntax for rpath as gcc
|
| 219 |
+
return any(name in compiler_name for name in ("gcc", "g++", "clang"))
|
| 220 |
+
|
| 221 |
+
def runtime_library_dir_option(self, dir):
|
| 222 |
+
# XXX Hackish, at the very least. See Python bug #445902:
|
| 223 |
+
# http://sourceforge.net/tracker/index.php
|
| 224 |
+
# ?func=detail&aid=445902&group_id=5470&atid=105470
|
| 225 |
+
# Linkers on different platforms need different options to
|
| 226 |
+
# specify that directories need to be added to the list of
|
| 227 |
+
# directories searched for dependencies when a dynamic library
|
| 228 |
+
# is sought. GCC on GNU systems (Linux, FreeBSD, ...) has to
|
| 229 |
+
# be told to pass the -R option through to the linker, whereas
|
| 230 |
+
# other compilers and gcc on other systems just know this.
|
| 231 |
+
# Other compilers may need something slightly different. At
|
| 232 |
+
# this time, there's no way to determine this information from
|
| 233 |
+
# the configuration data stored in the Python installation, so
|
| 234 |
+
# we use this hack.
|
| 235 |
+
import shlex
|
| 236 |
+
compiler = os.path.basename(shlex.split(sysconfig.get_config_var("CC"))[0])
|
| 237 |
+
if sys.platform[:6] == "darwin":
|
| 238 |
+
# MacOSX's linker doesn't understand the -R flag at all
|
| 239 |
+
return "-L" + dir
|
| 240 |
+
elif sys.platform[:7] == "freebsd":
|
| 241 |
+
return "-Wl,-rpath=" + dir
|
| 242 |
+
elif sys.platform[:5] == "hp-ux":
|
| 243 |
+
if self._is_gcc(compiler):
|
| 244 |
+
return ["-Wl,+s", "-L" + dir]
|
| 245 |
+
return ["+s", "-L" + dir]
|
| 246 |
+
else:
|
| 247 |
+
if self._is_gcc(compiler):
|
| 248 |
+
# gcc on non-GNU systems does not need -Wl, but can
|
| 249 |
+
# use it anyway. Since distutils has always passed in
|
| 250 |
+
# -Wl whenever gcc was used in the past it is probably
|
| 251 |
+
# safest to keep doing so.
|
| 252 |
+
if sysconfig.get_config_var("GNULD") == "yes":
|
| 253 |
+
# GNU ld needs an extra option to get a RUNPATH
|
| 254 |
+
# instead of just an RPATH.
|
| 255 |
+
return "-Wl,--enable-new-dtags,-R" + dir
|
| 256 |
+
else:
|
| 257 |
+
return "-Wl,-R" + dir
|
| 258 |
+
else:
|
| 259 |
+
# No idea how --enable-new-dtags would be passed on to
|
| 260 |
+
# ld if this system was using GNU ld. Don't know if a
|
| 261 |
+
# system like this even exists.
|
| 262 |
+
return "-R" + dir
|
| 263 |
+
|
| 264 |
+
def library_option(self, lib):
|
| 265 |
+
return "-l" + lib
|
| 266 |
+
|
| 267 |
+
def find_library_file(self, dirs, lib, debug=0):
|
| 268 |
+
shared_f = self.library_filename(lib, lib_type='shared')
|
| 269 |
+
dylib_f = self.library_filename(lib, lib_type='dylib')
|
| 270 |
+
xcode_stub_f = self.library_filename(lib, lib_type='xcode_stub')
|
| 271 |
+
static_f = self.library_filename(lib, lib_type='static')
|
| 272 |
+
|
| 273 |
+
if sys.platform == 'darwin':
|
| 274 |
+
# On OSX users can specify an alternate SDK using
|
| 275 |
+
# '-isysroot', calculate the SDK root if it is specified
|
| 276 |
+
# (and use it further on)
|
| 277 |
+
#
|
| 278 |
+
# Note that, as of Xcode 7, Apple SDKs may contain textual stub
|
| 279 |
+
# libraries with .tbd extensions rather than the normal .dylib
|
| 280 |
+
# shared libraries installed in /. The Apple compiler tool
|
| 281 |
+
# chain handles this transparently but it can cause problems
|
| 282 |
+
# for programs that are being built with an SDK and searching
|
| 283 |
+
# for specific libraries. Callers of find_library_file need to
|
| 284 |
+
# keep in mind that the base filename of the returned SDK library
|
| 285 |
+
# file might have a different extension from that of the library
|
| 286 |
+
# file installed on the running system, for example:
|
| 287 |
+
# /Applications/Xcode.app/Contents/Developer/Platforms/
|
| 288 |
+
# MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
|
| 289 |
+
# usr/lib/libedit.tbd
|
| 290 |
+
# vs
|
| 291 |
+
# /usr/lib/libedit.dylib
|
| 292 |
+
cflags = sysconfig.get_config_var('CFLAGS')
|
| 293 |
+
m = re.search(r'-isysroot\s*(\S+)', cflags)
|
| 294 |
+
if m is None:
|
| 295 |
+
sysroot = _osx_support._default_sysroot(sysconfig.get_config_var('CC'))
|
| 296 |
+
else:
|
| 297 |
+
sysroot = m.group(1)
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
for dir in dirs:
|
| 302 |
+
shared = os.path.join(dir, shared_f)
|
| 303 |
+
dylib = os.path.join(dir, dylib_f)
|
| 304 |
+
static = os.path.join(dir, static_f)
|
| 305 |
+
xcode_stub = os.path.join(dir, xcode_stub_f)
|
| 306 |
+
|
| 307 |
+
if sys.platform == 'darwin' and (
|
| 308 |
+
dir.startswith('/System/') or (
|
| 309 |
+
dir.startswith('/usr/') and not dir.startswith('/usr/local/'))):
|
| 310 |
+
|
| 311 |
+
shared = os.path.join(sysroot, dir[1:], shared_f)
|
| 312 |
+
dylib = os.path.join(sysroot, dir[1:], dylib_f)
|
| 313 |
+
static = os.path.join(sysroot, dir[1:], static_f)
|
| 314 |
+
xcode_stub = os.path.join(sysroot, dir[1:], xcode_stub_f)
|
| 315 |
+
|
| 316 |
+
# We're second-guessing the linker here, with not much hard
|
| 317 |
+
# data to go on: GCC seems to prefer the shared library, so I'm
|
| 318 |
+
# assuming that *all* Unix C compilers do. And of course I'm
|
| 319 |
+
# ignoring even GCC's "-static" option. So sue me.
|
| 320 |
+
if os.path.exists(dylib):
|
| 321 |
+
return dylib
|
| 322 |
+
elif os.path.exists(xcode_stub):
|
| 323 |
+
return xcode_stub
|
| 324 |
+
elif os.path.exists(shared):
|
| 325 |
+
return shared
|
| 326 |
+
elif os.path.exists(static):
|
| 327 |
+
return static
|
| 328 |
+
|
| 329 |
+
# Oops, didn't find it in *any* of 'dirs'
|
| 330 |
+
return None
|
data/conda_envs/evalclaw/lib/python3.11/distutils/util.py
ADDED
|
@@ -0,0 +1,562 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 8 |
+
import re
|
| 9 |
+
import importlib.util
|
| 10 |
+
import string
|
| 11 |
+
import sys
|
| 12 |
+
import distutils
|
| 13 |
+
from distutils.errors import DistutilsPlatformError
|
| 14 |
+
from distutils.dep_util import newer
|
| 15 |
+
from distutils.spawn import spawn
|
| 16 |
+
from distutils import log
|
| 17 |
+
from distutils.errors import DistutilsByteCompileError
|
| 18 |
+
|
| 19 |
+
def get_host_platform():
|
| 20 |
+
"""Return a string that identifies the current platform. This is used mainly to
|
| 21 |
+
distinguish platform-specific build directories and platform-specific built
|
| 22 |
+
distributions. Typically includes the OS name and version and the
|
| 23 |
+
architecture (as supplied by 'os.uname()'), although the exact information
|
| 24 |
+
included depends on the OS; eg. on Linux, the kernel version isn't
|
| 25 |
+
particularly important.
|
| 26 |
+
|
| 27 |
+
Examples of returned values:
|
| 28 |
+
linux-i586
|
| 29 |
+
linux-alpha (?)
|
| 30 |
+
solaris-2.6-sun4u
|
| 31 |
+
|
| 32 |
+
Windows will return one of:
|
| 33 |
+
win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
|
| 34 |
+
win32 (all others - specifically, sys.platform is returned)
|
| 35 |
+
|
| 36 |
+
For other non-POSIX platforms, currently just returns 'sys.platform'.
|
| 37 |
+
|
| 38 |
+
"""
|
| 39 |
+
if os.name == 'nt':
|
| 40 |
+
if 'amd64' in sys.version.lower():
|
| 41 |
+
return 'win-amd64'
|
| 42 |
+
if '(arm)' in sys.version.lower():
|
| 43 |
+
return 'win-arm32'
|
| 44 |
+
if '(arm64)' in sys.version.lower():
|
| 45 |
+
return 'win-arm64'
|
| 46 |
+
return sys.platform
|
| 47 |
+
|
| 48 |
+
# Set for cross builds explicitly
|
| 49 |
+
if "_PYTHON_HOST_PLATFORM" in os.environ:
|
| 50 |
+
return os.environ["_PYTHON_HOST_PLATFORM"]
|
| 51 |
+
|
| 52 |
+
if os.name != "posix" or not hasattr(os, 'uname'):
|
| 53 |
+
# XXX what about the architecture? NT is Intel or Alpha,
|
| 54 |
+
# Mac OS is M68k or PPC, etc.
|
| 55 |
+
return sys.platform
|
| 56 |
+
|
| 57 |
+
# Try to distinguish various flavours of Unix
|
| 58 |
+
|
| 59 |
+
(osname, host, release, version, machine) = os.uname()
|
| 60 |
+
|
| 61 |
+
# Convert the OS name to lowercase, remove '/' characters, and translate
|
| 62 |
+
# spaces (for "Power Macintosh")
|
| 63 |
+
osname = osname.lower().replace('/', '')
|
| 64 |
+
machine = machine.replace(' ', '_')
|
| 65 |
+
machine = machine.replace('/', '-')
|
| 66 |
+
|
| 67 |
+
if osname[:5] == "linux":
|
| 68 |
+
# At least on Linux/Intel, 'machine' is the processor --
|
| 69 |
+
# i386, etc.
|
| 70 |
+
# XXX what about Alpha, SPARC, etc?
|
| 71 |
+
return "%s-%s" % (osname, machine)
|
| 72 |
+
elif osname[:5] == "sunos":
|
| 73 |
+
if release[0] >= "5": # SunOS 5 == Solaris 2
|
| 74 |
+
osname = "solaris"
|
| 75 |
+
release = "%d.%s" % (int(release[0]) - 3, release[2:])
|
| 76 |
+
# We can't use "platform.architecture()[0]" because a
|
| 77 |
+
# bootstrap problem. We use a dict to get an error
|
| 78 |
+
# if some suspicious happens.
|
| 79 |
+
bitness = {2147483647:"32bit", 9223372036854775807:"64bit"}
|
| 80 |
+
machine += ".%s" % bitness[sys.maxsize]
|
| 81 |
+
# fall through to standard osname-release-machine representation
|
| 82 |
+
elif osname[:3] == "aix":
|
| 83 |
+
from _aix_support import aix_platform
|
| 84 |
+
return aix_platform()
|
| 85 |
+
elif osname[:6] == "cygwin":
|
| 86 |
+
osname = "cygwin"
|
| 87 |
+
rel_re = re.compile (r'[\d.]+', re.ASCII)
|
| 88 |
+
m = rel_re.match(release)
|
| 89 |
+
if m:
|
| 90 |
+
release = m.group()
|
| 91 |
+
elif osname[:6] == "darwin":
|
| 92 |
+
import _osx_support, distutils.sysconfig
|
| 93 |
+
osname, release, machine = _osx_support.get_platform_osx(
|
| 94 |
+
distutils.sysconfig.get_config_vars(),
|
| 95 |
+
osname, release, machine)
|
| 96 |
+
|
| 97 |
+
return "%s-%s-%s" % (osname, release, machine)
|
| 98 |
+
|
| 99 |
+
def get_platform():
|
| 100 |
+
if os.name == 'nt':
|
| 101 |
+
TARGET_TO_PLAT = {
|
| 102 |
+
'x86' : 'win32',
|
| 103 |
+
'x64' : 'win-amd64',
|
| 104 |
+
'arm' : 'win-arm32',
|
| 105 |
+
}
|
| 106 |
+
return TARGET_TO_PLAT.get(os.environ.get('VSCMD_ARG_TGT_ARCH')) or get_host_platform()
|
| 107 |
+
else:
|
| 108 |
+
return get_host_platform()
|
| 109 |
+
|
| 110 |
+
def convert_path (pathname):
|
| 111 |
+
"""Return 'pathname' as a name that will work on the native filesystem,
|
| 112 |
+
i.e. split it on '/' and put it back together again using the current
|
| 113 |
+
directory separator. Needed because filenames in the setup script are
|
| 114 |
+
always supplied in Unix style, and have to be converted to the local
|
| 115 |
+
convention before we can actually use them in the filesystem. Raises
|
| 116 |
+
ValueError on non-Unix-ish systems if 'pathname' either starts or
|
| 117 |
+
ends with a slash.
|
| 118 |
+
"""
|
| 119 |
+
if os.sep == '/':
|
| 120 |
+
return pathname
|
| 121 |
+
if not pathname:
|
| 122 |
+
return pathname
|
| 123 |
+
if pathname[0] == '/':
|
| 124 |
+
raise ValueError("path '%s' cannot be absolute" % pathname)
|
| 125 |
+
if pathname[-1] == '/':
|
| 126 |
+
raise ValueError("path '%s' cannot end with '/'" % pathname)
|
| 127 |
+
|
| 128 |
+
paths = pathname.split('/')
|
| 129 |
+
while '.' in paths:
|
| 130 |
+
paths.remove('.')
|
| 131 |
+
if not paths:
|
| 132 |
+
return os.curdir
|
| 133 |
+
return os.path.join(*paths)
|
| 134 |
+
|
| 135 |
+
# convert_path ()
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def change_root (new_root, pathname):
|
| 139 |
+
"""Return 'pathname' with 'new_root' prepended. If 'pathname' is
|
| 140 |
+
relative, this is equivalent to "os.path.join(new_root,pathname)".
|
| 141 |
+
Otherwise, it requires making 'pathname' relative and then joining the
|
| 142 |
+
two, which is tricky on DOS/Windows and Mac OS.
|
| 143 |
+
"""
|
| 144 |
+
if os.name == 'posix':
|
| 145 |
+
if not os.path.isabs(pathname):
|
| 146 |
+
return os.path.join(new_root, pathname)
|
| 147 |
+
else:
|
| 148 |
+
return os.path.join(new_root, pathname[1:])
|
| 149 |
+
|
| 150 |
+
elif os.name == 'nt':
|
| 151 |
+
(drive, path) = os.path.splitdrive(pathname)
|
| 152 |
+
if path[0] == '\\':
|
| 153 |
+
path = path[1:]
|
| 154 |
+
return os.path.join(new_root, path)
|
| 155 |
+
|
| 156 |
+
else:
|
| 157 |
+
raise DistutilsPlatformError("nothing known about platform '%s'" % os.name)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
_environ_checked = 0
|
| 161 |
+
def check_environ ():
|
| 162 |
+
"""Ensure that 'os.environ' has all the environment variables we
|
| 163 |
+
guarantee that users can use in config files, command-line options,
|
| 164 |
+
etc. Currently this includes:
|
| 165 |
+
HOME - user's home directory (Unix only)
|
| 166 |
+
PLAT - description of the current platform, including hardware
|
| 167 |
+
and OS (see 'get_platform()')
|
| 168 |
+
"""
|
| 169 |
+
global _environ_checked
|
| 170 |
+
if _environ_checked:
|
| 171 |
+
return
|
| 172 |
+
|
| 173 |
+
if os.name == 'posix' and 'HOME' not in os.environ:
|
| 174 |
+
try:
|
| 175 |
+
import pwd
|
| 176 |
+
os.environ['HOME'] = pwd.getpwuid(os.getuid())[5]
|
| 177 |
+
except (ImportError, KeyError):
|
| 178 |
+
# bpo-10496: if the current user identifier doesn't exist in the
|
| 179 |
+
# password database, do nothing
|
| 180 |
+
pass
|
| 181 |
+
|
| 182 |
+
if 'PLAT' not in os.environ:
|
| 183 |
+
os.environ['PLAT'] = get_platform()
|
| 184 |
+
|
| 185 |
+
_environ_checked = 1
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def subst_vars (s, local_vars):
|
| 189 |
+
"""Perform shell/Perl-style variable substitution on 'string'. Every
|
| 190 |
+
occurrence of '$' followed by a name is considered a variable, and
|
| 191 |
+
variable is substituted by the value found in the 'local_vars'
|
| 192 |
+
dictionary, or in 'os.environ' if it's not in 'local_vars'.
|
| 193 |
+
'os.environ' is first checked/augmented to guarantee that it contains
|
| 194 |
+
certain values: see 'check_environ()'. Raise ValueError for any
|
| 195 |
+
variables not found in either 'local_vars' or 'os.environ'.
|
| 196 |
+
"""
|
| 197 |
+
check_environ()
|
| 198 |
+
def _subst (match, local_vars=local_vars):
|
| 199 |
+
var_name = match.group(1)
|
| 200 |
+
if var_name in local_vars:
|
| 201 |
+
return str(local_vars[var_name])
|
| 202 |
+
else:
|
| 203 |
+
return os.environ[var_name]
|
| 204 |
+
|
| 205 |
+
try:
|
| 206 |
+
return re.sub(r'\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, s)
|
| 207 |
+
except KeyError as var:
|
| 208 |
+
raise ValueError("invalid variable '$%s'" % var)
|
| 209 |
+
|
| 210 |
+
# subst_vars ()
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def grok_environment_error (exc, prefix="error: "):
|
| 214 |
+
# Function kept for backward compatibility.
|
| 215 |
+
# Used to try clever things with EnvironmentErrors,
|
| 216 |
+
# but nowadays str(exception) produces good messages.
|
| 217 |
+
return prefix + str(exc)
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
# Needed by 'split_quoted()'
|
| 221 |
+
_wordchars_re = _squote_re = _dquote_re = None
|
| 222 |
+
def _init_regex():
|
| 223 |
+
global _wordchars_re, _squote_re, _dquote_re
|
| 224 |
+
_wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace)
|
| 225 |
+
_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
|
| 226 |
+
_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
|
| 227 |
+
|
| 228 |
+
def split_quoted (s):
|
| 229 |
+
"""Split a string up according to Unix shell-like rules for quotes and
|
| 230 |
+
backslashes. In short: words are delimited by spaces, as long as those
|
| 231 |
+
spaces are not escaped by a backslash, or inside a quoted string.
|
| 232 |
+
Single and double quotes are equivalent, and the quote characters can
|
| 233 |
+
be backslash-escaped. The backslash is stripped from any two-character
|
| 234 |
+
escape sequence, leaving only the escaped character. The quote
|
| 235 |
+
characters are stripped from any quoted string. Returns a list of
|
| 236 |
+
words.
|
| 237 |
+
"""
|
| 238 |
+
|
| 239 |
+
# This is a nice algorithm for splitting up a single string, since it
|
| 240 |
+
# doesn't require character-by-character examination. It was a little
|
| 241 |
+
# bit of a brain-bender to get it working right, though...
|
| 242 |
+
if _wordchars_re is None: _init_regex()
|
| 243 |
+
|
| 244 |
+
s = s.strip()
|
| 245 |
+
words = []
|
| 246 |
+
pos = 0
|
| 247 |
+
|
| 248 |
+
while s:
|
| 249 |
+
m = _wordchars_re.match(s, pos)
|
| 250 |
+
end = m.end()
|
| 251 |
+
if end == len(s):
|
| 252 |
+
words.append(s[:end])
|
| 253 |
+
break
|
| 254 |
+
|
| 255 |
+
if s[end] in string.whitespace: # unescaped, unquoted whitespace: now
|
| 256 |
+
words.append(s[:end]) # we definitely have a word delimiter
|
| 257 |
+
s = s[end:].lstrip()
|
| 258 |
+
pos = 0
|
| 259 |
+
|
| 260 |
+
elif s[end] == '\\': # preserve whatever is being escaped;
|
| 261 |
+
# will become part of the current word
|
| 262 |
+
s = s[:end] + s[end+1:]
|
| 263 |
+
pos = end+1
|
| 264 |
+
|
| 265 |
+
else:
|
| 266 |
+
if s[end] == "'": # slurp singly-quoted string
|
| 267 |
+
m = _squote_re.match(s, end)
|
| 268 |
+
elif s[end] == '"': # slurp doubly-quoted string
|
| 269 |
+
m = _dquote_re.match(s, end)
|
| 270 |
+
else:
|
| 271 |
+
raise RuntimeError("this can't happen (bad char '%c')" % s[end])
|
| 272 |
+
|
| 273 |
+
if m is None:
|
| 274 |
+
raise ValueError("bad string (mismatched %s quotes?)" % s[end])
|
| 275 |
+
|
| 276 |
+
(beg, end) = m.span()
|
| 277 |
+
s = s[:beg] + s[beg+1:end-1] + s[end:]
|
| 278 |
+
pos = m.end() - 2
|
| 279 |
+
|
| 280 |
+
if pos >= len(s):
|
| 281 |
+
words.append(s)
|
| 282 |
+
break
|
| 283 |
+
|
| 284 |
+
return words
|
| 285 |
+
|
| 286 |
+
# split_quoted ()
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
def execute (func, args, msg=None, verbose=0, dry_run=0):
|
| 290 |
+
"""Perform some action that affects the outside world (eg. by
|
| 291 |
+
writing to the filesystem). Such actions are special because they
|
| 292 |
+
are disabled by the 'dry_run' flag. This method takes care of all
|
| 293 |
+
that bureaucracy for you; all you have to do is supply the
|
| 294 |
+
function to call and an argument tuple for it (to embody the
|
| 295 |
+
"external action" being performed), and an optional message to
|
| 296 |
+
print.
|
| 297 |
+
"""
|
| 298 |
+
if msg is None:
|
| 299 |
+
msg = "%s%r" % (func.__name__, args)
|
| 300 |
+
if msg[-2:] == ',)': # correct for singleton tuple
|
| 301 |
+
msg = msg[0:-2] + ')'
|
| 302 |
+
|
| 303 |
+
log.info(msg)
|
| 304 |
+
if not dry_run:
|
| 305 |
+
func(*args)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def strtobool (val):
|
| 309 |
+
"""Convert a string representation of truth to true (1) or false (0).
|
| 310 |
+
|
| 311 |
+
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
|
| 312 |
+
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
|
| 313 |
+
'val' is anything else.
|
| 314 |
+
"""
|
| 315 |
+
val = val.lower()
|
| 316 |
+
if val in ('y', 'yes', 't', 'true', 'on', '1'):
|
| 317 |
+
return 1
|
| 318 |
+
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
|
| 319 |
+
return 0
|
| 320 |
+
else:
|
| 321 |
+
raise ValueError("invalid truth value %r" % (val,))
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
def byte_compile (py_files,
|
| 325 |
+
optimize=0, force=0,
|
| 326 |
+
prefix=None, base_dir=None,
|
| 327 |
+
verbose=1, dry_run=0,
|
| 328 |
+
direct=None):
|
| 329 |
+
"""Byte-compile a collection of Python source files to .pyc
|
| 330 |
+
files in a __pycache__ subdirectory. 'py_files' is a list
|
| 331 |
+
of files to compile; any files that don't end in ".py" are silently
|
| 332 |
+
skipped. 'optimize' must be one of the following:
|
| 333 |
+
0 - don't optimize
|
| 334 |
+
1 - normal optimization (like "python -O")
|
| 335 |
+
2 - extra optimization (like "python -OO")
|
| 336 |
+
If 'force' is true, all files are recompiled regardless of
|
| 337 |
+
timestamps.
|
| 338 |
+
|
| 339 |
+
The source filename encoded in each bytecode file defaults to the
|
| 340 |
+
filenames listed in 'py_files'; you can modify these with 'prefix' and
|
| 341 |
+
'basedir'. 'prefix' is a string that will be stripped off of each
|
| 342 |
+
source filename, and 'base_dir' is a directory name that will be
|
| 343 |
+
prepended (after 'prefix' is stripped). You can supply either or both
|
| 344 |
+
(or neither) of 'prefix' and 'base_dir', as you wish.
|
| 345 |
+
|
| 346 |
+
If 'dry_run' is true, doesn't actually do anything that would
|
| 347 |
+
affect the filesystem.
|
| 348 |
+
|
| 349 |
+
Byte-compilation is either done directly in this interpreter process
|
| 350 |
+
with the standard py_compile module, or indirectly by writing a
|
| 351 |
+
temporary script and executing it. Normally, you should let
|
| 352 |
+
'byte_compile()' figure out to use direct compilation or not (see
|
| 353 |
+
the source for details). The 'direct' flag is used by the script
|
| 354 |
+
generated in indirect mode; unless you know what you're doing, leave
|
| 355 |
+
it set to None.
|
| 356 |
+
"""
|
| 357 |
+
|
| 358 |
+
# Late import to fix a bootstrap issue: _posixsubprocess is built by
|
| 359 |
+
# setup.py, but setup.py uses distutils.
|
| 360 |
+
import subprocess
|
| 361 |
+
|
| 362 |
+
# nothing is done if sys.dont_write_bytecode is True
|
| 363 |
+
if sys.dont_write_bytecode:
|
| 364 |
+
raise DistutilsByteCompileError('byte-compiling is disabled.')
|
| 365 |
+
|
| 366 |
+
# First, if the caller didn't force us into direct or indirect mode,
|
| 367 |
+
# figure out which mode we should be in. We take a conservative
|
| 368 |
+
# approach: choose direct mode *only* if the current interpreter is
|
| 369 |
+
# in debug mode and optimize is 0. If we're not in debug mode (-O
|
| 370 |
+
# or -OO), we don't know which level of optimization this
|
| 371 |
+
# interpreter is running with, so we can't do direct
|
| 372 |
+
# byte-compilation and be certain that it's the right thing. Thus,
|
| 373 |
+
# always compile indirectly if the current interpreter is in either
|
| 374 |
+
# optimize mode, or if either optimization level was requested by
|
| 375 |
+
# the caller.
|
| 376 |
+
if direct is None:
|
| 377 |
+
direct = (__debug__ and optimize == 0)
|
| 378 |
+
|
| 379 |
+
# "Indirect" byte-compilation: write a temporary script and then
|
| 380 |
+
# run it with the appropriate flags.
|
| 381 |
+
if not direct:
|
| 382 |
+
try:
|
| 383 |
+
from tempfile import mkstemp
|
| 384 |
+
(script_fd, script_name) = mkstemp(".py")
|
| 385 |
+
except ImportError:
|
| 386 |
+
from tempfile import mktemp
|
| 387 |
+
(script_fd, script_name) = None, mktemp(".py")
|
| 388 |
+
log.info("writing byte-compilation script '%s'", script_name)
|
| 389 |
+
if not dry_run:
|
| 390 |
+
if script_fd is not None:
|
| 391 |
+
script = os.fdopen(script_fd, "w")
|
| 392 |
+
else:
|
| 393 |
+
script = open(script_name, "w")
|
| 394 |
+
|
| 395 |
+
with script:
|
| 396 |
+
script.write("""\
|
| 397 |
+
from distutils.util import byte_compile
|
| 398 |
+
files = [
|
| 399 |
+
""")
|
| 400 |
+
|
| 401 |
+
# XXX would be nice to write absolute filenames, just for
|
| 402 |
+
# safety's sake (script should be more robust in the face of
|
| 403 |
+
# chdir'ing before running it). But this requires abspath'ing
|
| 404 |
+
# 'prefix' as well, and that breaks the hack in build_lib's
|
| 405 |
+
# 'byte_compile()' method that carefully tacks on a trailing
|
| 406 |
+
# slash (os.sep really) to make sure the prefix here is "just
|
| 407 |
+
# right". This whole prefix business is rather delicate -- the
|
| 408 |
+
# problem is that it's really a directory, but I'm treating it
|
| 409 |
+
# as a dumb string, so trailing slashes and so forth matter.
|
| 410 |
+
|
| 411 |
+
#py_files = map(os.path.abspath, py_files)
|
| 412 |
+
#if prefix:
|
| 413 |
+
# prefix = os.path.abspath(prefix)
|
| 414 |
+
|
| 415 |
+
script.write(",\n".join(map(repr, py_files)) + "]\n")
|
| 416 |
+
script.write("""
|
| 417 |
+
byte_compile(files, optimize=%r, force=%r,
|
| 418 |
+
prefix=%r, base_dir=%r,
|
| 419 |
+
verbose=%r, dry_run=0,
|
| 420 |
+
direct=1)
|
| 421 |
+
""" % (optimize, force, prefix, base_dir, verbose))
|
| 422 |
+
|
| 423 |
+
msg = distutils._DEPRECATION_MESSAGE
|
| 424 |
+
cmd = [sys.executable]
|
| 425 |
+
cmd.extend(subprocess._optim_args_from_interpreter_flags())
|
| 426 |
+
cmd.append(f'-Wignore:{msg}:DeprecationWarning')
|
| 427 |
+
cmd.append(script_name)
|
| 428 |
+
spawn(cmd, dry_run=dry_run)
|
| 429 |
+
execute(os.remove, (script_name,), "removing %s" % script_name,
|
| 430 |
+
dry_run=dry_run)
|
| 431 |
+
|
| 432 |
+
# "Direct" byte-compilation: use the py_compile module to compile
|
| 433 |
+
# right here, right now. Note that the script generated in indirect
|
| 434 |
+
# mode simply calls 'byte_compile()' in direct mode, a weird sort of
|
| 435 |
+
# cross-process recursion. Hey, it works!
|
| 436 |
+
else:
|
| 437 |
+
from py_compile import compile
|
| 438 |
+
|
| 439 |
+
for file in py_files:
|
| 440 |
+
if file[-3:] != ".py":
|
| 441 |
+
# This lets us be lazy and not filter filenames in
|
| 442 |
+
# the "install_lib" command.
|
| 443 |
+
continue
|
| 444 |
+
|
| 445 |
+
# Terminology from the py_compile module:
|
| 446 |
+
# cfile - byte-compiled file
|
| 447 |
+
# dfile - purported source filename (same as 'file' by default)
|
| 448 |
+
if optimize >= 0:
|
| 449 |
+
opt = '' if optimize == 0 else optimize
|
| 450 |
+
cfile = importlib.util.cache_from_source(
|
| 451 |
+
file, optimization=opt)
|
| 452 |
+
else:
|
| 453 |
+
cfile = importlib.util.cache_from_source(file)
|
| 454 |
+
dfile = file
|
| 455 |
+
if prefix:
|
| 456 |
+
if file[:len(prefix)] != prefix:
|
| 457 |
+
raise ValueError("invalid prefix: filename %r doesn't start with %r"
|
| 458 |
+
% (file, prefix))
|
| 459 |
+
dfile = dfile[len(prefix):]
|
| 460 |
+
if base_dir:
|
| 461 |
+
dfile = os.path.join(base_dir, dfile)
|
| 462 |
+
|
| 463 |
+
cfile_base = os.path.basename(cfile)
|
| 464 |
+
if direct:
|
| 465 |
+
if force or newer(file, cfile):
|
| 466 |
+
log.info("byte-compiling %s to %s", file, cfile_base)
|
| 467 |
+
if not dry_run:
|
| 468 |
+
compile(file, cfile, dfile)
|
| 469 |
+
else:
|
| 470 |
+
log.debug("skipping byte-compilation of %s to %s",
|
| 471 |
+
file, cfile_base)
|
| 472 |
+
|
| 473 |
+
# byte_compile ()
|
| 474 |
+
|
| 475 |
+
def rfc822_escape (header):
|
| 476 |
+
"""Return a version of the string escaped for inclusion in an
|
| 477 |
+
RFC-822 header, by ensuring there are 8 spaces space after each newline.
|
| 478 |
+
"""
|
| 479 |
+
lines = header.split('\n')
|
| 480 |
+
sep = '\n' + 8 * ' '
|
| 481 |
+
return sep.join(lines)
|
| 482 |
+
|
| 483 |
+
# 2to3 support
|
| 484 |
+
|
| 485 |
+
def run_2to3(files, fixer_names=None, options=None, explicit=None):
|
| 486 |
+
"""Invoke 2to3 on a list of Python files.
|
| 487 |
+
The files should all come from the build area, as the
|
| 488 |
+
modification is done in-place. To reduce the build time,
|
| 489 |
+
only files modified since the last invocation of this
|
| 490 |
+
function should be passed in the files argument."""
|
| 491 |
+
|
| 492 |
+
if not files:
|
| 493 |
+
return
|
| 494 |
+
|
| 495 |
+
# Make this class local, to delay import of 2to3
|
| 496 |
+
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
|
| 497 |
+
class DistutilsRefactoringTool(RefactoringTool):
|
| 498 |
+
def log_error(self, msg, *args, **kw):
|
| 499 |
+
log.error(msg, *args)
|
| 500 |
+
|
| 501 |
+
def log_message(self, msg, *args):
|
| 502 |
+
log.info(msg, *args)
|
| 503 |
+
|
| 504 |
+
def log_debug(self, msg, *args):
|
| 505 |
+
log.debug(msg, *args)
|
| 506 |
+
|
| 507 |
+
if fixer_names is None:
|
| 508 |
+
fixer_names = get_fixers_from_package('lib2to3.fixes')
|
| 509 |
+
r = DistutilsRefactoringTool(fixer_names, options=options)
|
| 510 |
+
r.refactor(files, write=True)
|
| 511 |
+
|
| 512 |
+
def copydir_run_2to3(src, dest, template=None, fixer_names=None,
|
| 513 |
+
options=None, explicit=None):
|
| 514 |
+
"""Recursively copy a directory, only copying new and changed files,
|
| 515 |
+
running run_2to3 over all newly copied Python modules afterward.
|
| 516 |
+
|
| 517 |
+
If you give a template string, it's parsed like a MANIFEST.in.
|
| 518 |
+
"""
|
| 519 |
+
from distutils.dir_util import mkpath
|
| 520 |
+
from distutils.file_util import copy_file
|
| 521 |
+
from distutils.filelist import FileList
|
| 522 |
+
filelist = FileList()
|
| 523 |
+
curdir = os.getcwd()
|
| 524 |
+
os.chdir(src)
|
| 525 |
+
try:
|
| 526 |
+
filelist.findall()
|
| 527 |
+
finally:
|
| 528 |
+
os.chdir(curdir)
|
| 529 |
+
filelist.files[:] = filelist.allfiles
|
| 530 |
+
if template:
|
| 531 |
+
for line in template.splitlines():
|
| 532 |
+
line = line.strip()
|
| 533 |
+
if not line: continue
|
| 534 |
+
filelist.process_template_line(line)
|
| 535 |
+
copied = []
|
| 536 |
+
for filename in filelist.files:
|
| 537 |
+
outname = os.path.join(dest, filename)
|
| 538 |
+
mkpath(os.path.dirname(outname))
|
| 539 |
+
res = copy_file(os.path.join(src, filename), outname, update=1)
|
| 540 |
+
if res[1]: copied.append(outname)
|
| 541 |
+
run_2to3([fn for fn in copied if fn.lower().endswith('.py')],
|
| 542 |
+
fixer_names=fixer_names, options=options, explicit=explicit)
|
| 543 |
+
return copied
|
| 544 |
+
|
| 545 |
+
class Mixin2to3:
|
| 546 |
+
'''Mixin class for commands that run 2to3.
|
| 547 |
+
To configure 2to3, setup scripts may either change
|
| 548 |
+
the class variables, or inherit from individual commands
|
| 549 |
+
to override how 2to3 is invoked.'''
|
| 550 |
+
|
| 551 |
+
# provide list of fixers to run;
|
| 552 |
+
# defaults to all from lib2to3.fixers
|
| 553 |
+
fixer_names = None
|
| 554 |
+
|
| 555 |
+
# options dictionary
|
| 556 |
+
options = None
|
| 557 |
+
|
| 558 |
+
# list of fixers to invoke even though they are marked as explicit
|
| 559 |
+
explicit = None
|
| 560 |
+
|
| 561 |
+
def run_2to3(self, files):
|
| 562 |
+
return run_2to3(files, self.fixer_names, self.options, self.explicit)
|
data/conda_envs/evalclaw/lib/python3.11/distutils/version.py
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# distutils/version.py
|
| 3 |
+
#
|
| 4 |
+
# Implements multiple version numbering conventions for the
|
| 5 |
+
# Python Module Distribution Utilities.
|
| 6 |
+
#
|
| 7 |
+
# $Id$
|
| 8 |
+
#
|
| 9 |
+
|
| 10 |
+
"""Provides classes to represent module version numbers (one class for
|
| 11 |
+
each style of version numbering). There are currently two such classes
|
| 12 |
+
implemented: StrictVersion and LooseVersion.
|
| 13 |
+
|
| 14 |
+
Every version number class implements the following interface:
|
| 15 |
+
* the 'parse' method takes a string and parses it to some internal
|
| 16 |
+
representation; if the string is an invalid version number,
|
| 17 |
+
'parse' raises a ValueError exception
|
| 18 |
+
* the class constructor takes an optional string argument which,
|
| 19 |
+
if supplied, is passed to 'parse'
|
| 20 |
+
* __str__ reconstructs the string that was passed to 'parse' (or
|
| 21 |
+
an equivalent string -- ie. one that will generate an equivalent
|
| 22 |
+
version number instance)
|
| 23 |
+
* __repr__ generates Python code to recreate the version number instance
|
| 24 |
+
* _cmp compares the current instance with either another instance
|
| 25 |
+
of the same class or a string (which will be parsed to an instance
|
| 26 |
+
of the same class, thus must follow the same rules)
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
import re
|
| 30 |
+
|
| 31 |
+
class Version:
|
| 32 |
+
"""Abstract base class for version numbering classes. Just provides
|
| 33 |
+
constructor (__init__) and reproducer (__repr__), because those
|
| 34 |
+
seem to be the same for all version numbering classes; and route
|
| 35 |
+
rich comparisons to _cmp.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
def __init__ (self, vstring=None):
|
| 39 |
+
if vstring:
|
| 40 |
+
self.parse(vstring)
|
| 41 |
+
|
| 42 |
+
def __repr__ (self):
|
| 43 |
+
return "%s ('%s')" % (self.__class__.__name__, str(self))
|
| 44 |
+
|
| 45 |
+
def __eq__(self, other):
|
| 46 |
+
c = self._cmp(other)
|
| 47 |
+
if c is NotImplemented:
|
| 48 |
+
return c
|
| 49 |
+
return c == 0
|
| 50 |
+
|
| 51 |
+
def __lt__(self, other):
|
| 52 |
+
c = self._cmp(other)
|
| 53 |
+
if c is NotImplemented:
|
| 54 |
+
return c
|
| 55 |
+
return c < 0
|
| 56 |
+
|
| 57 |
+
def __le__(self, other):
|
| 58 |
+
c = self._cmp(other)
|
| 59 |
+
if c is NotImplemented:
|
| 60 |
+
return c
|
| 61 |
+
return c <= 0
|
| 62 |
+
|
| 63 |
+
def __gt__(self, other):
|
| 64 |
+
c = self._cmp(other)
|
| 65 |
+
if c is NotImplemented:
|
| 66 |
+
return c
|
| 67 |
+
return c > 0
|
| 68 |
+
|
| 69 |
+
def __ge__(self, other):
|
| 70 |
+
c = self._cmp(other)
|
| 71 |
+
if c is NotImplemented:
|
| 72 |
+
return c
|
| 73 |
+
return c >= 0
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# Interface for version-number classes -- must be implemented
|
| 77 |
+
# by the following classes (the concrete ones -- Version should
|
| 78 |
+
# be treated as an abstract class).
|
| 79 |
+
# __init__ (string) - create and take same action as 'parse'
|
| 80 |
+
# (string parameter is optional)
|
| 81 |
+
# parse (string) - convert a string representation to whatever
|
| 82 |
+
# internal representation is appropriate for
|
| 83 |
+
# this style of version numbering
|
| 84 |
+
# __str__ (self) - convert back to a string; should be very similar
|
| 85 |
+
# (if not identical to) the string supplied to parse
|
| 86 |
+
# __repr__ (self) - generate Python code to recreate
|
| 87 |
+
# the instance
|
| 88 |
+
# _cmp (self, other) - compare two version numbers ('other' may
|
| 89 |
+
# be an unparsed version string, or another
|
| 90 |
+
# instance of your version class)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class StrictVersion (Version):
|
| 94 |
+
|
| 95 |
+
"""Version numbering for anal retentives and software idealists.
|
| 96 |
+
Implements the standard interface for version number classes as
|
| 97 |
+
described above. A version number consists of two or three
|
| 98 |
+
dot-separated numeric components, with an optional "pre-release" tag
|
| 99 |
+
on the end. The pre-release tag consists of the letter 'a' or 'b'
|
| 100 |
+
followed by a number. If the numeric components of two version
|
| 101 |
+
numbers are equal, then one with a pre-release tag will always
|
| 102 |
+
be deemed earlier (lesser) than one without.
|
| 103 |
+
|
| 104 |
+
The following are valid version numbers (shown in the order that
|
| 105 |
+
would be obtained by sorting according to the supplied cmp function):
|
| 106 |
+
|
| 107 |
+
0.4 0.4.0 (these two are equivalent)
|
| 108 |
+
0.4.1
|
| 109 |
+
0.5a1
|
| 110 |
+
0.5b3
|
| 111 |
+
0.5
|
| 112 |
+
0.9.6
|
| 113 |
+
1.0
|
| 114 |
+
1.0.4a3
|
| 115 |
+
1.0.4b1
|
| 116 |
+
1.0.4
|
| 117 |
+
|
| 118 |
+
The following are examples of invalid version numbers:
|
| 119 |
+
|
| 120 |
+
1
|
| 121 |
+
2.7.2.2
|
| 122 |
+
1.3.a4
|
| 123 |
+
1.3pl1
|
| 124 |
+
1.3c4
|
| 125 |
+
|
| 126 |
+
The rationale for this version numbering system will be explained
|
| 127 |
+
in the distutils documentation.
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',
|
| 131 |
+
re.VERBOSE | re.ASCII)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def parse (self, vstring):
|
| 135 |
+
match = self.version_re.match(vstring)
|
| 136 |
+
if not match:
|
| 137 |
+
raise ValueError("invalid version number '%s'" % vstring)
|
| 138 |
+
|
| 139 |
+
(major, minor, patch, prerelease, prerelease_num) = \
|
| 140 |
+
match.group(1, 2, 4, 5, 6)
|
| 141 |
+
|
| 142 |
+
if patch:
|
| 143 |
+
self.version = tuple(map(int, [major, minor, patch]))
|
| 144 |
+
else:
|
| 145 |
+
self.version = tuple(map(int, [major, minor])) + (0,)
|
| 146 |
+
|
| 147 |
+
if prerelease:
|
| 148 |
+
self.prerelease = (prerelease[0], int(prerelease_num))
|
| 149 |
+
else:
|
| 150 |
+
self.prerelease = None
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def __str__ (self):
|
| 154 |
+
|
| 155 |
+
if self.version[2] == 0:
|
| 156 |
+
vstring = '.'.join(map(str, self.version[0:2]))
|
| 157 |
+
else:
|
| 158 |
+
vstring = '.'.join(map(str, self.version))
|
| 159 |
+
|
| 160 |
+
if self.prerelease:
|
| 161 |
+
vstring = vstring + self.prerelease[0] + str(self.prerelease[1])
|
| 162 |
+
|
| 163 |
+
return vstring
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def _cmp (self, other):
|
| 167 |
+
if isinstance(other, str):
|
| 168 |
+
other = StrictVersion(other)
|
| 169 |
+
elif not isinstance(other, StrictVersion):
|
| 170 |
+
return NotImplemented
|
| 171 |
+
|
| 172 |
+
if self.version != other.version:
|
| 173 |
+
# numeric versions don't match
|
| 174 |
+
# prerelease stuff doesn't matter
|
| 175 |
+
if self.version < other.version:
|
| 176 |
+
return -1
|
| 177 |
+
else:
|
| 178 |
+
return 1
|
| 179 |
+
|
| 180 |
+
# have to compare prerelease
|
| 181 |
+
# case 1: neither has prerelease; they're equal
|
| 182 |
+
# case 2: self has prerelease, other doesn't; other is greater
|
| 183 |
+
# case 3: self doesn't have prerelease, other does: self is greater
|
| 184 |
+
# case 4: both have prerelease: must compare them!
|
| 185 |
+
|
| 186 |
+
if (not self.prerelease and not other.prerelease):
|
| 187 |
+
return 0
|
| 188 |
+
elif (self.prerelease and not other.prerelease):
|
| 189 |
+
return -1
|
| 190 |
+
elif (not self.prerelease and other.prerelease):
|
| 191 |
+
return 1
|
| 192 |
+
elif (self.prerelease and other.prerelease):
|
| 193 |
+
if self.prerelease == other.prerelease:
|
| 194 |
+
return 0
|
| 195 |
+
elif self.prerelease < other.prerelease:
|
| 196 |
+
return -1
|
| 197 |
+
else:
|
| 198 |
+
return 1
|
| 199 |
+
else:
|
| 200 |
+
assert False, "never get here"
|
| 201 |
+
|
| 202 |
+
# end class StrictVersion
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
# The rules according to Greg Stein:
|
| 206 |
+
# 1) a version number has 1 or more numbers separated by a period or by
|
| 207 |
+
# sequences of letters. If only periods, then these are compared
|
| 208 |
+
# left-to-right to determine an ordering.
|
| 209 |
+
# 2) sequences of letters are part of the tuple for comparison and are
|
| 210 |
+
# compared lexicographically
|
| 211 |
+
# 3) recognize the numeric components may have leading zeroes
|
| 212 |
+
#
|
| 213 |
+
# The LooseVersion class below implements these rules: a version number
|
| 214 |
+
# string is split up into a tuple of integer and string components, and
|
| 215 |
+
# comparison is a simple tuple comparison. This means that version
|
| 216 |
+
# numbers behave in a predictable and obvious way, but a way that might
|
| 217 |
+
# not necessarily be how people *want* version numbers to behave. There
|
| 218 |
+
# wouldn't be a problem if people could stick to purely numeric version
|
| 219 |
+
# numbers: just split on period and compare the numbers as tuples.
|
| 220 |
+
# However, people insist on putting letters into their version numbers;
|
| 221 |
+
# the most common purpose seems to be:
|
| 222 |
+
# - indicating a "pre-release" version
|
| 223 |
+
# ('alpha', 'beta', 'a', 'b', 'pre', 'p')
|
| 224 |
+
# - indicating a post-release patch ('p', 'pl', 'patch')
|
| 225 |
+
# but of course this can't cover all version number schemes, and there's
|
| 226 |
+
# no way to know what a programmer means without asking him.
|
| 227 |
+
#
|
| 228 |
+
# The problem is what to do with letters (and other non-numeric
|
| 229 |
+
# characters) in a version number. The current implementation does the
|
| 230 |
+
# obvious and predictable thing: keep them as strings and compare
|
| 231 |
+
# lexically within a tuple comparison. This has the desired effect if
|
| 232 |
+
# an appended letter sequence implies something "post-release":
|
| 233 |
+
# eg. "0.99" < "0.99pl14" < "1.0", and "5.001" < "5.001m" < "5.002".
|
| 234 |
+
#
|
| 235 |
+
# However, if letters in a version number imply a pre-release version,
|
| 236 |
+
# the "obvious" thing isn't correct. Eg. you would expect that
|
| 237 |
+
# "1.5.1" < "1.5.2a2" < "1.5.2", but under the tuple/lexical comparison
|
| 238 |
+
# implemented here, this just isn't so.
|
| 239 |
+
#
|
| 240 |
+
# Two possible solutions come to mind. The first is to tie the
|
| 241 |
+
# comparison algorithm to a particular set of semantic rules, as has
|
| 242 |
+
# been done in the StrictVersion class above. This works great as long
|
| 243 |
+
# as everyone can go along with bondage and discipline. Hopefully a
|
| 244 |
+
# (large) subset of Python module programmers will agree that the
|
| 245 |
+
# particular flavour of bondage and discipline provided by StrictVersion
|
| 246 |
+
# provides enough benefit to be worth using, and will submit their
|
| 247 |
+
# version numbering scheme to its domination. The free-thinking
|
| 248 |
+
# anarchists in the lot will never give in, though, and something needs
|
| 249 |
+
# to be done to accommodate them.
|
| 250 |
+
#
|
| 251 |
+
# Perhaps a "moderately strict" version class could be implemented that
|
| 252 |
+
# lets almost anything slide (syntactically), and makes some heuristic
|
| 253 |
+
# assumptions about non-digits in version number strings. This could
|
| 254 |
+
# sink into special-case-hell, though; if I was as talented and
|
| 255 |
+
# idiosyncratic as Larry Wall, I'd go ahead and implement a class that
|
| 256 |
+
# somehow knows that "1.2.1" < "1.2.2a2" < "1.2.2" < "1.2.2pl3", and is
|
| 257 |
+
# just as happy dealing with things like "2g6" and "1.13++". I don't
|
| 258 |
+
# think I'm smart enough to do it right though.
|
| 259 |
+
#
|
| 260 |
+
# In any case, I've coded the test suite for this module (see
|
| 261 |
+
# ../test/test_version.py) specifically to fail on things like comparing
|
| 262 |
+
# "1.2a2" and "1.2". That's not because the *code* is doing anything
|
| 263 |
+
# wrong, it's because the simple, obvious design doesn't match my
|
| 264 |
+
# complicated, hairy expectations for real-world version numbers. It
|
| 265 |
+
# would be a snap to fix the test suite to say, "Yep, LooseVersion does
|
| 266 |
+
# the Right Thing" (ie. the code matches the conception). But I'd rather
|
| 267 |
+
# have a conception that matches common notions about version numbers.
|
| 268 |
+
|
| 269 |
+
class LooseVersion (Version):
|
| 270 |
+
|
| 271 |
+
"""Version numbering for anarchists and software realists.
|
| 272 |
+
Implements the standard interface for version number classes as
|
| 273 |
+
described above. A version number consists of a series of numbers,
|
| 274 |
+
separated by either periods or strings of letters. When comparing
|
| 275 |
+
version numbers, the numeric components will be compared
|
| 276 |
+
numerically, and the alphabetic components lexically. The following
|
| 277 |
+
are all valid version numbers, in no particular order:
|
| 278 |
+
|
| 279 |
+
1.5.1
|
| 280 |
+
1.5.2b2
|
| 281 |
+
161
|
| 282 |
+
3.10a
|
| 283 |
+
8.02
|
| 284 |
+
3.4j
|
| 285 |
+
1996.07.12
|
| 286 |
+
3.2.pl0
|
| 287 |
+
3.1.1.6
|
| 288 |
+
2g6
|
| 289 |
+
11g
|
| 290 |
+
0.960923
|
| 291 |
+
2.2beta29
|
| 292 |
+
1.13++
|
| 293 |
+
5.5.kw
|
| 294 |
+
2.0b1pl0
|
| 295 |
+
|
| 296 |
+
In fact, there is no such thing as an invalid version number under
|
| 297 |
+
this scheme; the rules for comparison are simple and predictable,
|
| 298 |
+
but may not always give the results you want (for some definition
|
| 299 |
+
of "want").
|
| 300 |
+
"""
|
| 301 |
+
|
| 302 |
+
component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE)
|
| 303 |
+
|
| 304 |
+
def __init__ (self, vstring=None):
|
| 305 |
+
if vstring:
|
| 306 |
+
self.parse(vstring)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
def parse (self, vstring):
|
| 310 |
+
# I've given up on thinking I can reconstruct the version string
|
| 311 |
+
# from the parsed tuple -- so I just store the string here for
|
| 312 |
+
# use by __str__
|
| 313 |
+
self.vstring = vstring
|
| 314 |
+
components = [x for x in self.component_re.split(vstring)
|
| 315 |
+
if x and x != '.']
|
| 316 |
+
for i, obj in enumerate(components):
|
| 317 |
+
try:
|
| 318 |
+
components[i] = int(obj)
|
| 319 |
+
except ValueError:
|
| 320 |
+
pass
|
| 321 |
+
|
| 322 |
+
self.version = components
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def __str__ (self):
|
| 326 |
+
return self.vstring
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
def __repr__ (self):
|
| 330 |
+
return "LooseVersion ('%s')" % str(self)
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
def _cmp (self, other):
|
| 334 |
+
if isinstance(other, str):
|
| 335 |
+
other = LooseVersion(other)
|
| 336 |
+
elif not isinstance(other, LooseVersion):
|
| 337 |
+
return NotImplemented
|
| 338 |
+
|
| 339 |
+
if self.version == other.version:
|
| 340 |
+
return 0
|
| 341 |
+
if self.version < other.version:
|
| 342 |
+
return -1
|
| 343 |
+
if self.version > other.version:
|
| 344 |
+
return 1
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
# end class LooseVersion
|
data/conda_envs/evalclaw/lib/python3.11/distutils/versionpredicate.py
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Module for parsing and testing package version predicate strings.
|
| 2 |
+
"""
|
| 3 |
+
import re
|
| 4 |
+
import distutils.version
|
| 5 |
+
import operator
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
re_validPackage = re.compile(r"(?i)^\s*([a-z_]\w*(?:\.[a-z_]\w*)*)(.*)",
|
| 9 |
+
re.ASCII)
|
| 10 |
+
# (package) (rest)
|
| 11 |
+
|
| 12 |
+
re_paren = re.compile(r"^\s*\((.*)\)\s*$") # (list) inside of parentheses
|
| 13 |
+
re_splitComparison = re.compile(r"^\s*(<=|>=|<|>|!=|==)\s*([^\s,]+)\s*$")
|
| 14 |
+
# (comp) (version)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def splitUp(pred):
|
| 18 |
+
"""Parse a single version comparison.
|
| 19 |
+
|
| 20 |
+
Return (comparison string, StrictVersion)
|
| 21 |
+
"""
|
| 22 |
+
res = re_splitComparison.match(pred)
|
| 23 |
+
if not res:
|
| 24 |
+
raise ValueError("bad package restriction syntax: %r" % pred)
|
| 25 |
+
comp, verStr = res.groups()
|
| 26 |
+
return (comp, distutils.version.StrictVersion(verStr))
|
| 27 |
+
|
| 28 |
+
compmap = {"<": operator.lt, "<=": operator.le, "==": operator.eq,
|
| 29 |
+
">": operator.gt, ">=": operator.ge, "!=": operator.ne}
|
| 30 |
+
|
| 31 |
+
class VersionPredicate:
|
| 32 |
+
"""Parse and test package version predicates.
|
| 33 |
+
|
| 34 |
+
>>> v = VersionPredicate('pyepat.abc (>1.0, <3333.3a1, !=1555.1b3)')
|
| 35 |
+
|
| 36 |
+
The `name` attribute provides the full dotted name that is given::
|
| 37 |
+
|
| 38 |
+
>>> v.name
|
| 39 |
+
'pyepat.abc'
|
| 40 |
+
|
| 41 |
+
The str() of a `VersionPredicate` provides a normalized
|
| 42 |
+
human-readable version of the expression::
|
| 43 |
+
|
| 44 |
+
>>> print(v)
|
| 45 |
+
pyepat.abc (> 1.0, < 3333.3a1, != 1555.1b3)
|
| 46 |
+
|
| 47 |
+
The `satisfied_by()` method can be used to determine with a given
|
| 48 |
+
version number is included in the set described by the version
|
| 49 |
+
restrictions::
|
| 50 |
+
|
| 51 |
+
>>> v.satisfied_by('1.1')
|
| 52 |
+
True
|
| 53 |
+
>>> v.satisfied_by('1.4')
|
| 54 |
+
True
|
| 55 |
+
>>> v.satisfied_by('1.0')
|
| 56 |
+
False
|
| 57 |
+
>>> v.satisfied_by('4444.4')
|
| 58 |
+
False
|
| 59 |
+
>>> v.satisfied_by('1555.1b3')
|
| 60 |
+
False
|
| 61 |
+
|
| 62 |
+
`VersionPredicate` is flexible in accepting extra whitespace::
|
| 63 |
+
|
| 64 |
+
>>> v = VersionPredicate(' pat( == 0.1 ) ')
|
| 65 |
+
>>> v.name
|
| 66 |
+
'pat'
|
| 67 |
+
>>> v.satisfied_by('0.1')
|
| 68 |
+
True
|
| 69 |
+
>>> v.satisfied_by('0.2')
|
| 70 |
+
False
|
| 71 |
+
|
| 72 |
+
If any version numbers passed in do not conform to the
|
| 73 |
+
restrictions of `StrictVersion`, a `ValueError` is raised::
|
| 74 |
+
|
| 75 |
+
>>> v = VersionPredicate('p1.p2.p3.p4(>=1.0, <=1.3a1, !=1.2zb3)')
|
| 76 |
+
Traceback (most recent call last):
|
| 77 |
+
...
|
| 78 |
+
ValueError: invalid version number '1.2zb3'
|
| 79 |
+
|
| 80 |
+
It the module or package name given does not conform to what's
|
| 81 |
+
allowed as a legal module or package name, `ValueError` is
|
| 82 |
+
raised::
|
| 83 |
+
|
| 84 |
+
>>> v = VersionPredicate('foo-bar')
|
| 85 |
+
Traceback (most recent call last):
|
| 86 |
+
...
|
| 87 |
+
ValueError: expected parenthesized list: '-bar'
|
| 88 |
+
|
| 89 |
+
>>> v = VersionPredicate('foo bar (12.21)')
|
| 90 |
+
Traceback (most recent call last):
|
| 91 |
+
...
|
| 92 |
+
ValueError: expected parenthesized list: 'bar (12.21)'
|
| 93 |
+
|
| 94 |
+
"""
|
| 95 |
+
|
| 96 |
+
def __init__(self, versionPredicateStr):
|
| 97 |
+
"""Parse a version predicate string.
|
| 98 |
+
"""
|
| 99 |
+
# Fields:
|
| 100 |
+
# name: package name
|
| 101 |
+
# pred: list of (comparison string, StrictVersion)
|
| 102 |
+
|
| 103 |
+
versionPredicateStr = versionPredicateStr.strip()
|
| 104 |
+
if not versionPredicateStr:
|
| 105 |
+
raise ValueError("empty package restriction")
|
| 106 |
+
match = re_validPackage.match(versionPredicateStr)
|
| 107 |
+
if not match:
|
| 108 |
+
raise ValueError("bad package name in %r" % versionPredicateStr)
|
| 109 |
+
self.name, paren = match.groups()
|
| 110 |
+
paren = paren.strip()
|
| 111 |
+
if paren:
|
| 112 |
+
match = re_paren.match(paren)
|
| 113 |
+
if not match:
|
| 114 |
+
raise ValueError("expected parenthesized list: %r" % paren)
|
| 115 |
+
str = match.groups()[0]
|
| 116 |
+
self.pred = [splitUp(aPred) for aPred in str.split(",")]
|
| 117 |
+
if not self.pred:
|
| 118 |
+
raise ValueError("empty parenthesized list in %r"
|
| 119 |
+
% versionPredicateStr)
|
| 120 |
+
else:
|
| 121 |
+
self.pred = []
|
| 122 |
+
|
| 123 |
+
def __str__(self):
|
| 124 |
+
if self.pred:
|
| 125 |
+
seq = [cond + " " + str(ver) for cond, ver in self.pred]
|
| 126 |
+
return self.name + " (" + ", ".join(seq) + ")"
|
| 127 |
+
else:
|
| 128 |
+
return self.name
|
| 129 |
+
|
| 130 |
+
def satisfied_by(self, version):
|
| 131 |
+
"""True if version is compatible with all the predicates in self.
|
| 132 |
+
The parameter version must be acceptable to the StrictVersion
|
| 133 |
+
constructor. It may be either a string or StrictVersion.
|
| 134 |
+
"""
|
| 135 |
+
for cond, ver in self.pred:
|
| 136 |
+
if not compmap[cond](version, ver):
|
| 137 |
+
return False
|
| 138 |
+
return True
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
_provision_rx = None
|
| 142 |
+
|
| 143 |
+
def split_provision(value):
|
| 144 |
+
"""Return the name and optional version number of a provision.
|
| 145 |
+
|
| 146 |
+
The version number, if given, will be returned as a `StrictVersion`
|
| 147 |
+
instance, otherwise it will be `None`.
|
| 148 |
+
|
| 149 |
+
>>> split_provision('mypkg')
|
| 150 |
+
('mypkg', None)
|
| 151 |
+
>>> split_provision(' mypkg( 1.2 ) ')
|
| 152 |
+
('mypkg', StrictVersion ('1.2'))
|
| 153 |
+
"""
|
| 154 |
+
global _provision_rx
|
| 155 |
+
if _provision_rx is None:
|
| 156 |
+
_provision_rx = re.compile(
|
| 157 |
+
r"([a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*)(?:\s*\(\s*([^)\s]+)\s*\))?$",
|
| 158 |
+
re.ASCII)
|
| 159 |
+
value = value.strip()
|
| 160 |
+
m = _provision_rx.match(value)
|
| 161 |
+
if not m:
|
| 162 |
+
raise ValueError("illegal provides specification: %r" % value)
|
| 163 |
+
ver = m.group(2) or None
|
| 164 |
+
if ver:
|
| 165 |
+
ver = distutils.version.StrictVersion(ver)
|
| 166 |
+
return m.group(1), ver
|
data/conda_envs/evalclaw/lib/python3.11/idlelib/CREDITS.txt
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Guido van Rossum, as well as being the creator of the Python language, is the
|
| 2 |
+
original creator of IDLE. Other contributors prior to Version 0.8 include
|
| 3 |
+
Mark Hammond, Jeremy Hylton, Tim Peters, and Moshe Zadka.
|
| 4 |
+
|
| 5 |
+
Until Python 2.3, IDLE's development was carried out in the SF IDLEfork project. The
|
| 6 |
+
objective was to develop a version of IDLE which had an execution environment
|
| 7 |
+
which could be initialized prior to each run of user code.
|
| 8 |
+
IDLefork was merged into the Python code base in 2003.
|
| 9 |
+
|
| 10 |
+
The IDLEfork project was initiated by David Scherer, with some help from Peter
|
| 11 |
+
Schneider-Kamp and Nicholas Riley. David wrote the first version of the RPC
|
| 12 |
+
code and designed a fast turn-around environment for VPython. Guido developed
|
| 13 |
+
the RPC code and Remote Debugger currently integrated in IDLE. Bruce Sherwood
|
| 14 |
+
contributed considerable time testing and suggesting improvements.
|
| 15 |
+
|
| 16 |
+
Besides David and Guido, the main developers who were active on IDLEfork
|
| 17 |
+
are Stephen M. Gava, who implemented the configuration GUI, the new
|
| 18 |
+
configuration system, and the About dialog, and Kurt B. Kaiser, who completed
|
| 19 |
+
the integration of the RPC and remote debugger, implemented the threaded
|
| 20 |
+
subprocess, and made a number of usability enhancements.
|
| 21 |
+
|
| 22 |
+
Other contributors include Raymond Hettinger, Tony Lownds (Mac integration),
|
| 23 |
+
Neal Norwitz (code check and clean-up), Ronald Oussoren (Mac integration),
|
| 24 |
+
Noam Raphael (Code Context, Call Tips, many other patches), and Chui Tey (RPC
|
| 25 |
+
integration, debugger integration and persistent breakpoints).
|
| 26 |
+
|
| 27 |
+
Scott David Daniels, Tal Einat, Hernan Foffani, Christos Georgiou,
|
| 28 |
+
Jim Jewett, Martin v. Löwis, Jason Orendorff, Guilherme Polo, Josh Robb,
|
| 29 |
+
Nigel Rowe, Bruce Sherwood, Jeff Shute, and Weeble have submitted useful
|
| 30 |
+
patches. Thanks, guys!
|
| 31 |
+
|
| 32 |
+
Major contributors since 2005:
|
| 33 |
+
|
| 34 |
+
- 2005: Tal Einat
|
| 35 |
+
- 2010: Terry Jan Reedy (current maintainer)
|
| 36 |
+
- 2013: Roger Serwys
|
| 37 |
+
- 2014: Saimadhav Heblikar
|
| 38 |
+
- 2015: Mark Roseman
|
| 39 |
+
- 2017: Louie Lu, Cheryl Sabella, and Serhiy Storchaka
|
| 40 |
+
|
| 41 |
+
For additional details refer to NEWS.txt and Changelog.
|
| 42 |
+
|
| 43 |
+
Please contact the IDLE maintainer (kbk@shore.net) to have yourself included
|
| 44 |
+
here if you are one of those we missed!
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
data/conda_envs/evalclaw/lib/python3.11/idlelib/ChangeLog
ADDED
|
@@ -0,0 +1,1591 @@
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Please refer to the IDLEfork and IDLE CVS repositories for
|
| 2 |
+
change details subsequent to the 0.8.1 release.
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
IDLEfork ChangeLog
|
| 6 |
+
==================
|
| 7 |
+
|
| 8 |
+
2001-07-20 11:35 elguavas
|
| 9 |
+
|
| 10 |
+
* README.txt, NEWS.txt: bring up to date for 0.8.1 release
|
| 11 |
+
|
| 12 |
+
2001-07-19 16:40 elguavas
|
| 13 |
+
|
| 14 |
+
* IDLEFORK.html: replaced by IDLEFORK-index.html
|
| 15 |
+
|
| 16 |
+
2001-07-19 16:39 elguavas
|
| 17 |
+
|
| 18 |
+
* IDLEFORK-index.html: updated placeholder idlefork homepage
|
| 19 |
+
|
| 20 |
+
2001-07-19 14:49 elguavas
|
| 21 |
+
|
| 22 |
+
* ChangeLog, EditorWindow.py, INSTALLATION, NEWS.txt, README.txt,
|
| 23 |
+
TODO.txt, idlever.py:
|
| 24 |
+
minor tidy-ups ready for 0.8.1 alpha tarball release
|
| 25 |
+
|
| 26 |
+
2001-07-17 15:12 kbk
|
| 27 |
+
|
| 28 |
+
* INSTALLATION, setup.py: INSTALLATION: Remove the coexist.patch
|
| 29 |
+
instructions
|
| 30 |
+
|
| 31 |
+
**************** setup.py:
|
| 32 |
+
|
| 33 |
+
Remove the idles script, add some words on IDLE Fork to the
|
| 34 |
+
long_description, and clean up some line spacing.
|
| 35 |
+
|
| 36 |
+
2001-07-17 15:01 kbk
|
| 37 |
+
|
| 38 |
+
* coexist.patch: Put this in the attic, at least for now...
|
| 39 |
+
|
| 40 |
+
2001-07-17 14:59 kbk
|
| 41 |
+
|
| 42 |
+
* PyShell.py, idle, idles: Implement idle command interface as
|
| 43 |
+
suggested by GvR [idle-dev] 16 July **************** PyShell: Added
|
| 44 |
+
functionality:
|
| 45 |
+
|
| 46 |
+
usage: idle.py [-c command] [-d] [-i] [-r script] [-s] [-t title]
|
| 47 |
+
[arg] ...
|
| 48 |
+
|
| 49 |
+
idle file(s) (without options) edit the file(s)
|
| 50 |
+
|
| 51 |
+
-c cmd run the command in a shell -d enable the
|
| 52 |
+
debugger -i open an interactive shell -i file(s) open a
|
| 53 |
+
shell and also an editor window for each file -r script run a file
|
| 54 |
+
as a script in a shell -s run $IDLESTARTUP or
|
| 55 |
+
$PYTHONSTARTUP before anything else -t title set title of shell
|
| 56 |
+
window
|
| 57 |
+
|
| 58 |
+
Remaining arguments are applied to the command (-c) or script (-r).
|
| 59 |
+
|
| 60 |
+
****************** idles: Removed the idles script, not needed
|
| 61 |
+
|
| 62 |
+
****************** idle: Removed the IdleConf references, not
|
| 63 |
+
required anymore
|
| 64 |
+
|
| 65 |
+
2001-07-16 17:08 kbk
|
| 66 |
+
|
| 67 |
+
* INSTALLATION, coexist.patch: Added installation instructions.
|
| 68 |
+
|
| 69 |
+
Added a patch which modifies idlefork so that it can co-exist with
|
| 70 |
+
"official" IDLE in the site-packages directory. This patch is not
|
| 71 |
+
necessary if only idlefork IDLE is installed. See INSTALLATION for
|
| 72 |
+
further details.
|
| 73 |
+
|
| 74 |
+
2001-07-16 15:50 kbk
|
| 75 |
+
|
| 76 |
+
* idles: Add a script "idles" which opens a Python Shell window.
|
| 77 |
+
|
| 78 |
+
The default behaviour of idlefork idle is to open an editor window
|
| 79 |
+
instead of a shell. Complex expressions may be run in a fresh
|
| 80 |
+
environment by selecting "run". There are times, however, when a
|
| 81 |
+
shell is desired. Though one can be started by "idle -t 'foo'",
|
| 82 |
+
this script is more convenient. In addition, a shell and an editor
|
| 83 |
+
window can be started in parallel by "idles -e foo.py".
|
| 84 |
+
|
| 85 |
+
2001-07-16 15:25 kbk
|
| 86 |
+
|
| 87 |
+
* PyShell.py: Call out IDLE Fork in startup message.
|
| 88 |
+
|
| 89 |
+
2001-07-16 14:00 kbk
|
| 90 |
+
|
| 91 |
+
* PyShell.py, setup.py: Add a script "idles" which opens a Python
|
| 92 |
+
Shell window.
|
| 93 |
+
|
| 94 |
+
The default behaviour of idlefork idle is to open an editor window
|
| 95 |
+
instead of a shell. Complex expressions may be run in a fresh
|
| 96 |
+
environment by selecting "run". There are times, however, when a
|
| 97 |
+
shell is desired. Though one can be started by "idle -t 'foo'",
|
| 98 |
+
this script is more convenient. In addition, a shell and an editor
|
| 99 |
+
window can be started in parallel by "idles -e foo.py".
|
| 100 |
+
|
| 101 |
+
2001-07-15 03:06 kbk
|
| 102 |
+
|
| 103 |
+
* pyclbr.py, tabnanny.py: tabnanny and pyclbr are now found in /Lib
|
| 104 |
+
|
| 105 |
+
2001-07-15 02:29 kbk
|
| 106 |
+
|
| 107 |
+
* BrowserControl.py: Remove, was retained for 1.5.2 support
|
| 108 |
+
|
| 109 |
+
2001-07-14 15:48 kbk
|
| 110 |
+
|
| 111 |
+
* setup.py: Installing Idle to site-packages via Distutils does not
|
| 112 |
+
copy the Idle help.txt file.
|
| 113 |
+
|
| 114 |
+
Ref SF Python Patch 422471
|
| 115 |
+
|
| 116 |
+
2001-07-14 15:26 kbk
|
| 117 |
+
|
| 118 |
+
* keydefs.py: py-cvs-2001_07_13 (Rev 1.3) merge
|
| 119 |
+
|
| 120 |
+
"Make copy, cut and paste events case insensitive. Reported by
|
| 121 |
+
Patrick K. O'Brien on idle-dev. (Should other bindings follow
|
| 122 |
+
suit?)" --GvR
|
| 123 |
+
|
| 124 |
+
2001-07-14 15:21 kbk
|
| 125 |
+
|
| 126 |
+
* idle.py: py-cvs-2001_07_13 (Rev 1.4) merge
|
| 127 |
+
|
| 128 |
+
"Move the action of loading the configuration to the IdleConf
|
| 129 |
+
module rather than the idle.py script. This has advantages and
|
| 130 |
+
disadvantages; the biggest advantage being that we can more easily
|
| 131 |
+
have an alternative main program." --GvR
|
| 132 |
+
|
| 133 |
+
2001-07-14 15:18 kbk
|
| 134 |
+
|
| 135 |
+
* extend.txt: py-cvs-2001_07_13 (Rev 1.4) merge
|
| 136 |
+
|
| 137 |
+
"Quick update to the extension mechanism (extend.py is gone, long
|
| 138 |
+
live config.txt)" --GvR
|
| 139 |
+
|
| 140 |
+
2001-07-14 15:15 kbk
|
| 141 |
+
|
| 142 |
+
* StackViewer.py: py-cvs-2001_07_13 (Rev 1.16) merge
|
| 143 |
+
|
| 144 |
+
"Refactored, with some future plans in mind. This now uses the new
|
| 145 |
+
gotofileline() method defined in FileList.py" --GvR
|
| 146 |
+
|
| 147 |
+
2001-07-14 15:10 kbk
|
| 148 |
+
|
| 149 |
+
* PyShell.py: py-cvs-2001_07_13 (Rev 1.34) merge
|
| 150 |
+
|
| 151 |
+
"Amazing. A very subtle change in policy in descr-branch actually
|
| 152 |
+
found a bug here. Here's the deal: Class PyShell derives from
|
| 153 |
+
class OutputWindow. Method PyShell.close() wants to invoke its
|
| 154 |
+
parent method, but because PyShell long ago was inherited from
|
| 155 |
+
class PyShellEditorWindow, it invokes
|
| 156 |
+
PyShelEditorWindow.close(self). Now, class PyShellEditorWindow
|
| 157 |
+
itself derives from class OutputWindow, and inherits the close()
|
| 158 |
+
method from there without overriding it. Under the old rules,
|
| 159 |
+
PyShellEditorWindow.close would return an unbound method restricted
|
| 160 |
+
to the class that defined the implementation of close(), which was
|
| 161 |
+
OutputWindow.close. Under the new rules, the unbound method is
|
| 162 |
+
restricted to the class whose method was requested, that is
|
| 163 |
+
PyShellEditorWindow, and this was correctly trapped as an error."
|
| 164 |
+
--GvR
|
| 165 |
+
|
| 166 |
+
2001-07-14 14:59 kbk
|
| 167 |
+
|
| 168 |
+
* PyParse.py: py-cvs-2001_07_13 (Rel 1.9) merge
|
| 169 |
+
|
| 170 |
+
"Taught IDLE's autoident parser that "yield" is a keyword that
|
| 171 |
+
begins a stmt. Along w/ the preceding change to keyword.py, making
|
| 172 |
+
all this work w/ a future-stmt just looks harder and harder."
|
| 173 |
+
--tim_one
|
| 174 |
+
|
| 175 |
+
(From Rel 1.8: "Hack to make this still work with Python 1.5.2.
|
| 176 |
+
;-( " --fdrake)
|
| 177 |
+
|
| 178 |
+
2001-07-14 14:51 kbk
|
| 179 |
+
|
| 180 |
+
* IdleConf.py: py-cvs-2001_07_13 (Rel 1.7) merge
|
| 181 |
+
|
| 182 |
+
"Move the action of loading the configuration to the IdleConf
|
| 183 |
+
module rather than the idle.py script. This has advantages and
|
| 184 |
+
disadvantages; the biggest advantage being that we can more easily
|
| 185 |
+
have an alternative main program." --GvR
|
| 186 |
+
|
| 187 |
+
2001-07-14 14:45 kbk
|
| 188 |
+
|
| 189 |
+
* FileList.py: py-cvs-2000_07_13 (Rev 1.9) merge
|
| 190 |
+
|
| 191 |
+
"Delete goodname() method, which is unused. Add gotofileline(), a
|
| 192 |
+
convenience method which I intend to use in a variant. Rename
|
| 193 |
+
test() to _test()." --GvR
|
| 194 |
+
|
| 195 |
+
This was an interesting merge. The join completely missed removing
|
| 196 |
+
goodname(), which was adjacent, but outside of, a small conflict.
|
| 197 |
+
I only caught it by comparing the 1.1.3.2/1.1.3.3 diff. CVS ain't
|
| 198 |
+
infallible.
|
| 199 |
+
|
| 200 |
+
2001-07-14 13:58 kbk
|
| 201 |
+
|
| 202 |
+
* EditorWindow.py: py-cvs-2000_07_13 (Rev 1.38) merge "Remove
|
| 203 |
+
legacy support for the BrowserControl module; the webbrowser module
|
| 204 |
+
has been included since Python 2.0, and that is the preferred
|
| 205 |
+
interface." --fdrake
|
| 206 |
+
|
| 207 |
+
2001-07-14 13:32 kbk
|
| 208 |
+
|
| 209 |
+
* EditorWindow.py, FileList.py, IdleConf.py, PyParse.py,
|
| 210 |
+
PyShell.py, StackViewer.py, extend.txt, idle.py, keydefs.py: Import
|
| 211 |
+
the 2001 July 13 23:59 GMT version of Python CVS IDLE on the
|
| 212 |
+
existing 1.1.3 vendor branch named py-cvs-vendor-branch. Release
|
| 213 |
+
tag is py-cvs-2001_07_13.
|
| 214 |
+
|
| 215 |
+
2001-07-14 12:02 kbk
|
| 216 |
+
|
| 217 |
+
* Icons/python.gif: py-cvs-rel2_1 (Rev 1.2) merge Copied py-cvs rev
|
| 218 |
+
1.2 changed file to idlefork MAIN
|
| 219 |
+
|
| 220 |
+
2001-07-14 11:58 kbk
|
| 221 |
+
|
| 222 |
+
* Icons/minusnode.gif: py-cvs-rel2_1 (Rev 1.2) merge Copied py-cvs
|
| 223 |
+
1.2 changed file to idlefork MAIN
|
| 224 |
+
|
| 225 |
+
2001-07-14 11:23 kbk
|
| 226 |
+
|
| 227 |
+
* ScrolledList.py: py-cvs-rel2_1 (rev 1.5) merge - whitespace
|
| 228 |
+
normalization
|
| 229 |
+
|
| 230 |
+
2001-07-14 11:20 kbk
|
| 231 |
+
|
| 232 |
+
* Separator.py: py-cvs-rel2_1 (Rev 1.3) merge - whitespace
|
| 233 |
+
normalization
|
| 234 |
+
|
| 235 |
+
2001-07-14 11:16 kbk
|
| 236 |
+
|
| 237 |
+
* StackViewer.py: py-cvs-rel2_1 (Rev 1.15) merge - whitespace
|
| 238 |
+
normalization
|
| 239 |
+
|
| 240 |
+
2001-07-14 11:14 kbk
|
| 241 |
+
|
| 242 |
+
* ToolTip.py: py-cvs-rel2_1 (Rev 1.2) merge - whitespace
|
| 243 |
+
normalization
|
| 244 |
+
|
| 245 |
+
2001-07-14 10:13 kbk
|
| 246 |
+
|
| 247 |
+
* PyShell.py: cvs-py-rel2_1 (Rev 1.29 - 1.33) merge
|
| 248 |
+
|
| 249 |
+
Merged the following py-cvs revs without conflict: 1.29 Reduce
|
| 250 |
+
copyright text output at startup 1.30 Delay setting sys.args until
|
| 251 |
+
Tkinter is fully initialized 1.31 Whitespace normalization 1.32
|
| 252 |
+
Turn syntax warning into error when interactive 1.33 Fix warning
|
| 253 |
+
initialization bug
|
| 254 |
+
|
| 255 |
+
Note that module is extensively modified wrt py-cvs
|
| 256 |
+
|
| 257 |
+
2001-07-14 06:33 kbk
|
| 258 |
+
|
| 259 |
+
* PyParse.py: py-cvs-rel2_1 (Rev 1.6 - 1.8) merge Fix autoindent
|
| 260 |
+
bug and deflect Unicode from text.get()
|
| 261 |
+
|
| 262 |
+
2001-07-14 06:00 kbk
|
| 263 |
+
|
| 264 |
+
* Percolator.py: py-cvs-rel2_1 (Rev 1.3) "move "from Tkinter import
|
| 265 |
+
*" to module level" --jhylton
|
| 266 |
+
|
| 267 |
+
2001-07-14 05:57 kbk
|
| 268 |
+
|
| 269 |
+
* PathBrowser.py: py-cvs-rel2_1 (Rev 1.6) merge - whitespace
|
| 270 |
+
normalization
|
| 271 |
+
|
| 272 |
+
2001-07-14 05:49 kbk
|
| 273 |
+
|
| 274 |
+
* ParenMatch.py: cvs-py-rel2_1 (Rev 1.5) merge - whitespace
|
| 275 |
+
normalization
|
| 276 |
+
|
| 277 |
+
2001-07-14 03:57 kbk
|
| 278 |
+
|
| 279 |
+
* ObjectBrowser.py: py-cvs-rel2_1 (Rev 1.3) merge "Make the test
|
| 280 |
+
program work outside IDLE." -- GvR
|
| 281 |
+
|
| 282 |
+
2001-07-14 03:52 kbk
|
| 283 |
+
|
| 284 |
+
* MultiStatusBar.py: py-cvs-rel2_1 (Rev 1.2) merge - whitespace
|
| 285 |
+
normalization
|
| 286 |
+
|
| 287 |
+
2001-07-14 03:44 kbk
|
| 288 |
+
|
| 289 |
+
* MultiScrolledLists.py: py-cvs-rel2_1 (Rev 1.2) merge - whitespace
|
| 290 |
+
normalization
|
| 291 |
+
|
| 292 |
+
2001-07-14 03:40 kbk
|
| 293 |
+
|
| 294 |
+
* IdleHistory.py: py-cvs-rel2_1 (Rev 1.4) merge - whitespace
|
| 295 |
+
normalization
|
| 296 |
+
|
| 297 |
+
2001-07-14 03:38 kbk
|
| 298 |
+
|
| 299 |
+
* IdleConf.py: py-cvs-rel2_1 (Rev 1.6) merge - whitespace
|
| 300 |
+
normalization
|
| 301 |
+
|
| 302 |
+
2001-07-13 14:18 kbk
|
| 303 |
+
|
| 304 |
+
* IOBinding.py: py-cvs-rel2_1 (Rev 1.4) merge - move "import *" to
|
| 305 |
+
module level
|
| 306 |
+
|
| 307 |
+
2001-07-13 14:12 kbk
|
| 308 |
+
|
| 309 |
+
* FormatParagraph.py: py-cvs-rel2_1 (Rev 1.9) merge - whitespace
|
| 310 |
+
normalization
|
| 311 |
+
|
| 312 |
+
2001-07-13 14:07 kbk
|
| 313 |
+
|
| 314 |
+
* FileList.py: py-cvs-rel2_1 (Rev 1.8) merge - whitespace
|
| 315 |
+
normalization
|
| 316 |
+
|
| 317 |
+
2001-07-13 13:35 kbk
|
| 318 |
+
|
| 319 |
+
* EditorWindow.py: py-cvs-rel2_1 (Rev 1.33 - 1.37) merge
|
| 320 |
+
|
| 321 |
+
VP IDLE version depended on VP's ExecBinding.py and spawn.py to get
|
| 322 |
+
the path to the Windows Doc directory (relative to python.exe).
|
| 323 |
+
Removed this conflicting code in favor of py-cvs updates which on
|
| 324 |
+
Windows use a hard coded path relative to the location of this
|
| 325 |
+
module. py-cvs updates include support for webbrowser.py. Module
|
| 326 |
+
still has BrowserControl.py for 1.5.2 support.
|
| 327 |
+
|
| 328 |
+
At this point, the differences wrt py-cvs relate to menu
|
| 329 |
+
functionality.
|
| 330 |
+
|
| 331 |
+
2001-07-13 11:30 kbk
|
| 332 |
+
|
| 333 |
+
* ConfigParser.py: py-cvs-rel2_1 merge - Remove, lives in /Lib
|
| 334 |
+
|
| 335 |
+
2001-07-13 10:10 kbk
|
| 336 |
+
|
| 337 |
+
* Delegator.py: py-cvs-rel2_1 (Rev 1.3) merge - whitespace
|
| 338 |
+
normalization
|
| 339 |
+
|
| 340 |
+
2001-07-13 10:07 kbk
|
| 341 |
+
|
| 342 |
+
* Debugger.py: py-cvs-rel2_1 (Rev 1.15) merge - whitespace
|
| 343 |
+
normalization
|
| 344 |
+
|
| 345 |
+
2001-07-13 10:04 kbk
|
| 346 |
+
|
| 347 |
+
* ColorDelegator.py: py-cvs-rel2_1 (Rev 1.11 and 1.12) merge
|
| 348 |
+
Colorize "as" after "import" / use DEBUG instead of __debug__
|
| 349 |
+
|
| 350 |
+
2001-07-13 09:54 kbk
|
| 351 |
+
|
| 352 |
+
* ClassBrowser.py: py-cvs-rel2_1 (Rev 1.12) merge - whitespace
|
| 353 |
+
normalization
|
| 354 |
+
|
| 355 |
+
2001-07-13 09:41 kbk
|
| 356 |
+
|
| 357 |
+
* BrowserControl.py: py-cvs-rel2_1 (Rev 1.1) merge - New File -
|
| 358 |
+
Force HEAD to trunk with -f Note: browser.py was renamed
|
| 359 |
+
BrowserControl.py 10 May 2000. It provides a collection of classes
|
| 360 |
+
and convenience functions to control external browsers "for 1.5.2
|
| 361 |
+
support". It was removed from py-cvs 18 April 2001.
|
| 362 |
+
|
| 363 |
+
2001-07-13 09:10 kbk
|
| 364 |
+
|
| 365 |
+
* CallTips.py: py-cvs-rel2_1 (Rev 1.8) merge - whitespace
|
| 366 |
+
normalization
|
| 367 |
+
|
| 368 |
+
2001-07-13 08:26 kbk
|
| 369 |
+
|
| 370 |
+
* CallTipWindow.py: py-cvs-rel2_1 (Rev 1.3) merge - whitespace
|
| 371 |
+
normalization
|
| 372 |
+
|
| 373 |
+
2001-07-13 08:13 kbk
|
| 374 |
+
|
| 375 |
+
* AutoExpand.py: py-cvs-rel1_2 (Rev 1.4) merge, "Add Alt-slash to
|
| 376 |
+
Unix keydefs (I somehow need it on RH 6.2). Get rid of assignment
|
| 377 |
+
to unused self.text.wordlist." --GvR
|
| 378 |
+
|
| 379 |
+
2001-07-12 16:54 elguavas
|
| 380 |
+
|
| 381 |
+
* ReplaceDialog.py: py-cvs merge, python 1.5.2 compatibility
|
| 382 |
+
|
| 383 |
+
2001-07-12 16:46 elguavas
|
| 384 |
+
|
| 385 |
+
* ScriptBinding.py: py-cvs merge, better error dialog
|
| 386 |
+
|
| 387 |
+
2001-07-12 16:38 elguavas
|
| 388 |
+
|
| 389 |
+
* TODO.txt: py-cvs merge, additions
|
| 390 |
+
|
| 391 |
+
2001-07-12 15:35 elguavas
|
| 392 |
+
|
| 393 |
+
* WindowList.py: py-cvs merge, correct indentation
|
| 394 |
+
|
| 395 |
+
2001-07-12 15:24 elguavas
|
| 396 |
+
|
| 397 |
+
* config.txt: py-cvs merge, correct typo
|
| 398 |
+
|
| 399 |
+
2001-07-12 15:21 elguavas
|
| 400 |
+
|
| 401 |
+
* help.txt: py-cvs merge, update colour changing info
|
| 402 |
+
|
| 403 |
+
2001-07-12 14:51 elguavas
|
| 404 |
+
|
| 405 |
+
* idle.py: py-cvs merge, idle_dir loading changed
|
| 406 |
+
|
| 407 |
+
2001-07-12 14:44 elguavas
|
| 408 |
+
|
| 409 |
+
* idlever.py: py-cvs merge, version update
|
| 410 |
+
|
| 411 |
+
2001-07-11 12:53 kbk
|
| 412 |
+
|
| 413 |
+
* BrowserControl.py: Initial revision
|
| 414 |
+
|
| 415 |
+
2001-07-11 12:53 kbk
|
| 416 |
+
|
| 417 |
+
* AutoExpand.py, BrowserControl.py, CallTipWindow.py, CallTips.py,
|
| 418 |
+
ClassBrowser.py, ColorDelegator.py, Debugger.py, Delegator.py,
|
| 419 |
+
EditorWindow.py, FileList.py, FormatParagraph.py, IOBinding.py,
|
| 420 |
+
IdleConf.py, IdleHistory.py, MultiScrolledLists.py,
|
| 421 |
+
MultiStatusBar.py, ObjectBrowser.py, OutputWindow.py,
|
| 422 |
+
ParenMatch.py, PathBrowser.py, Percolator.py, PyParse.py,
|
| 423 |
+
PyShell.py, RemoteInterp.py, ReplaceDialog.py, ScriptBinding.py,
|
| 424 |
+
ScrolledList.py, Separator.py, StackViewer.py, TODO.txt,
|
| 425 |
+
ToolTip.py, WindowList.py, config.txt, help.txt, idle, idle.bat,
|
| 426 |
+
idle.py, idlever.py, setup.py, Icons/minusnode.gif,
|
| 427 |
+
Icons/python.gif: Import the release 2.1 version of Python CVS IDLE
|
| 428 |
+
on the existing 1.1.3 vendor branch named py-cvs-vendor-branch,
|
| 429 |
+
with release tag py-cvs-rel2_1.
|
| 430 |
+
|
| 431 |
+
2001-07-11 12:34 kbk
|
| 432 |
+
|
| 433 |
+
* AutoExpand.py, AutoIndent.py, Bindings.py, CallTipWindow.py,
|
| 434 |
+
CallTips.py, ChangeLog, ClassBrowser.py, ColorDelegator.py,
|
| 435 |
+
Debugger.py, Delegator.py, EditorWindow.py, FileList.py,
|
| 436 |
+
FormatParagraph.py, FrameViewer.py, GrepDialog.py, IOBinding.py,
|
| 437 |
+
IdleConf.py, IdleHistory.py, MultiScrolledLists.py,
|
| 438 |
+
MultiStatusBar.py, NEWS.txt, ObjectBrowser.py, OldStackViewer.py,
|
| 439 |
+
OutputWindow.py, ParenMatch.py, PathBrowser.py, Percolator.py,
|
| 440 |
+
PyParse.py, PyShell.py, README.txt, RemoteInterp.py,
|
| 441 |
+
ReplaceDialog.py, ScriptBinding.py, ScrolledList.py,
|
| 442 |
+
SearchBinding.py, SearchDialog.py, SearchDialogBase.py,
|
| 443 |
+
SearchEngine.py, Separator.py, StackViewer.py, TODO.txt,
|
| 444 |
+
ToolTip.py, TreeWidget.py, UndoDelegator.py, WidgetRedirector.py,
|
| 445 |
+
WindowList.py, ZoomHeight.py, __init__.py, config-unix.txt,
|
| 446 |
+
config-win.txt, config.txt, eventparse.py, extend.txt, help.txt,
|
| 447 |
+
idle.bat, idle.py, idle.pyw, idlever.py, keydefs.py, pyclbr.py,
|
| 448 |
+
tabnanny.py, testcode.py, Icons/folder.gif, Icons/minusnode.gif,
|
| 449 |
+
Icons/openfolder.gif, Icons/plusnode.gif, Icons/python.gif,
|
| 450 |
+
Icons/tk.gif: Import the 9 March 2000 version of Python CVS IDLE as
|
| 451 |
+
1.1.3 vendor branch named py-cvs-vendor-branch.
|
| 452 |
+
|
| 453 |
+
2001-07-04 13:43 kbk
|
| 454 |
+
|
| 455 |
+
* Icons/: folder.gif, minusnode.gif, openfolder.gif, plusnode.gif,
|
| 456 |
+
python.gif, tk.gif: Null commit with -f option to force an uprev
|
| 457 |
+
and put HEADs firmly on the trunk.
|
| 458 |
+
|
| 459 |
+
2001-07-04 13:15 kbk
|
| 460 |
+
|
| 461 |
+
* AutoExpand.py, AutoIndent.py, Bindings.py, CallTipWindow.py,
|
| 462 |
+
CallTips.py, ChangeLog, ClassBrowser.py, ColorDelegator.py,
|
| 463 |
+
ConfigParser.py, Debugger.py, Delegator.py, EditorWindow.py,
|
| 464 |
+
ExecBinding.py, FileList.py, FormatParagraph.py, FrameViewer.py,
|
| 465 |
+
GrepDialog.py, IDLEFORK.html, IOBinding.py, IdleConf.py,
|
| 466 |
+
IdleHistory.py, MultiScrolledLists.py, MultiStatusBar.py, NEWS.txt,
|
| 467 |
+
ObjectBrowser.py, OldStackViewer.py, OutputWindow.py,
|
| 468 |
+
ParenMatch.py, PathBrowser.py, Percolator.py, PyParse.py,
|
| 469 |
+
PyShell.py, README.txt, Remote.py, RemoteInterp.py,
|
| 470 |
+
ReplaceDialog.py, ScriptBinding.py, ScrolledList.py,
|
| 471 |
+
SearchBinding.py, SearchDialog.py, SearchDialogBase.py,
|
| 472 |
+
SearchEngine.py, Separator.py, StackViewer.py, TODO.txt,
|
| 473 |
+
ToolTip.py, TreeWidget.py, UndoDelegator.py, WidgetRedirector.py,
|
| 474 |
+
WindowList.py, ZoomHeight.py, __init__.py, config-unix.txt,
|
| 475 |
+
config-win.txt, config.txt, eventparse.py, extend.txt, help.txt,
|
| 476 |
+
idle, idle.bat, idle.py, idle.pyw, idlever.py, keydefs.py,
|
| 477 |
+
loader.py, protocol.py, pyclbr.py, setup.py, spawn.py, tabnanny.py,
|
| 478 |
+
testcode.py: Null commit with -f option to force an uprev and put
|
| 479 |
+
HEADs firmly on the trunk.
|
| 480 |
+
|
| 481 |
+
2001-06-27 10:24 elguavas
|
| 482 |
+
|
| 483 |
+
* IDLEFORK.html: updated contact details
|
| 484 |
+
|
| 485 |
+
2001-06-25 17:23 elguavas
|
| 486 |
+
|
| 487 |
+
* idle, RemoteInterp.py, setup.py: Initial revision
|
| 488 |
+
|
| 489 |
+
2001-06-25 17:23 elguavas
|
| 490 |
+
|
| 491 |
+
* idle, RemoteInterp.py, setup.py: import current python cvs idle
|
| 492 |
+
as a vendor branch
|
| 493 |
+
|
| 494 |
+
2001-06-24 15:10 elguavas
|
| 495 |
+
|
| 496 |
+
* IDLEFORK.html: tiny change to test new syncmail setup
|
| 497 |
+
|
| 498 |
+
2001-06-24 14:41 elguavas
|
| 499 |
+
|
| 500 |
+
* IDLEFORK.html: change to new developer contact, also a test
|
| 501 |
+
commit for new syncmail setup
|
| 502 |
+
|
| 503 |
+
2001-06-23 18:15 elguavas
|
| 504 |
+
|
| 505 |
+
* IDLEFORK.html: tiny test update for revitalised idle-fork
|
| 506 |
+
|
| 507 |
+
2000-09-24 17:29 nriley
|
| 508 |
+
|
| 509 |
+
* protocol.py: Fixes for Python 1.6 compatibility - socket bind and
|
| 510 |
+
connect get a tuple instead two arguments.
|
| 511 |
+
|
| 512 |
+
2000-09-24 17:28 nriley
|
| 513 |
+
|
| 514 |
+
* spawn.py: Change for Python 1.6 compatibility - UNIX's 'os'
|
| 515 |
+
module defines 'spawnv' now, so we check for 'fork' first.
|
| 516 |
+
|
| 517 |
+
2000-08-15 22:51 nowonder
|
| 518 |
+
|
| 519 |
+
* IDLEFORK.html:
|
| 520 |
+
corrected email address
|
| 521 |
+
|
| 522 |
+
2000-08-15 22:47 nowonder
|
| 523 |
+
|
| 524 |
+
* IDLEFORK.html:
|
| 525 |
+
added .html file for http://idlefork.sourceforge.net
|
| 526 |
+
|
| 527 |
+
2000-08-15 11:13 dscherer
|
| 528 |
+
|
| 529 |
+
* AutoExpand.py, AutoIndent.py, Bindings.py, CallTipWindow.py,
|
| 530 |
+
CallTips.py, __init__.py, ChangeLog, ClassBrowser.py,
|
| 531 |
+
ColorDelegator.py, ConfigParser.py, Debugger.py, Delegator.py,
|
| 532 |
+
FileList.py, FormatParagraph.py, FrameViewer.py, GrepDialog.py,
|
| 533 |
+
IOBinding.py, IdleConf.py, IdleHistory.py, MultiScrolledLists.py,
|
| 534 |
+
MultiStatusBar.py, NEWS.txt, ObjectBrowser.py, OldStackViewer.py,
|
| 535 |
+
OutputWindow.py, ParenMatch.py, PathBrowser.py, Percolator.py,
|
| 536 |
+
PyParse.py, PyShell.py, README.txt, ReplaceDialog.py,
|
| 537 |
+
ScriptBinding.py, ScrolledList.py, SearchBinding.py,
|
| 538 |
+
SearchDialog.py, SearchDialogBase.py, SearchEngine.py,
|
| 539 |
+
Separator.py, StackViewer.py, TODO.txt, ToolTip.py, TreeWidget.py,
|
| 540 |
+
UndoDelegator.py, WidgetRedirector.py, WindowList.py, help.txt,
|
| 541 |
+
ZoomHeight.py, config-unix.txt, config-win.txt, config.txt,
|
| 542 |
+
eventparse.py, extend.txt, idle.bat, idle.py, idle.pyw, idlever.py,
|
| 543 |
+
keydefs.py, loader.py, pyclbr.py, tabnanny.py, testcode.py,
|
| 544 |
+
EditorWindow.py, ExecBinding.py, Remote.py, protocol.py, spawn.py,
|
| 545 |
+
Icons/folder.gif, Icons/minusnode.gif, Icons/openfolder.gif,
|
| 546 |
+
Icons/plusnode.gif, Icons/python.gif, Icons/tk.gif: Initial
|
| 547 |
+
revision
|
| 548 |
+
|
| 549 |
+
2000-08-15 11:13 dscherer
|
| 550 |
+
|
| 551 |
+
* AutoExpand.py, AutoIndent.py, Bindings.py, CallTipWindow.py,
|
| 552 |
+
CallTips.py, __init__.py, ChangeLog, ClassBrowser.py,
|
| 553 |
+
ColorDelegator.py, ConfigParser.py, Debugger.py, Delegator.py,
|
| 554 |
+
FileList.py, FormatParagraph.py, FrameViewer.py, GrepDialog.py,
|
| 555 |
+
IOBinding.py, IdleConf.py, IdleHistory.py, MultiScrolledLists.py,
|
| 556 |
+
MultiStatusBar.py, NEWS.txt, ObjectBrowser.py, OldStackViewer.py,
|
| 557 |
+
OutputWindow.py, ParenMatch.py, PathBrowser.py, Percolator.py,
|
| 558 |
+
PyParse.py, PyShell.py, README.txt, ReplaceDialog.py,
|
| 559 |
+
ScriptBinding.py, ScrolledList.py, SearchBinding.py,
|
| 560 |
+
SearchDialog.py, SearchDialogBase.py, SearchEngine.py,
|
| 561 |
+
Separator.py, StackViewer.py, TODO.txt, ToolTip.py, TreeWidget.py,
|
| 562 |
+
UndoDelegator.py, WidgetRedirector.py, WindowList.py, help.txt,
|
| 563 |
+
ZoomHeight.py, config-unix.txt, config-win.txt, config.txt,
|
| 564 |
+
eventparse.py, extend.txt, idle.bat, idle.py, idle.pyw, idlever.py,
|
| 565 |
+
keydefs.py, loader.py, pyclbr.py, tabnanny.py, testcode.py,
|
| 566 |
+
EditorWindow.py, ExecBinding.py, Remote.py, protocol.py, spawn.py,
|
| 567 |
+
Icons/folder.gif, Icons/minusnode.gif, Icons/openfolder.gif,
|
| 568 |
+
Icons/plusnode.gif, Icons/python.gif, Icons/tk.gif: Modified IDLE
|
| 569 |
+
from VPython 0.2
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
original IDLE ChangeLog:
|
| 573 |
+
========================
|
| 574 |
+
|
| 575 |
+
Tue Feb 15 18:08:19 2000 Guido van Rossum <guido@cnri.reston.va.us>
|
| 576 |
+
|
| 577 |
+
* NEWS.txt: Notice status bar and stack viewer.
|
| 578 |
+
|
| 579 |
+
* EditorWindow.py: Support for Moshe's status bar.
|
| 580 |
+
|
| 581 |
+
* MultiStatusBar.py: Status bar code -- by Moshe Zadka.
|
| 582 |
+
|
| 583 |
+
* OldStackViewer.py:
|
| 584 |
+
Adding the old stack viewer implementation back, for the debugger.
|
| 585 |
+
|
| 586 |
+
* StackViewer.py: New stack viewer, uses a tree widget.
|
| 587 |
+
(XXX: the debugger doesn't yet use this.)
|
| 588 |
+
|
| 589 |
+
* WindowList.py:
|
| 590 |
+
Correct a typo and remove an unqualified except that was hiding the error.
|
| 591 |
+
|
| 592 |
+
* ClassBrowser.py: Add an XXX comment about the ClassBrowser AIP.
|
| 593 |
+
|
| 594 |
+
* ChangeLog: Updated change log.
|
| 595 |
+
|
| 596 |
+
* NEWS.txt: News update. Probably incomplete; what else is new?
|
| 597 |
+
|
| 598 |
+
* README.txt:
|
| 599 |
+
Updated for pending IDLE 0.5 release (still very rough -- just getting
|
| 600 |
+
it out in a more convenient format than CVS).
|
| 601 |
+
|
| 602 |
+
* TODO.txt: Tiny addition.
|
| 603 |
+
|
| 604 |
+
Thu Sep 9 14:16:02 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 605 |
+
|
| 606 |
+
* TODO.txt: A few new TODO entries.
|
| 607 |
+
|
| 608 |
+
Thu Aug 26 23:06:22 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 609 |
+
|
| 610 |
+
* Bindings.py: Add Python Documentation entry to Help menu.
|
| 611 |
+
|
| 612 |
+
* EditorWindow.py:
|
| 613 |
+
Find the help.txt file relative to __file__ or ".", not in sys.path.
|
| 614 |
+
(Suggested by Moshe Zadka, but implemented differently.)
|
| 615 |
+
|
| 616 |
+
Add <<python-docs>> event which, on Unix, brings up Netscape pointing
|
| 617 |
+
to http://www.python.doc/current/ (a local copy would be nice but its
|
| 618 |
+
location can't be predicted). Windows solution TBD.
|
| 619 |
+
|
| 620 |
+
Wed Aug 11 14:55:43 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 621 |
+
|
| 622 |
+
* TreeWidget.py:
|
| 623 |
+
Moshe noticed an inconsistency in his comment, so I'm rephrasing it to
|
| 624 |
+
be clearer.
|
| 625 |
+
|
| 626 |
+
* TreeWidget.py:
|
| 627 |
+
Patch inspired by Moshe Zadka to search for the Icons directory in the
|
| 628 |
+
same directory as __file__, rather than searching for it along sys.path.
|
| 629 |
+
This works better when idle is a package.
|
| 630 |
+
|
| 631 |
+
Thu Jul 15 13:11:02 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 632 |
+
|
| 633 |
+
* TODO.txt: New wishes.
|
| 634 |
+
|
| 635 |
+
Sat Jul 10 13:17:35 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 636 |
+
|
| 637 |
+
* IdlePrefs.py:
|
| 638 |
+
Make the color for stderr red (i.e. the standard warning/danger/stop
|
| 639 |
+
color) rather than green. Suggested by Sam Schulenburg.
|
| 640 |
+
|
| 641 |
+
Fri Jun 25 17:26:34 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 642 |
+
|
| 643 |
+
* PyShell.py: Close debugger when closing. This may break a cycle.
|
| 644 |
+
|
| 645 |
+
* Debugger.py: Break cycle on close.
|
| 646 |
+
|
| 647 |
+
* ClassBrowser.py: Destroy the tree when closing.
|
| 648 |
+
|
| 649 |
+
* TreeWidget.py: Add destroy() method to recursively destroy a tree.
|
| 650 |
+
|
| 651 |
+
* PyShell.py: Extend _close() to break cycles.
|
| 652 |
+
Break some other cycles too (and destroy the root when done).
|
| 653 |
+
|
| 654 |
+
* EditorWindow.py:
|
| 655 |
+
Add _close() method that does the actual cleanup (close() asks the
|
| 656 |
+
user what they want first if there's unsaved stuff, and may cancel).
|
| 657 |
+
It closes more than before.
|
| 658 |
+
|
| 659 |
+
Add unload_extensions() method to unload all extensions; called from
|
| 660 |
+
_close(). It calls an extension's close() method if it has one.
|
| 661 |
+
|
| 662 |
+
* Percolator.py: Add close() method that breaks cycles.
|
| 663 |
+
|
| 664 |
+
* WidgetRedirector.py: Add unregister() method.
|
| 665 |
+
Unregister everything at closing.
|
| 666 |
+
Don't call close() in __del__, rely on explicit call to close().
|
| 667 |
+
|
| 668 |
+
* IOBinding.py, FormatParagraph.py, CallTips.py:
|
| 669 |
+
Add close() method that breaks a cycle.
|
| 670 |
+
|
| 671 |
+
Fri Jun 11 15:03:00 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 672 |
+
|
| 673 |
+
* AutoIndent.py, EditorWindow.py, FormatParagraph.py:
|
| 674 |
+
Tim Peters smart.patch:
|
| 675 |
+
|
| 676 |
+
EditorWindow.py:
|
| 677 |
+
|
| 678 |
+
+ Added get_tabwidth & set_tabwidth "virtual text" methods, that get/set the
|
| 679 |
+
widget's view of what a tab means.
|
| 680 |
+
|
| 681 |
+
+ Moved TK_TABWIDTH_DEFAULT here from AutoIndent.
|
| 682 |
+
|
| 683 |
+
+ Renamed Mark's get_selection_index to get_selection_indices (sorry, Mark,
|
| 684 |
+
but the name was plain wrong <wink>).
|
| 685 |
+
|
| 686 |
+
FormatParagraph.py: renamed use of get_selection_index.
|
| 687 |
+
|
| 688 |
+
AutoIndent.py:
|
| 689 |
+
|
| 690 |
+
+ Moved TK_TABWIDTH_DEFAULT to EditorWindow.
|
| 691 |
+
|
| 692 |
+
+ Rewrote set_indentation_params to use new VTW get/set_tabwidth methods.
|
| 693 |
+
|
| 694 |
+
+ Changed smart_backspace_event to delete whitespace back to closest
|
| 695 |
+
preceding virtual tab stop or real character (note that this may require
|
| 696 |
+
inserting characters if backspacing over a tab!).
|
| 697 |
+
|
| 698 |
+
+ Nuked almost references to the selection tag, in favor of using
|
| 699 |
+
get_selection_indices. The sole exception is in set_region, for which no
|
| 700 |
+
"set_selection" abstraction has yet been agreed upon.
|
| 701 |
+
|
| 702 |
+
+ Had too much fun using the spiffy new features of the format-paragraph
|
| 703 |
+
cmd.
|
| 704 |
+
|
| 705 |
+
Thu Jun 10 17:48:02 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 706 |
+
|
| 707 |
+
* FormatParagraph.py:
|
| 708 |
+
Code by Mark Hammond to format paragraphs embedded in comments.
|
| 709 |
+
Read the comments (which I reformatted using the new feature :-)
|
| 710 |
+
for some limitations.
|
| 711 |
+
|
| 712 |
+
* EditorWindow.py:
|
| 713 |
+
Added abstraction get_selection_index() (Mark Hammond). Also
|
| 714 |
+
reformatted some comment blocks to show off a cool feature I'm about
|
| 715 |
+
to check in next.
|
| 716 |
+
|
| 717 |
+
* ClassBrowser.py:
|
| 718 |
+
Adapt to the new pyclbr's support of listing top-level functions. If
|
| 719 |
+
this functionality is not present (e.g. when used with a vintage
|
| 720 |
+
Python 1.5.2 installation) top-level functions are not listed.
|
| 721 |
+
|
| 722 |
+
(Hmm... Any distribution of IDLE 0.5 should probably include a copy
|
| 723 |
+
of the new pyclbr.py!)
|
| 724 |
+
|
| 725 |
+
* AutoIndent.py:
|
| 726 |
+
Fix off-by-one error in Tim's recent change to comment_region(): the
|
| 727 |
+
list of lines returned by get_region() contains an empty line at the
|
| 728 |
+
end representing the start of the next line, and this shouldn't be
|
| 729 |
+
commented out!
|
| 730 |
+
|
| 731 |
+
* CallTips.py:
|
| 732 |
+
Mark Hammond writes: Here is another change that allows it to work for
|
| 733 |
+
class creation - tries to locate an __init__ function. Also updated
|
| 734 |
+
the test code to reflect your new "***" change.
|
| 735 |
+
|
| 736 |
+
* CallTipWindow.py:
|
| 737 |
+
Mark Hammond writes: Tim's suggestion of copying the font for the
|
| 738 |
+
CallTipWindow from the text control makes sense, and actually makes
|
| 739 |
+
the control look better IMO.
|
| 740 |
+
|
| 741 |
+
Wed Jun 9 20:34:57 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 742 |
+
|
| 743 |
+
* CallTips.py:
|
| 744 |
+
Append "..." if the appropriate flag (for varargs) in co_flags is set.
|
| 745 |
+
Ditto "***" for kwargs.
|
| 746 |
+
|
| 747 |
+
Tue Jun 8 13:06:07 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 748 |
+
|
| 749 |
+
* ReplaceDialog.py:
|
| 750 |
+
Hmm... Tim didn't turn "replace all" into a single undo block.
|
| 751 |
+
I think I like it better if it os, so here.
|
| 752 |
+
|
| 753 |
+
* ReplaceDialog.py: Tim Peters: made replacement atomic for undo/redo.
|
| 754 |
+
|
| 755 |
+
* AutoIndent.py: Tim Peters:
|
| 756 |
+
|
| 757 |
+
+ Set usetabs=1. Editing pyclbr.py was driving me nuts <0.6 wink>.
|
| 758 |
+
usetabs=1 is the Emacs pymode default too, and thanks to indentwidth !=
|
| 759 |
+
tabwidth magical usetabs disabling, new files are still created with tabs
|
| 760 |
+
turned off. The only implication is that if you open a file whose first
|
| 761 |
+
indent is a single tab, IDLE will now magically use tabs for that file (and
|
| 762 |
+
set indentwidth to 8). Note that the whole scheme doesn't work right for
|
| 763 |
+
PythonWin, though, since Windows users typically set tabwidth to 4; Mark
|
| 764 |
+
probably has to hide the IDLE algorithm from them (which he already knows).
|
| 765 |
+
|
| 766 |
+
+ Changed comment_region_event to stick "##" in front of every line. The
|
| 767 |
+
"holes" previously left on blank lines were visually confusing (made it
|
| 768 |
+
needlessly hard to figure out what to uncomment later).
|
| 769 |
+
|
| 770 |
+
Mon Jun 7 15:38:40 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 771 |
+
|
| 772 |
+
* TreeWidget.py, ObjectBrowser.py:
|
| 773 |
+
Remove unnecessary reference to pyclbr from test() code.
|
| 774 |
+
|
| 775 |
+
* PyParse.py: Tim Peters:
|
| 776 |
+
|
| 777 |
+
Smarter logic for finding a parse synch point.
|
| 778 |
+
|
| 779 |
+
Does a half to a fifth the work in normal cases; don't notice the speedup,
|
| 780 |
+
but makes more breathing room for other extensions.
|
| 781 |
+
|
| 782 |
+
Speeds terrible cases by at least a factor of 10. "Terrible" == e.g. you put
|
| 783 |
+
""" at the start of Tkinter.py, undo it, zoom to the bottom, and start
|
| 784 |
+
typing in code. Used to take about 8 seconds for ENTER to respond, now some
|
| 785 |
+
large fraction of a second. The new code gets indented correctly, despite
|
| 786 |
+
that it all remains "string colored" until the colorizer catches up (after
|
| 787 |
+
which, ENTER appears instantaneous again).
|
| 788 |
+
|
| 789 |
+
Fri Jun 4 19:21:19 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 790 |
+
|
| 791 |
+
* extend.py: Might as well enable CallTips by default.
|
| 792 |
+
If there are too many complaints I'll remove it again or fix it.
|
| 793 |
+
|
| 794 |
+
Thu Jun 3 14:32:16 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 795 |
+
|
| 796 |
+
* AutoIndent.py, EditorWindow.py, PyParse.py:
|
| 797 |
+
New offerings by Tim Peters; he writes:
|
| 798 |
+
|
| 799 |
+
IDLE is now the first Python editor in the Universe not confused by my
|
| 800 |
+
doctest.py <wink>.
|
| 801 |
+
|
| 802 |
+
As threatened, this defines IDLE's is_char_in_string function as a
|
| 803 |
+
method of EditorWindow. You just need to define one similarly in
|
| 804 |
+
whatever it is you pass as editwin to AutoIndent; looking at the
|
| 805 |
+
EditorWindow.py part of the patch should make this clear.
|
| 806 |
+
|
| 807 |
+
* GrepDialog.py: Enclose pattern in quotes in status message.
|
| 808 |
+
|
| 809 |
+
* CallTips.py:
|
| 810 |
+
Mark Hammond fixed some comments and improved the way the tip text is
|
| 811 |
+
constructed.
|
| 812 |
+
|
| 813 |
+
Wed Jun 2 18:18:57 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 814 |
+
|
| 815 |
+
* CallTips.py:
|
| 816 |
+
My fix to Mark's code: restore the universal check on <KeyRelease>.
|
| 817 |
+
Always cancel on <Key-Escape> or <ButtonPress>.
|
| 818 |
+
|
| 819 |
+
* CallTips.py:
|
| 820 |
+
A version that Mark Hammond posted to the newsgroup. Has some newer
|
| 821 |
+
stuff for getting the tip. Had to fix the Key-( and Key-) events
|
| 822 |
+
for Unix. Will have to re-apply my patch for catching KeyRelease and
|
| 823 |
+
ButtonRelease events.
|
| 824 |
+
|
| 825 |
+
* CallTipWindow.py, CallTips.py:
|
| 826 |
+
Call tips by Mark Hammond (plus tiny fix by me.)
|
| 827 |
+
|
| 828 |
+
* IdleHistory.py:
|
| 829 |
+
Changes by Mark Hammond: (1) support optional output_sep argument to
|
| 830 |
+
the constructor so he can eliminate the sys.ps2 that PythonWin leaves
|
| 831 |
+
in the source; (2) remove duplicate history items.
|
| 832 |
+
|
| 833 |
+
* AutoIndent.py:
|
| 834 |
+
Changes by Mark Hammond to allow using IDLE extensions in PythonWin as
|
| 835 |
+
well: make three dialog routines instance variables.
|
| 836 |
+
|
| 837 |
+
* EditorWindow.py:
|
| 838 |
+
Change by Mark Hammond to allow using IDLE extensions in PythonWin as
|
| 839 |
+
well: make three dialog routines instance variables.
|
| 840 |
+
|
| 841 |
+
Tue Jun 1 20:06:44 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 842 |
+
|
| 843 |
+
* AutoIndent.py: Hah! A fix of my own to Tim's code!
|
| 844 |
+
Unix bindings for <<toggle-tabs>> and <<change-indentwidth>> were
|
| 845 |
+
missing, and somehow that meant the events were never generated,
|
| 846 |
+
even though they were in the menu. The new Unix bindings are now
|
| 847 |
+
the same as the Windows bindings (M-t and M-u).
|
| 848 |
+
|
| 849 |
+
* AutoIndent.py, PyParse.py, PyShell.py: Tim Peters again:
|
| 850 |
+
|
| 851 |
+
The new version (attached) is fast enough all the time in every real module
|
| 852 |
+
I have <whew!>. You can make it slow by, e.g., creating an open list with
|
| 853 |
+
5,000 90-character identifiers (+ trailing comma) each on its own line, then
|
| 854 |
+
adding an item to the end -- but that still consumes less than a second on
|
| 855 |
+
my P5-166. Response time in real code appears instantaneous.
|
| 856 |
+
|
| 857 |
+
Fixed some bugs.
|
| 858 |
+
|
| 859 |
+
New feature: when hitting ENTER and the cursor is beyond the line's leading
|
| 860 |
+
indentation, whitespace is removed on both sides of the cursor; before
|
| 861 |
+
whitespace was removed only on the left; e.g., assuming the cursor is
|
| 862 |
+
between the comma and the space:
|
| 863 |
+
|
| 864 |
+
def something(arg1, arg2):
|
| 865 |
+
^ cursor to the left of here, and hit ENTER
|
| 866 |
+
arg2): # new line used to end up here
|
| 867 |
+
arg2): # but now lines up the way you expect
|
| 868 |
+
|
| 869 |
+
New hack: AutoIndent has grown a context_use_ps1 Boolean config option,
|
| 870 |
+
defaulting to 0 (false) and set to 1 (only) by PyShell. Reason: handling
|
| 871 |
+
the fancy stuff requires looking backward for a parsing synch point; ps1
|
| 872 |
+
lines are the only sensible thing to look for in a shell window, but are a
|
| 873 |
+
bad thing to look for in a file window (ps1 lines show up in my module
|
| 874 |
+
docstrings often). PythonWin's shell should set this true too.
|
| 875 |
+
|
| 876 |
+
Persistent problem: strings containing def/class can still screw things up
|
| 877 |
+
completely. No improvement. Simplest workaround is on the user's head, and
|
| 878 |
+
consists of inserting e.g.
|
| 879 |
+
|
| 880 |
+
def _(): pass
|
| 881 |
+
|
| 882 |
+
(or any other def/class) after the end of the multiline string that's
|
| 883 |
+
screwing them up. This is especially irksome because IDLE's syntax coloring
|
| 884 |
+
is *not* confused, so when this happens the colors don't match the
|
| 885 |
+
indentation behavior they see.
|
| 886 |
+
|
| 887 |
+
* AutoIndent.py: Tim Peters again:
|
| 888 |
+
|
| 889 |
+
[Tim, after adding some bracket smarts to AutoIndent.py]
|
| 890 |
+
> ...
|
| 891 |
+
> What it can't possibly do without reparsing large gobs of text is
|
| 892 |
+
> suggest a reasonable indent level after you've *closed* a bracket
|
| 893 |
+
> left open on some previous line.
|
| 894 |
+
> ...
|
| 895 |
+
|
| 896 |
+
The attached can, and actually fast enough to use -- most of the time. The
|
| 897 |
+
code is tricky beyond belief to achieve that, but it works so far; e.g.,
|
| 898 |
+
|
| 899 |
+
return len(string.expandtabs(str[self.stmt_start :
|
| 900 |
+
^ indents to caret
|
| 901 |
+
i],
|
| 902 |
+
^ indents to caret
|
| 903 |
+
self.tabwidth)) + 1
|
| 904 |
+
^ indents to caret
|
| 905 |
+
|
| 906 |
+
It's about as smart as pymode now, wrt both bracket and backslash
|
| 907 |
+
continuation rules. It does require reparsing large gobs of text, and if it
|
| 908 |
+
happens to find something that looks like a "def" or "class" or sys.ps1
|
| 909 |
+
buried in a multiline string, but didn't suck up enough preceding text to
|
| 910 |
+
see the start of the string, it's completely hosed. I can't repair that --
|
| 911 |
+
it's just too slow to reparse from the start of the file all the time.
|
| 912 |
+
|
| 913 |
+
AutoIndent has grown a new num_context_lines tuple attribute that controls
|
| 914 |
+
how far to look back, and-- like other params --this could/should be made
|
| 915 |
+
user-overridable at startup and per-file on the fly.
|
| 916 |
+
|
| 917 |
+
* PyParse.py: New file by Tim Peters:
|
| 918 |
+
|
| 919 |
+
One new file in the attached, PyParse.py. The LineStudier (whatever it was
|
| 920 |
+
called <wink>) class was removed from AutoIndent; PyParse subsumes its
|
| 921 |
+
functionality.
|
| 922 |
+
|
| 923 |
+
* AutoIndent.py: Tim Peters keeps revising this module (more to come):
|
| 924 |
+
|
| 925 |
+
Removed "New tabwidth" menu binding.
|
| 926 |
+
|
| 927 |
+
Added "a tab means how many spaces?" dialog to block tabify and untabify. I
|
| 928 |
+
think prompting for this is good now: they're usually at-most-once-per-file
|
| 929 |
+
commands, and IDLE can't let them change tabwidth from the Tk default
|
| 930 |
+
anymore, so IDLE can no longer presume to have any idea what a tab means.
|
| 931 |
+
|
| 932 |
+
Irony: for the purpose of keeping comments aligned via tabs, Tk's
|
| 933 |
+
non-default approach is much nicer than the Emacs/Notepad/Codewright/vi/etc
|
| 934 |
+
approach.
|
| 935 |
+
|
| 936 |
+
* EditorWindow.py:
|
| 937 |
+
1. Catch NameError on import (could be raised by case mismatch on Windows).
|
| 938 |
+
2. No longer need to reset pyclbr cache and show watch cursor when calling
|
| 939 |
+
ClassBrowser -- the ClassBrowser takes care of pyclbr and the TreeWidget
|
| 940 |
+
takes care of the watch cursor.
|
| 941 |
+
3. Reset the focus to the current window after error message about class
|
| 942 |
+
browser on buffer without filename.
|
| 943 |
+
|
| 944 |
+
* Icons/minusnode.gif, Icons/plusnode.gif: Missed a few.
|
| 945 |
+
|
| 946 |
+
* ClassBrowser.py, PathBrowser.py: Rewritten based on TreeWidget.py
|
| 947 |
+
|
| 948 |
+
* ObjectBrowser.py: Object browser, based on TreeWidget.py.
|
| 949 |
+
|
| 950 |
+
* TreeWidget.py: Tree widget done right.
|
| 951 |
+
|
| 952 |
+
* ToolTip.py: As yet unused code for tool tips.
|
| 953 |
+
|
| 954 |
+
* ScriptBinding.py:
|
| 955 |
+
Ensure sys.argv[0] is the script name on Run Script.
|
| 956 |
+
|
| 957 |
+
* ZoomHeight.py: Move zoom height functionality to separate function.
|
| 958 |
+
|
| 959 |
+
* Icons/folder.gif, Icons/openfolder.gif, Icons/python.gif, Icons/tk.gif:
|
| 960 |
+
A few icons used by ../TreeWidget.py and its callers.
|
| 961 |
+
|
| 962 |
+
* AutoIndent.py: New version by Tim Peters improves block opening test.
|
| 963 |
+
|
| 964 |
+
Fri May 21 04:46:17 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 965 |
+
|
| 966 |
+
* Attic/History.py, PyShell.py: Rename History to IdleHistory.
|
| 967 |
+
Add isatty() to pseudo files.
|
| 968 |
+
|
| 969 |
+
* StackViewer.py: Make initial stack viewer wider
|
| 970 |
+
|
| 971 |
+
* TODO.txt: New wishes
|
| 972 |
+
|
| 973 |
+
* AutoIndent.py, EditorWindow.py, PyShell.py:
|
| 974 |
+
Much improved autoindent and handling of tabs,
|
| 975 |
+
by Tim Peters.
|
| 976 |
+
|
| 977 |
+
Mon May 3 15:49:52 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 978 |
+
|
| 979 |
+
* AutoIndent.py, EditorWindow.py, FormatParagraph.py, UndoDelegator.py:
|
| 980 |
+
Tim Peters writes:
|
| 981 |
+
|
| 982 |
+
I'm still unsure, but couldn't stand the virtual event trickery so tried a
|
| 983 |
+
different sin (adding undo_block_start/stop methods to the Text instance in
|
| 984 |
+
EditorWindow.py). Like it or not, it's efficient and works <wink>. Better
|
| 985 |
+
idea?
|
| 986 |
+
|
| 987 |
+
Give the attached a whirl. Even if you hate the implementation, I think
|
| 988 |
+
you'll like the results. Think I caught all the "block edit" cmds,
|
| 989 |
+
including Format Paragraph, plus subtler ones involving smart indents and
|
| 990 |
+
backspacing.
|
| 991 |
+
|
| 992 |
+
* WidgetRedirector.py: Tim Peters writes:
|
| 993 |
+
|
| 994 |
+
[W]hile trying to dope out how redirection works, stumbled into two
|
| 995 |
+
possible glitches. In the first, it doesn't appear to make sense to try to
|
| 996 |
+
rename a command that's already been destroyed; in the second, the name
|
| 997 |
+
"previous" doesn't really bring to mind "ignore the previous value" <wink>.
|
| 998 |
+
|
| 999 |
+
Fri Apr 30 19:39:25 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1000 |
+
|
| 1001 |
+
* __init__.py: Support for using idle as a package.
|
| 1002 |
+
|
| 1003 |
+
* PathBrowser.py:
|
| 1004 |
+
Avoid listing files more than once (e.g. foomodule.so has two hits:
|
| 1005 |
+
once for foo + module.so, once for foomodule + .so).
|
| 1006 |
+
|
| 1007 |
+
Mon Apr 26 22:20:38 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1008 |
+
|
| 1009 |
+
* ChangeLog, ColorDelegator.py, PyShell.py: Tim Peters strikes again:
|
| 1010 |
+
|
| 1011 |
+
Ho ho ho -- that's trickier than it sounded! The colorizer is working with
|
| 1012 |
+
"line.col" strings instead of Text marks, and the absolute coordinates of
|
| 1013 |
+
the point of interest can change across the self.update call (voice of
|
| 1014 |
+
baffled experience, when two quick backspaces no longer fooled it, but a
|
| 1015 |
+
backspace followed by a quick ENTER did <wink>).
|
| 1016 |
+
|
| 1017 |
+
Anyway, the attached appears to do the trick. CPU usage goes way up when
|
| 1018 |
+
typing quickly into a long triple-quoted string, but the latency is fine for
|
| 1019 |
+
me (a relatively fast typist on a relatively slow machine). Most of the
|
| 1020 |
+
changes here are left over from reducing the # of vrbl names to help me
|
| 1021 |
+
reason about the logic better; I hope the code is a *little* easier to
|
| 1022 |
+
|
| 1023 |
+
Fri Apr 23 14:01:25 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1024 |
+
|
| 1025 |
+
* EditorWindow.py:
|
| 1026 |
+
Provide full arguments to __import__ so it works in packagized IDLE.
|
| 1027 |
+
|
| 1028 |
+
Thu Apr 22 23:20:17 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1029 |
+
|
| 1030 |
+
* help.txt:
|
| 1031 |
+
Bunch of updates necessary due to recent changes; added docs for File
|
| 1032 |
+
menu, command line and color preferences.
|
| 1033 |
+
|
| 1034 |
+
* Bindings.py: Remove obsolete 'script' menu.
|
| 1035 |
+
|
| 1036 |
+
* TODO.txt: Several wishes fulfilled.
|
| 1037 |
+
|
| 1038 |
+
* OutputWindow.py:
|
| 1039 |
+
Moved classes OnDemandOutputWindow and PseudoFile here,
|
| 1040 |
+
from ScriptBinding.py where they are no longer needed.
|
| 1041 |
+
|
| 1042 |
+
* ScriptBinding.py:
|
| 1043 |
+
Mostly rewritten. Instead of the old Run module and Debug module,
|
| 1044 |
+
there are two new commands:
|
| 1045 |
+
|
| 1046 |
+
Import module (F5) imports or reloads the module and also adds its
|
| 1047 |
+
name to the __main__ namespace. This gets executed in the PyShell
|
| 1048 |
+
window under control of its debug settings.
|
| 1049 |
+
|
| 1050 |
+
Run script (Control-F5) is similar but executes the contents of the
|
| 1051 |
+
file directly in the __main__ namespace.
|
| 1052 |
+
|
| 1053 |
+
* PyShell.py: Nits: document use of $IDLESTARTUP; display idle version
|
| 1054 |
+
|
| 1055 |
+
* idlever.py: New version to celebrate new command line
|
| 1056 |
+
|
| 1057 |
+
* OutputWindow.py: Added flush(), for completeness.
|
| 1058 |
+
|
| 1059 |
+
* PyShell.py:
|
| 1060 |
+
A lot of changes to make the command line more useful. You can now do:
|
| 1061 |
+
idle.py -e file ... -- to edit files
|
| 1062 |
+
idle.py script arg ... -- to run a script
|
| 1063 |
+
idle.py -c cmd arg ... -- to run a command
|
| 1064 |
+
Other options, see also the usage message (also new!) for more details:
|
| 1065 |
+
-d -- enable debugger
|
| 1066 |
+
-s -- run $IDLESTARTUP or $PYTHONSTARTUP
|
| 1067 |
+
-t title -- set Python Shell window's title
|
| 1068 |
+
sys.argv is set accordingly, unless -e is used.
|
| 1069 |
+
sys.path is absolutized, and all relevant paths are inserted into it.
|
| 1070 |
+
|
| 1071 |
+
Other changes:
|
| 1072 |
+
- the environment in which commands are executed is now the
|
| 1073 |
+
__main__ module
|
| 1074 |
+
- explicitly save sys.stdout etc., don't restore from sys.__stdout__
|
| 1075 |
+
- new interpreter methods execsource(), execfile(), stuffsource()
|
| 1076 |
+
- a few small nits
|
| 1077 |
+
|
| 1078 |
+
* TODO.txt:
|
| 1079 |
+
Some more TODO items. Made up my mind about command line args,
|
| 1080 |
+
Run/Import, __main__.
|
| 1081 |
+
|
| 1082 |
+
* ColorDelegator.py:
|
| 1083 |
+
Super-elegant patch by Tim Peters that speeds up colorization
|
| 1084 |
+
dramatically (up to 15 times he claims). Works by reading more than
|
| 1085 |
+
one line at a time, up to 100-line chunks (starting with one line and
|
| 1086 |
+
then doubling up to the limit). On a typical machine (e.g. Tim's
|
| 1087 |
+
P5-166) this doesn't reduce interactive responsiveness in a noticeable
|
| 1088 |
+
way.
|
| 1089 |
+
|
| 1090 |
+
Wed Apr 21 15:49:34 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1091 |
+
|
| 1092 |
+
* ColorDelegator.py:
|
| 1093 |
+
Patch by Tim Peters to speed up colorizing of big multiline strings.
|
| 1094 |
+
|
| 1095 |
+
Tue Apr 20 17:32:52 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1096 |
+
|
| 1097 |
+
* extend.txt:
|
| 1098 |
+
For an event 'foo-bar', the corresponding method must be called
|
| 1099 |
+
foo_bar_event(). Therefore, fix the references to zoom_height() in
|
| 1100 |
+
the example.
|
| 1101 |
+
|
| 1102 |
+
* IdlePrefs.py: Restored the original IDLE color scheme.
|
| 1103 |
+
|
| 1104 |
+
* PyShell.py, IdlePrefs.py, ColorDelegator.py, EditorWindow.py:
|
| 1105 |
+
Color preferences code by Loren Luke (massaged by me somewhat)
|
| 1106 |
+
|
| 1107 |
+
* SearchEngine.py:
|
| 1108 |
+
Patch by Mark Favas: it fixes the search engine behaviour where an
|
| 1109 |
+
unsuccessful search wraps around and re-searches that part of the file
|
| 1110 |
+
between the start of the search and the end of the file - only really
|
| 1111 |
+
an issue for very large files, but... (also removes a redundant
|
| 1112 |
+
m.span() call).
|
| 1113 |
+
|
| 1114 |
+
Mon Apr 19 16:26:02 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1115 |
+
|
| 1116 |
+
* TODO.txt: A few wishes are now fulfilled.
|
| 1117 |
+
|
| 1118 |
+
* AutoIndent.py: Tim Peters implements some of my wishes:
|
| 1119 |
+
|
| 1120 |
+
o Makes the tab key intelligently insert spaces when appropriate
|
| 1121 |
+
(see Help list banter twixt David Ascher and me; idea stolen from
|
| 1122 |
+
every other editor on earth <wink>).
|
| 1123 |
+
|
| 1124 |
+
o newline_and_indent_event trims trailing whitespace on the old
|
| 1125 |
+
line (pymode and Codewright).
|
| 1126 |
+
|
| 1127 |
+
o newline_and_indent_event no longer fooled by trailing whitespace or
|
| 1128 |
+
comment after ":" (pymode, PTUI).
|
| 1129 |
+
|
| 1130 |
+
o newline_and_indent_event now reduces the new line's indentation after
|
| 1131 |
+
return, break, continue, raise and pass stmts (pymode).
|
| 1132 |
+
|
| 1133 |
+
The last two are easy to fool in the presence of strings &
|
| 1134 |
+
continuations, but pymode requires Emacs's high-powered C parsing
|
| 1135 |
+
functions to avoid that in finite time.
|
| 1136 |
+
|
| 1137 |
+
======================================================================
|
| 1138 |
+
Python release 1.5.2c1, IDLE version 0.4
|
| 1139 |
+
======================================================================
|
| 1140 |
+
|
| 1141 |
+
Wed Apr 7 18:41:59 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1142 |
+
|
| 1143 |
+
* README.txt, NEWS.txt: New version.
|
| 1144 |
+
|
| 1145 |
+
* idlever.py: Version bump awaiting impending new release.
|
| 1146 |
+
(Not much has changed :-( )
|
| 1147 |
+
|
| 1148 |
+
Mon Mar 29 14:52:28 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1149 |
+
|
| 1150 |
+
* ScriptBinding.py, PyShell.py:
|
| 1151 |
+
At Tim Peters' recommendation, add a dummy flush() method to
|
| 1152 |
+
PseudoFile.
|
| 1153 |
+
|
| 1154 |
+
Thu Mar 11 23:21:23 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1155 |
+
|
| 1156 |
+
* PathBrowser.py: Don't crash when sys.path contains an empty string.
|
| 1157 |
+
|
| 1158 |
+
* Attic/Outline.py: This file was never supposed to be part of IDLE.
|
| 1159 |
+
|
| 1160 |
+
* PathBrowser.py:
|
| 1161 |
+
- Don't crash in the case where a superclass is a string instead of a
|
| 1162 |
+
pyclbr.Class object; this can happen when the superclass is
|
| 1163 |
+
unrecognizable (to pyclbr), e.g. when module renaming is used.
|
| 1164 |
+
|
| 1165 |
+
- Show a watch cursor when calling pyclbr (since it may take a while
|
| 1166 |
+
recursively parsing imported modules!).
|
| 1167 |
+
|
| 1168 |
+
Wed Mar 10 05:18:02 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1169 |
+
|
| 1170 |
+
* EditorWindow.py, Bindings.py: Add PathBrowser to File module
|
| 1171 |
+
|
| 1172 |
+
* PathBrowser.py: "Path browser" - 4 scrolled lists displaying:
|
| 1173 |
+
directories on sys.path
|
| 1174 |
+
modules in selected directory
|
| 1175 |
+
classes in selected module
|
| 1176 |
+
methods of selected class
|
| 1177 |
+
|
| 1178 |
+
Single clicking in a directory, module or class item updates the next
|
| 1179 |
+
column with info about the selected item. Double clicking in a
|
| 1180 |
+
module, class or method item opens the file (and selects the clicked
|
| 1181 |
+
item if it is a class or method).
|
| 1182 |
+
|
| 1183 |
+
I guess eventually I should be using a tree widget for this, but the
|
| 1184 |
+
ones I've seen don't work well enough, so for now I use the old
|
| 1185 |
+
Smalltalk or NeXT style multi-column hierarchical browser.
|
| 1186 |
+
|
| 1187 |
+
* MultiScrolledLists.py:
|
| 1188 |
+
New utility: multiple scrolled lists in parallel
|
| 1189 |
+
|
| 1190 |
+
* ScrolledList.py: - White background.
|
| 1191 |
+
- Display "(None)" (or text of your choosing) when empty.
|
| 1192 |
+
- Don't set the focus.
|
| 1193 |
+
|
| 1194 |
+
======================================================================
|
| 1195 |
+
Python release 1.5.2b2, IDLE version 0.3
|
| 1196 |
+
======================================================================
|
| 1197 |
+
|
| 1198 |
+
Wed Feb 17 22:47:41 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1199 |
+
|
| 1200 |
+
* NEWS.txt: News in 0.3.
|
| 1201 |
+
|
| 1202 |
+
* README.txt, idlever.py: Bump version to 0.3.
|
| 1203 |
+
|
| 1204 |
+
* EditorWindow.py:
|
| 1205 |
+
After all, we don't need to call the callbacks ourselves!
|
| 1206 |
+
|
| 1207 |
+
* WindowList.py:
|
| 1208 |
+
When deleting, call the callbacks *after* deleting the window from our list!
|
| 1209 |
+
|
| 1210 |
+
* EditorWindow.py:
|
| 1211 |
+
Fix up the Windows menu via the new callback mechanism instead of
|
| 1212 |
+
depending on menu post commands (which don't work when the menu is
|
| 1213 |
+
torn off).
|
| 1214 |
+
|
| 1215 |
+
* WindowList.py:
|
| 1216 |
+
Support callbacks to patch up Windows menus everywhere.
|
| 1217 |
+
|
| 1218 |
+
* ChangeLog: Oh, why not. Checking in the Emacs-generated change log.
|
| 1219 |
+
|
| 1220 |
+
Tue Feb 16 22:34:17 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1221 |
+
|
| 1222 |
+
* ScriptBinding.py:
|
| 1223 |
+
Only pop up the stack viewer when requested in the Debug menu.
|
| 1224 |
+
|
| 1225 |
+
Mon Feb 8 22:27:49 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1226 |
+
|
| 1227 |
+
* WindowList.py: Don't crash if a window no longer exists.
|
| 1228 |
+
|
| 1229 |
+
* TODO.txt: Restructured a bit.
|
| 1230 |
+
|
| 1231 |
+
Mon Feb 1 23:06:17 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1232 |
+
|
| 1233 |
+
* PyShell.py: Add current dir or paths of file args to sys.path.
|
| 1234 |
+
|
| 1235 |
+
* Debugger.py: Add canonic() function -- for brand new bdb.py feature.
|
| 1236 |
+
|
| 1237 |
+
* StackViewer.py: Protect against accessing an empty stack.
|
| 1238 |
+
|
| 1239 |
+
Fri Jan 29 20:44:45 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1240 |
+
|
| 1241 |
+
* ZoomHeight.py:
|
| 1242 |
+
Use only the height to decide whether to zoom in or out.
|
| 1243 |
+
|
| 1244 |
+
Thu Jan 28 22:24:30 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1245 |
+
|
| 1246 |
+
* EditorWindow.py, FileList.py:
|
| 1247 |
+
Make sure the Tcl variables are shared between windows.
|
| 1248 |
+
|
| 1249 |
+
* PyShell.py, EditorWindow.py, Bindings.py:
|
| 1250 |
+
Move menu/key binding code from Bindings.py to EditorWindow.py,
|
| 1251 |
+
with changed APIs -- it makes much more sense there.
|
| 1252 |
+
Also add a new feature: if the first character of a menu label is
|
| 1253 |
+
a '!', it gets a checkbox. Checkboxes are bound to Boolean Tcl variables
|
| 1254 |
+
that can be accessed through the new getvar/setvar/getrawvar API;
|
| 1255 |
+
the variable is named after the event to which the menu is bound.
|
| 1256 |
+
|
| 1257 |
+
* Debugger.py: Add Quit button to the debugger window.
|
| 1258 |
+
|
| 1259 |
+
* SearchDialog.py:
|
| 1260 |
+
When find_again() finds exactly the current selection, it's a failure.
|
| 1261 |
+
|
| 1262 |
+
* idle.py, Attic/idle: Rename idle -> idle.py
|
| 1263 |
+
|
| 1264 |
+
Mon Jan 18 15:18:57 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1265 |
+
|
| 1266 |
+
* EditorWindow.py, WindowList.py: Only deiconify when iconic.
|
| 1267 |
+
|
| 1268 |
+
* TODO.txt: Misc
|
| 1269 |
+
|
| 1270 |
+
Tue Jan 12 22:14:34 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1271 |
+
|
| 1272 |
+
* testcode.py, Attic/test.py:
|
| 1273 |
+
Renamed test.py to testcode.py so one can import Python's
|
| 1274 |
+
test package from inside IDLE. (Suggested by Jack Jansen.)
|
| 1275 |
+
|
| 1276 |
+
* EditorWindow.py, ColorDelegator.py:
|
| 1277 |
+
Hack to close a window that is colorizing.
|
| 1278 |
+
|
| 1279 |
+
* Separator.py: Vladimir Marangozov's patch:
|
| 1280 |
+
The separator dances too much and seems to jump by arbitrary amounts
|
| 1281 |
+
in arbitrary directions when I try to move it for resizing the frames.
|
| 1282 |
+
This patch makes it more quiet.
|
| 1283 |
+
|
| 1284 |
+
Mon Jan 11 14:52:40 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1285 |
+
|
| 1286 |
+
* TODO.txt: Some requests have been fulfilled.
|
| 1287 |
+
|
| 1288 |
+
* EditorWindow.py:
|
| 1289 |
+
Set the cursor to a watch when opening the class browser (which may
|
| 1290 |
+
take quite a while, browsing multiple files).
|
| 1291 |
+
|
| 1292 |
+
Newer, better center() -- but assumes no wrapping.
|
| 1293 |
+
|
| 1294 |
+
* SearchBinding.py:
|
| 1295 |
+
Got rid of debug print statement in goto_line_event().
|
| 1296 |
+
|
| 1297 |
+
* ScriptBinding.py:
|
| 1298 |
+
I think I like it better if it prints the traceback even when it displays
|
| 1299 |
+
the stack viewer.
|
| 1300 |
+
|
| 1301 |
+
* Debugger.py: Bind ESC to close-window.
|
| 1302 |
+
|
| 1303 |
+
* ClassBrowser.py: Use a HSeparator between the classes and the items.
|
| 1304 |
+
Make the list of classes wider by default (40 chars).
|
| 1305 |
+
Bind ESC to close-window.
|
| 1306 |
+
|
| 1307 |
+
* Separator.py:
|
| 1308 |
+
Separator classes (draggable divider between two panes).
|
| 1309 |
+
|
| 1310 |
+
Sat Jan 9 22:01:33 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1311 |
+
|
| 1312 |
+
* WindowList.py:
|
| 1313 |
+
Don't traceback when wakeup() is called when the window has been destroyed.
|
| 1314 |
+
This can happen when a torn-of Windows menu references closed windows.
|
| 1315 |
+
And Tim Peters claims that the Windows menu is his favorite to tear off...
|
| 1316 |
+
|
| 1317 |
+
* EditorWindow.py: Allow tearing off of the Windows menu.
|
| 1318 |
+
|
| 1319 |
+
* StackViewer.py: Close on ESC.
|
| 1320 |
+
|
| 1321 |
+
* help.txt: Updated a bunch of things (it was mostly still 0.1!)
|
| 1322 |
+
|
| 1323 |
+
* extend.py: Added ScriptBinding to standard bindings.
|
| 1324 |
+
|
| 1325 |
+
* ScriptBinding.py:
|
| 1326 |
+
This now actually works. See doc string. It can run a module (i.e.
|
| 1327 |
+
import or reload) or debug it (same with debugger control). Output
|
| 1328 |
+
goes to a fresh output window, only created when needed.
|
| 1329 |
+
|
| 1330 |
+
======================================================================
|
| 1331 |
+
Python release 1.5.2b1, IDLE version 0.2
|
| 1332 |
+
======================================================================
|
| 1333 |
+
|
| 1334 |
+
Fri Jan 8 17:26:02 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1335 |
+
|
| 1336 |
+
* README.txt, NEWS.txt: What's new in this release.
|
| 1337 |
+
|
| 1338 |
+
* Bindings.py, PyShell.py:
|
| 1339 |
+
Paul Prescod's patches to allow the stack viewer to pop up when a
|
| 1340 |
+
traceback is printed.
|
| 1341 |
+
|
| 1342 |
+
Thu Jan 7 00:12:15 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1343 |
+
|
| 1344 |
+
* FormatParagraph.py:
|
| 1345 |
+
Change paragraph width limit to 70 (like Emacs M-Q).
|
| 1346 |
+
|
| 1347 |
+
* README.txt:
|
| 1348 |
+
Separating TODO from README. Slight reformulation of features. No
|
| 1349 |
+
exact release date.
|
| 1350 |
+
|
| 1351 |
+
* TODO.txt: Separating TODO from README.
|
| 1352 |
+
|
| 1353 |
+
Mon Jan 4 21:19:09 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1354 |
+
|
| 1355 |
+
* FormatParagraph.py:
|
| 1356 |
+
Hm. There was a boundary condition error at the end of the file too.
|
| 1357 |
+
|
| 1358 |
+
* SearchBinding.py: Hm. Add Unix binding for replace, too.
|
| 1359 |
+
|
| 1360 |
+
* keydefs.py: Ran eventparse.py again.
|
| 1361 |
+
|
| 1362 |
+
* FormatParagraph.py: Added Unix Meta-q key binding;
|
| 1363 |
+
fix find_paragraph when at start of file.
|
| 1364 |
+
|
| 1365 |
+
* AutoExpand.py: Added Meta-/ binding for Unix as alt for Alt-/.
|
| 1366 |
+
|
| 1367 |
+
* SearchBinding.py:
|
| 1368 |
+
Add unix binding for grep (otherwise the menu entry doesn't work!)
|
| 1369 |
+
|
| 1370 |
+
* ZoomHeight.py: Adjusted Unix height to work with fvwm96. :=(
|
| 1371 |
+
|
| 1372 |
+
* GrepDialog.py: Need to import sys!
|
| 1373 |
+
|
| 1374 |
+
* help.txt, extend.txt, README.txt: Formatted some paragraphs
|
| 1375 |
+
|
| 1376 |
+
* extend.py, FormatParagraph.py:
|
| 1377 |
+
Add new extension to reformat a (text) paragraph.
|
| 1378 |
+
|
| 1379 |
+
* ZoomHeight.py: Typo in Win specific height setting.
|
| 1380 |
+
|
| 1381 |
+
Sun Jan 3 00:47:35 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1382 |
+
|
| 1383 |
+
* AutoIndent.py: Added something like Tim Peters' backspace patch.
|
| 1384 |
+
|
| 1385 |
+
* ZoomHeight.py: Adapted to Unix (i.e., more hardcoded constants).
|
| 1386 |
+
|
| 1387 |
+
Sat Jan 2 21:28:54 1999 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1388 |
+
|
| 1389 |
+
* keydefs.py, idlever.py, idle.pyw, idle.bat, help.txt, extend.txt, extend.py, eventparse.py, ZoomHeight.py, WindowList.py, UndoDelegator.py, StackViewer.py, SearchEngine.py, SearchDialogBase.py, SearchDialog.py, ScrolledList.py, SearchBinding.py, ScriptBinding.py, ReplaceDialog.py, Attic/README, README.txt, PyShell.py, Attic/PopupMenu.py, OutputWindow.py, IOBinding.py, Attic/HelpWindow.py, History.py, GrepDialog.py, FileList.py, FrameViewer.py, EditorWindow.py, Debugger.py, Delegator.py, ColorDelegator.py, Bindings.py, ClassBrowser.py, AutoExpand.py, AutoIndent.py:
|
| 1390 |
+
Checking in IDLE 0.2.
|
| 1391 |
+
|
| 1392 |
+
Much has changed -- too much, in fact, to write down.
|
| 1393 |
+
The big news is that there's a standard way to write IDLE extensions;
|
| 1394 |
+
see extend.txt. Some sample extensions have been provided, and
|
| 1395 |
+
some existing code has been converted to extensions. Probably the
|
| 1396 |
+
biggest new user feature is a new search dialog with more options,
|
| 1397 |
+
search and replace, and even search in files (grep).
|
| 1398 |
+
|
| 1399 |
+
This is exactly as downloaded from my laptop after returning
|
| 1400 |
+
from the holidays -- it hasn't even been tested on Unix yet.
|
| 1401 |
+
|
| 1402 |
+
Fri Dec 18 15:52:54 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1403 |
+
|
| 1404 |
+
* FileList.py, ClassBrowser.py:
|
| 1405 |
+
Fix the class browser to work even when the file is not on sys.path.
|
| 1406 |
+
|
| 1407 |
+
Tue Dec 8 20:39:36 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1408 |
+
|
| 1409 |
+
* Attic/turtle.py: Moved to Python 1.5.2/Lib
|
| 1410 |
+
|
| 1411 |
+
Fri Nov 27 03:19:20 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1412 |
+
|
| 1413 |
+
* help.txt: Typo
|
| 1414 |
+
|
| 1415 |
+
* EditorWindow.py, FileList.py: Support underlining of menu labels
|
| 1416 |
+
|
| 1417 |
+
* Bindings.py:
|
| 1418 |
+
New approach, separate tables for menus (platform-independent) and key
|
| 1419 |
+
definitions (platform-specific), and generating accelerator strings
|
| 1420 |
+
automatically from the key definitions.
|
| 1421 |
+
|
| 1422 |
+
Mon Nov 16 18:37:42 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1423 |
+
|
| 1424 |
+
* Attic/README: Clarify portability and main program.
|
| 1425 |
+
|
| 1426 |
+
* Attic/README: Added intro for 0.1 release and append Grail notes.
|
| 1427 |
+
|
| 1428 |
+
Mon Oct 26 18:49:00 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1429 |
+
|
| 1430 |
+
* Attic/turtle.py: root is now a global called _root
|
| 1431 |
+
|
| 1432 |
+
Sat Oct 24 16:38:38 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1433 |
+
|
| 1434 |
+
* Attic/turtle.py: Raise the root window on reset().
|
| 1435 |
+
Different action on WM_DELETE_WINDOW is more likely to do the right thing,
|
| 1436 |
+
allowing us to destroy old windows.
|
| 1437 |
+
|
| 1438 |
+
* Attic/turtle.py:
|
| 1439 |
+
Split the goto() function in two: _goto() is the internal one,
|
| 1440 |
+
using Canvas coordinates, and goto() uses turtle coordinates
|
| 1441 |
+
and accepts variable argument lists.
|
| 1442 |
+
|
| 1443 |
+
* Attic/turtle.py: Cope with destruction of the window
|
| 1444 |
+
|
| 1445 |
+
* Attic/turtle.py: Turtle graphics
|
| 1446 |
+
|
| 1447 |
+
* Debugger.py: Use of Breakpoint class should be bdb.Breakpoint.
|
| 1448 |
+
|
| 1449 |
+
Mon Oct 19 03:33:40 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1450 |
+
|
| 1451 |
+
* SearchBinding.py:
|
| 1452 |
+
Speed up the search a bit -- don't drag a mark around...
|
| 1453 |
+
|
| 1454 |
+
* PyShell.py:
|
| 1455 |
+
Change our special entries from <console#N> to <pyshell#N>.
|
| 1456 |
+
Patch linecache.checkcache() to keep our special entries alive.
|
| 1457 |
+
Add popup menu to all editor windows to set a breakpoint.
|
| 1458 |
+
|
| 1459 |
+
* Debugger.py:
|
| 1460 |
+
Use and pass through the 'force' flag to set_dict() where appropriate.
|
| 1461 |
+
Default source and globals checkboxes to false.
|
| 1462 |
+
Don't interact in user_return().
|
| 1463 |
+
Add primitive set_breakpoint() method.
|
| 1464 |
+
|
| 1465 |
+
* ColorDelegator.py:
|
| 1466 |
+
Raise priority of 'sel' tag so its foreground (on Windows) will take
|
| 1467 |
+
priority over text colorization (which on Windows is almost the
|
| 1468 |
+
same color as the selection background).
|
| 1469 |
+
|
| 1470 |
+
Define a tag and color for breakpoints ("BREAK").
|
| 1471 |
+
|
| 1472 |
+
* Attic/PopupMenu.py: Disable "Open stack viewer" and "help" commands.
|
| 1473 |
+
|
| 1474 |
+
* StackViewer.py:
|
| 1475 |
+
Add optional 'force' argument (default 0) to load_dict().
|
| 1476 |
+
If set, redo the display even if it's the same dict.
|
| 1477 |
+
|
| 1478 |
+
Fri Oct 16 21:10:12 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1479 |
+
|
| 1480 |
+
* StackViewer.py: Do nothing when loading the same dict as before.
|
| 1481 |
+
|
| 1482 |
+
* PyShell.py: Details for debugger interface.
|
| 1483 |
+
|
| 1484 |
+
* Debugger.py:
|
| 1485 |
+
Restructured and more consistent. Save checkboxes across instantiations.
|
| 1486 |
+
|
| 1487 |
+
* EditorWindow.py, Attic/README, Bindings.py:
|
| 1488 |
+
Get rid of conflicting ^X binding. Use ^W.
|
| 1489 |
+
|
| 1490 |
+
* Debugger.py, StackViewer.py:
|
| 1491 |
+
Debugger can now show local and global variables.
|
| 1492 |
+
|
| 1493 |
+
* Debugger.py: Oops
|
| 1494 |
+
|
| 1495 |
+
* Debugger.py, PyShell.py: Better debugger support (show stack etc).
|
| 1496 |
+
|
| 1497 |
+
* Attic/PopupMenu.py: Follow renames in StackViewer module
|
| 1498 |
+
|
| 1499 |
+
* StackViewer.py:
|
| 1500 |
+
Rename classes to StackViewer (the widget) and StackBrowser (the toplevel).
|
| 1501 |
+
|
| 1502 |
+
* ScrolledList.py: Add close() method
|
| 1503 |
+
|
| 1504 |
+
* EditorWindow.py: Clarify 'Open Module' dialog text
|
| 1505 |
+
|
| 1506 |
+
* StackViewer.py: Restructured into a browser and a widget.
|
| 1507 |
+
|
| 1508 |
+
Thu Oct 15 23:27:08 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1509 |
+
|
| 1510 |
+
* ClassBrowser.py, ScrolledList.py:
|
| 1511 |
+
Generalized the scrolled list which is the base for the class and
|
| 1512 |
+
method browser into a separate class in its own module.
|
| 1513 |
+
|
| 1514 |
+
* Attic/test.py: Cosmetic change
|
| 1515 |
+
|
| 1516 |
+
* Debugger.py: Don't show function name if there is none
|
| 1517 |
+
|
| 1518 |
+
Wed Oct 14 03:43:05 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1519 |
+
|
| 1520 |
+
* Debugger.py, PyShell.py: Polish the Debugger GUI a bit.
|
| 1521 |
+
Closing it now also does the right thing.
|
| 1522 |
+
|
| 1523 |
+
Tue Oct 13 23:51:13 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1524 |
+
|
| 1525 |
+
* Debugger.py, PyShell.py, Bindings.py:
|
| 1526 |
+
Ad primitive debugger interface (so far it will step and show you the
|
| 1527 |
+
source, but it doesn't yet show the stack).
|
| 1528 |
+
|
| 1529 |
+
* Attic/README: Misc
|
| 1530 |
+
|
| 1531 |
+
* StackViewer.py: Whoops -- referenced self.top before it was set.
|
| 1532 |
+
|
| 1533 |
+
* help.txt: Added history and completion commands.
|
| 1534 |
+
|
| 1535 |
+
* help.txt: Updated
|
| 1536 |
+
|
| 1537 |
+
* FileList.py: Add class browser functionality.
|
| 1538 |
+
|
| 1539 |
+
* StackViewer.py:
|
| 1540 |
+
Add a close() method and bind to WM_DELETE_WINDOW protocol
|
| 1541 |
+
|
| 1542 |
+
* PyShell.py: Clear the linecache before printing a traceback
|
| 1543 |
+
|
| 1544 |
+
* Bindings.py: Added class browser binding.
|
| 1545 |
+
|
| 1546 |
+
* ClassBrowser.py: Much improved, much left to do.
|
| 1547 |
+
|
| 1548 |
+
* PyShell.py: Make the return key do what I mean more often.
|
| 1549 |
+
|
| 1550 |
+
* ClassBrowser.py:
|
| 1551 |
+
Adding the beginnings of a Class browser. Incomplete, yet.
|
| 1552 |
+
|
| 1553 |
+
* EditorWindow.py, Bindings.py:
|
| 1554 |
+
Add new command, "Open module". You select or type a module name,
|
| 1555 |
+
and it opens the source.
|
| 1556 |
+
|
| 1557 |
+
Mon Oct 12 23:59:27 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1558 |
+
|
| 1559 |
+
* PyShell.py: Subsume functionality from Popup menu in Debug menu.
|
| 1560 |
+
Other stuff so the PyShell window can be resurrected from the Windows menu.
|
| 1561 |
+
|
| 1562 |
+
* FileList.py: Get rid of PopUp menu.
|
| 1563 |
+
Create a simple Windows menu. (Imperfect when Untitled windows exist.)
|
| 1564 |
+
Add wakeup() method: deiconify, raise, focus.
|
| 1565 |
+
|
| 1566 |
+
* EditorWindow.py: Generalize menu creation.
|
| 1567 |
+
|
| 1568 |
+
* Bindings.py: Add Debug and Help menu items.
|
| 1569 |
+
|
| 1570 |
+
* EditorWindow.py: Added a menu bar to every window.
|
| 1571 |
+
|
| 1572 |
+
* Bindings.py: Add menu configuration to the event configuration.
|
| 1573 |
+
|
| 1574 |
+
* Attic/PopupMenu.py: Pass a root to the help window.
|
| 1575 |
+
|
| 1576 |
+
* SearchBinding.py:
|
| 1577 |
+
Add parent argument to 'go to line number' dialog box.
|
| 1578 |
+
|
| 1579 |
+
Sat Oct 10 19:15:32 1998 Guido van Rossum <guido@cnri.reston.va.us>
|
| 1580 |
+
|
| 1581 |
+
* StackViewer.py:
|
| 1582 |
+
Add a label at the top showing (very basic) help for the stack viewer.
|
| 1583 |
+
Add a label at the bottom showing the exception info.
|
| 1584 |
+
|
| 1585 |
+
* Attic/test.py, Attic/idle: Add Unix main script and test program.
|
| 1586 |
+
|
| 1587 |
+
* idle.pyw, help.txt, WidgetRedirector.py, UndoDelegator.py, StackViewer.py, SearchBinding.py, Attic/README, PyShell.py, Attic/PopupMenu.py, Percolator.py, Outline.py, IOBinding.py, History.py, Attic/HelpWindow.py, FrameViewer.py, FileList.py, EditorWindow.py, Delegator.py, ColorDelegator.py, Bindings.py, AutoIndent.py, AutoExpand.py:
|
| 1588 |
+
Initial checking of Tk-based Python IDE.
|
| 1589 |
+
Features: text editor with syntax coloring and undo;
|
| 1590 |
+
subclassed into interactive Python shell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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Original IDLE todo, much of it now outdated:
|
| 2 |
+
============================================
|
| 3 |
+
TO DO:
|
| 4 |
+
|
| 5 |
+
- improve debugger:
|
| 6 |
+
- manage breakpoints globally, allow bp deletion, tbreak, cbreak etc.
|
| 7 |
+
- real object browser
|
| 8 |
+
- help on how to use it (a simple help button will do wonders)
|
| 9 |
+
- performance? (updates of large sets of locals are slow)
|
| 10 |
+
- better integration of "debug module"
|
| 11 |
+
- debugger should be global resource (attached to flist, not to shell)
|
| 12 |
+
- fix the stupid bug where you need to step twice
|
| 13 |
+
- display class name in stack viewer entries for methods
|
| 14 |
+
- suppress tracing through IDLE internals (e.g. print) DONE
|
| 15 |
+
- add a button to suppress through a specific module or class or method
|
| 16 |
+
- more object inspection to stack viewer, e.g. to view all array items
|
| 17 |
+
- insert the initial current directory into sys.path DONE
|
| 18 |
+
- default directory attribute for each window instead of only for windows
|
| 19 |
+
that have an associated filename
|
| 20 |
+
- command expansion from keywords, module contents, other buffers, etc.
|
| 21 |
+
- "Recent documents" menu item DONE
|
| 22 |
+
- Filter region command
|
| 23 |
+
- Optional horizontal scroll bar
|
| 24 |
+
- more Emacsisms:
|
| 25 |
+
- ^K should cut to buffer
|
| 26 |
+
- M-[, M-] to move by paragraphs
|
| 27 |
+
- incremental search?
|
| 28 |
+
- search should indicate wrap-around in some way
|
| 29 |
+
- restructure state sensitive code to avoid testing flags all the time
|
| 30 |
+
- persistent user state (e.g. window and cursor positions, bindings)
|
| 31 |
+
- make backups when saving
|
| 32 |
+
- check file mtimes at various points
|
| 33 |
+
- Pluggable interface with RCS/CVS/Perforce/Clearcase
|
| 34 |
+
- better help?
|
| 35 |
+
- don't open second class browser on same module (nor second path browser)
|
| 36 |
+
- unify class and path browsers
|
| 37 |
+
- Need to define a standard way whereby one can determine one is running
|
| 38 |
+
inside IDLE (needed for Tk mainloop, also handy for $PYTHONSTARTUP)
|
| 39 |
+
- Add more utility methods for use by extensions (a la get_selection)
|
| 40 |
+
- Way to run command in totally separate interpreter (fork+os.system?) DONE
|
| 41 |
+
- Way to find definition of fully-qualified name:
|
| 42 |
+
In other words, select "UserDict.UserDict", hit some magic key and
|
| 43 |
+
it loads up UserDict.py and finds the first def or class for UserDict.
|
| 44 |
+
- need a way to force colorization on/off
|
| 45 |
+
- need a way to force auto-indent on/off
|
| 46 |
+
|
| 47 |
+
Details:
|
| 48 |
+
|
| 49 |
+
- ^O (on Unix -- open-line) should honor autoindent
|
| 50 |
+
- after paste, show end of pasted text
|
| 51 |
+
- on Windows, should turn short filename to long filename (not only in argv!)
|
| 52 |
+
(shouldn't this be done -- or undone -- by ntpath.normpath?)
|
| 53 |
+
- new autoindent after colon even indents when the colon is in a comment!
|
| 54 |
+
- sometimes forward slashes in pathname remain
|
| 55 |
+
- sometimes star in window name remains in Windows menu
|
| 56 |
+
- With unix bindings, ESC by itself is ignored
|
| 57 |
+
- Sometimes for no apparent reason a selection from the cursor to the
|
| 58 |
+
end of the command buffer appears, which is hard to get rid of
|
| 59 |
+
because it stays when you are typing!
|
| 60 |
+
- The Line/Col in the status bar can be wrong initially in PyShell DONE
|
| 61 |
+
|
| 62 |
+
Structural problems:
|
| 63 |
+
|
| 64 |
+
- too much knowledge in FileList about EditorWindow (for example)
|
| 65 |
+
- should add some primitives for accessing the selection etc.
|
| 66 |
+
to repeat cumbersome code over and over
|
| 67 |
+
|
| 68 |
+
======================================================================
|
| 69 |
+
|
| 70 |
+
Jeff Bauer suggests:
|
| 71 |
+
|
| 72 |
+
- Open Module doesn't appear to handle hierarchical packages.
|
| 73 |
+
- Class browser should also allow hierarchical packages.
|
| 74 |
+
- Open and Open Module could benefit from a history, DONE
|
| 75 |
+
either command line style, or Microsoft recent-file
|
| 76 |
+
style.
|
| 77 |
+
- Add a Smalltalk-style inspector (i.e. Tkinspect)
|
| 78 |
+
|
| 79 |
+
The last suggestion is already a reality, but not yet
|
| 80 |
+
integrated into IDLE. I use a module called inspector.py,
|
| 81 |
+
that used to be available from python.org(?) It no longer
|
| 82 |
+
appears to be in the contributed section, and the source
|
| 83 |
+
has no author attribution.
|
| 84 |
+
|
| 85 |
+
In any case, the code is useful for visually navigating
|
| 86 |
+
an object's attributes, including its container hierarchy.
|
| 87 |
+
|
| 88 |
+
>>> from inspector import Tkinspect
|
| 89 |
+
>>> Tkinspect(None, myObject)
|
| 90 |
+
|
| 91 |
+
Tkinspect could probably be extended and refined to
|
| 92 |
+
integrate better into IDLE.
|
| 93 |
+
|
| 94 |
+
======================================================================
|
| 95 |
+
|
| 96 |
+
Comparison to PTUI
|
| 97 |
+
------------------
|
| 98 |
+
|
| 99 |
+
+ PTUI's help is better (HTML!)
|
| 100 |
+
|
| 101 |
+
+ PTUI can attach a shell to any module
|
| 102 |
+
|
| 103 |
+
+ PTUI has some more I/O commands:
|
| 104 |
+
open multiple
|
| 105 |
+
append
|
| 106 |
+
examine (what's that?)
|
| 107 |
+
|
| 108 |
+
======================================================================
|
| 109 |
+
|
| 110 |
+
Notes after trying to run Grail
|
| 111 |
+
-------------------------------
|
| 112 |
+
|
| 113 |
+
- Grail does stuff to sys.path based on sys.argv[0]; you must set
|
| 114 |
+
sys.argv[0] to something decent first (it is normally set to the path of
|
| 115 |
+
the idle script).
|
| 116 |
+
|
| 117 |
+
- Grail must be exec'ed in __main__ because that's imported by some
|
| 118 |
+
other parts of Grail.
|
| 119 |
+
|
| 120 |
+
- Grail uses a module called History and so does idle :-(
|
| 121 |
+
|
| 122 |
+
======================================================================
|
| 123 |
+
|
| 124 |
+
Robin Friedrich's items:
|
| 125 |
+
|
| 126 |
+
Things I'd like to see:
|
| 127 |
+
- I'd like support for shift-click extending the selection. There's a
|
| 128 |
+
bug now that it doesn't work the first time you try it.
|
| 129 |
+
- Printing is needed. How hard can that be on Windows? FIRST CUT DONE
|
| 130 |
+
- The python-mode trick of autoindenting a line with <tab> is neat and
|
| 131 |
+
very handy.
|
| 132 |
+
- (someday) a spellchecker for docstrings and comments.
|
| 133 |
+
- a pagedown/up command key which moves to next class/def statement (top
|
| 134 |
+
level)
|
| 135 |
+
- split window capability
|
| 136 |
+
- DnD text relocation/copying
|
| 137 |
+
|
| 138 |
+
Things I don't want to see.
|
| 139 |
+
- line numbers... will probably slow things down way too much.
|
| 140 |
+
- Please use another icon for the tree browser leaf. The small snake
|
| 141 |
+
isn't cutting it.
|
| 142 |
+
|
| 143 |
+
----------------------------------------------------------------------
|
| 144 |
+
|
| 145 |
+
- Customizable views (multi-window or multi-pane). (Markus Gritsch)
|
| 146 |
+
|
| 147 |
+
- Being able to double click (maybe double right click) on a callable
|
| 148 |
+
object in the editor which shows the source of the object, if
|
| 149 |
+
possible. (Gerrit Holl)
|
| 150 |
+
|
| 151 |
+
- Hooks into the guts, like in Emacs. (Mike Romberg)
|
| 152 |
+
|
| 153 |
+
- Sharing the editor with a remote tutor. (Martijn Faassen)
|
| 154 |
+
|
| 155 |
+
- Multiple views on the same file. (Tony J Ibbs)
|
| 156 |
+
|
| 157 |
+
- Store breakpoints in a global (per-project) database (GvR); Dirk
|
| 158 |
+
Heise adds: save some space-trimmed context and search around when
|
| 159 |
+
reopening a file that might have been edited by someone else.
|
| 160 |
+
|
| 161 |
+
- Capture menu events in extensions without changing the IDLE source.
|
| 162 |
+
(Matthias Barmeier)
|
| 163 |
+
|
| 164 |
+
- Use overlapping panels (a "notebook" in MFC terms I think) for info
|
| 165 |
+
that doesn't need to be accessible simultaneously (e.g. HTML source
|
| 166 |
+
and output). Use multi-pane windows for info that does need to be
|
| 167 |
+
shown together (e.g. class browser and source). (Albert Brandl)
|
| 168 |
+
|
| 169 |
+
- A project should invisibly track all symbols, for instant search,
|
| 170 |
+
replace and cross-ref. Projects should be allowed to span multiple
|
| 171 |
+
directories, hosts, etc. Project management files are placed in a
|
| 172 |
+
directory you specify. A global mapping between project names and
|
| 173 |
+
project directories should exist [not so sure --GvR]. (Tim Peters)
|
| 174 |
+
|
| 175 |
+
- Merge attr-tips and auto-expand. (Mark Hammond, Tim Peters)
|
| 176 |
+
|
| 177 |
+
- Python Shell should behave more like a "shell window" as users know
|
| 178 |
+
it -- i.e. you can only edit the current command, and the cursor can't
|
| 179 |
+
escape from the command area. (Albert Brandl)
|
| 180 |
+
|
| 181 |
+
- Set X11 class to "idle/Idle", set icon and title to something
|
| 182 |
+
beginning with "idle" -- for window manangers. (Randall Hopper)
|
| 183 |
+
|
| 184 |
+
- Config files editable through a preferences dialog. (me) DONE
|
| 185 |
+
|
| 186 |
+
- Config files still editable outside the preferences dialog.
|
| 187 |
+
(Randall Hopper) DONE
|
| 188 |
+
|
| 189 |
+
- When you're editing a command in PyShell, and there are only blank
|
| 190 |
+
lines below the cursor, hitting Return should ignore or delete those
|
| 191 |
+
blank lines rather than deciding you're not on the last line. (me)
|
| 192 |
+
|
| 193 |
+
- Run command (F5 c.s.) should be more like Pythonwin's Run -- a
|
| 194 |
+
dialog with options to give command line arguments, run the debugger,
|
| 195 |
+
etc. (me)
|
| 196 |
+
|
| 197 |
+
- Shouldn't be able to delete part of the prompt (or any text before
|
| 198 |
+
it) in the PyShell. (Martijn Faassen) DONE
|
| 199 |
+
|
| 200 |
+
- Emacs style auto-fill (also smart about comments and strings).
|
| 201 |
+
(Jeremy Hylton)
|
| 202 |
+
|
| 203 |
+
- Output of Run Script should go to a separate output window, not to
|
| 204 |
+
the shell window. Output of separate runs should all go to the same
|
| 205 |
+
window but clearly delimited. (David Scherer) REJECT FIRST, LATTER DONE
|
| 206 |
+
|
| 207 |
+
- GUI form designer to kick VB's butt. (Robert Geiger) THAT'S NOT IDLE
|
| 208 |
+
|
| 209 |
+
- Printing! Possibly via generation of PDF files which the user must
|
| 210 |
+
then send to the printer separately. (Dinu Gherman) FIRST CUT
|
data/conda_envs/evalclaw/lib/python3.11/idlelib/__main__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
IDLE main entry point
|
| 3 |
+
|
| 4 |
+
Run IDLE as python -m idlelib
|
| 5 |
+
"""
|
| 6 |
+
import idlelib.pyshell
|
| 7 |
+
idlelib.pyshell.main()
|
| 8 |
+
# This file does not work for 2.7; See issue 24212.
|
data/conda_envs/evalclaw/lib/python3.11/idlelib/autocomplete_w.py
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
An auto-completion window for IDLE, used by the autocomplete extension
|
| 3 |
+
"""
|
| 4 |
+
import platform
|
| 5 |
+
|
| 6 |
+
from tkinter import *
|
| 7 |
+
from tkinter.ttk import Scrollbar
|
| 8 |
+
|
| 9 |
+
from idlelib.autocomplete import FILES, ATTRS
|
| 10 |
+
from idlelib.multicall import MC_SHIFT
|
| 11 |
+
|
| 12 |
+
HIDE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-hide>>"
|
| 13 |
+
HIDE_FOCUS_OUT_SEQUENCE = "<FocusOut>"
|
| 14 |
+
HIDE_SEQUENCES = (HIDE_FOCUS_OUT_SEQUENCE, "<ButtonPress>")
|
| 15 |
+
KEYPRESS_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keypress>>"
|
| 16 |
+
# We need to bind event beyond <Key> so that the function will be called
|
| 17 |
+
# before the default specific IDLE function
|
| 18 |
+
KEYPRESS_SEQUENCES = ("<Key>", "<Key-BackSpace>", "<Key-Return>", "<Key-Tab>",
|
| 19 |
+
"<Key-Up>", "<Key-Down>", "<Key-Home>", "<Key-End>",
|
| 20 |
+
"<Key-Prior>", "<Key-Next>", "<Key-Escape>")
|
| 21 |
+
KEYRELEASE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keyrelease>>"
|
| 22 |
+
KEYRELEASE_SEQUENCE = "<KeyRelease>"
|
| 23 |
+
LISTUPDATE_SEQUENCE = "<B1-ButtonRelease>"
|
| 24 |
+
WINCONFIG_SEQUENCE = "<Configure>"
|
| 25 |
+
DOUBLECLICK_SEQUENCE = "<B1-Double-ButtonRelease>"
|
| 26 |
+
|
| 27 |
+
class AutoCompleteWindow:
|
| 28 |
+
|
| 29 |
+
def __init__(self, widget, tags):
|
| 30 |
+
# The widget (Text) on which we place the AutoCompleteWindow
|
| 31 |
+
self.widget = widget
|
| 32 |
+
# Tags to mark inserted text with
|
| 33 |
+
self.tags = tags
|
| 34 |
+
# The widgets we create
|
| 35 |
+
self.autocompletewindow = self.listbox = self.scrollbar = None
|
| 36 |
+
# The default foreground and background of a selection. Saved because
|
| 37 |
+
# they are changed to the regular colors of list items when the
|
| 38 |
+
# completion start is not a prefix of the selected completion
|
| 39 |
+
self.origselforeground = self.origselbackground = None
|
| 40 |
+
# The list of completions
|
| 41 |
+
self.completions = None
|
| 42 |
+
# A list with more completions, or None
|
| 43 |
+
self.morecompletions = None
|
| 44 |
+
# The completion mode, either autocomplete.ATTRS or .FILES.
|
| 45 |
+
self.mode = None
|
| 46 |
+
# The current completion start, on the text box (a string)
|
| 47 |
+
self.start = None
|
| 48 |
+
# The index of the start of the completion
|
| 49 |
+
self.startindex = None
|
| 50 |
+
# The last typed start, used so that when the selection changes,
|
| 51 |
+
# the new start will be as close as possible to the last typed one.
|
| 52 |
+
self.lasttypedstart = None
|
| 53 |
+
# Do we have an indication that the user wants the completion window
|
| 54 |
+
# (for example, he clicked the list)
|
| 55 |
+
self.userwantswindow = None
|
| 56 |
+
# event ids
|
| 57 |
+
self.hideid = self.keypressid = self.listupdateid = \
|
| 58 |
+
self.winconfigid = self.keyreleaseid = self.doubleclickid = None
|
| 59 |
+
# Flag set if last keypress was a tab
|
| 60 |
+
self.lastkey_was_tab = False
|
| 61 |
+
# Flag set to avoid recursive <Configure> callback invocations.
|
| 62 |
+
self.is_configuring = False
|
| 63 |
+
|
| 64 |
+
def _change_start(self, newstart):
|
| 65 |
+
min_len = min(len(self.start), len(newstart))
|
| 66 |
+
i = 0
|
| 67 |
+
while i < min_len and self.start[i] == newstart[i]:
|
| 68 |
+
i += 1
|
| 69 |
+
if i < len(self.start):
|
| 70 |
+
self.widget.delete("%s+%dc" % (self.startindex, i),
|
| 71 |
+
"%s+%dc" % (self.startindex, len(self.start)))
|
| 72 |
+
if i < len(newstart):
|
| 73 |
+
self.widget.insert("%s+%dc" % (self.startindex, i),
|
| 74 |
+
newstart[i:],
|
| 75 |
+
self.tags)
|
| 76 |
+
self.start = newstart
|
| 77 |
+
|
| 78 |
+
def _binary_search(self, s):
|
| 79 |
+
"""Find the first index in self.completions where completions[i] is
|
| 80 |
+
greater or equal to s, or the last index if there is no such.
|
| 81 |
+
"""
|
| 82 |
+
i = 0; j = len(self.completions)
|
| 83 |
+
while j > i:
|
| 84 |
+
m = (i + j) // 2
|
| 85 |
+
if self.completions[m] >= s:
|
| 86 |
+
j = m
|
| 87 |
+
else:
|
| 88 |
+
i = m + 1
|
| 89 |
+
return min(i, len(self.completions)-1)
|
| 90 |
+
|
| 91 |
+
def _complete_string(self, s):
|
| 92 |
+
"""Assuming that s is the prefix of a string in self.completions,
|
| 93 |
+
return the longest string which is a prefix of all the strings which
|
| 94 |
+
s is a prefix of them. If s is not a prefix of a string, return s.
|
| 95 |
+
"""
|
| 96 |
+
first = self._binary_search(s)
|
| 97 |
+
if self.completions[first][:len(s)] != s:
|
| 98 |
+
# There is not even one completion which s is a prefix of.
|
| 99 |
+
return s
|
| 100 |
+
# Find the end of the range of completions where s is a prefix of.
|
| 101 |
+
i = first + 1
|
| 102 |
+
j = len(self.completions)
|
| 103 |
+
while j > i:
|
| 104 |
+
m = (i + j) // 2
|
| 105 |
+
if self.completions[m][:len(s)] != s:
|
| 106 |
+
j = m
|
| 107 |
+
else:
|
| 108 |
+
i = m + 1
|
| 109 |
+
last = i-1
|
| 110 |
+
|
| 111 |
+
if first == last: # only one possible completion
|
| 112 |
+
return self.completions[first]
|
| 113 |
+
|
| 114 |
+
# We should return the maximum prefix of first and last
|
| 115 |
+
first_comp = self.completions[first]
|
| 116 |
+
last_comp = self.completions[last]
|
| 117 |
+
min_len = min(len(first_comp), len(last_comp))
|
| 118 |
+
i = len(s)
|
| 119 |
+
while i < min_len and first_comp[i] == last_comp[i]:
|
| 120 |
+
i += 1
|
| 121 |
+
return first_comp[:i]
|
| 122 |
+
|
| 123 |
+
def _selection_changed(self):
|
| 124 |
+
"""Call when the selection of the Listbox has changed.
|
| 125 |
+
|
| 126 |
+
Updates the Listbox display and calls _change_start.
|
| 127 |
+
"""
|
| 128 |
+
cursel = int(self.listbox.curselection()[0])
|
| 129 |
+
|
| 130 |
+
self.listbox.see(cursel)
|
| 131 |
+
|
| 132 |
+
lts = self.lasttypedstart
|
| 133 |
+
selstart = self.completions[cursel]
|
| 134 |
+
if self._binary_search(lts) == cursel:
|
| 135 |
+
newstart = lts
|
| 136 |
+
else:
|
| 137 |
+
min_len = min(len(lts), len(selstart))
|
| 138 |
+
i = 0
|
| 139 |
+
while i < min_len and lts[i] == selstart[i]:
|
| 140 |
+
i += 1
|
| 141 |
+
newstart = selstart[:i]
|
| 142 |
+
self._change_start(newstart)
|
| 143 |
+
|
| 144 |
+
if self.completions[cursel][:len(self.start)] == self.start:
|
| 145 |
+
# start is a prefix of the selected completion
|
| 146 |
+
self.listbox.configure(selectbackground=self.origselbackground,
|
| 147 |
+
selectforeground=self.origselforeground)
|
| 148 |
+
else:
|
| 149 |
+
self.listbox.configure(selectbackground=self.listbox.cget("bg"),
|
| 150 |
+
selectforeground=self.listbox.cget("fg"))
|
| 151 |
+
# If there are more completions, show them, and call me again.
|
| 152 |
+
if self.morecompletions:
|
| 153 |
+
self.completions = self.morecompletions
|
| 154 |
+
self.morecompletions = None
|
| 155 |
+
self.listbox.delete(0, END)
|
| 156 |
+
for item in self.completions:
|
| 157 |
+
self.listbox.insert(END, item)
|
| 158 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 159 |
+
self._selection_changed()
|
| 160 |
+
|
| 161 |
+
def show_window(self, comp_lists, index, complete, mode, userWantsWin):
|
| 162 |
+
"""Show the autocomplete list, bind events.
|
| 163 |
+
|
| 164 |
+
If complete is True, complete the text, and if there is exactly
|
| 165 |
+
one matching completion, don't open a list.
|
| 166 |
+
"""
|
| 167 |
+
# Handle the start we already have
|
| 168 |
+
self.completions, self.morecompletions = comp_lists
|
| 169 |
+
self.mode = mode
|
| 170 |
+
self.startindex = self.widget.index(index)
|
| 171 |
+
self.start = self.widget.get(self.startindex, "insert")
|
| 172 |
+
if complete:
|
| 173 |
+
completed = self._complete_string(self.start)
|
| 174 |
+
start = self.start
|
| 175 |
+
self._change_start(completed)
|
| 176 |
+
i = self._binary_search(completed)
|
| 177 |
+
if self.completions[i] == completed and \
|
| 178 |
+
(i == len(self.completions)-1 or
|
| 179 |
+
self.completions[i+1][:len(completed)] != completed):
|
| 180 |
+
# There is exactly one matching completion
|
| 181 |
+
return completed == start
|
| 182 |
+
self.userwantswindow = userWantsWin
|
| 183 |
+
self.lasttypedstart = self.start
|
| 184 |
+
|
| 185 |
+
self.autocompletewindow = acw = Toplevel(self.widget)
|
| 186 |
+
acw.withdraw()
|
| 187 |
+
acw.wm_overrideredirect(1)
|
| 188 |
+
try:
|
| 189 |
+
# Prevent grabbing focus on macOS.
|
| 190 |
+
acw.tk.call("::tk::unsupported::MacWindowStyle", "style", acw._w,
|
| 191 |
+
"help", "noActivates")
|
| 192 |
+
except TclError:
|
| 193 |
+
pass
|
| 194 |
+
self.scrollbar = scrollbar = Scrollbar(acw, orient=VERTICAL)
|
| 195 |
+
self.listbox = listbox = Listbox(acw, yscrollcommand=scrollbar.set,
|
| 196 |
+
exportselection=False)
|
| 197 |
+
for item in self.completions:
|
| 198 |
+
listbox.insert(END, item)
|
| 199 |
+
self.origselforeground = listbox.cget("selectforeground")
|
| 200 |
+
self.origselbackground = listbox.cget("selectbackground")
|
| 201 |
+
scrollbar.config(command=listbox.yview)
|
| 202 |
+
scrollbar.pack(side=RIGHT, fill=Y)
|
| 203 |
+
listbox.pack(side=LEFT, fill=BOTH, expand=True)
|
| 204 |
+
#acw.update_idletasks() # Need for tk8.6.8 on macOS: #40128.
|
| 205 |
+
acw.lift() # work around bug in Tk 8.5.18+ (issue #24570)
|
| 206 |
+
|
| 207 |
+
# Initialize the listbox selection
|
| 208 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 209 |
+
self._selection_changed()
|
| 210 |
+
|
| 211 |
+
# bind events
|
| 212 |
+
self.hideaid = acw.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
|
| 213 |
+
self.hidewid = self.widget.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
|
| 214 |
+
acw.event_add(HIDE_VIRTUAL_EVENT_NAME, HIDE_FOCUS_OUT_SEQUENCE)
|
| 215 |
+
for seq in HIDE_SEQUENCES:
|
| 216 |
+
self.widget.event_add(HIDE_VIRTUAL_EVENT_NAME, seq)
|
| 217 |
+
|
| 218 |
+
self.keypressid = self.widget.bind(KEYPRESS_VIRTUAL_EVENT_NAME,
|
| 219 |
+
self.keypress_event)
|
| 220 |
+
for seq in KEYPRESS_SEQUENCES:
|
| 221 |
+
self.widget.event_add(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
|
| 222 |
+
self.keyreleaseid = self.widget.bind(KEYRELEASE_VIRTUAL_EVENT_NAME,
|
| 223 |
+
self.keyrelease_event)
|
| 224 |
+
self.widget.event_add(KEYRELEASE_VIRTUAL_EVENT_NAME,KEYRELEASE_SEQUENCE)
|
| 225 |
+
self.listupdateid = listbox.bind(LISTUPDATE_SEQUENCE,
|
| 226 |
+
self.listselect_event)
|
| 227 |
+
self.is_configuring = False
|
| 228 |
+
self.winconfigid = acw.bind(WINCONFIG_SEQUENCE, self.winconfig_event)
|
| 229 |
+
self.doubleclickid = listbox.bind(DOUBLECLICK_SEQUENCE,
|
| 230 |
+
self.doubleclick_event)
|
| 231 |
+
return None
|
| 232 |
+
|
| 233 |
+
def winconfig_event(self, event):
|
| 234 |
+
if self.is_configuring:
|
| 235 |
+
# Avoid running on recursive <Configure> callback invocations.
|
| 236 |
+
return
|
| 237 |
+
|
| 238 |
+
self.is_configuring = True
|
| 239 |
+
if not self.is_active():
|
| 240 |
+
return
|
| 241 |
+
|
| 242 |
+
# Since the <Configure> event may occur after the completion window is gone,
|
| 243 |
+
# catch potential TclError exceptions when accessing acw. See: bpo-41611.
|
| 244 |
+
try:
|
| 245 |
+
# Position the completion list window
|
| 246 |
+
text = self.widget
|
| 247 |
+
text.see(self.startindex)
|
| 248 |
+
x, y, cx, cy = text.bbox(self.startindex)
|
| 249 |
+
acw = self.autocompletewindow
|
| 250 |
+
if platform.system().startswith('Windows'):
|
| 251 |
+
# On Windows an update() call is needed for the completion
|
| 252 |
+
# list window to be created, so that we can fetch its width
|
| 253 |
+
# and height. However, this is not needed on other platforms
|
| 254 |
+
# (tested on Ubuntu and macOS) but at one point began
|
| 255 |
+
# causing freezes on macOS. See issues 37849 and 41611.
|
| 256 |
+
acw.update()
|
| 257 |
+
acw_width, acw_height = acw.winfo_width(), acw.winfo_height()
|
| 258 |
+
text_width, text_height = text.winfo_width(), text.winfo_height()
|
| 259 |
+
new_x = text.winfo_rootx() + min(x, max(0, text_width - acw_width))
|
| 260 |
+
new_y = text.winfo_rooty() + y
|
| 261 |
+
if (text_height - (y + cy) >= acw_height # enough height below
|
| 262 |
+
or y < acw_height): # not enough height above
|
| 263 |
+
# place acw below current line
|
| 264 |
+
new_y += cy
|
| 265 |
+
else:
|
| 266 |
+
# place acw above current line
|
| 267 |
+
new_y -= acw_height
|
| 268 |
+
acw.wm_geometry("+%d+%d" % (new_x, new_y))
|
| 269 |
+
acw.deiconify()
|
| 270 |
+
acw.update_idletasks()
|
| 271 |
+
except TclError:
|
| 272 |
+
pass
|
| 273 |
+
|
| 274 |
+
if platform.system().startswith('Windows'):
|
| 275 |
+
# See issue 15786. When on Windows platform, Tk will misbehave
|
| 276 |
+
# to call winconfig_event multiple times, we need to prevent this,
|
| 277 |
+
# otherwise mouse button double click will not be able to used.
|
| 278 |
+
try:
|
| 279 |
+
acw.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
|
| 280 |
+
except TclError:
|
| 281 |
+
pass
|
| 282 |
+
self.winconfigid = None
|
| 283 |
+
|
| 284 |
+
self.is_configuring = False
|
| 285 |
+
|
| 286 |
+
def _hide_event_check(self):
|
| 287 |
+
if not self.autocompletewindow:
|
| 288 |
+
return
|
| 289 |
+
|
| 290 |
+
try:
|
| 291 |
+
if not self.autocompletewindow.focus_get():
|
| 292 |
+
self.hide_window()
|
| 293 |
+
except KeyError:
|
| 294 |
+
# See issue 734176, when user click on menu, acw.focus_get()
|
| 295 |
+
# will get KeyError.
|
| 296 |
+
self.hide_window()
|
| 297 |
+
|
| 298 |
+
def hide_event(self, event):
|
| 299 |
+
# Hide autocomplete list if it exists and does not have focus or
|
| 300 |
+
# mouse click on widget / text area.
|
| 301 |
+
if self.is_active():
|
| 302 |
+
if event.type == EventType.FocusOut:
|
| 303 |
+
# On Windows platform, it will need to delay the check for
|
| 304 |
+
# acw.focus_get() when click on acw, otherwise it will return
|
| 305 |
+
# None and close the window
|
| 306 |
+
self.widget.after(1, self._hide_event_check)
|
| 307 |
+
elif event.type == EventType.ButtonPress:
|
| 308 |
+
# ButtonPress event only bind to self.widget
|
| 309 |
+
self.hide_window()
|
| 310 |
+
|
| 311 |
+
def listselect_event(self, event):
|
| 312 |
+
if self.is_active():
|
| 313 |
+
self.userwantswindow = True
|
| 314 |
+
cursel = int(self.listbox.curselection()[0])
|
| 315 |
+
self._change_start(self.completions[cursel])
|
| 316 |
+
|
| 317 |
+
def doubleclick_event(self, event):
|
| 318 |
+
# Put the selected completion in the text, and close the list
|
| 319 |
+
cursel = int(self.listbox.curselection()[0])
|
| 320 |
+
self._change_start(self.completions[cursel])
|
| 321 |
+
self.hide_window()
|
| 322 |
+
|
| 323 |
+
def keypress_event(self, event):
|
| 324 |
+
if not self.is_active():
|
| 325 |
+
return None
|
| 326 |
+
keysym = event.keysym
|
| 327 |
+
if hasattr(event, "mc_state"):
|
| 328 |
+
state = event.mc_state
|
| 329 |
+
else:
|
| 330 |
+
state = 0
|
| 331 |
+
if keysym != "Tab":
|
| 332 |
+
self.lastkey_was_tab = False
|
| 333 |
+
if (len(keysym) == 1 or keysym in ("underscore", "BackSpace")
|
| 334 |
+
or (self.mode == FILES and keysym in
|
| 335 |
+
("period", "minus"))) \
|
| 336 |
+
and not (state & ~MC_SHIFT):
|
| 337 |
+
# Normal editing of text
|
| 338 |
+
if len(keysym) == 1:
|
| 339 |
+
self._change_start(self.start + keysym)
|
| 340 |
+
elif keysym == "underscore":
|
| 341 |
+
self._change_start(self.start + '_')
|
| 342 |
+
elif keysym == "period":
|
| 343 |
+
self._change_start(self.start + '.')
|
| 344 |
+
elif keysym == "minus":
|
| 345 |
+
self._change_start(self.start + '-')
|
| 346 |
+
else:
|
| 347 |
+
# keysym == "BackSpace"
|
| 348 |
+
if len(self.start) == 0:
|
| 349 |
+
self.hide_window()
|
| 350 |
+
return None
|
| 351 |
+
self._change_start(self.start[:-1])
|
| 352 |
+
self.lasttypedstart = self.start
|
| 353 |
+
self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
|
| 354 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 355 |
+
self._selection_changed()
|
| 356 |
+
return "break"
|
| 357 |
+
|
| 358 |
+
elif keysym == "Return":
|
| 359 |
+
self.complete()
|
| 360 |
+
self.hide_window()
|
| 361 |
+
return 'break'
|
| 362 |
+
|
| 363 |
+
elif (self.mode == ATTRS and keysym in
|
| 364 |
+
("period", "space", "parenleft", "parenright", "bracketleft",
|
| 365 |
+
"bracketright")) or \
|
| 366 |
+
(self.mode == FILES and keysym in
|
| 367 |
+
("slash", "backslash", "quotedbl", "apostrophe")) \
|
| 368 |
+
and not (state & ~MC_SHIFT):
|
| 369 |
+
# If start is a prefix of the selection, but is not '' when
|
| 370 |
+
# completing file names, put the whole
|
| 371 |
+
# selected completion. Anyway, close the list.
|
| 372 |
+
cursel = int(self.listbox.curselection()[0])
|
| 373 |
+
if self.completions[cursel][:len(self.start)] == self.start \
|
| 374 |
+
and (self.mode == ATTRS or self.start):
|
| 375 |
+
self._change_start(self.completions[cursel])
|
| 376 |
+
self.hide_window()
|
| 377 |
+
return None
|
| 378 |
+
|
| 379 |
+
elif keysym in ("Home", "End", "Prior", "Next", "Up", "Down") and \
|
| 380 |
+
not state:
|
| 381 |
+
# Move the selection in the listbox
|
| 382 |
+
self.userwantswindow = True
|
| 383 |
+
cursel = int(self.listbox.curselection()[0])
|
| 384 |
+
if keysym == "Home":
|
| 385 |
+
newsel = 0
|
| 386 |
+
elif keysym == "End":
|
| 387 |
+
newsel = len(self.completions)-1
|
| 388 |
+
elif keysym in ("Prior", "Next"):
|
| 389 |
+
jump = self.listbox.nearest(self.listbox.winfo_height()) - \
|
| 390 |
+
self.listbox.nearest(0)
|
| 391 |
+
if keysym == "Prior":
|
| 392 |
+
newsel = max(0, cursel-jump)
|
| 393 |
+
else:
|
| 394 |
+
assert keysym == "Next"
|
| 395 |
+
newsel = min(len(self.completions)-1, cursel+jump)
|
| 396 |
+
elif keysym == "Up":
|
| 397 |
+
newsel = max(0, cursel-1)
|
| 398 |
+
else:
|
| 399 |
+
assert keysym == "Down"
|
| 400 |
+
newsel = min(len(self.completions)-1, cursel+1)
|
| 401 |
+
self.listbox.select_clear(cursel)
|
| 402 |
+
self.listbox.select_set(newsel)
|
| 403 |
+
self._selection_changed()
|
| 404 |
+
self._change_start(self.completions[newsel])
|
| 405 |
+
return "break"
|
| 406 |
+
|
| 407 |
+
elif (keysym == "Tab" and not state):
|
| 408 |
+
if self.lastkey_was_tab:
|
| 409 |
+
# two tabs in a row; insert current selection and close acw
|
| 410 |
+
cursel = int(self.listbox.curselection()[0])
|
| 411 |
+
self._change_start(self.completions[cursel])
|
| 412 |
+
self.hide_window()
|
| 413 |
+
return "break"
|
| 414 |
+
else:
|
| 415 |
+
# first tab; let AutoComplete handle the completion
|
| 416 |
+
self.userwantswindow = True
|
| 417 |
+
self.lastkey_was_tab = True
|
| 418 |
+
return None
|
| 419 |
+
|
| 420 |
+
elif any(s in keysym for s in ("Shift", "Control", "Alt",
|
| 421 |
+
"Meta", "Command", "Option")):
|
| 422 |
+
# A modifier key, so ignore
|
| 423 |
+
return None
|
| 424 |
+
|
| 425 |
+
elif event.char and event.char >= ' ':
|
| 426 |
+
# Regular character with a non-length-1 keycode
|
| 427 |
+
self._change_start(self.start + event.char)
|
| 428 |
+
self.lasttypedstart = self.start
|
| 429 |
+
self.listbox.select_clear(0, int(self.listbox.curselection()[0]))
|
| 430 |
+
self.listbox.select_set(self._binary_search(self.start))
|
| 431 |
+
self._selection_changed()
|
| 432 |
+
return "break"
|
| 433 |
+
|
| 434 |
+
else:
|
| 435 |
+
# Unknown event, close the window and let it through.
|
| 436 |
+
self.hide_window()
|
| 437 |
+
return None
|
| 438 |
+
|
| 439 |
+
def keyrelease_event(self, event):
|
| 440 |
+
if not self.is_active():
|
| 441 |
+
return
|
| 442 |
+
if self.widget.index("insert") != \
|
| 443 |
+
self.widget.index("%s+%dc" % (self.startindex, len(self.start))):
|
| 444 |
+
# If we didn't catch an event which moved the insert, close window
|
| 445 |
+
self.hide_window()
|
| 446 |
+
|
| 447 |
+
def is_active(self):
|
| 448 |
+
return self.autocompletewindow is not None
|
| 449 |
+
|
| 450 |
+
def complete(self):
|
| 451 |
+
self._change_start(self._complete_string(self.start))
|
| 452 |
+
# The selection doesn't change.
|
| 453 |
+
|
| 454 |
+
def hide_window(self):
|
| 455 |
+
if not self.is_active():
|
| 456 |
+
return
|
| 457 |
+
|
| 458 |
+
# unbind events
|
| 459 |
+
self.autocompletewindow.event_delete(HIDE_VIRTUAL_EVENT_NAME,
|
| 460 |
+
HIDE_FOCUS_OUT_SEQUENCE)
|
| 461 |
+
for seq in HIDE_SEQUENCES:
|
| 462 |
+
self.widget.event_delete(HIDE_VIRTUAL_EVENT_NAME, seq)
|
| 463 |
+
|
| 464 |
+
self.autocompletewindow.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hideaid)
|
| 465 |
+
self.widget.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hidewid)
|
| 466 |
+
self.hideaid = None
|
| 467 |
+
self.hidewid = None
|
| 468 |
+
for seq in KEYPRESS_SEQUENCES:
|
| 469 |
+
self.widget.event_delete(KEYPRESS_VIRTUAL_EVENT_NAME, seq)
|
| 470 |
+
self.widget.unbind(KEYPRESS_VIRTUAL_EVENT_NAME, self.keypressid)
|
| 471 |
+
self.keypressid = None
|
| 472 |
+
self.widget.event_delete(KEYRELEASE_VIRTUAL_EVENT_NAME,
|
| 473 |
+
KEYRELEASE_SEQUENCE)
|
| 474 |
+
self.widget.unbind(KEYRELEASE_VIRTUAL_EVENT_NAME, self.keyreleaseid)
|
| 475 |
+
self.keyreleaseid = None
|
| 476 |
+
self.listbox.unbind(LISTUPDATE_SEQUENCE, self.listupdateid)
|
| 477 |
+
self.listupdateid = None
|
| 478 |
+
if self.winconfigid:
|
| 479 |
+
self.autocompletewindow.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
|
| 480 |
+
self.winconfigid = None
|
| 481 |
+
|
| 482 |
+
# Re-focusOn frame.text (See issue #15786)
|
| 483 |
+
self.widget.focus_set()
|
| 484 |
+
|
| 485 |
+
# destroy widgets
|
| 486 |
+
self.scrollbar.destroy()
|
| 487 |
+
self.scrollbar = None
|
| 488 |
+
self.listbox.destroy()
|
| 489 |
+
self.listbox = None
|
| 490 |
+
self.autocompletewindow.destroy()
|
| 491 |
+
self.autocompletewindow = None
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
if __name__ == '__main__':
|
| 495 |
+
from unittest import main
|
| 496 |
+
main('idlelib.idle_test.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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import builtins
|
| 2 |
+
import keyword
|
| 3 |
+
import re
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
from idlelib.config import idleConf
|
| 7 |
+
from idlelib.delegator import Delegator
|
| 8 |
+
|
| 9 |
+
DEBUG = False
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def any(name, alternates):
|
| 13 |
+
"Return a named group pattern matching list of alternates."
|
| 14 |
+
return "(?P<%s>" % name + "|".join(alternates) + ")"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def make_pat():
|
| 18 |
+
kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
|
| 19 |
+
match_softkw = (
|
| 20 |
+
r"^[ \t]*" + # at beginning of line + possible indentation
|
| 21 |
+
r"(?P<MATCH_SOFTKW>match)\b" +
|
| 22 |
+
r"(?![ \t]*(?:" + "|".join([ # not followed by ...
|
| 23 |
+
r"[:,;=^&|@~)\]}]", # a character which means it can't be a
|
| 24 |
+
# pattern-matching statement
|
| 25 |
+
r"\b(?:" + r"|".join(keyword.kwlist) + r")\b", # a keyword
|
| 26 |
+
]) +
|
| 27 |
+
r"))"
|
| 28 |
+
)
|
| 29 |
+
case_default = (
|
| 30 |
+
r"^[ \t]*" + # at beginning of line + possible indentation
|
| 31 |
+
r"(?P<CASE_SOFTKW>case)" +
|
| 32 |
+
r"[ \t]+(?P<CASE_DEFAULT_UNDERSCORE>_\b)"
|
| 33 |
+
)
|
| 34 |
+
case_softkw_and_pattern = (
|
| 35 |
+
r"^[ \t]*" + # at beginning of line + possible indentation
|
| 36 |
+
r"(?P<CASE_SOFTKW2>case)\b" +
|
| 37 |
+
r"(?![ \t]*(?:" + "|".join([ # not followed by ...
|
| 38 |
+
r"_\b", # a lone underscore
|
| 39 |
+
r"[:,;=^&|@~)\]}]", # a character which means it can't be a
|
| 40 |
+
# pattern-matching case
|
| 41 |
+
r"\b(?:" + r"|".join(keyword.kwlist) + r")\b", # a keyword
|
| 42 |
+
]) +
|
| 43 |
+
r"))"
|
| 44 |
+
)
|
| 45 |
+
builtinlist = [str(name) for name in dir(builtins)
|
| 46 |
+
if not name.startswith('_') and
|
| 47 |
+
name not in keyword.kwlist]
|
| 48 |
+
builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
|
| 49 |
+
comment = any("COMMENT", [r"#[^\n]*"])
|
| 50 |
+
stringprefix = r"(?i:r|u|f|fr|rf|b|br|rb)?"
|
| 51 |
+
sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?"
|
| 52 |
+
dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?'
|
| 53 |
+
sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
|
| 54 |
+
dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
|
| 55 |
+
string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
|
| 56 |
+
prog = re.compile("|".join([
|
| 57 |
+
builtin, comment, string, kw,
|
| 58 |
+
match_softkw, case_default,
|
| 59 |
+
case_softkw_and_pattern,
|
| 60 |
+
any("SYNC", [r"\n"]),
|
| 61 |
+
]),
|
| 62 |
+
re.DOTALL | re.MULTILINE)
|
| 63 |
+
return prog
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
prog = make_pat()
|
| 67 |
+
idprog = re.compile(r"\s+(\w+)")
|
| 68 |
+
prog_group_name_to_tag = {
|
| 69 |
+
"MATCH_SOFTKW": "KEYWORD",
|
| 70 |
+
"CASE_SOFTKW": "KEYWORD",
|
| 71 |
+
"CASE_DEFAULT_UNDERSCORE": "KEYWORD",
|
| 72 |
+
"CASE_SOFTKW2": "KEYWORD",
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def matched_named_groups(re_match):
|
| 77 |
+
"Get only the non-empty named groups from an re.Match object."
|
| 78 |
+
return ((k, v) for (k, v) in re_match.groupdict().items() if v)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def color_config(text):
|
| 82 |
+
"""Set color options of Text widget.
|
| 83 |
+
|
| 84 |
+
If ColorDelegator is used, this should be called first.
|
| 85 |
+
"""
|
| 86 |
+
# Called from htest, TextFrame, Editor, and Turtledemo.
|
| 87 |
+
# Not automatic because ColorDelegator does not know 'text'.
|
| 88 |
+
theme = idleConf.CurrentTheme()
|
| 89 |
+
normal_colors = idleConf.GetHighlight(theme, 'normal')
|
| 90 |
+
cursor_color = idleConf.GetHighlight(theme, 'cursor')['foreground']
|
| 91 |
+
select_colors = idleConf.GetHighlight(theme, 'hilite')
|
| 92 |
+
text.config(
|
| 93 |
+
foreground=normal_colors['foreground'],
|
| 94 |
+
background=normal_colors['background'],
|
| 95 |
+
insertbackground=cursor_color,
|
| 96 |
+
selectforeground=select_colors['foreground'],
|
| 97 |
+
selectbackground=select_colors['background'],
|
| 98 |
+
inactiveselectbackground=select_colors['background'], # new in 8.5
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class ColorDelegator(Delegator):
|
| 103 |
+
"""Delegator for syntax highlighting (text coloring).
|
| 104 |
+
|
| 105 |
+
Instance variables:
|
| 106 |
+
delegate: Delegator below this one in the stack, meaning the
|
| 107 |
+
one this one delegates to.
|
| 108 |
+
|
| 109 |
+
Used to track state:
|
| 110 |
+
after_id: Identifier for scheduled after event, which is a
|
| 111 |
+
timer for colorizing the text.
|
| 112 |
+
allow_colorizing: Boolean toggle for applying colorizing.
|
| 113 |
+
colorizing: Boolean flag when colorizing is in process.
|
| 114 |
+
stop_colorizing: Boolean flag to end an active colorizing
|
| 115 |
+
process.
|
| 116 |
+
"""
|
| 117 |
+
|
| 118 |
+
def __init__(self):
|
| 119 |
+
Delegator.__init__(self)
|
| 120 |
+
self.init_state()
|
| 121 |
+
self.prog = prog
|
| 122 |
+
self.idprog = idprog
|
| 123 |
+
self.LoadTagDefs()
|
| 124 |
+
|
| 125 |
+
def init_state(self):
|
| 126 |
+
"Initialize variables that track colorizing state."
|
| 127 |
+
self.after_id = None
|
| 128 |
+
self.allow_colorizing = True
|
| 129 |
+
self.stop_colorizing = False
|
| 130 |
+
self.colorizing = False
|
| 131 |
+
|
| 132 |
+
def setdelegate(self, delegate):
|
| 133 |
+
"""Set the delegate for this instance.
|
| 134 |
+
|
| 135 |
+
A delegate is an instance of a Delegator class and each
|
| 136 |
+
delegate points to the next delegator in the stack. This
|
| 137 |
+
allows multiple delegators to be chained together for a
|
| 138 |
+
widget. The bottom delegate for a colorizer is a Text
|
| 139 |
+
widget.
|
| 140 |
+
|
| 141 |
+
If there is a delegate, also start the colorizing process.
|
| 142 |
+
"""
|
| 143 |
+
if self.delegate is not None:
|
| 144 |
+
self.unbind("<<toggle-auto-coloring>>")
|
| 145 |
+
Delegator.setdelegate(self, delegate)
|
| 146 |
+
if delegate is not None:
|
| 147 |
+
self.config_colors()
|
| 148 |
+
self.bind("<<toggle-auto-coloring>>", self.toggle_colorize_event)
|
| 149 |
+
self.notify_range("1.0", "end")
|
| 150 |
+
else:
|
| 151 |
+
# No delegate - stop any colorizing.
|
| 152 |
+
self.stop_colorizing = True
|
| 153 |
+
self.allow_colorizing = False
|
| 154 |
+
|
| 155 |
+
def config_colors(self):
|
| 156 |
+
"Configure text widget tags with colors from tagdefs."
|
| 157 |
+
for tag, cnf in self.tagdefs.items():
|
| 158 |
+
self.tag_configure(tag, **cnf)
|
| 159 |
+
self.tag_raise('sel')
|
| 160 |
+
|
| 161 |
+
def LoadTagDefs(self):
|
| 162 |
+
"Create dictionary of tag names to text colors."
|
| 163 |
+
theme = idleConf.CurrentTheme()
|
| 164 |
+
self.tagdefs = {
|
| 165 |
+
"COMMENT": idleConf.GetHighlight(theme, "comment"),
|
| 166 |
+
"KEYWORD": idleConf.GetHighlight(theme, "keyword"),
|
| 167 |
+
"BUILTIN": idleConf.GetHighlight(theme, "builtin"),
|
| 168 |
+
"STRING": idleConf.GetHighlight(theme, "string"),
|
| 169 |
+
"DEFINITION": idleConf.GetHighlight(theme, "definition"),
|
| 170 |
+
"SYNC": {'background': None, 'foreground': None},
|
| 171 |
+
"TODO": {'background': None, 'foreground': None},
|
| 172 |
+
"ERROR": idleConf.GetHighlight(theme, "error"),
|
| 173 |
+
# "hit" is used by ReplaceDialog to mark matches. It shouldn't be changed by Colorizer, but
|
| 174 |
+
# that currently isn't technically possible. This should be moved elsewhere in the future
|
| 175 |
+
# when fixing the "hit" tag's visibility, or when the replace dialog is replaced with a
|
| 176 |
+
# non-modal alternative.
|
| 177 |
+
"hit": idleConf.GetHighlight(theme, "hit"),
|
| 178 |
+
}
|
| 179 |
+
if DEBUG: print('tagdefs', self.tagdefs)
|
| 180 |
+
|
| 181 |
+
def insert(self, index, chars, tags=None):
|
| 182 |
+
"Insert chars into widget at index and mark for colorizing."
|
| 183 |
+
index = self.index(index)
|
| 184 |
+
self.delegate.insert(index, chars, tags)
|
| 185 |
+
self.notify_range(index, index + "+%dc" % len(chars))
|
| 186 |
+
|
| 187 |
+
def delete(self, index1, index2=None):
|
| 188 |
+
"Delete chars between indexes and mark for colorizing."
|
| 189 |
+
index1 = self.index(index1)
|
| 190 |
+
self.delegate.delete(index1, index2)
|
| 191 |
+
self.notify_range(index1)
|
| 192 |
+
|
| 193 |
+
def notify_range(self, index1, index2=None):
|
| 194 |
+
"Mark text changes for processing and restart colorizing, if active."
|
| 195 |
+
self.tag_add("TODO", index1, index2)
|
| 196 |
+
if self.after_id:
|
| 197 |
+
if DEBUG: print("colorizing already scheduled")
|
| 198 |
+
return
|
| 199 |
+
if self.colorizing:
|
| 200 |
+
self.stop_colorizing = True
|
| 201 |
+
if DEBUG: print("stop colorizing")
|
| 202 |
+
if self.allow_colorizing:
|
| 203 |
+
if DEBUG: print("schedule colorizing")
|
| 204 |
+
self.after_id = self.after(1, self.recolorize)
|
| 205 |
+
return
|
| 206 |
+
|
| 207 |
+
def close(self):
|
| 208 |
+
if self.after_id:
|
| 209 |
+
after_id = self.after_id
|
| 210 |
+
self.after_id = None
|
| 211 |
+
if DEBUG: print("cancel scheduled recolorizer")
|
| 212 |
+
self.after_cancel(after_id)
|
| 213 |
+
self.allow_colorizing = False
|
| 214 |
+
self.stop_colorizing = True
|
| 215 |
+
|
| 216 |
+
def toggle_colorize_event(self, event=None):
|
| 217 |
+
"""Toggle colorizing on and off.
|
| 218 |
+
|
| 219 |
+
When toggling off, if colorizing is scheduled or is in
|
| 220 |
+
process, it will be cancelled and/or stopped.
|
| 221 |
+
|
| 222 |
+
When toggling on, colorizing will be scheduled.
|
| 223 |
+
"""
|
| 224 |
+
if self.after_id:
|
| 225 |
+
after_id = self.after_id
|
| 226 |
+
self.after_id = None
|
| 227 |
+
if DEBUG: print("cancel scheduled recolorizer")
|
| 228 |
+
self.after_cancel(after_id)
|
| 229 |
+
if self.allow_colorizing and self.colorizing:
|
| 230 |
+
if DEBUG: print("stop colorizing")
|
| 231 |
+
self.stop_colorizing = True
|
| 232 |
+
self.allow_colorizing = not self.allow_colorizing
|
| 233 |
+
if self.allow_colorizing and not self.colorizing:
|
| 234 |
+
self.after_id = self.after(1, self.recolorize)
|
| 235 |
+
if DEBUG:
|
| 236 |
+
print("auto colorizing turned",
|
| 237 |
+
"on" if self.allow_colorizing else "off")
|
| 238 |
+
return "break"
|
| 239 |
+
|
| 240 |
+
def recolorize(self):
|
| 241 |
+
"""Timer event (every 1ms) to colorize text.
|
| 242 |
+
|
| 243 |
+
Colorizing is only attempted when the text widget exists,
|
| 244 |
+
when colorizing is toggled on, and when the colorizing
|
| 245 |
+
process is not already running.
|
| 246 |
+
|
| 247 |
+
After colorizing is complete, some cleanup is done to
|
| 248 |
+
make sure that all the text has been colorized.
|
| 249 |
+
"""
|
| 250 |
+
self.after_id = None
|
| 251 |
+
if not self.delegate:
|
| 252 |
+
if DEBUG: print("no delegate")
|
| 253 |
+
return
|
| 254 |
+
if not self.allow_colorizing:
|
| 255 |
+
if DEBUG: print("auto colorizing is off")
|
| 256 |
+
return
|
| 257 |
+
if self.colorizing:
|
| 258 |
+
if DEBUG: print("already colorizing")
|
| 259 |
+
return
|
| 260 |
+
try:
|
| 261 |
+
self.stop_colorizing = False
|
| 262 |
+
self.colorizing = True
|
| 263 |
+
if DEBUG: print("colorizing...")
|
| 264 |
+
t0 = time.perf_counter()
|
| 265 |
+
self.recolorize_main()
|
| 266 |
+
t1 = time.perf_counter()
|
| 267 |
+
if DEBUG: print("%.3f seconds" % (t1-t0))
|
| 268 |
+
finally:
|
| 269 |
+
self.colorizing = False
|
| 270 |
+
if self.allow_colorizing and self.tag_nextrange("TODO", "1.0"):
|
| 271 |
+
if DEBUG: print("reschedule colorizing")
|
| 272 |
+
self.after_id = self.after(1, self.recolorize)
|
| 273 |
+
|
| 274 |
+
def recolorize_main(self):
|
| 275 |
+
"Evaluate text and apply colorizing tags."
|
| 276 |
+
next = "1.0"
|
| 277 |
+
while todo_tag_range := self.tag_nextrange("TODO", next):
|
| 278 |
+
self.tag_remove("SYNC", todo_tag_range[0], todo_tag_range[1])
|
| 279 |
+
sync_tag_range = self.tag_prevrange("SYNC", todo_tag_range[0])
|
| 280 |
+
head = sync_tag_range[1] if sync_tag_range else "1.0"
|
| 281 |
+
|
| 282 |
+
chars = ""
|
| 283 |
+
next = head
|
| 284 |
+
lines_to_get = 1
|
| 285 |
+
ok = False
|
| 286 |
+
while not ok:
|
| 287 |
+
mark = next
|
| 288 |
+
next = self.index(mark + "+%d lines linestart" %
|
| 289 |
+
lines_to_get)
|
| 290 |
+
lines_to_get = min(lines_to_get * 2, 100)
|
| 291 |
+
ok = "SYNC" in self.tag_names(next + "-1c")
|
| 292 |
+
line = self.get(mark, next)
|
| 293 |
+
##print head, "get", mark, next, "->", repr(line)
|
| 294 |
+
if not line:
|
| 295 |
+
return
|
| 296 |
+
for tag in self.tagdefs:
|
| 297 |
+
self.tag_remove(tag, mark, next)
|
| 298 |
+
chars += line
|
| 299 |
+
self._add_tags_in_section(chars, head)
|
| 300 |
+
if "SYNC" in self.tag_names(next + "-1c"):
|
| 301 |
+
head = next
|
| 302 |
+
chars = ""
|
| 303 |
+
else:
|
| 304 |
+
ok = False
|
| 305 |
+
if not ok:
|
| 306 |
+
# We're in an inconsistent state, and the call to
|
| 307 |
+
# update may tell us to stop. It may also change
|
| 308 |
+
# the correct value for "next" (since this is a
|
| 309 |
+
# line.col string, not a true mark). So leave a
|
| 310 |
+
# crumb telling the next invocation to resume here
|
| 311 |
+
# in case update tells us to leave.
|
| 312 |
+
self.tag_add("TODO", next)
|
| 313 |
+
self.update_idletasks()
|
| 314 |
+
if self.stop_colorizing:
|
| 315 |
+
if DEBUG: print("colorizing stopped")
|
| 316 |
+
return
|
| 317 |
+
|
| 318 |
+
def _add_tag(self, start, end, head, matched_group_name):
|
| 319 |
+
"""Add a tag to a given range in the text widget.
|
| 320 |
+
|
| 321 |
+
This is a utility function, receiving the range as `start` and
|
| 322 |
+
`end` positions, each of which is a number of characters
|
| 323 |
+
relative to the given `head` index in the text widget.
|
| 324 |
+
|
| 325 |
+
The tag to add is determined by `matched_group_name`, which is
|
| 326 |
+
the name of a regular expression "named group" as matched by
|
| 327 |
+
by the relevant highlighting regexps.
|
| 328 |
+
"""
|
| 329 |
+
tag = prog_group_name_to_tag.get(matched_group_name,
|
| 330 |
+
matched_group_name)
|
| 331 |
+
self.tag_add(tag,
|
| 332 |
+
f"{head}+{start:d}c",
|
| 333 |
+
f"{head}+{end:d}c")
|
| 334 |
+
|
| 335 |
+
def _add_tags_in_section(self, chars, head):
|
| 336 |
+
"""Parse and add highlighting tags to a given part of the text.
|
| 337 |
+
|
| 338 |
+
`chars` is a string with the text to parse and to which
|
| 339 |
+
highlighting is to be applied.
|
| 340 |
+
|
| 341 |
+
`head` is the index in the text widget where the text is found.
|
| 342 |
+
"""
|
| 343 |
+
for m in self.prog.finditer(chars):
|
| 344 |
+
for name, matched_text in matched_named_groups(m):
|
| 345 |
+
a, b = m.span(name)
|
| 346 |
+
self._add_tag(a, b, head, name)
|
| 347 |
+
if matched_text in ("def", "class"):
|
| 348 |
+
if m1 := self.idprog.match(chars, b):
|
| 349 |
+
a, b = m1.span(1)
|
| 350 |
+
self._add_tag(a, b, head, "DEFINITION")
|
| 351 |
+
|
| 352 |
+
def removecolors(self):
|
| 353 |
+
"Remove all colorizing tags."
|
| 354 |
+
for tag in self.tagdefs:
|
| 355 |
+
self.tag_remove(tag, "1.0", "end")
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
def _color_delegator(parent): # htest #
|
| 359 |
+
from tkinter import Toplevel, Text
|
| 360 |
+
from idlelib.idle_test.test_colorizer import source
|
| 361 |
+
from idlelib.percolator import Percolator
|
| 362 |
+
|
| 363 |
+
top = Toplevel(parent)
|
| 364 |
+
top.title("Test ColorDelegator")
|
| 365 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 366 |
+
top.geometry("700x550+%d+%d" % (x + 20, y + 175))
|
| 367 |
+
|
| 368 |
+
text = Text(top, background="white")
|
| 369 |
+
text.pack(expand=1, fill="both")
|
| 370 |
+
text.insert("insert", source)
|
| 371 |
+
text.focus_set()
|
| 372 |
+
|
| 373 |
+
color_config(text)
|
| 374 |
+
p = Percolator(text)
|
| 375 |
+
d = ColorDelegator()
|
| 376 |
+
p.insertfilter(d)
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
if __name__ == "__main__":
|
| 380 |
+
from unittest import main
|
| 381 |
+
main('idlelib.idle_test.test_colorizer', verbosity=2, exit=False)
|
| 382 |
+
|
| 383 |
+
from idlelib.idle_test.htest import run
|
| 384 |
+
run(_color_delegator)
|
data/conda_envs/evalclaw/lib/python3.11/idlelib/config-highlight.def
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IDLE reads several config files to determine user preferences. This
|
| 2 |
+
# file is the default config file for idle highlight theme settings.
|
| 3 |
+
|
| 4 |
+
[IDLE Classic]
|
| 5 |
+
normal-foreground= #000000
|
| 6 |
+
normal-background= #ffffff
|
| 7 |
+
keyword-foreground= #ff7700
|
| 8 |
+
keyword-background= #ffffff
|
| 9 |
+
builtin-foreground= #900090
|
| 10 |
+
builtin-background= #ffffff
|
| 11 |
+
comment-foreground= #dd0000
|
| 12 |
+
comment-background= #ffffff
|
| 13 |
+
string-foreground= #00aa00
|
| 14 |
+
string-background= #ffffff
|
| 15 |
+
definition-foreground= #0000ff
|
| 16 |
+
definition-background= #ffffff
|
| 17 |
+
hilite-foreground= #000000
|
| 18 |
+
hilite-background= gray
|
| 19 |
+
break-foreground= black
|
| 20 |
+
break-background= #ffff55
|
| 21 |
+
hit-foreground= #ffffff
|
| 22 |
+
hit-background= #000000
|
| 23 |
+
error-foreground= #000000
|
| 24 |
+
error-background= #ff7777
|
| 25 |
+
context-foreground= #000000
|
| 26 |
+
context-background= lightgray
|
| 27 |
+
linenumber-foreground= gray
|
| 28 |
+
linenumber-background= #ffffff
|
| 29 |
+
#cursor (only foreground can be set, restart IDLE)
|
| 30 |
+
cursor-foreground= black
|
| 31 |
+
#shell window
|
| 32 |
+
stdout-foreground= blue
|
| 33 |
+
stdout-background= #ffffff
|
| 34 |
+
stderr-foreground= red
|
| 35 |
+
stderr-background= #ffffff
|
| 36 |
+
console-foreground= #770000
|
| 37 |
+
console-background= #ffffff
|
| 38 |
+
|
| 39 |
+
[IDLE New]
|
| 40 |
+
normal-foreground= #000000
|
| 41 |
+
normal-background= #ffffff
|
| 42 |
+
keyword-foreground= #ff7700
|
| 43 |
+
keyword-background= #ffffff
|
| 44 |
+
builtin-foreground= #900090
|
| 45 |
+
builtin-background= #ffffff
|
| 46 |
+
comment-foreground= #dd0000
|
| 47 |
+
comment-background= #ffffff
|
| 48 |
+
string-foreground= #00aa00
|
| 49 |
+
string-background= #ffffff
|
| 50 |
+
definition-foreground= #0000ff
|
| 51 |
+
definition-background= #ffffff
|
| 52 |
+
hilite-foreground= #000000
|
| 53 |
+
hilite-background= gray
|
| 54 |
+
break-foreground= black
|
| 55 |
+
break-background= #ffff55
|
| 56 |
+
hit-foreground= #ffffff
|
| 57 |
+
hit-background= #000000
|
| 58 |
+
error-foreground= #000000
|
| 59 |
+
error-background= #ff7777
|
| 60 |
+
context-foreground= #000000
|
| 61 |
+
context-background= lightgray
|
| 62 |
+
linenumber-foreground= gray
|
| 63 |
+
linenumber-background= #ffffff
|
| 64 |
+
#cursor (only foreground can be set, restart IDLE)
|
| 65 |
+
cursor-foreground= black
|
| 66 |
+
#shell window
|
| 67 |
+
stdout-foreground= blue
|
| 68 |
+
stdout-background= #ffffff
|
| 69 |
+
stderr-foreground= red
|
| 70 |
+
stderr-background= #ffffff
|
| 71 |
+
console-foreground= #770000
|
| 72 |
+
console-background= #ffffff
|
| 73 |
+
|
| 74 |
+
[IDLE Dark]
|
| 75 |
+
comment-foreground = #dd0000
|
| 76 |
+
console-foreground = #ff4d4d
|
| 77 |
+
error-foreground = #FFFFFF
|
| 78 |
+
hilite-background = #7e7e7e
|
| 79 |
+
string-foreground = #02ff02
|
| 80 |
+
stderr-background = #002240
|
| 81 |
+
stderr-foreground = #ffb3b3
|
| 82 |
+
console-background = #002240
|
| 83 |
+
hit-background = #fbfbfb
|
| 84 |
+
string-background = #002240
|
| 85 |
+
normal-background = #002240
|
| 86 |
+
hilite-foreground = #FFFFFF
|
| 87 |
+
keyword-foreground = #ff8000
|
| 88 |
+
error-background = #c86464
|
| 89 |
+
keyword-background = #002240
|
| 90 |
+
builtin-background = #002240
|
| 91 |
+
break-background = #808000
|
| 92 |
+
builtin-foreground = #ff00ff
|
| 93 |
+
definition-foreground = #5e5eff
|
| 94 |
+
stdout-foreground = #c2d1fa
|
| 95 |
+
definition-background = #002240
|
| 96 |
+
normal-foreground = #FFFFFF
|
| 97 |
+
cursor-foreground = #ffffff
|
| 98 |
+
stdout-background = #002240
|
| 99 |
+
hit-foreground = #002240
|
| 100 |
+
comment-background = #002240
|
| 101 |
+
break-foreground = #FFFFFF
|
| 102 |
+
context-foreground= #ffffff
|
| 103 |
+
context-background= #454545
|
| 104 |
+
linenumber-foreground= gray
|
| 105 |
+
linenumber-background= #002240
|
data/conda_env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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IDLE reads several config files to determine user preferences. This
|
| 2 |
+
# file is the default config file for idle key binding settings.
|
| 3 |
+
# Where multiple keys are specified for an action: if they are separated
|
| 4 |
+
# by a space (eg. action=<key1> <key2>) then the keys are alternatives, if
|
| 5 |
+
# there is no space (eg. action=<key1><key2>) then the keys comprise a
|
| 6 |
+
# single 'emacs style' multi-keystoke binding. The tk event specifier 'Key'
|
| 7 |
+
# is used in all cases, for consistency in auto key conflict checking in the
|
| 8 |
+
# configuration gui.
|
| 9 |
+
|
| 10 |
+
[IDLE Classic Windows]
|
| 11 |
+
copy=<Control-Key-c> <Control-Key-C>
|
| 12 |
+
cut=<Control-Key-x> <Control-Key-X>
|
| 13 |
+
paste=<Control-Key-v> <Control-Key-V>
|
| 14 |
+
beginning-of-line= <Key-Home>
|
| 15 |
+
center-insert=<Control-Key-l> <Control-Key-L>
|
| 16 |
+
close-all-windows=<Control-Key-q> <Control-Key-Q>
|
| 17 |
+
close-window=<Alt-Key-F4> <Meta-Key-F4>
|
| 18 |
+
do-nothing=<Control-Key-F12>
|
| 19 |
+
end-of-file=<Control-Key-d> <Control-Key-D>
|
| 20 |
+
python-docs=<Key-F1>
|
| 21 |
+
python-context-help=<Shift-Key-F1>
|
| 22 |
+
history-next=<Alt-Key-n> <Meta-Key-n> <Alt-Key-N> <Meta-Key-N>
|
| 23 |
+
history-previous=<Alt-Key-p> <Meta-Key-p> <Alt-Key-P> <Meta-Key-P>
|
| 24 |
+
interrupt-execution=<Control-Key-c> <Control-Key-C>
|
| 25 |
+
view-restart=<Key-F6>
|
| 26 |
+
restart-shell=<Control-Key-F6>
|
| 27 |
+
open-class-browser=<Alt-Key-c> <Meta-Key-c> <Alt-Key-C> <Meta-Key-C>
|
| 28 |
+
open-module=<Alt-Key-m> <Meta-Key-m> <Alt-Key-M> <Meta-Key-M>
|
| 29 |
+
open-new-window=<Control-Key-n> <Control-Key-N>
|
| 30 |
+
open-window-from-file=<Control-Key-o> <Control-Key-O>
|
| 31 |
+
plain-newline-and-indent=<Control-Key-j> <Control-Key-J>
|
| 32 |
+
print-window=<Control-Key-p> <Control-Key-P>
|
| 33 |
+
redo=<Control-Shift-Key-Z> <Control-Shift-Key-z>
|
| 34 |
+
remove-selection=<Key-Escape>
|
| 35 |
+
save-copy-of-window-as-file=<Alt-Shift-Key-S> <Alt-Shift-Key-s>
|
| 36 |
+
save-window-as-file=<Control-Shift-Key-S> <Control-Shift-Key-s>
|
| 37 |
+
save-window=<Control-Key-s> <Control-Key-S>
|
| 38 |
+
select-all=<Control-Key-a> <Control-Key-A>
|
| 39 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 40 |
+
undo=<Control-Key-z> <Control-Key-Z>
|
| 41 |
+
find=<Control-Key-f> <Control-Key-F>
|
| 42 |
+
find-again=<Control-Key-g> <Key-F3> <Control-Key-G>
|
| 43 |
+
find-in-files=<Alt-Key-F3> <Meta-Key-F3>
|
| 44 |
+
find-selection=<Control-Key-F3>
|
| 45 |
+
replace=<Control-Key-h> <Control-Key-H>
|
| 46 |
+
goto-line=<Alt-Key-g> <Meta-Key-g> <Alt-Key-G> <Meta-Key-G>
|
| 47 |
+
smart-backspace=<Key-BackSpace>
|
| 48 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 49 |
+
smart-indent=<Key-Tab>
|
| 50 |
+
indent-region=<Control-Key-bracketright>
|
| 51 |
+
dedent-region=<Control-Key-bracketleft>
|
| 52 |
+
comment-region=<Alt-Key-3> <Meta-Key-3>
|
| 53 |
+
uncomment-region=<Alt-Key-4> <Meta-Key-4>
|
| 54 |
+
tabify-region=<Alt-Key-5> <Meta-Key-5>
|
| 55 |
+
untabify-region=<Alt-Key-6> <Meta-Key-6>
|
| 56 |
+
toggle-tabs=<Alt-Key-t> <Meta-Key-t> <Alt-Key-T> <Meta-Key-T>
|
| 57 |
+
change-indentwidth=<Alt-Key-u> <Meta-Key-u> <Alt-Key-U> <Meta-Key-U>
|
| 58 |
+
del-word-left=<Control-Key-BackSpace>
|
| 59 |
+
del-word-right=<Control-Key-Delete>
|
| 60 |
+
force-open-completions= <Control-Key-space>
|
| 61 |
+
expand-word= <Alt-Key-slash>
|
| 62 |
+
force-open-calltip= <Control-Key-backslash>
|
| 63 |
+
format-paragraph= <Alt-Key-q>
|
| 64 |
+
flash-paren= <Control-Key-0>
|
| 65 |
+
run-module= <Key-F5>
|
| 66 |
+
run-custom= <Shift-Key-F5>
|
| 67 |
+
check-module= <Alt-Key-x>
|
| 68 |
+
zoom-height= <Alt-Key-2>
|
| 69 |
+
|
| 70 |
+
[IDLE Classic Unix]
|
| 71 |
+
copy=<Alt-Key-w> <Meta-Key-w>
|
| 72 |
+
cut=<Control-Key-w>
|
| 73 |
+
paste=<Control-Key-y>
|
| 74 |
+
beginning-of-line=<Control-Key-a> <Key-Home>
|
| 75 |
+
center-insert=<Control-Key-l>
|
| 76 |
+
close-all-windows=<Control-Key-x><Control-Key-c>
|
| 77 |
+
close-window=<Control-Key-x><Control-Key-0>
|
| 78 |
+
do-nothing=<Control-Key-x>
|
| 79 |
+
end-of-file=<Control-Key-d>
|
| 80 |
+
history-next=<Alt-Key-n> <Meta-Key-n>
|
| 81 |
+
history-previous=<Alt-Key-p> <Meta-Key-p>
|
| 82 |
+
interrupt-execution=<Control-Key-c>
|
| 83 |
+
view-restart=<Key-F6>
|
| 84 |
+
restart-shell=<Control-Key-F6>
|
| 85 |
+
open-class-browser=<Control-Key-x><Control-Key-b>
|
| 86 |
+
open-module=<Control-Key-x><Control-Key-m>
|
| 87 |
+
open-new-window=<Control-Key-x><Control-Key-n>
|
| 88 |
+
open-window-from-file=<Control-Key-x><Control-Key-f>
|
| 89 |
+
plain-newline-and-indent=<Control-Key-j>
|
| 90 |
+
print-window=<Control-x><Control-Key-p>
|
| 91 |
+
python-docs=<Control-Key-h>
|
| 92 |
+
python-context-help=<Control-Shift-Key-H>
|
| 93 |
+
redo=<Alt-Key-z> <Meta-Key-z>
|
| 94 |
+
remove-selection=<Key-Escape>
|
| 95 |
+
save-copy-of-window-as-file=<Control-Key-x><Control-Key-y>
|
| 96 |
+
save-window-as-file=<Control-Key-x><Control-Key-w>
|
| 97 |
+
save-window=<Control-Key-x><Control-Key-s>
|
| 98 |
+
select-all=<Alt-Key-a> <Meta-Key-a>
|
| 99 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 100 |
+
undo=<Control-Key-z>
|
| 101 |
+
find=<Control-Key-u><Control-Key-u><Control-Key-s>
|
| 102 |
+
find-again=<Control-Key-u><Control-Key-s>
|
| 103 |
+
find-in-files=<Alt-Key-s> <Meta-Key-s>
|
| 104 |
+
find-selection=<Control-Key-s>
|
| 105 |
+
replace=<Control-Key-r>
|
| 106 |
+
goto-line=<Alt-Key-g> <Meta-Key-g>
|
| 107 |
+
smart-backspace=<Key-BackSpace>
|
| 108 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 109 |
+
smart-indent=<Key-Tab>
|
| 110 |
+
indent-region=<Control-Key-bracketright>
|
| 111 |
+
dedent-region=<Control-Key-bracketleft>
|
| 112 |
+
comment-region=<Alt-Key-3>
|
| 113 |
+
uncomment-region=<Alt-Key-4>
|
| 114 |
+
tabify-region=<Alt-Key-5>
|
| 115 |
+
untabify-region=<Alt-Key-6>
|
| 116 |
+
toggle-tabs=<Alt-Key-t>
|
| 117 |
+
change-indentwidth=<Alt-Key-u>
|
| 118 |
+
del-word-left=<Alt-Key-BackSpace>
|
| 119 |
+
del-word-right=<Alt-Key-d>
|
| 120 |
+
force-open-completions= <Control-Key-space>
|
| 121 |
+
expand-word= <Alt-Key-slash>
|
| 122 |
+
force-open-calltip= <Control-Key-backslash>
|
| 123 |
+
format-paragraph= <Alt-Key-q>
|
| 124 |
+
flash-paren= <Control-Key-0>
|
| 125 |
+
run-module= <Key-F5>
|
| 126 |
+
run-custom= <Shift-Key-F5>
|
| 127 |
+
check-module= <Alt-Key-x>
|
| 128 |
+
zoom-height= <Alt-Key-2>
|
| 129 |
+
|
| 130 |
+
[IDLE Modern Unix]
|
| 131 |
+
copy = <Control-Shift-Key-C> <Control-Key-Insert>
|
| 132 |
+
cut = <Control-Key-x> <Shift-Key-Delete>
|
| 133 |
+
paste = <Control-Key-v> <Shift-Key-Insert>
|
| 134 |
+
beginning-of-line = <Key-Home>
|
| 135 |
+
center-insert = <Control-Key-l>
|
| 136 |
+
close-all-windows = <Control-Key-q>
|
| 137 |
+
close-window = <Control-Key-w> <Control-Shift-Key-W>
|
| 138 |
+
do-nothing = <Control-Key-F12>
|
| 139 |
+
end-of-file = <Control-Key-d>
|
| 140 |
+
history-next = <Alt-Key-n> <Meta-Key-n>
|
| 141 |
+
history-previous = <Alt-Key-p> <Meta-Key-p>
|
| 142 |
+
interrupt-execution = <Control-Key-c>
|
| 143 |
+
view-restart = <Key-F6>
|
| 144 |
+
restart-shell = <Control-Key-F6>
|
| 145 |
+
open-class-browser = <Control-Key-b>
|
| 146 |
+
open-module = <Control-Key-m>
|
| 147 |
+
open-new-window = <Control-Key-n>
|
| 148 |
+
open-window-from-file = <Control-Key-o>
|
| 149 |
+
plain-newline-and-indent = <Control-Key-j>
|
| 150 |
+
print-window = <Control-Key-p>
|
| 151 |
+
python-context-help = <Shift-Key-F1>
|
| 152 |
+
python-docs = <Key-F1>
|
| 153 |
+
redo = <Control-Shift-Key-Z>
|
| 154 |
+
remove-selection = <Key-Escape>
|
| 155 |
+
save-copy-of-window-as-file = <Alt-Shift-Key-S>
|
| 156 |
+
save-window-as-file = <Control-Shift-Key-S>
|
| 157 |
+
save-window = <Control-Key-s>
|
| 158 |
+
select-all = <Control-Key-a>
|
| 159 |
+
toggle-auto-coloring = <Control-Key-slash>
|
| 160 |
+
undo = <Control-Key-z>
|
| 161 |
+
find = <Control-Key-f>
|
| 162 |
+
find-again = <Key-F3>
|
| 163 |
+
find-in-files = <Control-Shift-Key-f>
|
| 164 |
+
find-selection = <Control-Key-h>
|
| 165 |
+
replace = <Control-Key-r>
|
| 166 |
+
goto-line = <Control-Key-g>
|
| 167 |
+
smart-backspace = <Key-BackSpace>
|
| 168 |
+
newline-and-indent = <Key-Return> <Key-KP_Enter>
|
| 169 |
+
smart-indent = <Key-Tab>
|
| 170 |
+
indent-region = <Control-Key-bracketright>
|
| 171 |
+
dedent-region = <Control-Key-bracketleft>
|
| 172 |
+
comment-region = <Control-Key-d>
|
| 173 |
+
uncomment-region = <Control-Shift-Key-D>
|
| 174 |
+
tabify-region = <Alt-Key-5>
|
| 175 |
+
untabify-region = <Alt-Key-6>
|
| 176 |
+
toggle-tabs = <Control-Key-T>
|
| 177 |
+
change-indentwidth = <Alt-Key-u>
|
| 178 |
+
del-word-left = <Control-Key-BackSpace>
|
| 179 |
+
del-word-right = <Control-Key-Delete>
|
| 180 |
+
force-open-completions= <Control-Key-space>
|
| 181 |
+
expand-word= <Alt-Key-slash>
|
| 182 |
+
force-open-calltip= <Control-Key-backslash>
|
| 183 |
+
format-paragraph= <Alt-Key-q>
|
| 184 |
+
flash-paren= <Control-Key-0>
|
| 185 |
+
run-module= <Key-F5>
|
| 186 |
+
run-custom= <Shift-Key-F5>
|
| 187 |
+
check-module= <Alt-Key-x>
|
| 188 |
+
zoom-height= <Alt-Key-2>
|
| 189 |
+
|
| 190 |
+
[IDLE Classic Mac]
|
| 191 |
+
copy=<Command-Key-c>
|
| 192 |
+
cut=<Command-Key-x>
|
| 193 |
+
paste=<Command-Key-v>
|
| 194 |
+
beginning-of-line= <Key-Home>
|
| 195 |
+
center-insert=<Control-Key-l>
|
| 196 |
+
close-all-windows=<Command-Key-q>
|
| 197 |
+
close-window=<Command-Key-w>
|
| 198 |
+
do-nothing=<Control-Key-F12>
|
| 199 |
+
end-of-file=<Control-Key-d>
|
| 200 |
+
python-docs=<Key-F1>
|
| 201 |
+
python-context-help=<Shift-Key-F1>
|
| 202 |
+
history-next=<Control-Key-n>
|
| 203 |
+
history-previous=<Control-Key-p>
|
| 204 |
+
interrupt-execution=<Control-Key-c>
|
| 205 |
+
view-restart=<Key-F6>
|
| 206 |
+
restart-shell=<Control-Key-F6>
|
| 207 |
+
open-class-browser=<Command-Key-b>
|
| 208 |
+
open-module=<Command-Key-m>
|
| 209 |
+
open-new-window=<Command-Key-n>
|
| 210 |
+
open-window-from-file=<Command-Key-o>
|
| 211 |
+
plain-newline-and-indent=<Control-Key-j>
|
| 212 |
+
print-window=<Command-Key-p>
|
| 213 |
+
redo=<Shift-Command-Key-Z>
|
| 214 |
+
remove-selection=<Key-Escape>
|
| 215 |
+
save-window-as-file=<Shift-Command-Key-S>
|
| 216 |
+
save-window=<Command-Key-s>
|
| 217 |
+
save-copy-of-window-as-file=<Option-Command-Key-s>
|
| 218 |
+
select-all=<Command-Key-a>
|
| 219 |
+
toggle-auto-coloring=<Control-Key-slash>
|
| 220 |
+
undo=<Command-Key-z>
|
| 221 |
+
find=<Command-Key-f>
|
| 222 |
+
find-again=<Command-Key-g> <Key-F3>
|
| 223 |
+
find-in-files=<Command-Key-F3>
|
| 224 |
+
find-selection=<Shift-Command-Key-F3>
|
| 225 |
+
replace=<Command-Key-r>
|
| 226 |
+
goto-line=<Command-Key-j>
|
| 227 |
+
smart-backspace=<Key-BackSpace>
|
| 228 |
+
newline-and-indent=<Key-Return> <Key-KP_Enter>
|
| 229 |
+
smart-indent=<Key-Tab>
|
| 230 |
+
indent-region=<Command-Key-bracketright>
|
| 231 |
+
dedent-region=<Command-Key-bracketleft>
|
| 232 |
+
comment-region=<Control-Key-3>
|
| 233 |
+
uncomment-region=<Control-Key-4>
|
| 234 |
+
tabify-region=<Control-Key-5>
|
| 235 |
+
untabify-region=<Control-Key-6>
|
| 236 |
+
toggle-tabs=<Control-Key-t>
|
| 237 |
+
change-indentwidth=<Control-Key-u>
|
| 238 |
+
del-word-left=<Control-Key-BackSpace>
|
| 239 |
+
del-word-right=<Control-Key-Delete>
|
| 240 |
+
force-open-completions= <Control-Key-space>
|
| 241 |
+
expand-word= <Option-Key-slash>
|
| 242 |
+
force-open-calltip= <Control-Key-backslash>
|
| 243 |
+
format-paragraph= <Option-Key-q>
|
| 244 |
+
flash-paren= <Control-Key-0>
|
| 245 |
+
run-module= <Key-F5>
|
| 246 |
+
run-custom= <Shift-Key-F5>
|
| 247 |
+
check-module= <Option-Key-x>
|
| 248 |
+
zoom-height= <Option-Key-0>
|
| 249 |
+
|
| 250 |
+
[IDLE Classic OSX]
|
| 251 |
+
toggle-tabs = <Control-Key-t>
|
| 252 |
+
interrupt-execution = <Control-Key-c>
|
| 253 |
+
untabify-region = <Control-Key-6>
|
| 254 |
+
remove-selection = <Key-Escape>
|
| 255 |
+
print-window = <Command-Key-p>
|
| 256 |
+
replace = <Command-Key-r>
|
| 257 |
+
goto-line = <Command-Key-j>
|
| 258 |
+
plain-newline-and-indent = <Control-Key-j>
|
| 259 |
+
history-previous = <Control-Key-p>
|
| 260 |
+
beginning-of-line = <Control-Key-Left>
|
| 261 |
+
end-of-line = <Control-Key-Right>
|
| 262 |
+
comment-region = <Control-Key-3>
|
| 263 |
+
redo = <Shift-Command-Key-Z>
|
| 264 |
+
close-window = <Command-Key-w>
|
| 265 |
+
restart-shell = <Control-Key-F6>
|
| 266 |
+
save-window-as-file = <Shift-Command-Key-S>
|
| 267 |
+
close-all-windows = <Command-Key-q>
|
| 268 |
+
view-restart = <Key-F6>
|
| 269 |
+
tabify-region = <Control-Key-5>
|
| 270 |
+
find-again = <Command-Key-g> <Key-F3>
|
| 271 |
+
find = <Command-Key-f>
|
| 272 |
+
toggle-auto-coloring = <Control-Key-slash>
|
| 273 |
+
select-all = <Command-Key-a>
|
| 274 |
+
smart-backspace = <Key-BackSpace>
|
| 275 |
+
change-indentwidth = <Control-Key-u>
|
| 276 |
+
do-nothing = <Control-Key-F12>
|
| 277 |
+
smart-indent = <Key-Tab>
|
| 278 |
+
center-insert = <Control-Key-l>
|
| 279 |
+
history-next = <Control-Key-n>
|
| 280 |
+
del-word-right = <Option-Key-Delete>
|
| 281 |
+
undo = <Command-Key-z>
|
| 282 |
+
save-window = <Command-Key-s>
|
| 283 |
+
uncomment-region = <Control-Key-4>
|
| 284 |
+
cut = <Command-Key-x>
|
| 285 |
+
find-in-files = <Command-Key-F3>
|
| 286 |
+
dedent-region = <Command-Key-bracketleft>
|
| 287 |
+
copy = <Command-Key-c>
|
| 288 |
+
paste = <Command-Key-v>
|
| 289 |
+
indent-region = <Command-Key-bracketright>
|
| 290 |
+
del-word-left = <Option-Key-BackSpace> <Option-Command-Key-BackSpace>
|
| 291 |
+
newline-and-indent = <Key-Return> <Key-KP_Enter>
|
| 292 |
+
end-of-file = <Control-Key-d>
|
| 293 |
+
open-class-browser = <Command-Key-b>
|
| 294 |
+
open-new-window = <Command-Key-n>
|
| 295 |
+
open-module = <Command-Key-m>
|
| 296 |
+
find-selection = <Shift-Command-Key-F3>
|
| 297 |
+
python-context-help = <Shift-Key-F1>
|
| 298 |
+
save-copy-of-window-as-file = <Option-Command-Key-s>
|
| 299 |
+
open-window-from-file = <Command-Key-o>
|
| 300 |
+
python-docs = <Key-F1>
|
| 301 |
+
force-open-completions= <Control-Key-space>
|
| 302 |
+
expand-word= <Option-Key-slash>
|
| 303 |
+
force-open-calltip= <Control-Key-backslash>
|
| 304 |
+
format-paragraph= <Option-Key-q>
|
| 305 |
+
flash-paren= <Control-Key-0>
|
| 306 |
+
run-module= <Key-F5>
|
| 307 |
+
run-custom= <Shift-Key-F5>
|
| 308 |
+
check-module= <Option-Key-x>
|
| 309 |
+
zoom-height= <Option-Key-0>
|
data/conda_envs/evalclaw/lib/python3.11/idlelib/config.py
ADDED
|
@@ -0,0 +1,916 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
| 1 |
+
"""idlelib.config -- Manage IDLE configuration information.
|
| 2 |
+
|
| 3 |
+
The comments at the beginning of config-main.def describe the
|
| 4 |
+
configuration files and the design implemented to update user
|
| 5 |
+
configuration information. In particular, user configuration choices
|
| 6 |
+
which duplicate the defaults will be removed from the user's
|
| 7 |
+
configuration files, and if a user file becomes empty, it will be
|
| 8 |
+
deleted.
|
| 9 |
+
|
| 10 |
+
The configuration database maps options to values. Conceptually, the
|
| 11 |
+
database keys are tuples (config-type, section, item). As implemented,
|
| 12 |
+
there are separate dicts for default and user values. Each has
|
| 13 |
+
config-type keys 'main', 'extensions', 'highlight', and 'keys'. The
|
| 14 |
+
value for each key is a ConfigParser instance that maps section and item
|
| 15 |
+
to values. For 'main' and 'extensions', user values override
|
| 16 |
+
default values. For 'highlight' and 'keys', user sections augment the
|
| 17 |
+
default sections (and must, therefore, have distinct names).
|
| 18 |
+
|
| 19 |
+
Throughout this module there is an emphasis on returning usable defaults
|
| 20 |
+
when a problem occurs in returning a requested configuration value back to
|
| 21 |
+
idle. This is to allow IDLE to continue to function in spite of errors in
|
| 22 |
+
the retrieval of config information. When a default is returned instead of
|
| 23 |
+
a requested config value, a message is printed to stderr to aid in
|
| 24 |
+
configuration problem notification and resolution.
|
| 25 |
+
"""
|
| 26 |
+
# TODOs added Oct 2014, tjr
|
| 27 |
+
|
| 28 |
+
from configparser import ConfigParser
|
| 29 |
+
import os
|
| 30 |
+
import sys
|
| 31 |
+
|
| 32 |
+
from tkinter.font import Font
|
| 33 |
+
import idlelib
|
| 34 |
+
|
| 35 |
+
class InvalidConfigType(Exception): pass
|
| 36 |
+
class InvalidConfigSet(Exception): pass
|
| 37 |
+
class InvalidTheme(Exception): pass
|
| 38 |
+
|
| 39 |
+
class IdleConfParser(ConfigParser):
|
| 40 |
+
"""
|
| 41 |
+
A ConfigParser specialised for idle configuration file handling
|
| 42 |
+
"""
|
| 43 |
+
def __init__(self, cfgFile, cfgDefaults=None):
|
| 44 |
+
"""
|
| 45 |
+
cfgFile - string, fully specified configuration file name
|
| 46 |
+
"""
|
| 47 |
+
self.file = cfgFile # This is currently '' when testing.
|
| 48 |
+
ConfigParser.__init__(self, defaults=cfgDefaults, strict=False)
|
| 49 |
+
|
| 50 |
+
def Get(self, section, option, type=None, default=None, raw=False):
|
| 51 |
+
"""
|
| 52 |
+
Get an option value for given section/option or return default.
|
| 53 |
+
If type is specified, return as type.
|
| 54 |
+
"""
|
| 55 |
+
# TODO Use default as fallback, at least if not None
|
| 56 |
+
# Should also print Warning(file, section, option).
|
| 57 |
+
# Currently may raise ValueError
|
| 58 |
+
if not self.has_option(section, option):
|
| 59 |
+
return default
|
| 60 |
+
if type == 'bool':
|
| 61 |
+
return self.getboolean(section, option)
|
| 62 |
+
elif type == 'int':
|
| 63 |
+
return self.getint(section, option)
|
| 64 |
+
else:
|
| 65 |
+
return self.get(section, option, raw=raw)
|
| 66 |
+
|
| 67 |
+
def GetOptionList(self, section):
|
| 68 |
+
"Return a list of options for given section, else []."
|
| 69 |
+
if self.has_section(section):
|
| 70 |
+
return self.options(section)
|
| 71 |
+
else: #return a default value
|
| 72 |
+
return []
|
| 73 |
+
|
| 74 |
+
def Load(self):
|
| 75 |
+
"Load the configuration file from disk."
|
| 76 |
+
if self.file:
|
| 77 |
+
self.read(self.file)
|
| 78 |
+
|
| 79 |
+
class IdleUserConfParser(IdleConfParser):
|
| 80 |
+
"""
|
| 81 |
+
IdleConfigParser specialised for user configuration handling.
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
def SetOption(self, section, option, value):
|
| 85 |
+
"""Return True if option is added or changed to value, else False.
|
| 86 |
+
|
| 87 |
+
Add section if required. False means option already had value.
|
| 88 |
+
"""
|
| 89 |
+
if self.has_option(section, option):
|
| 90 |
+
if self.get(section, option) == value:
|
| 91 |
+
return False
|
| 92 |
+
else:
|
| 93 |
+
self.set(section, option, value)
|
| 94 |
+
return True
|
| 95 |
+
else:
|
| 96 |
+
if not self.has_section(section):
|
| 97 |
+
self.add_section(section)
|
| 98 |
+
self.set(section, option, value)
|
| 99 |
+
return True
|
| 100 |
+
|
| 101 |
+
def RemoveOption(self, section, option):
|
| 102 |
+
"""Return True if option is removed from section, else False.
|
| 103 |
+
|
| 104 |
+
False if either section does not exist or did not have option.
|
| 105 |
+
"""
|
| 106 |
+
if self.has_section(section):
|
| 107 |
+
return self.remove_option(section, option)
|
| 108 |
+
return False
|
| 109 |
+
|
| 110 |
+
def AddSection(self, section):
|
| 111 |
+
"If section doesn't exist, add it."
|
| 112 |
+
if not self.has_section(section):
|
| 113 |
+
self.add_section(section)
|
| 114 |
+
|
| 115 |
+
def RemoveEmptySections(self):
|
| 116 |
+
"Remove any sections that have no options."
|
| 117 |
+
for section in self.sections():
|
| 118 |
+
if not self.GetOptionList(section):
|
| 119 |
+
self.remove_section(section)
|
| 120 |
+
|
| 121 |
+
def IsEmpty(self):
|
| 122 |
+
"Return True if no sections after removing empty sections."
|
| 123 |
+
self.RemoveEmptySections()
|
| 124 |
+
return not self.sections()
|
| 125 |
+
|
| 126 |
+
def Save(self):
|
| 127 |
+
"""Update user configuration file.
|
| 128 |
+
|
| 129 |
+
If self not empty after removing empty sections, write the file
|
| 130 |
+
to disk. Otherwise, remove the file from disk if it exists.
|
| 131 |
+
"""
|
| 132 |
+
fname = self.file
|
| 133 |
+
if fname and fname[0] != '#':
|
| 134 |
+
if not self.IsEmpty():
|
| 135 |
+
try:
|
| 136 |
+
cfgFile = open(fname, 'w')
|
| 137 |
+
except OSError:
|
| 138 |
+
os.unlink(fname)
|
| 139 |
+
cfgFile = open(fname, 'w')
|
| 140 |
+
with cfgFile:
|
| 141 |
+
self.write(cfgFile)
|
| 142 |
+
elif os.path.exists(self.file):
|
| 143 |
+
os.remove(self.file)
|
| 144 |
+
|
| 145 |
+
class IdleConf:
|
| 146 |
+
"""Hold config parsers for all idle config files in singleton instance.
|
| 147 |
+
|
| 148 |
+
Default config files, self.defaultCfg --
|
| 149 |
+
for config_type in self.config_types:
|
| 150 |
+
(idle install dir)/config-{config-type}.def
|
| 151 |
+
|
| 152 |
+
User config files, self.userCfg --
|
| 153 |
+
for config_type in self.config_types:
|
| 154 |
+
(user home dir)/.idlerc/config-{config-type}.cfg
|
| 155 |
+
"""
|
| 156 |
+
def __init__(self, _utest=False):
|
| 157 |
+
self.config_types = ('main', 'highlight', 'keys', 'extensions')
|
| 158 |
+
self.defaultCfg = {}
|
| 159 |
+
self.userCfg = {}
|
| 160 |
+
self.cfg = {} # TODO use to select userCfg vs defaultCfg
|
| 161 |
+
# self.blink_off_time = <first editor text>['insertofftime']
|
| 162 |
+
# See https:/bugs.python.org/issue4630, msg356516.
|
| 163 |
+
|
| 164 |
+
if not _utest:
|
| 165 |
+
self.CreateConfigHandlers()
|
| 166 |
+
self.LoadCfgFiles()
|
| 167 |
+
|
| 168 |
+
def CreateConfigHandlers(self):
|
| 169 |
+
"Populate default and user config parser dictionaries."
|
| 170 |
+
idledir = os.path.dirname(__file__)
|
| 171 |
+
self.userdir = userdir = '' if idlelib.testing else self.GetUserCfgDir()
|
| 172 |
+
for cfg_type in self.config_types:
|
| 173 |
+
self.defaultCfg[cfg_type] = IdleConfParser(
|
| 174 |
+
os.path.join(idledir, f'config-{cfg_type}.def'))
|
| 175 |
+
self.userCfg[cfg_type] = IdleUserConfParser(
|
| 176 |
+
os.path.join(userdir or '#', f'config-{cfg_type}.cfg'))
|
| 177 |
+
|
| 178 |
+
def GetUserCfgDir(self):
|
| 179 |
+
"""Return a filesystem directory for storing user config files.
|
| 180 |
+
|
| 181 |
+
Creates it if required.
|
| 182 |
+
"""
|
| 183 |
+
cfgDir = '.idlerc'
|
| 184 |
+
userDir = os.path.expanduser('~')
|
| 185 |
+
if userDir != '~': # expanduser() found user home dir
|
| 186 |
+
if not os.path.exists(userDir):
|
| 187 |
+
if not idlelib.testing:
|
| 188 |
+
warn = ('\n Warning: os.path.expanduser("~") points to\n ' +
|
| 189 |
+
userDir + ',\n but the path does not exist.')
|
| 190 |
+
try:
|
| 191 |
+
print(warn, file=sys.stderr)
|
| 192 |
+
except OSError:
|
| 193 |
+
pass
|
| 194 |
+
userDir = '~'
|
| 195 |
+
if userDir == "~": # still no path to home!
|
| 196 |
+
# traditionally IDLE has defaulted to os.getcwd(), is this adequate?
|
| 197 |
+
userDir = os.getcwd()
|
| 198 |
+
userDir = os.path.join(userDir, cfgDir)
|
| 199 |
+
if not os.path.exists(userDir):
|
| 200 |
+
try:
|
| 201 |
+
os.mkdir(userDir)
|
| 202 |
+
except OSError:
|
| 203 |
+
if not idlelib.testing:
|
| 204 |
+
warn = ('\n Warning: unable to create user config directory\n' +
|
| 205 |
+
userDir + '\n Check path and permissions.\n Exiting!\n')
|
| 206 |
+
try:
|
| 207 |
+
print(warn, file=sys.stderr)
|
| 208 |
+
except OSError:
|
| 209 |
+
pass
|
| 210 |
+
raise SystemExit
|
| 211 |
+
# TODO continue without userDIr instead of exit
|
| 212 |
+
return userDir
|
| 213 |
+
|
| 214 |
+
def GetOption(self, configType, section, option, default=None, type=None,
|
| 215 |
+
warn_on_default=True, raw=False):
|
| 216 |
+
"""Return a value for configType section option, or default.
|
| 217 |
+
|
| 218 |
+
If type is not None, return a value of that type. Also pass raw
|
| 219 |
+
to the config parser. First try to return a valid value
|
| 220 |
+
(including type) from a user configuration. If that fails, try
|
| 221 |
+
the default configuration. If that fails, return default, with a
|
| 222 |
+
default of None.
|
| 223 |
+
|
| 224 |
+
Warn if either user or default configurations have an invalid value.
|
| 225 |
+
Warn if default is returned and warn_on_default is True.
|
| 226 |
+
"""
|
| 227 |
+
try:
|
| 228 |
+
if self.userCfg[configType].has_option(section, option):
|
| 229 |
+
return self.userCfg[configType].Get(section, option,
|
| 230 |
+
type=type, raw=raw)
|
| 231 |
+
except ValueError:
|
| 232 |
+
warning = ('\n Warning: config.py - IdleConf.GetOption -\n'
|
| 233 |
+
' invalid %r value for configuration option %r\n'
|
| 234 |
+
' from section %r: %r' %
|
| 235 |
+
(type, option, section,
|
| 236 |
+
self.userCfg[configType].Get(section, option, raw=raw)))
|
| 237 |
+
_warn(warning, configType, section, option)
|
| 238 |
+
try:
|
| 239 |
+
if self.defaultCfg[configType].has_option(section,option):
|
| 240 |
+
return self.defaultCfg[configType].Get(
|
| 241 |
+
section, option, type=type, raw=raw)
|
| 242 |
+
except ValueError:
|
| 243 |
+
pass
|
| 244 |
+
#returning default, print warning
|
| 245 |
+
if warn_on_default:
|
| 246 |
+
warning = ('\n Warning: config.py - IdleConf.GetOption -\n'
|
| 247 |
+
' problem retrieving configuration option %r\n'
|
| 248 |
+
' from section %r.\n'
|
| 249 |
+
' returning default value: %r' %
|
| 250 |
+
(option, section, default))
|
| 251 |
+
_warn(warning, configType, section, option)
|
| 252 |
+
return default
|
| 253 |
+
|
| 254 |
+
def SetOption(self, configType, section, option, value):
|
| 255 |
+
"""Set section option to value in user config file."""
|
| 256 |
+
self.userCfg[configType].SetOption(section, option, value)
|
| 257 |
+
|
| 258 |
+
def GetSectionList(self, configSet, configType):
|
| 259 |
+
"""Return sections for configSet configType configuration.
|
| 260 |
+
|
| 261 |
+
configSet must be either 'user' or 'default'
|
| 262 |
+
configType must be in self.config_types.
|
| 263 |
+
"""
|
| 264 |
+
if not (configType in self.config_types):
|
| 265 |
+
raise InvalidConfigType('Invalid configType specified')
|
| 266 |
+
if configSet == 'user':
|
| 267 |
+
cfgParser = self.userCfg[configType]
|
| 268 |
+
elif configSet == 'default':
|
| 269 |
+
cfgParser=self.defaultCfg[configType]
|
| 270 |
+
else:
|
| 271 |
+
raise InvalidConfigSet('Invalid configSet specified')
|
| 272 |
+
return cfgParser.sections()
|
| 273 |
+
|
| 274 |
+
def GetHighlight(self, theme, element):
|
| 275 |
+
"""Return dict of theme element highlight colors.
|
| 276 |
+
|
| 277 |
+
The keys are 'foreground' and 'background'. The values are
|
| 278 |
+
tkinter color strings for configuring backgrounds and tags.
|
| 279 |
+
"""
|
| 280 |
+
cfg = ('default' if self.defaultCfg['highlight'].has_section(theme)
|
| 281 |
+
else 'user')
|
| 282 |
+
theme_dict = self.GetThemeDict(cfg, theme)
|
| 283 |
+
fore = theme_dict[element + '-foreground']
|
| 284 |
+
if element == 'cursor':
|
| 285 |
+
element = 'normal'
|
| 286 |
+
back = theme_dict[element + '-background']
|
| 287 |
+
return {"foreground": fore, "background": back}
|
| 288 |
+
|
| 289 |
+
def GetThemeDict(self, type, themeName):
|
| 290 |
+
"""Return {option:value} dict for elements in themeName.
|
| 291 |
+
|
| 292 |
+
type - string, 'default' or 'user' theme type
|
| 293 |
+
themeName - string, theme name
|
| 294 |
+
Values are loaded over ultimate fallback defaults to guarantee
|
| 295 |
+
that all theme elements are present in a newly created theme.
|
| 296 |
+
"""
|
| 297 |
+
if type == 'user':
|
| 298 |
+
cfgParser = self.userCfg['highlight']
|
| 299 |
+
elif type == 'default':
|
| 300 |
+
cfgParser = self.defaultCfg['highlight']
|
| 301 |
+
else:
|
| 302 |
+
raise InvalidTheme('Invalid theme type specified')
|
| 303 |
+
# Provide foreground and background colors for each theme
|
| 304 |
+
# element (other than cursor) even though some values are not
|
| 305 |
+
# yet used by idle, to allow for their use in the future.
|
| 306 |
+
# Default values are generally black and white.
|
| 307 |
+
# TODO copy theme from a class attribute.
|
| 308 |
+
theme ={'normal-foreground':'#000000',
|
| 309 |
+
'normal-background':'#ffffff',
|
| 310 |
+
'keyword-foreground':'#000000',
|
| 311 |
+
'keyword-background':'#ffffff',
|
| 312 |
+
'builtin-foreground':'#000000',
|
| 313 |
+
'builtin-background':'#ffffff',
|
| 314 |
+
'comment-foreground':'#000000',
|
| 315 |
+
'comment-background':'#ffffff',
|
| 316 |
+
'string-foreground':'#000000',
|
| 317 |
+
'string-background':'#ffffff',
|
| 318 |
+
'definition-foreground':'#000000',
|
| 319 |
+
'definition-background':'#ffffff',
|
| 320 |
+
'hilite-foreground':'#000000',
|
| 321 |
+
'hilite-background':'gray',
|
| 322 |
+
'break-foreground':'#ffffff',
|
| 323 |
+
'break-background':'#000000',
|
| 324 |
+
'hit-foreground':'#ffffff',
|
| 325 |
+
'hit-background':'#000000',
|
| 326 |
+
'error-foreground':'#ffffff',
|
| 327 |
+
'error-background':'#000000',
|
| 328 |
+
'context-foreground':'#000000',
|
| 329 |
+
'context-background':'#ffffff',
|
| 330 |
+
'linenumber-foreground':'#000000',
|
| 331 |
+
'linenumber-background':'#ffffff',
|
| 332 |
+
#cursor (only foreground can be set)
|
| 333 |
+
'cursor-foreground':'#000000',
|
| 334 |
+
#shell window
|
| 335 |
+
'stdout-foreground':'#000000',
|
| 336 |
+
'stdout-background':'#ffffff',
|
| 337 |
+
'stderr-foreground':'#000000',
|
| 338 |
+
'stderr-background':'#ffffff',
|
| 339 |
+
'console-foreground':'#000000',
|
| 340 |
+
'console-background':'#ffffff',
|
| 341 |
+
}
|
| 342 |
+
for element in theme:
|
| 343 |
+
if not (cfgParser.has_option(themeName, element) or
|
| 344 |
+
# Skip warning for new elements.
|
| 345 |
+
element.startswith(('context-', 'linenumber-'))):
|
| 346 |
+
# Print warning that will return a default color
|
| 347 |
+
warning = ('\n Warning: config.IdleConf.GetThemeDict'
|
| 348 |
+
' -\n problem retrieving theme element %r'
|
| 349 |
+
'\n from theme %r.\n'
|
| 350 |
+
' returning default color: %r' %
|
| 351 |
+
(element, themeName, theme[element]))
|
| 352 |
+
_warn(warning, 'highlight', themeName, element)
|
| 353 |
+
theme[element] = cfgParser.Get(
|
| 354 |
+
themeName, element, default=theme[element])
|
| 355 |
+
return theme
|
| 356 |
+
|
| 357 |
+
def CurrentTheme(self):
|
| 358 |
+
"Return the name of the currently active text color theme."
|
| 359 |
+
return self.current_colors_and_keys('Theme')
|
| 360 |
+
|
| 361 |
+
def CurrentKeys(self):
|
| 362 |
+
"""Return the name of the currently active key set."""
|
| 363 |
+
return self.current_colors_and_keys('Keys')
|
| 364 |
+
|
| 365 |
+
def current_colors_and_keys(self, section):
|
| 366 |
+
"""Return the currently active name for Theme or Keys section.
|
| 367 |
+
|
| 368 |
+
idlelib.config-main.def ('default') includes these sections
|
| 369 |
+
|
| 370 |
+
[Theme]
|
| 371 |
+
default= 1
|
| 372 |
+
name= IDLE Classic
|
| 373 |
+
name2=
|
| 374 |
+
|
| 375 |
+
[Keys]
|
| 376 |
+
default= 1
|
| 377 |
+
name=
|
| 378 |
+
name2=
|
| 379 |
+
|
| 380 |
+
Item 'name2', is used for built-in ('default') themes and keys
|
| 381 |
+
added after 2015 Oct 1 and 2016 July 1. This kludge is needed
|
| 382 |
+
because setting 'name' to a builtin not defined in older IDLEs
|
| 383 |
+
to display multiple error messages or quit.
|
| 384 |
+
See https://bugs.python.org/issue25313.
|
| 385 |
+
When default = True, 'name2' takes precedence over 'name',
|
| 386 |
+
while older IDLEs will just use name. When default = False,
|
| 387 |
+
'name2' may still be set, but it is ignored.
|
| 388 |
+
"""
|
| 389 |
+
cfgname = 'highlight' if section == 'Theme' else 'keys'
|
| 390 |
+
default = self.GetOption('main', section, 'default',
|
| 391 |
+
type='bool', default=True)
|
| 392 |
+
name = ''
|
| 393 |
+
if default:
|
| 394 |
+
name = self.GetOption('main', section, 'name2', default='')
|
| 395 |
+
if not name:
|
| 396 |
+
name = self.GetOption('main', section, 'name', default='')
|
| 397 |
+
if name:
|
| 398 |
+
source = self.defaultCfg if default else self.userCfg
|
| 399 |
+
if source[cfgname].has_section(name):
|
| 400 |
+
return name
|
| 401 |
+
return "IDLE Classic" if section == 'Theme' else self.default_keys()
|
| 402 |
+
|
| 403 |
+
@staticmethod
|
| 404 |
+
def default_keys():
|
| 405 |
+
if sys.platform[:3] == 'win':
|
| 406 |
+
return 'IDLE Classic Windows'
|
| 407 |
+
elif sys.platform == 'darwin':
|
| 408 |
+
return 'IDLE Classic OSX'
|
| 409 |
+
else:
|
| 410 |
+
return 'IDLE Modern Unix'
|
| 411 |
+
|
| 412 |
+
def GetExtensions(self, active_only=True,
|
| 413 |
+
editor_only=False, shell_only=False):
|
| 414 |
+
"""Return extensions in default and user config-extensions files.
|
| 415 |
+
|
| 416 |
+
If active_only True, only return active (enabled) extensions
|
| 417 |
+
and optionally only editor or shell extensions.
|
| 418 |
+
If active_only False, return all extensions.
|
| 419 |
+
"""
|
| 420 |
+
extns = self.RemoveKeyBindNames(
|
| 421 |
+
self.GetSectionList('default', 'extensions'))
|
| 422 |
+
userExtns = self.RemoveKeyBindNames(
|
| 423 |
+
self.GetSectionList('user', 'extensions'))
|
| 424 |
+
for extn in userExtns:
|
| 425 |
+
if extn not in extns: #user has added own extension
|
| 426 |
+
extns.append(extn)
|
| 427 |
+
for extn in ('AutoComplete','CodeContext',
|
| 428 |
+
'FormatParagraph','ParenMatch'):
|
| 429 |
+
extns.remove(extn)
|
| 430 |
+
# specific exclusions because we are storing config for mainlined old
|
| 431 |
+
# extensions in config-extensions.def for backward compatibility
|
| 432 |
+
if active_only:
|
| 433 |
+
activeExtns = []
|
| 434 |
+
for extn in extns:
|
| 435 |
+
if self.GetOption('extensions', extn, 'enable', default=True,
|
| 436 |
+
type='bool'):
|
| 437 |
+
#the extension is enabled
|
| 438 |
+
if editor_only or shell_only: # TODO both True contradict
|
| 439 |
+
if editor_only:
|
| 440 |
+
option = "enable_editor"
|
| 441 |
+
else:
|
| 442 |
+
option = "enable_shell"
|
| 443 |
+
if self.GetOption('extensions', extn,option,
|
| 444 |
+
default=True, type='bool',
|
| 445 |
+
warn_on_default=False):
|
| 446 |
+
activeExtns.append(extn)
|
| 447 |
+
else:
|
| 448 |
+
activeExtns.append(extn)
|
| 449 |
+
return activeExtns
|
| 450 |
+
else:
|
| 451 |
+
return extns
|
| 452 |
+
|
| 453 |
+
def RemoveKeyBindNames(self, extnNameList):
|
| 454 |
+
"Return extnNameList with keybinding section names removed."
|
| 455 |
+
return [n for n in extnNameList if not n.endswith(('_bindings', '_cfgBindings'))]
|
| 456 |
+
|
| 457 |
+
def GetExtnNameForEvent(self, virtualEvent):
|
| 458 |
+
"""Return the name of the extension binding virtualEvent, or None.
|
| 459 |
+
|
| 460 |
+
virtualEvent - string, name of the virtual event to test for,
|
| 461 |
+
without the enclosing '<< >>'
|
| 462 |
+
"""
|
| 463 |
+
extName = None
|
| 464 |
+
vEvent = '<<' + virtualEvent + '>>'
|
| 465 |
+
for extn in self.GetExtensions(active_only=0):
|
| 466 |
+
for event in self.GetExtensionKeys(extn):
|
| 467 |
+
if event == vEvent:
|
| 468 |
+
extName = extn # TODO return here?
|
| 469 |
+
return extName
|
| 470 |
+
|
| 471 |
+
def GetExtensionKeys(self, extensionName):
|
| 472 |
+
"""Return dict: {configurable extensionName event : active keybinding}.
|
| 473 |
+
|
| 474 |
+
Events come from default config extension_cfgBindings section.
|
| 475 |
+
Keybindings come from GetCurrentKeySet() active key dict,
|
| 476 |
+
where previously used bindings are disabled.
|
| 477 |
+
"""
|
| 478 |
+
keysName = extensionName + '_cfgBindings'
|
| 479 |
+
activeKeys = self.GetCurrentKeySet()
|
| 480 |
+
extKeys = {}
|
| 481 |
+
if self.defaultCfg['extensions'].has_section(keysName):
|
| 482 |
+
eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
|
| 483 |
+
for eventName in eventNames:
|
| 484 |
+
event = '<<' + eventName + '>>'
|
| 485 |
+
binding = activeKeys[event]
|
| 486 |
+
extKeys[event] = binding
|
| 487 |
+
return extKeys
|
| 488 |
+
|
| 489 |
+
def __GetRawExtensionKeys(self,extensionName):
|
| 490 |
+
"""Return dict {configurable extensionName event : keybinding list}.
|
| 491 |
+
|
| 492 |
+
Events come from default config extension_cfgBindings section.
|
| 493 |
+
Keybindings list come from the splitting of GetOption, which
|
| 494 |
+
tries user config before default config.
|
| 495 |
+
"""
|
| 496 |
+
keysName = extensionName+'_cfgBindings'
|
| 497 |
+
extKeys = {}
|
| 498 |
+
if self.defaultCfg['extensions'].has_section(keysName):
|
| 499 |
+
eventNames = self.defaultCfg['extensions'].GetOptionList(keysName)
|
| 500 |
+
for eventName in eventNames:
|
| 501 |
+
binding = self.GetOption(
|
| 502 |
+
'extensions', keysName, eventName, default='').split()
|
| 503 |
+
event = '<<' + eventName + '>>'
|
| 504 |
+
extKeys[event] = binding
|
| 505 |
+
return extKeys
|
| 506 |
+
|
| 507 |
+
def GetExtensionBindings(self, extensionName):
|
| 508 |
+
"""Return dict {extensionName event : active or defined keybinding}.
|
| 509 |
+
|
| 510 |
+
Augment self.GetExtensionKeys(extensionName) with mapping of non-
|
| 511 |
+
configurable events (from default config) to GetOption splits,
|
| 512 |
+
as in self.__GetRawExtensionKeys.
|
| 513 |
+
"""
|
| 514 |
+
bindsName = extensionName + '_bindings'
|
| 515 |
+
extBinds = self.GetExtensionKeys(extensionName)
|
| 516 |
+
#add the non-configurable bindings
|
| 517 |
+
if self.defaultCfg['extensions'].has_section(bindsName):
|
| 518 |
+
eventNames = self.defaultCfg['extensions'].GetOptionList(bindsName)
|
| 519 |
+
for eventName in eventNames:
|
| 520 |
+
binding = self.GetOption(
|
| 521 |
+
'extensions', bindsName, eventName, default='').split()
|
| 522 |
+
event = '<<' + eventName + '>>'
|
| 523 |
+
extBinds[event] = binding
|
| 524 |
+
|
| 525 |
+
return extBinds
|
| 526 |
+
|
| 527 |
+
def GetKeyBinding(self, keySetName, eventStr):
|
| 528 |
+
"""Return the keybinding list for keySetName eventStr.
|
| 529 |
+
|
| 530 |
+
keySetName - name of key binding set (config-keys section).
|
| 531 |
+
eventStr - virtual event, including brackets, as in '<<event>>'.
|
| 532 |
+
"""
|
| 533 |
+
eventName = eventStr[2:-2] #trim off the angle brackets
|
| 534 |
+
binding = self.GetOption('keys', keySetName, eventName, default='',
|
| 535 |
+
warn_on_default=False).split()
|
| 536 |
+
return binding
|
| 537 |
+
|
| 538 |
+
def GetCurrentKeySet(self):
|
| 539 |
+
"Return CurrentKeys with 'darwin' modifications."
|
| 540 |
+
result = self.GetKeySet(self.CurrentKeys())
|
| 541 |
+
|
| 542 |
+
if sys.platform == "darwin":
|
| 543 |
+
# macOS (OS X) Tk variants do not support the "Alt"
|
| 544 |
+
# keyboard modifier. Replace it with "Option".
|
| 545 |
+
# TODO (Ned?): the "Option" modifier does not work properly
|
| 546 |
+
# for Cocoa Tk and XQuartz Tk so we should not use it
|
| 547 |
+
# in the default 'OSX' keyset.
|
| 548 |
+
for k, v in result.items():
|
| 549 |
+
v2 = [ x.replace('<Alt-', '<Option-') for x in v ]
|
| 550 |
+
if v != v2:
|
| 551 |
+
result[k] = v2
|
| 552 |
+
|
| 553 |
+
return result
|
| 554 |
+
|
| 555 |
+
def GetKeySet(self, keySetName):
|
| 556 |
+
"""Return event-key dict for keySetName core plus active extensions.
|
| 557 |
+
|
| 558 |
+
If a binding defined in an extension is already in use, the
|
| 559 |
+
extension binding is disabled by being set to ''
|
| 560 |
+
"""
|
| 561 |
+
keySet = self.GetCoreKeys(keySetName)
|
| 562 |
+
activeExtns = self.GetExtensions(active_only=1)
|
| 563 |
+
for extn in activeExtns:
|
| 564 |
+
extKeys = self.__GetRawExtensionKeys(extn)
|
| 565 |
+
if extKeys: #the extension defines keybindings
|
| 566 |
+
for event in extKeys:
|
| 567 |
+
if extKeys[event] in keySet.values():
|
| 568 |
+
#the binding is already in use
|
| 569 |
+
extKeys[event] = '' #disable this binding
|
| 570 |
+
keySet[event] = extKeys[event] #add binding
|
| 571 |
+
return keySet
|
| 572 |
+
|
| 573 |
+
def IsCoreBinding(self, virtualEvent):
|
| 574 |
+
"""Return True if the virtual event is one of the core idle key events.
|
| 575 |
+
|
| 576 |
+
virtualEvent - string, name of the virtual event to test for,
|
| 577 |
+
without the enclosing '<< >>'
|
| 578 |
+
"""
|
| 579 |
+
return ('<<'+virtualEvent+'>>') in self.GetCoreKeys()
|
| 580 |
+
|
| 581 |
+
# TODO make keyBindings a file or class attribute used for test above
|
| 582 |
+
# and copied in function below.
|
| 583 |
+
|
| 584 |
+
former_extension_events = { # Those with user-configurable keys.
|
| 585 |
+
'<<force-open-completions>>', '<<expand-word>>',
|
| 586 |
+
'<<force-open-calltip>>', '<<flash-paren>>', '<<format-paragraph>>',
|
| 587 |
+
'<<run-module>>', '<<check-module>>', '<<zoom-height>>',
|
| 588 |
+
'<<run-custom>>',
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
def GetCoreKeys(self, keySetName=None):
|
| 592 |
+
"""Return dict of core virtual-key keybindings for keySetName.
|
| 593 |
+
|
| 594 |
+
The default keySetName None corresponds to the keyBindings base
|
| 595 |
+
dict. If keySetName is not None, bindings from the config
|
| 596 |
+
file(s) are loaded _over_ these defaults, so if there is a
|
| 597 |
+
problem getting any core binding there will be an 'ultimate last
|
| 598 |
+
resort fallback' to the CUA-ish bindings defined here.
|
| 599 |
+
"""
|
| 600 |
+
# TODO: = dict(sorted([(v-event, keys), ...]))?
|
| 601 |
+
keyBindings={
|
| 602 |
+
# vitual-event: list of key events.
|
| 603 |
+
'<<copy>>': ['<Control-c>', '<Control-C>'],
|
| 604 |
+
'<<cut>>': ['<Control-x>', '<Control-X>'],
|
| 605 |
+
'<<paste>>': ['<Control-v>', '<Control-V>'],
|
| 606 |
+
'<<beginning-of-line>>': ['<Control-a>', '<Home>'],
|
| 607 |
+
'<<center-insert>>': ['<Control-l>'],
|
| 608 |
+
'<<close-all-windows>>': ['<Control-q>'],
|
| 609 |
+
'<<close-window>>': ['<Alt-F4>'],
|
| 610 |
+
'<<do-nothing>>': ['<Control-x>'],
|
| 611 |
+
'<<end-of-file>>': ['<Control-d>'],
|
| 612 |
+
'<<python-docs>>': ['<F1>'],
|
| 613 |
+
'<<python-context-help>>': ['<Shift-F1>'],
|
| 614 |
+
'<<history-next>>': ['<Alt-n>'],
|
| 615 |
+
'<<history-previous>>': ['<Alt-p>'],
|
| 616 |
+
'<<interrupt-execution>>': ['<Control-c>'],
|
| 617 |
+
'<<view-restart>>': ['<F6>'],
|
| 618 |
+
'<<restart-shell>>': ['<Control-F6>'],
|
| 619 |
+
'<<open-class-browser>>': ['<Alt-c>'],
|
| 620 |
+
'<<open-module>>': ['<Alt-m>'],
|
| 621 |
+
'<<open-new-window>>': ['<Control-n>'],
|
| 622 |
+
'<<open-window-from-file>>': ['<Control-o>'],
|
| 623 |
+
'<<plain-newline-and-indent>>': ['<Control-j>'],
|
| 624 |
+
'<<print-window>>': ['<Control-p>'],
|
| 625 |
+
'<<redo>>': ['<Control-y>'],
|
| 626 |
+
'<<remove-selection>>': ['<Escape>'],
|
| 627 |
+
'<<save-copy-of-window-as-file>>': ['<Alt-Shift-S>'],
|
| 628 |
+
'<<save-window-as-file>>': ['<Alt-s>'],
|
| 629 |
+
'<<save-window>>': ['<Control-s>'],
|
| 630 |
+
'<<select-all>>': ['<Alt-a>'],
|
| 631 |
+
'<<toggle-auto-coloring>>': ['<Control-slash>'],
|
| 632 |
+
'<<undo>>': ['<Control-z>'],
|
| 633 |
+
'<<find-again>>': ['<Control-g>', '<F3>'],
|
| 634 |
+
'<<find-in-files>>': ['<Alt-F3>'],
|
| 635 |
+
'<<find-selection>>': ['<Control-F3>'],
|
| 636 |
+
'<<find>>': ['<Control-f>'],
|
| 637 |
+
'<<replace>>': ['<Control-h>'],
|
| 638 |
+
'<<goto-line>>': ['<Alt-g>'],
|
| 639 |
+
'<<smart-backspace>>': ['<Key-BackSpace>'],
|
| 640 |
+
'<<newline-and-indent>>': ['<Key-Return>', '<Key-KP_Enter>'],
|
| 641 |
+
'<<smart-indent>>': ['<Key-Tab>'],
|
| 642 |
+
'<<indent-region>>': ['<Control-Key-bracketright>'],
|
| 643 |
+
'<<dedent-region>>': ['<Control-Key-bracketleft>'],
|
| 644 |
+
'<<comment-region>>': ['<Alt-Key-3>'],
|
| 645 |
+
'<<uncomment-region>>': ['<Alt-Key-4>'],
|
| 646 |
+
'<<tabify-region>>': ['<Alt-Key-5>'],
|
| 647 |
+
'<<untabify-region>>': ['<Alt-Key-6>'],
|
| 648 |
+
'<<toggle-tabs>>': ['<Alt-Key-t>'],
|
| 649 |
+
'<<change-indentwidth>>': ['<Alt-Key-u>'],
|
| 650 |
+
'<<del-word-left>>': ['<Control-Key-BackSpace>'],
|
| 651 |
+
'<<del-word-right>>': ['<Control-Key-Delete>'],
|
| 652 |
+
'<<force-open-completions>>': ['<Control-Key-space>'],
|
| 653 |
+
'<<expand-word>>': ['<Alt-Key-slash>'],
|
| 654 |
+
'<<force-open-calltip>>': ['<Control-Key-backslash>'],
|
| 655 |
+
'<<flash-paren>>': ['<Control-Key-0>'],
|
| 656 |
+
'<<format-paragraph>>': ['<Alt-Key-q>'],
|
| 657 |
+
'<<run-module>>': ['<Key-F5>'],
|
| 658 |
+
'<<run-custom>>': ['<Shift-Key-F5>'],
|
| 659 |
+
'<<check-module>>': ['<Alt-Key-x>'],
|
| 660 |
+
'<<zoom-height>>': ['<Alt-Key-2>'],
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
if keySetName:
|
| 664 |
+
if not (self.userCfg['keys'].has_section(keySetName) or
|
| 665 |
+
self.defaultCfg['keys'].has_section(keySetName)):
|
| 666 |
+
warning = (
|
| 667 |
+
'\n Warning: config.py - IdleConf.GetCoreKeys -\n'
|
| 668 |
+
' key set %r is not defined, using default bindings.' %
|
| 669 |
+
(keySetName,)
|
| 670 |
+
)
|
| 671 |
+
_warn(warning, 'keys', keySetName)
|
| 672 |
+
else:
|
| 673 |
+
for event in keyBindings:
|
| 674 |
+
binding = self.GetKeyBinding(keySetName, event)
|
| 675 |
+
if binding:
|
| 676 |
+
keyBindings[event] = binding
|
| 677 |
+
# Otherwise return default in keyBindings.
|
| 678 |
+
elif event not in self.former_extension_events:
|
| 679 |
+
warning = (
|
| 680 |
+
'\n Warning: config.py - IdleConf.GetCoreKeys -\n'
|
| 681 |
+
' problem retrieving key binding for event %r\n'
|
| 682 |
+
' from key set %r.\n'
|
| 683 |
+
' returning default value: %r' %
|
| 684 |
+
(event, keySetName, keyBindings[event])
|
| 685 |
+
)
|
| 686 |
+
_warn(warning, 'keys', keySetName, event)
|
| 687 |
+
return keyBindings
|
| 688 |
+
|
| 689 |
+
def GetExtraHelpSourceList(self, configSet):
|
| 690 |
+
"""Return list of extra help sources from a given configSet.
|
| 691 |
+
|
| 692 |
+
Valid configSets are 'user' or 'default'. Return a list of tuples of
|
| 693 |
+
the form (menu_item , path_to_help_file , option), or return the empty
|
| 694 |
+
list. 'option' is the sequence number of the help resource. 'option'
|
| 695 |
+
values determine the position of the menu items on the Help menu,
|
| 696 |
+
therefore the returned list must be sorted by 'option'.
|
| 697 |
+
|
| 698 |
+
"""
|
| 699 |
+
helpSources = []
|
| 700 |
+
if configSet == 'user':
|
| 701 |
+
cfgParser = self.userCfg['main']
|
| 702 |
+
elif configSet == 'default':
|
| 703 |
+
cfgParser = self.defaultCfg['main']
|
| 704 |
+
else:
|
| 705 |
+
raise InvalidConfigSet('Invalid configSet specified')
|
| 706 |
+
options=cfgParser.GetOptionList('HelpFiles')
|
| 707 |
+
for option in options:
|
| 708 |
+
value=cfgParser.Get('HelpFiles', option, default=';')
|
| 709 |
+
if value.find(';') == -1: #malformed config entry with no ';'
|
| 710 |
+
menuItem = '' #make these empty
|
| 711 |
+
helpPath = '' #so value won't be added to list
|
| 712 |
+
else: #config entry contains ';' as expected
|
| 713 |
+
value=value.split(';')
|
| 714 |
+
menuItem=value[0].strip()
|
| 715 |
+
helpPath=value[1].strip()
|
| 716 |
+
if menuItem and helpPath: #neither are empty strings
|
| 717 |
+
helpSources.append( (menuItem,helpPath,option) )
|
| 718 |
+
helpSources.sort(key=lambda x: x[2])
|
| 719 |
+
return helpSources
|
| 720 |
+
|
| 721 |
+
def GetAllExtraHelpSourcesList(self):
|
| 722 |
+
"""Return a list of the details of all additional help sources.
|
| 723 |
+
|
| 724 |
+
Tuples in the list are those of GetExtraHelpSourceList.
|
| 725 |
+
"""
|
| 726 |
+
allHelpSources = (self.GetExtraHelpSourceList('default') +
|
| 727 |
+
self.GetExtraHelpSourceList('user') )
|
| 728 |
+
return allHelpSources
|
| 729 |
+
|
| 730 |
+
def GetFont(self, root, configType, section):
|
| 731 |
+
"""Retrieve a font from configuration (font, font-size, font-bold)
|
| 732 |
+
Intercept the special value 'TkFixedFont' and substitute
|
| 733 |
+
the actual font, factoring in some tweaks if needed for
|
| 734 |
+
appearance sakes.
|
| 735 |
+
|
| 736 |
+
The 'root' parameter can normally be any valid Tkinter widget.
|
| 737 |
+
|
| 738 |
+
Return a tuple (family, size, weight) suitable for passing
|
| 739 |
+
to tkinter.Font
|
| 740 |
+
"""
|
| 741 |
+
family = self.GetOption(configType, section, 'font', default='courier')
|
| 742 |
+
size = self.GetOption(configType, section, 'font-size', type='int',
|
| 743 |
+
default='10')
|
| 744 |
+
bold = self.GetOption(configType, section, 'font-bold', default=0,
|
| 745 |
+
type='bool')
|
| 746 |
+
if (family == 'TkFixedFont'):
|
| 747 |
+
f = Font(name='TkFixedFont', exists=True, root=root)
|
| 748 |
+
actualFont = Font.actual(f)
|
| 749 |
+
family = actualFont['family']
|
| 750 |
+
size = actualFont['size']
|
| 751 |
+
if size <= 0:
|
| 752 |
+
size = 10 # if font in pixels, ignore actual size
|
| 753 |
+
bold = actualFont['weight'] == 'bold'
|
| 754 |
+
return (family, size, 'bold' if bold else 'normal')
|
| 755 |
+
|
| 756 |
+
def LoadCfgFiles(self):
|
| 757 |
+
"Load all configuration files."
|
| 758 |
+
for key in self.defaultCfg:
|
| 759 |
+
self.defaultCfg[key].Load()
|
| 760 |
+
self.userCfg[key].Load() #same keys
|
| 761 |
+
|
| 762 |
+
def SaveUserCfgFiles(self):
|
| 763 |
+
"Write all loaded user configuration files to disk."
|
| 764 |
+
for key in self.userCfg:
|
| 765 |
+
self.userCfg[key].Save()
|
| 766 |
+
|
| 767 |
+
|
| 768 |
+
idleConf = IdleConf()
|
| 769 |
+
|
| 770 |
+
_warned = set()
|
| 771 |
+
def _warn(msg, *key):
|
| 772 |
+
key = (msg,) + key
|
| 773 |
+
if key not in _warned:
|
| 774 |
+
try:
|
| 775 |
+
print(msg, file=sys.stderr)
|
| 776 |
+
except OSError:
|
| 777 |
+
pass
|
| 778 |
+
_warned.add(key)
|
| 779 |
+
|
| 780 |
+
|
| 781 |
+
class ConfigChanges(dict):
|
| 782 |
+
"""Manage a user's proposed configuration option changes.
|
| 783 |
+
|
| 784 |
+
Names used across multiple methods:
|
| 785 |
+
page -- one of the 4 top-level dicts representing a
|
| 786 |
+
.idlerc/config-x.cfg file.
|
| 787 |
+
config_type -- name of a page.
|
| 788 |
+
section -- a section within a page/file.
|
| 789 |
+
option -- name of an option within a section.
|
| 790 |
+
value -- value for the option.
|
| 791 |
+
|
| 792 |
+
Methods
|
| 793 |
+
add_option: Add option and value to changes.
|
| 794 |
+
save_option: Save option and value to config parser.
|
| 795 |
+
save_all: Save all the changes to the config parser and file.
|
| 796 |
+
delete_section: If section exists,
|
| 797 |
+
delete from changes, userCfg, and file.
|
| 798 |
+
clear: Clear all changes by clearing each page.
|
| 799 |
+
"""
|
| 800 |
+
def __init__(self):
|
| 801 |
+
"Create a page for each configuration file"
|
| 802 |
+
self.pages = [] # List of unhashable dicts.
|
| 803 |
+
for config_type in idleConf.config_types:
|
| 804 |
+
self[config_type] = {}
|
| 805 |
+
self.pages.append(self[config_type])
|
| 806 |
+
|
| 807 |
+
def add_option(self, config_type, section, item, value):
|
| 808 |
+
"Add item/value pair for config_type and section."
|
| 809 |
+
page = self[config_type]
|
| 810 |
+
value = str(value) # Make sure we use a string.
|
| 811 |
+
if section not in page:
|
| 812 |
+
page[section] = {}
|
| 813 |
+
page[section][item] = value
|
| 814 |
+
|
| 815 |
+
@staticmethod
|
| 816 |
+
def save_option(config_type, section, item, value):
|
| 817 |
+
"""Return True if the configuration value was added or changed.
|
| 818 |
+
|
| 819 |
+
Helper for save_all.
|
| 820 |
+
"""
|
| 821 |
+
if idleConf.defaultCfg[config_type].has_option(section, item):
|
| 822 |
+
if idleConf.defaultCfg[config_type].Get(section, item) == value:
|
| 823 |
+
# The setting equals a default setting, remove it from user cfg.
|
| 824 |
+
return idleConf.userCfg[config_type].RemoveOption(section, item)
|
| 825 |
+
# If we got here, set the option.
|
| 826 |
+
return idleConf.userCfg[config_type].SetOption(section, item, value)
|
| 827 |
+
|
| 828 |
+
def save_all(self):
|
| 829 |
+
"""Save configuration changes to the user config file.
|
| 830 |
+
|
| 831 |
+
Clear self in preparation for additional changes.
|
| 832 |
+
Return changed for testing.
|
| 833 |
+
"""
|
| 834 |
+
idleConf.userCfg['main'].Save()
|
| 835 |
+
|
| 836 |
+
changed = False
|
| 837 |
+
for config_type in self:
|
| 838 |
+
cfg_type_changed = False
|
| 839 |
+
page = self[config_type]
|
| 840 |
+
for section in page:
|
| 841 |
+
if section == 'HelpFiles': # Remove it for replacement.
|
| 842 |
+
idleConf.userCfg['main'].remove_section('HelpFiles')
|
| 843 |
+
cfg_type_changed = True
|
| 844 |
+
for item, value in page[section].items():
|
| 845 |
+
if self.save_option(config_type, section, item, value):
|
| 846 |
+
cfg_type_changed = True
|
| 847 |
+
if cfg_type_changed:
|
| 848 |
+
idleConf.userCfg[config_type].Save()
|
| 849 |
+
changed = True
|
| 850 |
+
for config_type in ['keys', 'highlight']:
|
| 851 |
+
# Save these even if unchanged!
|
| 852 |
+
idleConf.userCfg[config_type].Save()
|
| 853 |
+
self.clear()
|
| 854 |
+
# ConfigDialog caller must add the following call
|
| 855 |
+
# self.save_all_changed_extensions() # Uses a different mechanism.
|
| 856 |
+
return changed
|
| 857 |
+
|
| 858 |
+
def delete_section(self, config_type, section):
|
| 859 |
+
"""Delete a section from self, userCfg, and file.
|
| 860 |
+
|
| 861 |
+
Used to delete custom themes and keysets.
|
| 862 |
+
"""
|
| 863 |
+
if section in self[config_type]:
|
| 864 |
+
del self[config_type][section]
|
| 865 |
+
configpage = idleConf.userCfg[config_type]
|
| 866 |
+
configpage.remove_section(section)
|
| 867 |
+
configpage.Save()
|
| 868 |
+
|
| 869 |
+
def clear(self):
|
| 870 |
+
"""Clear all 4 pages.
|
| 871 |
+
|
| 872 |
+
Called in save_all after saving to idleConf.
|
| 873 |
+
XXX Mark window *title* when there are changes; unmark here.
|
| 874 |
+
"""
|
| 875 |
+
for page in self.pages:
|
| 876 |
+
page.clear()
|
| 877 |
+
|
| 878 |
+
|
| 879 |
+
# TODO Revise test output, write expanded unittest
|
| 880 |
+
def _dump(): # htest # (not really, but ignore in coverage)
|
| 881 |
+
from zlib import crc32
|
| 882 |
+
line, crc = 0, 0
|
| 883 |
+
|
| 884 |
+
def sprint(obj):
|
| 885 |
+
nonlocal line, crc
|
| 886 |
+
txt = str(obj)
|
| 887 |
+
line += 1
|
| 888 |
+
crc = crc32(txt.encode(encoding='utf-8'), crc)
|
| 889 |
+
print(txt)
|
| 890 |
+
#print('***', line, crc, '***') # Uncomment for diagnosis.
|
| 891 |
+
|
| 892 |
+
def dumpCfg(cfg):
|
| 893 |
+
print('\n', cfg, '\n') # Cfg has variable '0xnnnnnnnn' address.
|
| 894 |
+
for key in sorted(cfg):
|
| 895 |
+
sections = cfg[key].sections()
|
| 896 |
+
sprint(key)
|
| 897 |
+
sprint(sections)
|
| 898 |
+
for section in sections:
|
| 899 |
+
options = cfg[key].options(section)
|
| 900 |
+
sprint(section)
|
| 901 |
+
sprint(options)
|
| 902 |
+
for option in options:
|
| 903 |
+
sprint(option + ' = ' + cfg[key].Get(section, option))
|
| 904 |
+
|
| 905 |
+
dumpCfg(idleConf.defaultCfg)
|
| 906 |
+
dumpCfg(idleConf.userCfg)
|
| 907 |
+
print('\nlines = ', line, ', crc = ', crc, sep='')
|
| 908 |
+
|
| 909 |
+
|
| 910 |
+
if __name__ == '__main__':
|
| 911 |
+
from unittest import main
|
| 912 |
+
main('idlelib.idle_test.test_config', verbosity=2, exit=False)
|
| 913 |
+
|
| 914 |
+
_dump()
|
| 915 |
+
# Run revised _dump() (700+ lines) as htest? More sorting.
|
| 916 |
+
# Perhaps as window with tabs for textviews, making it config viewer.
|
data/conda_envs/evalclaw/lib/python3.11/idlelib/debugger_r.py
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Support for remote Python debugging.
|
| 2 |
+
|
| 3 |
+
Some ASCII art to describe the structure:
|
| 4 |
+
|
| 5 |
+
IN PYTHON SUBPROCESS # IN IDLE PROCESS
|
| 6 |
+
#
|
| 7 |
+
# oid='gui_adapter'
|
| 8 |
+
+----------+ # +------------+ +-----+
|
| 9 |
+
| GUIProxy |--remote#call-->| GUIAdapter |--calls-->| GUI |
|
| 10 |
+
+-----+--calls-->+----------+ # +------------+ +-----+
|
| 11 |
+
| Idb | # /
|
| 12 |
+
+-----+<-calls--+------------+ # +----------+<--calls-/
|
| 13 |
+
| IdbAdapter |<--remote#call--| IdbProxy |
|
| 14 |
+
+------------+ # +----------+
|
| 15 |
+
oid='idb_adapter' #
|
| 16 |
+
|
| 17 |
+
The purpose of the Proxy and Adapter classes is to translate certain
|
| 18 |
+
arguments and return values that cannot be transported through the RPC
|
| 19 |
+
barrier, in particular frame and traceback objects.
|
| 20 |
+
|
| 21 |
+
"""
|
| 22 |
+
import reprlib
|
| 23 |
+
import types
|
| 24 |
+
from idlelib import debugger
|
| 25 |
+
|
| 26 |
+
debugging = 0
|
| 27 |
+
|
| 28 |
+
idb_adap_oid = "idb_adapter"
|
| 29 |
+
gui_adap_oid = "gui_adapter"
|
| 30 |
+
|
| 31 |
+
#=======================================
|
| 32 |
+
#
|
| 33 |
+
# In the PYTHON subprocess:
|
| 34 |
+
|
| 35 |
+
frametable = {}
|
| 36 |
+
dicttable = {}
|
| 37 |
+
codetable = {}
|
| 38 |
+
tracebacktable = {}
|
| 39 |
+
|
| 40 |
+
def wrap_frame(frame):
|
| 41 |
+
fid = id(frame)
|
| 42 |
+
frametable[fid] = frame
|
| 43 |
+
return fid
|
| 44 |
+
|
| 45 |
+
def wrap_info(info):
|
| 46 |
+
"replace info[2], a traceback instance, by its ID"
|
| 47 |
+
if info is None:
|
| 48 |
+
return None
|
| 49 |
+
else:
|
| 50 |
+
traceback = info[2]
|
| 51 |
+
assert isinstance(traceback, types.TracebackType)
|
| 52 |
+
traceback_id = id(traceback)
|
| 53 |
+
tracebacktable[traceback_id] = traceback
|
| 54 |
+
modified_info = (info[0], info[1], traceback_id)
|
| 55 |
+
return modified_info
|
| 56 |
+
|
| 57 |
+
class GUIProxy:
|
| 58 |
+
|
| 59 |
+
def __init__(self, conn, gui_adap_oid):
|
| 60 |
+
self.conn = conn
|
| 61 |
+
self.oid = gui_adap_oid
|
| 62 |
+
|
| 63 |
+
def interaction(self, message, frame, info=None):
|
| 64 |
+
# calls rpc.SocketIO.remotecall() via run.MyHandler instance
|
| 65 |
+
# pass frame and traceback object IDs instead of the objects themselves
|
| 66 |
+
self.conn.remotecall(self.oid, "interaction",
|
| 67 |
+
(message, wrap_frame(frame), wrap_info(info)),
|
| 68 |
+
{})
|
| 69 |
+
|
| 70 |
+
class IdbAdapter:
|
| 71 |
+
|
| 72 |
+
def __init__(self, idb):
|
| 73 |
+
self.idb = idb
|
| 74 |
+
|
| 75 |
+
#----------called by an IdbProxy----------
|
| 76 |
+
|
| 77 |
+
def set_step(self):
|
| 78 |
+
self.idb.set_step()
|
| 79 |
+
|
| 80 |
+
def set_quit(self):
|
| 81 |
+
self.idb.set_quit()
|
| 82 |
+
|
| 83 |
+
def set_continue(self):
|
| 84 |
+
self.idb.set_continue()
|
| 85 |
+
|
| 86 |
+
def set_next(self, fid):
|
| 87 |
+
frame = frametable[fid]
|
| 88 |
+
self.idb.set_next(frame)
|
| 89 |
+
|
| 90 |
+
def set_return(self, fid):
|
| 91 |
+
frame = frametable[fid]
|
| 92 |
+
self.idb.set_return(frame)
|
| 93 |
+
|
| 94 |
+
def get_stack(self, fid, tbid):
|
| 95 |
+
frame = frametable[fid]
|
| 96 |
+
if tbid is None:
|
| 97 |
+
tb = None
|
| 98 |
+
else:
|
| 99 |
+
tb = tracebacktable[tbid]
|
| 100 |
+
stack, i = self.idb.get_stack(frame, tb)
|
| 101 |
+
stack = [(wrap_frame(frame2), k) for frame2, k in stack]
|
| 102 |
+
return stack, i
|
| 103 |
+
|
| 104 |
+
def run(self, cmd):
|
| 105 |
+
import __main__
|
| 106 |
+
self.idb.run(cmd, __main__.__dict__)
|
| 107 |
+
|
| 108 |
+
def set_break(self, filename, lineno):
|
| 109 |
+
msg = self.idb.set_break(filename, lineno)
|
| 110 |
+
return msg
|
| 111 |
+
|
| 112 |
+
def clear_break(self, filename, lineno):
|
| 113 |
+
msg = self.idb.clear_break(filename, lineno)
|
| 114 |
+
return msg
|
| 115 |
+
|
| 116 |
+
def clear_all_file_breaks(self, filename):
|
| 117 |
+
msg = self.idb.clear_all_file_breaks(filename)
|
| 118 |
+
return msg
|
| 119 |
+
|
| 120 |
+
#----------called by a FrameProxy----------
|
| 121 |
+
|
| 122 |
+
def frame_attr(self, fid, name):
|
| 123 |
+
frame = frametable[fid]
|
| 124 |
+
return getattr(frame, name)
|
| 125 |
+
|
| 126 |
+
def frame_globals(self, fid):
|
| 127 |
+
frame = frametable[fid]
|
| 128 |
+
gdict = frame.f_globals
|
| 129 |
+
did = id(gdict)
|
| 130 |
+
dicttable[did] = gdict
|
| 131 |
+
return did
|
| 132 |
+
|
| 133 |
+
def frame_locals(self, fid):
|
| 134 |
+
frame = frametable[fid]
|
| 135 |
+
ldict = frame.f_locals
|
| 136 |
+
did = id(ldict)
|
| 137 |
+
dicttable[did] = ldict
|
| 138 |
+
return did
|
| 139 |
+
|
| 140 |
+
def frame_code(self, fid):
|
| 141 |
+
frame = frametable[fid]
|
| 142 |
+
code = frame.f_code
|
| 143 |
+
cid = id(code)
|
| 144 |
+
codetable[cid] = code
|
| 145 |
+
return cid
|
| 146 |
+
|
| 147 |
+
#----------called by a CodeProxy----------
|
| 148 |
+
|
| 149 |
+
def code_name(self, cid):
|
| 150 |
+
code = codetable[cid]
|
| 151 |
+
return code.co_name
|
| 152 |
+
|
| 153 |
+
def code_filename(self, cid):
|
| 154 |
+
code = codetable[cid]
|
| 155 |
+
return code.co_filename
|
| 156 |
+
|
| 157 |
+
#----------called by a DictProxy----------
|
| 158 |
+
|
| 159 |
+
def dict_keys(self, did):
|
| 160 |
+
raise NotImplementedError("dict_keys not public or pickleable")
|
| 161 |
+
## return dicttable[did].keys()
|
| 162 |
+
|
| 163 |
+
### Needed until dict_keys type is finished and pickleable.
|
| 164 |
+
# xxx finished. pickleable?
|
| 165 |
+
### Will probably need to extend rpc.py:SocketIO._proxify at that time.
|
| 166 |
+
def dict_keys_list(self, did):
|
| 167 |
+
return list(dicttable[did].keys())
|
| 168 |
+
|
| 169 |
+
def dict_item(self, did, key):
|
| 170 |
+
value = dicttable[did][key]
|
| 171 |
+
return reprlib.repr(value) # Can't pickle module 'builtins'.
|
| 172 |
+
|
| 173 |
+
#----------end class IdbAdapter----------
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def start_debugger(rpchandler, gui_adap_oid):
|
| 177 |
+
"""Start the debugger and its RPC link in the Python subprocess
|
| 178 |
+
|
| 179 |
+
Start the subprocess side of the split debugger and set up that side of the
|
| 180 |
+
RPC link by instantiating the GUIProxy, Idb debugger, and IdbAdapter
|
| 181 |
+
objects and linking them together. Register the IdbAdapter with the
|
| 182 |
+
RPCServer to handle RPC requests from the split debugger GUI via the
|
| 183 |
+
IdbProxy.
|
| 184 |
+
|
| 185 |
+
"""
|
| 186 |
+
gui_proxy = GUIProxy(rpchandler, gui_adap_oid)
|
| 187 |
+
idb = debugger.Idb(gui_proxy)
|
| 188 |
+
idb_adap = IdbAdapter(idb)
|
| 189 |
+
rpchandler.register(idb_adap_oid, idb_adap)
|
| 190 |
+
return idb_adap_oid
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
#=======================================
|
| 194 |
+
#
|
| 195 |
+
# In the IDLE process:
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
class FrameProxy:
|
| 199 |
+
|
| 200 |
+
def __init__(self, conn, fid):
|
| 201 |
+
self._conn = conn
|
| 202 |
+
self._fid = fid
|
| 203 |
+
self._oid = "idb_adapter"
|
| 204 |
+
self._dictcache = {}
|
| 205 |
+
|
| 206 |
+
def __getattr__(self, name):
|
| 207 |
+
if name[:1] == "_":
|
| 208 |
+
raise AttributeError(name)
|
| 209 |
+
if name == "f_code":
|
| 210 |
+
return self._get_f_code()
|
| 211 |
+
if name == "f_globals":
|
| 212 |
+
return self._get_f_globals()
|
| 213 |
+
if name == "f_locals":
|
| 214 |
+
return self._get_f_locals()
|
| 215 |
+
return self._conn.remotecall(self._oid, "frame_attr",
|
| 216 |
+
(self._fid, name), {})
|
| 217 |
+
|
| 218 |
+
def _get_f_code(self):
|
| 219 |
+
cid = self._conn.remotecall(self._oid, "frame_code", (self._fid,), {})
|
| 220 |
+
return CodeProxy(self._conn, self._oid, cid)
|
| 221 |
+
|
| 222 |
+
def _get_f_globals(self):
|
| 223 |
+
did = self._conn.remotecall(self._oid, "frame_globals",
|
| 224 |
+
(self._fid,), {})
|
| 225 |
+
return self._get_dict_proxy(did)
|
| 226 |
+
|
| 227 |
+
def _get_f_locals(self):
|
| 228 |
+
did = self._conn.remotecall(self._oid, "frame_locals",
|
| 229 |
+
(self._fid,), {})
|
| 230 |
+
return self._get_dict_proxy(did)
|
| 231 |
+
|
| 232 |
+
def _get_dict_proxy(self, did):
|
| 233 |
+
if did in self._dictcache:
|
| 234 |
+
return self._dictcache[did]
|
| 235 |
+
dp = DictProxy(self._conn, self._oid, did)
|
| 236 |
+
self._dictcache[did] = dp
|
| 237 |
+
return dp
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
class CodeProxy:
|
| 241 |
+
|
| 242 |
+
def __init__(self, conn, oid, cid):
|
| 243 |
+
self._conn = conn
|
| 244 |
+
self._oid = oid
|
| 245 |
+
self._cid = cid
|
| 246 |
+
|
| 247 |
+
def __getattr__(self, name):
|
| 248 |
+
if name == "co_name":
|
| 249 |
+
return self._conn.remotecall(self._oid, "code_name",
|
| 250 |
+
(self._cid,), {})
|
| 251 |
+
if name == "co_filename":
|
| 252 |
+
return self._conn.remotecall(self._oid, "code_filename",
|
| 253 |
+
(self._cid,), {})
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
class DictProxy:
|
| 257 |
+
|
| 258 |
+
def __init__(self, conn, oid, did):
|
| 259 |
+
self._conn = conn
|
| 260 |
+
self._oid = oid
|
| 261 |
+
self._did = did
|
| 262 |
+
|
| 263 |
+
## def keys(self):
|
| 264 |
+
## return self._conn.remotecall(self._oid, "dict_keys", (self._did,), {})
|
| 265 |
+
|
| 266 |
+
# 'temporary' until dict_keys is a pickleable built-in type
|
| 267 |
+
def keys(self):
|
| 268 |
+
return self._conn.remotecall(self._oid,
|
| 269 |
+
"dict_keys_list", (self._did,), {})
|
| 270 |
+
|
| 271 |
+
def __getitem__(self, key):
|
| 272 |
+
return self._conn.remotecall(self._oid, "dict_item",
|
| 273 |
+
(self._did, key), {})
|
| 274 |
+
|
| 275 |
+
def __getattr__(self, name):
|
| 276 |
+
##print("*** Failed DictProxy.__getattr__:", name)
|
| 277 |
+
raise AttributeError(name)
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
class GUIAdapter:
|
| 281 |
+
|
| 282 |
+
def __init__(self, conn, gui):
|
| 283 |
+
self.conn = conn
|
| 284 |
+
self.gui = gui
|
| 285 |
+
|
| 286 |
+
def interaction(self, message, fid, modified_info):
|
| 287 |
+
##print("*** Interaction: (%s, %s, %s)" % (message, fid, modified_info))
|
| 288 |
+
frame = FrameProxy(self.conn, fid)
|
| 289 |
+
self.gui.interaction(message, frame, modified_info)
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
class IdbProxy:
|
| 293 |
+
|
| 294 |
+
def __init__(self, conn, shell, oid):
|
| 295 |
+
self.oid = oid
|
| 296 |
+
self.conn = conn
|
| 297 |
+
self.shell = shell
|
| 298 |
+
|
| 299 |
+
def call(self, methodname, /, *args, **kwargs):
|
| 300 |
+
##print("*** IdbProxy.call %s %s %s" % (methodname, args, kwargs))
|
| 301 |
+
value = self.conn.remotecall(self.oid, methodname, args, kwargs)
|
| 302 |
+
##print("*** IdbProxy.call %s returns %r" % (methodname, value))
|
| 303 |
+
return value
|
| 304 |
+
|
| 305 |
+
def run(self, cmd, locals):
|
| 306 |
+
# Ignores locals on purpose!
|
| 307 |
+
seq = self.conn.asyncqueue(self.oid, "run", (cmd,), {})
|
| 308 |
+
self.shell.interp.active_seq = seq
|
| 309 |
+
|
| 310 |
+
def get_stack(self, frame, tbid):
|
| 311 |
+
# passing frame and traceback IDs, not the objects themselves
|
| 312 |
+
stack, i = self.call("get_stack", frame._fid, tbid)
|
| 313 |
+
stack = [(FrameProxy(self.conn, fid), k) for fid, k in stack]
|
| 314 |
+
return stack, i
|
| 315 |
+
|
| 316 |
+
def set_continue(self):
|
| 317 |
+
self.call("set_continue")
|
| 318 |
+
|
| 319 |
+
def set_step(self):
|
| 320 |
+
self.call("set_step")
|
| 321 |
+
|
| 322 |
+
def set_next(self, frame):
|
| 323 |
+
self.call("set_next", frame._fid)
|
| 324 |
+
|
| 325 |
+
def set_return(self, frame):
|
| 326 |
+
self.call("set_return", frame._fid)
|
| 327 |
+
|
| 328 |
+
def set_quit(self):
|
| 329 |
+
self.call("set_quit")
|
| 330 |
+
|
| 331 |
+
def set_break(self, filename, lineno):
|
| 332 |
+
msg = self.call("set_break", filename, lineno)
|
| 333 |
+
return msg
|
| 334 |
+
|
| 335 |
+
def clear_break(self, filename, lineno):
|
| 336 |
+
msg = self.call("clear_break", filename, lineno)
|
| 337 |
+
return msg
|
| 338 |
+
|
| 339 |
+
def clear_all_file_breaks(self, filename):
|
| 340 |
+
msg = self.call("clear_all_file_breaks", filename)
|
| 341 |
+
return msg
|
| 342 |
+
|
| 343 |
+
def start_remote_debugger(rpcclt, pyshell):
|
| 344 |
+
"""Start the subprocess debugger, initialize the debugger GUI and RPC link
|
| 345 |
+
|
| 346 |
+
Request the RPCServer start the Python subprocess debugger and link. Set
|
| 347 |
+
up the Idle side of the split debugger by instantiating the IdbProxy,
|
| 348 |
+
debugger GUI, and debugger GUIAdapter objects and linking them together.
|
| 349 |
+
|
| 350 |
+
Register the GUIAdapter with the RPCClient to handle debugger GUI
|
| 351 |
+
interaction requests coming from the subprocess debugger via the GUIProxy.
|
| 352 |
+
|
| 353 |
+
The IdbAdapter will pass execution and environment requests coming from the
|
| 354 |
+
Idle debugger GUI to the subprocess debugger via the IdbProxy.
|
| 355 |
+
|
| 356 |
+
"""
|
| 357 |
+
global idb_adap_oid
|
| 358 |
+
|
| 359 |
+
idb_adap_oid = rpcclt.remotecall("exec", "start_the_debugger",\
|
| 360 |
+
(gui_adap_oid,), {})
|
| 361 |
+
idb_proxy = IdbProxy(rpcclt, pyshell, idb_adap_oid)
|
| 362 |
+
gui = debugger.Debugger(pyshell, idb_proxy)
|
| 363 |
+
gui_adap = GUIAdapter(rpcclt, gui)
|
| 364 |
+
rpcclt.register(gui_adap_oid, gui_adap)
|
| 365 |
+
return gui
|
| 366 |
+
|
| 367 |
+
def close_remote_debugger(rpcclt):
|
| 368 |
+
"""Shut down subprocess debugger and Idle side of debugger RPC link
|
| 369 |
+
|
| 370 |
+
Request that the RPCServer shut down the subprocess debugger and link.
|
| 371 |
+
Unregister the GUIAdapter, which will cause a GC on the Idle process
|
| 372 |
+
debugger and RPC link objects. (The second reference to the debugger GUI
|
| 373 |
+
is deleted in pyshell.close_remote_debugger().)
|
| 374 |
+
|
| 375 |
+
"""
|
| 376 |
+
close_subprocess_debugger(rpcclt)
|
| 377 |
+
rpcclt.unregister(gui_adap_oid)
|
| 378 |
+
|
| 379 |
+
def close_subprocess_debugger(rpcclt):
|
| 380 |
+
rpcclt.remotecall("exec", "stop_the_debugger", (idb_adap_oid,), {})
|
| 381 |
+
|
| 382 |
+
def restart_subprocess_debugger(rpcclt):
|
| 383 |
+
idb_adap_oid_ret = rpcclt.remotecall("exec", "start_the_debugger",\
|
| 384 |
+
(gui_adap_oid,), {})
|
| 385 |
+
assert idb_adap_oid_ret == idb_adap_oid, 'Idb restarted with different oid'
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
if __name__ == "__main__":
|
| 389 |
+
from unittest import main
|
| 390 |
+
main('idlelib.idle_test.test_debugger_r', verbosity=2, exit=False)
|
data/conda_envs/evalclaw/lib/python3.11/idlelib/debugobj.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Define tree items for debug stackviewer, which is only user.
|
| 2 |
+
"""
|
| 3 |
+
# XXX TO DO:
|
| 4 |
+
# - popup menu
|
| 5 |
+
# - support partial or total redisplay
|
| 6 |
+
# - more doc strings
|
| 7 |
+
# - tooltips
|
| 8 |
+
|
| 9 |
+
# object browser
|
| 10 |
+
|
| 11 |
+
# XXX TO DO:
|
| 12 |
+
# - for classes/modules, add "open source" to object browser
|
| 13 |
+
from reprlib import Repr
|
| 14 |
+
|
| 15 |
+
from idlelib.tree import TreeItem, TreeNode, ScrolledCanvas
|
| 16 |
+
|
| 17 |
+
myrepr = Repr()
|
| 18 |
+
myrepr.maxstring = 100
|
| 19 |
+
myrepr.maxother = 100
|
| 20 |
+
|
| 21 |
+
class ObjectTreeItem(TreeItem):
|
| 22 |
+
def __init__(self, labeltext, object_, setfunction=None):
|
| 23 |
+
self.labeltext = labeltext
|
| 24 |
+
self.object = object_
|
| 25 |
+
self.setfunction = setfunction
|
| 26 |
+
def GetLabelText(self):
|
| 27 |
+
return self.labeltext
|
| 28 |
+
def GetText(self):
|
| 29 |
+
return myrepr.repr(self.object)
|
| 30 |
+
def GetIconName(self):
|
| 31 |
+
if not self.IsExpandable():
|
| 32 |
+
return "python"
|
| 33 |
+
def IsEditable(self):
|
| 34 |
+
return self.setfunction is not None
|
| 35 |
+
def SetText(self, text):
|
| 36 |
+
try:
|
| 37 |
+
value = eval(text)
|
| 38 |
+
self.setfunction(value)
|
| 39 |
+
except:
|
| 40 |
+
pass
|
| 41 |
+
else:
|
| 42 |
+
self.object = value
|
| 43 |
+
def IsExpandable(self):
|
| 44 |
+
return not not dir(self.object)
|
| 45 |
+
def GetSubList(self):
|
| 46 |
+
keys = dir(self.object)
|
| 47 |
+
sublist = []
|
| 48 |
+
for key in keys:
|
| 49 |
+
try:
|
| 50 |
+
value = getattr(self.object, key)
|
| 51 |
+
except AttributeError:
|
| 52 |
+
continue
|
| 53 |
+
item = make_objecttreeitem(
|
| 54 |
+
str(key) + " =",
|
| 55 |
+
value,
|
| 56 |
+
lambda value, key=key, object_=self.object:
|
| 57 |
+
setattr(object_, key, value))
|
| 58 |
+
sublist.append(item)
|
| 59 |
+
return sublist
|
| 60 |
+
|
| 61 |
+
class ClassTreeItem(ObjectTreeItem):
|
| 62 |
+
def IsExpandable(self):
|
| 63 |
+
return True
|
| 64 |
+
def GetSubList(self):
|
| 65 |
+
sublist = ObjectTreeItem.GetSubList(self)
|
| 66 |
+
if len(self.object.__bases__) == 1:
|
| 67 |
+
item = make_objecttreeitem("__bases__[0] =",
|
| 68 |
+
self.object.__bases__[0])
|
| 69 |
+
else:
|
| 70 |
+
item = make_objecttreeitem("__bases__ =", self.object.__bases__)
|
| 71 |
+
sublist.insert(0, item)
|
| 72 |
+
return sublist
|
| 73 |
+
|
| 74 |
+
class AtomicObjectTreeItem(ObjectTreeItem):
|
| 75 |
+
def IsExpandable(self):
|
| 76 |
+
return False
|
| 77 |
+
|
| 78 |
+
class SequenceTreeItem(ObjectTreeItem):
|
| 79 |
+
def IsExpandable(self):
|
| 80 |
+
return len(self.object) > 0
|
| 81 |
+
def keys(self):
|
| 82 |
+
return range(len(self.object))
|
| 83 |
+
def GetSubList(self):
|
| 84 |
+
sublist = []
|
| 85 |
+
for key in self.keys():
|
| 86 |
+
try:
|
| 87 |
+
value = self.object[key]
|
| 88 |
+
except KeyError:
|
| 89 |
+
continue
|
| 90 |
+
def setfunction(value, key=key, object_=self.object):
|
| 91 |
+
object_[key] = value
|
| 92 |
+
item = make_objecttreeitem(f"{key!r}:", value, setfunction)
|
| 93 |
+
sublist.append(item)
|
| 94 |
+
return sublist
|
| 95 |
+
|
| 96 |
+
class DictTreeItem(SequenceTreeItem):
|
| 97 |
+
def keys(self):
|
| 98 |
+
# TODO return sorted(self.object)
|
| 99 |
+
keys = list(self.object)
|
| 100 |
+
try:
|
| 101 |
+
keys.sort()
|
| 102 |
+
except:
|
| 103 |
+
pass
|
| 104 |
+
return keys
|
| 105 |
+
|
| 106 |
+
dispatch = {
|
| 107 |
+
int: AtomicObjectTreeItem,
|
| 108 |
+
float: AtomicObjectTreeItem,
|
| 109 |
+
str: AtomicObjectTreeItem,
|
| 110 |
+
tuple: SequenceTreeItem,
|
| 111 |
+
list: SequenceTreeItem,
|
| 112 |
+
dict: DictTreeItem,
|
| 113 |
+
type: ClassTreeItem,
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
def make_objecttreeitem(labeltext, object_, setfunction=None):
|
| 117 |
+
t = type(object_)
|
| 118 |
+
if t in dispatch:
|
| 119 |
+
c = dispatch[t]
|
| 120 |
+
else:
|
| 121 |
+
c = ObjectTreeItem
|
| 122 |
+
return c(labeltext, object_, setfunction)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _debug_object_browser(parent): # htest #
|
| 126 |
+
import sys
|
| 127 |
+
from tkinter import Toplevel
|
| 128 |
+
top = Toplevel(parent)
|
| 129 |
+
top.title("Test debug object browser")
|
| 130 |
+
x, y = map(int, parent.geometry().split('+')[1:])
|
| 131 |
+
top.geometry("+%d+%d" % (x + 100, y + 175))
|
| 132 |
+
top.configure(bd=0, bg="yellow")
|
| 133 |
+
top.focus_set()
|
| 134 |
+
sc = ScrolledCanvas(top, bg="white", highlightthickness=0, takefocus=1)
|
| 135 |
+
sc.frame.pack(expand=1, fill="both")
|
| 136 |
+
item = make_objecttreeitem("sys", sys)
|
| 137 |
+
node = TreeNode(sc.canvas, None, item)
|
| 138 |
+
node.update()
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
if __name__ == '__main__':
|
| 142 |
+
from unittest import main
|
| 143 |
+
main('idlelib.idle_test.test_debugobj', verbosity=2, exit=False)
|
| 144 |
+
|
| 145 |
+
from idlelib.idle_test.htest import run
|
| 146 |
+
run(_debug_object_browser)
|
data/conda_envs/evalclaw/lib/python3.11/idlelib/debugobj_r.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from idlelib import rpc
|
| 2 |
+
|
| 3 |
+
def remote_object_tree_item(item):
|
| 4 |
+
wrapper = WrappedObjectTreeItem(item)
|
| 5 |
+
oid = id(wrapper)
|
| 6 |
+
rpc.objecttable[oid] = wrapper
|
| 7 |
+
return oid
|
| 8 |
+
|
| 9 |
+
class WrappedObjectTreeItem:
|
| 10 |
+
# Lives in PYTHON subprocess
|
| 11 |
+
|
| 12 |
+
def __init__(self, item):
|
| 13 |
+
self.__item = item
|
| 14 |
+
|
| 15 |
+
def __getattr__(self, name):
|
| 16 |
+
value = getattr(self.__item, name)
|
| 17 |
+
return value
|
| 18 |
+
|
| 19 |
+
def _GetSubList(self):
|
| 20 |
+
sub_list = self.__item._GetSubList()
|
| 21 |
+
return list(map(remote_object_tree_item, sub_list))
|
| 22 |
+
|
| 23 |
+
class StubObjectTreeItem:
|
| 24 |
+
# Lives in IDLE process
|
| 25 |
+
|
| 26 |
+
def __init__(self, sockio, oid):
|
| 27 |
+
self.sockio = sockio
|
| 28 |
+
self.oid = oid
|
| 29 |
+
|
| 30 |
+
def __getattr__(self, name):
|
| 31 |
+
value = rpc.MethodProxy(self.sockio, self.oid, name)
|
| 32 |
+
return value
|
| 33 |
+
|
| 34 |
+
def _GetSubList(self):
|
| 35 |
+
sub_list = self.sockio.remotecall(self.oid, "_GetSubList", (), {})
|
| 36 |
+
return [StubObjectTreeItem(self.sockio, oid) for oid in sub_list]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
if __name__ == '__main__':
|
| 40 |
+
from unittest import main
|
| 41 |
+
main('idlelib.idle_test.test_debugobj_r', verbosity=2)
|