Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
branchv marked this conversation as resolved.
Resolved
inline-quotes = double
# Allow omission of a return type hint for __init__ if at least one argument is annotated
# used by flake8-annotations
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ def get(self, setting_name: str, default: Any = None) -> Any:
# 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))
Expand Down
10 changes: 3 additions & 7 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@

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
Expand Down
4 changes: 1 addition & 3 deletions src/poetry/console/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def handle(self) -> None:

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)
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/cache/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def handle(self) -> int:
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)):
Expand Down
26 changes: 11 additions & 15 deletions src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def handle(self) -> Optional[int]:
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]
Expand Down Expand Up @@ -270,7 +270,7 @@ def handle(self) -> Optional[int]:

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,
Expand Down Expand Up @@ -307,19 +307,16 @@ def _list_configuration(self, config: Dict, raw: Dict, k: str = "") -> None:

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>"
Expand Down Expand Up @@ -361,12 +358,11 @@ def _get_setting(
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)

Expand Down
4 changes: 1 addition & 3 deletions src/poetry/console/commands/debug/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def handle(self) -> int:
"\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}</>",
]
)
)
Expand Down
5 changes: 2 additions & 3 deletions src/poetry/console/commands/env/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ def _display_complete_info(self, env: "Env") -> None:
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}</>",
]
Expand Down
16 changes: 5 additions & 11 deletions src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ def handle(self) -> int:
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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a common enough pattern that I'm wondering if it's worth factoring out into a helper.

Something like version_specifier_for(specifier='^', minor=True, patch=False) (this API sucks, please do better 😄).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in some places, it was easier to use Version.from_parts(*sys.version_info[:3]). i experimented with the helper below, but wanted to explore if it made more sense to use the Version class everywhere. note i've left the helper out of this pr to avoid delaying it longer:

def fmt_version(
    version: Tuple[int, int, int],
    precision: Literal["major", "minor", "patch"] = "patch",
) -> str:
    major, minor, patch, *_ = version
    if precision == "major":
        return f"{major}"
    elif precision == "minor":
        return f"{major}.{minor}"
    else:
        return f"{major}.{minor}.{patch}"

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)
Expand Down Expand Up @@ -282,9 +280,7 @@ def _determine_requirements(
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(
Expand Down Expand Up @@ -314,9 +310,7 @@ def _determine_requirements(
)

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
Expand Down
28 changes: 10 additions & 18 deletions src/poetry/console/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,32 +176,24 @@ def handle(self) -> int:
# 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("")
return 0

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
10 changes: 3 additions & 7 deletions src/poetry/console/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def handle(self) -> None:
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"
Expand All @@ -64,9 +64,7 @@ def handle(self) -> None:
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])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above note about version specifier strings.


layout_ = layout_(
name,
Expand All @@ -83,7 +81,5 @@ def handle(self) -> None:
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()}</>"
)
25 changes: 9 additions & 16 deletions src/poetry/console/commands/plugin/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def handle(self) -> int:
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: {
Expand Down Expand Up @@ -57,27 +58,21 @@ def handle(self) -> int:

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)
Expand All @@ -87,9 +82,7 @@ def handle(self) -> int:
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
4 changes: 2 additions & 2 deletions src/poetry/console/commands/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def handle(self) -> Optional[int]:
# 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>")

Expand Down
4 changes: 1 addition & 3 deletions src/poetry/console/commands/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ def handle(self) -> int:
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
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/console/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def run_script(self, script: Union[str, dict], args: str) -> Any:
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)
4 changes: 1 addition & 3 deletions src/poetry/console/commands/self/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ def handle(self) -> int:

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
Expand Down
3 changes: 1 addition & 2 deletions src/poetry/console/commands/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def handle(self) -> None:
) == 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
Expand Down
Loading