Skip to content

Commit a585c58

Browse files
committed
Use emit to yield lines, and render the lines in one place.
1 parent c0f2fe5 commit a585c58

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

__main__.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@
1515
import pathlib
1616

1717
from jaraco.ui.main import main
18-
from more_itertools import flatten
18+
from more_itertools import consume, flatten
1919

2020
from . import imports, pypi
2121

2222

2323
def emit_plain(deps):
24-
print(*deps, sep="\n")
24+
yield from deps
2525

2626

2727
def emit_toml(deps):
28-
print("[project]\nrequires = [")
29-
print(*map(lambda d: f' "{d}",', deps), sep="\n")
30-
print("]")
28+
yield "[project]\nrequires = ["
29+
yield from map(lambda d: f' "{d}",', deps)
30+
yield "]"
3131

3232

3333
def emit_inline(deps):
34-
print("""# ///\n# requires-python = ">=3.8"\n# dependencies = [""")
35-
print(*map(lambda d: f'# "{d}",', deps), sep="\n")
36-
print("# ]\n# ///")
34+
yield """# ///\n# requires-python = ">=3.8"\n# dependencies = ["""
35+
yield from map(lambda d: f'# "{d}",', deps)
36+
yield "# ]\n# ///"
3737

3838

3939
def emit_python(deps):
40-
print("""__requires__ = [""")
41-
print(*map(lambda d: f' "{d}",', deps), sep="\n")
42-
print("]")
40+
yield """__requires__ = ["""
41+
yield from map(lambda d: f' "{d}",', deps)
42+
yield "]"
4343

4444

4545
def parse_glob(spec: str):
@@ -54,4 +54,5 @@ def main(
5454
files = flatten(map(parse_glob, globs))
5555
imps = flatten(map(imports.get_module_imports, files))
5656
deps = (pypi.distribution_for(imp) for imp in imps if not imp.excluded())
57-
globals()[f'emit_{format}'](deps)
57+
lines = globals()[f'emit_{format}'](deps)
58+
consume(map(print, lines))

0 commit comments

Comments
 (0)