Skip to content

Commit

Permalink
Address reviews #1477:
Browse files Browse the repository at this point in the history
- Replace the map-based dispatching with more readable blocks
- Catch (unlikely) invalid style value now that it won't raise a KeyError,
  although it should be caught earlier via Click args
- Add a little more comment context to the use of 24 as column size

Co-authored-by: Albert Tugushev <albert@tugushev.ru>
  • Loading branch information
AndydeCleyre and atugushev committed Sep 20, 2021
1 parent 368e1e4 commit b6162c6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions piptools/writer.py
Expand Up @@ -277,13 +277,15 @@ def _format_requirement(
required_by.add(_comes_from_as_string(ireq))

if required_by:
annotation = {
"split": annotation_style_split,
"line": annotation_style_line,
}[self.annotation_style](required_by)
sep = {"split": "\n ", "line": "\n " if ireq_hashes else " "}[
self.annotation_style
]
if self.annotation_style == "split":
annotation = annotation_style_split(required_by)
sep = "\n "
elif self.annotation_style == "line":
annotation = annotation_style_line(required_by)
sep = "\n " if ireq_hashes else " "
else: # pragma: no cover
raise ValueError("Invalid value for annotation style")
# 24 is one reasonable column size to use here, that we've used in the past
lines = f"{line:24}{sep}{comment(annotation)}".splitlines()
line = "\n".join(ln.rstrip() for ln in lines)

Expand Down

0 comments on commit b6162c6

Please sign in to comment.