-
Notifications
You must be signed in to change notification settings - Fork 447
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
Parse settings from pyproject.toml #777
Comments
@akx @benselme @blagasz @kvesteri @mitsuhiko @sils |
I'd also like to submit a patch for the f-string problem. There is not a nice way to do it, but I think we could add a hack for it (which includes a small speed expense) that depends on a config/pyproject setting or environment variable or something to enable. Possibly with a new/different import when you gettext_install. That way it would not be a breaking change, and would avoid slowing down every implementation unless they enabled the feature. |
@miigotu There's no policy or stopper preventing a PR for pyproject.toml. However:
As for "the f-string problem"... I think that's quite unrelated here? |
Yeah I messed with the spec for it a bit last night, and pulled a global options out. Toml allows multiple definitions of the same key, so [tool.babel.config.extractors]
type = "python"
options =
paths =
match = "**/source/*.py"
[tool.babel.config.extractors]
type = "js"
match = "**/js/*.js Works, but I need to think about it more. |
Is my understanding right that if I am not using setuptools I cannot use any config file (even I don't mind not using pyproject.toml - but if |
Ideally nobody should have to add a secondary config file to their project when pyproject.toml is the preferred and python team recommended method for new projects, and handles all possible use cases in the spec for any tools that is willing to implement their config from it. It was sort of the purpose of the pep, to make it so we didn't need 10 different files for configuration cluttering up our source code, and searching all over the place for where settings came from in larger projects. Setuptools is being phased out in most projects. I understand keeping backwards compatibility, but forwards compatibility keeps tools relevant for people who are perfectionists and prefer some level of interoperability and conformity to standards. |
? What are people using to build packages if not setuptools? (enscons?) |
Poetry or flit are the leading tools to package new projects. Peps 517, 518, 621, 631, 633, 660 (and more) provide for pyproject.toml to include project metadata, build system information, dependencies (including extras and optional named groups), configuration for third party tools and requirements in the expanded toml, elimination for the need of requirements.txt, requirements-dev.txt, requirements-win.txt, setup.py, setup.cfg, and numerous other files in a project. Ideally, a project should only need a readme, pyproject.toml, code, and possibly contributing.md and a LICENSE file. Everything else can be handled in the pyproject.toml provided the tools you use read configuration from it. I use about a dozen tools in my project, python-babel is the only one that does not check the pyproject except for .editorconfig. https://github.com/python-poetry/poetry These eliminate the need for multiple tools to build, package, and publish separately. Adding/removing depends, installing (editable or not), multiple virtualenv functionality for testing or building, building/packaging, and pushing to pypi are all handled with one tool. Particularly with poetry, you dont need to use virtualenv, pipenv, tox, twine, pip, setuptools, pyenv, or anything. You can even define custom commands to run, inside the pyproject, using poethepoet. It's a complete tool, that is extensible with plugins. Setuptools itself even works and reads config from pyproject.toml https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html |
FWIW flake8 also doesn't support pyproject.toml PyCQA/flake8#234 Anyway, this project is open to a PR so why not just contribute one? #777 (comment) Edit: Off-topic, but I use the pyenv-virtualenv Homebrew package, which automatically installs pip and setuptools, and pip-tools for my applications (not my packages). Then I use the https://github.com/pypa/gh-action-pypi-publish GitHub Action, which uses twine to publish the package. Don't need pipenv (alternative to pip-tools) or tox (just create a matrix in GitHub Actions). I guess one CLI with many packages as plugins might be preferred to multiple CLIs from many packages... Anyway, +1 to pyproject.toml support – I prefer to have fewer config files, too. |
I disagree - I've been starting to use PyPA's own |
Even though most projects are using something like black/blackd instead of flake8, flake8 does in fact support pyproject.toml |
What are you disagreeing with? Flit and poetry are the two leading projects for pyproject based projects. I never said they are the ONLY options. Even hatch uses pyproject only. |
And as far as your edit, I was listing projects that you absolutely have no need for with flit or poetry, because the functionality of all of them is included. I also publish with GitHub actions (again, there's a thousand ways to do this) The point is that setup.py and setup.cfg are antiquated ways of managing a project, especially if you only have one tool requiring a setup.cfg or .babelrc, when there is a file specifically created and extended for this purpose of configuration of 3rd party tools. Open source software is always going to have many ways to do things. Our job is to make it easier to do them, and simplify the process, to foster future growth of developers and make their life easier while using our software (and the language we are using). Just because something CAN be done a certain way, doesn't mean it is the best way. "Hacking" is literally the process of finding things that can be improved and then improving them. When I get around to this, I'll try to make the PR. Unless someone more familiar with this projects source and coding conventions can get to it before then. |
Apologies, I use flake9 (fork of flake8) that keeps rebased on flake8 and accepts configuration from pyproject.toml, because of their similar reluctance to accept widely accepted PEPs. Silly to me for flake8 to not accept PEPs when the entire project is a result of a PEP specifying code formatting 😂 Afaik, the initial refusal was due to a pip bug when pyproject was initially implemented, that was fixed 2 years ago. Flake8 itself might even work with the pyproject config now, but I have not personally tried it since flake9 has continued to stay up to date and all of the flake8 plugins usually have flake9 counterparts, such as flake9-isort. I don't think that reluctance to adhere to a new configuration format should be a reason to cause a forking event, but some people have ideas in their head sometimes that are hard to change, myself included. It causes projects to become obsolete, which is why things like black are born to replace them. With the advent of f-strings, and not being able to use pyproject, something similar could happen to babel, but I think a few things could just be fixed here instead. I just need to find the time away from work and all of my projects to attempt the PR here. It's my birthday today (40 ugh) so commenting is all I'm going to do for today lol. |
@miigotu Happy birthday! 🍰 Also, yeah, "I disagree" may have been a bit inaccurate - what I meant was that I don't think |
Thanks. So yeah, setuptools does work with pyproject. Setuptools is not really recommended even by pyca or any of the other major groups anymore, but the true successor has not emerged just yet. The few build systems that have came about all have their pros and cons, but that's kind of what the purpose was, for options in how you want your project to be built and distributed. Poetry might be the best option for rust and c extensions once the documentation is improved for that part, but it's definitely a fast changing environment for build and deployment ecosystems at the moment. Heck I might even release a project to work around f-strings in a nice way, and have it disabled unless someone absolutely needs translations because of the performance loss. Point being there is no reason to continue being one of the last major projects that requires a setup.{cfg,py} or a separate configuration file. It's much nicer to have all of that configuration in one place. |
Sorry to bring that up again. It's a old issue but still un-resolved. What is the roadmap to support the new |
@ikus060 You can use
And run pybabel directly. I use a task runner plugin for poetry:
|
For those like @ikus060 who switched from python -c 'from setuptools import setup; setup()' extract_messages |
Maybe there could be a quick hack until someone wants to do a bigger PR: https://tox.wiki/en/latest/config.html#pyproject-toml Something like tox has done there would already enable people to get rid of babel.cfg in their toplevel directory. |
This works fine for me in pyproject.toml, for defining new extractors: [project.entry-points."babel.extractors"]
mystuff = "my.module:extract_mystuff" Combined with a mapping in a |
@jpmckinney Hi there! Since Babel 2.16 (brand new), you should be able to put the mapping configuration in |
@akx What does the configuration look like? There are many approaches discussed in the PR, and I can see the (supposedly working) TOML example in the PR's tests, but if I do: Edit: Ah, I made a typo in my pyproject.toml config. Works like: [[tool.babel.mappings]]
method = "jinja2"
pattern = "**.html"
encoding = "utf-8"
ignore_tags = "script,style"
include_attrs = "alt title summary" |
This project is the last of my dependencies that can only read from setup.cfg. the domains that I think should be used are something like:
pyproject.toml:
The text was updated successfully, but these errors were encountered: