Skip to content

Conversation

@bengterik
Copy link

Some generators do not automatically create the output directory which results in this cryptic error when running mavgen for JavaScript, Python and TypeScript.

remoteaero% python3 -m pymavlink.tools.mavgen --lang=Python --wire-protocol=2.0 --output=include/v2.0 message_definitions/v1.0/common.xml
Validating message_definitions/v1.0/common.xml
Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/remote/Documents/git/pymavlink/tools/mavgen.py", line 30, in <module>
    ok = mavgen.mavgen(args, args.definitions)
  File "/Users/remote/Documents/git/pymavlink/generator/mavgen.py", line 229, in mavgen
    if not mavgen_validate(fname):
  File "/Users/remote/Documents/git/pymavlink/generator/mavgen.py", line 198, in mavgen_validate
    with open(xmlfile, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'message_definitions/v1.0/common.xml'

@peterbarker
Copy link
Contributor

Please remove the merge commit

@bengterik bengterik force-pushed the bengterik-auto-create-output-dir branch from 2b2db3d to 68b9f91 Compare September 26, 2025 11:43
Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@peterbarker
Copy link
Contributor

@bengterik well, CI isn't happy. Is it possible some of the generators are creating the output directory without saying, "exists is OK"?

@bengterik
Copy link
Author

Hm, seems like some generators create a file with the same name as the output directory.

Thought I'd solve it for the general case in mavgen.py but I guess I'll add it to the individual JS, TS and Python generators.

@peterbarker do I create a new PR or just commit here on this branch?

@shancock884
Copy link
Contributor

shancock884 commented Oct 1, 2025

For a number of generators (including Python, JS and WLua), the last bit of the output argument is the base part of a filename, rather than a folder name.
In which case, your code could do this instead:

dirname = os.path.dirname(opts.output)
if dirname != '':
    os.makedirs(dirname, exist_ok=True)

That way, the parent folder is sure to exist before writing.

For any generators that are genuinely want the output to be a folder, they should check/create it themselves (C, C++ and Java already seem to do this).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants