Skip to content

Commit

Permalink
Move python project to source root
Browse files Browse the repository at this point in the history
  • Loading branch information
nevillelyh committed Dec 12, 2024
1 parent b743227 commit 017735b
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 60 deletions.
File renamed without changes.
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
53 changes: 53 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[project]
name = 'coglet'
version = '0.1.0'
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']
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*']
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
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

0 comments on commit 017735b

Please sign in to comment.