Skip to content

Commit d6dcc83

Browse files
$HFPR_PACKAGE_NAME is now replaced with package name in readme substitutions (#64)
* `$HFPR_PACKAGE_NAME` is now replaced with package name in readme substitutions * Add PR number to changelog
1 parent faccab5 commit d6dcc83

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ The **third number** is for emergencies when we need to start branches for older
1313

1414
## [Unreleased](https://github.com/hynek/hatch-fancy-pypi-readme/compare/24.1.0...HEAD)
1515

16+
### Added
17+
18+
- `$HFPR_PACKAGE_NAME` is now replaced by the package name in the PyPI readme.
19+
The version is not available in CLI mode, therefore it's replaced by the dummy value of `your-package`.
20+
[#64](https://github.com/hynek/hatch-fancy-pypi-readme/pull/64)
21+
1622
### Removed
1723

1824
- Support for Python 3.7.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ Again, please check out our [example configuration][example-config] for a comple
243243

244244
### Referencing Packaging Metadata
245245

246-
If the final readme contains the string `$HFPR_VERSION`, it is replaced by the current package version.
246+
If the final readme contains the strings `$HFPR_PACKAGE_NAME` or `$HFPR_VERSION`, they will be replaced by the current package name or version.
247247

248248
When running *hatch-fancy-pypi-readme* in CLI mode (as described in the next section), packaging metadata is not available.
249-
In that case `$HFPR_VERSION` is hardcoded to `42.0` so you can still test your readme.
249+
In that case `$HFPR_PACKAGE_NAME` is hardcoded to `your-package`, and `$HFPR_VERSION` to `42.0`, so you can still test your readme.
250250

251251

252252
## CLI Interface

src/hatch_fancy_pypi_readme/_builder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
def build_text(
1616
fragments: list[Fragment],
1717
substitutions: list[Substituter],
18+
package_name: str = "",
1819
version: str = "",
1920
) -> str:
2021
"""
@@ -26,4 +27,6 @@ def build_text(
2627
for sub in substitutions:
2728
text = sub.substitute(text)
2829

29-
return text.replace("$HFPR_VERSION", version)
30+
return text.replace("$HFPR_PACKAGE_NAME", package_name).replace(
31+
"$HFPR_VERSION", version
32+
)

src/hatch_fancy_pypi_readme/_cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ def cli_run(
6565
+ "\n".join(f"- {msg}" for msg in e.errors),
6666
)
6767

68-
print(build_text(config.fragments, config.substitutions, "42.0"), file=out)
68+
print(
69+
build_text(
70+
config.fragments, config.substitutions, "your-package", "42.0"
71+
),
72+
file=out,
73+
)
6974

7075

7176
def _fail(msg: str) -> NoReturn:

src/hatch_fancy_pypi_readme/hooks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def update(self, metadata: dict[str, Any]) -> None:
2727
"text": build_text(
2828
config.fragments,
2929
config.substitutions,
30+
package_name=metadata.get("name", ""),
3031
version=metadata.get("version", ""),
3132
),
3233
}

tests/test_builder.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ def test_single_text_fragment(self):
1111
"""
1212
A single text fragment becomes the readme.
1313
"""
14-
assert "This is the README for 1.0!" == build_text(
15-
[TextFragment("This is the README for $HFPR_VERSION!")], [], "1.0"
14+
assert "This is the README for your-package 1.0!" == build_text(
15+
[
16+
TextFragment(
17+
"This is the README for $HFPR_PACKAGE_NAME $HFPR_VERSION!"
18+
)
19+
],
20+
[],
21+
"your-package",
22+
"1.0",
1623
)
1724

1825
def test_multiple_text_fragment(self):
@@ -26,5 +33,6 @@ def test_multiple_text_fragment(self):
2633
TextFragment("This is the README!"),
2734
],
2835
[],
36+
"your-package",
2937
"1.0",
3038
)

0 commit comments

Comments
 (0)