Skip to content

Commit

Permalink
Add circuitpython-munge script
Browse files Browse the repository at this point in the history
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
```
jepler committed Jun 17, 2024
1 parent ac0e070 commit a173e39
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions circuitpython_build_tools/scripts/munge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pathlib
from difflib import unified_diff
import click
from ..munge import munge


@click.command
@click.option("--diff/--no-diff", "show_diff", default=False)
@click.option("--munged-version", default="munged-version")
@click.argument("input", type=click.Path(exists=True))
@click.argument("output", type=click.File("w", encoding="utf-8"), default="-")
def main(show_diff, munged_version, input, output):
input_path = pathlib.Path(input)
munged = munge(input, munged_version)
if show_diff:
old_lines = input_path.read_text(encoding="utf-8").splitlines(keepends=True)
new_lines = munged.splitlines(keepends=True)
output.writelines(
unified_diff(
old_lines,
new_lines,
fromfile=input,
tofile=str(input_path.with_suffix(".munged.py")),
)
)
else:
output.write(munged)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -18,5 +18,6 @@
entry_points='''
[console_scripts]
circuitpython-build-bundles=circuitpython_build_tools.scripts.build_bundles:build_bundles
circuitpython-munge=circuitpython_build_tools.scripts.munge:main
'''
)

0 comments on commit a173e39

Please sign in to comment.