pup-py commited on
Commit
a0b1478
·
1 Parent(s): 1594f3a

install from git

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. fetch.py +24 -4
  3. pyproject.toml +1 -1
README.md CHANGED
@@ -31,5 +31,5 @@ curl -fsSL "https://pup-py-fetch.hf.space?pixi=marimo&env1=duckdb,pandas&env2=co
31
  ```
32
 
33
  ```powershell
34
- iex (iwr "https://pup-py-fetch.hf.space?python=3.11&pixi=marimo&tables=duckdb,pandas,polars").Content
35
  ```
 
31
  ```
32
 
33
  ```powershell
34
+ iex (iwr "https://pup-py-fetch.hf.space?python=3.11&pixi=marimo&tables=duckdb,polars,liquidcarbon/affinity").Content
35
  ```
fetch.py CHANGED
@@ -3,7 +3,12 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
3
  from contextlib import asynccontextmanager
4
  from datetime import datetime
5
  from fastapi import FastAPI, Request
6
- from fastapi.responses import FileResponse, PlainTextResponse, Response
 
 
 
 
 
7
  from os import environ, getenv
8
  from pathlib import Path
9
  from typing import Any
@@ -33,16 +38,22 @@ app = FastAPI(lifespan=lifespan)
33
 
34
 
35
  @app.get("/")
36
- def read_root(request: Request):
37
  """Main URL returning an executable installer script.
38
 
39
  Query parameters can be used to install specific things, e.g.
40
  curl -fsSL "https://pup-py-fetch.hf.space?python=3.11&pixi=marimo&myenv=cowsay,duckdb"
41
 
 
42
  Package specs "duckdb>=1.1" are not supported.
43
  """
44
 
45
  query_params = dict(request.query_params)
 
 
 
 
 
46
  py_ver = query_params.pop("python", "3.12")
47
  if "Windows" in request.headers.get("user-agent"):
48
  pup_url = "https://raw.githubusercontent.com/liquidcarbon/puppy/main/pup.ps1"
@@ -56,9 +67,12 @@ def read_root(request: Request):
56
  script = [f"curl -fsSL {pup_url} | bash -s {py_ver}"]
57
  hint = f"""curl -fsSL "{request.url}" | bash"""
58
 
 
59
  pixi_packages = query_params.pop("pixi", "")
60
  if pixi_packages:
61
  for pkg in pixi_packages.split(","):
 
 
62
  script.append(f"pixi add {pkg}")
63
 
64
  # remaining query params are venvs
@@ -66,6 +80,8 @@ def read_root(request: Request):
66
  if venv in ["logs"]:
67
  continue
68
  for pkg in uv_packages.split(","):
 
 
69
  script.append(f"pup add {venv} {pkg}")
70
 
71
  script.extend(
@@ -136,10 +152,14 @@ async def ping():
136
 
137
 
138
  def self_ping():
139
- self_host = getenv("SPACE_HOST", "0.0.0.0:7860")
 
140
  with httpx.Client() as client:
141
- _ = client.get(f"http://{self_host}/ping", follow_redirects=True)
 
 
142
 
 
143
 
144
  scheduler = AsyncIOScheduler(executors={"default": AsyncIOExecutor()})
145
  scheduler.add_job(self_ping, "interval", minutes=720)
 
3
  from contextlib import asynccontextmanager
4
  from datetime import datetime
5
  from fastapi import FastAPI, Request
6
+ from fastapi.responses import (
7
+ FileResponse,
8
+ PlainTextResponse,
9
+ RedirectResponse,
10
+ Response,
11
+ )
12
  from os import environ, getenv
13
  from pathlib import Path
14
  from typing import Any
 
38
 
39
 
40
  @app.get("/")
41
+ def read_root(request: Request) -> Response:
42
  """Main URL returning an executable installer script.
43
 
44
  Query parameters can be used to install specific things, e.g.
45
  curl -fsSL "https://pup-py-fetch.hf.space?python=3.11&pixi=marimo&myenv=cowsay,duckdb"
46
 
47
+ A slash ("/") in package name is interpreted as a git repo.
48
  Package specs "duckdb>=1.1" are not supported.
49
  """
50
 
51
  query_params = dict(request.query_params)
52
+ if "ping" in query_params:
53
+ self_host = getenv("SPACE_HOST", "0.0.0.0:7860")
54
+ return RedirectResponse(f"http://{self_host}/ping")
55
+
56
+ # python version
57
  py_ver = query_params.pop("python", "3.12")
58
  if "Windows" in request.headers.get("user-agent"):
59
  pup_url = "https://raw.githubusercontent.com/liquidcarbon/puppy/main/pup.ps1"
 
67
  script = [f"curl -fsSL {pup_url} | bash -s {py_ver}"]
68
  hint = f"""curl -fsSL "{request.url}" | bash"""
69
 
70
+ # pixi packages
71
  pixi_packages = query_params.pop("pixi", "")
72
  if pixi_packages:
73
  for pkg in pixi_packages.split(","):
74
+ if "/" in pkg:
75
+ pkg = f"https://github.com/{pkg}.git"
76
  script.append(f"pixi add {pkg}")
77
 
78
  # remaining query params are venvs
 
80
  if venv in ["logs"]:
81
  continue
82
  for pkg in uv_packages.split(","):
83
+ if "/" in pkg:
84
+ pkg = f"https://github.com/{pkg}.git"
85
  script.append(f"pup add {venv} {pkg}")
86
 
87
  script.extend(
 
152
 
153
 
154
  def self_ping():
155
+ # self_host = getenv("SPACE_HOST", "0.0.0.0:7860")
156
+ self_host = "https://huggingface.co/spaces/pup-py/fetch?ping"
157
  with httpx.Client() as client:
158
+ # _ = client.get(f"http://{self_host}/ping", follow_redirects=True)
159
+ _ = client.get(self_host, follow_redirects=True)
160
+
161
 
162
+ self_ping()
163
 
164
  scheduler = AsyncIOScheduler(executors={"default": AsyncIOExecutor()})
165
  scheduler.add_job(self_ping, "interval", minutes=720)
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
  [project]
2
  name = "fetch"
3
- version = "0.4.1"
4
  description = "Puppy Installer"
5
  authors = [
6
  { name = "Alex Kislukhin" }
 
1
  [project]
2
  name = "fetch"
3
+ version = "0.5.0"
4
  description = "Puppy Installer"
5
  authors = [
6
  { name = "Alex Kislukhin" }