Skip to content

Commit

Permalink
Merge pull request #588 from linsword13/run-pyupgrade
Browse files Browse the repository at this point in the history
Clean up older (3.5 and below) python syntax under /lib/ramble/ramble
  • Loading branch information
douglasjacobsen authored Jul 31, 2024
2 parents 2f2d023 + 6a2ae06 commit 1179cbe
Show file tree
Hide file tree
Showing 107 changed files with 412 additions and 514 deletions.
12 changes: 6 additions & 6 deletions lib/ramble/ramble/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _get_context_display_name(context):
)


class ApplicationBase(object, metaclass=ApplicationMeta):
class ApplicationBase(metaclass=ApplicationMeta):
name = None
_builtin_name = "builtin::{name}"
_builtin_required_key = "required"
Expand Down Expand Up @@ -346,7 +346,7 @@ def _long_print(self):
out_str.append(rucolor.nested_1(" %s:\n" % name))
for key, val in info.items():
if val:
out_str.append(" %s = %s\n" % (key, val.replace("@", "@@")))
out_str.append(" {} = {}\n".format(key, val.replace("@", "@@")))

return out_str

Expand Down Expand Up @@ -639,7 +639,7 @@ def create_experiment_chain(self, workspace):
# Build initial stack. Uses a reversal of the current instance's
# chained experiments
parent_namespace = self.expander.experiment_namespace
classes_in_stack = set([self])
classes_in_stack = {self}
chain_idx = 0
chain_stack = []
for exp in reversed(self.chained_experiments):
Expand Down Expand Up @@ -1386,7 +1386,7 @@ def populate_inventory(self, workspace, force_compute=False, require_exist=False
inventory_file = os.path.join(experiment_run_dir, self._inventory_file_name)

if os.path.exists(inventory_file) and not force_compute:
with open(inventory_file, "r") as f:
with open(inventory_file) as f:
self.hash_inventory = spack.util.spack_json.load(f)

else:
Expand Down Expand Up @@ -1593,7 +1593,7 @@ def format_context(context_match, context_format):
logger.debug(f"Skipping analysis of non-existent file: {file}")
continue

with open(file, "r") as f:
with open(file) as f:
for line in f.readlines():
logger.debug(f"Line: {line}")

Expand Down Expand Up @@ -2038,7 +2038,7 @@ def read_status(self):
)

if os.path.isfile(status_path):
with open(status_path, "r") as f:
with open(status_path) as f:
status_data = spack.util.spack_json.load(f)
self.variables[self.keywords.experiment_status] = status_data[
self.keywords.experiment_status
Expand Down
2 changes: 1 addition & 1 deletion lib/ramble/ramble/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _fetch_cache():
return ramble.fetch_strategy.FsCache(path)


class MirrorCache(object):
class MirrorCache:
def __init__(self, root):
self.root = os.path.abspath(root)

Expand Down
9 changes: 3 additions & 6 deletions lib/ramble/ramble/cmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.

from __future__ import print_function

import os
import re
Expand Down Expand Up @@ -113,7 +112,7 @@ def get_module(cmd_name):

try:
# Try to import the command from the built-in directory
module_name = "%s.%s" % (__name__, pname)
module_name = f"{__name__}.{pname}"
module = __import__(module_name, fromlist=[pname, SETUP_PARSER, DESCRIPTION], level=0)
logger.debug(f"Imported {pname} from built-in commands")
except ImportError:
Expand Down Expand Up @@ -190,17 +189,15 @@ class PythonNameError(ramble.error.RambleError):

def __init__(self, name):
self.name = name
super(PythonNameError, self).__init__("{0} is not a permissible Python name.".format(name))
super().__init__(f"{name} is not a permissible Python name.")


class CommandNameError(ramble.error.RambleError):
"""Exception class thrown for impermissible command names"""

def __init__(self, name):
self.name = name
super(CommandNameError, self).__init__(
"{0} is not a permissible Ramble command name.".format(name)
)
super().__init__(f"{name} is not a permissible Ramble command name.")


########################################
Expand Down
9 changes: 4 additions & 5 deletions lib/ramble/ramble/cmd/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.

from __future__ import print_function

import argparse
from collections import defaultdict
Expand Down Expand Up @@ -91,7 +90,7 @@ def objects_to_attributes(
if not object_names:
object_names = ramble.repository.paths[object_type].all_object_names()

app_to_users = defaultdict(lambda: set())
app_to_users = defaultdict(set)
for name in object_names:
cls = ramble.repository.paths[object_type].get_obj_class(name)
for user in getattr(cls, attr_name):
Expand All @@ -103,7 +102,7 @@ def objects_to_attributes(
def attributes_to_objects(
users=None, attr_name=default_attr, object_type=ramble.repository.default_type
):
user_to_apps = defaultdict(lambda: [])
user_to_apps = defaultdict(list)
object_names = ramble.repository.paths[object_type].all_object_names()
for name in object_names:
cls = ramble.repository.paths[object_type].get_obj_class(name)
Expand Down Expand Up @@ -163,15 +162,15 @@ def attributes(parser, args):
args.object_or_attr, attr_name=attr_name, object_type=object_type
)
for user, objects in sorted(attributes.items()):
color.cprint("@c{%s}: %s" % (user, ", ".join(sorted(objects))))
color.cprint("@c{{{}}}: {}".format(user, ", ".join(sorted(objects))))
return 0 if attributes else 1

else:
objects = objects_to_attributes(
args.object_or_attr, attr_name=attr_name, object_type=object_type
)
for app, attributes in sorted(objects.items()):
color.cprint("@c{%s}: %s" % (app, ", ".join(sorted(attributes))))
color.cprint("@c{{{}}}: {}".format(app, ", ".join(sorted(attributes))))
return 0 if objects else 1

if args.by_attribute:
Expand Down
25 changes: 12 additions & 13 deletions lib/ramble/ramble/cmd/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.

from __future__ import print_function

import argparse
import copy
Expand Down Expand Up @@ -102,15 +101,15 @@ def __init__(
rst_levels=["-", "-", "^", "~", ":", "`"],
):
out = sys.stdout if out is None else out
super(RambleArgparseRstWriter, self).__init__(prog, out, aliases, rst_levels)
super().__init__(prog, out, aliases, rst_levels)
self.documented = documented_commands

def usage(self, *args):
string = super(RambleArgparseRstWriter, self).usage(*args)
string = super().usage(*args)

cmd = self.parser.prog.replace(" ", "-")
if cmd in self.documented:
string += "\n:ref:`More documentation <cmd-{0}>`\n".format(cmd)
string += f"\n:ref:`More documentation <cmd-{cmd}>`\n"

return string

Expand Down Expand Up @@ -141,9 +140,9 @@ def body(self, positionals, optionals, subcommands):
return """
if $list_options
then
{0}
{}
else
{1}
{}
fi
""".format(
self.optionals(optionals), self.positionals(positionals)
Expand All @@ -152,16 +151,16 @@ def body(self, positionals, optionals, subcommands):
return """
if $list_options
then
{0}
{}
else
{1}
{}
fi
""".format(
self.optionals(optionals), self.subcommands(subcommands)
)
else:
return """
{0}
{}
""".format(
self.optionals(optionals)
)
Expand All @@ -177,10 +176,10 @@ def positionals(self, positionals):
return 'RAMBLE_COMREPLY=""'

def optionals(self, optionals):
return 'RAMBLE_COMPREPLY="{0}"'.format(" ".join(optionals))
return 'RAMBLE_COMPREPLY="{}"'.format(" ".join(optionals))

def subcommands(self, subcommands):
return 'RAMBLE_COMPREPLY="{0}"'.format(" ".join(subcommands))
return 'RAMBLE_COMPREPLY="{}"'.format(" ".join(subcommands))


@formatter
Expand All @@ -200,7 +199,7 @@ def rst_index(out):
dmax = max(len(section_descriptions.get(s, s)) for s in sections) + 2
cmax = max(len(c) for _, c in sections.items()) + 60

row = "%s %s\n" % ("=" * dmax, "=" * cmax)
row = "{} {}\n".format("=" * dmax, "=" * cmax)
line = "%%-%ds %%s\n" % dmax

out.write(row)
Expand All @@ -211,7 +210,7 @@ def rst_index(out):

for i, cmd in enumerate(sorted(commands)):
description = description.capitalize() if i == 0 else ""
ref = ":ref:`%s <ramble-%s>`" % (cmd, cmd)
ref = f":ref:`{cmd} <ramble-{cmd}>`"
comma = "," if i != len(commands) - 1 else ""
bar = "| " if i % 8 == 0 else " "
out.write(line % (description, bar + ref + comma))
Expand Down
1 change: 0 additions & 1 deletion lib/ramble/ramble/cmd/common/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.

from __future__ import print_function

import llnl.util.tty.color as color

Expand Down
21 changes: 7 additions & 14 deletions lib/ramble/ramble/cmd/common/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.

from __future__ import print_function
from __future__ import division

import argparse
import fnmatch
Expand All @@ -22,10 +20,7 @@
import ramble.cmd.common.arguments as arguments
from ramble.util.logger import logger

if sys.version_info > (3, 1):
from html import escape # novm
else:
from cgi import escape
from html import escape # novm


formatters = {}
Expand Down Expand Up @@ -179,7 +174,7 @@ def head(n, span_id, title, anchor=None):
out.write('<tr class="row-odd">\n' if i % 2 == 0 else '<tr class="row-even">\n')
for name in row:
out.write("<td>\n")
out.write('<a class="reference internal" href="#%s">%s</a></td>\n' % (name, name))
out.write(f'<a class="reference internal" href="#{name}">{name}</a></td>\n')
out.write("</td>\n")
out.write("</tr>\n")
out.write("</tbody>\n")
Expand All @@ -204,13 +199,11 @@ def head(n, span_id, title, anchor=None):
out.write(f'<dt>Ramble {obj_def["dir_name"]}:</dt>\n')
out.write('<dd><ul class="first last simple">\n')
out.write(
(
"<li>"
'<a class="reference external" '
f'href="{github_url(obj, object_type)}">'
f'{obj.name}/{obj_def["file_name"]}</a>' # noqa: E501
"</li>\n"
)
"<li>"
'<a class="reference external" '
f'href="{github_url(obj, object_type)}">'
f'{obj.name}/{obj_def["file_name"]}</a>' # noqa: E501
"</li>\n"
)
out.write("</ul></dd>\n")

Expand Down
4 changes: 2 additions & 2 deletions lib/ramble/ramble/cmd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def config_update(args):
if cannot_overwrite:
msg = "Detected permission issues with the following scopes:\n\n"
for scope, cfg_file in cannot_overwrite:
msg += "\t[scope={0}, cfg={1}]\n".format(scope.name, cfg_file)
msg += f"\t[scope={scope.name}, cfg={cfg_file}]\n"
msg += (
"\nEither ensure that you have sufficient permissions to "
"modify these files or do not include these scopes in the "
Expand All @@ -304,7 +304,7 @@ def config_update(args):
)
for scope in updates:
cfg_file = ramble.config.config.get_config_filename(scope.name, args.section)
msg += "\t[scope={0}, file={1}]\n".format(scope.name, cfg_file)
msg += f"\t[scope={scope.name}, file={cfg_file}]\n"
msg += (
"\nIf the configuration files are updated, versions of Ramble "
"that are older than this version may not be able to read "
Expand Down
5 changes: 2 additions & 3 deletions lib/ramble/ramble/cmd/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.

from __future__ import print_function

import os
import platform
Expand Down Expand Up @@ -52,9 +51,9 @@ def _debug_tarball_suffix():
commit = git("rev-parse", "--short", "HEAD", output=str).strip()

if symbolic == commit:
return "nobranch.%s.%s" % (commit, suffix)
return f"nobranch.{commit}.{suffix}"
else:
return "%s.%s.%s" % (symbolic, commit, suffix)
return f"{symbolic}.{commit}.{suffix}"


def report(args):
Expand Down
8 changes: 1 addition & 7 deletions lib/ramble/ramble/cmd/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# except according to those terms.

import os
import sys

import llnl.util.filesystem as fs

Expand All @@ -26,11 +25,6 @@
import ramble.pipeline
import ramble.filters

if sys.version_info >= (3, 3):
from collections.abc import Sequence # novm noqa: F401
else:
from collections import Sequence # noqa: F401


description = "(experimental) manage workspace deployments"
section = "workspaces"
Expand Down Expand Up @@ -130,7 +124,7 @@ def pull_file(src, dest):

pull_file(remote_index_path, local_index_path)

with open(local_index_path, "r") as f:
with open(local_index_path) as f:
index_data = sjson.load(f)

for file in index_data[push_cls.index_namespace]:
Expand Down
2 changes: 1 addition & 1 deletion lib/ramble/ramble/cmd/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def edit(parser, args):
blacklist = [".pyc", "~"] # blacklist binaries and backups
files = list(filter(lambda x: all(s not in x for s in blacklist), files))
if len(files) > 1:
m = "Multiple files exist with the name {0}.".format(name)
m = f"Multiple files exist with the name {name}."
m += " Please specify a suffix. Files are:\n\n"
for f in files:
m += " " + os.path.basename(f) + "\n"
Expand Down
Loading

0 comments on commit 1179cbe

Please sign in to comment.