-
Notifications
You must be signed in to change notification settings - Fork 4
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
Migrate to pyproject.toml and hatchling #6
Conversation
Using Hatch https://hatch.pypa.io/
Only flake8 does not support pyproject.toml so it stays for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, moving from setup.py to pyproject.toml is great! Since the CI setups of elasticsearch-py and elasticsearch-serverless-are based on what urllib3 was doing in 2021, I have opinions. 😬
The main thing I'm wondering about is inlining scripts inside pyproject.toml
. While setup.py is bad because it requires executing arbitrary Python code and building a wheel to learn about simple facts such as the package name, I don't think everything should move to pyproject.toml:
- In particular, I think keeping scripts in a Python file where they can be highlighted, linted, formatted and expanded easily is a better option. (And I like using scripts, I find using nox much simpler than tox, which planned at some point to support scripts too, but apparently that never happened.)
- Additionally, moving to Hatch the project manager is harder to undo that just moving to Hatchling the build backend. I prefer using small tools that can do one thing well.
But then I am biased as I've been using nox for a long time now. And apparently Hatch is so easy to use that this is the second time I'm seeing a coworker moving to it :) elastic/rally-tracks#289
@pquentin Good points! And all things I was hoping to uncover by opening a draft PR. I'm more than happy to keep things in Nox. I really like how Hatch manages envs and their dependencies, but it's more of a convenience than a necessity. Part of the inspiration here was that elasticsearch-py has an open issue where Seth seconded the use of Hatch to help migrate away from setup.py. But your point about just using Hatchling for packaging strikes a nice balance. I'll see about shifting back that direction. |
@pquentin cleaned things up a bit. what do you think? |
I kept Hatch as a dependency for version bumping and build targets, but I assume I could drop |
Not needed if we're not aligning versions with the Elastic stack for serverless. See elastic/devtools-team#618
Actually I just talked myself out of |
Use optional dependencies in pyproject.toml instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Is there any way to test the CI parts?
.readthedocs.yml
Outdated
jobs: | ||
pre_install: | ||
- "python -m pip install sphinx-rtd-theme sphinx-autodoc-typehints" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed since those dependencies are now in docs extra requirements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nox -s docs
was failing due to missing config values that sphinx-rtd-theme
needed. I just looked into it more closely and needed to enforce versions on sphinx and the theme to work around it. Fixed in 16c972f.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wondered what was going and investigated too to be able to tell when we can drop the pins. As you've noticed, the root cause is that the two sphinx packages that we install currently require incompatible versions of Sphinx:
- sphinx-rtd-theme 1.2.2 (the last release) supports Sphinx >=1.6,<7: https://github.com/readthedocs/sphinx_rtd_theme/blob/9899ee4ee2f547f81e51297dc12317f018e62fdd/setup.cfg#L48
- sphinx-autodoc-typehints 1.24.0 (the last release) supports Sphinx>=7.0.1: https://github.com/tox-dev/sphinx-autodoc-typehints/blob/a41715889940c8f8c37b32bac59db9416f47c958/pyproject.toml#L41
Then pip considers that the plugin "at fault" is sphinx-rtd-theme. I'm not sure how the resolver works, maybe it's the only package that does not support Sphinx 7. Anyway, pip then tries to find a version that does in fact support Sphinx 7:
INFO: pip is looking at multiple versions of sphinx-rtd-theme to determine which version is compatible with other requirements. This could take a while.
Collecting sphinx-rtd-theme (from elasticsearch-serverless==0.1.0)
Obtaining dependency information for sphinx-rtd-theme from https://files.pythonhosted.org/packages/c2/73/946cdd32f29c87843edaa059b9fc52ab9267d1137b3a76dee1d5
9d02a01a/sphinx_rtd_theme-1.2.1-py2.py3-none-any.whl.metadata
Using cached sphinx_rtd_theme-1.2.1-py2.py3-none-any.whl.metadata (4.5 kB)
Using cached sphinx_rtd_theme-1.2.0-py2.py3-none-any.whl (2.8 MB)
Using cached sphinx_rtd_theme-1.1.1-py2.py3-none-any.whl (2.8 MB)
Using cached sphinx_rtd_theme-1.1.0-py2.py3-none-any.whl (2.8 MB)
Using cached sphinx_rtd_theme-1.0.0-py2.py3-none-any.whl (2.8 MB)
Using cached sphinx_rtd_theme-0.5.2-py2.py3-none-any.whl (9.1 MB)
Using cached sphinx_rtd_theme-0.5.1-py2.py3-none-any.whl (2.8 MB)
Since sphinx-rtd-theme 0.5.1 is the latest release without bounds, pip considers that it does support Sphinx 7. And then installs it. This is something we are likely to continue seeing in the future, given:
- Sphinx releasing new major version ~every 6 months
- sphinx-autodoc-typehints always requiring the latest Sphinx release (Sudden incompatibility for Sphinx<7 tox-dev/sphinx-autodoc-typehints#371)
- sphinx-rtd-theme being a bit behind on latest Sphinx support (1.3.0 is not released yet)
I can see two ways out of this issue:
-
We can use a different theme like which updates faster than sphinx-autodoc-typehints (but does not use a lower bound): https://github.com/pradyunsg/furo.
-
We can pin Sphinx ourselves, and periodically bump to the latest version that sphinx-rtd-theme supports:
docs = [ # sphinx-rtd-theme does not support Sphinx 7 yet "sphinx<7", "sphinx-rtd-theme", "sphinx-autodoc-typehints", ]
I think I prefer the second approach. Although it does not have to block the pull request, we can do this later as this pull request is otherwise ready to be merged IMO.
Co-authored-by: Quentin Pradet <quentin.pradet@gmail.com>
Co-authored-by: Quentin Pradet <quentin.pradet@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great now! Thanks for iterating.
Of course! Thanks for all the useful feedback @pquentin. First time migrating from a setup.py. 😄 |
I used Hatch to convert
setup.py
intopyproject.toml
, and then did some cleanup to drop dev-requirements.txt, ensurenox
scripts keep running, etc.