diff --git a/skore/ci/pip-compile.sh b/skore/ci/pip-compile.sh index f73a23f35..b6d48e615 100644 --- a/skore/ci/pip-compile.sh +++ b/skore/ci/pip-compile.sh @@ -1,9 +1,12 @@ #!/bin/bash # # This script compiles all the `test-requirements.txt` files, based on combinations of -# `python` and `scikit-learn` versions. +# `python` and `scikit-learn` versions. These combinations mirror those defined in the +# GitHub `backend` workflow. # -# The combinations mirror those defined in the GitHub `backend` workflow. +# You can pass any piptools parameter: +# +# $ bash pip-compile.sh --upgrade # CWD="$PWD" diff --git a/skore/hatch/metadata.py b/skore/hatch/metadata.py index c3bc1c473..99b93891b 100644 --- a/skore/hatch/metadata.py +++ b/skore/hatch/metadata.py @@ -1,14 +1,8 @@ -import shutil from pathlib import Path -from contextlib import ExitStack, suppress from hatchling.metadata.plugin.interface import MetadataHookInterface -# @dataclasses.dataclass -# class Configuration: - - def readlines(filepath): with open(filepath) as file: yield from file @@ -16,37 +10,62 @@ def readlines(filepath): class MetadataHook(MetadataHookInterface): def update(self, metadata): - license_path = Path(self.root, self.config["license-file"]) - license = license_path.read_text(encoding="utf-8") - readme = Path(self.root, self.config["readme-file"]).read_text(encoding="utf-8") - version = self.config["version-default"] + """ + Notes + ----- + Example of configuration: + + { + 'path': 'hatch/metadata.py', + 'license': {'file': '../LICENSE'}, + 'readme': {'file': '../README.md'}, + 'version-default': '0.0.0+unknown', + 'dependencies': {'file': 'requirements.in'}, + 'optional-dependencies': { + 'test': {'file': 'test-requirements.in'}, + 'sphinx': {'file': 'sphinx-requirements.in'}, + } + } + """ + + # Retrieve LICENCE from root files + license_filepath = self.config["license"]["file"] + license = Path(self.root, license_filepath).read_text(encoding="utf-8") + + # Copy LICENCE file in `sdist` + with open(Path(self.root, "LICENSE"), "w") as f: + f.write(license) - with suppress(FileNotFoundError): + # Retrieve README from root files + readme_filepath = self.config["readme"]["file"] + readme = Path(self.root, readme_filepath).read_text(encoding="utf-8") + + # Retrieve VERSION from file created by the CI + try: version = Path(self.root, "VERSION.txt").read_text(encoding="utf-8") + except FileNotFoundError: + version = self.config["version-default"] + + # Retrieve dependencies from requirements.in + dependencies_filepath = self.config["dependencies"]["file"] + dependencies = list(map(str.strip, readlines(dependencies_filepath))) + + # Retrieve optional dependencies from *-requirements.in + optional_dependencies_label_to_filepath = self.config["optional-dependencies"] + optional_dependencies = {} + for label, filepath in optional_dependencies_label_to_filepath: + optional_dependencies_filepath = filepath["file"] + optional_dependencies[label] = list( + map( + str.strip, + readlines(optional_dependencies_filepath), + ) + ) + + # Update metadata metadata["license"] = {"text": license, "content-type": "text/plain"} metadata["readme"] = {"text": readme, "content-type": "text/markdown"} metadata["version"] = version - - license_dest = Path(self.root, license_path.name) - shutil.copy2(license_path, license_dest) - - # { - # 'path': 'hatch/metadata.py', - # 'license-file': '../LICENSE', - # 'readme-file': '../README.md', - # 'version-default': '0.0.0+unknown', - # 'dependencies': {'file': 'requirements.in'}, - # 'optional-dependencies': { - # 'test': {'file': 'test-requirements.in'}, - # 'sphinx': {'file': 'sphinx-requirements.in'} - # } - # } - - metadata["dependencies"] = list( - map(str.strip, readlines(self.config["dependencies"])) - ) - metadata["optional-dependencies"] = { - label: list(map(str.strip, readlines(filepath))) - for label, filepath in self.config["optional-dependencies"].items() - } + Metadata["dependencies"] = dependencies + metadata["optional-dependencies"] = optional_dependencies diff --git a/skore/pyproject.toml b/skore/pyproject.toml index c300e1be3..7e8352315 100644 --- a/skore/pyproject.toml +++ b/skore/pyproject.toml @@ -45,12 +45,12 @@ build-backend = "hatchling.build" [tool.hatch.metadata.hooks.custom] path = "hatch/metadata.py" -license-file = "../LICENSE" -readme-file = "../README.md" version-default = "0.0.0+unknown" -dependencies = "requirements.in" -optional-dependencies.test = "test-requirements.in" -optional-dependencies.sphinx = "sphinx-requirements.in" +license = { "file" = "../LICENSE" } +readme = { "file" = "../README.md" } +dependencies = { "file" = "requirements.in" } +optional-dependencies.test = { "file" = "test-requirements.in" } +optional-dependencies.sphinx = { "file" = "sphinx-requirements.in" } [tool.hatch.build.targets.sdist] only-include = ["src/", "hatch/"]