python - How to add a format script in a Poetry project that runs the Black formatter over a specific directory? - Stack Overflo

admin2025-04-18  4

I would like to add a script to my Poetry project that runs the Black formatter over a specific directory. I wrote this:

[tool.poetry.scripts]
    format-scripts = "black:main scripts/**/*.py"

But it doesn't work. I am getting this error when running poetry run format-scripts:

Warning: 'format-scripts' is an entry point defined in pyproject.toml, but it's not installed as a script. You may get improper `sys.argv[0]`.

The support to run uninstalled scripts will be removed in a future release.

Run `poetry install` to resolve and get rid of this message.

  File "<string>", line 1
    import sys; from importlib import import_module; sys.argv = ['format-scripts']; sys.exit(import_module('black').main scripts/**/*.py())
                                                                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

I tried removing the scripts/**/*.py path from the script, like so:

[tool.poetry.scripts]
    format-scripts = "black:main"

This made it work, but I'm still getting the warning:

poetry run format-scripts scripts/**/*.py
Warning: 'format-scripts' is an entry point defined in pyproject.toml, but it's not installed as a script. You may get improper `sys.argv[0]`.

The support to run uninstalled scripts will be removed in a future release.

Run `poetry install` to resolve and get rid of this message.

All done! ✨ 
转载请注明原文地址:http://www.anycun.com/QandA/1744966278a90143.html