8000 Improve project tooling by aron · Pull Request #2351 · replicate/cog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve project tooling #2351

New issue

Have a question about this project? S 8000 ign 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 6 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ Common contribution types include: `doc`, `code`, `bug`, and `ideas`. See the fu

## Development environment

We use the ["scripts to rule them all"](https://github.blog/engineering/engineering-principles/scripts-to-rule-them-all/) philosophy to manage common tasks across the project. These are mostly backed by a Makefile that contains the implementation.

You'll need the following dependencies installed to build Cog locally:
- [Go](https://golang.org/doc/install): We're targeting 1.24, but you can install the latest version since Go is backwards compatible. If you're using a newer Mac with an M1 chip, be sure to download the `darwin-arm64` installer package. Alternatively you can run `brew install go` which will automatically detect and use the appropriate installer for your system architecture.
- [uv](https://docs.astral.sh/uv/): Python versions and dependencies are managed by uv.
Expand All @@ -102,19 +104,31 @@ Install the Python dependencies:

script/setup

Once you have Go installed, run:
Once you have Go installed you can install the cog binary by running:

make install PREFIX=$(go env GOPATH)

This installs the `cog` binary to `$GOPATH/bin/cog`.

To run the tests:
To run ALL the tests:

script/test-all

To run per-language tests (forwards arguments to test runner):

script/test-python --no-cov python/tests/cog/test_files.py -k test_put_file_to_signed_endpoint_with_location

script/test-go ./pkg/config

The project is formatted by goimports and ruff. To format the source code, run:

script/format

make test
To 8000 run code linting across all files:

The project is formatted by goimports. To format the source code, run:
script/lint

make fmt
For more information check the Makefile targets for more specific commands.

If you encounter any errors, see the troubleshooting section below?

Expand Down Expand Up @@ -150,21 +164,24 @@ There are a few concepts used throughout Cog that might be helpful to understand
**To run the entire test suite:**

```sh
make test
script/test # see also: make test
```

**To run just the Golang tests:**

```sh
make test-go
script/test-go # see also: make test-go
```

**To run just the Python tests:**

```sh
make test-python
script/test-python # see also: make test-python
```

> [!INFO]
> Note that this will run the Python test suite using only the current version of Python defined in .python-version. To run a more comprehensive Python test suite then use `make test-python`.

**To run just the integration tests:**

```sh
Expand All @@ -173,6 +190,12 @@ make test-integration

**To run a specific Python test:**

```sh
script/test-python python/tests/server/test_http.py::test_openapi_specification_with_yield
```

**To run a specific Python test under a specific environment**

```sh
uv run tox -e py312-pydantic2-tests -- python/tests/server/test_http.py::test_openapi_specification_with_yield
```
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ test: test-go test-python test-integration
.PHONY: fmt
fmt:
$(GOIMPORTS) -w -d .
uv run ruff format

.PHONY: generate
generate:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dynamic = ["version"]
[dependency-groups]
dev = [
"build>=1.2.2.post1",
"ruff",
"setuptools-scm>=8.2.0",
"tox>=4.25.0",
"tox-uv>=1.13.1",
Expand Down
5 changes: 5 additions & 0 deletions script/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(git rev-parse --show-toplevel)"
exec make fmt
5 changes: 5 additions & 0 deletions script/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(git rev-parse --show-toplevel)"
exec make lint
File renamed without changes.
10 changes: 10 additions & 0 deletions script/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(git rev-parse --show-toplevel)"

echo "script/test is not used in this project, check out:"
echo " script/test-all - runs all the tests, including integration tests"
echo " script/test-go - runs 6D40 just the go tests"
echo " script/test-python - runs just the python tests"
exit 1
5 changes: 5 additions & 0 deletions script/test-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(git rev-parse --show-toplevel)"
exec make test
11 changes: 11 additions & 0 deletions script/test-go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Runs go test suite for current python version and passes
# any additional arguments along to pytest command.
#
# Usage:
# ./script/test-go ./pkg/config
set -euo pipefail

cd "$(git rev-parse --show-toplevel)"

exec go tool gotestsum -- -short -timeout 1200s -parallel 5 "${@:-"./..."}"
14 changes: 14 additions & 0 deletions script/test-python
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Runs python test suite for current python version and passes
# any additional arguments along to pytest command.
#
# Usage:
# ./script/test-python --no-cov python/tests/cog/test_files.py -k test_put_file_to_signed_endpoint_with_location
set -euo pipefail

cd "$(git rev-parse --show-toplevel)"

IFS=. read -r major minor _ <".python-version"
PYVERSION="py${major}${minor}"

exec uv run tox -e "$PYVERSION-pydantic1-tests,$PYVERSION-pydantic2-tests" -- "$@"
11 changes: 6 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ commands =
tests: pytest python/tests --cov={env_site_packages_dir}/cog --cov-report term-missing:skip-covered {posargs:-n auto -vv}

[testenv:lint]
b 9E22 ase_python = python3.12
base_python = python3.13
skip_install = true
deps = ruff==0.9.1
dependency_groups =
dev
commands =
ruff check python/cog
ruff format --check python

[testenv:typecheck-pydantic1]
base_python = python3.12
base_python = python3.13
deps =
pyright==1.1.375
pydantic>=1,<2
Expand All @@ -54,14 +55,14 @@ allowlist_externals =
sed

[testenv:typecheck-pydantic2]
base_python = python3.12
base_python = python3.13
deps =
pyright==1.1.375
pydantic>=2,<3
commands = pyright {posargs}

[testenv:integration]
base_python = python3.12
base_python = python3.13
changedir = test-integration
skip_install = true
deps =
Expand Down
Loading
0