-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
3,501 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,8 @@ MANIFEST | |
.vscode/ | ||
|
||
# Environments | ||
/.env | ||
/.venv | ||
.env | ||
.venv | ||
/env/ | ||
/venv/ | ||
/ENV/ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests==2.31.0 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |