<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import ConfigParser <EOL> import copy <EOL> import os <EOL> import subprocess <EOL> import sys <EOL> IGNORED_DIRECTORIES = [ <EOL> os . path . join ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . join ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> IGNORED_FILES = [ <EOL> os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' , <EOL> ] <EOL> SCRIPTS_DIR = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> PRODUCTION_RC = os . path . join ( SCRIPTS_DIR , '<STR_LIT>' ) <EOL> TEST_RC = os . path . join ( SCRIPTS_DIR , '<STR_LIT>' ) <EOL> TEST_DISABLED_MESSAGES = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> TEST_RC_ADDITIONS = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT:U+002CU+0020>' . join ( TEST_DISABLED_MESSAGES ) , <EOL> } , <EOL> } <EOL> TEST_RC_REPLACEMENTS = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } , <EOL> } <EOL> def read_config ( filename ) : <EOL> """<STR_LIT>""" <EOL> config = ConfigParser . ConfigParser ( ) <EOL> with open ( filename , '<STR_LIT:r>' ) as file_obj : <EOL> config . readfp ( file_obj ) <EOL> return config <EOL> def make_test_rc ( base_rc_filename , additions_dict , <EOL> replacements_dict , target_filename ) : <EOL> """<STR_LIT>""" <EOL> main_cfg = read_config ( base_rc_filename ) <EOL> test_cfg = ConfigParser . ConfigParser ( ) <EOL> test_cfg . _sections = copy . deepcopy ( main_cfg . _sections ) <EOL> for section , opts in additions_dict . items ( ) : <EOL> curr_section = test_cfg . _sections . setdefault ( <EOL> section , test_cfg . _dict ( ) ) <EOL> for opt , opt_val in opts . items ( ) : <EOL> curr_val = curr_section . get ( opt ) <EOL> if curr_val is None : <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> curr_val = curr_val . rstrip ( '<STR_LIT:U+002C>' ) <EOL> curr_section [ opt ] = '<STR_LIT>' % ( curr_val , opt_val ) <EOL> for section , opts in replacements_dict . items ( ) : <EOL> curr_section = test_cfg . _sections . setdefault ( <EOL> section , test_cfg . _dict ( ) ) <EOL> for opt , opt_val in opts . items ( ) : <EOL> curr_val = curr_section . get ( opt ) <EOL> if curr_val is None : <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> curr_section [ opt ] = '<STR_LIT:%s>' % ( opt_val , ) <EOL> with open ( target_filename , '<STR_LIT:w>' ) as file_obj : <EOL> test_cfg . write ( file_obj ) <EOL> def valid_filename ( filename ) : <EOL> """<STR_LIT>""" <EOL> for directory in IGNORED_DIRECTORIES : <EOL> if filename . startswith ( directory ) : <EOL> return False <EOL> return ( filename . endswith ( '<STR_LIT>' ) and <EOL> filename not in IGNORED_FILES ) <EOL> def is_production_filename ( filename ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:test>' not in filename and '<STR_LIT>' not in filename <EOL> def get_files_for_linting ( allow_limited = True ) : <EOL> """<STR_LIT>""" <EOL> diff_base = None <EOL> if ( os . getenv ( '<STR_LIT>' ) == '<STR_LIT>' and <EOL> os . getenv ( '<STR_LIT>' ) != '<STR_LIT:false>' ) : <EOL> diff_base = '<STR_LIT>' <EOL> elif os . getenv ( '<STR_LIT>' ) is None : <EOL> remote = os . getenv ( '<STR_LIT>' ) <EOL> branch = os . getenv ( '<STR_LIT>' ) <EOL> if remote is not None and branch is not None : <EOL> diff_base = '<STR_LIT>' % ( remote , branch ) <EOL> if diff_base is not None and allow_limited : <EOL> result = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> diff_base ] ) <EOL> print ( '<STR_LIT>' % ( diff_base , ) ) <EOL> print ( '<STR_LIT:->' * <NUM_LIT> ) <EOL> print ( result . rstrip ( '<STR_LIT:\n>' ) ) <EOL> print ( '<STR_LIT:->' * <NUM_LIT> ) <EOL> else : <EOL> print ( '<STR_LIT>' ) <EOL> result = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> return result . rstrip ( '<STR_LIT:\n>' ) . split ( '<STR_LIT:\n>' ) , diff_base <EOL> def get_python_files ( all_files = None ) : <EOL> """<STR_LIT>""" <EOL> using_restricted = False <EOL> if all_files is None : <EOL> all_files , diff_base = get_files_for_linting ( ) <EOL> using_restricted = diff_base is not None <EOL> library_files = [ ] <EOL> non_library_files = [ ] <EOL> for filename in all_files : <EOL> if valid_filename ( filename ) : <EOL> if is_production_filename ( filename ) : <EOL> library_files . append ( filename ) <EOL> else : <EOL> non_library_files . append ( filename ) <EOL> return library_files , non_library_files , using_restricted <EOL> def lint_fileset ( filenames , rcfile , description ) : <EOL> """<STR_LIT>""" <EOL> filenames = [ filename for filename in filenames <EOL> if os . path . exists ( filename ) ] <EOL> if filenames : <EOL> rc_flag = '<STR_LIT>' % ( rcfile , ) <EOL> pylint_shell_command = [ '<STR_LIT>' , rc_flag ] + filenames <EOL> status_code = subprocess . call ( pylint_shell_command ) <EOL> if status_code != <NUM_LIT:0> : <EOL> error_message = ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( description , status_code ) ) <EOL> print ( error_message , file = sys . stderr ) <EOL> sys . exit ( status_code ) <EOL> else : <EOL> print ( '<STR_LIT>' % ( description , ) ) <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> make_test_rc ( PRODUCTION_RC , TEST_RC_ADDITIONS , <EOL> TEST_RC_REPLACEMENTS , TEST_RC ) <EOL> library_files , non_library_files , using_restricted = get_python_files ( ) <EOL> try : <EOL> lint_fileset ( library_files , PRODUCTION_RC , '<STR_LIT>' ) <EOL> lint_fileset ( non_library_files , TEST_RC , '<STR_LIT>' ) <EOL> except SystemExit : <EOL> if not using_restricted : <EOL> raise <EOL> message = '<STR_LIT>' <EOL> print ( message , file = sys . stderr ) <EOL> all_files , _ = get_files_for_linting ( allow_limited = False ) <EOL> library_files , non_library_files , _ = get_python_files ( <EOL> all_files = all_files ) <EOL> lint_fileset ( library_files , PRODUCTION_RC , '<STR_LIT>' ) <EOL> lint_fileset ( non_library_files , TEST_RC , '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
