Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ruff/pyupgrade issues #361

Open
wants to merge 2 commits into
base: 3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions capsul/in_context/freesurfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def freesurfer_command_with_environment(
cmd = [
shell,
"-c",
'setenv FREESURFER_HOME "{0}"; source {1}; exec {2} '.format(
freesurfer_dir, freesurfer_script, command[0]
)
f'setenv FREESURFER_HOME "{freesurfer_dir}"; source {freesurfer_script}; exec {command[0]} '
+ " ".join("'%s'" % i.replace("'", "\\'") for i in command[1:]),
]

Expand All @@ -88,9 +86,7 @@ def freesurfer_command_with_environment(
cmd = [
shell,
"-c",
'export FREESURFER_HOME="{0}"; source {1}; exec {2} '.format(
freesurfer_dir, freesurfer_script, command[0]
)
f'export FREESURFER_HOME="{freesurfer_dir}"; source {freesurfer_script}; exec {command[0]} '
+ " ".join("'%s'" % i.replace("'", "\\'") for i in command[1:]),
]

Expand Down
4 changes: 2 additions & 2 deletions capsul/pipeline/test/test_complex_pipeline_activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,14 +862,14 @@ def test_complex_activations(self):
f"Pipeline {node_pipeline.pipeline} has no node named {node_name}"
) from e
try:
what = "activation of node {0}".format(
what = "activation of node {}".format(
full_node_name or "main pipeline node"
)
expected = node_activations.get("_activated")
if expected is not None:
got = node.activated
self.assertEqual(expected, got)
what = "enabled for node {0}".format(
what = "enabled for node {}".format(
full_node_name or "main pipeline node"
)
expected = node_activations.get("_enabled")
Expand Down
34 changes: 21 additions & 13 deletions capsul/process/nipype_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import logging
import os
import sys
import textwrap
import types

import soma.controller as sc
Expand Down Expand Up @@ -207,11 +208,12 @@ def sync_process_output_traits(process_instance):
traceback.print_exc()
ex_type, ex, tb = sys.exc_info()
logging.debug(
"Something wrong in the nipype output trait "
"synchronization:\n\n\tError: {0} - {1}\n"
"\tTraceback:\n{2}".format(
ex_type, ex, "".join(traceback.format_tb(tb))
)
textwrap.dedent(f"""\
Something wrong in the nipype output trait synchronization:

\tError: {ex_type} - {ex}
\tTraceback:
{''.join(traceback.format_tb(tb))}""")
)
nipype_outputs = {}

Expand Down Expand Up @@ -247,10 +249,13 @@ def sync_process_output_traits(process_instance):
traceback.print_exc()
ex_type, ex, tb = sys.exc_info()
logging.debug(
"Something wrong in the nipype output trait "
"synchronization:\n\n\tError: {0} - {1}\n"
"\tTraceback:\n{2}".format(
ex_type, ex, "".join(traceback.format_tb(tb))
textwrap.dedent(
f"""\
Something wrong in the nipype output trait synchronization:

\tError: {ex_type} - {ex}
\tTraceback:
{''.join(traceback.format_tb(tb))}"""
)
)

Expand Down Expand Up @@ -278,10 +283,13 @@ def sync_process_output_traits(process_instance):
traceback.print_exc()
ex_type, ex, tb = sys.exc_info()
logging.debug(
"Something wrong in the nipype output trait "
"synchronization:\n\n\tError: {0} - {1}\n"
"\tTraceback:\n{2}".format(
ex_type, ex, "".join(traceback.format_tb(tb))
textwrap.dedent(
f"""\
Something wrong in the nipype output trait synchronization:

\tError: {ex_type} - {ex}
\tTraceback:
{"".join(traceback.format_tb(tb))}"""
)
)

Expand Down
7 changes: 2 additions & 5 deletions capsul/process/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ def __init__(
# as specified in the docstring
if "name" not in parameter:
raise Exception(
"Can't create parameter with unknown"
"identifier and parameter {0}".format(parameter)
f"Can't create parameter with unknown identifier and parameter {parameter}"
)
parameter = parameter.copy()
# force the parameter type
Expand All @@ -264,9 +263,7 @@ def __init__(
self._add_plug(parameter)
else:
raise Exception(
"Can't create Node. Expect a dict structure "
"to initialize the Node, "
"got {0}: {1}".format(type(parameter), parameter)
f"Can't create Node. Expect a dict structure to initialize the Node, got {type(parameter)}: {parameter}"
)

def __del__(self):
Expand Down
14 changes: 6 additions & 8 deletions capsul/process/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def get_help(self, returnhelp=False, use_labels=False):
# Update the documentation with a description of the pipeline
# when the xml to pipeline wrapper has been used
if returnhelp and hasattr(self, "_pipeline_desc"):
str_desc = "".join([" {0}".format(line) for line in self._pipeline_desc])
str_desc = "".join(f" {line}" for line in self._pipeline_desc)
doctring += [
".. hidden-code-block:: python",
" :starthidden: True",
Expand All @@ -307,26 +307,24 @@ def get_help(self, returnhelp=False, use_labels=False):
# when the function to process wrapper has been used
if hasattr(self, "_func_name") and hasattr(self, "_func_module"):
doctring += [
"This process has been wrapped from {0}.{1}.".format(
self._func_module, self._func_name
),
f"This process has been wrapped from {self._func_module}.{self._func_name}.",
"",
]
if returnhelp:
doctring += [
".. currentmodule:: {0}".format(self._func_module),
f".. currentmodule:: {self._func_module}",
"",
".. autosummary::",
" :toctree: ./",
"",
" {0}".format(self._func_name),
f" {self._func_name}",
"",
]

# Append the input and output fields help
if use_labels:
in_label = [".. _%s.%s_inputs:\n\n" % (self.__module__, self.name)]
out_label = [".. _%s.%s_outputs:\n\n" % (self.__module__, self.name)]
in_label = [f".. _{self.__module__}.{self.name}_inputs:\n\n"]
out_label = [f".. _{self.__module__}.{self.name}_outputs:\n\n"]
else:
in_label = []
out_label = []
Expand Down
2 changes: 1 addition & 1 deletion capsul/process/test/test_runprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DummyProcess(Process):
f: field(type_=float, doc="help for parameter f")

def execute(self, context=None):
print("DummyProcess exec, f={0}".format(self.f))
print(f"DummyProcess exec, f={self.f}")


class TestRunProcess(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion capsul/qt_gui/widgets/pipeline_developer_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def _colored_text_item(self, label, text=None, margin=2):
label2 = QtGui.QLabel(text)
label2.setObjectName("label")
label2.setStyleSheet(
"background: rgba({0}, {1}, {2}, 255); "
"background: rgba({}, {}, {}, 255); "
"border-radius: 7px; border: 0px solid; "
"padding: 1px;".format(*color)
)
Expand Down
8 changes: 4 additions & 4 deletions capsul/test/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
capsul_src = Path(__file__).parent.parent
if args.html:
Path(args.html).mkdir(exist_ok=True)
pytest_command += ["--cov=capsul", "--html={}/tests.html".format(args.html)]
pytest_command += ["--cov=capsul", f"--html={args.html}/tests.html"]
coverage_command = [sys.executable, "-m", "coverage", "html", "-d", args.html]
env = os.environ.copy()
print(" ".join("'{}'".format(i) for i in pytest_command))
print(" ".join(f"'{i}'" for i in pytest_command))
subprocess.check_call(pytest_command, env=env, cwd=capsul_src)
print(" ".join("'{}'".format(i) for i in coverage_command))
print(" ".join(f"'{i}'" for i in coverage_command))
subprocess.check_call(coverage_command)
else:
print(" ".join("'{}'".format(i) for i in pytest_command))
print(" ".join(f"'{i}'" for i in pytest_command))
subprocess.check_call(pytest_command, cwd=capsul_src)
2 changes: 0 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ ignore = [
"E741",
"E501",
"UP015",
"UP030",
"UP031",
"UP032",
# https://docs.astral.sh/ruff/rules/redundant-open-modes/
# we prefer explicit to implicit open modes
"UP015",
Expand Down
Loading