Skip to content

Commit a173e39

Browse files
committed
Add circuitpython-munge script
this script can either show the munged version of a Python program, or show the diff. Typical output: ```diff $ circuitpython-munge src/bundle/libraries/helpers/requests/adafruit_requests.py --diff --- src/bundle/libraries/helpers/requests/adafruit_requests.py +++ src/bundle/libraries/helpers/requests/adafruit_requests.munged.py @@ -33,7 +33,7 @@ """ -__version__ = "0.0.0+auto.0" +__version__ = "munged-version" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Requests.git" import errno @@ -41,7 +41,7 @@ import json as json_module -if not sys.implementation.name == "circuitpython": +if 0: from ssl import SSLContext from types import ModuleType, TracebackType from typing import Any, Dict, Optional, Tuple, Type, Union ```
1 parent ac0e070 commit a173e39

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pathlib
2+
from difflib import unified_diff
3+
import click
4+
from ..munge import munge
5+
6+
7+
@click.command
8+
@click.option("--diff/--no-diff", "show_diff", default=False)
9+
@click.option("--munged-version", default="munged-version")
10+
@click.argument("input", type=click.Path(exists=True))
11+
@click.argument("output", type=click.File("w", encoding="utf-8"), default="-")
12+
def main(show_diff, munged_version, input, output):
13+
input_path = pathlib.Path(input)
14+
munged = munge(input, munged_version)
15+
if show_diff:
16+
old_lines = input_path.read_text(encoding="utf-8").splitlines(keepends=True)
17+
new_lines = munged.splitlines(keepends=True)
18+
output.writelines(
19+
unified_diff(
20+
old_lines,
21+
new_lines,
22+
fromfile=input,
23+
tofile=str(input_path.with_suffix(".munged.py")),
24+
)
25+
)
26+
else:
27+
output.write(munged)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
entry_points='''
1919
[console_scripts]
2020
circuitpython-build-bundles=circuitpython_build_tools.scripts.build_bundles:build_bundles
21+
circuitpython-munge=circuitpython_build_tools.scripts.munge:main
2122
'''
2223
)

0 commit comments

Comments
 (0)