Skip to content

Commit

Permalink
convert all % formatted strings under src/ to str.format format
Browse files Browse the repository at this point in the history
For the most part this is a straight forward conversion. The only tricky part is where %d was used on arguments that may be floats. Currently, python's float doesn't support the d format, so I had to change those locations so that the argument was coerced to an int before rendering.
  • Loading branch information
baroquebobcat committed Apr 7, 2015
1 parent 14886c5 commit ddab60e
Show file tree
Hide file tree
Showing 121 changed files with 479 additions and 480 deletions.
2 changes: 1 addition & 1 deletion src/python/pants/backend/authentication/netrc_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def _ensure_loaded(self):
if len(self._login) == 0:
raise self.NetrcError('Found no usable authentication blocks in ~/.netrc')
except NetrcParseError as e:
raise self.NetrcError('Problem parsing ~/.netrc: %s' % e)
raise self.NetrcError('Problem parsing ~/.netrc: {}'.format(e))
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def __init__(self,

def check_value_for_arg(arg, value, values):
if value and value not in values:
raise TargetDefinitionException(self, "%s may only be set to %s ('%s' not valid)" %
(arg, ', or '.join(map(repr, values)), value))
raise TargetDefinitionException(self, "{} may only be set to {} ('{}' not valid)"
.format(arg, ', or '.join(map(repr, values)), value))
return value

# TODO(pl): These should all live in payload fields
Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/backend/codegen/tasks/antlr_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def genlangs(self):

def genlang(self, lang, targets):
if lang != 'java':
raise TaskError('Unrecognized antlr gen lang: %s' % lang)
raise TaskError('Unrecognized antlr gen lang: {}'.format(lang))

# TODO: Instead of running the compiler for each target, collect the targets
# by type and invoke it twice, once for antlr3 and once for antlr4.
Expand Down Expand Up @@ -87,7 +87,7 @@ def genlang(self, lang, targets):
result = self.runjava(classpath=antlr_classpath, main=java_main,
args=args, workunit_name='antlr')
if result != 0:
raise TaskError('java %s ... exited non-zero (%i)' % (java_main, result))
raise TaskError('java {} ... exited non-zero ({})'.format(java_main, result))

# This checks to make sure that all of the sources have an identical package source structure, and
# if they do, uses that as the package. If they are different, then the user will need to set the
Expand All @@ -111,7 +111,7 @@ def collect_sources(target):

def createtarget(self, lang, gentarget, dependees):
if lang != 'java':
raise TaskError('Unrecognized antlr gen lang: %s' % lang)
raise TaskError('Unrecognized antlr gen lang: {}'.format(lang))
return self._create_java_target(gentarget, dependees)

def _create_java_target(self, target, dependees):
Expand Down
20 changes: 10 additions & 10 deletions src/python/pants/backend/codegen/tasks/apache_thrift_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

def _copytree(from_base, to_base):
def abort(error):
raise TaskError('Failed to copy from %s to %s: %s' % (from_base, to_base, error))
raise TaskError('Failed to copy from {} to {}: {}'.format(from_base, to_base, error))

# TODO(John Sirois): Consider adding a unit test and lifting this to common/dirutils or similar
def safe_link(src, dst):
Expand Down Expand Up @@ -142,7 +142,7 @@ def genlang(self, lang, targets):
elif lang == 'python':
gen = self.gen_python.gen
else:
raise TaskError('Unrecognized thrift gen lang: %s' % lang)
raise TaskError('Unrecognized thrift gen lang: {}'.format(lang))

args = [
self.thrift_binary,
Expand All @@ -159,7 +159,7 @@ def genlang(self, lang, targets):

sessions = []
for source in sources:
self.context.log.info('Generating thrift for %s\n' % source)
self.context.log.info('Generating thrift for {}\n'.format(source))
# Create a unique session dir for this thrift root. Sources may be full paths but we only
# need the path relative to the build root to ensure uniqueness.
# TODO(John Sirois): file paths should be normalized early on and uniformly, fix the need to
Expand All @@ -172,7 +172,7 @@ def genlang(self, lang, targets):
cmd = args[:]
cmd.extend(('-o', outdir))
cmd.append(relsource)
self.context.log.debug('Executing: %s' % ' '.join(cmd))
self.context.log.debug('Executing: {}'.format(' '.join(cmd)))
sessions.append(self.ThriftSession(outdir, cmd, subprocess.Popen(cmd)))

result = 0
Expand All @@ -182,19 +182,19 @@ def genlang(self, lang, targets):
else:
result = session.process.wait()
if result != 0:
self.context.log.error('Failed: %s' % ' '.join(session.cmd))
self.context.log.error('Failed: {}'.format(' '.join(session.cmd)))
else:
_copytree(session.outdir, self.combined_dir)
if result != 0:
raise TaskError('%s ... exited non-zero (%i)' % (self.thrift_binary, result))
raise TaskError('{} ... exited non-zero ({})'.format(self.thrift_binary, result))

def createtarget(self, lang, gentarget, dependees):
if lang == 'java':
return self._create_java_target(gentarget, dependees)
elif lang == 'python':
return self._create_python_target(gentarget, dependees)
else:
raise TaskError('Unrecognized thrift gen lang: %s' % lang)
raise TaskError('Unrecognized thrift gen lang: {}'.format(lang))

def _create_java_target(self, target, dependees):
def create_target(files, deps):
Expand Down Expand Up @@ -280,21 +280,21 @@ def calculate_gen(source):
def calculate_python_genfiles(namespace, types):
basepath = namespace.replace('.', '/')
def path(name):
return os.path.join(basepath, '%s.py' % name)
return os.path.join(basepath, '{}.py'.format(name))
yield path('__init__')
if 'const' in types:
yield path('constants')
if 'const' in types or set(['enum', 'exception', 'struct', 'union']) & set(types.keys()):
yield path('ttypes')
for service in types['service']:
yield path(service)
yield os.path.join(basepath, '%s-remote' % service)
yield os.path.join(basepath, '{}-remote'.format(service))


def calculate_java_genfiles(namespace, types):
basepath = namespace.replace('.', '/')
def path(name):
return os.path.join(basepath, '%s.java' % name)
return os.path.join(basepath, '{}.java'.format(name))
if 'const' in types:
yield path('Constants')
for typename in ['enum', 'exception', 'service', 'struct', 'union']:
Expand Down
8 changes: 4 additions & 4 deletions src/python/pants/backend/codegen/tasks/code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ def find_gentargets(predicate):
forced = True
gentargets_bylang[lang] = gentargets if self.is_forced(lang) else find_gentargets(predicate)
if not forced and gentargets_by_dependee:
self.context.log.warn('Left with unexpected unconsumed gen targets:\n\t%s' % '\n\t'.join(
'%s -> %s' % (dependee, gentargets)
for dependee, gentargets in gentargets_by_dependee.items()
))
self.context.log.warn('Left with unexpected unconsumed gen targets:\n\t{}'.format('\n\t'.join(
'{} -> {}'.format(dependee, gentargets)
for dependee, gentargets in gentargets_by_dependee.items()
)))

if gentargets:
self.prepare_gen(gentargets)
Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/backend/codegen/tasks/jaxb_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def prepare_gen(self, target):

def genlang(self, lang, targets):
if lang != 'java':
raise TaskError('Unrecognized jaxb language: %s' % lang)
raise TaskError('Unrecognized jaxb language: {}'.format(lang))
output_dir = os.path.join(self.workdir, 'gen-java')
safe_mkdir(output_dir)
cache = []
Expand Down Expand Up @@ -137,7 +137,7 @@ def _correct_package(self, package):
package = re.sub(r'^\.+', '', package)
package = re.sub(r'\.+$', '', package)
if re.search(r'\.{2,}', package) is not None:
raise ValueError('Package name cannot have consecutive periods! (%s)' % package)
raise ValueError('Package name cannot have consecutive periods! ({})'.format(package))
return package

@classmethod
Expand Down Expand Up @@ -170,4 +170,4 @@ def _sources_to_be_generated(self, package, path):

names.append('ObjectFactory')
outdir = package.replace('.', '/')
return [os.path.join(outdir, '%s.java' % name) for name in names]
return [os.path.join(outdir, '{}.java'.format(name)) for name in names]
2 changes: 1 addition & 1 deletion src/python/pants/backend/core/targets/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(self,
super(Page, self).__init__(address=address, payload=payload, **kwargs)

if provides and not isinstance(provides[0], WikiArtifact):
raise ValueError('Page must provide a wiki_artifact. Found instead: %s' % provides)
raise ValueError('Page must provide a wiki_artifact. Found instead: {}'.format(provides))

@property
def source(self):
Expand Down
8 changes: 4 additions & 4 deletions src/python/pants/backend/core/tasks/builddictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _gen_build_dictionary(self):
# generate rst
template = resource_string(__name__, os.path.join(self._templates_dir, 'page.mustache'))
filename = os.path.join(self._outdir, 'build_dictionary.rst')
self.context.log.info('Generating %s' % filename)
self.context.log.info('Generating {}'.format(filename))
with safe_open(filename, 'wb') as outfile:
generator = Generator(template,
tocs=tocs,
Expand All @@ -91,7 +91,7 @@ def _gen_build_dictionary(self):
# generate html
template = resource_string(__name__, os.path.join(self._templates_dir, 'bdict_html.mustache'))
filename = os.path.join(self._outdir, 'build_dictionary.html')
self.context.log.info('Generating %s' % filename)
self.context.log.info('Generating {}'.format(filename))
with safe_open(filename, 'wb') as outfile:
generator = Generator(template,
tocs=tocs,
Expand All @@ -113,7 +113,7 @@ def _gen_options_reference(self):
template = resource_string(__name__,
os.path.join(self._templates_dir, 'options_reference.mustache'))
filename = os.path.join(self._outdir, 'options_reference.rst')
self.context.log.info('Generating %s' % filename)
self.context.log.info('Generating {}'.format(filename))
with safe_open(filename, 'wb') as outfile:
generator = Generator(template, goals=filtered_goals, glopts=glopts)
generator.write(outfile)
Expand All @@ -122,7 +122,7 @@ def _gen_options_reference(self):
template = resource_string(__name__,
os.path.join(self._templates_dir, 'oref_html.mustache'))
filename = os.path.join(self._outdir, 'options_reference.html')
self.context.log.info('Generating %s' % filename)
self.context.log.info('Generating {}'.format(filename))
with safe_open(filename, 'wb') as outfile:
generator = Generator(template, goals=filtered_goals, glopts=glopts)
generator.write(outfile)
2 changes: 1 addition & 1 deletion src/python/pants/backend/core/tasks/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _cautious_rmtree(root):
real_buildroot = os.path.realpath(os.path.abspath(get_buildroot()))
real_root = os.path.realpath(os.path.abspath(root))
if not real_root.startswith(real_buildroot):
raise TaskError('DANGER: Attempting to delete %s, which is not under the build root!')
raise TaskError('DANGER: Attempting to delete {}, which is not under the build root!'.format(real_root))
safe_rmtree(real_root)


Expand Down
18 changes: 9 additions & 9 deletions src/python/pants/backend/core/tasks/confluence_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def execute(self):
for page, wiki_artifact in pages:
html_info = genmap.get((wiki_artifact, page))
if len(html_info) > 1:
raise TaskError('Unexpected resources for %s: %s' % (page, html_info))
raise TaskError('Unexpected resources for {}: {}'.format(page, html_info))
basedir, htmls = html_info.items()[0]
if len(htmls) != 1:
raise TaskError('Unexpected resources for %s: %s' % (page, htmls))
raise TaskError('Unexpected resources for {}: {}'.format(page, htmls))
with safe_open(os.path.join(basedir, htmls[0])) as contents:
url = self.publish_page(
page.address,
Expand All @@ -85,18 +85,18 @@ def execute(self):
)
if url:
urls.append(url)
self.context.log.info('Published %s to %s' % (page, url))
self.context.log.info('Published {} to {}'.format(page, url))

if self.open and urls:
binary_util.ui_open(*urls)

def publish_page(self, address, space, title, content, parent=None):
body = textwrap.dedent('''
<!-- DO NOT EDIT - generated by pants from %s -->
<!-- DO NOT EDIT - generated by pants from {} -->
%s
''').strip() % (address, content)
{}
''').strip().format(address, content)

pageopts = dict(
versionComment = 'updated by pants!'
Expand All @@ -105,7 +105,7 @@ def publish_page(self, address, space, title, content, parent=None):
existing = wiki.getpage(space, title)
if existing:
if not self.force and existing['content'].strip() == body.strip():
self.context.log.warn("Skipping publish of '%s' - no changes" % title)
self.context.log.warn("Skipping publish of '{}' - no changes".format(title))
return

pageopts['id'] = existing['id']
Expand All @@ -115,12 +115,12 @@ def publish_page(self, address, space, title, content, parent=None):
page = wiki.create_html_page(space, title, body, parent, **pageopts)
return page['url']
except ConfluenceError as e:
raise TaskError('Failed to update confluence: %s' % e)
raise TaskError('Failed to update confluence: {}'.format(e))

def login(self):
if not self._wiki:
try:
self._wiki = Confluence.login(self.url, self.user, self.api())
except ConfluenceError as e:
raise TaskError('Failed to login to confluence: %s' % e)
raise TaskError('Failed to login to confluence: {}'.format(e))
return self._wiki
6 changes: 3 additions & 3 deletions src/python/pants/backend/core/tasks/dependees.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def console_output(self, _):
for dependees_type in self._dependees_type:
target_aliases = self.context.build_file_parser.registered_aliases().targets
if dependees_type not in target_aliases:
raise TaskError('Invalid type name: %s' % dependees_type)
raise TaskError('Invalid type name: {}'.format(dependees_type))
target_type = target_aliases[dependees_type]
# Try to find the SourceRoot for the given input type
try:
Expand All @@ -59,9 +59,9 @@ def console_output(self, _):
pass

if not base_paths:
raise TaskError('No SourceRoot set for any target type in %s.' % self._dependees_type +
raise TaskError('No SourceRoot set for any target type in {}.'.format(self._dependees_type) +
'\nPlease define a source root in BUILD file as:' +
'\n\tsource_root(\'<src-folder>\', %s)' % ', '.join(self._dependees_type))
'\n\tsource_root(\'<src-folder>\', {})'.format(', '.join(self._dependees_type)))
for base_path in base_paths:
buildfiles.update(BuildFile.scan_buildfiles(get_buildroot(),
os.path.join(get_buildroot(), base_path),
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/core/tasks/filemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def console_output(self, _):
if target not in visited:
visited.add(target)
for rel_source in target.sources_relative_to_buildroot():
yield '%s %s' % (rel_source, target.address.spec)
yield '{} {}'.format(rel_source, target.address.spec)

def _find_targets(self):
if len(self.context.target_roots) > 0:
Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/backend/core/tasks/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ def filter_for_type(name):
try:
# Try to do a fully qualified import 1st for filtering on custom types.
from_list, module, type_name = name.rsplit('.', 2)
module = __import__('%s.%s' % (from_list, module), fromlist=[from_list])
module = __import__('{}.{}'.format(from_list, module), fromlist=[from_list])
target_type = getattr(module, type_name)
except (ImportError, ValueError):
# Fall back on pants provided target types.
registered_aliases = self.context.build_file_parser.registered_aliases()
if name not in registered_aliases.targets:
raise TaskError('Invalid type name: %s' % name)
raise TaskError('Invalid type name: {}'.format(name))
target_type = registered_aliases.targets[name]
if not issubclass(target_type, Target):
raise TaskError('Not a Target type: %s' % name)
raise TaskError('Not a Target type: {}'.format(name))
return lambda target: isinstance(target, target_type)
self._filters.extend(_create_filters(self.get_options().type, filter_for_type))

Expand Down
12 changes: 6 additions & 6 deletions src/python/pants/backend/core/tasks/group_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ def group_name(self):
cls._GROUPS[name] = group_task

if group_task.product_types() != product_type:
raise ValueError('The group %r was already registered with product type: %r - refusing to '
'overwrite with new product type: %r' % (name, group_task.product_types(),
product_type))
raise ValueError('The group {!r} was already registered with product type: {!r} - refusing to '
'overwrite with new product type: {!r}'.format(name, group_task.product_types(),
product_type))

return group_task

Expand All @@ -271,7 +271,7 @@ def add_member(cls, group_member):
"""
if not issubclass(group_member, GroupMember):
raise ValueError('Only GroupMember subclasses can join a GroupTask, '
'given %s of type %s' % (group_member, type(group_member)))
'given {} of type {}'.format(group_member, type(group_member)))

group_member.options_scope = Goal.scope(cls.parent_options_scope, group_member.name())
cls._member_types().append(group_member)
Expand Down Expand Up @@ -306,9 +306,9 @@ def execute(self):
ordered_chunks.append((group_member, chunk))
chunks_by_member[group_member].append(chunk)

self.context.log.debug('::: created chunks(%d)' % len(ordered_chunks))
self.context.log.debug('::: created chunks({})'.format(len(ordered_chunks)))
for i, (group_member, goal_chunk) in enumerate(ordered_chunks):
self.context.log.debug(' chunk(%d) [flavor=%s]:\n\t%s' % (
self.context.log.debug(' chunk({}) [flavor={}]:\n\t{}'.format(
i, group_member.name(), '\n\t'.join(sorted(map(str, goal_chunk)))))

# prep
Expand Down
Loading

0 comments on commit ddab60e

Please sign in to comment.