Skip to content

Commit

Permalink
feat: Implement UV lock translator (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewianda authored Jul 9, 2024
1 parent 05882e5 commit b0b8c8f
Show file tree
Hide file tree
Showing 18 changed files with 1,265 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# `rules_pycross` - Python + cross platform

Use your Poetry or PDM lock files with Bazel and enabling cross-platform builds.
Use your Poetry or PDM or UV lock files with Bazel and enabling cross-platform builds.

### Features:

- A single lock file for all target platforms, thanks to Poetry and PDM
- A single lock file for all target platforms, thanks to Poetry, PDM and UV
- Builds that happen in build actions, not during WORKSPACE initialization
- Standard Bazel `http_file` rules used for fetching dependencies. `pip` is not a build-time dependency.

> **Notice:** UV is still experimental
See the [examples](examples).

### Why?
Expand Down
30 changes: 29 additions & 1 deletion docs/ext_lock_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ lock_import.import_pdm(<a href="#lock_import.import_pdm-all_development_groups">
<a href="#lock_import.import_pdm-require_static_urls">require_static_urls</a>, <a href="#lock_import.import_pdm-target_environments">target_environments</a>)
lock_import.import_poetry(<a href="#lock_import.import_poetry-default_alias_single_version">default_alias_single_version</a>, <a href="#lock_import.import_poetry-disallow_builds">disallow_builds</a>, <a href="#lock_import.import_poetry-local_wheels">local_wheels</a>, <a href="#lock_import.import_poetry-lock_file">lock_file</a>,
<a href="#lock_import.import_poetry-project_file">project_file</a>, <a href="#lock_import.import_poetry-repo">repo</a>, <a href="#lock_import.import_poetry-target_environments">target_environments</a>)
lock_import.import_uv(<a href="#lock_import.import_uv-all_development_groups">all_development_groups</a>, <a href="#lock_import.import_uv-all_optional_groups">all_optional_groups</a>, <a href="#lock_import.import_uv-default">default</a>,
<a href="#lock_import.import_uv-default_alias_single_version">default_alias_single_version</a>, <a href="#lock_import.import_uv-development_groups">development_groups</a>, <a href="#lock_import.import_uv-disallow_builds">disallow_builds</a>, <a href="#lock_import.import_uv-local_wheels">local_wheels</a>,
<a href="#lock_import.import_uv-lock_file">lock_file</a>, <a href="#lock_import.import_uv-optional_groups">optional_groups</a>, <a href="#lock_import.import_uv-project_file">project_file</a>, <a href="#lock_import.import_uv-repo">repo</a>, <a href="#lock_import.import_uv-require_static_urls">require_static_urls</a>,
<a href="#lock_import.import_uv-target_environments">target_environments</a>)
lock_import.package(<a href="#lock_import.package-name">name</a>, <a href="#lock_import.package-always_build">always_build</a>, <a href="#lock_import.package-build_dependencies">build_dependencies</a>, <a href="#lock_import.package-build_target">build_target</a>, <a href="#lock_import.package-ignore_dependencies">ignore_dependencies</a>,
<a href="#lock_import.package-install_exclude_globs">install_exclude_globs</a>, <a href="#lock_import.package-repo">repo</a>)
</pre>
Expand All @@ -38,7 +42,7 @@ Import a PDM lock file.
| <a id="lock_import.import_pdm-development_groups"></a>development_groups | List of development dependency groups to install. | List of strings | optional | `[]` |
| <a id="lock_import.import_pdm-disallow_builds"></a>disallow_builds | If True, only pre-built wheels are allowed. | Boolean | optional | `False` |
| <a id="lock_import.import_pdm-local_wheels"></a>local_wheels | A list of local .whl files to consider when processing lock files. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="lock_import.import_pdm-lock_file"></a>lock_file | The pdm.lock file. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="lock_import.import_pdm-lock_file"></a>lock_file | The lock file. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="lock_import.import_pdm-optional_groups"></a>optional_groups | List of optional dependency groups to install. | List of strings | optional | `[]` |
| <a id="lock_import.import_pdm-project_file"></a>project_file | The pyproject.toml file. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="lock_import.import_pdm-repo"></a>repo | The repository name | String | required | |
Expand All @@ -63,6 +67,30 @@ Import a Poetry lock file.
| <a id="lock_import.import_poetry-repo"></a>repo | The repository name | String | required | |
| <a id="lock_import.import_poetry-target_environments"></a>target_environments | A list of target environment descriptors. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `["@pycross_environments//:environments"]` |

<a id="lock_import.import_uv"></a>

### import_uv

Import a uv lock file.

**Attributes**

| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="lock_import.import_uv-all_development_groups"></a>all_development_groups | Install all dev dependencies. | Boolean | optional | `False` |
| <a id="lock_import.import_uv-all_optional_groups"></a>all_optional_groups | Install all optional dependencies. | Boolean | optional | `False` |
| <a id="lock_import.import_uv-default"></a>default | Whether to install dependencies from the default group. | Boolean | optional | `True` |
| <a id="lock_import.import_uv-default_alias_single_version"></a>default_alias_single_version | Generate aliases for all packages that have a single version in the lock file. | Boolean | optional | `False` |
| <a id="lock_import.import_uv-development_groups"></a>development_groups | List of development dependency groups to install. | List of strings | optional | `[]` |
| <a id="lock_import.import_uv-disallow_builds"></a>disallow_builds | If True, only pre-built wheels are allowed. | Boolean | optional | `False` |
| <a id="lock_import.import_uv-local_wheels"></a>local_wheels | A list of local .whl files to consider when processing lock files. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="lock_import.import_uv-lock_file"></a>lock_file | The lock file. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="lock_import.import_uv-optional_groups"></a>optional_groups | List of optional dependency groups to install. | List of strings | optional | `[]` |
| <a id="lock_import.import_uv-project_file"></a>project_file | The pyproject.toml file. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="lock_import.import_uv-repo"></a>repo | The repository name | String | required | |
| <a id="lock_import.import_uv-require_static_urls"></a>require_static_urls | Require that the lock file is created with --static-urls. | Boolean | optional | `True` |
| <a id="lock_import.import_uv-target_environments"></a>target_environments | A list of target environment descriptors. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `["@pycross_environments//:environments"]` |

<a id="lock_import.package"></a>

### package
Expand Down
2 changes: 1 addition & 1 deletion docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pycross_pdm_lock_model(<a href="#pycross_pdm_lock_model-name">name</a>, <a href=
| <a id="pycross_pdm_lock_model-all_optional_groups"></a>all_optional_groups | Install all optional dependencies. | Boolean | optional | `False` |
| <a id="pycross_pdm_lock_model-default"></a>default | Whether to install dependencies from the default group. | Boolean | optional | `True` |
| <a id="pycross_pdm_lock_model-development_groups"></a>development_groups | List of development dependency groups to install. | List of strings | optional | `[]` |
| <a id="pycross_pdm_lock_model-lock_file"></a>lock_file | The pdm.lock file. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="pycross_pdm_lock_model-lock_file"></a>lock_file | The lock file. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="pycross_pdm_lock_model-optional_groups"></a>optional_groups | List of optional dependency groups to install. | List of strings | optional | `[]` |
| <a id="pycross_pdm_lock_model-project_file"></a>project_file | The pyproject.toml file. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="pycross_pdm_lock_model-require_static_urls"></a>require_static_urls | Require that the lock file is created with --static-urls. | Boolean | optional | `True` |
Expand Down
26 changes: 26 additions & 0 deletions docs/workspace_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ lock_repo_model_poetry(<a href="#lock_repo_model_poetry-project_file">project_fi
| <a id="lock_repo_model_poetry-lock_file"></a>lock_file | <p align="center"> - </p> | none |


<a id="lock_repo_model_uv"></a>

## lock_repo_model_uv

<pre>
lock_repo_model_uv(<a href="#lock_repo_model_uv-project_file">project_file</a>, <a href="#lock_repo_model_uv-lock_file">lock_file</a>, <a href="#lock_repo_model_uv-default">default</a>, <a href="#lock_repo_model_uv-optional_groups">optional_groups</a>, <a href="#lock_repo_model_uv-all_optional_groups">all_optional_groups</a>,
<a href="#lock_repo_model_uv-development_groups">development_groups</a>, <a href="#lock_repo_model_uv-all_development_groups">all_development_groups</a>, <a href="#lock_repo_model_uv-require_static_urls">require_static_urls</a>)
</pre>



**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="lock_repo_model_uv-project_file"></a>project_file | <p align="center"> - </p> | none |
| <a id="lock_repo_model_uv-lock_file"></a>lock_file | <p align="center"> - </p> | none |
| <a id="lock_repo_model_uv-default"></a>default | <p align="center"> - </p> | `True` |
| <a id="lock_repo_model_uv-optional_groups"></a>optional_groups | <p align="center"> - </p> | `[]` |
| <a id="lock_repo_model_uv-all_optional_groups"></a>all_optional_groups | <p align="center"> - </p> | `False` |
| <a id="lock_repo_model_uv-development_groups"></a>development_groups | <p align="center"> - </p> | `[]` |
| <a id="lock_repo_model_uv-all_development_groups"></a>all_development_groups | <p align="center"> - </p> | `False` |
| <a id="lock_repo_model_uv-require_static_urls"></a>require_static_urls | <p align="center"> - </p> | `True` |


<a id="pycross_lock_repo"></a>

## pycross_lock_repo
Expand Down
16 changes: 15 additions & 1 deletion e2e/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ lock_import.import_pdm(
repo = "pdm",
target_environments = ["@smoke_environments//:environments"],
)

# lock_repo with UV and some package overrides
lock_import.import_uv(
default_alias_single_version = True,
local_wheels = [
"//:cowsay-6.1-py3-none-any.whl",
],
lock_file = "//:uv.lock",
project_file = "//:pyproject.toml",
repo = "uv",
target_environments = ["@smoke_environments//:environments"],
)

# lock_repo with PDM and some package overrides
lock_import.package(
name = "regex",
always_build = True,
Expand All @@ -107,7 +121,7 @@ lock_import.package(

# The actual repos are loaded from the lock_repos extension.
lock_repos = use_extension("@rules_pycross//pycross/extensions:lock_repos.bzl", "lock_repos")
use_repo(lock_repos, "pdm", "poetry")
use_repo(lock_repos, "pdm", "poetry", "uv")

# Lock repos for vended lock files
lock_file = use_extension("@rules_pycross//pycross/extensions:lock_file.bzl", "lock_file")
Expand Down
Loading

0 comments on commit b0b8c8f

Please sign in to comment.