Skip to content
Closed
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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ repos:
- id: end-of-file-fixer
exclude: ^tests/.*/fixtures/.*
- id: debug-statements
- repo: https://github.com/asottile/pyupgrade
rev: v2.13.0
hooks:
- id: pyupgrade
args:
- --py36-plus
43 changes: 21 additions & 22 deletions get-poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from functools import cmp_to_key
from gzip import GzipFile
from io import UnsupportedOperation
from io import open


try:
Expand Down Expand Up @@ -152,7 +151,7 @@ def colorize(style, text):
if not is_decorated():
return text

return "{}{}\033[0m".format(STYLES[style], text)
return f"{STYLES[style]}{text}\033[0m"


@contextmanager
Expand Down Expand Up @@ -363,7 +362,7 @@ def run(self):
version, upgrade=current_version is not None, file=self._offline_file
)
except subprocess.CalledProcessError as e:
print(colorize("error", "An error has occured: {}".format(str(e))))
print(colorize("error", f"An error has occured: {str(e)}"))
print(e.output.decode())

return e.returncode
Expand Down Expand Up @@ -434,7 +433,7 @@ def _compare_versions(x, y):
)

if self._version and self._version not in releases:
print(colorize("error", "Version {} does not exist.".format(self._version)))
print(colorize("error", f"Version {self._version} does not exist."))

return None, None

Expand Down Expand Up @@ -572,25 +571,25 @@ def _make_lib(self, version):
if platform == "linux2":
platform = "linux"

url = self._base_url + "{}/".format(version)
name = "poetry-{}-{}.tar.gz".format(version, platform)
checksum = "poetry-{}-{}.sha256sum".format(version, platform)
url = self._base_url + f"{version}/"
name = f"poetry-{version}-{platform}.tar.gz"
checksum = f"poetry-{version}-{platform}.sha256sum"

try:
r = urlopen(url + "{}".format(checksum))
r = urlopen(url + f"{checksum}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couldn't this concatenation be like that?

Suggested change
r = urlopen(url + f"{checksum}")
r = urlopen(f"{url}{checksum}")

except HTTPError as e:
if e.code == 404:
raise RuntimeError("Could not find {} file".format(checksum))
raise RuntimeError(f"Could not find {checksum} file")

raise

checksum = r.read().decode()

try:
r = urlopen(url + "{}".format(name))
r = urlopen(url + f"{name}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here too

Suggested change
r = urlopen(url + f"{name}")
r = urlopen(f"{url}{name}")

except HTTPError as e:
if e.code == 404:
raise RuntimeError("Could not find {} file".format(name))
raise RuntimeError(f"Could not find {name} file")

raise

Expand Down Expand Up @@ -692,7 +691,7 @@ def make_bin(self):
if WINDOWS:
python_executable = "python"

f.write(u("#!/usr/bin/env {}\n".format(python_executable)))
f.write(u(f"#!/usr/bin/env {python_executable}\n"))
f.write(u(BIN))

if not WINDOWS:
Expand Down Expand Up @@ -723,14 +722,14 @@ def update_path(self):
# Updating any profile we can on UNIX systems
export_string = self.get_export_string()

addition = "\n{}\n".format(export_string)
addition = f"\n{export_string}\n"

profiles = self.get_unix_profiles()
for profile in profiles:
if not os.path.exists(profile):
continue

with open(profile, "r") as f:
with open(profile) as f:
content = f.read()

if addition not in content:
Expand Down Expand Up @@ -758,8 +757,8 @@ def add_to_fish_path(self):
["fish", "-c", "echo $fish_user_paths"]
).decode("utf-8")
if POETRY_BIN not in fish_user_paths:
cmd = "set -U fish_user_paths {} $fish_user_paths".format(POETRY_BIN)
set_fish_user_path = ["fish", "-c", "{}".format(cmd)]
cmd = f"set -U fish_user_paths {POETRY_BIN} $fish_user_paths"
set_fish_user_path = ["fish", "-c", f"{cmd}"]
subprocess.check_output(set_fish_user_path)
else:
print(
Expand All @@ -774,7 +773,7 @@ def add_to_fish_path(self):
def add_to_windows_path(self):
try:
old_path = self.get_windows_path_var()
except WindowsError:
except OSError:
old_path = None

if old_path is None:
Expand Down Expand Up @@ -824,7 +823,7 @@ def set_windows_path_var(self, value):
HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
u"Environment",
"Environment",
SMTO_ABORTIFHUNG,
5000,
ctypes.byref(result),
Expand All @@ -847,7 +846,7 @@ def remove_from_fish_path(self):
cmd = "set -U fish_user_paths (string match -v {} $fish_user_paths)".format(
POETRY_BIN
)
set_fish_user_path = ["fish", "-c", "{}".format(cmd)]
set_fish_user_path = ["fish", "-c", f"{cmd}"]
subprocess.check_output(set_fish_user_path)

def remove_from_windows_path(self):
Expand All @@ -866,14 +865,14 @@ def remove_from_unix_path(self):
# Updating any profile we can on UNIX systems
export_string = self.get_export_string()

addition = "{}\n".format(export_string)
addition = f"{export_string}\n"

profiles = self.get_unix_profiles()
for profile in profiles:
if not os.path.exists(profile):
continue

with open(profile, "r") as f:
with open(profile) as f:
content = f.readlines()

if addition not in content:
Expand All @@ -894,7 +893,7 @@ def remove_from_unix_path(self):

def get_export_string(self):
path = POETRY_BIN.replace(os.getenv("HOME", ""), "$HOME")
export_string = 'export PATH="{}:$PATH"'.format(path)
export_string = f'export PATH="{path}:$PATH"'

return export_string

Expand Down
20 changes: 9 additions & 11 deletions install-poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def colorize(style, text):
if not is_decorated():
return text

return "{}{}\033[0m".format(STYLES[style], text)
return f"{STYLES[style]}{text}\033[0m"


def string_to_bool(value):
Expand Down Expand Up @@ -282,32 +282,32 @@ def __init__(self) -> None:
self._output = sys.stdout

def move_up(self, lines: int = 1) -> "Cursor":
self._output.write("\x1b[{}A".format(lines))
self._output.write(f"\x1b[{lines}A")

return self

def move_down(self, lines: int = 1) -> "Cursor":
self._output.write("\x1b[{}B".format(lines))
self._output.write(f"\x1b[{lines}B")

return self

def move_right(self, columns: int = 1) -> "Cursor":
self._output.write("\x1b[{}C".format(columns))
self._output.write(f"\x1b[{columns}C")

return self

def move_left(self, columns: int = 1) -> "Cursor":
self._output.write("\x1b[{}D".format(columns))
self._output.write(f"\x1b[{columns}D")

return self

def move_to_column(self, column: int) -> "Cursor":
self._output.write("\x1b[{}G".format(column))
self._output.write(f"\x1b[{column}G")

return self

def move_to_position(self, column: int, row: int) -> "Cursor":
self._output.write("\x1b[{};{}H".format(row + 1, column))
self._output.write(f"\x1b[{row + 1};{column}H")

return self

Expand Down Expand Up @@ -416,7 +416,7 @@ def run(self) -> int:
try:
self.install(version)
except subprocess.CalledProcessError as e:
print(colorize("error", "An error has occured: {}".format(str(e))))
print(colorize("error", f"An error has occured: {str(e)}"))
print(e.output.decode())

return e.returncode
Expand Down Expand Up @@ -684,9 +684,7 @@ def _compare_versions(x, y):
)

if self._version and self._version not in releases:
self._write(
colorize("error", "Version {} does not exist.".format(self._version))
)
self._write(colorize("error", f"Version {self._version} does not exist."))

return None, None

Expand Down
3 changes: 1 addition & 2 deletions poetry/console/commands/add.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from typing import Dict
from typing import List

Expand Down Expand Up @@ -222,7 +221,7 @@ def notify_about_existing_packages(self, existing_packages: List[str]) -> None:
"The following packages are already present in the pyproject.toml and will be skipped:\n"
)
for name in existing_packages:
self.line(" • <c1>{name}</c1>".format(name=name))
self.line(f" • <c1>{name}</c1>")
self.line(
"\nIf you want to update it to the latest compatible version, you can use `poetry update package`.\n"
"If you prefer to upgrade it to the latest available version, you can use `poetry add package@latest`.\n"
Expand Down
16 changes: 7 additions & 9 deletions poetry/console/commands/cache/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def handle(self) -> int:
try:
cache_dir.relative_to(REPOSITORY_CACHE_DIR)
except ValueError:
raise ValueError("{} is not a valid repository cache".format(root))
raise ValueError(f"{root} is not a valid repository cache")

cache = CacheManager(
{
Expand All @@ -47,17 +47,15 @@ def handle(self) -> int:
)

if not os.path.exists(str(cache_dir)):
self.line("No cache entries for {}".format(parts[0]))
self.line(f"No cache entries for {parts[0]}")
return 0

# Calculate number of entries
entries_count = 0
for path, dirs, files in os.walk(str(cache_dir)):
entries_count += len(files)

delete = self.confirm(
"<question>Delete {} entries?</>".format(entries_count)
)
delete = self.confirm(f"<question>Delete {entries_count} entries?</>")
if not delete:
return 0

Expand All @@ -71,14 +69,14 @@ def handle(self) -> int:
package = parts[1]
version = parts[2]

if not cache.has("{}:{}".format(package, version)):
self.line("No cache entries for {}:{}".format(package, version))
if not cache.has(f"{package}:{version}"):
self.line(f"No cache entries for {package}:{version}")
return 0

delete = self.confirm("Delete cache entry {}:{}".format(package, version))
delete = self.confirm(f"Delete cache entry {package}:{version}")
if not delete:
return 0

cache.forget("{}:{}".format(package, version))
cache.forget(f"{package}:{version}")
else:
raise ValueError("Invalid cache key")
2 changes: 1 addition & 1 deletion poetry/console/commands/cache/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def handle(self) -> Optional[int]:
caches = list(sorted(REPOSITORY_CACHE_DIR.iterdir()))
if caches:
for cache in caches:
self.line("<info>{}</>".format(cache.name))
self.line(f"<info>{cache.name}</>")
return 0

self.line("<warning>No caches found</>")
4 changes: 2 additions & 2 deletions poetry/console/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def handle(self) -> int:
return 0

for error in check_result["errors"]:
self.line("<error>Error: {}</error>".format(error))
self.line(f"<error>Error: {error}</error>")

for error in check_result["warnings"]:
self.line("<warning>Warning: {}</warning>".format(error))
self.line(f"<warning>Warning: {error}</warning>")

return 1
Loading