|
2 | 2 | [poetry]: https://github.com/python-poetry/poetry |
3 | 3 | [pdm]: https://github.com/pdm-project/pdm |
4 | 4 | [ruff]: https://github.com/astral-sh/ruff |
| 5 | +[ty]: https://github.com/astral-sh/ty |
5 | 6 | [pixi]: https://github.com/prefix-dev/pixi |
6 | 7 | [npm-check-updates]: https://www.npmjs.com/package/npm-check-updates |
7 | 8 |
|
@@ -30,17 +31,80 @@ Keep all your ruff settings in `afterpython/ruff.toml`, not in `pyproject.toml` |
30 | 31 | If `ap init` finds an existing ruff config there, it skips the ruff setup; remove it and run `ap init ruff` to set it up again. |
31 | 32 |
|
32 | 33 | Wrappers (all arguments are passed through to ruff): |
33 | | -- `ap check` (alias: `ap lint`) runs `ruff check`, e.g. `ap check --fix`. |
| 34 | +- `ap lint` runs `ruff check`, e.g. `ap lint --fix`. |
34 | 35 | - `ap format` runs `ruff format`, e.g. `ap format --check`. |
35 | 36 |
|
36 | 37 | Or you can just directly use the `ruff` command (and ruff editor extensions) as usual, they use the same config. |
37 | 38 |
|
| 39 | +The ruff hooks (`ruff-check` and `ruff-format`) and the ruff step of the CI `lint` job only run when `afterpython/ruff.toml` exists. |
| 40 | +If you declined ruff during `ap init` (or its setup was skipped), they are removed/skipped; if you use your own ruff config, set up its hooks and CI yourself. |
| 41 | + |
38 | 42 | :::{note} |
39 | 43 | Relative paths in `afterpython/ruff.toml` are resolved from `afterpython/`, not the project root, |
40 | 44 | e.g. use `"../tests/*"` in `per-file-ignores` to target your project's `tests/` folder. |
41 | 45 | ::: |
42 | 46 |
|
43 | 47 |
|
| 48 | +--- |
| 49 | +## Type Checking |
| 50 | +`afterpython` uses [ty] for type checking, configured in `afterpython/ty.toml`. |
| 51 | + |
| 52 | +- `ap check` runs `ty check` with `afterpython/ty.toml` (all arguments are passed through to ty), e.g. `ap check src/`. |
| 53 | + |
| 54 | +Unlike ruff, ty doesn't support `extend` yet, so `pyproject.toml` can't point to `afterpython/ty.toml`, and ty only finds it when it's told to. So: |
| 55 | +- use `ap check` instead of `ty check` (or run `ty check --config-file afterpython/ty.toml` from the project root) |
| 56 | +- set up your editor as shown [below](#editor-setup) |
| 57 | + |
| 58 | +Keep all your ty settings in `afterpython/ty.toml`, not in `pyproject.toml` (`[tool.ty]`) or a `ty.toml` at the project root. |
| 59 | +If `ap init` finds an existing ty config there, it skips the ty setup; remove it and run `ap init ty` to set it up again. |
| 60 | + |
| 61 | +The `ty` hook (runs `ap check` on every commit) and the CI `typecheck` job only run when `afterpython/ty.toml` exists. |
| 62 | +If you declined ty during `ap init` (or its setup was skipped), they are removed/skipped. |
| 63 | + |
| 64 | +:::{note} |
| 65 | +Unlike `afterpython/ruff.toml`, relative paths in `afterpython/ty.toml` are resolved from the project root, |
| 66 | +e.g. use `"tests/"` to target your project's `tests/` folder. |
| 67 | +::: |
| 68 | + |
| 69 | +### Python Environment |
| 70 | +ty needs your project's Python environment to resolve imports of installed packages. |
| 71 | +It automatically uses the activated virtual environment, or `.venv` at the project root. |
| 72 | +For other environments (e.g. `pixi` or `conda`), or if your project has both `.venv` and a `pixi` environment and you want the latter, set it in `afterpython/ty.toml`: |
| 73 | +```toml |
| 74 | +[environment] |
| 75 | +python = ".pixi/envs/default" |
| 76 | +``` |
| 77 | +Packages you only use in some files (e.g. `pytest` in `tests/`) must be installed in that environment too, otherwise ty reports them as unresolved imports. |
| 78 | +With `pixi`, that means adding the feature to your default environment, e.g. `default = ["dev", "test"]` in `pixi.toml`. |
| 79 | + |
| 80 | +### Editor Setup |
| 81 | +ty's language server (used by editor extensions) doesn't find `afterpython/ty.toml` by itself, you need to set its `configurationFile` setting **in your project's settings**, e.g. |
| 82 | + |
| 83 | +VS Code (`.vscode/settings.json`): |
| 84 | +```json |
| 85 | +{ |
| 86 | + "ty.configurationFile": "./afterpython/ty.toml" |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +Zed (`.zed/settings.json`): |
| 91 | +```json |
| 92 | +{ |
| 93 | + "lsp": { |
| 94 | + "ty": { |
| 95 | + "settings": { |
| 96 | + "configurationFile": "./afterpython/ty.toml" |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | +``` |
| 102 | +For other editors, see ty's [editor settings](https://docs.astral.sh/ty/reference/editor-settings/#configurationfile). |
| 103 | + |
| 104 | +:::{warning} |
| 105 | +Don't set it in your global (user) settings, ty fails to load projects that don't have `afterpython/ty.toml`. |
| 106 | +::: |
| 107 | + |
44 | 108 | --- |
45 | 109 | ## Python Check Updates (`pcu`) |
46 | 110 | As a package maintainer, you face a dilemma: your dependencies (e.g. `pandas`) release new versions with bug fixes and features, but updating the minimum versions (e.g. `pandas>=2.0.0`) in your `pyproject.toml` means dropping support for users with older versions. |
|
0 commit comments