1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
# hatch-mypyc
| | |
| --- | --- |
| CI/CD | [](https://github.com/ofek/hatch-mypyc/actions/workflows/test.yml) [](https://github.com/ofek/hatch-mypyc/actions/workflows/build.yml) |
| Package | [](https://pypi.org/project/hatch-mypyc/) [](https://pypi.org/project/hatch-mypyc/) |
| Meta | [](https://github.com/pypa/hatch) [](https://github.com/psf/black) [](https://github.com/ambv/black) [](https://spdx.org/licenses/) [](https://github.com/sponsors/ofek) |
-----
This provides a [build hook](https://hatch.pypa.io/latest/config/build/#build-hooks) plugin for [Hatch](https://github.com/pypa/hatch) that compiles code with [Mypyc](https://github.com/mypyc/mypyc).
**Table of Contents**
- [Configuration](#configuration)
- [File selection](#file-selection)
- [Mypy arguments](#mypy-arguments)
- [Options](#options)
- [Missing types](#missing-types)
- [License](#license)
## Configuration
The [build hook plugin](https://hatch.pypa.io/latest/plugins/build-hook/) name is `mypyc`.
- ***pyproject.toml***
```toml
[tool.hatch.build.targets.wheel.hooks.mypyc]
dependencies = ["hatch-mypyc"]
```
- ***hatch.toml***
```toml
[build.targets.wheel.hooks.mypyc]
dependencies = ["hatch-mypyc"]
```
### File selection
By default, all files included using the [standard file selection options](https://hatch.pypa.io/latest/config/build/#file-selection) with a `.py` extension will be targeted. You can narrow what files to compile to an even smaller subset with the `include`/`exclude` options, which represent [Git-style glob patterns](https://git-scm.com/docs/gitignore#_pattern_format).
```toml
[build.targets.wheel.hooks.mypyc]
include = ["/src/pkg/server"]
exclude = ["__main__.py"]
```
### Mypy arguments
You can specify extra [Mypy arguments](https://mypy.readthedocs.io/en/stable/command_line.html) with the `mypy-args` option.
```toml
[build.targets.wheel.hooks.mypyc]
mypy-args = [
"--disallow-untyped-defs",
]
```
### Options
You can specify `options` that affect the behavior of [mypycify](https://github.com/python/mypy/blob/v0.930/mypyc/build.py#L429).
```toml
[build.targets.wheel.hooks.mypyc.options]
opt_level = "3"
```
Note:
- the `target_dir` option is used internally and therefore has no effect
## Missing types
If you need more packages at build time in order to successfully type check, you can use the following options where you [configured the plugin](#configuration):
- `dependencies` - add more dependencies alongside `hatch-mypyc`
- `require-runtime-dependencies` - set to `true` to include dependencies defined in the `project.dependencies` array
- `require-runtime-features` - set to an array of named dependency groups that are defined in `project.optional-dependencies`
## License
`hatch-mypyc` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|