idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
38,600
def set_context_prefix ( self , name , prefix ) : data = self . _context ( name ) data [ "prefix" ] = prefix self . _flush_tools ( )
Set a context s prefix .
38,601
def set_context_suffix ( self , name , suffix ) : data = self . _context ( name ) data [ "suffix" ] = suffix self . _flush_tools ( )
Set a context s suffix .
38,602
def bump_context ( self , name ) : data = self . _context ( name ) data [ "priority" ] = self . _next_priority self . _flush_tools ( )
Causes the context s tools to take priority over all others .
38,603
def hide_tool ( self , context_name , tool_name ) : data = self . _context ( context_name ) hidden_tools = data [ "hidden_tools" ] if tool_name not in hidden_tools : self . _validate_tool ( context_name , tool_name ) hidden_tools . add ( tool_name ) self . _flush_tools ( )
Hide a tool so that it is not exposed in the suite .
38,604
def unhide_tool ( self , context_name , tool_name ) : data = self . _context ( context_name ) hidden_tools = data [ "hidden_tools" ] if tool_name in hidden_tools : hidden_tools . remove ( tool_name ) self . _flush_tools ( )
Unhide a tool so that it may be exposed in a suite .
38,605
def alias_tool ( self , context_name , tool_name , tool_alias ) : data = self . _context ( context_name ) aliases = data [ "tool_aliases" ] if tool_name in aliases : raise SuiteError ( "Tool %r in context %r is already aliased to %r" % ( tool_name , context_name , aliases [ tool_name ] ) ) self . _validate_tool ( conte...
Register an alias for a specific tool .
38,606
def unalias_tool ( self , context_name , tool_name ) : data = self . _context ( context_name ) aliases = data [ "tool_aliases" ] if tool_name in aliases : del aliases [ tool_name ] self . _flush_tools ( )
Deregister an alias for a specific tool .
38,607
def get_tool_filepath ( self , tool_alias ) : tools_dict = self . get_tools ( ) if tool_alias in tools_dict : if self . tools_path is None : return None else : return os . path . join ( self . tools_path , tool_alias ) else : return None
Given a visible tool alias return the full path to the executable .
38,608
def get_tool_context ( self , tool_alias ) : tools_dict = self . get_tools ( ) data = tools_dict . get ( tool_alias ) if data : return data [ "context_name" ] return None
Given a visible tool alias return the name of the context it belongs to .
38,609
def validate ( self ) : for context_name in self . context_names : context = self . context ( context_name ) try : context . validate ( ) except ResolvedContextError as e : raise SuiteError ( "Error in context %r: %s" % ( context_name , str ( e ) ) )
Validate the suite .
38,610
def save ( self , path , verbose = False ) : path = os . path . realpath ( path ) if os . path . exists ( path ) : if self . load_path and self . load_path == path : if verbose : print "saving over previous suite..." for context_name in self . context_names : self . context ( context_name ) shutil . rmtree ( path ) els...
Save the suite to disk .
38,611
def print_info ( self , buf = sys . stdout , verbose = False ) : _pr = Printer ( buf ) if not self . contexts : _pr ( "Suite is empty." ) return context_names = sorted ( self . contexts . iterkeys ( ) ) _pr ( "Suite contains %d contexts:" % len ( context_names ) ) if not verbose : _pr ( ' ' . join ( context_names ) ) r...
Prints a message summarising the contents of the suite .
38,612
def get_valid_build_systems ( working_dir , package = None ) : from rez . plugin_managers import plugin_manager from rez . exceptions import PackageMetadataError try : package = package or get_developer_package ( working_dir ) except PackageMetadataError : pass if package : if getattr ( package , "build_command" , None...
Returns the build system classes that could build the source in given dir .
38,613
def create_build_system ( working_dir , buildsys_type = None , package = None , opts = None , write_build_scripts = False , verbose = False , build_args = [ ] , child_build_args = [ ] ) : from rez . plugin_managers import plugin_manager if not buildsys_type : clss = get_valid_build_systems ( working_dir , package = pac...
Return a new build system that can build the source in working_dir .
38,614
def build ( self , context , variant , build_path , install_path , install = False , build_type = BuildType . local ) : raise NotImplementedError
Implement this method to perform the actual build .
38,615
def get_standard_vars ( cls , context , variant , build_type , install , build_path , install_path = None ) : from rez . config import config package = variant . parent variant_requires = map ( str , variant . variant_requires ) if variant . index is None : variant_subpath = '' else : variant_subpath = variant . _non_s...
Returns a standard set of environment variables that can be set for the build system to use
38,616
def set_standard_vars ( cls , executor , context , variant , build_type , install , build_path , install_path = None ) : vars = cls . get_standard_vars ( context = context , variant = variant , build_type = build_type , install = install , build_path = build_path , install_path = install_path ) for var , value in vars ...
Sets a standard set of environment variables for the build system to use
38,617
def run_pip_command ( command_args , pip_version = None , python_version = None ) : pip_exe , context = find_pip ( pip_version , python_version ) command = [ pip_exe ] + list ( command_args ) if context is None : return popen ( command ) else : return context . execute_shell ( command = command , block = False )
Run a pip command .
38,618
def find_pip ( pip_version = None , python_version = None ) : pip_exe = "pip" try : context = create_context ( pip_version , python_version ) except BuildError as e : from rez . backport . shutilwhich import which pip_exe = which ( "pip" ) if pip_exe : print_warning ( "pip rez package could not be found; system 'pip' c...
Find a pip exe using the given python version .
38,619
def create_context ( pip_version = None , python_version = None ) : if pip_version : pip_req = "pip-%s" % str ( pip_version ) else : pip_req = "pip" if python_version : ver = Version ( str ( python_version ) ) major_minor_ver = ver . trim ( 2 ) py_req = "python-%s" % str ( major_minor_ver ) else : package = get_latest_...
Create a context containing the specific pip and python .
38,620
def convert_old_variant_handle ( handle_dict ) : old_variables = handle_dict . get ( "variables" , { } ) variables = dict ( repository_type = "filesystem" ) for old_key , key in variant_key_conversions . iteritems ( ) : value = old_variables . get ( old_key ) variables [ key ] = value path = handle_dict [ "path" ] file...
Convert a variant handle from serialize_version < 4 . 0 .
38,621
def convert_requirement ( req ) : pkg_name = convert_name ( req . project_name ) if not req . specs : return [ pkg_name ] req_strs = [ ] for spec in req . specs : op , ver = spec ver = convert_version ( ver ) if op == "<" : r = "%s-0+<%s" % ( pkg_name , ver ) req_strs . append ( r ) elif op == "<=" : r = "%s-0+<%s|%s" ...
Converts a pkg_resources . Requirement object into a list of Rez package request strings .
38,622
def get_dist_dependencies ( name , recurse = True ) : dist = pkg_resources . get_distribution ( name ) pkg_name = convert_name ( dist . project_name ) reqs = set ( ) working = set ( [ dist ] ) depth = 0 while working : deps = set ( ) for distname in working : dist = pkg_resources . get_distribution ( distname ) pkg_nam...
Get the dependencies of the given already installed distribution .
38,623
def add_graph ( self , other ) : self . add_nodes ( n for n in other . nodes ( ) if not n in self . nodes ( ) ) for each_node in other . nodes ( ) : for each_edge in other . neighbors ( each_node ) : if ( not self . has_edge ( ( each_node , each_edge ) ) ) : self . add_edge ( ( each_node , each_edge ) )
Add other graph to this graph .
38,624
def add_spanning_tree ( self , st ) : self . add_nodes ( list ( st . keys ( ) ) ) for each in st : if ( st [ each ] is not None ) : self . add_edge ( ( st [ each ] , each ) )
Add a spanning tree to the graph .
38,625
def complete ( self ) : for each in self . nodes ( ) : for other in self . nodes ( ) : if ( each != other and not self . has_edge ( ( each , other ) ) ) : self . add_edge ( ( each , other ) )
Make the graph a complete graph .
38,626
def inverse ( self ) : inv = self . __class__ ( ) inv . add_nodes ( self . nodes ( ) ) inv . complete ( ) for each in self . edges ( ) : if ( inv . has_edge ( each ) ) : inv . del_edge ( each ) return inv
Return the inverse of the graph .
38,627
def reverse ( self ) : assert self . DIRECTED , "Undirected graph types such as %s cannot be reversed" % self . __class__ . __name__ N = self . __class__ ( ) N . add_nodes ( n for n in self . nodes ( ) ) for ( u , v ) in self . edges ( ) : wt = self . edge_weight ( ( u , v ) ) label = self . edge_label ( ( u , v ) ) at...
Generate the reverse of a directed graph returns an identical graph if not directed . Attributes & weights are preserved .
38,628
def get_lock_request ( name , version , patch_lock , weak = True ) : ch = '~' if weak else '' if patch_lock == PatchLock . lock : s = "%s%s==%s" % ( ch , name , str ( version ) ) return PackageRequest ( s ) elif ( patch_lock == PatchLock . no_lock ) or ( not version ) : return None version_ = version . trim ( patch_loc...
Given a package and patch lock return the equivalent request .
38,629
def requested_packages ( self , include_implicit = False ) : if include_implicit : return self . _package_requests + self . implicit_packages else : return self . _package_requests
Get packages in the request .
38,630
def get_resolved_package ( self , name ) : pkgs = [ x for x in self . _resolved_packages if x . name == name ] return pkgs [ 0 ] if pkgs else None
Returns a Variant object or None if the package is not in the resolve .
38,631
def get_patched_request ( self , package_requests = None , package_subtractions = None , strict = False , rank = 0 ) : if strict : request = [ ] for variant in self . resolved_packages : req = PackageRequest ( variant . qualified_package_name ) request . append ( req ) else : request = self . requested_packages ( ) [ :...
Get a patched request .
38,632
def write_to_buffer ( self , buf ) : doc = self . to_dict ( ) if config . rxt_as_yaml : content = dump_yaml ( doc ) else : content = json . dumps ( doc , indent = 4 , separators = ( "," , ": " ) ) buf . write ( content )
Save the context to a buffer .
38,633
def get_current ( cls ) : filepath = os . getenv ( "REZ_RXT_FILE" ) if not filepath or not os . path . exists ( filepath ) : return None return cls . load ( filepath )
Get the context for the current env if there is one .
38,634
def load ( cls , path ) : with open ( path ) as f : context = cls . read_from_buffer ( f , path ) context . set_load_path ( path ) return context
Load a resolved context from file .
38,635
def read_from_buffer ( cls , buf , identifier_str = None ) : try : return cls . _read_from_buffer ( buf , identifier_str ) except Exception as e : cls . _load_error ( e , identifier_str )
Load the context from a buffer .
38,636
def get_resolve_diff ( self , other ) : if self . package_paths != other . package_paths : from difflib import ndiff diff = ndiff ( self . package_paths , other . package_paths ) raise ResolvedContextError ( "Cannot diff resolves, package search " "paths differ:\n%s" % '\n' . join ( diff ) ) d = { } self_pkgs_ = set ( ...
Get the difference between the resolve in this context and another .
38,637
def print_resolve_diff ( self , other , heading = None ) : d = self . get_resolve_diff ( other ) if not d : return rows = [ ] if heading is True and self . load_path and other . load_path : a = os . path . basename ( self . load_path ) b = os . path . basename ( other . load_path ) heading = ( a , b ) if isinstance ( h...
Print the difference between the resolve of two contexts .
38,638
def get_dependency_graph ( self ) : from rez . vendor . pygraph . classes . digraph import digraph nodes = { } edges = set ( ) for variant in self . _resolved_packages : nodes [ variant . name ] = variant . qualified_package_name for request in variant . get_requires ( ) : if not request . conflict : edges . add ( ( va...
Generate the dependency graph .
38,639
def validate ( self ) : try : for pkg in self . resolved_packages : pkg . validate_data ( ) except RezError as e : raise ResolvedContextError ( "%s: %s" % ( e . __class__ . __name__ , str ( e ) ) )
Validate the context .
38,640
def get_environ ( self , parent_environ = None ) : interp = Python ( target_environ = { } , passive = True ) executor = self . _create_executor ( interp , parent_environ ) self . _execute ( executor ) return executor . get_output ( )
Get the environ dict resulting from interpreting this context .
38,641
def get_key ( self , key , request_only = False ) : values = { } requested_names = [ x . name for x in self . _package_requests if not x . conflict ] for pkg in self . resolved_packages : if ( not request_only ) or ( pkg . name in requested_names ) : value = getattr ( pkg , key ) if value is not None : values [ pkg . n...
Get a data key value for each resolved package .
38,642
def get_conflicting_tools ( self , request_only = False ) : from collections import defaultdict tool_sets = defaultdict ( set ) tools_dict = self . get_tools ( request_only = request_only ) for variant , tools in tools_dict . itervalues ( ) : for tool in tools : tool_sets [ tool ] . add ( variant ) conflicts = dict ( (...
Returns tools of the same name provided by more than one package .
38,643
def get_shell_code ( self , shell = None , parent_environ = None , style = OutputStyle . file ) : executor = self . _create_executor ( interpreter = create_shell ( shell ) , parent_environ = parent_environ ) if self . load_path and os . path . isfile ( self . load_path ) : executor . env . REZ_RXT_FILE = self . load_pa...
Get the shell code resulting from intepreting this context .
38,644
def get_actions ( self , parent_environ = None ) : interp = Python ( target_environ = { } , passive = True ) executor = self . _create_executor ( interp , parent_environ ) self . _execute ( executor ) return executor . actions
Get the list of rex . Action objects resulting from interpreting this context . This is provided mainly for testing purposes .
38,645
def apply ( self , parent_environ = None ) : interpreter = Python ( target_environ = os . environ ) executor = self . _create_executor ( interpreter , parent_environ ) self . _execute ( executor ) interpreter . apply_environ ( )
Apply the context to the current python session .
38,646
def which ( self , cmd , parent_environ = None , fallback = False ) : env = self . get_environ ( parent_environ = parent_environ ) path = which ( cmd , env = env ) if fallback and path is None : path = which ( cmd ) return path
Find a program in the resolved environment .
38,647
def execute_command ( self , args , parent_environ = None , ** subprocess_kwargs ) : if parent_environ in ( None , os . environ ) : target_environ = { } else : target_environ = parent_environ . copy ( ) interpreter = Python ( target_environ = target_environ ) executor = self . _create_executor ( interpreter , parent_en...
Run a command within a resolved context .
38,648
def execute_rex_code ( self , code , filename = None , shell = None , parent_environ = None , ** Popen_args ) : def _actions_callback ( executor ) : executor . execute_code ( code , filename = filename ) return self . execute_shell ( shell = shell , parent_environ = parent_environ , command = '' , block = False , actio...
Run some rex code in the context .
38,649
def execute_shell ( self , shell = None , parent_environ = None , rcfile = None , norc = False , stdin = False , command = None , quiet = False , block = None , actions_callback = None , post_actions_callback = None , context_filepath = None , start_new_session = False , detached = False , pre_command = None , ** Popen...
Spawn a possibly - interactive shell .
38,650
def to_dict ( self , fields = None ) : data = { } def _add ( field ) : return ( fields is None or field in fields ) if _add ( "resolved_packages" ) : resolved_packages = [ ] for pkg in ( self . _resolved_packages or [ ] ) : resolved_packages . append ( pkg . handle . to_dict ( ) ) data [ "resolved_packages" ] = resolve...
Convert context to dict containing only builtin types .
38,651
def add_sys_paths ( paths ) : original_syspath = sys . path [ : ] sys . path . extend ( paths ) try : yield finally : sys . path = original_syspath
Add to sys . path and revert on scope exit .
38,652
def popen ( args , ** kwargs ) : if "stdin" not in kwargs : try : file_no = sys . stdin . fileno ( ) except AttributeError : file_no = sys . __stdin__ . fileno ( ) if file_no not in ( 0 , 1 , 2 ) : kwargs [ "stdin" ] = subprocess . PIPE return subprocess . Popen ( args , ** kwargs )
Wrapper for subprocess . Popen .
38,653
def get_relative_to_remote ( self ) : s = self . git ( "status" , "--short" , "-b" ) [ 0 ] r = re . compile ( "\[([^\]]+)\]" ) toks = r . findall ( s ) if toks : try : s2 = toks [ - 1 ] adj , n = s2 . split ( ) assert ( adj in ( "ahead" , "behind" ) ) n = int ( n ) return - n if adj == "behind" else n except Exception ...
Return the number of commits we are relative to the remote . Negative is behind positive in front zero means we are matched to remote .
38,654
def links ( self , obj ) : if obj in self . edge_links : return self . edge_links [ obj ] else : return self . node_links [ obj ]
Return all nodes connected by the given hyperedge or all hyperedges connected to the given hypernode .
38,655
def neighbors ( self , obj ) : neighbors = set ( [ ] ) for e in self . node_links [ obj ] : neighbors . update ( set ( self . edge_links [ e ] ) ) return list ( neighbors - set ( [ obj ] ) )
Return all neighbors adjacent to the given node .
38,656
def del_node ( self , node ) : if self . has_node ( node ) : for e in self . node_links [ node ] : self . edge_links [ e ] . remove ( node ) self . node_links . pop ( node ) self . graph . del_node ( ( node , 'n' ) )
Delete a given node from the hypergraph .
38,657
def add_hyperedge ( self , hyperedge ) : if ( not hyperedge in self . edge_links ) : self . edge_links [ hyperedge ] = [ ] self . graph . add_node ( ( hyperedge , 'h' ) )
Add given hyperedge to the hypergraph .
38,658
def del_hyperedge ( self , hyperedge ) : if ( hyperedge in self . hyperedges ( ) ) : for n in self . edge_links [ hyperedge ] : self . node_links [ n ] . remove ( hyperedge ) del ( self . edge_links [ hyperedge ] ) self . del_edge_labeling ( hyperedge ) self . graph . del_node ( ( hyperedge , 'h' ) )
Delete the given hyperedge .
38,659
def link ( self , node , hyperedge ) : if ( hyperedge not in self . node_links [ node ] ) : self . edge_links [ hyperedge ] . append ( node ) self . node_links [ node ] . append ( hyperedge ) self . graph . add_edge ( ( ( node , 'n' ) , ( hyperedge , 'h' ) ) ) else : raise AdditionError ( "Link (%s, %s) already in grap...
Link given node and hyperedge .
38,660
def unlink ( self , node , hyperedge ) : self . node_links [ node ] . remove ( hyperedge ) self . edge_links [ hyperedge ] . remove ( node ) self . graph . del_edge ( ( ( node , 'n' ) , ( hyperedge , 'h' ) ) )
Unlink given node and hyperedge .
38,661
def rank ( self ) : max_rank = 0 for each in self . hyperedges ( ) : if len ( self . edge_links [ each ] ) > max_rank : max_rank = len ( self . edge_links [ each ] ) return max_rank
Return the rank of the given hypergraph .
38,662
def get_next_base26 ( prev = None ) : if not prev : return 'a' r = re . compile ( "^[a-z]*$" ) if not r . match ( prev ) : raise ValueError ( "Invalid base26" ) if not prev . endswith ( 'z' ) : return prev [ : - 1 ] + chr ( ord ( prev [ - 1 ] ) + 1 ) return get_next_base26 ( prev [ : - 1 ] ) + 'a'
Increment letter - based IDs .
38,663
def create_unique_base26_symlink ( path , source ) : retries = 0 while True : name = find_matching_symlink ( path , source ) if name : return os . path . join ( path , name ) names = [ x for x in os . listdir ( path ) if os . path . islink ( os . path . join ( path , x ) ) ] if names : prev = max ( names ) else : prev ...
Create a base - 26 symlink in path pointing to source .
38,664
def find_wheels ( projects , search_dirs ) : wheels = [ ] for project in projects : for dirname in search_dirs : files = glob . glob ( os . path . join ( dirname , project + '-*.whl' ) ) if files : wheels . append ( os . path . abspath ( files [ 0 ] ) ) break else : logger . fatal ( 'Cannot find a wheel for %s' % ( pro...
Find wheels from which we can import PROJECTS .
38,665
def relative_script ( lines ) : "Return a script that'll work in a relocatable environment." activate = "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)); del os, activat...
Return a script that ll work in a relocatable environment .
38,666
def fixup_pth_and_egg_link ( home_dir , sys_path = None ) : home_dir = os . path . normcase ( os . path . abspath ( home_dir ) ) if sys_path is None : sys_path = sys . path for path in sys_path : if not path : path = '.' if not os . path . isdir ( path ) : continue path = os . path . normcase ( os . path . abspath ( pa...
Makes . pth and . egg - link files use relative paths
38,667
def make_relative_path ( source , dest , dest_is_directory = True ) : source = os . path . dirname ( source ) if not dest_is_directory : dest_filename = os . path . basename ( dest ) dest = os . path . dirname ( dest ) dest = os . path . normpath ( os . path . abspath ( dest ) ) source = os . path . normpath ( os . pat...
Make a filename relative where the filename is dest and it is being referred to from the filename source .
38,668
def create_bootstrap_script ( extra_text , python_version = '' ) : filename = __file__ if filename . endswith ( '.pyc' ) : filename = filename [ : - 1 ] f = codecs . open ( filename , 'r' , encoding = 'utf-8' ) content = f . read ( ) f . close ( ) py_exe = 'python%s' % python_version content = ( ( '#!/usr/bin/env %s\n'...
Creates a bootstrap script which is like this script but with extend_parser adjust_options and after_install hooks .
38,669
def read_data ( file , endian , num = 1 ) : res = struct . unpack ( endian + 'L' * num , file . read ( num * 4 ) ) if len ( res ) == 1 : return res [ 0 ] return res
Read a given number of 32 - bits unsigned integers from the given file with the given endianness .
38,670
def _stdout_level ( self ) : for level , consumer in self . consumers : if consumer is sys . stdout : return level return self . FATAL
Returns the level that stdout runs at
38,671
def get_config_section ( self , name ) : if self . config . has_section ( name ) : return self . config . items ( name ) return [ ]
Get a section of a configuration
38,672
def get_environ_vars ( self , prefix = 'VIRTUALENV_' ) : for key , val in os . environ . items ( ) : if key . startswith ( prefix ) : yield ( key . replace ( prefix , '' ) . lower ( ) , val )
Returns a generator with all environmental vars with prefix VIRTUALENV
38,673
def copy ( self , overrides = None , locked = False ) : other = copy . copy ( self ) if overrides is not None : other . overrides = overrides other . locked = locked other . _uncache ( ) return other
Create a separate copy of this config .
38,674
def override ( self , key , value ) : keys = key . split ( '.' ) if len ( keys ) > 1 : if keys [ 0 ] != "plugins" : raise AttributeError ( "no such setting: %r" % key ) self . plugins . override ( keys [ 1 : ] , value ) else : self . overrides [ key ] = value self . _uncache ( key )
Set a setting to the given value .
38,675
def remove_override ( self , key ) : keys = key . split ( '.' ) if len ( keys ) > 1 : raise NotImplementedError elif key in self . overrides : del self . overrides [ key ] self . _uncache ( key )
Remove a setting override if one exists .
38,676
def warn ( self , key ) : return ( not self . quiet and not self . warn_none and ( self . warn_all or getattr ( self , "warn_%s" % key ) ) )
Returns True if the warning setting is enabled .
38,677
def debug ( self , key ) : return ( not self . quiet and not self . debug_none and ( self . debug_all or getattr ( self , "debug_%s" % key ) ) )
Returns True if the debug setting is enabled .
38,678
def data ( self ) : d = { } for key in self . _data : if key == "plugins" : d [ key ] = self . plugins . data ( ) else : try : d [ key ] = getattr ( self , key ) except AttributeError : pass return d
Returns the entire configuration as a dict .
38,679
def nonlocal_packages_path ( self ) : paths = self . packages_path [ : ] if self . local_packages_path in paths : paths . remove ( self . local_packages_path ) return paths
Returns package search paths with local path removed .
38,680
def _swap ( self , other ) : self . __dict__ , other . __dict__ = other . __dict__ , self . __dict__
Swap this config with another .
38,681
def _create_main_config ( cls , overrides = None ) : filepaths = [ ] filepaths . append ( get_module_root_config ( ) ) filepath = os . getenv ( "REZ_CONFIG_FILE" ) if filepath : filepaths . extend ( filepath . split ( os . pathsep ) ) filepath = os . path . expanduser ( "~/.rezconfig" ) filepaths . append ( filepath ) ...
See comment block at top of rezconfig describing how the main config is assembled .
38,682
def platform_mapped ( func ) : def inner ( * args , ** kwargs ) : from rez . config import config result = func ( * args , ** kwargs ) entry = config . platform_map . get ( func . __name__ ) if entry : for key , value in entry . iteritems ( ) : result , changes = re . subn ( key , value , result ) if changes > 0 : brea...
Decorates functions for lookups within a config . platform_map dictionary .
38,683
def pagerank ( graph , damping_factor = 0.85 , max_iterations = 100 , min_delta = 0.00001 ) : nodes = graph . nodes ( ) graph_size = len ( nodes ) if graph_size == 0 : return { } min_value = ( 1.0 - damping_factor ) / graph_size pagerank = dict . fromkeys ( nodes , 1.0 / graph_size ) for i in range ( max_iterations ) :...
Compute and return the PageRank in an directed graph .
38,684
def exec_command ( attr , cmd ) : import subprocess p = popen ( cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) out , err = p . communicate ( ) if p . returncode : from rez . exceptions import InvalidPackageError raise InvalidPackageError ( "Error determining package attribute '%s':\n%s" % ( attr , err ...
Runs a subproc to calculate a package attribute .
38,685
def exec_python ( attr , src , executable = "python" ) : import subprocess if isinstance ( src , basestring ) : src = [ src ] p = popen ( [ executable , "-c" , "; " . join ( src ) ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) out , err = p . communicate ( ) if p . returncode : from rez . exceptions impo...
Runs a python subproc to calculate a package attribute .
38,686
def find_site_python ( module_name , paths = None ) : from rez . packages_ import iter_packages import subprocess import ast import os py_cmd = 'import {x}; print {x}.__path__' . format ( x = module_name ) p = popen ( [ "python" , "-c" , py_cmd ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) out , err = p...
Find the rez native python package that contains the given module .
38,687
def _intersection ( A , B ) : intersection = [ ] for i in A : if i in B : intersection . append ( i ) return intersection
A simple function to find an intersection between two arrays .
38,688
def critical_path ( graph ) : if not len ( find_cycle ( graph ) ) == 0 : return [ ] node_tuples = { } topological_nodes = topological_sorting ( graph ) for node in topological_nodes : node_tuples . update ( { node : ( None , 0 ) } ) for node in topological_nodes : predecessors = [ ] for pre in graph . incidents ( node ...
Compute and return the critical path in an acyclic directed weighted graph .
38,689
def build ( self , context , variant , build_path , install_path , install = False , build_type = BuildType . local ) : ret = { } if self . write_build_scripts : build_env_script = os . path . join ( build_path , "build-env" ) create_forwarding_script ( build_env_script , module = ( "build_system" , "custom" ) , func_n...
Perform the build .
38,690
def _create_tag_highlevel ( self , tag_name , message = None ) : results = [ ] if self . patch_path : tagged = self . _create_tag_lowlevel ( tag_name , message = message , patch = True ) if tagged : results . append ( { 'type' : 'tag' , 'patch' : True } ) self . hg ( 'bookmark' , '-f' , tag_name ) results . append ( { ...
Create a tag on the toplevel repo if there is no patch repo or a tag on the patch repo and bookmark on the top repo if there is a patch repo
38,691
def _create_tag_lowlevel ( self , tag_name , message = None , force = True , patch = False ) : tags = self . get_tags ( patch = patch ) old_commit = tags . get ( tag_name ) if old_commit is not None : if not force : return False old_rev = old_commit [ 'rev' ] if self . is_ancestor ( old_rev , '.' , patch = patch ) : al...
Create a tag on the toplevel or patch repo
38,692
def is_ancestor ( self , commit1 , commit2 , patch = False ) : result = self . hg ( "log" , "-r" , "first(%s::%s)" % ( commit1 , commit2 ) , "--template" , "exists" , patch = patch ) return "exists" in result
Returns True if commit1 is a direct ancestor of commit2 or False otherwise .
38,693
def get_patched_request ( requires , patchlist ) : rules = { '' : ( True , True , True ) , '!' : ( False , False , False ) , '~' : ( False , False , True ) , '^' : ( True , True , True ) } requires = [ Requirement ( x ) if not isinstance ( x , Requirement ) else x for x in requires ] appended = [ ] for patch in patchli...
Apply patch args to a request .
38,694
def execute ( self , app_path , app_args , version , ** kwargs ) : multi_launchapp = self . parent extra = multi_launchapp . get_setting ( "extra" ) use_rez = False if self . check_rez ( ) : from rez . resolved_context import ResolvedContext from rez . config import config config . parent_variables = [ "PYTHONPATH" , "...
The execute functon of the hook will be called to start the required application
38,695
def check_rez ( self , strict = True ) : system = sys . platform if system == "win32" : rez_cmd = 'rez-env rez -- echo %REZ_REZ_ROOT%' else : rez_cmd = 'rez-env rez -- printenv REZ_REZ_ROOT' process = subprocess . Popen ( rez_cmd , stdout = subprocess . PIPE , shell = True ) rez_path , err = process . communicate ( ) i...
Checks to see if a Rez package is available in the current environment . If it is available add it to the system path exposing the Rez Python API
38,696
def get_last_changed_revision ( client , url ) : try : svn_entries = client . info2 ( url , pysvn . Revision ( pysvn . opt_revision_kind . head ) , recurse = False ) if not svn_entries : raise ReleaseVCSError ( "svn.info2() returned no results on url %s" % url ) return svn_entries [ 0 ] [ 1 ] . last_changed_rev except ...
util func get last revision of url
38,697
def get_svn_login ( realm , username , may_save ) : import getpass print "svn requires a password for the user %s:" % username pwd = '' while not pwd . strip ( ) : pwd = getpass . getpass ( " ) return True , username , pwd , False
provide svn with permissions .
38,698
def read ( string ) : dom = parseString ( string ) if dom . getElementsByTagName ( "graph" ) : G = graph ( ) elif dom . getElementsByTagName ( "digraph" ) : G = digraph ( ) elif dom . getElementsByTagName ( "hypergraph" ) : return read_hypergraph ( string ) else : raise InvalidGraphType for each_node in dom . getElemen...
Read a graph from a XML document and return it . Nodes and edges specified in the input will be added to the current graph .
38,699
def read_hypergraph ( string ) : hgr = hypergraph ( ) dom = parseString ( string ) for each_node in dom . getElementsByTagName ( "node" ) : hgr . add_node ( each_node . getAttribute ( 'id' ) ) for each_node in dom . getElementsByTagName ( "hyperedge" ) : hgr . add_hyperedge ( each_node . getAttribute ( 'id' ) ) dom = p...
Read a graph from a XML document . Nodes and hyperedges specified in the input will be added to the current graph .