def test_file_have_coding_utf8(self): """ Look through all .py files and ensure they start with the line '# coding=utf8' """ build_configuration = load_build_configuration_from_source() build_file_parser = BuildFileParser(build_configuration, get_buildroot()) def has_hand_coded_python_files(tgt): return (not tgt.is_synthetic) and tgt.is_original and tgt.has_sources('.py') nonconforming_files = [] for target in build_file_parser.scan().targets(has_hand_coded_python_files): for src in target.sources_relative_to_buildroot(): with open(os.path.join(get_buildroot(), src), 'r') as python_file: coding_line = python_file.readline() if '' == coding_line and os.path.basename(src) == '__init__.py': continue if coding_line[0:2] == '#!': # Executable file: look for the coding on the second line. coding_line = python_file.readline() if not coding_line.rstrip() == '# coding=utf-8': nonconforming_files.append(src) if len(nonconforming_files) > 0: self.fail('Expected these files to contain first line "# coding=utf8": ' + str(nonconforming_files))
def test_file_have_coding_utf8(self): """ Look through all .py files and ensure they start with the line '# coding=utf8' """ config = Config.load() backend_packages = config.getlist('backends', 'packages') build_configuration = load_build_configuration_from_source( backend_packages) build_file_parser = BuildFileParser( root_dir=get_buildroot(), build_configuration=build_configuration) address_mapper = BuildFileAddressMapper(build_file_parser) build_graph = BuildGraph(address_mapper=address_mapper) for address in address_mapper.scan_addresses( get_buildroot(), spec_excludes=[config.getdefault('pants_workdir')]): build_graph.inject_address_closure(address) def has_hand_coded_python_files(tgt): return (not tgt.is_synthetic ) and tgt.is_original and tgt.has_sources('.py') nonconforming_files = [] for target in build_graph.targets(has_hand_coded_python_files): for src in target.sources_relative_to_buildroot(): with open(os.path.join(get_buildroot(), src), 'r') as python_file: coding_line = python_file.readline() if '' == coding_line and os.path.basename( src) == '__init__.py': continue if coding_line[0:2] == '#!': # Executable file: look for the coding on the second line. coding_line = python_file.readline() if not coding_line.rstrip() == '# coding=utf-8': nonconforming_files.append(src) if len(nonconforming_files) > 0: self.fail( 'Expected these files to contain first line "# coding=utf8": ' + str(nonconforming_files))
def test_file_have_coding_utf8(self): """ Look through all .py files and ensure they start with the line '# coding=utf8' """ config = Config.load() backend_packages = config.getlist('backends', 'packages') build_configuration = load_build_configuration_from_source(backend_packages) build_file_parser = BuildFileParser(root_dir=get_buildroot(), build_configuration=build_configuration) address_mapper = BuildFileAddressMapper(build_file_parser) build_graph = BuildGraph(address_mapper=address_mapper) for address in address_mapper.scan_addresses( get_buildroot(), spec_excludes=[config.getdefault('pants_workdir')]): build_graph.inject_address_closure(address) def has_hand_coded_python_files(tgt): return (not tgt.is_synthetic) and tgt.is_original and tgt.has_sources('.py') nonconforming_files = [] for target in build_graph.targets(has_hand_coded_python_files): for src in target.sources_relative_to_buildroot(): with open(os.path.join(get_buildroot(), src), 'r') as python_file: coding_line = python_file.readline() if '' == coding_line and os.path.basename(src) == '__init__.py': continue if coding_line[0:2] == '#!': # Executable file: look for the coding on the second line. coding_line = python_file.readline() if not coding_line.rstrip() == '# coding=utf-8': nonconforming_files.append(src) if len(nonconforming_files) > 0: self.fail('Expected these files to contain first line "# coding=utf8": ' + str(nonconforming_files))
def _run(): # Place the registration of the unhandled exception hook as early as possible in the code. sys.excepthook = _unhandled_exception_hook """ To add additional paths to sys.path, add a block to the config similar to the following: [main] roots: ['src/python/pants_internal/test/',] """ logging.basicConfig() version = pants_version() if len(sys.argv) == 2 and sys.argv[1] == _VERSION_OPTION: _do_exit(msg=version, out=sys.stdout) root_dir = get_buildroot() if not os.path.exists(root_dir): _exit_and_fail('PANTS_BUILD_ROOT does not point to a valid path: %s' % root_dir) if len(sys.argv) < 2: argv = ['goal'] else: argv = sys.argv[1:] # Hack to force ./pants -h etc. to redirect to goal. if argv[0] != 'goal' and set(['-h', '--help', 'help']).intersection(argv): argv = ['goal'] + argv parser = optparse.OptionParser(add_help_option=False, version=version) RcFile.install_disable_rc_option(parser) parser.add_option(_LOG_EXIT_OPTION, action='store_true', default=False, dest='log_exit', help='Log an exit message on success or failure.') config = Config.load() # XXX(wickman) This should be in the command goal, not in pants_exe.py! run_tracker = RunTracker.from_config(config) report = initial_reporting(config, run_tracker) run_tracker.start(report) url = run_tracker.run_info.get_info('report_url') if url: run_tracker.log(Report.INFO, 'See a report at: %s' % url) else: run_tracker.log(Report.INFO, '(To run a reporting server: ./pants goal server)') backend_packages = config.getlist('backends', 'packages') build_configuration = load_build_configuration_from_source(additional_backends=backend_packages) build_file_parser = BuildFileParser(build_configuration=build_configuration, root_dir=root_dir, run_tracker=run_tracker) address_mapper = BuildFileAddressMapper(build_file_parser) build_graph = BuildGraph(run_tracker=run_tracker, address_mapper=address_mapper) command_class, command_args = _parse_command(root_dir, argv) command = command_class(run_tracker, root_dir, parser, command_args, build_file_parser, address_mapper, build_graph) try: if command.serialized(): def onwait(pid): process = psutil.Process(pid) print('Waiting on pants process %d (%s) to complete' % (pid, ' '.join(process.cmdline)), file=sys.stderr) return True runfile = os.path.join(root_dir, '.pants.run') lock = Lock.acquire(runfile, onwait=onwait) else: lock = Lock.unlocked() try: result = command.run(lock) if result: run_tracker.set_root_outcome(WorkUnit.FAILURE) _do_exit(result) except KeyboardInterrupt: command.cleanup() raise except Exception: run_tracker.set_root_outcome(WorkUnit.FAILURE) raise finally: lock.release() finally: run_tracker.end() # Must kill nailguns only after run_tracker.end() is called, because there may still # be pending background work that needs a nailgun. if (hasattr(command.old_options, 'cleanup_nailguns') and command.old_options.cleanup_nailguns) \ or config.get('nailgun', 'autokill', default=False): NailgunTask.killall(None)
def alias_groups(self): return load_build_configuration_from_source().registered_aliases()
def _run(): # place the registration of the unhandled exception hook # as early as possible in the code sys.excepthook = _unhandled_exception_hook """ To add additional paths to sys.path, add a block to the config similar to the following: [main] roots: ['src/python/pants_internal/test/',] """ logging.basicConfig() version = pants_version() if len(sys.argv) == 2 and sys.argv[1] == _VERSION_OPTION: _do_exit(msg=version, out=sys.stdout) root_dir = get_buildroot() if not os.path.exists(root_dir): _exit_and_fail('PANTS_BUILD_ROOT does not point to a valid path: %s' % root_dir) if len(sys.argv) < 2: argv = ['goal'] else: argv = sys.argv[1:] # Hack to force ./pants -h etc. to redirect to goal. if argv[0] != 'goal' and set(['-h', '--help', 'help']).intersection(argv): argv = ['goal'] + argv parser = optparse.OptionParser(add_help_option=False, version=version) RcFile.install_disable_rc_option(parser) parser.add_option(_LOG_EXIT_OPTION, action='store_true', default=False, dest='log_exit', help='Log an exit message on success or failure.') config = Config.load() # XXX(wickman) This should be in the command goal, not in pants_exe.py! run_tracker = RunTracker.from_config(config) report = initial_reporting(config, run_tracker) run_tracker.start(report) url = run_tracker.run_info.get_info('report_url') if url: run_tracker.log(Report.INFO, 'See a report at: %s' % url) else: run_tracker.log(Report.INFO, '(To run a reporting server: ./pants goal server)') backend_packages = config.getlist('backends', 'packages') build_configuration = load_build_configuration_from_source( additional_backends=backend_packages) build_file_parser = BuildFileParser( build_configuration=build_configuration, root_dir=root_dir, run_tracker=run_tracker) address_mapper = BuildFileAddressMapper(build_file_parser) build_graph = BuildGraph(run_tracker=run_tracker, address_mapper=address_mapper) command_class, command_args = _parse_command(root_dir, argv) command = command_class(run_tracker, root_dir, parser, command_args, build_file_parser, address_mapper, build_graph) try: if command.serialized(): def onwait(pid): process = psutil.Process(pid) print('Waiting on pants process %d (%s) to complete' % (pid, ' '.join(process.cmdline)), file=sys.stderr) return True runfile = os.path.join(root_dir, '.pants.run') lock = Lock.acquire(runfile, onwait=onwait) else: lock = Lock.unlocked() try: result = command.run(lock) if result: run_tracker.set_root_outcome(WorkUnit.FAILURE) _do_exit(result) except KeyboardInterrupt: command.cleanup() raise finally: lock.release() finally: run_tracker.end() # Must kill nailguns only after run_tracker.end() is called, because there may still # be pending background work that needs a nailgun. if (hasattr(command.options, 'cleanup_nailguns') and command.options.cleanup_nailguns) \ or config.get('nailgun', 'autokill', default=False): NailgunTask.killall(None)