Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
🚨 f-strings and cosmetic issues
Browse files Browse the repository at this point in the history
  • Loading branch information
antirotor committed Aug 1, 2022
1 parent 26ba676 commit bb10fdd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
10 changes: 3 additions & 7 deletions igniter/bootstrap_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self, *args, **kwargs):
if self.staging:
if kwargs.get("build"):
if "staging" not in kwargs.get("build"):
kwargs["build"] = "{}-staging".format(kwargs.get("build"))
kwargs["build"] = f"{kwargs.get('build')}-staging"
else:
kwargs["build"] = "staging"

Expand All @@ -136,8 +136,7 @@ def __eq__(self, other):
return bool(result and self.staging == other.staging)

def __repr__(self):
return "<{}: {} - path={}>".format(
self.__class__.__name__, str(self), self.path)
return f"<{self.__class__.__name__}: {str(self)} - path={self.path}>"

def __lt__(self, other: OpenPypeVersion):
result = super().__lt__(other)
Expand Down Expand Up @@ -232,10 +231,7 @@ def parse(cls, version):
return openpype_version

def __hash__(self):
if self.path:
return hash(self.path)
else:
return hash(str(self))
return hash(self.path) if self.path else hash(str(self))

@staticmethod
def is_version_in_dir(
Expand Down
55 changes: 25 additions & 30 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ def _print(message: str):
if "--headless" in sys.argv:
os.environ["OPENPYPE_HEADLESS_MODE"] = "1"
sys.argv.remove("--headless")
else:
if os.getenv("OPENPYPE_HEADLESS_MODE") != "1":
os.environ.pop("OPENPYPE_HEADLESS_MODE", None)
elif os.getenv("OPENPYPE_HEADLESS_MODE") != "1":
os.environ.pop("OPENPYPE_HEADLESS_MODE", None)

# Enabled logging debug mode when "--debug" is passed
if "--verbose" in sys.argv:
Expand All @@ -203,8 +202,8 @@ def _print(message: str):
value = sys.argv.pop(idx)
else:
raise RuntimeError((
"Expect value after \"--verbose\" argument. {}"
).format(expected_values))
f"Expect value after \"--verbose\" argument. {expected_values}"
))

log_level = None
low_value = value.lower()
Expand All @@ -225,8 +224,9 @@ def _print(message: str):

if log_level is None:
raise RuntimeError((
"Unexpected value after \"--verbose\" argument \"{}\". {}"
).format(value, expected_values))
"Unexpected value after \"--verbose\" "
f"argument \"{value}\". {expected_values}"
))

os.environ["OPENPYPE_LOG_LEVEL"] = str(log_level)

Expand Down Expand Up @@ -336,34 +336,33 @@ def run_disk_mapping_commands(settings):
destination = destination.rstrip('/')
source = source.rstrip('/')

if low_platform == "windows":
args = ["subst", destination, source]
elif low_platform == "darwin":
scr = "do shell script \"ln -s {} {}\" with administrator privileges".format(source, destination) # noqa: E501
if low_platform == "darwin":
scr = f'do shell script "ln -s {source} {destination}" with administrator privileges' # noqa

args = ["osascript", "-e", scr]
elif low_platform == "windows":
args = ["subst", destination, source]
else:
args = ["sudo", "ln", "-s", source, destination]

_print("disk mapping args:: {}".format(args))
_print(f"*** disk mapping arguments: {args}")
try:
if not os.path.exists(destination):
output = subprocess.Popen(args)
if output.returncode and output.returncode != 0:
exc_msg = "Executing was not successful: \"{}\"".format(
args)
exc_msg = f'Executing was not successful: "{args}"'

raise RuntimeError(exc_msg)
except TypeError as exc:
_print("Error {} in mapping drive {}, {}".format(str(exc),
source,
destination))
_print(
f"Error {str(exc)} in mapping drive {source}, {destination}")
raise


def set_avalon_environments():
"""Set avalon specific environments.
These are non modifiable environments for avalon workflow that must be set
These are non-modifiable environments for avalon workflow that must be set
before avalon module is imported because avalon works with globals set with
environment variables.
"""
Expand Down Expand Up @@ -508,7 +507,7 @@ def _process_arguments() -> tuple:
)
if m and m.group('version'):
use_version = m.group('version')
_print(">>> Requested version [ {} ]".format(use_version))
_print(f">>> Requested version [ {use_version} ]")
if "+staging" in use_version:
use_staging = True
break
Expand Down Expand Up @@ -614,8 +613,8 @@ def _determine_mongodb() -> str:
try:
openpype_mongo = bootstrap.secure_registry.get_item(
"openPypeMongo")
except ValueError:
raise RuntimeError("Missing MongoDB url")
except ValueError as e:
raise RuntimeError("Missing MongoDB url") from e

return openpype_mongo

Expand Down Expand Up @@ -816,11 +815,8 @@ def _bootstrap_from_code(use_version, use_staging):
use_version, use_staging
)
if version_to_use is None:
raise OpenPypeVersionNotFound(
"Requested version \"{}\" was not found.".format(
use_version
)
)
raise OpenPypeVersionIncompatible(
f"Requested version \"{use_version}\" was not found.")
else:
# Staging version should be used
version_to_use = bootstrap.find_latest_openpype_version(
Expand Down Expand Up @@ -906,7 +902,7 @@ def _boot_validate_versions(use_version, local_version):
use_version, openpype_versions
)
valid, message = bootstrap.validate_openpype_version(version_path)
_print("{}{}".format(">>> " if valid else "!!! ", message))
_print(f'{">>> " if valid else "!!! "}{message}')


def _boot_print_versions(use_staging, local_version, openpype_root):
Expand Down Expand Up @@ -1043,7 +1039,7 @@ def boot():
if not result[0]:
_print(f"!!! Invalid version: {result[1]}")
sys.exit(1)
_print(f"--- version is valid")
_print("--- version is valid")
else:
try:
version_path = _bootstrap_from_code(use_version, use_staging)
Expand Down Expand Up @@ -1164,8 +1160,7 @@ def get_info(use_staging=None) -> list:
formatted = []
for info in inf:
padding = (maximum - len(info[0])) + 1
formatted.append(
"... {}:{}[ {} ]".format(info[0], " " * padding, info[1]))
formatted.append(f'... {info[0]}:{" " * padding}[ {info[1]} ]')
return formatted


Expand Down
2 changes: 1 addition & 1 deletion tools/create_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _print(msg: str, message_type: int = 0) -> None:
else:
header = term.darkolivegreen3("--- ")

print("{}{}".format(header, msg))
print(f"{header}{msg}")


if __name__ == "__main__":
Expand Down

0 comments on commit bb10fdd

Please sign in to comment.