Skip to content

Commit

Permalink
Clean docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
thomass-dev committed Jan 30, 2025
1 parent 3dbc4e4 commit 62e8daf
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 41 deletions.
7 changes: 5 additions & 2 deletions skore/ci/pip-compile.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
87 changes: 53 additions & 34 deletions skore/hatch/metadata.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,71 @@
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


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
10 changes: 5 additions & 5 deletions skore/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/"]
Expand Down

0 comments on commit 62e8daf

Please sign in to comment.