Skip to content

Commit

Permalink
Add ruff precommit linting and formatting (#731)
Browse files Browse the repository at this point in the history
* add ruff and pre-commit as dev-dependencies

* .py-files after ruff formatting

* output of notebook formatting - autofixed

* manual fixes to satisfy linter

* small fix to address equality test in tests/integration/test_integration_docker.py::TestMsmarcoDockerDeployment::test_instantiate_vespa_docker_from_container_name_or_id

* Add explanation about linting and formatting to README.md
  • Loading branch information
thomasht86 committed Apr 9, 2024
1 parent e1a7da2 commit f28532b
Show file tree
Hide file tree
Showing 37 changed files with 14,173 additions and 7,587 deletions.
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.5
hooks:
# Run the linter.
- id: ruff
types_or: [ python, pyi, jupyter ]
args: [ --fix ]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi, jupyter ]

10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ Code licensed under the Apache 2.0 license. See [LICENSE](LICENSE) for terms.


## Development environment
Check [screwdriver.yaml](screwdriver.yaml) to see which packages and environment variables
need to be set to run unit and integration tests.
To install editable version of the library with dev dependencies, run the following command from the root directory of the repository:

```python
pip install -e .[]
```

Note that this will enforce linting and formatting with [Ruff](https://github.com/astral-sh/ruff), which also will be triggered by a [pre-commit](https://pre-commit.com/)-hook.

This means that you may get an error message when trying to commit changes if the code does not pass the linting and formatting checks. The errors are detailed in the output, and you can optionally run manually with `ruff` CLI-tool.

## Releases
Find releases and release notes on [GitHub](https://github.com/vespa-engine/pyvespa/releases).
Expand Down
25 changes: 15 additions & 10 deletions docs/sphinx/source/application-packages.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
}
],
"source": [
"import os, tempfile\n",
"import os\n",
"import tempfile\n",
"from pathlib import Path\n",
"from vespa.package import ApplicationPackage\n",
"\n",
Expand All @@ -80,7 +81,7 @@
"temp_dir = tempfile.TemporaryDirectory()\n",
"app_package.to_files(temp_dir.name)\n",
"\n",
"for p in Path(temp_dir.name).rglob('*'):\n",
"for p in Path(temp_dir.name).rglob(\"*\"):\n",
" if p.is_file():\n",
" print(p)"
]
Expand Down Expand Up @@ -139,17 +140,19 @@
"from vespa.package import Field, FieldSet, RankProfile\n",
"\n",
"app_package.schema.add_fields(\n",
" Field(name = \"id\", type = \"string\", indexing = [\"attribute\", \"summary\"]),\n",
" Field(name = \"title\", type = \"string\", indexing = [\"index\", \"summary\"], index = \"enable-bm25\"),\n",
" Field(name = \"body\", type = \"string\", indexing = [\"index\", \"summary\"], index = \"enable-bm25\")\n",
" Field(name=\"id\", type=\"string\", indexing=[\"attribute\", \"summary\"]),\n",
" Field(\n",
" name=\"title\", type=\"string\", indexing=[\"index\", \"summary\"], index=\"enable-bm25\"\n",
" ),\n",
" Field(\n",
" name=\"body\", type=\"string\", indexing=[\"index\", \"summary\"], index=\"enable-bm25\"\n",
" ),\n",
")\n",
"\n",
"app_package.schema.add_field_set(\n",
" FieldSet(name = \"default\", fields = [\"title\", \"body\"])\n",
")\n",
"app_package.schema.add_field_set(FieldSet(name=\"default\", fields=[\"title\", \"body\"]))\n",
"\n",
"app_package.schema.add_rank_profile(\n",
" RankProfile(name = \"default\", first_phase = \"bm25(title) + bm25(body)\")\n",
" RankProfile(name=\"default\", first_phase=\"bm25(title) + bm25(body)\")\n",
")"
]
},
Expand Down Expand Up @@ -377,7 +380,9 @@
}
],
"source": [
"vespa_connection = vespa_container.deploy_from_disk(application_name=app_name, application_root=temp_dir.name)"
"vespa_connection = vespa_container.deploy_from_disk(\n",
" application_name=app_name, application_root=temp_dir.name\n",
")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
}

# anchoring with github sites will always fail
linkcheck_ignore = [r'https://github.com/.*#.*', r'http://localhost:\d+/']
linkcheck_ignore = [r"https://github.com/.*#.*", r"http://localhost:\d+/"]
1,483 changes: 1,482 additions & 1 deletion docs/sphinx/source/examples/Matryoshka_embeddings_in_Vespa-cloud.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit f28532b

Please sign in to comment.