There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
""" | ||
Normalise an mpconfigport.h file by ordering config options, and removing any | ||
that are the defaults. The standard order and defaults come from py/mpconfig.h. | ||
|
||
Run from the root of the repository. | ||
|
||
Example usage: | ||
|
||
python3 tools/normalise_mpconfigport.py ports/stm32/mpconfigport.h | ||
|
||
""" | ||
|
||
import collections, re, sys | ||
|
||
|
||
regexs = ( | ||
("define", re.compile(r"#define (MICROPY_[A-Z0-9_]+) +(.+)")), | ||
("comment", re.compile(r"// (Extended modules)")), | ||
("comment_strip", re.compile(r"/\* (.+) \*/")), | ||
) | ||
|
||
|
||
def match_line(line): | ||
for kind, regex in regexs: | ||
m = regex.match(line) | ||
if m: | ||
return kind, m | ||
return None, None | ||
|
||
|
||
def parse_config(filename, parse_section_names=False): | ||
config = collections.OrderedDict() | ||
section_num = 0 | ||
section_comment = None | ||
with open(filename) as f: | ||
for line in f: | ||
kind, match = match_line(line) | ||
if kind == "define": | ||
if section_comment: | ||
if parse_section_names: | ||
config[f"_section{section_num}"] = section_comment | ||
section_num += 1 | ||
section_comment = None | ||
config[match.group(1)] = match.group(2) | ||
elif kind == "comment": | ||
section_comment = match.group(1) | ||
elif kind == "comment_strip": | ||
section_comment = match.group(1).strip() | ||
|
||
return config | ||
|
||
|
||
def main(): | ||
defaults = parse_config("py/mpconfig.h", True) | ||
port = parse_config(sys.argv[1]) | ||
|
||
# Print out the standard config options in order. | ||
for k, v in defaults.items(): | ||
if k.startswith("_section"): | ||
print() | ||
print(f"// {v}") | ||
continue | ||
if k in port: | ||
if port[k] != v: | ||
print("#define {:40}{}".format(k, port[k])) | ||
del port[k] | ||
|
||
# Print out any remaining config options that are not standard ones. | ||
if port: | ||
print() 4468 | ||
for k, v in port.items(): | ||
print("#define {:40}{}".format(k, v)) | ||
|
||
|
||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
tools/normalise_mpconfigport.py: Add script to normalise config (WIP) #7538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
tools/normalise_mpconfigport.py: Add script to normalise config (WIP) #7538
Changes from all commits
048bc42
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.