Modernize packaging

Switch to pyproject.toml packaging, using hatchling.

- Replace all uses of setup.py with updated equivalent
- BREAKING: Change extra name `amazon_ses` to
  `amazon-ses`, to comply with Python packaging
  name normalization
- Use hatch custom build hook to freeze version number
  in readme (previously custom setup.py code)
- Move separate requirements for dev, docs, tests
  into their own requirements.txt files
- Fix AnymailImproperlyInstalled to correctly refer
  to package extra name
- Update testing documentation
- Update docs readme rendering to match PyPI
  (and avoid setup.py)
- In tox tests, use isolated builds and update pip
- Remove AUTHORS.txt (it just referred to GitHub)
This commit is contained in:
Mike Edmunds
2023-05-03 16:55:08 -07:00
committed by GitHub
parent 9fba58237d
commit e8df0ec8e0
31 changed files with 418 additions and 292 deletions

43
hatch_build.py Normal file
View File

@@ -0,0 +1,43 @@
# Hatch custom build hook that generates dynamic readme.
import re
from pathlib import Path
from hatchling.metadata.plugin.interface import MetadataHookInterface
def freeze_readme_versions(text: str, version: str) -> str:
"""
Rewrite links in readme text to refer to specific version.
(This assumes version X.Y will be tagged "vX.Y" in git.)
"""
release_tag = f"v{version}"
return re.sub(
# (?<=...) is "positive lookbehind": must be there, but won't get replaced
# GitHub Actions build status: branch=main --> branch=vX.Y.Z:
r"(?<=branch[=:])main"
# ReadTheDocs links: /stable --> /vX.Y.Z:
r"|(?<=/)stable"
# ReadTheDocs badge: version=stable --> version=vX.Y.Z:
r"|(?<=version=)stable",
release_tag,
text,
)
class CustomMetadataHook(MetadataHookInterface):
def update(self, metadata):
"""
Update the project table's metadata.
"""
readme_path = Path(self.root) / self.config["readme"]
content_type = self.config.get("content-type", "text/x-rst")
version = metadata["version"]
readme_text = readme_path.read_text()
readme_text = freeze_readme_versions(readme_text, version)
metadata["readme"] = {
"content-type": content_type,
"text": readme_text,
}