Skip to content

neville/build #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ jobs:
fetch-depth: 0
- uses: hynek/build-and-inspect-python-package@v2
id: baipp
with:
path: ./python
outputs:
python-versions: ${{ steps.baipp.outputs.supported_python_classifiers_json_array }}

Expand Down
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.egg-info
.idea
__pycache__
uv.lock
.envrc
.direnv/
python/.coverage*
.envrc
/.idea
/dist
/internal/util/version.txt
/python/coglet/_version.py
/uv.lock
__pycache__
File renamed without changes.
3 changes: 1 addition & 2 deletions cmd/cog-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/peterbourgon/ff/v4/ffhelp"
"github.com/replicate/go/logging"
"github.com/replicate/go/must"
"github.com/replicate/go/version"
_ "go.uber.org/automaxprocs"

"github.com/replicate/cog-runtime/internal/server"
Expand Down Expand Up @@ -111,7 +110,7 @@ func main() {
os.Exit(1)
}

log.Infow("starting Cog HTTP server", "version", version.Version())
log.Infow("starting Cog HTTP server", "version", util.Version())
ctx, cancel := context.WithCancel(context.Background())
go func() {
ch := make(chan os.Signal, 1)
Expand Down
4 changes: 2 additions & 2 deletions internal/tests/cog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (ct *CogTest) Start() error {
}

func (ct *CogTest) runtimeCmd() *exec.Cmd {
pathEnv := path.Join(basePath, "python", ".venv", "bin")
pathEnv := path.Join(basePath, ".venv", "bin")
pythonPathEnv := path.Join(basePath, "python")
ct.serverPort = portFinder.Get()
args := []string{
Expand All @@ -173,7 +173,7 @@ func (ct *CogTest) legacyCmd() *exec.Cmd {
module := fmt.Sprintf("%s.py", ct.module)
must.Do(os.Symlink(path.Join(runnersPath, "cog.yaml"), path.Join(tmpDir, "cog.yaml")))
must.Do(os.Symlink(path.Join(runnersPath, module), path.Join(tmpDir, "predict.py")))
pythonBin := path.Join(basePath, "python", ".venv-legacy", "bin", "python3")
pythonBin := path.Join(basePath, ".venv-legacy", "bin", "python3")
ct.serverPort = portFinder.Get()
args := []string{
"-m", "cog.server.http",
Expand Down
15 changes: 15 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package util

import (
"embed"
_ "embed"
"encoding/base32"
"fmt"
"os"
Expand Down Expand Up @@ -58,3 +60,16 @@ func JoinLogs(logs []string) string {
}
return r
}

// Wildcard match in case version.txt is not generated yet
//
//go:embed *
var embedFS embed.FS

func Version() string {
bs, err := embedFS.ReadFile("version.txt")
if err != nil {
return "0.0.0+unknown"
}
return strings.TrimSpace(string(bs))
}
56 changes: 56 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[project]
name = 'coglet'
dynamic = ['version']
description = 'Minimum viable Cog runtime'
readme = 'README.md'
requires-python = '>=3.9'
classifiers = [
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
]
dependencies = []

[project.optional-dependencies]
dev = [
'build',
'ipython',
'mypy',
'setuptools',
]

test = [
'pytest',
'pytest-asyncio',
]

[build-system]
requires = ['setuptools', 'setuptools-scm']
build-backend = 'setuptools.build_meta'

[tool.pytest.ini_options]
asyncio_default_fixture_loop_scope = 'function'
filterwarnings = [
'ignore::ImportWarning',
]
testpaths = [
'python',
]

[tool.ruff]
src = ['python']

[tool.ruff.format]
quote-style = 'single'

[tool.ruff.lint]
extend-select = ['I']

[tool.setuptools.packages.find]
where = ['python']
exclude = ['tests*']

[tool.setuptools_scm]
version_file = "python/coglet/_version.py"
5 changes: 5 additions & 0 deletions python/coglet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import sys
import warnings

try:
from ._version import __version__
except ImportError:
__version__ = '0.0.0+unknown'

warnings.warn(
(
'coglet/_compat/ is being added to the front of sys.path '
Expand Down
4 changes: 2 additions & 2 deletions python/coglet/_compat/cog/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import coglet
from coglet.api import (
BaseModel,
BasePredictor,
Expand All @@ -8,8 +9,7 @@
Secret,
)

__version__ = '0.0.8001+coglet'
__version_tuple__ = (0, 0, 8001, '', 'coglet')
__version__ = coglet.__version__

__all__ = [
'BaseModel',
Expand Down
40 changes: 0 additions & 40 deletions python/pyproject.toml

This file was deleted.

5 changes: 0 additions & 5 deletions python/ruff.toml

This file was deleted.

3 changes: 3 additions & 0 deletions python/tests/test_file_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def wait_for_process(p: subprocess.Popen, code: int = 0) -> None:
def run_file_runner(
tmp_path: str, predictor: str, env: Optional[Dict[str, str]] = None
) -> subprocess.Popen:
if env is None:
env = {}
env['PYTHONPATH'] = str(pathlib.Path(__file__).absolute().parent.parent)
cmd = [
sys.executable,
'-m',
Expand Down
19 changes: 19 additions & 0 deletions script/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Build binaries

set -euo pipefail

base_dir="$(git rev-parse --show-toplevel)"

cd "$base_dir"
python -m build

# Export Python version to Go
python -c 'import coglet; print(coglet.__version__)' > internal/util/version.txt

for os in darwin linux; do
for arch in amd64 arm64; do
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o dist/cog-server-$os-$arch ./cmd/cog-server
done
done
3 changes: 1 addition & 2 deletions script/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ check_go() {
}

check_python() {
cd "$base_dir/python"
uv sync --all-extras
if [[ -z "${CI:-}" ]]; then
uv tool run ruff check --fix
Expand All @@ -28,7 +27,7 @@ check_python() {
uv tool run ruff check
uv tool run ruff format --check
fi
.venv/bin/mypy . --exclude tests/runners --exclude tests/schemas
.venv/bin/mypy . --exclude python/tests/runners --exclude python/tests/schemas
}

if [ $# -eq 0 ]; then
Expand Down
13 changes: 7 additions & 6 deletions script/cog-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ base_dir="$(git rev-parse --show-toplevel)"
# PYTHON=1 to run with legacy Cog
if [ -z "${PYTHON:-}" ]; then
export LOG_FORMAT=development
export PATH="$base_dir/python/.venv/bin:$PATH"
export PATH="$base_dir/.venv/bin:$PATH"
export PYTHONPATH="$base_dir/python"
go run cmd/cog-server/main.go \
--module-name "tests.runners.$module" \
--class-name Predictor \
"$@"
args=(--module-name "tests.runners.$module" --class-name Predictor)
if [ -n "${PORT:-}" ]; then
args+=(--port "$PORT")
fi
go run cmd/cog-server/main.go "${args[@]}" "$@"
else
cd "$base_dir/python/tests/runners"
ln -fs "$module.py" predict.py
trap "rm -f predict.py" EXIT
"$base_dir/python/.venv-legacy/bin/python3" -m cog.server.http "$@"
"$base_dir/.venv-legacy/bin/python3" -m cog.server.http "$@"
fi
6 changes: 3 additions & 3 deletions script/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
set -euo pipefail

base_dir="$(git rev-parse --show-toplevel)"
python_version="$(cat "$base_dir/python/.python-version")"
python_version="$(cat "$base_dir/.python-version")"

cd "$base_dir/python"
cd "$base_dir"
uv sync --all-extras

# venv with legacy Cog
uv venv --python "$python_version" .venv-legacy
export VIRTUAL_ENV="$base_dir/python/.venv-legacy"
export VIRTUAL_ENV="$base_dir/.venv-legacy"
uv pip install cog
2 changes: 1 addition & 1 deletion script/schemas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ trap "rm -f predict.py" EXIT
for f in *.py; do
echo "Generating schema for $(basename "$f")"
ln -fs "$f" predict.py
"$base_dir/python/.venv-legacy/bin/python3" -m cog.command.openapi_schema > "$(basename "$f" .py).json"
"$base_dir/.venv-legacy/bin/python3" -m cog.command.openapi_schema > "$(basename "$f" .py).json"
done
1 change: 0 additions & 1 deletion script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ test_go() {
}

test_python() {
cd "$base_dir/python"
.venv/bin/pytest "$@"
}

Expand Down
Loading