text stringlengths 0 828 |
|---|
args = args[1:] |
else: |
raise ValueError(""Hum, %r is a callable, but not a function/method, "" |
""nor a instance with __call__ arg..."" |
% acallable) |
if vargs or vkwargs: |
raise SyntaxError(""variable *arg or **kwarg are not supported."") |
if is_bound(acallable): |
args = args[1:] |
if defaults is None: |
defaults = () ## be coherent |
return args, defaults" |
222,"def match_prototype(acallable, arguments): |
""""""Return tuple (pos args, kwargs) to call given callable |
Let's define a callable that will printout |
>>> arguments = {'alphonse': 1, 'bertrand': 2, 'charlie': 3} |
>>> match_prototype(lambda arguments: None, arguments) |
([{'bertrand': 2, 'charlie': 3, 'alphonse': 1}], {}) |
>>> match_prototype(lambda args: None, arguments) |
([{'bertrand': 2, 'charlie': 3, 'alphonse': 1}], {}) |
>>> match_prototype(lambda bertrand, arguments: None, arguments) |
([2, {'charlie': 3, 'alphonse': 1}], {}) |
>>> match_prototype(lambda bertrand, arguments, foo=None: None, arguments) |
([2, {'charlie': 3, 'alphonse': 1}], {}) |
>>> match_prototype(lambda bertrand, arguments, charlie=None: None, |
... arguments) |
([2, {'alphonse': 1}], {'charlie': 3}) |
"""""" |
args, defaults = get_calling_prototype(acallable) |
arguments = arguments.copy() |
defaults = [] if defaults is None else defaults |
p = [] |
kw = {} |
pos_args = len(args) - len(defaults) |
has_args = any(k in ('args', 'arguments') |
for k in args) |
args_label_pos = None |
for i, arg in enumerate(args): |
is_pos = i < pos_args |
val = None |
if not args_label_pos and arg in ('arguments', 'args'): |
val = arguments ## copy by reference here is important |
else: |
k = None |
for k in arguments: |
norm = k |
if norm.startswith(""--""): |
if is_pos: |
continue |
norm = norm[2:] |
elif k.startswith(""-""): |
if is_pos: |
continue |
norm = norm[1:] |
norm = norm.lower() |
norm = norm.replace('-', '_') |
if norm == arg: |
break |
else: |
if not has_args: |
raise SyntaxError( |
""Can't match your function argument %r with "" |
""command line keys (%s)."" |
% (arg, "", "".join(arguments.keys()))) |
else: |
k = None |
if k is not None: |
## inplace removal is important here |
val = arguments.pop(k) |
if is_pos: |
p.append(val) |
else: |
if val is not None: |
## we should only have strings if it was set. |
kw[arg] = val |
return p, kw" |
223,"def initialize(self): |
"""""" Generate the root directory root if it doesn't already exist """""" |
if not os.path.exists(self.root_dir): |
os.makedirs(self.root_dir) |
assert os.path.isdir(self.root_dir), ""%s is not a directory! Please move or remove it."" % self.root_dir |
for d in [""bin"", ""lib"", ""include""]: |
target_path = os.path.join(self.root_dir, d) |
if not os.path.exists(target_path): |
os.makedirs(target_path) |
if not os.path.exists(self.manifest_path): |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.