Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
This repo is to support
https://github.com/scikit-build/scikit-build-core/issues/230.

| :exclamation: This plugin is still a WiP!|
|------------------------------------------|

## For users

Every external plugin must specify a "provider", which is a module that provides
the API listed in the next section.

```toml
[tool.dynamic-metadata.v1]
[tool.dynamic-metadata]
<field-name>.provider = "<module>"
```

Expand All @@ -43,7 +46,7 @@ build-backend = "..."
[project]
dynamic = ["version"]

[tool.dynamic-metadata.v1.version]
[tool.dynamic-metadata.version]
provider = "dynamic_metadata.plugins.regex"
input = "src/my_package/__init__.py"
regex = '(?i)^(__version__|VERSION) *= *([\'"])v?(?P<value>.+?)\2'
Expand Down Expand Up @@ -82,7 +85,7 @@ A plugin can return METADATA 2.2 dynamic status:

```python
def dynamic_wheel(field: str, settings: Mapping[str, Any] | None = None) -> bool:
... # Return true if metadata can change from SDist to whlee (METADATA 2.2 feature)
... # Return true if metadata can change from SDist to wheel (METADATA 2.2 feature)
```

If this hook is not implemented, it will default to "false". Note that "version"
Expand Down Expand Up @@ -121,7 +124,7 @@ def dynamic_metadata(
raise RuntimeError("Must set 'input' and/or 'regex' to strings")

input = settings["input"]
# If not explicitly specified in the `tool.dynamic-metadata.v1.<field-name>` table,
# If not explicitly specified in the `tool.dynamic-metadata.<field-name>` table,
# the default regex provided below is used.
regex = settings.get(
"regex", r'(?i)^(__version__|VERSION) *= *([\'"])v?(?P<value>.+?)\2'
Expand All @@ -143,7 +146,7 @@ library provides some helper functions you can use if you want, but you can
implement them yourself following the standard provided or vendor the helper
file (which will be tested and supported).

You should collect the contents of `tool.dynamic-metadata.v1` and load each,
You should collect the contents of `tool.dynamic-metadata` and load each,
something like this:

```python
Expand Down
19 changes: 14 additions & 5 deletions src/dynamic_metadata/plugins/fancy_pypi_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ def dynamic_metadata(
pyproject_dict["tool"]["hatch"]["metadata"]["hooks"]["fancy-pypi-readme"]
)

# Version 22.3 does not have fragment support
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": build_text(config.fragments, config.substitutions)
if hasattr(config, "substitutions")
# pylint: disable-next=no-value-for-parameter
else build_text(config.fragments), # type: ignore[call-arg]
"text": text,
}


Expand Down
20 changes: 19 additions & 1 deletion src/dynamic_metadata/plugins/setuptools_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,25 @@ def dynamic_metadata(
from setuptools_scm import Configuration, _get_version

config = Configuration.from_file("pyproject.toml")
version: str = _get_version(config)
version: str | None
try:
version = _get_version(config, force_write_version_files=True)
except TypeError: # setuptools_scm < 8
version = _get_version(config)

if version is None:
msg = (
f"setuptools-scm was unable to detect version for {config.absolute_root}.\n\n"
"Make sure you're either building from a fully intact git repository "
"or PyPI tarballs. Most other sources (such as GitHub's tarballs, a "
"git checkout without the .git folder) don't contain the necessary "
"metadata and will not work.\n\n"
"For example, if you're using pip, instead of "
"https://github.com/user/proj/archive/master.zip "
"use git+https://github.com/user/proj.git#egg=proj"
)

raise ValueError(msg)

return version

Expand Down
36 changes: 15 additions & 21 deletions src/dynamic_metadata/resources/toml_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@
"type": "object",
"additionalProperties": false,
"properties": {
"v1": {
"type": "object",
"additionalProperties": false,
"properties": {
"version": { "$ref": "#/$defs/entry" },
"description": { "$ref": "#/$defs/entry" },
"readme": { "$ref": "#/$defs/entry" },
"requires-python": { "$ref": "#/$defs/entry" },
"license": { "$ref": "#/$defs/entry" },
"authors": { "$ref": "#/$defs/entry" },
"maintainers": { "$ref": "#/$defs/entry" },
"keywords": { "$ref": "#/$defs/entry" },
"classifiers": { "$ref": "#/$defs/entry" },
"urls": { "$ref": "#/$defs/entry" },
"scripts": { "$ref": "#/$defs/entry" },
"gui-scripts": { "$ref": "#/$defs/entry" },
"entry-points": { "$ref": "#/$defs/entry" },
"dependencies": { "$ref": "#/$defs/entry" },
"optional-dependencies": { "$ref": "#/$defs/entry" }
}
}
"version": { "$ref": "#/$defs/entry" },
"description": { "$ref": "#/$defs/entry" },
"readme": { "$ref": "#/$defs/entry" },
"requires-python": { "$ref": "#/$defs/entry" },
"license": { "$ref": "#/$defs/entry" },
"authors": { "$ref": "#/$defs/entry" },
"maintainers": { "$ref": "#/$defs/entry" },
"keywords": { "$ref": "#/$defs/entry" },
"classifiers": { "$ref": "#/$defs/entry" },
"urls": { "$ref": "#/$defs/entry" },
"scripts": { "$ref": "#/$defs/entry" },
"gui-scripts": { "$ref": "#/$defs/entry" },
"entry-points": { "$ref": "#/$defs/entry" },
"dependencies": { "$ref": "#/$defs/entry" },
"optional-dependencies": { "$ref": "#/$defs/entry" }
},
"$defs": {
"entry": {
Expand Down