Commit 5814e335 by Branch Vincent Committed by Bjorn Neergaard

chore: use fstrings

parent 3fae3702
......@@ -2,6 +2,8 @@
min_python_version = 3.6.0
max-line-length = 88
ban-relative-imports = true
# flake8-use-fstring: https://github.com/MichaelKim0407/flake8-use-fstring#--percent-greedy-and---format-greedy
format-greedy = 1
inline-quotes = double
# Allow omission of a return type hint for __init__ if at least one argument is annotated
# used by flake8-annotations
......
......@@ -42,6 +42,7 @@ repos:
- flake8-tidy-imports==4.5.0
- flake8-type-checking==1.1.0
- flake8-typing-imports==1.11.0
- flake8-use-fstring==1.3
- pep8-naming==0.12.1
- repo: https://github.com/asottile/pyupgrade
......
......@@ -111,9 +111,7 @@ class Config:
# Looking in the environment if the setting
# is set via a POETRY_* environment variable
if self._use_environment:
env = "POETRY_{}".format(
"_".join(k.upper().replace("-", "_") for k in keys)
)
env = "POETRY_" + "_".join(k.upper().replace("-", "_") for k in keys)
env_value = os.getenv(env)
if env_value is not None:
return self.process(self._get_normalizer(setting_name)(env_value))
......
......@@ -39,13 +39,9 @@ if TYPE_CHECKING:
def load_command(name: str) -> Callable:
def _load() -> Type[Command]:
module = import_module(
"poetry.console.commands.{}".format(".".join(name.split(" ")))
)
command_class = getattr(
module, "{}Command".format("".join(c.title() for c in name.split(" ")))
)
words = name.split(" ")
module = import_module("poetry.console.commands." + ".".join(words))
command_class = getattr(module, "".join(c.title() for c in words) + "Command")
return command_class()
return _load
......
......@@ -27,9 +27,7 @@ class BuildCommand(EnvCommand):
package = self.poetry.package
self.line(
"Building <c1>{}</c1> (<c2>{}</c2>)".format(
package.pretty_name, package.version
)
f"Building <c1>{package.pretty_name}</c1> (<c2>{package.version}</c2>)"
)
builder = Builder(self.poetry)
......
......@@ -43,7 +43,7 @@ class CacheClearCommand(Command):
if not self.option("all"):
raise RuntimeError(
"Add the --all option if you want to clear all "
"{} caches".format(parts[0])
f"{parts[0]} caches"
)
if not os.path.exists(str(cache_dir)):
......
......@@ -230,7 +230,7 @@ To remove a repository (repo is a short alias for repositories):
elif len(values) != 2:
raise ValueError(
"Expected one or two arguments "
"(username, password), got {}".format(len(values))
f"(username, password), got {len(values)}"
)
else:
username = values[0]
......@@ -270,7 +270,7 @@ To remove a repository (repo is a short alias for repositories):
return 0
raise ValueError("Setting {} does not exist".format(self.argument("key")))
raise ValueError(f"Setting {self.argument('key')} does not exist")
def _handle_single_value(
self,
......@@ -307,19 +307,16 @@ To remove a repository (repo is a short alias for repositories):
continue
elif isinstance(value, list):
value = [
value = ", ".join(
json.dumps(val) if isinstance(val, list) else val for val in value
]
value = "[{}]".format(", ".join(value))
)
value = f"[{value}]"
if k.startswith("repositories."):
message = "<c1>{}</c1> = <c2>{}</c2>".format(
k + key, json.dumps(raw_val)
)
message = f"<c1>{k + key}</c1> = <c2>{json.dumps(raw_val)}</c2>"
elif isinstance(raw_val, str) and raw_val != value:
message = "<c1>{}</c1> = <c2>{}</c2> # {}".format(
k + key, json.dumps(raw_val), value
message = (
f"<c1>{k + key}</c1> = <c2>{json.dumps(raw_val)}</c2> # {value}"
)
else:
message = f"<c1>{k + key}</c1> = <c2>{json.dumps(value)}</c2>"
......@@ -361,12 +358,11 @@ To remove a repository (repo is a short alias for repositories):
continue
if isinstance(value, list):
value = [
value = ", ".join(
json.dumps(val) if isinstance(val, list) else val
for val in value
]
value = "[{}]".format(", ".join(value))
)
value = f"[{value}]"
value = json.dumps(value)
......
......@@ -17,9 +17,7 @@ class DebugInfoCommand(Command):
"\n".join(
[
f"<info>Version</info>: <comment>{self.poetry.VERSION}</>",
"<info>Python</info>: <comment>{}</>".format(
poetry_python_version
),
f"<info>Python</info>: <comment>{poetry_python_version}</>",
]
)
)
......
......@@ -52,15 +52,14 @@ class EnvInfoCommand(Command):
self.line("")
system_env = env.parent_env
python = ".".join(str(v) for v in system_env.version_info[:3])
self.line("<b>System</b>")
self.line(
"\n".join(
[
f"<info>Platform</info>: <comment>{env.platform}</>",
f"<info>OS</info>: <comment>{env.os}</>",
"<info>Python</info>: <comment>{}</>".format(
".".join(str(v) for v in system_env.version_info[:3])
),
f"<info>Python</info>: <comment>{python}</>",
f"<info>Path</info>: <comment>{system_env.path}</>",
f"<info>Executable</info>: <comment>{system_env.python}</>",
]
......
......@@ -146,13 +146,11 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
python = self.option("python")
if not python:
current_env = SystemEnv(Path(sys.executable))
default_python = "^{}".format(
".".join(str(v) for v in current_env.version_info[:2])
default_python = "^" + ".".join(
str(v) for v in current_env.version_info[:2]
)
question = self.create_question(
"Compatible Python versions [<comment>{}</comment>]: ".format(
default_python
),
f"Compatible Python versions [<comment>{default_python}</comment>]: ",
default=default_python,
)
python = self.ask(question)
......@@ -282,9 +280,7 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
choices.append(found_package.pretty_name)
self.line(
"Found <info>{}</info> packages matching <c1>{}</c1>".format(
len(matches), package
)
f"Found <info>{len(matches)}</info> packages matching <c1>{package}</c1>"
)
package = self.choice(
......@@ -314,9 +310,7 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
)
self.line(
"Using version <b>{}</b> for <c1>{}</c1>".format(
package_constraint, package
)
f"Using version <b>{package_constraint}</b> for <c1>{package}</c1>"
)
constraint["version"] = package_constraint
......
......@@ -176,19 +176,15 @@ dependencies and not including the current project, run the command with the
# If this is a true error it will be picked up later by build anyway.
return 0
log_install = (
f"<b>Installing</> the current project: <c1>{self.poetry.package.pretty_name}</c1> "
f"(<{{tag}}>{self.poetry.package.pretty_version}</>)"
)
overwrite = self._io.output.is_decorated() and not self.io.is_debug()
self.line("")
if not self._io.output.is_decorated() or self.io.is_debug():
self.line(
"<b>Installing</> the current project: <c1>{}</c1> (<c2>{}</c2>)".format(
self.poetry.package.pretty_name, self.poetry.package.pretty_version
)
)
else:
self.write(
"<b>Installing</> the current project: <c1>{}</c1> (<c2>{}</c2>)".format(
self.poetry.package.pretty_name, self.poetry.package.pretty_version
)
)
self.write(log_install.format(tag="c2"))
if not overwrite:
self.line("")
if self.option("dry-run"):
self.line("")
......@@ -196,12 +192,8 @@ dependencies and not including the current project, run the command with the
builder.build()
if self._io.output.is_decorated() and not self.io.is_debug():
self.overwrite(
"<b>Installing</> the current project: <c1>{}</c1> (<success>{}</success>)".format(
self.poetry.package.pretty_name, self.poetry.package.pretty_version
)
)
if overwrite:
self.overwrite(log_install.format(tag="success"))
self.line("")
return 0
......@@ -50,7 +50,7 @@ class NewCommand(Command):
if path.exists() and list(path.glob("*")):
# Directory is not empty. Aborting.
raise RuntimeError(
"Destination <fg=yellow>{}</> " "exists and is not empty".format(path)
f"Destination <fg=yellow>{path}</> " "exists and is not empty"
)
readme_format = self.option("readme") or "md"
......@@ -64,9 +64,7 @@ class NewCommand(Command):
author += f" <{author_email}>"
current_env = SystemEnv(Path(sys.executable))
default_python = "^{}".format(
".".join(str(v) for v in current_env.version_info[:2])
)
default_python = "^" + ".".join(str(v) for v in current_env.version_info[:2])
layout_ = layout_(
name,
......@@ -83,7 +81,5 @@ class NewCommand(Command):
path = path.relative_to(Path.cwd())
self.line(
"Created package <info>{}</> in <fg=blue>{}</>".format(
layout_._package_name, path.as_posix()
)
f"Created package <info>{layout_._package_name}</> in <fg=blue>{path.as_posix()}</>"
)
......@@ -24,6 +24,7 @@ class PluginShowCommand(Command):
from poetry.repositories.installed_repository import InstalledRepository
from poetry.utils.env import EnvManager
from poetry.utils.helpers import canonicalize_name
from poetry.utils.helpers import pluralize
plugins: DefaultDict[str, Dict[str, Union["Package", List[str]]]] = defaultdict(
lambda: {
......@@ -57,27 +58,21 @@ class PluginShowCommand(Command):
for name, info in plugins.items():
package = info["package"]
description = " " + package.description if package.description else ""
self.line("")
self.line(
" • <c1>{}</c1> (<c2>{}</c2>){}".format(
name,
package.version,
" " + package.description if package.description else "",
)
)
self.line(f" • <c1>{name}</c1> (<c2>{package.version}</c2>){description}")
provide_line = " "
if info["plugins"]:
provide_line += " <info>{}</info> plugin{}".format(
len(info["plugins"]), "s" if len(info["plugins"]) > 1 else ""
)
count = len(info["plugins"])
provide_line += f" <info>{count}</info> plugin{pluralize(count)}"
if info["application_plugins"]:
if info["plugins"]:
provide_line += " and"
provide_line += " <info>{}</info> application plugin{}".format(
len(info["application_plugins"]),
"s" if len(info["application_plugins"]) > 1 else "",
count = len(info["application_plugins"])
provide_line += (
f" <info>{count}</info> application plugin{pluralize(count)}"
)
self.line(provide_line)
......@@ -87,9 +82,7 @@ class PluginShowCommand(Command):
self.line(" <info>Dependencies</info>")
for dependency in package.requires:
self.line(
" - {} (<c2>{}</c2>)".format(
dependency.pretty_name, dependency.pretty_constraint
)
f" - {dependency.pretty_name} (<c2>{dependency.pretty_constraint}</c2>)"
)
return 0
......@@ -49,8 +49,8 @@ the config command.
# Building package first, if told
if self.option("build"):
if publisher.files and not self.confirm(
"There are <info>{}</info> files ready for publishing. "
"Build anyway?".format(len(publisher.files))
f"There are <info>{len(publisher.files)}</info> files ready for publishing. "
"Build anyway?"
):
self.line_error("<error>Aborted!</error>")
......
......@@ -88,9 +88,7 @@ list of installed packages
not_found = set(packages).difference(removed)
if not_found:
raise ValueError(
"The following packages were not found: {}".format(
", ".join(sorted(not_found))
)
"The following packages were not found: " + ", ".join(sorted(not_found))
)
# Refresh the locker
......
......@@ -54,8 +54,8 @@ class RunCommand(EnvCommand):
cmd += [
"import sys; "
"from importlib import import_module; "
"sys.argv = {!r}; {}"
"import_module('{}').{}()".format(args, src_in_sys_path, module, callable_)
f"sys.argv = {args!r}; {src_in_sys_path}"
f"import_module('{module}').{callable_}()"
]
return self.env.execute(*cmd)
......@@ -139,9 +139,7 @@ class SelfUpdateCommand(Command):
self.line("")
self.line(
"<c1>Poetry</c1> (<c2>{}</c2>) is installed now. Great!".format(
release.version
)
f"<c1>Poetry</c1> (<c2>{release.version}</c2>) is installed now. Great!"
)
return 0
......
......@@ -25,8 +25,7 @@ If one doesn't exist yet, it will be created.
) == str(self.env.path)
if venv_activated:
self.line(
"Virtual environment already activated: "
"<info>{}</>".format(self.env.path)
f"Virtual environment already activated: <info>{self.env.path}</>"
)
return
......
......@@ -201,9 +201,7 @@ lists all packages available."""
self.line("<info>dependencies</info>")
for dependency in pkg.requires:
self.line(
" - <c1>{}</c1> <b>{}</b>".format(
dependency.pretty_name, dependency.pretty_constraint
)
f" - <c1>{dependency.pretty_name}</c1> <b>{dependency.pretty_constraint}</b>"
)
if required_by:
......@@ -303,16 +301,12 @@ lists all packages available."""
):
continue
line = "<fg={}>{:{}}{}</>".format(
color, name, name_length - len(install_marker), install_marker
)
line = f"<fg={color}>{name:{name_length - len(install_marker)}}{install_marker}</>"
if write_version:
line += " <b>{:{}}</b>".format(
get_package_version_display_string(
locked, root=self.poetry.file.parent
),
version_length,
version = get_package_version_display_string(
locked, root=self.poetry.file.parent
)
line += f" <b>{version:{version_length}}</b>"
if show_latest:
latest = latest_packages[locked.pretty_name]
update_status = latest_statuses[locked.pretty_name]
......@@ -324,13 +318,10 @@ lists all packages available."""
elif update_status == "update-possible":
color = "yellow"
line += " <fg={}>{:{}}</>".format(
color,
get_package_version_display_string(
latest, root=self.poetry.file.parent
),
latest_length,
version = get_package_version_display_string(
latest, root=self.poetry.file.parent
)
line += f" <fg={color}>{version:{latest_length}}</>"
if write_description:
description = locked.description
......@@ -366,12 +357,7 @@ lists all packages available."""
level = 1
color = self.colors[level]
info = "{tree_bar}── <{color}>{name}</{color}> {constraint}".format(
tree_bar=tree_bar,
color=color,
name=dependency.name,
constraint=dependency.pretty_constraint,
)
info = f"{tree_bar}── <{color}>{dependency.name}</{color}> {dependency.pretty_constraint}"
self._write_tree_line(io, info)
tree_bar = tree_bar.replace("└", " ")
......@@ -414,13 +400,7 @@ lists all packages available."""
if dependency.name in current_tree:
circular_warn = "(circular dependency aborted here)"
info = "{tree_bar}── <{color}>{name}</{color}> {constraint} {warn}".format(
tree_bar=tree_bar,
color=color,
name=dependency.name,
constraint=dependency.pretty_constraint,
warn=circular_warn,
)
info = f"{tree_bar}── <{color}>{dependency.name}</{color}> {dependency.pretty_constraint} {circular_warn}"
self._write_tree_line(io, info)
tree_bar = tree_bar.replace("└", " ")
......
......@@ -58,9 +58,7 @@ patch, minor, major, prepatch, preminor, premajor, prerelease.
self.line(version.to_string())
else:
self.line(
"Bumping version from <b>{}</> to <fg=green>{}</>".format(
self.poetry.package.pretty_version, version
)
f"Bumping version from <b>{self.poetry.package.pretty_version}</> to <fg=green>{version}</>"
)
content = self.poetry.file.read()
......
......@@ -100,9 +100,7 @@ class Factory(BaseFactory):
if config_file.exists():
if io.is_debug():
io.write_line(
"<debug>Loading configuration file {}</debug>".format(
config_file.path
)
f"<debug>Loading configuration file {config_file.path}</debug>"
)
config.merge(config_file.read())
......@@ -114,9 +112,7 @@ class Factory(BaseFactory):
if auth_config_file.exists():
if io.is_debug():
io.write_line(
"<debug>Loading configuration file {}</debug>".format(
auth_config_file.path
)
f"<debug>Loading configuration file {auth_config_file.path}</debug>"
)
config.merge(auth_config_file.read())
......@@ -134,9 +130,7 @@ class Factory(BaseFactory):
is_default = source.get("default", False)
is_secondary = source.get("secondary", False)
if io.is_debug():
message = "Adding repository {} ({})".format(
repository.name, repository.url
)
message = f"Adding repository {repository.name} ({repository.url})"
if is_default:
message += " and setting it as the default one"
elif is_secondary:
......
......@@ -49,7 +49,7 @@ class PackageInfoError(ValueError):
def __init__(
self, path: Union[Path, str], *reasons: Union[BaseException, str]
) -> None:
reasons = (f"Unable to determine package info for path: {str(path)}",) + reasons
reasons = (f"Unable to determine package info for path: {path!s}",) + reasons
super().__init__("\n\n".join(str(msg).strip() for msg in reasons if msg))
......@@ -178,8 +178,8 @@ class PackageInfo:
except ValueError:
# Likely unable to parse constraint so we skip it
self._log(
"Invalid constraint ({}) found in {}-{} dependencies, "
"skipping".format(req, package.name, package.version),
f"Invalid constraint ({req}) found in {package.name}-{package.version} dependencies, "
"skipping",
level="warning",
)
continue
......@@ -460,6 +460,10 @@ class PackageInfo:
dest_dir = venv.path.parent / "dist"
dest_dir.mkdir()
pep517_meta_build_script = PEP517_META_BUILD.format(
source=path.as_posix(), dest=dest_dir.as_posix()
)
try:
venv.run_pip(
"install",
......@@ -470,9 +474,7 @@ class PackageInfo:
venv.run(
"python",
"-",
input_=PEP517_META_BUILD.format(
source=path.as_posix(), dest=dest_dir.as_posix()
),
input_=pep517_meta_build_script,
)
return cls.from_metadata(dest_dir)
except EnvCommandError as e:
......
......@@ -149,8 +149,8 @@ class Chooser:
wheel = Wheel(link.filename)
if not wheel.is_supported_by_environment(self._env):
raise RuntimeError(
"{} is not a supported wheel for this platform. It "
"can't be sorted.".format(wheel.filename)
f"{wheel.filename} is not a supported wheel for this platform. It "
"can't be sorted."
)
# TODO: Binary preference
......
......@@ -17,6 +17,7 @@ from poetry.repositories import Repository
from poetry.repositories.installed_repository import InstalledRepository
from poetry.utils.extras import get_extra_package_names
from poetry.utils.helpers import canonicalize_name
from poetry.utils.helpers import pluralize
if TYPE_CHECKING:
......@@ -385,23 +386,13 @@ class Installer:
uninstalls += 1
self._io.write_line("")
self._io.write_line(
"Package operations: "
"<info>{}</> install{}, "
"<info>{}</> update{}, "
"<info>{}</> removal{}"
"{}".format(
installs,
"" if installs == 1 else "s",
updates,
"" if updates == 1 else "s",
uninstalls,
"" if uninstalls == 1 else "s",
f", <info>{skipped}</> skipped"
if skipped and self.is_verbose()
else "",
)
)
self._io.write("Package operations: ")
self._io.write(f"<info>{installs}</> install{pluralize(installs)}, ")
self._io.write(f"<info>{updates}</> update{pluralize(updates)}, ")
self._io.write(f"<info>{uninstalls}</> removal{pluralize(uninstalls)}")
if skipped and self.is_verbose():
self._io.write(f", <info>{skipped}</> skipped")
self._io.write_line("")
self._io.write_line("")
......@@ -419,23 +410,18 @@ class Installer:
getattr(self, f"_execute_{method}")(operation)
def _execute_install(self, operation: Install) -> None:
target = operation.package
if operation.skipped:
if self.is_verbose() and (self._execute_operations or self.is_dry_run()):
self._io.write_line(
" - Skipping <c1>{}</c1> (<c2>{}</c2>) {}".format(
operation.package.pretty_name,
operation.package.full_pretty_version,
operation.skip_reason,
)
f" - Skipping <c1>{target.pretty_name}</c1> (<c2>{target.full_pretty_version}</c2>) {operation.skip_reason}"
)
return
if self._execute_operations or self.is_dry_run():
self._io.write_line(
" - Installing <c1>{}</c1> (<c2>{}</c2>)".format(
operation.package.pretty_name, operation.package.full_pretty_version
)
f" - Installing <c1>{target.pretty_name}</c1> (<c2>{target.full_pretty_version}</c2>)"
)
if not self._execute_operations:
......@@ -450,22 +436,16 @@ class Installer:
if operation.skipped:
if self.is_verbose() and (self._execute_operations or self.is_dry_run()):
self._io.write_line(
" - Skipping <c1>{}</c1> (<c2>{}</c2>) {}".format(
target.pretty_name,
target.full_pretty_version,
operation.skip_reason,
)
f" - Skipping <c1>{target.pretty_name}</c1> "
f"(<c2>{target.full_pretty_version}</c2>) {operation.skip_reason}"
)
return
if self._execute_operations or self.is_dry_run():
self._io.write_line(
" - Updating <c1>{}</c1> (<c2>{}</c2> -> <c2>{}</c2>)".format(
target.pretty_name,
source.full_pretty_version,
target.full_pretty_version,
)
f" - Updating <c1>{target.pretty_name}</c1> "
f"(<c2>{source.full_pretty_version}</c2> -> <c2>{target.full_pretty_version}</c2>)"
)
if not self._execute_operations:
......@@ -474,23 +454,18 @@ class Installer:
self._installer.update(source, target)
def _execute_uninstall(self, operation: Uninstall) -> None:
target = operation.package
if operation.skipped:
if self.is_verbose() and (self._execute_operations or self.is_dry_run()):
self._io.write_line(
" - Not removing <c1>{}</c1> (<c2>{}</c2>) {}".format(
operation.package.pretty_name,
operation.package.full_pretty_version,
operation.skip_reason,
)
f" - Not removing <c1>{target.pretty_name}</c1> (<c2>{target.pretty_version}</c2>) {operation.skip_reason}"
)
return
if self._execute_operations or self.is_dry_run():
self._io.write_line(
" - Removing <c1>{}</c1> (<c2>{}</c2>)".format(
operation.package.pretty_name, operation.package.full_pretty_version
)
f" - Removing <c1>{target.pretty_name}</c1> (<c2>{target.pretty_version}</c2>)"
)
if not self._execute_operations:
......
......@@ -25,11 +25,7 @@ class Install(Operation):
return "install"
def __str__(self) -> str:
return "Installing {} ({})".format(
self.package.pretty_name, self.format_version(self.package)
)
return f"Installing {self.package.pretty_name} ({self.format_version(self.package)})"
def __repr__(self) -> str:
return "<Install {} ({})>".format(
self.package.pretty_name, self.format_version(self.package)
)
return f"<Install {self.package.pretty_name} ({self.format_version(self.package)})>"
......@@ -28,11 +28,7 @@ class Uninstall(Operation):
return "uninstall"
def __str__(self) -> str:
return "Uninstalling {} ({})".format(
self.package.pretty_name, self.format_version(self._package)
)
return f"Uninstalling {self.package.pretty_name} ({self.format_version(self._package)})"
def __repr__(self) -> str:
return "<Uninstall {} ({})>".format(
self.package.pretty_name, self.format_version(self.package)
)
return f"<Uninstall {self.package.pretty_name} ({self.format_version(self.package)})>"
......@@ -38,17 +38,17 @@ class Update(Operation):
return "update"
def __str__(self) -> str:
return "Updating {} ({}) to {} ({})".format(
self.initial_package.pretty_name,
self.format_version(self.initial_package),
self.target_package.pretty_name,
self.format_version(self.target_package),
init_version = self.format_version(self.initial_package)
target_version = self.format_version(self.target_package)
return (
f"Updating {self.initial_package.pretty_name} ({init_version}) "
f"to {self.target_package.pretty_name} ({target_version})"
)
def __repr__(self) -> str:
return "<Update {} ({}) to {} ({})>".format(
self.initial_package.pretty_name,
self.format_version(self.initial_package),
self.target_package.pretty_name,
self.format_version(self.target_package),
init_version = self.format_version(self.initial_package)
target_version = self.format_version(self.target_package)
return (
f"<Update {self.initial_package.pretty_name} ({init_version}) "
f"to {self.target_package.pretty_name} ({target_version})>"
)
......@@ -52,9 +52,7 @@ class PipInstaller(BaseInstaller):
parsed = urllib.parse.urlparse(package.source_url)
if parsed.scheme == "http":
self._io.write_error(
" <warning>Installing from unsecure host: {}</warning>".format(
parsed.hostname
)
f" <warning>Installing from unsecure host: {parsed.hostname}</warning>"
)
args += ["--trusted-host", parsed.hostname]
......@@ -161,9 +159,7 @@ class PipInstaller(BaseInstaller):
return req
if package.source_type == "git":
req = "git+{}@{}#egg={}".format(
package.source_url, package.source_reference, package.name
)
req = f"git+{package.source_url}@{package.source_reference}#egg={package.name}"
if package.develop:
req = ["-e", req]
......
......@@ -31,9 +31,8 @@ def validate_object(obj: dict, schema_name: str) -> List[str]:
for error in validation_errors:
message = error.message
if error.path:
message = "[{}] {}".format(
".".join(str(x) for x in error.absolute_path), message
)
path = ".".join(str(x) for x in error.absolute_path)
message = f"[{path}] {message}"
errors.append(message)
......
......@@ -61,10 +61,9 @@ class Layout:
self._readme_format = readme_format.lower()
if self._readme_format not in self.ACCEPTED_README_FORMATS:
accepted_readme_formats = ", ".join(self.ACCEPTED_README_FORMATS)
raise ValueError(
"Invalid readme format '{}', use one of {}.".format(
readme_format, ", ".join(self.ACCEPTED_README_FORMATS)
)
f"Invalid readme format '{readme_format}', use one of {accepted_readme_formats}."
)
self._license = license
......
......@@ -47,9 +47,7 @@ class EditableBuilder(Builder):
def build(self) -> None:
self._debug(
" - Building package <c1>{}</c1> in <info>editable</info> mode".format(
self._package.name
)
f" - Building package <c1>{self._package.name}</c1> in <info>editable</info> mode"
)
if self._package.build_script:
......@@ -65,9 +63,7 @@ class EditableBuilder(Builder):
distribution_name=self._package.name
):
self._debug(
" - Removed <c2>{}</c2> directory from <b>{}</b>".format(
removed.name, removed.parent
)
f" - Removed <c2>{removed.name}</c2> directory from <b>{removed.parent}</b>"
)
added_files = []
......@@ -128,9 +124,7 @@ class EditableBuilder(Builder):
# remove any pre-existing pth files for this package
for file in self._env.site_packages.find(path=pth_file, writable_only=True):
self._debug(
" - Removing existing <c2>{}</c2> from <b>{}</b> for {}".format(
file.name, file.parent, self._poetry.file.parent
)
f" - Removing existing <c2>{file.name}</c2> from <b>{file.parent}</b> for {self._poetry.file.parent}"
)
# We can't use unlink(missing_ok=True) because it's not always available
if file.exists():
......@@ -141,17 +135,13 @@ class EditableBuilder(Builder):
pth_file, content, encoding="utf-8"
)
self._debug(
" - Adding <c2>{}</c2> to <b>{}</b> for {}".format(
pth_file.name, pth_file.parent, self._poetry.file.parent
)
f" - Adding <c2>{pth_file.name}</c2> to <b>{pth_file.parent}</b> for {self._poetry.file.parent}"
)
return [pth_file]
except OSError:
# TODO: Replace with PermissionError
self._io.write_error_line(
" - Failed to create <c2>{}</c2> for {}".format(
pth_file.name, self._poetry.file.parent
)
f" - Failed to create <c2>{pth_file.name}</c2> for {self._poetry.file.parent}"
)
return []
......@@ -164,9 +154,7 @@ class EditableBuilder(Builder):
break
else:
self._io.write_error_line(
" - Failed to find a suitable script installation directory for {}".format(
self._poetry.file.parent
)
f" - Failed to find a suitable script installation directory for {self._poetry.file.parent}"
)
return []
......@@ -178,9 +166,7 @@ class EditableBuilder(Builder):
script_file = scripts_path.joinpath(name)
self._debug(
" - Adding the <c2>{}</c2> script to <b>{}</b>".format(
name, scripts_path
)
f" - Adding the <c2>{name}</c2> script to <b>{scripts_path}</b>"
)
with script_file.open("w", encoding="utf-8") as f:
f.write(
......@@ -202,9 +188,7 @@ class EditableBuilder(Builder):
cmd_script = script_file.with_suffix(".cmd")
cmd = WINDOWS_CMD_TEMPLATE.format(python=self._env.python, script=name)
self._debug(
" - Adding the <c2>{}</c2> script wrapper to <b>{}</b>".format(
cmd_script.name, scripts_path
)
f" - Adding the <c2>{cmd_script.name}</c2> script wrapper to <b>{scripts_path}</b>"
)
with cmd_script.open("w", encoding="utf-8") as f:
......@@ -223,9 +207,7 @@ class EditableBuilder(Builder):
dist_info = self._env.site_packages.mkdir(Path(builder.dist_info))
self._debug(
" - Adding the <c2>{}</c2> directory to <b>{}</b>".format(
dist_info.name, dist_info.parent
)
f" - Adding the <c2>{dist_info.name}</c2> directory to <b>{dist_info.parent}</b>"
)
with dist_info.joinpath("METADATA").open("w", encoding="utf-8") as f:
......@@ -246,14 +228,15 @@ class EditableBuilder(Builder):
added_files.append(dist_info.joinpath("entry_points.txt"))
with dist_info.joinpath("RECORD").open("w", encoding="utf-8") as f:
record = dist_info.joinpath("RECORD")
with record.open("w", encoding="utf-8") as f:
for path in added_files:
hash = self._get_file_hash(path)
size = path.stat().st_size
f.write(f"{str(path)},sha256={hash},{size}\n")
f.write(f"{path!s},sha256={hash},{size}\n")
# RECORD itself is recorded with no hash or size
f.write("{},,\n".format(dist_info.joinpath("RECORD")))
f.write(f"{record},,\n")
def _get_file_hash(self, filepath: Path) -> str:
hashsum = hashlib.sha256()
......
......@@ -43,11 +43,9 @@ class _Writer:
if isinstance(incompatibility.cause, PythonCause):
if not required_python_version_notification:
buffer.append(
"The current project's Python requirement ({}) "
f"The current project's Python requirement ({incompatibility.cause.root_python_version}) "
"is not compatible with some of the required "
"packages Python requirement:".format(
incompatibility.cause.root_python_version
)
"packages Python requirement:"
)
required_python_version_notification = True
......@@ -56,11 +54,9 @@ class _Writer:
)
constraint = parse_constraint(incompatibility.cause.python_version)
buffer.append(
" - {} requires Python {}, so it will not be satisfied for Python {}".format(
incompatibility.terms[0].dependency.name,
incompatibility.cause.python_version,
root_constraint.difference(constraint),
)
f" - {incompatibility.terms[0].dependency.name} requires Python "
f"{incompatibility.cause.python_version}, so it will not be satisfied "
f"for Python {root_constraint.difference(constraint)}"
)
if required_python_version_notification:
......@@ -128,14 +124,12 @@ class _Writer:
other_line = self._line_numbers.get(cause.other)
if conflict_line is not None and other_line is not None:
reason = cause.conflict.and_to_string(
cause.other, details_for_cause, conflict_line, other_line
)
self._write(
incompatibility,
"Because {}, {}.".format(
cause.conflict.and_to_string(
cause.other, details_for_cause, conflict_line, other_line
),
incompatibility_string,
),
f"Because {reason}, {incompatibility_string}.",
numbered=numbered,
)
elif conflict_line is not None or other_line is not None:
......@@ -151,9 +145,7 @@ class _Writer:
self._visit(without_line, details_for_cause)
self._write(
incompatibility,
"{} because {} ({}), {}.".format(
conjunction, str(with_line), line, incompatibility_string
),
f"{conjunction} because {with_line!s} ({line}), {incompatibility_string}.",
numbered=numbered,
)
else:
......@@ -178,12 +170,7 @@ class _Writer:
self._write(
incompatibility,
"{} because {} ({}), {}".format(
conjunction,
str(cause.conflict),
self._line_numbers[cause.conflict],
incompatibility_string,
),
f"{conjunction} because {cause.conflict!s} ({self._line_numbers[cause.conflict]}), {incompatibility_string}",
numbered=numbered,
)
elif isinstance(cause.conflict.cause, ConflictCause) or isinstance(
......@@ -202,14 +189,12 @@ class _Writer:
derived_line = self._line_numbers.get(derived)
if derived_line is not None:
reason = ext.and_to_string(
derived, details_for_cause, None, derived_line
)
self._write(
incompatibility,
"Because {}, {}.".format(
ext.and_to_string(
derived, details_for_cause, None, derived_line
),
incompatibility_string,
),
f"Because {reason}, {incompatibility_string}.",
numbered=numbered,
)
elif self._is_collapsible(derived):
......@@ -227,33 +212,26 @@ class _Writer:
details_for_cause = {}
self._visit(collapsed_derived, details_for_cause)
reason = collapsed_ext.and_to_string(ext, details_for_cause, None, None)
self._write(
incompatibility,
"{} because {}, {}.".format(
conjunction,
collapsed_ext.and_to_string(ext, details_for_cause, None, None),
incompatibility_string,
),
f"{conjunction} because {reason}, {incompatibility_string}.",
numbered=numbered,
)
else:
self._visit(derived, details_for_cause)
self._write(
incompatibility,
"{} because {}, {}.".format(
conjunction, str(ext), incompatibility_string
),
f"{conjunction} because {ext!s}, {incompatibility_string}.",
numbered=numbered,
)
else:
reason = cause.conflict.and_to_string(
cause.other, details_for_cause, None, None
)
self._write(
incompatibility,
"Because {}, {}.".format(
cause.conflict.and_to_string(
cause.other, details_for_cause, None, None
),
incompatibility_string,
),
f"Because {reason}, {incompatibility_string}.",
numbered=numbered,
)
......
......@@ -130,9 +130,7 @@ class Incompatibility:
assert depender.is_positive()
assert not dependee.is_positive()
return "{} depends on {}".format(
self._terse(depender, allow_every=True), self._terse(dependee)
)
return f"{self._terse(depender, allow_every=True)} depends on {self._terse(dependee)}"
elif isinstance(self._cause, PythonCause):
assert len(self._terms) == 1
assert self._terms[0].is_positive()
......@@ -155,9 +153,7 @@ class Incompatibility:
assert len(self._terms) == 1
assert self._terms[0].is_positive()
return "no versions of {} match {}".format(
self._terms[0].dependency.name, self._terms[0].constraint
)
return f"no versions of {self._terms[0].dependency.name} match {self._terms[0].constraint}"
elif isinstance(self._cause, PackageNotFoundCause):
assert len(self._terms) == 1
assert self._terms[0].is_positive()
......@@ -168,18 +164,14 @@ class Incompatibility:
assert not self._terms[0].is_positive()
assert self._terms[0].dependency.is_root
return "{} is {}".format(
self._terms[0].dependency.name, self._terms[0].dependency.constraint
)
return f"{self._terms[0].dependency.name} is {self._terms[0].dependency.constraint}"
elif self.is_failure():
return "version solving failed"
if len(self._terms) == 1:
term = self._terms[0]
return "{} is {}".format(
term.dependency.name,
"forbidden" if term.is_positive() else "required",
)
verb = "forbidden" if term.is_positive() else "required"
return f"{term.dependency.name} is {verb}"
if len(self._terms) == 2:
term1 = self._terms[0]
......@@ -200,9 +192,7 @@ class Incompatibility:
return f"{package1} is incompatible with {package2}"
else:
return "either {} or {}".format(
self._terse(term1), self._terse(term2)
)
return f"either {self._terse(term1)} or {self._terse(term2)}"
positive = []
negative = []
......@@ -217,17 +207,13 @@ class Incompatibility:
if len(positive) == 1:
positive_term = [term for term in self._terms if term.is_positive()][0]
return "{} requires {}".format(
self._terse(positive_term, allow_every=True), " or ".join(negative)
)
return f"{self._terse(positive_term, allow_every=True)} requires {' or '.join(negative)}"
else:
return "if {} then {}".format(
" and ".join(positive), " or ".join(negative)
)
return f"if {' and '.join(positive)} then {' or '.join(negative)}"
elif positive:
return "one of {} must be false".format(" or ".join(positive))
return f"one of {' or '.join(positive)} must be false"
else:
return "one of {} must be true".format(" or ".join(negative))
return f"one of {' or '.join(negative)} must be true"
def and_to_string(
self,
......@@ -254,12 +240,12 @@ class Incompatibility:
buffer = [str(self)]
if this_line is not None:
buffer.append(" " + str(this_line))
buffer.append(f" {this_line!s}")
buffer.append(f" and {str(other)}")
buffer.append(f" and {other!s}")
if other_line is not None:
buffer.append(" " + str(other_line))
buffer.append(f" {other_line!s}")
return "\n".join(buffer)
......@@ -454,9 +440,7 @@ class Incompatibility:
if term.dependency.is_root:
return term.dependency.pretty_name
return "{} ({})".format(
term.dependency.pretty_name, term.dependency.pretty_constraint
)
return f"{term.dependency.pretty_name} ({term.dependency.pretty_constraint})"
def _single_term_where(
self, callable: Callable[["Term"], bool]
......@@ -474,4 +458,4 @@ class Incompatibility:
return found
def __repr__(self) -> str:
return f"<Incompatibility {str(self)}>"
return f"<Incompatibility {self!s}>"
......@@ -26,11 +26,9 @@ class PythonRequirementSolution(Solution):
constraint = parse_constraint(incompatibility.cause.python_version)
version_solutions.append(
"For <fg=default;options=bold>{}</>, a possible solution would be "
'to set the `<fg=default;options=bold>python</>` property to <fg=yellow>"{}"</>'.format(
incompatibility.terms[0].dependency.name,
root_constraint.intersect(constraint),
)
f"For <fg=default;options=bold>{incompatibility.terms[0].dependency.name}</>, "
"a possible solution would be to set the `<fg=default;options=bold>python</>` "
f'property to <fg=yellow>"{root_constraint.intersect(constraint)}"</>'
)
description = (
......
......@@ -162,7 +162,8 @@ class Term:
return Term(self.dependency.with_constraint(constraint), is_positive)
def __str__(self) -> str:
return "{}{}".format("not " if not self.is_positive() else "", self._dependency)
prefix = "not " if not self.is_positive() else ""
return f"{prefix}{self._dependency}"
def __repr__(self) -> str:
return f"<Term {str(self)}>"
return f"<Term {self!s}>"
......@@ -87,10 +87,8 @@ class VersionSolver:
raise
finally:
self._log(
"Version solving took {:.3f} seconds.\n"
"Tried {} solutions.".format(
time.time() - start, self._solution.attempted_solutions
)
f"Version solving took {time.time() - start:.3f} seconds.\n"
f"Tried {self._solution.attempted_solutions} solutions."
)
def _propagate(self, package: str) -> None:
......@@ -172,11 +170,8 @@ class VersionSolver:
if unsatisfied is None:
return _conflict
self._log(
"derived: {}{}".format(
"not " if unsatisfied.is_positive() else "", unsatisfied.dependency
)
)
adverb = "not " if unsatisfied.is_positive() else ""
self._log(f"derived: {adverb}{unsatisfied.dependency}")
self._solution.derive(
unsatisfied.dependency, not unsatisfied.is_positive(), incompatibility
......@@ -304,14 +299,11 @@ class VersionSolver:
new_incompatibility = True
partially = "" if difference is None else " partially"
bang = "!"
self._log(
"{} {} is{} satisfied by {}".format(
bang, most_recent_term, partially, most_recent_satisfier
)
f"! {most_recent_term} is{partially} satisfied by {most_recent_satisfier}"
)
self._log(f'{bang} which is caused by "{most_recent_satisfier.cause}"')
self._log(f"{bang} thus: {incompatibility}")
self._log(f'! which is caused by "{most_recent_satisfier.cause}"')
self._log(f"! thus: {incompatibility}")
raise SolveFailure(incompatibility)
......@@ -412,9 +404,7 @@ class VersionSolver:
if not conflict:
self._solution.decide(version)
self._log(
"selecting {} ({})".format(
version.complete_name, version.full_pretty_version
)
f"selecting {version.complete_name} ({version.full_pretty_version})"
)
return dependency.complete_name
......
......@@ -67,9 +67,7 @@ class Publisher:
auth = self._authenticator.get_http_auth(repository_name)
if auth:
logger.debug(
"Found authentication information for {}.".format(
repository_name
)
f"Found authentication information for {repository_name}."
)
username = auth["username"]
password = auth["password"]
......@@ -88,13 +86,11 @@ class Publisher:
self._uploader.auth(username, password)
if repository_name == "pypi":
repository_name = "PyPI"
self._io.write_line(
"Publishing <c1>{}</c1> (<c2>{}</c2>) "
"to <info>{}</info>".format(
self._package.pretty_name,
self._package.pretty_version,
"PyPI" if repository_name == "pypi" else repository_name,
)
f"Publishing <c1>{self._package.pretty_name}</c1> (<c2>{self._package.pretty_version}</c2>) "
f"to <info>{repository_name}</info>"
)
self._uploader.upload(
......
......@@ -335,4 +335,4 @@ class Uploader:
elif len(exts) >= 2 and "".join(exts[-2:]) == ".tar.gz":
return "sdist"
raise ValueError("Unknown distribution format {}".format("".join(exts)))
raise ValueError("Unknown distribution format " + "".join(exts))
......@@ -216,9 +216,8 @@ class Provider:
if vcs != "git":
raise ValueError(f"Unsupported VCS dependency {vcs}")
tmp_dir = Path(
mkdtemp(prefix="pypoetry-git-{}".format(url.split("/")[-1].rstrip(".git")))
)
suffix = url.split("/")[-1].rstrip(".git")
tmp_dir = Path(mkdtemp(prefix=f"pypoetry-git-{suffix}"))
try:
git = Git()
......@@ -259,9 +258,7 @@ class Provider:
if dependency.name != package.name:
# For now, the dependency's name must match the actual package's name
raise RuntimeError(
"The dependency name for {} does not match the actual package's name: {}".format(
dependency.name, package.name
)
f"The dependency name for {dependency.name} does not match the actual package's name: {package.name}"
)
if dependency.base is not None:
......@@ -321,9 +318,7 @@ class Provider:
if name and name != package.name:
# For now, the dependency's name must match the actual package's name
raise RuntimeError(
"The dependency name for {} does not match the actual package's name: {}".format(
name, package.name
)
f"The dependency name for {name} does not match the actual package's name: {package.name}"
)
return package
......@@ -337,9 +332,7 @@ class Provider:
if dependency.name != package.name:
# For now, the dependency's name must match the actual package's name
raise RuntimeError(
"The dependency name for {} does not match the actual package's name: {}".format(
dependency.name, package.name
)
f"The dependency name for {dependency.name} does not match the actual package's name: {package.name}"
)
for extra in dependency.extras:
......@@ -596,7 +589,7 @@ class Provider:
continue
if len(by_constraint) == 1:
self.debug(f"<debug>Merging requirements for {str(deps[0])}</debug>")
self.debug(f"<debug>Merging requirements for {deps[0]!s}</debug>")
dependencies.append(list(by_constraint.values())[0][0])
continue
......@@ -633,28 +626,19 @@ class Provider:
# with the following overrides:
# - {<Package foo (1.2.3): {"bar": <Dependency bar (>=2.0)>}
# - {<Package foo (1.2.3): {"bar": <Dependency bar (<2.0)>}
markers = []
for deps in by_constraint.values():
markers.append(deps[0].marker)
_deps = [_dep[0] for _dep in by_constraint.values()]
self.debug(
"<warning>Different requirements found for {}.</warning>".format(
", ".join(
"<c1>{}</c1> <fg=default>(<c2>{}</c2>)</> with markers <b>{}</b>".format(
d.name,
d.pretty_constraint,
d.marker if not d.marker.is_any() else "*",
)
for d in _deps[:-1]
)
+ " and "
+ "<c1>{}</c1> <fg=default>(<c2>{}</c2>)</> with markers <b>{}</b>".format(
_deps[-1].name,
_deps[-1].pretty_constraint,
_deps[-1].marker if not _deps[-1].marker.is_any() else "*",
)
def fmt_warning(d: "Dependency") -> str:
marker = d.marker if not d.marker.is_any() else "*"
return (
f"<c1>{d.name}</c1> <fg=default>(<c2>{d.pretty_constraint}</c2>)</> "
f"with markers <b>{marker}</b>"
)
warnings = ", ".join(fmt_warning(d) for d in _deps[:-1])
warnings += f" and {fmt_warning(_deps[-1])}"
self.debug(
f"<warning>Different requirements found for {warnings}.</warning>"
)
# We need to check if one of the duplicate dependencies
......@@ -758,10 +742,8 @@ class Provider:
version = ""
message = (
"<fg=blue>fact</>: <c1>{}</c1>{} "
"depends on <c1>{}</c1> (<c2>{}</c2>)".format(
name, version, m.group(2), m.group(3)
)
f"<fg=blue>fact</>: <c1>{name}</c1>{version} "
f"depends on <c1>{m.group(2)}</c1> (<c2>{m.group(3)}</c2>)"
)
elif " is " in message:
message = re.sub(
......@@ -773,7 +755,7 @@ class Provider:
message = re.sub(
r"(?<=: )(.+?) \((.+?)\)", "<c1>\\1</c1> (<c2>\\2</c2>)", message
)
message = "<fg=blue>fact</>: {}".format(message.split("fact: ")[1])
message = f"<fg=blue>fact</>: {message.split('fact: ')[1]}"
elif message.startswith("selecting "):
message = re.sub(
r"selecting (.+?) \((.+?)\)",
......@@ -783,12 +765,10 @@ class Provider:
elif message.startswith("derived:"):
m = re.match(r"derived: (.+?) \((.+?)\)$", message)
if m:
message = "<fg=blue>derived</>: <c1>{}</c1> (<c2>{}</c2>)".format(
m.group(1), m.group(2)
)
message = f"<fg=blue>derived</>: <c1>{m.group(1)}</c1> (<c2>{m.group(2)}</c2>)"
else:
message = "<fg=blue>derived</>: <c1>{}</c1>".format(
message.split("derived: ")[1]
message = (
f"<fg=blue>derived</>: <c1>{message.split('derived: ')[1]}</c1>"
)
elif message.startswith("conflict:"):
m = re.match(r"conflict: (.+?) depends on (.+?) \((.+?)\)", message)
......@@ -802,15 +782,11 @@ class Provider:
version = ""
message = (
"<fg=red;options=bold>conflict</>: <c1>{}</c1>{} "
"depends on <c1>{}</c1> (<c2>{}</c2>)".format(
name, version, m.group(2), m.group(3)
)
f"<fg=red;options=bold>conflict</>: <c1>{name}</c1>{version} "
f"depends on <c1>{m.group(2)}</c1> (<c2>{m.group(3)}</c2>)"
)
else:
message = "<fg=red;options=bold>conflict</>: {}".format(
message.split("conflict: ")[1]
)
message = f"<fg=red;options=bold>conflict</>: {message.split('conflict: ')[1]}"
message = message.replace("! ", "<error>!</error> ")
......
......@@ -78,9 +78,7 @@ class Solver:
if len(self._overrides) > 1:
self._provider.debug(
"Complete version solving took {:.3f} seconds with {} overrides".format(
end - start, len(self._overrides)
)
f"Complete version solving took {end - start:.3f} seconds with {len(self._overrides)} overrides"
)
self._provider.debug(
f"Resolved with overrides: {', '.join(f'({b})' for b in self._overrides)}"
......
......@@ -145,7 +145,7 @@ class Page:
"""Makes sure a link is fully encoded. That is, if a ' ' shows up in
the link, it will be rewritten to %20 (while not over-quoting
% or other characters)."""
return self._clean_re.sub(lambda match: "%%%2x" % ord(match.group(0)), url)
return self._clean_re.sub(lambda match: f"%{match.group(0):2x}", url)
# TODO: revisit whether the LegacyRepository should inherit from PyPiRepository.
......@@ -217,14 +217,10 @@ class LegacyRepository(PyPiRepository):
return self.url
parsed = urllib.parse.urlparse(self.url)
username = quote(self._session.auth.username, safe="")
password = quote(self._session.auth.password, safe="")
return "{scheme}://{username}:{password}@{netloc}{path}".format(
scheme=parsed.scheme,
username=quote(self._session.auth.username, safe=""),
password=quote(self._session.auth.password, safe=""),
netloc=parsed.netloc,
path=parsed.path,
)
return f"{parsed.scheme}://{username}:{password}@{parsed.netloc}{parsed.path}"
def find_packages(self, dependency: "Dependency") -> List[Package]:
packages = []
......@@ -247,14 +243,14 @@ class LegacyRepository(PyPiRepository):
key = dependency.name
if not constraint.is_any():
key = f"{key}:{str(constraint)}"
key = f"{key}:{constraint!s}"
ignored_pre_release_versions = []
if self._cache.store("matches").has(key):
versions = self._cache.store("matches").get(key)
else:
page = self._get_page("/{}/".format(dependency.name.replace(".", "-")))
page = self._get_page(f"/{dependency.name.replace('.', '-')}/")
if page is None:
return []
......@@ -284,9 +280,7 @@ class LegacyRepository(PyPiRepository):
packages.append(package)
self._log(
"{} packages found for {} {}".format(
len(packages), dependency.name, str(constraint)
),
f"{len(packages)} packages found for {dependency.name} {constraint!s}",
level="debug",
)
......@@ -323,14 +317,14 @@ class LegacyRepository(PyPiRepository):
return package
def find_links_for_package(self, package: Package) -> List[Link]:
page = self._get_page("/{}/".format(package.name.replace(".", "-")))
page = self._get_page(f"/{package.name.replace('.', '-')}/")
if page is None:
return []
return list(page.links_for_version(package.version))
def _get_release_info(self, name: str, version: str) -> dict:
page = self._get_page("/{}/".format(canonicalize_name(name).replace(".", "-")))
page = self._get_page(f"/{canonicalize_name(name).replace('.', '-')}/")
if page is None:
raise PackageNotFound(f'No package named "{name}"')
......@@ -348,9 +342,7 @@ class LegacyRepository(PyPiRepository):
links = list(page.links_for_version(Version.parse(version)))
if not links:
raise PackageNotFound(
'No valid distribution links found for package: "{}" version: "{}"'.format(
name, version
)
f'No valid distribution links found for package: "{name}" version: "{version}"'
)
urls = defaultdict(list)
files = []
......@@ -388,9 +380,7 @@ class LegacyRepository(PyPiRepository):
required_hash.update(chunk)
if not known_hash or known_hash.hexdigest() == link.hash:
file_hash = "{}:{}".format(
required_hash.name, required_hash.hexdigest()
)
file_hash = f"{required_hash.name}:{required_hash.hexdigest()}"
files.append({"file": link.filename, "hash": file_hash})
......@@ -422,9 +412,7 @@ class LegacyRepository(PyPiRepository):
if response.url != url:
self._log(
"Response URL {response_url} differs from request URL {url}".format(
response_url=response.url, url=url
),
f"Response URL {response.url} differs from request URL {url}",
level="debug",
)
......
......@@ -109,7 +109,7 @@ class PyPiRepository(RemoteRepository):
info = self.get_package_info(dependency.name)
except PackageNotFound:
self._log(
f"No packages found for {dependency.name} {str(constraint)}",
f"No packages found for {dependency.name} {constraint!s}",
level="debug",
)
return []
......@@ -121,9 +121,7 @@ class PyPiRepository(RemoteRepository):
if not release:
# Bad release
self._log(
"No release information found for {}-{}, skipping".format(
dependency.name, version
),
f"No release information found for {dependency.name}-{version}, skipping",
level="debug",
)
continue
......@@ -132,9 +130,7 @@ class PyPiRepository(RemoteRepository):
package = Package(info["info"]["name"], version)
except InvalidVersion:
self._log(
'Unable to parse version "{}" for the {} package, skipping'.format(
version, dependency.name
),
f'Unable to parse version "{version}" for the {dependency.name} package, skipping',
level="debug",
)
continue
......@@ -149,9 +145,7 @@ class PyPiRepository(RemoteRepository):
packages.append(package)
self._log(
"{} packages found for {} {}".format(
len(packages), dependency.name, str(constraint)
),
f"{len(packages)} packages found for {dependency.name} {constraint!s}",
level="debug",
)
......@@ -189,9 +183,7 @@ class PyPiRepository(RemoteRepository):
results.append(result)
except InvalidVersion:
self._log(
'Unable to parse version "{}" for the {} package, skipping'.format(
version, name
),
f'Unable to parse version "{version}" for the {name} package, skipping',
level="debug",
)
......@@ -254,7 +246,7 @@ class PyPiRepository(RemoteRepository):
links = []
for url in json_data["urls"]:
h = "sha256={}".format(url["digests"]["sha256"])
h = f"sha256={url['digests']['sha256']}"
links.append(Link(url["url"] + "#" + h))
return links
......@@ -433,14 +425,9 @@ class PyPiRepository(RemoteRepository):
def _get_info_from_wheel(self, url: str) -> "PackageInfo":
from poetry.inspection.info import PackageInfo
self._log(
"Downloading wheel: {}".format(
urllib.parse.urlparse(url).path.rsplit("/")[-1]
),
level="debug",
)
filename = os.path.basename(urllib.parse.urlparse(url).path.rsplit("/")[-1])
wheel_name = urllib.parse.urlparse(url).path.rsplit("/")[-1]
self._log(f"Downloading wheel: {wheel_name}", level="debug")
filename = os.path.basename(wheel_name)
with temporary_directory() as temp_dir:
filepath = Path(temp_dir) / filename
......@@ -451,14 +438,9 @@ class PyPiRepository(RemoteRepository):
def _get_info_from_sdist(self, url: str) -> "PackageInfo":
from poetry.inspection.info import PackageInfo
self._log(
"Downloading sdist: {}".format(
urllib.parse.urlparse(url).path.rsplit("/")[-1]
),
level="debug",
)
filename = os.path.basename(urllib.parse.urlparse(url).path)
sdist_name = urllib.parse.urlparse(url).path
self._log(f"Downloading sdist: {sdist_name.rsplit('/')[-1]}", level="debug")
filename = os.path.basename(sdist_name)
with temporary_directory() as temp_dir:
filepath = Path(temp_dir) / filename
......
......@@ -35,11 +35,7 @@ class Authenticator:
def _log(self, message: str, level: str = "debug") -> None:
if self._io is not None:
self._io.write_line(
"<{level:s}>{message:s}</{level:s}>".format(
message=message, level=level
)
)
self._io.write_line(f"<{level}>{message}</{level}>")
else:
getattr(logger, level, logger.debug)(message)
......
......@@ -254,19 +254,16 @@ class SitePackages:
except ValueError:
pass
else:
site_type = "writable " if writable_only else ""
raise ValueError(
"{} is not relative to any discovered {}sites".format(
path, "writable " if writable_only else ""
)
f"{path} is not relative to any discovered {site_type}sites"
)
results = [candidate / path for candidate in candidates if candidate]
if not results and strict:
raise RuntimeError(
'Unable to find a suitable destination for "{}" in {}'.format(
str(path), paths_csv(self._candidates)
)
f'Unable to find a suitable destination for "{path}" in {paths_csv(self._candidates)}'
)
return results
......@@ -421,9 +418,7 @@ class EnvCommandError(EnvError):
def __init__(self, e: CalledProcessError, input: Optional[str] = None) -> None:
self.e = e
message = "Command {} errored with the following return code {}, and output: \n{}".format(
e.cmd, e.returncode, decode(e.output)
)
message = f"Command {e.cmd} errored with the following return code {e.returncode}, and output: \n{decode(e.output)}"
if input:
message += f"input was : {input}"
super().__init__(message)
......@@ -433,11 +428,11 @@ class NoCompatiblePythonVersionFound(EnvError):
def __init__(self, expected: str, given: Optional[str] = None) -> None:
if given:
message = (
"The specified Python version ({}) "
"is not supported by the project ({}).\n"
f"The specified Python version ({given}) "
f"is not supported by the project ({expected}).\n"
"Please choose a compatible version "
"or loosen the python constraint specified "
"in the pyproject.toml file.".format(given, expected)
"in the pyproject.toml file."
)
else:
message = (
......@@ -573,11 +568,8 @@ class EnvManager:
envs = envs_file.read()
env = envs.get(name)
if env is not None:
io.write_line(
"Deactivating virtualenv: <comment>{}</comment>".format(
venv_path / (name + "-py{}".format(env["minor"]))
)
)
venv = venv_path / f"{name}-py{env['minor']}"
io.write_line(f"Deactivating virtualenv: <comment>{venv}</comment>")
del envs[name]
envs_file.write(envs)
......@@ -834,11 +826,9 @@ class EnvManager:
)
io.write_line(
"<warning>The currently activated Python version {} "
"is not supported by the project ({}).\n"
"Trying to find and use a compatible version.</warning> ".format(
python_patch, self._poetry.package.python_versions
)
f"<warning>The currently activated Python version {python_patch} "
f"is not supported by the project ({self._poetry.package.python_versions}).\n"
"Trying to find and use a compatible version.</warning> "
)
for python_to_try in sorted(
......@@ -910,17 +900,15 @@ class EnvManager:
return self.get_system_env()
io.write_line(f"Creating virtualenv <c1>{name}</> in {str(venv_path)}")
io.write_line(f"Creating virtualenv <c1>{name}</> in {venv_path!s}")
else:
create_venv = False
if force:
if not env.is_sane():
io.write_line(
"<warning>The virtual environment found in {} seems to be broken.</warning>".format(
env.path
)
f"<warning>The virtual environment found in {env.path} seems to be broken.</warning>"
)
io.write_line(f"Recreating virtualenv <c1>{name}</> in {str(venv)}")
io.write_line(f"Recreating virtualenv <c1>{name}</> in {venv!s}")
self.remove_venv(venv)
create_venv = True
elif io.is_very_verbose():
......@@ -1493,7 +1481,7 @@ class SystemEnv(Env):
def get_marker_env(self) -> Dict[str, Any]:
if hasattr(sys, "implementation"):
info = sys.implementation.version
iver = "{0.major}.{0.minor}.{0.micro}".format(info)
iver = f"{info.major}.{info.minor}.{info.micro}"
kind = info.releaselevel
if kind != "final":
iver += kind[0] + str(info.serial)
......@@ -1678,8 +1666,8 @@ class GenericEnv(VirtualEnv):
patterns = [("python*", "pip*")]
if self._child_env:
minor_version = "{}.{}".format(
self._child_env.version_info[0], self._child_env.version_info[1]
minor_version = (
f"{self._child_env.version_info[0]}.{self._child_env.version_info[1]}"
)
major_version = f"{self._child_env.version_info[0]}"
patterns = [
......
......@@ -45,7 +45,7 @@ class Exporter:
if fmt not in self.ACCEPTED_FORMATS:
raise ValueError(f"Invalid export format: {fmt}")
getattr(self, "_export_{}".format(fmt.replace(".", "_")))(
getattr(self, "_export_" + fmt.replace(".", "_"))(
cwd,
output,
with_hashes=with_hashes,
......@@ -120,11 +120,8 @@ class Exporter:
hashes.append(f"{algorithm}:{h}")
if hashes:
line += " \\\n"
for i, h in enumerate(hashes):
line += " --hash={}{}".format(
h, " \\\n" if i < len(hashes) - 1 else ""
)
sep = " \\\n"
line += sep + sep.join(f" --hash={h}" for h in hashes)
dependency_lines.add(line)
content += "\n".join(sorted(dependency_lines))
......
......@@ -110,16 +110,14 @@ def get_package_version_display_string(
package: "Package", root: Optional[Path] = None
) -> str:
if package.source_type in ["file", "directory"] and root:
return "{} {}".format(
package.version,
Path(os.path.relpath(package.source_url, root.as_posix())).as_posix(),
)
path = Path(os.path.relpath(package.source_url, root.as_posix())).as_posix()
return f"{package.version} {path}"
return package.full_pretty_version
def paths_csv(paths: List[Path]) -> str:
return ", ".join(f'"{str(c)}"' for c in paths)
return ", ".join(f'"{c!s}"' for c in paths)
def is_dir_writable(path: Path, create: bool = False) -> bool:
......@@ -135,3 +133,9 @@ def is_dir_writable(path: Path, create: bool = False) -> bool:
return False
else:
return True
def pluralize(count: int, word: str = "") -> str:
if count == 1:
return word
return word + "s"
......@@ -61,9 +61,7 @@ class KeyRing:
keyring.set_password(name, username, password)
except (RuntimeError, keyring.errors.KeyringError) as e:
raise KeyRingError(
"Unable to store the password for {} in the key ring: {}".format(
name, str(e)
)
f"Unable to store the password for {name} in the key ring: {e}"
)
def delete_password(self, name: str, username: str) -> None:
......@@ -89,7 +87,7 @@ class KeyRing:
try:
import keyring
except Exception as e:
logger.debug(f"An error occurred while importing keyring: {str(e)}")
logger.debug(f"An error occurred while importing keyring: {e!s}")
self._is_available = False
return
......
......@@ -41,9 +41,8 @@ class SetupReader:
if not filepath.exists():
continue
new_result = getattr(cls(), "read_{}".format(filename.replace(".", "_")))(
filepath
)
read_file_func = getattr(cls(), "read_" + filename.replace(".", "_"))
new_result = read_file_func(filepath)
for key in result.keys():
if new_result[key]:
......
......@@ -309,7 +309,7 @@ def current_python(current_env: SystemEnv) -> Tuple[int, int, int]:
@pytest.fixture(scope="session")
def default_python(current_python: Tuple[int, int, int]) -> str:
return "^{}".format(".".join(str(v) for v in current_python[:2]))
return "^" + ".".join(str(v) for v in current_python[:2])
@pytest.fixture
......
......@@ -33,27 +33,21 @@ def tester(command_tester_factory: "CommandTesterFactory") -> "CommandTester":
def test_env_info_displays_complete_info(tester: "CommandTester"):
tester.execute()
expected = """
expected = f"""
Virtualenv
Python: 3.7.0
Implementation: CPython
Path: {prefix}
Executable: {executable}
Path: {Path('/prefix')}
Executable: {sys.executable}
Valid: True
System
Platform: darwin
OS: posix
Python: {base_version}
Path: {base_prefix}
Executable: {base_executable}
""".format(
prefix=str(Path("/prefix")),
base_prefix=str(Path("/base/prefix")),
base_version=".".join(str(v) for v in sys.version_info[:3]),
executable=sys.executable,
base_executable="python",
)
Python: {'.'.join(str(v) for v in sys.version_info[:3])}
Path: {Path('/base/prefix')}
Executable: python
"""
assert expected == tester.io.fetch_output()
......
......@@ -82,14 +82,10 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
assert envs[venv_name]["minor"] == "3.7"
assert envs[venv_name]["patch"] == "3.7.1"
expected = """\
Creating virtualenv {} in {}
Using virtualenv: {}
""".format(
venv_py37.name,
venv_py37.parent,
venv_py37,
)
expected = f"""\
Creating virtualenv {venv_py37.name} in {venv_py37.parent}
Using virtualenv: {venv_py37}
"""
assert expected == tester.io.fetch_output()
......@@ -115,11 +111,9 @@ def test_get_prefers_explicitly_activated_virtualenvs_over_env_var(
tester.execute(python_minor)
expected = """\
Using virtualenv: {}
""".format(
venv_dir
)
expected = f"""\
Using virtualenv: {venv_dir}
"""
assert expected == tester.io.fetch_output()
......@@ -151,13 +145,9 @@ def test_get_prefers_explicitly_activated_non_existing_virtualenvs_over_env_var(
tester.execute(python_minor)
expected = """\
Creating virtualenv {} in {}
Using virtualenv: {}
""".format(
venv_dir.name,
venv_dir.parent,
venv_dir,
)
expected = f"""\
Creating virtualenv {venv_dir.name} in {venv_dir.parent}
Using virtualenv: {venv_dir}
"""
assert expected == tester.io.fetch_output()
......@@ -70,7 +70,7 @@ def test_self_update_can_update_from_recommended_installation(
tester.execute()
expected_output = """\
expected_output = f"""\
Updating Poetry to 1.2.0
Updating dependencies
......@@ -79,14 +79,12 @@ Resolving dependencies...
Package operations: 0 installs, 2 updates, 0 removals
- Updating cleo (0.8.2 -> 1.0.0)
- Updating poetry ({} -> {})
- Updating poetry ({__version__} -> {new_version})
Updating the poetry script
Poetry ({}) is installed now. Great!
""".format(
__version__, new_version, new_version
)
Poetry ({new_version}) is installed now. Great!
"""
assert tester.io.fetch_output() == expected_output
......
......@@ -366,7 +366,7 @@ def test_add_directory_constraint(
path = "../git/github.com/demo/demo"
tester.execute(f"{path}" if not editable else f"-e {path}")
expected = """\
expected = f"""\
Updating dependencies
Resolving dependencies...
......@@ -376,10 +376,8 @@ Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.2 {})
""".format(
app.poetry.file.parent.joinpath(path).resolve().as_posix()
)
• Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
"""
assert expected == tester.io.fetch_output()
assert tester.command.installer.executor.installations_count == 2
......@@ -409,7 +407,7 @@ def test_add_directory_with_poetry(
path = "../git/github.com/demo/pyproject-demo"
tester.execute(f"{path}")
expected = """\
expected = f"""\
Updating dependencies
Resolving dependencies...
......@@ -419,10 +417,8 @@ Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.2 {})
""".format(
app.poetry.file.parent.joinpath(path).resolve().as_posix()
)
• Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
"""
assert expected == tester.io.fetch_output()
assert tester.command.installer.executor.installations_count == 2
......@@ -443,7 +439,7 @@ def test_add_file_constraint_wheel(
path = "../distributions/demo-0.1.0-py2.py3-none-any.whl"
tester.execute(f"{path}")
expected = """\
expected = f"""\
Updating dependencies
Resolving dependencies...
......@@ -453,10 +449,8 @@ Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.0 {})
""".format(
app.poetry.file.parent.joinpath(path).resolve().as_posix()
)
• Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
"""
assert expected == tester.io.fetch_output()
assert tester.command.installer.executor.installations_count == 2
......@@ -483,7 +477,7 @@ def test_add_file_constraint_sdist(
path = "../distributions/demo-0.1.0.tar.gz"
tester.execute(f"{path}")
expected = """\
expected = f"""\
Updating dependencies
Resolving dependencies...
......@@ -493,10 +487,8 @@ Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.0 {})
""".format(
app.poetry.file.parent.joinpath(path).resolve().as_posix()
)
• Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
"""
assert expected == tester.io.fetch_output()
assert tester.command.installer.executor.installations_count == 2
......@@ -1305,7 +1297,7 @@ def test_add_directory_constraint_old_installer(
path = "../git/github.com/demo/demo"
old_tester.execute(f"{path}")
expected = """\
expected = f"""\
Updating dependencies
Resolving dependencies...
......@@ -1315,10 +1307,8 @@ Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.2 {})
""".format(
app.poetry.file.parent.joinpath(path).resolve().as_posix()
)
- Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
"""
assert expected == old_tester.io.fetch_output()
......@@ -1345,7 +1335,7 @@ def test_add_directory_with_poetry_old_installer(
path = "../git/github.com/demo/pyproject-demo"
old_tester.execute(f"{path}")
expected = """\
expected = f"""\
Updating dependencies
Resolving dependencies...
......@@ -1355,10 +1345,8 @@ Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.2 {})
""".format(
app.poetry.file.parent.joinpath(path).resolve().as_posix()
)
- Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
"""
assert expected == old_tester.io.fetch_output()
......@@ -1380,7 +1368,7 @@ def test_add_file_constraint_wheel_old_installer(
path = "../distributions/demo-0.1.0-py2.py3-none-any.whl"
old_tester.execute(f"{path}")
expected = """\
expected = f"""\
Updating dependencies
Resolving dependencies...
......@@ -1390,10 +1378,8 @@ Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.0 {})
""".format(
app.poetry.file.parent.joinpath(path).resolve().as_posix()
)
- Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
"""
assert expected == old_tester.io.fetch_output()
......@@ -1422,7 +1408,7 @@ def test_add_file_constraint_sdist_old_installer(
path = "../distributions/demo-0.1.0.tar.gz"
old_tester.execute(f"{path}")
expected = """\
expected = f"""\
Updating dependencies
Resolving dependencies...
......@@ -1432,10 +1418,8 @@ Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.0 {})
""".format(
app.poetry.file.parent.joinpath(path).resolve().as_posix()
)
- Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
"""
assert expected == old_tester.io.fetch_output()
......
......@@ -53,12 +53,10 @@ def test_cache_list(
):
tester.execute()
expected = """\
{}
{}
""".format(
repository_one, repository_two
)
expected = f"""\
{repository_one}
{repository_two}
"""
assert expected == tester.io.fetch_output()
......
......@@ -45,7 +45,9 @@ def test_list_displays_default_value_if_not_set(
):
tester.execute("--list")
expected = """cache-dir = {cache}
cache_dir = json.dumps(str(config_cache_dir))
venv_path = json.dumps(os.path.join("{cache-dir}", "virtualenvs"))
expected = f"""cache-dir = {cache_dir}
experimental.new-installer = true
installer.max-workers = null
installer.parallel = true
......@@ -53,12 +55,8 @@ virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {path} # {virtualenvs}
""".format(
cache=json.dumps(str(config_cache_dir)),
path=json.dumps(os.path.join("{cache-dir}", "virtualenvs")),
virtualenvs=str(config_cache_dir / "virtualenvs"),
)
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
"""
assert expected == tester.io.fetch_output()
......@@ -70,7 +68,9 @@ def test_list_displays_set_get_setting(
tester.execute("--list")
expected = """cache-dir = {cache}
cache_dir = json.dumps(str(config_cache_dir))
venv_path = json.dumps(os.path.join("{cache-dir}", "virtualenvs"))
expected = f"""cache-dir = {cache_dir}
experimental.new-installer = true
installer.max-workers = null
installer.parallel = true
......@@ -78,12 +78,8 @@ virtualenvs.create = false
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {path} # {virtualenvs}
""".format(
cache=json.dumps(str(config_cache_dir)),
path=json.dumps(os.path.join("{cache-dir}", "virtualenvs")),
virtualenvs=str(config_cache_dir / "virtualenvs"),
)
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
"""
assert config.set_config_source.call_count == 0
assert expected == tester.io.fetch_output()
......@@ -119,7 +115,9 @@ def test_list_displays_set_get_local_setting(
tester.execute("--list")
expected = """cache-dir = {cache}
cache_dir = json.dumps(str(config_cache_dir))
venv_path = json.dumps(os.path.join("{cache-dir}", "virtualenvs"))
expected = f"""cache-dir = {cache_dir}
experimental.new-installer = true
installer.max-workers = null
installer.parallel = true
......@@ -127,12 +125,8 @@ virtualenvs.create = false
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {path} # {virtualenvs}
""".format(
cache=json.dumps(str(config_cache_dir)),
path=json.dumps(os.path.join("{cache-dir}", "virtualenvs")),
virtualenvs=str(config_cache_dir / "virtualenvs"),
)
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
"""
assert config.set_config_source.call_count == 1
assert expected == tester.io.fetch_output()
......
......@@ -180,7 +180,8 @@ def test_empty_license(tester: CommandTester):
]
tester.execute(inputs="\n".join(inputs))
expected = """\
python = ".".join(str(c) for c in sys.version_info[:2])
expected = f"""\
[tool.poetry]
name = "my-package"
version = "1.2.3"
......@@ -191,9 +192,7 @@ packages = [{{include = "my_package"}}]
[tool.poetry.dependencies]
python = "^{python}"
""".format(
python=".".join(str(c) for c in sys.version_info[:2])
)
"""
assert expected in tester.io.fetch_output()
......
......@@ -216,8 +216,6 @@ class TestRepository(Repository):
def find_links_for_package(self, package: Package) -> List[Link]:
return [
Link(
"https://foo.bar/files/{}-{}-py2.py3-none-any.whl".format(
escape_name(package.name), escape_version(package.version.text)
)
f"https://foo.bar/files/{escape_name(package.name)}-{escape_version(package.version.text)}-py2.py3-none-any.whl"
)
]
......@@ -83,9 +83,7 @@ def test_get_cache_directory_for_link(config: "Config", config_cache_dir: Path):
)
expected = Path(
"{}/artifacts/ba/63/13/283a3b3b7f95f05e9e6f84182d276f7bb0951d5b0cc24422b33f7a4648".format(
config_cache_dir.as_posix()
)
f"{config_cache_dir.as_posix()}/artifacts/ba/63/13/283a3b3b7f95f05e9e6f84182d276f7bb0951d5b0cc24422b33f7a4648"
)
assert expected == directory
......@@ -161,18 +161,16 @@ def test_execute_executes_a_batch_of_operations(
]
)
expected = """
expected = f"""
Package operations: 4 installs, 1 update, 1 removal
• Installing pytest (3.5.2)
• Removing attrs (17.4.0)
• Updating requests (2.18.3 -> 2.18.4)
• Installing demo (0.1.0 {})
• Installing simple-project (1.2.3 {})
• Installing demo (0.1.0 {file_package.source_url})
• Installing simple-project (1.2.3 {directory_package.source_url})
• Installing demo (0.1.0 master)
""".format(
file_package.source_url, directory_package.source_url
)
"""
expected = set(expected.splitlines())
output = set(io.fetch_output().splitlines())
......
......@@ -152,42 +152,36 @@ My Package
assert str(dist_info.joinpath("entry_points.txt")) in records
assert str(dist_info.joinpath("RECORD")) in records
baz_script = """\
#!{python}
baz_script = f"""\
#!{tmp_venv.python}
import sys
from bar import baz
if __name__ == '__main__':
sys.exit(baz.boom.bim())
""".format(
python=tmp_venv.python
)
"""
assert baz_script == tmp_venv._bin_dir.joinpath("baz").read_text()
foo_script = """\
#!{python}
foo_script = f"""\
#!{tmp_venv.python}
import sys
from foo import bar
if __name__ == '__main__':
sys.exit(bar())
""".format(
python=tmp_venv.python
)
"""
assert foo_script == tmp_venv._bin_dir.joinpath("foo").read_text()
fox_script = """\
#!{python}
fox_script = f"""\
#!{tmp_venv.python}
import sys
from fuz.foo import bar
if __name__ == '__main__':
sys.exit(bar.baz())
""".format(
python=tmp_venv.python
)
"""
assert fox_script == tmp_venv._bin_dir.joinpath("fox").read_text()
......
......@@ -430,18 +430,15 @@ A = []
def test_locker_should_emit_warnings_if_lock_version_is_newer_but_allowed(
locker: Locker, caplog: "LogCaptureFixture"
):
content = """\
version = ".".join(Version.parse(Locker._VERSION).next_minor().text.split(".")[:2])
content = f"""\
[metadata]
lock-version = "{version}"
python-versions = "~2.7 || ^3.4"
content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77"
[metadata.files]
""".format(
version=".".join(
Version.parse(Locker._VERSION).next_minor().text.split(".")[:2]
)
)
"""
caplog.set_level(logging.WARNING, logger="poetry.packages.locker")
locker.lock.write(tomlkit.parse(content))
......@@ -524,16 +521,14 @@ def test_locker_should_neither_emit_warnings_nor_raise_error_for_lower_compatibl
older_version = ".".join(
[str(current_version.major), str(current_version.minor - 1)]
)
content = """\
content = f"""\
[metadata]
lock-version = "{version}"
lock-version = "{older_version}"
python-versions = "~2.7 || ^3.4"
content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77"
[metadata.files]
""".format(
version=older_version
)
"""
caplog.set_level(logging.WARNING, logger="poetry.packages.locker")
locker.lock.write(tomlkit.parse(content))
......
......@@ -207,7 +207,7 @@ def test_authenticator_request_retries_on_exception(
mocker: "MockerFixture", config: "Config", http: Type[httpretty.httpretty]
):
sleep = mocker.patch("time.sleep")
sdist_uri = f"https://foo.bar/files/{str(uuid.uuid4())}/foo-0.1.0.tar.gz"
sdist_uri = f"https://foo.bar/files/{uuid.uuid4()!s}/foo-0.1.0.tar.gz"
content = str(uuid.uuid4())
seen = []
......@@ -232,7 +232,7 @@ def test_authenticator_request_raises_exception_when_attempts_exhausted(
mocker: "MockerFixture", config: "Config", http: Type[httpretty.httpretty]
):
sleep = mocker.patch("time.sleep")
sdist_uri = f"https://foo.bar/files/{str(uuid.uuid4())}/foo-0.1.0.tar.gz"
sdist_uri = f"https://foo.bar/files/{uuid.uuid4()!s}/foo-0.1.0.tar.gz"
def callback(*_: Any, **___: Any) -> None:
raise requests.exceptions.ConnectionError(str(uuid.uuid4()))
......@@ -267,7 +267,7 @@ def test_authenticator_request_retries_on_status_code(
attempts: int,
):
sleep = mocker.patch("time.sleep")
sdist_uri = f"https://foo.bar/files/{str(uuid.uuid4())}/foo-0.1.0.tar.gz"
sdist_uri = f"https://foo.bar/files/{uuid.uuid4()!s}/foo-0.1.0.tar.gz"
content = str(uuid.uuid4())
def callback(
......
......@@ -470,10 +470,8 @@ def test_deactivate_non_activated_but_existing(
venv_name = manager.generate_env_name("simple-project", str(poetry.file.parent))
(
Path(tmp_dir)
/ "{}-py{}".format(venv_name, ".".join(str(c) for c in sys.version_info[:2]))
).mkdir()
python = ".".join(str(c) for c in sys.version_info[:2])
(Path(tmp_dir) / f"{venv_name}-py{python}").mkdir()
config.merge({"virtualenvs": {"path": str(tmp_dir)}})
......@@ -485,9 +483,7 @@ def test_deactivate_non_activated_but_existing(
manager.deactivate(NullIO())
env = manager.get()
assert env.path == Path(tmp_dir) / "{}-py{}".format(
venv_name, ".".join(str(c) for c in sys.version_info[:2])
)
assert env.path == Path(tmp_dir) / f"{venv_name}-py{python}"
assert Path("/prefix")
......@@ -502,7 +498,7 @@ def test_deactivate_activated(
del os.environ["VIRTUAL_ENV"]
venv_name = manager.generate_env_name("simple-project", str(poetry.file.parent))
version = Version.parse(".".join(str(c) for c in sys.version_info[:3]))
version = Version.from_parts(*sys.version_info[:3])
other_version = Version.parse("3.4") if version.major == 2 else version.next_minor()
(Path(tmp_dir) / f"{venv_name}-py{version.major}.{version.minor}").mkdir()
(
......@@ -527,9 +523,7 @@ def test_deactivate_activated(
manager.deactivate(NullIO())
env = manager.get()
assert env.path == Path(tmp_dir) / "{}-py{}.{}".format(
venv_name, version.major, version.minor
)
assert env.path == Path(tmp_dir) / f"{venv_name}-py{version.major}.{version.minor}"
assert Path("/prefix")
envs = envs_file.read()
......@@ -928,9 +922,9 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
version = Version.parse(".".join(str(c) for c in sys.version_info[:3]))
poetry.package.python_versions = "^{}".format(
".".join(str(c) for c in sys.version_info[:3])
version = Version.from_parts(*sys.version_info[:3])
poetry.package.python_versions = "^" + ".".join(
str(c) for c in sys.version_info[:3]
)
venv_name = manager.generate_env_name("simple-project", str(poetry.file.parent))
......@@ -966,10 +960,8 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
version = Version.parse(".".join(str(c) for c in sys.version_info[:3]))
poetry.package.python_versions = "~{}".format(
".".join(str(c) for c in (version.major, version.minor - 1, 0))
)
version = Version.from_parts(*sys.version_info[:3])
poetry.package.python_versions = f"~{version.major}.{version.minor-1}.0"
venv_name = manager.generate_env_name("simple-project", str(poetry.file.parent))
check_output = mocker.patch(
......@@ -1087,16 +1079,10 @@ def test_env_finds_the_correct_executables(tmp_dir: str, manager: EnvManager):
manager.build_venv(str(venv_path), with_pip=True)
venv = VirtualEnv(venv_path)
default_executable = expected_executable = "python" + (".exe" if WINDOWS else "")
default_pip_executable = expected_pip_executable = "pip" + (
".exe" if WINDOWS else ""
)
major_executable = "python{}{}".format(
sys.version_info[0], ".exe" if WINDOWS else ""
)
major_pip_executable = "pip{}{}".format(
sys.version_info[0], ".exe" if WINDOWS else ""
)
default_executable = expected_executable = f"python{'.exe' if WINDOWS else ''}"
default_pip_executable = expected_pip_executable = f"pip{'.exe' if WINDOWS else ''}"
major_executable = f"python{sys.version_info[0]}{'.exe' if WINDOWS else ''}"
major_pip_executable = f"pip{sys.version_info[0]}{'.exe' if WINDOWS else ''}"
if (
venv._bin_dir.joinpath(default_executable).exists()
......@@ -1130,11 +1116,11 @@ def test_env_finds_the_correct_executables_for_generic_env(
)
venv = GenericEnv(parent_venv.path, child_env=VirtualEnv(child_venv_path))
expected_executable = "python{}.{}{}".format(
sys.version_info[0], sys.version_info[1], ".exe" if WINDOWS else ""
expected_executable = (
f"python{sys.version_info[0]}.{sys.version_info[1]}{'.exe' if WINDOWS else ''}"
)
expected_pip_executable = "pip{}.{}{}".format(
sys.version_info[0], sys.version_info[1], ".exe" if WINDOWS else ""
expected_pip_executable = (
f"pip{sys.version_info[0]}.{sys.version_info[1]}{'.exe' if WINDOWS else ''}"
)
if WINDOWS:
......@@ -1157,12 +1143,10 @@ def test_env_finds_fallback_executables_for_generic_env(
)
venv = GenericEnv(parent_venv.path, child_env=VirtualEnv(child_venv_path))
default_executable = "python" + (".exe" if WINDOWS else "")
major_executable = "python{}{}".format(
sys.version_info[0], ".exe" if WINDOWS else ""
)
minor_executable = "python{}.{}{}".format(
sys.version_info[0], sys.version_info[1], ".exe" if WINDOWS else ""
default_executable = f"python{'.exe' if WINDOWS else ''}"
major_executable = f"python{sys.version_info[0]}{'.exe' if WINDOWS else ''}"
minor_executable = (
f"python{sys.version_info[0]}.{sys.version_info[1]}{'.exe' if WINDOWS else ''}"
)
expected_executable = minor_executable
if (
......@@ -1179,12 +1163,10 @@ def test_env_finds_fallback_executables_for_generic_env(
venv._bin_dir.joinpath(expected_executable).unlink()
expected_executable = default_executable
default_pip_executable = "pip" + (".exe" if WINDOWS else "")
major_pip_executable = "pip{}{}".format(
sys.version_info[0], ".exe" if WINDOWS else ""
)
minor_pip_executable = "pip{}.{}{}".format(
sys.version_info[0], sys.version_info[1], ".exe" if WINDOWS else ""
default_pip_executable = f"pip{'.exe' if WINDOWS else ''}"
major_pip_executable = f"pip{sys.version_info[0]}{'.exe' if WINDOWS else ''}"
minor_pip_executable = (
f"pip{sys.version_info[0]}.{sys.version_info[1]}{'.exe' if WINDOWS else ''}"
)
expected_pip_executable = minor_pip_executable
if (
......
......@@ -1125,11 +1125,9 @@ def test_exporter_can_export_requirements_txt_with_directory_packages(
with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()
expected = """\
foo @ {}/tests/fixtures/sample_project
""".format(
working_directory.as_uri()
)
expected = f"""\
foo @ {working_directory.as_uri()}/tests/fixtures/sample_project
"""
assert expected == content
......@@ -1193,15 +1191,11 @@ def test_exporter_can_export_requirements_txt_with_nested_directory_packages(
with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()
expected = """\
bar @ {}/tests/fixtures/project_with_nested_local/bar
baz @ {}/tests/fixtures/project_with_nested_local
foo @ {}/tests/fixtures/sample_project
""".format(
working_directory.as_uri(),
working_directory.as_uri(),
working_directory.as_uri(),
)
expected = f"""\
bar @ {working_directory.as_uri()}/tests/fixtures/project_with_nested_local/bar
baz @ {working_directory.as_uri()}/tests/fixtures/project_with_nested_local
foo @ {working_directory.as_uri()}/tests/fixtures/sample_project
"""
assert expected == content
......@@ -1242,11 +1236,9 @@ def test_exporter_can_export_requirements_txt_with_directory_packages_and_marker
with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()
expected = """\
foo @ {}/tests/fixtures/sample_project ; python_version < "3.7"
""".format(
working_directory.as_uri()
)
expected = f"""\
foo @ {working_directory.as_uri()}/tests/fixtures/sample_project ; python_version < "3.7"
"""
assert expected == content
......@@ -1286,11 +1278,9 @@ def test_exporter_can_export_requirements_txt_with_file_packages(
with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()
expected = """\
foo @ {}/tests/fixtures/distributions/demo-0.1.0.tar.gz
""".format(
working_directory.as_uri()
)
expected = f"""\
foo @ {working_directory.as_uri()}/tests/fixtures/distributions/demo-0.1.0.tar.gz
"""
assert expected == content
......@@ -1331,11 +1321,9 @@ def test_exporter_can_export_requirements_txt_with_file_packages_and_markers(
with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()
expected = """\
foo @ {}/tests/fixtures/distributions/demo-0.1.0.tar.gz ; python_version < "3.7"
""".format(
working_directory.as_uri()
)
expected = f"""\
foo @ {working_directory.as_uri()}/tests/fixtures/distributions/demo-0.1.0.tar.gz ; python_version < "3.7"
"""
assert expected == content
......@@ -1570,7 +1558,7 @@ def test_exporter_exports_requirements_txt_with_dev_extras(
with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()
assert content == "{}\n".format("\n".join(expected))
assert content == "\n".join(expected) + "\n"
def test_exporter_exports_requirements_txt_with_legacy_packages_and_duplicate_sources(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment