Skip to content

ament_black cannot parse python 3.10 code #4

@LeviTranstrum

Description

@LeviTranstrum

Hello, I am implementing ament_black as a pytest to run on all my ROS packages when colcon test is called. It works wonderfully well - except for one package which contains a file with python 3.10 code. This file causes ament_black to fail with the message, "The invocation of 'black' failed with error code 123".

When I run black on the same file, its output is a little more descriptive:

error: cannot format driver.py: Cannot parse: 189:18: match request.operation: Consider using --target-version py310 to parse Python 3.10 code. Oh no! 💥 💔 💥 1 file failed to reformat.

The suggested --target-version flag works with black, but ament_black accepts no such flag. I've dug through your documentation and code and can't seem to find any option to configure the target version.

Your ament_black/main.py seems to suggest that a --config flag can be passed in to set the path to a config file, however, ament_black doesn't seem to accept this flag.

my test_black.py configuration is below:

`from ament_black.main import main

def test_black():
rc = main(
argv=[
"--xunit-file",
"black.xunit.xml",
"."
]
)
assert rc == 0, "black failed with error code %d" % rc`

Is there a way to configure ament_black to understand this file, or at least skip it (without having to manually set the path to every other .py file in the package)?

Any help would be appreciated - I'm new at this, but ament_black has already been incredibly useful especially alongside other ament_lint packages. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions