Skip to content

Commit

Permalink
Converts all python projects to uv (#78)
Browse files Browse the repository at this point in the history
Converts all python projects from poetry to uv, with supporting
/tools/makefiles/python.mk and changes to Dockerfiles.
  • Loading branch information
markwaddle authored Oct 2, 2024
1 parent 85942e9 commit 4c42025
Show file tree
Hide file tree
Showing 103 changed files with 584 additions and 846 deletions.
32 changes: 25 additions & 7 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
"name": "semantic-workbench",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm",
"hostRequirements": {
"cpus": 4,
"memory": "16gb",
"storage": "32gb"
},
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {
"version": "latest"
},
"ghcr.io/jungaretti/features/make:1": {},
"ghcr.io/jungaretti/features/vim:1": {},
"ghcr.io/devcontainers-contrib/features/pipx-package:1": {
"package": "uv",
"version": "latest"
},
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"installYarnUsingApt": true,
Expand All @@ -24,7 +30,10 @@
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000, 4000],
"forwardPorts": [
3000,
4000
],
// Use 'portsAttributes' to configure the behavior of specific port forwarding instances.
"portsAttributes": {
"3000": {
Expand All @@ -37,12 +46,14 @@
// Use 'otherPortsAttributes' to set the defaults that are applied to all ports, unless overridden
// with port-specific entries in 'portsAttributes'.
// "otherPortsAttributes": {},
"updateContentCommand": "make -C /workspaces/semanticworkbench",
"updateContentCommand": "make -C ${containerWorkspaceFolder} && chown -R vscode:vscode ${containerWorkspaceFolder}",
"postCreateCommand": "git config --global push.autoSetupRemote true",
// Configure tool-specific properties.
"customizations": {
"codespaces": {
"openFiles": [".devcontainer/POST_SETUP_README.md"]
"openFiles": [
".devcontainer/POST_SETUP_README.md"
]
},
"vscode": {
"extensions": [
Expand All @@ -65,6 +76,13 @@
]
}
},
"containerEnv": {
// The default `uv` cache dir is at /home/vscode/.cache/uv, which is on a different disk than the default
// for workspaces.
// Ensure the cache is on the same disk for optimal uv performance. https://docs.astral.sh/uv/concepts/cache/#cache-directory
// ${containerWorkspaceFolder} == /workspaces/repo-name
"UV_CACHE_DIR": "${containerWorkspaceFolder}/../.cache/uv"
},
// Connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
// "remoteUser": "root"
}
20 changes: 6 additions & 14 deletions .github/workflows/workbench-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,21 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.11"]
poetry-version: ["1.7.1"]
dbtype: ["sqlite", "postgresql"]
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install package
run: |
poetry install
run: uv sync

- name: pytest
run: |
poetry run pytest --dbtype=${{ matrix.dbtype }}
run: uv run pytest --dbtype=${{ matrix.dbtype }}

build:
runs-on: ubuntu-latest
Expand Down
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
.env
*.local
*__local__*
.data/
.data
.idea/
appsettings.*.json

# Dependencies and build cache
node_modules
poetry.lock
uv.lock
.venv
__pycache__
.pytest_cache
.ruff_cache
.cache
bin/
obj/
*.egg-info
bin
obj
dist
build

# Logs
*.log
Expand Down
9 changes: 0 additions & 9 deletions assistants/prospector-assistant/.gitignore

This file was deleted.

5 changes: 1 addition & 4 deletions assistants/prospector-assistant/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
repo_root = $(shell git rev-parse --show-toplevel)

.DEFAULT_GOAL := venv

include $(repo_root)/tools/makefiles/poetry.mk
include $(repo_root)/tools/makefiles/python.mk
include $(repo_root)/tools/makefiles/docker-assistant.mk
6 changes: 3 additions & 3 deletions assistants/prospector-assistant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ See the [Responsible AI FAQ](../../RESPONSIBLE_AI_FAQ.md) for more information.
## Starting the example from CLI

If you're not using VS Code and/or Codespaces, you can also work from the
command line, using `poetry`:
command line, using `uv`:

```
cd <PATH TO THIS FOLDER>
poetry install
uv sync
poetry run start-semantic-workbench-assistant assistant.chat:app
uv run start-semantic-workbench-assistant assistant.chat:app
```

## Create your own assistant
Expand Down
2 changes: 0 additions & 2 deletions assistants/prospector-assistant/poetry.toml

This file was deleted.

41 changes: 21 additions & 20 deletions assistants/prospector-assistant/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
[tool.poetry]
[project]
name = "assistant"
version = "0.1.0"
description = "Exploration of a python Semantic Workbench OpenAI assistant to help mine artifacts for ideas."
authors = ["Semantic Workbench Team"]
authors = [{ name = "Semantic Workbench Team" }]
readme = "README.md"
packages = [{ include = "assistant" }]
requires-python = ">=3.11"
dependencies = [
"deepmerge>=2.0",
"docx2txt>=0.8",
"html2docx>=1.6.0",
"markdown>=3.6",
"openai>=1.3.9",
"pdfplumber>=0.11.2",
"tiktoken>=0.7.0",
"semantic-workbench-assistant>=0.1.0",
"content-safety>=0.1.0",
]

[tool.poetry.dependencies]
python = "~3.11"
deepmerge = "^2.0"
docx2txt = "^0.8"
html2docx = "^1.6.0"
markdown = "^3.6"
openai = "^1.3.9"
pdfplumber = "^0.11.2"
tiktoken = "^0.7.0"
[tool.uv]
package = true

# If you copy this file to your project, you should verify the relative path to the following:
semantic-workbench-assistant = { path = "../../libraries/python/semantic-workbench-assistant", develop = true }
content-safety = { path = "../../libraries/python/content-safety/", develop = true }

[tool.poetry.group.dev.dependencies]
ruff = "^0.6.4"
[tool.uv.sources]
semantic-workbench-assistant = { path = "../../libraries/python/semantic-workbench-assistant", editable = true }
content-safety = { path = "../../libraries/python/content-safety/", editable = true }

[build-system]
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.pyright]
exclude = ["venv", ".venv"]
9 changes: 0 additions & 9 deletions assistants/skill-assistant/.gitignore

This file was deleted.

5 changes: 1 addition & 4 deletions assistants/skill-assistant/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
repo_root = $(shell git rev-parse --show-toplevel)

.DEFAULT_GOAL := venv

include $(repo_root)/tools/makefiles/poetry.mk
include $(repo_root)/tools/makefiles/python.mk
include $(repo_root)/tools/makefiles/docker-assistant.mk
6 changes: 3 additions & 3 deletions assistants/skill-assistant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ See the [Responsible AI FAQ](../../RESPONSIBLE_AI_FAQ.md) for more information.
## Starting the example from CLI

If you're not using VS Code and/or Codespaces, you can also work from the
command line, using `poetry`:
command line, using `uv`:

```
cd <PATH TO THIS FOLDER>
poetry install
uv sync
poetry run start-semantic-workbench-assistant assistant.chat:app
uv run start-semantic-workbench-assistant assistant.chat:app
```

## Create your own assistant
Expand Down
2 changes: 0 additions & 2 deletions assistants/skill-assistant/poetry.toml

This file was deleted.

46 changes: 21 additions & 25 deletions assistants/skill-assistant/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
[tool.poetry]
[project]
name = "assistant"
version = "0.1.0"
description = "Exploration of a skill assistant library assistant (name to be updated)."
authors = ["Semantic Workbench Team"]
authors = [{ name = "Semantic Workbench Team" }]
readme = "README.md"
packages = [{ include = "assistant" }]
requires-python = ">=3.11"
dependencies = [
"azure-ai-contentsafety>=1.0.0",
"azure-identity>=1.16.0",
"azure-core[aio]>=1.30.0",
"openai>=1.3.9",
"semantic-workbench-assistant>=0.1.0",
"content-safety>=0.1.0",
"posix-skill>=0.1.0",
]

[tool.poetry.dependencies]
python = "~3.11"
azure-ai-contentsafety = "^1.0.0"
azure-identity = "^1.16.0"
azure-core = { version = "*", extras = ["aio"] }
openai = "^1.3.9"
[tool.uv]
package = true
dev-dependencies = ["pytest>=8.3.1", "pytest-asyncio>=0.23.8"]

[tool.uv.sources]
# If you copy this file to your project, you should verify the relative path to the following:
semantic-workbench-assistant = { path = "../../libraries/python/semantic-workbench-assistant", develop = true }
content-safety = { path = "../../libraries/python/content-safety/", develop = true }

chat_driver = { path = "../../libraries/python/chat-driver", develop = true }
context = { path = "../../libraries/python/context", develop = true }
events = { path = "../../libraries/python/events", develop = true }

posix-skill = { path = "../../libraries/python/skills/skills/posix-skill", develop = true }
skill-library = { path = "../../libraries/python/skills/skill-library", develop = true }

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.1"
pytest-asyncio = "^0.23.8"
ruff = "^0.6.4"
semantic-workbench-assistant = { path = "../../libraries/python/semantic-workbench-assistant", editable = true }
content-safety = { path = "../../libraries/python/content-safety/", editable = true }
posix-skill = { path = "../../libraries/python/skills/skills/posix-skill", editable = true }

[build-system]
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.pyright]
exclude = ["venv", ".venv"]
21 changes: 8 additions & 13 deletions docs/SETUP_DEV_ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,28 @@ Recommended installers:

The backend service for the Semantic Workbench is written in Python. Currently we require Python 3.11.

The core dependencies you need to install are: `python 3.11`, `poetry`, `make`.
The core dependencies you need to install are: `uv` and `make`.

`uv` will automatically install the correct version of Python for you when you run `uv sync`.

Linux:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.11 python3-pip python3-poetry python-is-python3
pip install cffi

If you have other versions of python installed, make sure they are all registered with update-alternatives and ensure python 3.11 is active:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 100
sudo update-alternatives --config python3
sudo apt install pipx
pipx ensurepath
pipx install uv

macOS:

brew install python@3.11
brew install poetry
brew install uv
brew install make

Windows:

winget install Python.Python.3.11
winget install ezwinports.make
python -m pip install --user pipx
python -m pipx ensurepath
pipx install poetry
pipx install uv

If you haven't already, enable long file paths on Windows.

Expand Down
9 changes: 0 additions & 9 deletions examples/python/python-01-echo-bot/.gitignore

This file was deleted.

5 changes: 1 addition & 4 deletions examples/python/python-01-echo-bot/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
repo_root = $(shell git rev-parse --show-toplevel)

.DEFAULT_GOAL := venv

include $(repo_root)/tools/makefiles/poetry.mk
include $(repo_root)/tools/makefiles/python.mk
6 changes: 3 additions & 3 deletions examples/python/python-01-echo-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ The code here is only meant to **show the basics**, to **familiarize with code s
## Starting the example from CLI

If you're not using VS Code and/or Codespaces, you can also work from the
command line, using `poetry`:
command line, using `uv`:

```
cd <PATH TO THIS FOLDER>
poetry install
uv sync
poetry run start-semantic-workbench-assistant assistant.chat:app
uv run start-semantic-workbench-assistant assistant.chat:app
```

## Create your own assistant
Expand Down
Loading

0 comments on commit 4c42025

Please sign in to comment.