-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix build config to exclude sibling packages from distributions #6966
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
72ca110
Stop shipping sibling packages' .pyi stubs in the reflex distributions
masenf 06c1d68
Keep the build hook out of the wheel, anchor the packages' stub artif…
masenf 7d58b9b
Trim the build comments, rewrite the news fragment for its audience
masenf 93b4ef1
Note that fragments may carry an example or a migration snippet
masenf 35f540d
Name the news fragment for its PR
masenf 379f43f
Read the build config through hatchling instead of tomllib
masenf acd74c7
Merge branch 'main' into claude/reflex-pyi-duplication-d1nxt7
masenf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Reduce published wheel and sdist size by removing misplaced generated artifacts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| """Tests for the file selection of the workspace's hatch build configs.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from hatchling.builders.plugin.interface import BuilderInterface | ||
| from hatchling.builders.sdist import SdistBuilder | ||
| from hatchling.builders.wheel import WheelBuilder | ||
|
|
||
| REPO_ROOT = Path(__file__).parents[2] | ||
|
|
||
| # The build hook that regenerates the stubs. The sdist ships it so that the | ||
| # wheel can be built from the sdist; the wheel itself has no use for it. | ||
| BUILD_HOOK = "scripts/hatch_build.py" | ||
|
|
||
| # Everything the reflex distributions are meant to ship: the package and its | ||
| # generated stubs. | ||
| SELECTED = [ | ||
| "reflex/app.py", | ||
| "reflex/__init__.pyi", | ||
| "reflex/components/__init__.pyi", | ||
| ] | ||
|
|
||
| # Sibling workspace packages bundle their own stubs and templates, so none of | ||
| # their files belong in the reflex distributions. Neither do the pyi_generator | ||
| # golden files, which are only test fixtures. | ||
| NOT_SELECTED = [ | ||
| "packages/reflex-components-core/src/reflex_components_core/el/element.py", | ||
| "packages/reflex-components-core/src/reflex_components_core/el/element.pyi", | ||
| "packages/reflex-components-lucide/src/reflex_components_lucide/icon.pyi", | ||
| "packages/reflex-base/src/reflex_base/.templates/web/components/reflex/color_mode.js", | ||
| "tests/units/reflex_base/utils/pyi_generator/golden/var_types.pyi", | ||
| "docs/app/docs.py", | ||
| ] | ||
|
|
||
| BUILDERS = pytest.mark.parametrize( | ||
| "builder_class", [SdistBuilder, WheelBuilder], ids=["sdist", "wheel"] | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def builder(builder_class: type[BuilderInterface]) -> BuilderInterface: | ||
| return builder_class(str(REPO_ROOT)) | ||
|
|
||
|
|
||
| def stub_packages() -> list[Path]: | ||
| """Find the workspace packages that generate stubs at build time. | ||
|
|
||
| Discovery keys off the build hook rather than off the artifact patterns, so | ||
| that dropping a package's patterns fails its assertions below instead of | ||
| quietly dropping it from the parametrization. | ||
|
|
||
| Returns: | ||
| The directory of every package that runs the stub generator. | ||
| """ | ||
| packages = [] | ||
| for path in sorted((REPO_ROOT / "packages").glob("*/pyproject.toml")): | ||
| build_config = SdistBuilder(str(path.parent)).config.build_config | ||
| if "reflex-pyi" in build_config.get("hooks", {}): | ||
| packages.append(path.parent) | ||
| return packages | ||
|
|
||
|
|
||
| @BUILDERS | ||
| @pytest.mark.parametrize("relative_path", SELECTED) | ||
| def test_build_selects_reflex_files(builder: BuilderInterface, relative_path: str): | ||
| assert builder.config.include_path(relative_path) | ||
|
|
||
|
|
||
| @BUILDERS | ||
| @pytest.mark.parametrize("relative_path", NOT_SELECTED) | ||
| def test_build_skips_files_outside_reflex( | ||
| builder: BuilderInterface, relative_path: str | ||
| ): | ||
| assert not builder.config.include_path(relative_path) | ||
|
|
||
|
|
||
| @BUILDERS | ||
| def test_build_walks_only_the_reflex_tree( | ||
| builder: BuilderInterface, builder_class: type[BuilderInterface] | ||
| ): | ||
| allowed = {BUILD_HOOK} if builder_class is SdistBuilder else set() | ||
| selected = { | ||
| Path(included.relative_path).as_posix() | ||
| for included in builder.recurse_included_files() | ||
| } | ||
| outside = sorted( | ||
| path | ||
| for path in selected | ||
| if not path.startswith("reflex/") and path not in allowed | ||
| ) | ||
| assert outside == [] | ||
|
|
||
|
|
||
| def test_sdist_ships_the_build_hook(): | ||
| assert SdistBuilder(str(REPO_ROOT)).config.include_path(BUILD_HOOK) | ||
|
|
||
|
|
||
| def test_wheel_omits_the_build_hook(): | ||
| assert not WheelBuilder(str(REPO_ROOT)).config.include_path(BUILD_HOOK) | ||
|
|
||
|
|
||
| @BUILDERS | ||
| @pytest.mark.parametrize("package", stub_packages(), ids=lambda path: path.name) | ||
| def test_package_ships_only_its_own_stubs( | ||
| builder_class: type[BuilderInterface], package: Path | ||
| ): | ||
| config = builder_class(str(package)).config | ||
| assert config.include_path("src/module/component.pyi") | ||
| # Anything a package keeps beside `src` — fixtures, docs, a vendored | ||
| # checkout — is not part of what it distributes. | ||
| assert not config.include_path("tests/golden.pyi") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.