This commit is contained in:
despiegk 2024-11-08 19:45:52 +03:00
parent aa84cc8793
commit 19988900c6
7 changed files with 129 additions and 7 deletions

17
.gitignore vendored Normal file
View File

@ -0,0 +1,17 @@
__pycache__
*.pyc
.venv
.vscode
index/
prompts2/
python3.12/
python3.13/
site-packages/
include/
bin/
state/
node_modules/
.mypy_cache
target/
lib/investorstool/parsers/input
docs/

View File

@ -1,3 +1,20 @@
# www_threefold4 # www_threefold4
new version of threefold, minimalistic new version of threefold, minimalistic
## to debug / develop
```bash
hero git clone -u git@git.ourworld.tf:tfgrid/www_threefold4.git
cd ~/code/git.ourworld.tf/tfgrid/www_threefold4
source myenv.sh
# to test an example
cd poc
python server.py
```
## to add package to pip
add it to https://git.ourworld.tf/projectmycelium/hero_server/src/branch/main/requirements.txt

24
install.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
set -ex
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
source ${BASE_DIR}/myenv.sh
cd $BASE_DIR
python3 -m pip install -r "$BASE_DIR/requirements.txt"
# pip freeze > requirements.txt
#to make sure we have the paths towards hero in our library
PYTHON_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
echo "$BASE_DIR/lib" > "${VENV_DIR}/lib/python${PYTHON_VERSION}/site-packages/herolib.pth"
#for osx
# pip3 install psycopg2-binary
# psycopg2
echo "OK"
python3 -m pip install -r "requirements.txt"
pip install --upgrade pip

27
myenv.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
# Script is being sourced
export BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
else
# Script is being executed
export BASE_DIR="$( cd "$( dirname "${0}" )" && pwd )"
fi
export VENV_DIR="${BASE_DIR}/.venv"
python3 -m venv "$VENV_DIR"
source $VENV_DIR/bin/activate
# Check if the directory exists
if [ ! -d "$VENV_DIR" ]; then
echo "Directory $VENV_DIR does not exist. Creating it and setting up a virtual environment."
# The -p flag makes mkdir create any necessary parent directories as well
mkdir -p "$VENV_DIR"
# Create the virtual environment
python3 -m venv "$VENV_DIR"
python3 -m pip install --upgrade pip
fi
export CONTEXTROOT='~/context'
echo "We're good to go"

View File

@ -7,7 +7,9 @@ import os
import markdown import markdown
import re import re
sources_dir = "/Users/despiegk1/code/git.ourworld.tf/freeflowuniverse/heroweb/research/dancing_banner/" sources_dir = os.path.expanduser("~/code/git.ourworld.tf/tfgrid/www_threefold4/poc")
if not os.path.exists(sources_dir):
raise RuntimeError(f"The source directory '{sources_dir}' does not exist.")
static_dir = f"{sources_dir}/static" static_dir = f"{sources_dir}/static"
content_dir = f"{sources_dir}/content" content_dir = f"{sources_dir}/content"
@ -15,20 +17,20 @@ def get_content(name: str) -> str:
"""Get content by name from either HTML or markdown files in content directory""" """Get content by name from either HTML or markdown files in content directory"""
# Remove any leading/trailing slashes # Remove any leading/trailing slashes
name = name.strip('/') name = name.strip('/')
# Check for file with .html extension # Check for file with .html extension
html_path = os.path.join(content_dir, f"{name}.html") html_path = os.path.join(content_dir, f"{name}.html")
if os.path.exists(html_path): if os.path.exists(html_path):
with open(html_path, 'r') as f: with open(html_path, 'r') as f:
return f.read() return f.read()
# Check for file with .md extension # Check for file with .md extension
md_path = os.path.join(content_dir, f"{name}.md") md_path = os.path.join(content_dir, f"{name}.md")
if os.path.exists(md_path): if os.path.exists(md_path):
with open(md_path, 'r') as f: with open(md_path, 'r') as f:
content = f.read() content = f.read()
return markdown.markdown(content) return markdown.markdown(content)
return f"[[{name} not found]]" return f"[[{name} not found]]"
def process_content(content: str) -> str: def process_content(content: str) -> str:
@ -36,7 +38,7 @@ def process_content(content: str) -> str:
def replace_content(match): def replace_content(match):
name = match.group(1) name = match.group(1)
return get_content(name) return get_content(name)
# Replace all [[name]] patterns # Replace all [[name]] patterns
return re.sub(r'\[\[(.*?)\]\]', replace_content, content) return re.sub(r'\[\[(.*?)\]\]', replace_content, content)
@ -69,7 +71,7 @@ async def favicon():
raise HTTPException(status_code=404, detail="Favicon not found") raise HTTPException(status_code=404, detail="Favicon not found")
@app.get("/", response_class=HTMLResponse) @app.get("/", response_class=HTMLResponse)
async def read_index(request: Request): async def read_index(request: Request):
template = env.get_template("index.html") template = env.get_template("index.html")
content = template.render(request=request) content = template.render(request=request)
return process_content(content) return process_content(content)

26
requirements.txt Normal file
View File

@ -0,0 +1,26 @@
IPython
colorama
colorlog
flet
inflect
jinja2
markdown-it-py
mdformat
mypy>=1.9.0
openai
psutil
pudb
pydantic>=2.7.1
pylance>=0.10.12
python-Levenshtein
pywalletconnect
pyyaml
qrcode
redis>=5.0.3
requests>=2.32
toml
urllib3
uvicorn
pillow
pymupdf
markdown

9
start.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
set -ex
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
cd $BASE_DIR
source myenv.sh
cd poc
python server.py