mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-17 02:52:45 +00:00
## Summary We weren't respecting `tool.uv.sources` for `build-requires`. Closes https://github.com/astral-sh/uv/issues/7147.
80 lines
2.8 KiB
Markdown
80 lines
2.8 KiB
Markdown
# Publishing a package
|
|
|
|
uv supports building Python packages into source and binary distributions via `uv build` and
|
|
uploading them to a registry with `uv publish`.
|
|
|
|
## Preparing your project for packaging
|
|
|
|
Before attempting to publish your project, you'll want to make sure it's ready to be packaged for
|
|
distribution.
|
|
|
|
If your project does not include a `[build-system]` definition in the `pyproject.toml`, uv will not
|
|
build it by default. This means that your project may not be ready for distribution. Read more about
|
|
the effect of declaring a build system in the
|
|
[project concept](../concepts/projects.md#build-systems) documentation.
|
|
|
|
## Building your package
|
|
|
|
Build your package with `uv build`:
|
|
|
|
```console
|
|
$ uv build
|
|
```
|
|
|
|
By default, `uv build` will build the project in the current directory, and place the built
|
|
artifacts in a `dist/` subdirectory.
|
|
|
|
Alternatively, `uv build <SRC>` will build the package in the specified directory, while
|
|
`uv build --package <PACKAGE>` will build the specified package within the current workspace.
|
|
|
|
!!! info
|
|
|
|
By default, `uv build` respects `tool.uv.sources` when resolving build dependencies from the
|
|
`build-system.requires` section of the `pyproject.toml`. When publishing a package, we recommend
|
|
running `uv build --no-sources` to ensure that the package builds correctly when `tool.uv.sources`
|
|
is disabled, as is the case when using other build tools, like [`pypa/build`](https://github.com/pypa/build).
|
|
|
|
## Publishing your package
|
|
|
|
Publish your package with `uv publish`:
|
|
|
|
```console
|
|
$ uv publish
|
|
```
|
|
|
|
Set a PyPI token with `--token` or `UV_PUBLISH_TOKEN`, or set a username with `--username` or
|
|
`UV_PUBLISH_USERNAME` and password with `--password` or `UV_PUBLISH_PASSWORD`.
|
|
|
|
!!! info
|
|
|
|
For publishing to PyPI from GitHub Actions, you don't need to set any credentials. Instead,
|
|
[add a trusted publisher to the PyPI project](https://docs.pypi.org/trusted-publishers/adding-a-publisher/).
|
|
|
|
!!! note
|
|
|
|
PyPI does not support publishing with username and password anymore, instead you need to
|
|
generate a token. Using a token is equivalent to setting `--username __token__` and using the
|
|
token as password.
|
|
|
|
## Installing your package
|
|
|
|
Test that the package can be installed and imported with `uv run`:
|
|
|
|
```console
|
|
$ uv run --with <PACKAGE> --no-project -- python -c "import <PACKAGE>"
|
|
```
|
|
|
|
The `--no-project` flag is used to avoid installing the package from your local project directory.
|
|
|
|
!!! tip
|
|
|
|
If you have recently installed the package, you may need to include the
|
|
`--refresh-package <PACKAGE>` option to avoid using a cached version of the package.
|
|
|
|
## Next steps
|
|
|
|
To learn more about publishing packages, check out the
|
|
[PyPA guides](https://packaging.python.org/en/latest/guides/section-build-and-publish/) on building
|
|
and publishing.
|
|
|
|
Or, read on for more details about the concepts in uv.
|