Skip to content

Commit

Permalink
switch to uv (#3)
Browse files Browse the repository at this point in the history
* switch to uv

* fix uv command

* add ruff to deps

* fix things

* una as subdir

* working

* release
  • Loading branch information
carderne authored Aug 27, 2024
1 parent b206798 commit 4edd526
Show file tree
Hide file tree
Showing 34 changed files with 918 additions and 348 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,19 @@ jobs:
if: needs.changes.outputs.python == 'true'
steps:
- uses: actions/checkout@v4
- uses: eifinger/setup-rye@v3
id: setup-rye
- uses: actions/setup-python@v5
with:
version: '0.38.0'
- run: rye pin 3.12.3
python-version: '3.12'
- run: pip install uv
- name: Sync
run: |
rye sync
if [[ $(git diff --stat requirements.lock) != '' ]]; then
echo 'Rye lockfile not up-to-date'
git diff requirements.lock
uv sync --python-preference=system
if [[ $(git diff --stat uv.lock) != '' ]]; then
echo 'uv.lock not up-to-date'
git diff uv.lock
exit 1
fi
- run: rye fmt --check
- run: rye lint
- run: rye run check
- run: rye run test
- run: rye run check
working-directory: plugins/hatch
- run: make fmt-check
- run: make lint
- run: make check
- run: make test
11 changes: 7 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: eifinger/setup-rye@v3
id: setup-rye
- uses: actions/setup-python@v5
with:
version: '0.38.0'
- run: rye build --all
python-version: '3.12'
- run: pip install uv
- run: |
uvx --from build pyproject-build --installer uv --outdir=dist una
uvx --from build pyproject-build --installer uv --outdir=dist plugins/hatch
uvx --from build pyproject-build --installer uv --outdir=dist plugins/pdm
- uses: pypa/gh-action-pypi-publish@release/v1
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
all: fmt lint check test

fmt:
@uv run ruff format

fmt-check:
@uv run ruff format --check

lint:
@uv run ruff check --fix

lint-check:
@uv run ruff check

check:
@uv run basedpyright

test:
@uv run pytest
44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Currently it works with the following build backends, but more will follow:
- [Hatch](https://hatch.pypa.io) (used by default and and in all documentation)
- [PDM](https://pdm-project.org/)

All instructions and examples use Rye for local development, but there is nothing inherently Rye-specific about the tool.
All instructions and examples use [uv](https://docs.astral.sh/uv/) for local development.

## Examples
You can see an example repo here:
Expand All @@ -44,22 +44,22 @@ You can see an example repo here:
## Quickstart
This will give you a quick view of how this all works.

First install Rye:
First install uv:
```bash
curl -sSf https://rye.astral.sh/get | bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

And start your workspace:
```bash
rye init unarepo # choose another name if you prefer
uv init unarepo # choose another name if you prefer
cd unarepo
rye add --dev una
uv add --dev una
```

Then setup the Una workspace. This will generate a structure and an example lib and app.
```
rye run una create workspace
rye sync
uv run una create workspace
uv sync
```

Have a look at what's been generated:
Expand All @@ -79,7 +79,7 @@ You can do this by running the following:
```bash
# this checks all imports and ensures they are added to
# [tool.una.deps] in the appropriate pyproject.toml
rye run una sync
uv run una sync
```

Have a look at what happened:
Expand All @@ -92,7 +92,7 @@ It didn't add `cowsay-python`, as external dependencies are only resolved at bui

Now you can build your app:
```bash
rye build --package printer
uvx --from build pyproject-build --installer uv apps/printer
# this will inject the cowsay-python externel dependency
```

Expand Down Expand Up @@ -121,7 +121,7 @@ But you will likely struggle to manage your monorepo without the tool!

So you may as well install it:
```bash
rye add --dev una
uv add --dev una
```

As for the build-time `hatch-una`, it will automatically be installed by build tools when it spots this in your `pyproject.toml` (this will be configured automatically by the CLI):
Expand All @@ -134,19 +134,17 @@ build-backend = "hatchling.build"
## Usage
The CLI has a few commands and options, have a look:
```bash
rye run una --help
uv run una --help

Usage: una [OPTIONS] COMMAND [ARGS]...

╭─ Options ───────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰─────────────────────────────────────────────────────────────────────────╯
╭─ Commands ──────────────────────────────────────────────────────────────╮
│ create Commands for creating a workspace, apps, libs and projects. │
│ diff Shows changed int_deps compared to the latest git tag. │
│ info Info about the Una workspace. │
│ sync Update pyproject.toml with missing int_deps. │
╰─────────────────────────────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────────╮
│ create Commands for creating workspace and packages.│
│ sync Update packages with missing dependencies. │
╰───────────────────────────────────────────────────────╯
```

## Documentation
Expand All @@ -160,10 +158,10 @@ It covers additional things like:
## Contributing
See the instructions at the [official documentation](https://una.rdrn.me/contributing/).

Very briefly, local development is with Rye:
Very briefly, local development is with uv:
```bash
rye sync
rye run all # will fmt, lint, typecheck and test
uv sync
make all # will fmt, lint, typecheck and test
```

Then open a PR.
Expand Down
10 changes: 2 additions & 8 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ then `hatch-una` will inject all the needed internal dependencies (other stuff i

So all you need to do is run something like:
```bash
rye build

# or just wheels
rye build --wheel

# or with `build`
rye run build
uvx --from build pyproject-build --installer uv apps/printer
```

You'll get some `*.whl` files, which you can then deploy with Docker or whatever you prefer.
They are fully self-contained, so you don't need Hatch/Rye/PDM or Una or anything else wherever you want to install them.
They are fully self-contained, so you don't need uv/Hatch/PDM or Una or anything else wherever you want to install them.
18 changes: 9 additions & 9 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ cd una
git checkout -b add-my-contribution
```

## Setup Rye
Install it if needed (full instructions [here](https://rye.astral.sh/)):
## Setup uv
Install it if needed (full instructions [here](https://docs.astral.sh/uv/getting-started/installation/)):
```bash
curl -sSf https://rye.astral.sh/get | bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

Then sync your local environment:
```bash
rye sync
uv sync
```

## Run all code quality checks
```bash
rye run fmt
rye run lint
rye run check
rye run test
make fmt
make lint
make check
make test

# or
rye run all
make all
```

## Open a PR
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Currently it works with the following build backends, but more will follow:
- [Hatch](https://hatch.pypa.io) (used by default and and in all documentation)
- [PDM](https://pdm-project.org/)

All instructions and examples use Rye for local development, but there is nothing inherently Rye-specific about the tool.
All instructions and examples use [uv](https://docs.astral.sh/uv/) for local development.

## Examples
You can see an example repo here:
Expand Down
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ But you will likely struggle to manage your monorepo without the tool!

So you may as well install it:
```bash
rye add --dev una
uv add --dev una
```

As for the build-time `hatch-una`, it will automatically be installed by build tools when it spots this in your `pyproject.toml` (this will be configured automatically by the CLI):
Expand Down
25 changes: 16 additions & 9 deletions docs/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
You can see an example of this here:
- [una-example](https://github.com/carderne/una-example-packages)

In this setup, we use Rye's built-in workspace support (but you could also just create this structure some other way, YMMV). The structure will look something like this:
In this setup, we use uv's built-in workspace support (but you could also just create this structure some other way, YMMV). The structure will look something like this:
```bash
.
├── pyproject.toml
Expand All @@ -28,31 +28,33 @@ In this setup, we use Rye's built-in workspace support (but you could also just
```

This means:

1. Each `app` or `lib` (collectively, internal dependencies) is it's own Python package with a `pyproject.toml`.
2. You must specify the workspace members in `tool.rye.workspace.members`.
2. You must specify the workspace members in `tool.uv.workspace.members`.
3. Type-checking and testing should be done on a per-package level.
That is, you should run `pyright` and `pytest` from `apps/server` or `libs/mylib`, _not_ from the root.

In the example above, the only build artifact will be for `apps/server`. At build-time, Una will do the following:

1. Read the list of internal dependencies (more on this shortly) and inject them into the build.
2. Read all externel requirements of those dependencies, and add them to the dependency table.

You can then use the Una CLI tool to ensure that all internal dependencies are kept in sync. What are the key steps?
1. Use a Rye workspace:

1. Use a uv workspace:
```toml
# /pyproject.toml
[tool.rye]
managed = true
virtual = true
[tool.uv]

[tool.rye.workspace]
[tool.uv.workspace]
members = ["apps/*", "libs/*"]
```

2. Create your apps and your libs as you would, ensuring that app code is never imported.
Ensure that you choose a good namespace and always use it in your package structures (check `your_ns` in the example structure above.)
3. Add external dependencies to your libs and apps as normal.
Then, to add an internal dependency to an app, we do the following in its pyproject.toml:

```toml
# /apps/server/pyproject.toml
[build-system]
Expand All @@ -64,8 +66,13 @@ build-backend = "hatchling.build"
[tool.una.deps]
"../../libs/mylib/example/mylib" = "example/mylib"
```
4. Then you can run `rye build --wheel` from that package directory and Una will inject everything that is needed.
Once you have your built `.whl` file, all you need in your Dockerfile is:

4. Then you can build from that package directory and Una will inject everything that is needed:
```bash
uvx --from build pyproject-build --installer uv
```

5. Once you have your built `.whl` file, all you need in your Dockerfile is:
```Dockerfile
FROM python
COPY dist dist
Expand Down
16 changes: 8 additions & 8 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Quickstart
This will give you a quick view of how this all works.

First install Rye:
First install uv:
```bash
curl -sSf https://rye.astral.sh/get | bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

And start your workspace:
```bash
rye init unarepo # choose another name if you prefer
uv init unarepo # choose another name if you prefer
cd unarepo
rye add --dev una
uv add --dev una
```

Then setup the Una workspace. This will generate a structure and an example lib and app.
```
rye run una create workspace
rye sync
uv run una create workspace
uv sync
```

Have a look at what's been generated:
Expand All @@ -36,7 +36,7 @@ You can do this by running the following:
```bash
# this checks all imports and ensures they are added to
# [tool.una.deps] in the appropriate pyproject.toml
rye run una sync
uv run una sync
```

Have a look at what happened:
Expand All @@ -49,7 +49,7 @@ It didn't add `cowsay-python`, as external dependencies are only resolved at bui

Now you can build your app:
```bash
rye build --package printer
uvx --from build pyproject-build --installer uv apps/printer
# this will inject the cowsay-python externel dependency
```

Expand Down
2 changes: 1 addition & 1 deletion docs/types-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pythonVersion = "3.11"
strict = ["**/*.py"]
```

Once that is added, you can run `rye run pyright` in the root and it should work correctly.
Once that is added, you can run `uv run pyright` in the root and it should work correctly.

## Pytest
You can just configure pytest as follows in the root pyproject.toml:
Expand Down
18 changes: 8 additions & 10 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Usage
The CLI has a few commands and options, have a look:
```bash
rye run una --help
uv run una --help

Usage: una [OPTIONS] COMMAND [ARGS]...

╭─ Options ───────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰─────────────────────────────────────────────────────────────────────────╯
╭─ Commands ──────────────────────────────────────────────────────────────╮
│ create Commands for creating a workspace, apps, libs and projects. │
│ diff Shows changed int_deps compared to the latest git tag. │
│ info Info about the Una workspace. │
│ sync Update pyproject.toml with missing int_deps. │
╰─────────────────────────────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────────╮
│ create Commands for creating workspace and packages.│
│ sync Update packages with missing dependencies. │
╰───────────────────────────────────────────────────────╯
```
Loading

0 comments on commit 4edd526

Please sign in to comment.