Skip to content

Commit

Permalink
Add toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Oct 14, 2023
1 parent 0f9e9d7 commit 28c4be5
Show file tree
Hide file tree
Showing 8 changed files with 3,501 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ MANIFEST
.vscode/

# Environments
/.env
/.venv
.env
.venv
/env/
/venv/
/ENV/
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions crates/huak_python_manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "huak_python_manager"
description = "An application for managing Python installations."
version = "0.0.0"
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true

[dependencies]
huak_home = { version = "0.0.0", path = "../huak_home" }

[lints]
workspace = true
18 changes: 18 additions & 0 deletions crates/huak_python_manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Python Manager

A Python interpreter management system for Huak.

## Usage

```
huak_python_manager install 3.11
```

## How it works

### Installing a Python interpreter

1. Fetch the interpreter from https://github.com/indygreg/python-build-standalone using GitHub API.
1. Validate the checksum of the interpreter.
1. Extract the interpreter using `tar`.
1. Place the interpreter in Huak's home directory (~/.huak/bin/).
98 changes: 98 additions & 0 deletions crates/huak_python_manager/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""This module generates generated.rs with Python interpreter data."""
import re
import subprocess
from typing import NamedTuple
import requests
from pathlib import Path

class Release(NamedTuple):
kind: str
version: str
os: str
architecture: str
build_configuration: str
url: str

def to_rust_string(self) -> str:
return f"""\
Release::new("{self.kind}", "{self.version}", "{self.os}", "{self.architecture}", "{self.build_configuration}", "{self.url}")\
""" # noqa


url = "https://api.github.com/repos/indygreg/python-build-standalone/releases"

response = requests.get(url)
response.raise_for_status()

data = response.json()
version_pattern = r"cpython-(\d+\.\d+\.\d+)"
os_pattern = r"-(windows|apple|linux)-"
arch_pattern = r"-(aarch64|i686|x86_64)-"
build_pattern = r"-(pgo+lto|pgo|lto|noopt|debug)"

module = """\
pub struct Release<'a> {
kind: &'a str,
version: &'a str,
os: &'a str,
architecture: &'a str,
build_configuration: &'a str,
url: &'a str,
}
impl Release<'static> {
const fn new(
kind: &'static str,
version: &'static str,
os: &'static str,
architecture: &'static str,
build_configuration: &'static str,
url: &'static str,
) -> Self {
Release {
kind,
version,
os,
architecture,
build_configuration,
url,
}
}
}
pub const RELEASES: &'static [Release] = &[\
"""

for release in data:
for asset in release["assets"]:
# TODO(cnpryer): Validate checksum
if asset["browser_download_url"].endswith(".sha256"):
continue

version_res = re.search(version_pattern, asset["browser_download_url"])
if version_res:
version_str = version_res.group(1)

os_res = re.search(os_pattern, asset["browser_download_url"])
if os_res:
os_str = os_res.group(1)

arch_res = re.search(arch_pattern, asset["browser_download_url"])
if arch_res:
arch_str = arch_res.group(1)

build_res = re.search(build_pattern, asset["browser_download_url"])
if build_res:
build_str = build_res.group(1)

module += (
"\n\t"
+ Release(
"cpython", version_str, os_str, arch_str, build_str, asset["browser_download_url"]
).to_rust_string()
+ ","
)
module += "\n];"

path = Path(__file__).parent / "src" / "generated.rs"
path.write_text(module)
1 change: 1 addition & 0 deletions crates/huak_python_manager/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.31.0
3,355 changes: 3,355 additions & 0 deletions crates/huak_python_manager/src/generated.rs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions crates/huak_python_manager/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use huak_home::huak_home_dir;
mod generated;

fn main() {
println!("{:?}", huak_home_dir());
}

0 comments on commit 28c4be5

Please sign in to comment.