Skip to content

Commit

Permalink
Merge pull request #343 from tweag/poetry-python-modules
Browse files Browse the repository at this point in the history
Initial implementation of python modules with poetry
  • Loading branch information
mergify[bot] authored Mar 14, 2023
2 parents b8a985a + 02a66d2 commit ad61728
Show file tree
Hide file tree
Showing 17 changed files with 835 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .bazelrc.common
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ build --host_platform=@rules_nixpkgs_core//platforms:host
build:bzlmod --enable_bzlmod
build:bzlmod --registry=https://bcr.bazel.build

test --test_output=errors

# User Configuration
# ------------------
try-import %workspace%/.bazelrc.local
Expand Down
146 changes: 146 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ See [examples](/examples/toolchains) for how to use `rules_nixpkgs` with differe
* [nixpkgs_cc_configure_deprecated](#nixpkgs_cc_configure_deprecated)
* [nixpkgs_java_configure](#nixpkgs_java_configure)
* [nixpkgs_python_configure](#nixpkgs_python_configure)
* [nixpkgs_python_repository](#nixpkgs_python_repository)
* [nixpkgs_go_configure](toolchains/go/README.md#nixpkgs_go_configure)
* [nixpkgs_rust_configure](#nixpkgs_rust_configure)
* [nixpkgs_sh_posix_configure](#nixpkgs_sh_posix_configure)
Expand Down Expand Up @@ -1836,6 +1837,151 @@ default is <code>True</code>
</table>


<a id="#nixpkgs_python_repository"></a>

### nixpkgs_python_repository

<pre>
nixpkgs_python_repository(<a href="#nixpkgs_python_repository-name">name</a>, <a href="#nixpkgs_python_repository-repository">repository</a>, <a href="#nixpkgs_python_repository-repositories">repositories</a>, <a href="#nixpkgs_python_repository-nix_file">nix_file</a>, <a href="#nixpkgs_python_repository-nix_file_deps">nix_file_deps</a>, <a href="#nixpkgs_python_repository-quiet">quiet</a>)
</pre>

Define a collection of python packages based on a nix file.

The only entry point is a [`nix_file`](#nixpkgs_python_repository-nix_file)
which should expose a `pkgs` and a `python` attributes. `python` is the
python interpreter, and `pkgs` a set of python packages that will be made
available to bazel.

:warning: All the packages in `pkgs` are built by this rule. It is
therefore not a good idea to expose something as big as `pkgs.python3` as
provided by nixpkgs.

This rule is instead intended to expose an ad-hoc set of packages for your
project, as can be built by poetry2nix, mach-nix, dream2nix or by manually
picking the python packages you need from nixpkgs.

The format is generic to support the many ways to generate such packages
sets with nixpkgs. See our python [`tests`](/testing/toolchains/python) and
[examples](`/examples/toolchains/python`) to get started.

This rule is intended to mimic as closely as possible the [rules_python
API](https://github.com/bazelbuild/rules_python#using-the-package-installation-rules).
`nixpkgs_python_repository` should be a drop-in replacement of `pip_parse`.
As such, it also provides a `requirement` function.

:warning: Using the `requirement` fucntion inherits the same advantages and
limitations as the one in rules_python. All the function does is create a
label of the form `@{nixpkgs_python_repository_name}//:{package_name}`.
While depending on such a label directly will work, the layout may change
in the future. To be on the safe side, define and import your own
`requirement` function if you need to play with these labels.

:warning: Just as with rules_python, nothing is done to enforce consistency
between the version of python used to generate this repository and the one
configured in your toolchain, even if you use nixpkgs_python_toolchain. You
should ensure they both use the same python from the same nixpkgs version.

:warning: packages names exposed by this rule are determined by the `pname`
attribute of the corresponding nix package. These may vary slightly from
names used by rules_python. Should this be a problem, you can provide you
own `requirement` function, for example one that lowercases its argument.


#### Parameters

<table class="params-table">
<colgroup>
<col class="col-param" />
<col class="col-description" />
</colgroup>
<tbody>
<tr id="nixpkgs_python_repository-name">
<td><code>name</code></td>
<td>

required.

<p>

The name for the created package set.

</p>
</td>
</tr>
<tr id="nixpkgs_python_repository-repository">
<td><code>repository</code></td>
<td>

optional.
default is <code>None</code>

<p>

See [`nixpkgs_package`](#nixpkgs_package-repository).

</p>
</td>
</tr>
<tr id="nixpkgs_python_repository-repositories">
<td><code>repositories</code></td>
<td>

optional.
default is <code>{}</code>

<p>

See [`nixpkgs_package`](#nixpkgs_package-repositories).

</p>
</td>
</tr>
<tr id="nixpkgs_python_repository-nix_file">
<td><code>nix_file</code></td>
<td>

optional.
default is <code>None</code>

<p>

See [`nixpkgs_package`](#nixpkgs_package-nix_file).

</p>
</td>
</tr>
<tr id="nixpkgs_python_repository-nix_file_deps">
<td><code>nix_file_deps</code></td>
<td>

optional.
default is <code>[]</code>

<p>

See [`nixpkgs_package`](#nixpkgs_package-nix_file_deps).

</p>
</td>
</tr>
<tr id="nixpkgs_python_repository-quiet">
<td><code>quiet</code></td>
<td>

optional.
default is <code>False</code>

<p>

See [`nixpkgs_package`](#nixpkgs_package-quiet).

</p>
</td>
</tr>
</tbody>
</table>


<a id="#nixpkgs_rust_configure"></a>

### nixpkgs_rust_configure
Expand Down
1 change: 1 addition & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ generate_documentation(
"nixpkgs_go_configure",
"nixpkgs_java_configure",
"nixpkgs_python_configure",
"nixpkgs_python_repository",
"nixpkgs_rust_configure",
"nixpkgs_sh_posix_configure",
"nixpkgs_nodejs_configure",
Expand Down
3 changes: 3 additions & 0 deletions nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ See [examples](/examples/toolchains) for how to use `rules_nixpkgs` with differe
* [nixpkgs_cc_configure_deprecated](#nixpkgs_cc_configure_deprecated)
* [nixpkgs_java_configure](#nixpkgs_java_configure)
* [nixpkgs_python_configure](#nixpkgs_python_configure)
* [nixpkgs_python_repository](#nixpkgs_python_repository)
* [nixpkgs_go_configure](toolchains/go/README.md#nixpkgs_go_configure)
* [nixpkgs_rust_configure](#nixpkgs_rust_configure)
* [nixpkgs_sh_posix_configure](#nixpkgs_sh_posix_configure)
Expand Down Expand Up @@ -130,6 +131,7 @@ load(
load(
"@rules_nixpkgs_python//:python.bzl",
_nixpkgs_python_configure = "nixpkgs_python_configure",
_nixpkgs_python_repository = "nixpkgs_python_repository",
)
load(
"@rules_nixpkgs_java//:java.bzl",
Expand Down Expand Up @@ -158,6 +160,7 @@ nixpkgs_git_repository = _nixpkgs_git_repository
nixpkgs_local_repository = _nixpkgs_local_repository
nixpkgs_package = _nixpkgs_package
nixpkgs_python_configure = _nixpkgs_python_configure
nixpkgs_python_repository = _nixpkgs_python_repository
nixpkgs_java_configure = _nixpkgs_java_configure
nixpkgs_cc_configure = _nixpkgs_cc_configure
nixpkgs_rust_configure = _nixpkgs_rust_configure
Expand Down
5 changes: 5 additions & 0 deletions testing/python/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ use_repo(non_module_deps, "nixpkgs_python_toolchain")
use_repo(non_module_deps, "nixpkgs_python_configure_test")
use_repo(non_module_deps, "nixpkgs_python_toolchain_python3")
register_toolchains("@nixpkgs_python_toolchain//:all")

use_repo(non_module_deps, "generated_poetry_packages_deps")
use_repo(non_module_deps, "poetry_packages")
use_repo(non_module_deps, "generated_vanilla_packages_deps")
use_repo(non_module_deps, "vanilla_packages")
Loading

0 comments on commit ad61728

Please sign in to comment.