Skip to content
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

Please add support for pyproject-fmt >= 2 #103

Open
mgorny opened this issue May 13, 2024 · 8 comments
Open

Please add support for pyproject-fmt >= 2 #103

mgorny opened this issue May 13, 2024 · 8 comments

Comments

@mgorny
Copy link
Contributor

mgorny commented May 13, 2024

It seems that pyproject-fmt-2 changed API:

$ python3.12 -c 'from pyproject_fmt import Config, format_pyproject'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'Config' from 'pyproject_fmt' (/usr/lib/python3.12/site-packages/pyproject_fmt/__init__.py)

As a result, ini2toml -F fails with:

$ ini2toml -F pyproject.toml 
usage: ini2toml [-h] [-V] [-o OUTPUT_FILE] [-p PROFILE] [-D TRANSFORMATION [TRANSFORMATION ...]] [-v] [-vv] input_file
ini2toml: error: unrecognized arguments: -F

By the way, could you consider making the option return a clear error instead of not adding it entirely? This is a bit confusing.

@abravalheri abravalheri added the help wanted Extra attention is needed label May 13, 2024
@abravalheri
Copy link
Owner

abravalheri commented May 13, 2024

Thank you very much for reporting the problem.

By the way, could you consider making the option return a clear error instead of not adding it entirely? This is a bit confusing.

This is probably an edge case due to the change in APIs for pyproject_fmt.

I don't think there is an easy and not convoluted way for ini2toml to know that it was installed with the experimental extra but the import does not work because of change in APIs... Do you have any suggestion about that?

@abravalheri abravalheri added the bug Something isn't working label May 13, 2024
@mgorny
Copy link
Contributor Author

mgorny commented May 13, 2024

I don't think there is an easy and not convoluted way for ini2toml to know that it was installed with the experimental extra but the import does not work because of change in APIs... Do you have any suggestion about that?

I merely meant that rather than not having -F option, showing something like "-F option requires pyproject-fmt installed" or likewise.

@abravalheri
Copy link
Owner

I see... I think I found an approach for now that should give some level of error feedback.
Because the formatting is only experimental, I prefer to leave the option hidden if the user did not explicitly install with the "experimental" feature.

@abravalheri
Copy link
Owner

After some discussion with pyproject-fmt maintainers, these are my conclusions:

  • pyproject-fmt>=2 no longer has an API that allows formatting in memory strings. Initially all APIs were removed, but now there is a limited API that allows formatting files.

  • Because we need to format in-memory strings in ini2toml, there would be 3 options:

    a. Use NamedTemporaryFile - I do not wish to pursue this approach
    b. Use pyproject-fmt-rust. The caveat with this approach is that, the API may vary (e.g. it might introduce new configuration fields in the pyproject_fmt_rust.Settings class, or remove/rename old ones). This can cause more long term lack of stability.
    c. Remove support for formatting. The users can call it manually later.

I am a bit tempted with (c) to be honest, but I could give a go to (b) for sometime before deciding to keeping it or removing.

@abravalheri abravalheri removed bug Something isn't working help wanted Extra attention is needed labels May 15, 2024
@mgorny
Copy link
Contributor Author

mgorny commented May 15, 2024

Just to be clear, I'm only maintaining ini2toml in Gentoo as a test dependency of setuptools (and to be honest, we've only added pyproject-fmt, because it was a test dependency of ini2toml). So from my perspective, I don't mind having the functionality removed at all.

@abravalheri
Copy link
Owner

abravalheri commented May 15, 2024

Thanks for confirming @mgorny.

@mtelka, do you have a opinion about this?

@mtelka
Copy link

mtelka commented May 16, 2024

@mtelka, do you have a opinion about this?

I'm on the same page as @mgorny, with only difference: s/Gentoo/OpenIndiana/.

@abravalheri
Copy link
Owner

Perfect, #108 is the direction that I am planning to take.

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

No branches or pull requests

3 participants