Skip to content

Commit

Permalink
Make all non-optional
Browse files Browse the repository at this point in the history
More comments and stuff

WIP

Fix more tests

Remove top-level symbols. Move more stuff

Pre-commit

fix constants/tests

Fix install commands and builder group

Manage poetry extras

Isolate base, cleanup trash
  • Loading branch information
marius-baseten committed Oct 29, 2024
1 parent 26193f7 commit 3c9d7dc
Show file tree
Hide file tree
Showing 227 changed files with 943 additions and 938 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/_integration_test_shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry install --with=dev,dev-server --extras=all
- run: |
poetry run pytest truss/tests \
--durations=0 -m 'integration' \
Expand All @@ -34,7 +34,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry install --with=dev,dev-server --extras=all
- run: |
poetry run pytest truss-chains/tests \
--durations=0 -m 'integration' \
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
fetch-depth: 2
- uses: ./.github/actions/detect-versions/
id: versions

build-and-push-truss-base-images-if-needed:
needs: [detect-version-changed]
if: needs.detect-version-changed.outputs.build_base_images == 'true'
Expand All @@ -46,7 +47,7 @@ jobs:

- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry install --with=dev,dev-server --extras=all
- shell: bash
run: |
poetry run bin/generate_base_images.py \
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
fetch-depth: 2
- uses: ./.github/actions/detect-versions/
id: versions

build-and-push-truss-base-images-if-needed:
needs: [detect-version-changed]
if: needs.detect-version-changed.outputs.build_base_images == 'true'
Expand All @@ -49,7 +50,7 @@ jobs:

- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry install --with=dev,dev-server --extras=all
- shell: bash
run: |
poetry run bin/generate_base_images.py \
Expand All @@ -64,7 +65,7 @@ jobs:
if: ${{ !failure() && !cancelled() && (needs.build-and-push-truss-base-images-if-needed.result == 'success' || needs.build-and-push-truss-base-images-if-needed.result == 'skipped') }}
uses: ./.github/workflows/_integration_test_shared.yml

publish-to-pypi:
publish-rc-to-pypi:
needs: [detect-version-changed]
if: ${{ !failure() && !cancelled() && needs.detect-version-changed.outputs.release_version == 'true' && needs.detect-version-changed.outputs.is_prerelease_version == 'true' }}
runs-on: ubuntu-20.04
Expand All @@ -84,7 +85,7 @@ jobs:
- uses: ./.github/actions/setup-python/

- name: Install poetry packages
run: poetry install --no-dev
run: poetry install --extras=all

- name: Build
run: poetry build
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
lfs: true
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry install --with=dev,dev-server --extras=all
- run: poetry run pre-commit run --all-files
env:
SKIP: ruff
Expand All @@ -31,7 +31,7 @@ jobs:
with:
lfs: true
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry install --with=dev,dev-server --extras=all
- name: run tests
run: poetry run pytest --durations=0 -m 'not integration' --junitxml=report.xml
- name: Publish Test Report # Not sure how to display this in the UI for non PRs.
Expand All @@ -50,7 +50,6 @@ jobs:
use-verbose-mode: "yes"
folder-path: "docs"


enforce-chains-example-docs-sync:
runs-on: ubuntu-20.04
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-truss-utils.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Install poetry packages
working-directory: truss-utils
run: poetry install --no-dev
run: poetry install

- name: Build
working-directory: truss-utils
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
tags: baseten/truss-context-builder:v${{ needs.detect-version-changed.outputs.new_version }}
labels: ${{ steps.meta.outputs.labels }}

publish-to-pypi:
publish-release-to-pypi:
needs: [detect-version-changed]
if: ${{ !failure() && !cancelled() && needs.detect-version-changed.outputs.release_version == 'true' }}
runs-on: ubuntu-20.04
Expand All @@ -80,7 +80,7 @@ jobs:
- uses: ./.github/actions/setup-python/

- name: Install poetry packages
run: poetry install --no-dev
run: poetry install --extras=all

- name: Build
run: poetry build
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ repos:
- id: ruff-format
- repo: local
hooks:
- id: pyproject.toml
name: pyproject.toml
entry: poetry run python bin/pyproject_toml_linter.py
language: python
additional_dependencies: [tomlkit]
- id: mypy
name: mypy-local
entry: poetry run mypy
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Truss was first created at [Baseten](https://baseten.co), but as an open and liv

We use GitHub features for project management on Truss:

* For bugs and feature requests, file an issue.
* For changes and updates, create a pull request.
* For bugs and feature requests, [file an issue](https://github.com/basetenlabs/truss/issues).
* For changes and updates, create a [pull request](https://github.com/basetenlabs/truss/pulls).
* To view and comment on the roadmap, [check the projects tab](https://github.com/orgs/basetenlabs/projects/3).

## Local development
Expand All @@ -30,7 +30,7 @@ asdf plugin add poetry
asdf install

# Install poetry dependencies
poetry install
poetry install --with=dev,dev-server --extras=all

# And finally precommit
poetry run pre-commit install
Expand Down
8 changes: 0 additions & 8 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion bin/codespace_post_create.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
poetry install
poetry install --with=dev,dev-server --extras=all
poetry run pre-commit install
git lfs install
2 changes: 1 addition & 1 deletion bin/generate_base_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import List, Optional, Set

from jinja2 import Environment, FileSystemLoader
from truss.constants import SUPPORTED_PYTHON_VERSIONS
from truss.base.constants import SUPPORTED_PYTHON_VERSIONS
from truss.contexts.image_builder.util import (
truss_base_image_name,
truss_base_image_tag,
Expand Down
77 changes: 77 additions & 0 deletions bin/pyproject_toml_linter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# type: ignore # tomlkit APIs are messy.
import collections
import pathlib
from typing import DefaultDict, Set

import tomlkit


def _populate_extras(pyproject_path: pathlib.Path) -> None:
with pyproject_path.open("r", encoding="utf-8") as file:
original_content = file.read()
content = tomlkit.parse(original_content)

dependencies = content["tool"]["poetry"]["dependencies"]
dependency_metadata = content["tool"]["dependency_metadata"]

extra_sections: DefaultDict[str, Set[str]] = collections.defaultdict(set)
all_deps: Set[str] = set()

for key, value in dependencies.items():
if isinstance(value, dict):
is_optional = value.get("optional", False)
else:
is_optional = False # Base dependencies.

if not is_optional:
continue

if key not in dependency_metadata:
raise ValueError(
f"`{key}` is missing in `[tool.dependency_metadata]`. "
f"(file: {pyproject_path}). Please add metadata."
)
metadata = dependency_metadata[key]
components = metadata["components"].split(",")
for component in components:
if component == "base":
continue
extra_sections[component].add(key)
all_deps.add(key)

for key in dependency_metadata.keys():
if key not in dependencies:
raise ValueError(
f"`{key}` in `[tool.dependency_metadata]` is not in "
"`[tool.poetry.dependencies]`. "
f"(file: {pyproject_path}). Please remove or sync."
)

extras_section = tomlkit.table()
for extra_section, deps in extra_sections.items():
extras_section[extra_section] = tomlkit.array()
extras_section[extra_section].extend(sorted(deps))

extras_section["all"] = tomlkit.array()
extras_section["all"].extend(sorted(all_deps))

if "extras" not in content["tool"]["poetry"]:
raise ValueError("Expected section [tool.poetry.extras] to be present.")

content["tool"]["poetry"]["extras"] = extras_section

updated_content = tomlkit.dumps(content)

# Compare the content before and after; if changes were made, fail the check
if original_content != updated_content:
with pyproject_path.open("w", encoding="utf-8") as file:
file.write(updated_content)
print(f"File '{pyproject_path}' was updated. Please re-stage the changes.")
exit(1)

print("No changes detected.")


if __name__ == "__main__":
pyproject_file = pathlib.Path(__file__).parent.parent.resolve() / "pyproject.toml"
_populate_extras(pyproject_file)
3 changes: 1 addition & 2 deletions context_builder.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ COPY ./README.md ./README.md

# https://python-poetry.org/docs/configuration/#virtualenvsin-project
# to write to project root .venv file to be used for context builder test
RUN poetry config virtualenvs.in-project true \
&& poetry install --only builder
RUN poetry config virtualenvs.in-project true && poetry install --extras=all
4 changes: 2 additions & 2 deletions docs/chains/doc_gen/API-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ For example, model weight caching can be used like this:

```python
import truss_chains as chains
from truss import truss_config
from truss.base import truss_config

mistral_cache = truss_config.ModelRepo(
repo_id="mistralai/Mistral-7B-Instruct-v0.2",
allow_patterns=["*.json", "*.safetensors", ".model"]
)
)
chains.Assets(cached=[mistral_cache], ...)
```

Expand Down
9 changes: 0 additions & 9 deletions docs/contribute/contributing.md

This file was deleted.

38 changes: 0 additions & 38 deletions docs/contribute/setup.md

This file was deleted.

Loading

0 comments on commit 3c9d7dc

Please sign in to comment.