|
| 1 | +# Copyright 2025 The HuggingFace Inc. team. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +from setuptools import setup |
| 17 | + |
| 18 | + |
| 19 | +def get_version_from_toml() -> str: |
| 20 | + """Return the project's version string parsed from `pyproject.toml`. |
| 21 | +
|
| 22 | + The function scans `pyproject.toml` line-by-line looking for a line |
| 23 | + that starts with ``version`` (for example: ``version = "1.2.3"``) |
| 24 | + and returns the value without surrounding quotes. If no such line is |
| 25 | + found a :class:`ValueError` is raised. |
| 26 | +
|
| 27 | + Returns: |
| 28 | + The version string from `pyproject.toml` (e.g. ``"1.2.3"`` -> |
| 29 | + ``1.2.3``). |
| 30 | + """ |
| 31 | + |
| 32 | + version = None |
| 33 | + with open("pyproject.toml", encoding="utf-8") as f: |
| 34 | + for line in f: |
| 35 | + if line.strip().startswith("version"): |
| 36 | + version = line.split("=")[1].strip().strip('"') |
| 37 | + break |
| 38 | + if version is None: |
| 39 | + raise ValueError("Version not found in pyproject.toml") |
| 40 | + return version |
| 41 | + |
| 42 | + |
| 43 | +def read_long_description() -> str: |
| 44 | + """Read and return the project's long description for setup. |
| 45 | +
|
| 46 | + This function reads `README.md` and replaces image links that point |
| 47 | + to the local `./media/` directory with absolute raw GitHub URLs that |
| 48 | + reference the release tag corresponding to the version parsed from |
| 49 | + `pyproject.toml` (for example, ``v1.2.3``). The modified README |
| 50 | + content is returned as a string suitable for passing to |
| 51 | + ``setuptools.setup(long_description=...)``. |
| 52 | +
|
| 53 | + Returns: |
| 54 | + The README content with rewritten media links. |
| 55 | + """ |
| 56 | + |
| 57 | + with open("README.md", encoding="utf-8") as f: |
| 58 | + content = f.read() |
| 59 | + |
| 60 | + version = get_version_from_toml() |
| 61 | + git_tag = f"v{version}" |
| 62 | + |
| 63 | + base_raw_url = f"https://raw.githubusercontent.com/huggingface/lerobot/{git_tag}/" |
| 64 | + content = content.replace('src="./media/', f'src="{base_raw_url}media/') |
| 65 | + |
| 66 | + return content |
| 67 | + |
| 68 | + |
| 69 | +setup( |
| 70 | + long_description=read_long_description(), |
| 71 | + long_description_content_type="text/markdown", |
| 72 | +) |
0 commit comments