|
15 | 15 | from __future__ import annotations |
16 | 16 |
|
17 | 17 | import functools |
| 18 | +import io |
| 19 | +import json |
18 | 20 | import logging |
19 | 21 | import random |
20 | 22 | import re |
|
23 | 25 | import packaging.version |
24 | 26 | import requests |
25 | 27 | from fastapi import APIRouter, HTTPException, Request, Response |
26 | | -from fastapi.responses import FileResponse, HTMLResponse |
| 28 | +from fastapi.responses import FileResponse, HTMLResponse, StreamingResponse |
27 | 29 |
|
28 | 30 | import murfey |
29 | 31 | from murfey.server import get_machine_config, respond_with_template |
|
43 | 45 | bootstrap = APIRouter(prefix="/bootstrap", tags=["bootstrap"]) |
44 | 46 | cygwin = APIRouter(prefix="/cygwin", tags=["bootstrap"]) |
45 | 47 | msys2 = APIRouter(prefix="/msys2", tags=["bootstrap"]) |
| 48 | +rust = APIRouter(prefix="/rust", tags=["bootstrap"]) |
46 | 49 | pypi = APIRouter(prefix="/pypi", tags=["bootstrap"]) |
47 | 50 | plugins = APIRouter(prefix="/plugins", tags=["bootstrap"]) |
48 | 51 |
|
@@ -565,6 +568,44 @@ def get_msys2_package_file( |
565 | 568 | raise HTTPException(status_code=package_file.status_code) |
566 | 569 |
|
567 | 570 |
|
| 571 | +""" |
| 572 | +======================================================================================= |
| 573 | +RUST-RELATED FUNCTIONS AND ENDPOINTS |
| 574 | +======================================================================================= |
| 575 | +""" |
| 576 | + |
| 577 | +rust_dl = "https://static.crates.io/crates" |
| 578 | +rust_api = "https://crates.io" |
| 579 | + |
| 580 | + |
| 581 | +@rust.get("/cargo/config.json", response_class=StreamingResponse) |
| 582 | +def get_maturin_config(request: Request): |
| 583 | + """ |
| 584 | + Download a config.json file used by Maturin that is used when integrating Rust |
| 585 | + backends for Python packages. This file will determine where Maturin sources |
| 586 | + Rust backend packages from. |
| 587 | +
|
| 588 | + This config is to be saved in ~/.cargo/registry/config.json |
| 589 | + """ |
| 590 | + |
| 591 | + # Construct config file with the necessary endpoints |
| 592 | + config = { |
| 593 | + "dl": f"{request.url.scheme}://{request.url.netloc}/crates", |
| 594 | + "api": f"{request.url.scheme}://{request.url.netloc}/api/crates", |
| 595 | + # "proxy": f"{request.url.scheme}://{request.url.netloc}", |
| 596 | + } |
| 597 | + |
| 598 | + # Save it as a JSON and return it as part of the response |
| 599 | + json_data = json.dumps(config, indent=4) |
| 600 | + json_bytes = io.BytesIO(json_data.encode("utf-8")) |
| 601 | + |
| 602 | + return StreamingResponse( |
| 603 | + json_bytes, |
| 604 | + media_type="application/json", |
| 605 | + headers={"Content-Disposition": "attachment; filename=config.json"}, |
| 606 | + ) |
| 607 | + |
| 608 | + |
568 | 609 | """ |
569 | 610 | ======================================================================================= |
570 | 611 | PYPI-RELATED FUNCTIONS AND ENDPOINTS |
|
0 commit comments