Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: install uv through pip #347

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/compwa_policy/check_dev_files/readthedocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import IO, TYPE_CHECKING, cast

from ruamel.yaml.comments import CommentedMap
from ruamel.yaml.scalarstring import DoubleQuotedScalarString, LiteralScalarString
from ruamel.yaml.scalarstring import DoubleQuotedScalarString

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import CONFIG_PATH, get_nested_dict
Expand Down Expand Up @@ -63,42 +63,44 @@ def _update_python_version(config: ReadTheDocs, python_version: PythonVersion) -
def _update_post_install(config: ReadTheDocs, python_version: PythonVersion) -> None:
jobs = get_nested_dict(config.document, ["build", "jobs"])
steps: list[str] = jobs.get("post_install", [])
if steps is None:
return
expected_steps = __get_install_steps(python_version)
step_idx = __find_pip_install_step(steps)
if step_idx is None:
step_idx = 0
start = max(0, step_idx - len(expected_steps) - 1)
end = step_idx + 1
existing_steps = steps[start:end]
if existing_steps == expected_steps:
expected_pip_install_steps = __get_install_steps(python_version)
start = __find_step(steps, pattern="pip install")
if start is None:
start = 0
end = __find_step(steps, pattern="pip install", invert=True)
if end is None:
end = len(steps)
existing_pip_install_steps = steps[start:end]
if existing_pip_install_steps == expected_pip_install_steps:
return
jobs["post_install"] = [
*steps[:start],
*expected_steps,
*expected_pip_install_steps,
*steps[end:],
]
msg = "Updated pip install steps"
config.changelog.append(msg)


def __get_install_steps(python_version: PythonVersion) -> list[str]:
pip_install = "/home/docs/.cargo/bin/uv pip install --system"
pip_install = "python -m uv pip install"
constraints_file = get_constraints_file(python_version)
if constraints_file is None:
install_statement = f"{pip_install} -e .[doc]"
else:
install_statement = f"{pip_install} -c {constraints_file} -e .[doc]"
return [
"curl -LsSf https://astral.sh/uv/install.sh | sh",
LiteralScalarString(install_statement),
"python -m pip install 'uv>=0.2.0'",
install_statement,
]


def __find_pip_install_step(post_install: list[str]) -> int | None:
for idx, step in enumerate(post_install):
if "pip install" in step:
def __find_step(steps: list[str], pattern: str, invert: bool = False) -> int | None:
for idx, step in enumerate(steps):
if invert:
if pattern not in step:
return idx
elif pattern in step:
return idx
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ build:
python: "3.9"
jobs:
post_install:
- curl -LsSf https://astral.sh/uv/install.sh | sh
- |-
/home/docs/.cargo/bin/uv pip install --system -e .[doc]
- python -m pip install 'uv>=0.2.0'
- python -m uv pip install -e .[doc]
- |
wget https://julialang-s3.julialang.org/bin/linux/x64/1.9/julia-1.9.2-linux-x86_64.tar.gz
- tar xzf julia-1.9.2-linux-x86_64.tar.gz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ build:
python: "3.9"
jobs:
post_install:
- curl -LsSf https://astral.sh/uv/install.sh | sh
- |-
/home/docs/.cargo/bin/uv pip install --system -e .[doc]
- python -m pip install 'uv>=0.2.0'
- python -m uv pip install -e .[doc]
Loading