Skip to content

Commit

Permalink
Rework CLI tools to use modern install method
Browse files Browse the repository at this point in the history
Modern python installs (i.e. using pyproject.toml) want to install CLI
tools by just pointing to a module method and generating the executables
on install. In order to support this, move the installed tools to the
dtschema module directory renaming them to be modules.

This fixes allowing modifications to the tools on editable installs. The
conversion to pyproject.toml inadvertently broke this.

Signed-off-by: Rob Herring <[email protected]>
  • Loading branch information
robherring committed Nov 10, 2023
1 parent b3f210b commit 7a2305d
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tools/dt-check-compatible → dtschema/check_compatible.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def sigint_handler(signum, frame):

import dtschema

if __name__ == "__main__":
def main():
ap = argparse.ArgumentParser(fromfile_prefix_chars='@',
epilog='Arguments can also be passed in a file prefixed with a "@" character.')
ap.add_argument("compatible_str", nargs='+',
Expand Down
2 changes: 1 addition & 1 deletion tools/dt-doc-validate → dtschema/doc_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def check_doc(filename):

return ret

if __name__ == "__main__":
def main():
ap = argparse.ArgumentParser(fromfile_prefix_chars='@',
epilog='Arguments can also be passed in a file prefixed with a "@" character.')
ap.add_argument("yamldt", nargs='*', type=str,
Expand Down
2 changes: 1 addition & 1 deletion tools/dtb2py → dtschema/dtb2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

strict = False

if __name__ == "__main__":
def main():
ap = argparse.ArgumentParser()
ap.add_argument("dtbfile", type=str, help="Schema directories and/or files")
ap.add_argument('-s', '--schema', help="path to additional additional schema files")
Expand Down
4 changes: 2 additions & 2 deletions tools/dt-validate → dtschema/dtb_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def check_subtree(self, tree, subtree, disabled, nodename, fullname, filename):
def check_dtb(self, filename):
"""Check the given DT against all schemas"""
with open(filename, 'rb') as f:
dt = sg.validator.decode_dtb(f.read())
dt = self.validator.decode_dtb(f.read())
for subtree in dt:
self.check_subtree(dt, subtree, False, "/", "/", filename)

if __name__ == "__main__":
def main():
ap = argparse.ArgumentParser(fromfile_prefix_chars='@',
epilog='Arguments can also be passed in a file prefixed with a "@" character.')
ap.add_argument("dtbs", nargs='*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def item_generator(json_input, lookup_key):
for item_val in item_generator(item, lookup_key):
yield item_val

if __name__ == "__main__":

def main():
ap = argparse.ArgumentParser()
ap.add_argument("yamlfile", type=str,
help="Filename of YAML encoded schema input file")
Expand Down
2 changes: 1 addition & 1 deletion tools/dt-extract-example → dtschema/extract_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def sigint_handler(signum, frame):

yaml = ruamel.yaml.YAML(typ='safe')

if __name__ == "__main__":
def main():
ex = '// empty'
ap = argparse.ArgumentParser()
ap.add_argument("yamlfile", type=str,
Expand Down
2 changes: 1 addition & 1 deletion tools/dt-extract-props → dtschema/extract_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def sigint_handler(signum, frame):

strict = False

if __name__ == "__main__":
def main():
ap = argparse.ArgumentParser()
ap.add_argument("schema_files", type=str, nargs='*',
help="preparsed schema file or list of additional schema files/directories")
Expand Down
5 changes: 2 additions & 3 deletions tools/dt-mk-schema → dtschema/mk_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def sigint_handler(signum, frame):
import json



if __name__ == "__main__":
def main():
ap = argparse.ArgumentParser(fromfile_prefix_chars='@',
epilog='Arguments can also be passed in a file prefixed with a "@" character.')
ap.add_argument("-o", "--outfile", type=str,
Expand All @@ -37,7 +36,7 @@ def sigint_handler(signum, frame):

schemas = dtschema.DTValidator(args.schemas).schemas
if not schemas:
exit(-1)
return -1

if args.outfile:
f = open(args.outfile, 'w', encoding='utf-8')
Expand Down
20 changes: 9 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ dependencies = [
"pylibfdt",
]

[project.scripts]
dt-check-compatible = "dtschema.check_compatible:main"
dt-doc-validate = "dtschema.doc_validate:main"
dt-extract-example = "dtschema.extract_example:main"
dt-extract-props = "dtschema.extract_props:main"
dt-mk-schema = "dtschema.mk_schema:main"
dt-validate = "dtschema.dtb_validate:main"
dtb2py = "dtschema.dtb2py:main"

[project.urls]
Homepage="https://github.com/devicetree-org/dt-schema"
Source="https://github.com/devicetree-org/dt-schema"

[tool.setuptools]
script-files = [
'tools/dt-check-compatible',
'tools/dt-validate',
'tools/dt-doc-validate',
'tools/dt-mk-schema',
'tools/dt-extract-example',
'tools/dt-extract-props',
'tools/dtb2py'
]

0 comments on commit 7a2305d

Please sign in to comment.