Skip to content

Commit

Permalink
Add test script
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 28, 2024
1 parent afe7fe6 commit 6b40ac0
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 12 deletions.
111 changes: 111 additions & 0 deletions .github/workflows/system-install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: System Install

on:
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
CARGO_TERM_COLOR: always
RUSTUP_MAX_RETRIES: 10

jobs:
install-ubuntu:
name: "Install Python on Ubuntu"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: "Install Rust toolchain"
run: rustup show

- uses: Swatinem/rust-cache@v2

- name: "Build"
run: cargo build

- name: "Print Python path"
run: echo $(which python)

- name: "Validate global Python install"
run: python scripts/check_system_python.py --uv ./target/debug/uv

install-macos:
name: "Install Python on macOS"
runs-on: macos-14
steps:
- uses: actions/checkout@v4

- name: "Install Python"
run: brew install [email protected]

- name: "Install Rust toolchain"
run: rustup show

- uses: Swatinem/rust-cache@v2

- name: "Build"
run: cargo build

- name: "Print Python path"
run: echo $(which python3.11)

- name: "Validate global Python install"
run: python3.11 scripts/check_system_python.py --uv ./target/debug/uv

install-windows:
name: "Install Python on Windows"
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

# - name: "Install Python"
# run: choco install python

- name: "Install Rust toolchain"
run: rustup show

- uses: Swatinem/rust-cache@v2

- name: "Build"
run: cargo build

# - name: "Print Python path"
# run: echo $(which python3.12)

- name: "Validate global Python install"
run: py ./scripts/check_system_python.py --uv ./target/debug/uv

install-pyenv:
name: "Install Python using pyenv"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: "Install pyenv"
uses: "gabrielfalcao/pyenv-action@v18"
with:
default: 3.9.7

- name: "Install Rust toolchain"
run: rustup show

- uses: Swatinem/rust-cache@v2

- name: "Build"
run: cargo build

- name: "Print Python path"
run: echo $(which python3.9)

- name: "Validate global Python install"
run: python3.9 scripts/check_system_python.py --uv ./target/debug/uv
24 changes: 12 additions & 12 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ struct PipSyncArgs {
/// any parent directory. The `--system` option instructs `uv` to instead use the first Python
/// found in the system `PATH`.
///
/// `--system` is intended for use in continuous integration (CI) environments and should be
/// used with caution, as it can modify the system Python installation.
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution, as it can modify the system Python installation.
#[clap(long, conflicts_with = "python")]
system: bool,

Expand Down Expand Up @@ -655,8 +655,8 @@ struct PipInstallArgs {
/// any parent directory. The `--system` option instructs `uv` to instead use the first Python
/// found in the system `PATH`.
///
/// `--system` is intended for use in continuous integration (CI) environments and should be
/// used with caution, as it can modify the system Python installation.
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution, as it can modify the system Python installation.
#[clap(long, conflicts_with = "python")]
system: bool,

Expand Down Expand Up @@ -750,8 +750,8 @@ struct PipUninstallArgs {
/// any parent directory. The `--system` option instructs `uv` to instead use the first Python
/// found in the system `PATH`.
///
/// `--system` is intended for use in continuous integration (CI) environments and should be
/// used with caution, as it can modify the system Python installation.
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution, as it can modify the system Python installation.
#[clap(long, conflicts_with = "python")]
system: bool,
}
Expand Down Expand Up @@ -785,8 +785,8 @@ struct PipFreezeArgs {
/// falling back to the system Python if no virtual environment is found. The `--system` option
/// instructs `uv` to use the first Python found in the system `PATH`.
///
/// `--system` is intended for use in continuous integration (CI) environments and should be
/// used with caution.
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution.
#[clap(long, conflicts_with = "python")]
system: bool,
}
Expand Down Expand Up @@ -832,8 +832,8 @@ struct PipListArgs {
/// falling back to the system Python if no virtual environment is found. The `--system` option
/// instructs `uv` to use the first Python found in the system `PATH`.
///
/// `--system` is intended for use in continuous integration (CI) environments and should be
/// used with caution.
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution.
#[clap(long, conflicts_with = "python")]
system: bool,
}
Expand All @@ -860,8 +860,8 @@ struct VenvArgs {
/// any parent directory. The `--system` option instructs `uv` to use the first Python found in
/// the system `PATH`.
///
/// `--system` is intended for use in continuous integration (CI) environments and should be
/// used with caution, as it can modify the system Python installation.
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution, as it can modify the system Python installation.
#[clap(long, conflicts_with = "python")]
system: bool,

Expand Down
76 changes: 76 additions & 0 deletions scripts/check_system_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python3

"""Install `black` into the system Python."""

import argparse
import logging
import os
import subprocess
import sys
import tempfile

if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")

print("sys.executable:: %s" % sys.executable)

parser = argparse.ArgumentParser(description="Check a Python interpreter.")
parser.add_argument("--uv", help="Path to a uv binary.")
args = parser.parse_args()

uv: str = os.path.abspath(args.uv) if args.uv else "uv"

# Create a temporary directory.
temp_dir = tempfile.mkdtemp()

# Ensure that the package (`black`) isn't installed.
logging.info("Checking that `black` isn't installed.")
code = subprocess.run(
[sys.executable, "-m", "pip", "show", "black"],
cwd=temp_dir,
)
if code.returncode == 0:
raise Exception("The package `black` is installed.")

# Install the package (`black`).
logging.info("Installing the package `black`.")
subprocess.run(
[uv, "pip", "install", "black", "--system", "--verbose"],
cwd=temp_dir,
check=True,
)

# Ensure that the package (`black`) isn't installed.
logging.info("Checking that `black` is installed.")
code = subprocess.run(
[sys.executable, "-m", "pip", "show", "black"],
cwd=temp_dir,
)
if code.returncode != 0:
raise Exception("The package `black` isn't installed.")

# Ensure that the package is in the path.
logging.info("Checking that `black` is in the path.")
code = subprocess.run(
["black", "--version"],
cwd=temp_dir,
)
if code.returncode != 0:
raise Exception("The package `black` isn't in the path.")

# Uninstall the package (`black`).
logging.info("Uninstalling the package `black`.")
subprocess.run(
[uv, "pip", "uninstall", "black", "--system", "--verbose"],
cwd=temp_dir,
check=True,
)

# Ensure that the package (`black`) isn't installed.
logging.info("Checking that `black` isn't installed.")
code = subprocess.run(
[sys.executable, "-m", "pip", "show", "black"],
cwd=temp_dir,
)
if code.returncode == 0:
raise Exception("The package `black` is installed.")

0 comments on commit 6b40ac0

Please sign in to comment.