Skip to content

Commit

Permalink
chore(build): Infer dynamically the version, license and readme of sk…
Browse files Browse the repository at this point in the history
…ore (#465)

```bash
$ cd skore/
$ python -m build
Successfully built skore-0.0.0+unknown.tar.gz and skore-0.0.0+unknown-py3-none-any.whl
```
---

To locally build a package with a version other than the default
`0.0.0+unknown`:

```bash
$ cd skore/
$ echo "X.Y.Z" > VERSION.txt
$ python -m build
Successfully built skore-X.Y.Z.tar.gz and skore-X.Y.Z-py3-none-any.whl
```
  • Loading branch information
thomass-dev authored Oct 10, 2024
1 parent 28e83a4 commit 91ff22e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ jobs:

- name: Build package distributions
run: |
cp --remove-destination LICENSE skore/LICENSE
cp --remove-destination README.md skore/README.md
cd skore
python -m pip install build
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/skore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,14 @@ jobs:
pre-commit run --all-files ruff
# Build
cp --remove-destination ../LICENSE ./LICENSE
cp --remove-destination ../README.md ./README.md
python -m build
# Install
python -m pip install dist/*.whl --no-dependencies
python -m pip install -r requirements.txt -r requirements-test.txt
# Test
python -m pytest
python -m pytest src/ tests/
cleanup:
runs-on: ubuntu-latest
Expand Down
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ pip-compile:
python -m piptools compile --extra=tools --output-file=skore/requirements-tools.txt skore/pyproject.toml

install-skore:
cp LICENSE skore/LICENSE
cp README.md skore/README.md

python -m pip install \
-e skore/ \
-r skore/requirements.txt \
-r skore/requirements-test.txt \
-r skore/requirements-tools.txt

rm skore/LICENSE
rm skore/README.md

pre-commit install

build-skore-ui:
Expand Down
1 change: 0 additions & 1 deletion skore/VERSION.txt

This file was deleted.

18 changes: 18 additions & 0 deletions skore/hatch/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pathlib import Path
from contextlib import suppress

from hatchling.metadata.plugin.interface import MetadataHookInterface


class MetadataHook(MetadataHookInterface):
def update(self, metadata):
license = Path(self.root, self.config["license-file"]).read_text()
readme = Path(self.root, self.config["readme-file"]).read_text()
version = self.config["version-default"]

with suppress(FileNotFoundError):
version = Path(self.root, "VERSION.txt").read_text()

metadata["license"] = {"text": license, "content-type": "text/plain"}
metadata["readme"] = {"text": readme, "content-type": "text/markdown"}
metadata["version"] = version
18 changes: 11 additions & 7 deletions skore/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[project]
name = "skore"
description = "Tooling and assistance for data scientists to \"Own Your Data Science\""
dynamic = ["version"]
readme = "README.md"
dynamic = [
"license",
"readme",
"version"
]
requires-python = ">=3.11"
maintainers = [
{name = "skore developers", email="[email protected]"},
Expand All @@ -14,7 +17,6 @@ dependencies = [
"skops",
"uvicorn",
]
license = { file = "LICENSE" }
classifiers=[
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
Expand Down Expand Up @@ -43,12 +45,14 @@ Issues = "https://github.com/probabl-ai/skore/issues"
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.version]
path = "VERSION.txt"
pattern = "(?P<version>[^']+)"
[tool.hatch.metadata.hooks.custom]
path = "hatch/metadata.py"
license-file = "../LICENSE"
readme-file = "../README.md"
version-default = "0.0.0+unknown"

[tool.hatch.build.targets.sdist]
only-include = ["src/"]
only-include = ["src/", "hatch/"]
artifacts = ["src/skore/ui/static/"]

[tool.hatch.build.targets.wheel]
Expand Down

0 comments on commit 91ff22e

Please sign in to comment.