-
Notifications
You must be signed in to change notification settings - Fork 0
feat: first draft #1
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
9 commits
Select commit
Hold shift + click to select a range
1ad9202
feat: first draft
henryiii 0fa1b2a
feat: add schema
henryiii e615723
Apply suggestions from code review
henryiii 3380ce7
fix: some changes from impl in scikit-build-core
henryiii 1379043
style: ignore a few pylint codes
henryiii 4567756
small-changes to draft (#8)
aryamanjeendgar f412a95
Draft changes (#9)
aryamanjeendgar 27c766f
chore: admonition-syntax for warning (#10)
aryamanjeendgar e111a9f
style: pre-commit fixes
pre-commit-ci[bot] 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
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,14 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
|
|
||
| if sys.version_info < (3, 11): | ||
| from tomli import load | ||
| else: | ||
| from tomllib import load | ||
|
|
||
| __all__ = ["load"] | ||
|
|
||
|
|
||
| def __dir__() -> list[str]: | ||
| return __all__ |
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,79 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import importlib | ||
| import sys | ||
| from collections.abc import Generator, Iterable, Mapping | ||
| from pathlib import Path | ||
| from typing import Any, Union | ||
|
|
||
| from ._compat.typing import Protocol | ||
|
|
||
| __all__ = ["load_provider", "load_dynamic_metadata"] | ||
|
|
||
|
|
||
| def __dir__() -> list[str]: | ||
| return __all__ | ||
|
|
||
|
|
||
| class DynamicMetadataProtocol(Protocol): | ||
| def dynamic_metadata( | ||
| self, fields: Iterable[str], settings: dict[str, Any] | ||
| ) -> dict[str, Any]: | ||
| ... | ||
|
|
||
|
|
||
| class DynamicMetadataRequirementsProtocol(DynamicMetadataProtocol, Protocol): | ||
| def get_requires_for_dynamic_metadata(self, settings: dict[str, Any]) -> list[str]: | ||
| ... | ||
|
|
||
|
|
||
| class DynamicMetadataWheelProtocol(DynamicMetadataProtocol, Protocol): | ||
| def dynamic_wheel( | ||
| self, field: str, settings: Mapping[str, Any] | None = None | ||
| ) -> bool: | ||
| ... | ||
|
|
||
|
|
||
| class DynamicMetadataRequirementsWheelProtocol( | ||
| DynamicMetadataRequirementsProtocol, DynamicMetadataWheelProtocol, Protocol | ||
| ): | ||
| ... | ||
|
|
||
|
|
||
| DMProtocols = Union[ | ||
| DynamicMetadataProtocol, | ||
| DynamicMetadataRequirementsProtocol, | ||
| DynamicMetadataWheelProtocol, | ||
| DynamicMetadataRequirementsWheelProtocol, | ||
| ] | ||
|
|
||
|
|
||
| def load_provider( | ||
| provider: str, | ||
| provider_path: str | None = None, | ||
| ) -> DMProtocols: | ||
| if provider_path is None: | ||
| return importlib.import_module(provider) | ||
|
|
||
| if not Path(provider_path).is_dir(): | ||
| msg = "provider-path must be an existing directory" | ||
| raise AssertionError(msg) | ||
|
|
||
| try: | ||
| sys.path.insert(0, provider_path) | ||
| return importlib.import_module(provider) | ||
| finally: | ||
| sys.path.pop(0) | ||
|
|
||
|
|
||
| def load_dynamic_metadata( | ||
| metadata: Mapping[str, Mapping[str, str]] | ||
| ) -> Generator[tuple[str, DMProtocols | None, dict[str, str]], None, None]: | ||
| for field, orig_config in metadata.items(): | ||
| if "provider" in orig_config: | ||
| config = dict(orig_config) | ||
| provider = config.pop("provider") | ||
| provider_path = config.pop("provider-path", None) | ||
| yield field, load_provider(provider, provider_path), config | ||
| else: | ||
| yield field, None, dict(orig_config) |
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,58 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from .._compat import tomllib | ||
|
|
||
| __all__ = ["dynamic_metadata", "get_requires_for_dynamic_metadata"] | ||
|
|
||
|
|
||
| def __dir__() -> list[str]: | ||
| return __all__ | ||
|
|
||
|
|
||
| def dynamic_metadata( | ||
| field: str, | ||
| settings: dict[str, list[str] | str] | None = None, | ||
| ) -> dict[str, str | None]: | ||
| from hatch_fancy_pypi_readme._builder import build_text | ||
| from hatch_fancy_pypi_readme._config import load_and_validate_config | ||
|
|
||
| if field != "readme": | ||
| msg = "Only the 'readme' field is supported" | ||
| raise ValueError(msg) | ||
|
|
||
| if settings: | ||
| msg = "No inline configuration is supported" | ||
| raise ValueError(msg) | ||
|
|
||
| with Path("pyproject.toml").open("rb") as f: | ||
| pyproject_dict = tomllib.load(f) | ||
|
|
||
| config = load_and_validate_config( | ||
| pyproject_dict["tool"]["hatch"]["metadata"]["hooks"]["fancy-pypi-readme"] | ||
| ) | ||
|
|
||
| if hasattr(config, "substitutions"): | ||
| try: | ||
| # We don't have access to the version at this point | ||
| text = build_text(config.fragments, config.substitutions, "") | ||
| except TypeError: | ||
| # Version 23.2.0 and before don't have a version field | ||
| # pylint: disable-next=no-value-for-parameter | ||
| text = build_text(config.fragments, config.substitutions) | ||
| else: | ||
| # Version 22.3 does not have fragment support | ||
| # pylint: disable-next=no-value-for-parameter | ||
| text = build_text(config.fragments) # type: ignore[call-arg] | ||
|
|
||
| return { | ||
| "content-type": config.content_type, | ||
| "text": text, | ||
| } | ||
|
|
||
|
|
||
| def get_requires_for_dynamic_metadata( | ||
| _settings: dict[str, object] | None = None, | ||
| ) -> list[str]: | ||
| return ["hatch-fancy-pypi-readme>=22.3"] |
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.