Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lock generation in WORKSPACE #58

Merged
merged 16 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ python_register_toolchains(
python_version = "3.12.0",
)

load("@python//:defs.bzl", python_interpreter = "interpreter")

# Fetch dependencies which users need as well
load("//pycross:repositories.bzl", "rules_pycross_dependencies")

rules_pycross_dependencies()
rules_pycross_dependencies(python_interpreter)

# For running our own unit tests
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
Expand Down
103 changes: 85 additions & 18 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Public API re-exports

<pre>
pycross_lock_file(<a href="#pycross_lock_file-name">name</a>, <a href="#pycross_lock_file-always_build_packages">always_build_packages</a>, <a href="#pycross_lock_file-build_prefix">build_prefix</a>, <a href="#pycross_lock_file-build_target_overrides">build_target_overrides</a>,
<a href="#pycross_lock_file-default_alias_single_version">default_alias_single_version</a>, <a href="#pycross_lock_file-disallow_builds">disallow_builds</a>, <a href="#pycross_lock_file-environment_prefix">environment_prefix</a>, <a href="#pycross_lock_file-local_wheels">local_wheels</a>,
<a href="#pycross_lock_file-lock_model_file">lock_model_file</a>, <a href="#pycross_lock_file-out">out</a>, <a href="#pycross_lock_file-package_build_dependencies">package_build_dependencies</a>, <a href="#pycross_lock_file-package_ignore_dependencies">package_ignore_dependencies</a>,
<a href="#pycross_lock_file-package_prefix">package_prefix</a>, <a href="#pycross_lock_file-pypi_index">pypi_index</a>, <a href="#pycross_lock_file-remote_wheels">remote_wheels</a>, <a href="#pycross_lock_file-repo_prefix">repo_prefix</a>, <a href="#pycross_lock_file-target_environments">target_environments</a>)
<a href="#pycross_lock_file-default_alias_single_version">default_alias_single_version</a>, <a href="#pycross_lock_file-disallow_builds">disallow_builds</a>, <a href="#pycross_lock_file-environment_prefix">environment_prefix</a>,
<a href="#pycross_lock_file-generate_file_map">generate_file_map</a>, <a href="#pycross_lock_file-local_wheels">local_wheels</a>, <a href="#pycross_lock_file-lock_model_file">lock_model_file</a>, <a href="#pycross_lock_file-out">out</a>, <a href="#pycross_lock_file-package_build_dependencies">package_build_dependencies</a>,
<a href="#pycross_lock_file-package_ignore_dependencies">package_ignore_dependencies</a>, <a href="#pycross_lock_file-package_prefix">package_prefix</a>, <a href="#pycross_lock_file-pypi_index">pypi_index</a>, <a href="#pycross_lock_file-remote_wheels">remote_wheels</a>, <a href="#pycross_lock_file-repo_prefix">repo_prefix</a>,
<a href="#pycross_lock_file-target_environments">target_environments</a>)
</pre>


Expand All @@ -27,6 +28,7 @@ pycross_lock_file(<a href="#pycross_lock_file-name">name</a>, <a href="#pycross_
| <a id="pycross_lock_file-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 | <code>False</code> |
| <a id="pycross_lock_file-disallow_builds"></a>disallow_builds | Do not allow pycross_wheel_build targets in the final lock file (i.e., require wheels). | Boolean | optional | <code>False</code> |
| <a id="pycross_lock_file-environment_prefix"></a>environment_prefix | An optional prefix to apply to environment targets. Defaults to _env | String | optional | <code>"_env"</code> |
| <a id="pycross_lock_file-generate_file_map"></a>generate_file_map | Generate a FILES dict containing a mapping of filenames to repo labels. | Boolean | optional | <code>False</code> |
| <a id="pycross_lock_file-local_wheels"></a>local_wheels | A list of wheel files. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="pycross_lock_file-lock_model_file"></a>lock_model_file | The lock model JSON file. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="pycross_lock_file-out"></a>out | The output file. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
Expand Down Expand Up @@ -87,6 +89,45 @@ pycross_pdm_lock_model(<a href="#pycross_pdm_lock_model-name">name</a>, <a href=
| <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 | <code>True</code> |


<a id="pycross_pkg_repo"></a>

## pycross_pkg_repo

<pre>
pycross_pkg_repo(<a href="#pycross_pkg_repo-name">name</a>, <a href="#pycross_pkg_repo-always_build_packages">always_build_packages</a>, <a href="#pycross_pkg_repo-build_prefix">build_prefix</a>, <a href="#pycross_pkg_repo-build_target_overrides">build_target_overrides</a>,
<a href="#pycross_pkg_repo-default_alias_single_version">default_alias_single_version</a>, <a href="#pycross_pkg_repo-disallow_builds">disallow_builds</a>, <a href="#pycross_pkg_repo-environment_prefix">environment_prefix</a>, <a href="#pycross_pkg_repo-generate_file_map">generate_file_map</a>,
<a href="#pycross_pkg_repo-local_wheels">local_wheels</a>, <a href="#pycross_pkg_repo-lock_model">lock_model</a>, <a href="#pycross_pkg_repo-package_build_dependencies">package_build_dependencies</a>, <a href="#pycross_pkg_repo-package_ignore_dependencies">package_ignore_dependencies</a>,
<a href="#pycross_pkg_repo-package_prefix">package_prefix</a>, <a href="#pycross_pkg_repo-pypi_index">pypi_index</a>, <a href="#pycross_pkg_repo-remote_wheels">remote_wheels</a>, <a href="#pycross_pkg_repo-repo_mapping">repo_mapping</a>, <a href="#pycross_pkg_repo-repo_prefix">repo_prefix</a>,
<a href="#pycross_pkg_repo-target_environments">target_environments</a>)
</pre>



**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="pycross_pkg_repo-name"></a>name | A unique name for this repository. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="pycross_pkg_repo-always_build_packages"></a>always_build_packages | A list of package keys (name or name@version) to always build from source. | List of strings | optional | <code>[]</code> |
| <a id="pycross_pkg_repo-build_prefix"></a>build_prefix | An optional prefix to apply to package build targets. Defaults to _build | String | optional | <code>"_build"</code> |
| <a id="pycross_pkg_repo-build_target_overrides"></a>build_target_overrides | A mapping of package keys (name or name@version) to existing pycross_wheel_build build targets. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="pycross_pkg_repo-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 | <code>False</code> |
| <a id="pycross_pkg_repo-disallow_builds"></a>disallow_builds | Do not allow pycross_wheel_build targets in the final lock file (i.e., require wheels). | Boolean | optional | <code>False</code> |
| <a id="pycross_pkg_repo-environment_prefix"></a>environment_prefix | An optional prefix to apply to environment targets. Defaults to _env | String | optional | <code>"_env"</code> |
| <a id="pycross_pkg_repo-generate_file_map"></a>generate_file_map | Generate a FILES dict containing a mapping of filenames to repo labels. | Boolean | optional | <code>False</code> |
| <a id="pycross_pkg_repo-local_wheels"></a>local_wheels | A list of wheel files. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="pycross_pkg_repo-lock_model"></a>lock_model | Lock model params. The returned value of pkg_repo_model_pdm or pkg_repo_model_poetry. | String | required | |
| <a id="pycross_pkg_repo-package_build_dependencies"></a>package_build_dependencies | A dict of package keys (name or name@version) to a list of that packages build dependency keys. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> List of strings</a> | optional | <code>{}</code> |
| <a id="pycross_pkg_repo-package_ignore_dependencies"></a>package_ignore_dependencies | A dict of package keys (name or name@version) to a list of that packages dependency keys to ignore. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> List of strings</a> | optional | <code>{}</code> |
| <a id="pycross_pkg_repo-package_prefix"></a>package_prefix | An optional prefix to apply to package targets. | String | optional | <code>""</code> |
| <a id="pycross_pkg_repo-pypi_index"></a>pypi_index | The PyPI-compatible index to use (must support the JSON API). | String | optional | <code>""</code> |
| <a id="pycross_pkg_repo-remote_wheels"></a>remote_wheels | A mapping of remote wheels to their sha256 hashes. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="pycross_pkg_repo-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |
| <a id="pycross_pkg_repo-repo_prefix"></a>repo_prefix | The prefix to apply to repository targets. Defaults to the lock file target name. | String | optional | <code>""</code> |
| <a id="pycross_pkg_repo-target_environments"></a>target_environments | A list of pycross_target_environment labels. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |


<a id="pycross_poetry_lock_model"></a>

## pycross_poetry_lock_model
Expand Down Expand Up @@ -232,42 +273,68 @@ Downloads a file from a PyPI-compatible package index.
| <a id="pypi_file-sha256"></a>sha256 | The expected SHA-256 of the file downloaded. | String | required | |


<a id="PycrossTargetEnvironmentInfo"></a>
<a id="PycrossWheelInfo"></a>

## PycrossTargetEnvironmentInfo
## PycrossWheelInfo

<pre>
PycrossTargetEnvironmentInfo(<a href="#PycrossTargetEnvironmentInfo-python_compatible_with">python_compatible_with</a>, <a href="#PycrossTargetEnvironmentInfo-file">file</a>)
PycrossWheelInfo(<a href="#PycrossWheelInfo-name_file">name_file</a>, <a href="#PycrossWheelInfo-wheel_file">wheel_file</a>)
</pre>

A target environment description.
Information about a Python wheel.

**FIELDS**


| Name | Description |
| :------------- | :------------- |
| <a id="PycrossTargetEnvironmentInfo-python_compatible_with"></a>python_compatible_with | A list of constraints used to select this platform. |
| <a id="PycrossTargetEnvironmentInfo-file"></a>file | The JSON file containing target environment information. |
| <a id="PycrossWheelInfo-name_file"></a>name_file | File: A file containing the canonical name of the wheel. |
| <a id="PycrossWheelInfo-wheel_file"></a>wheel_file | File: The wheel file itself. |


<a id="PycrossWheelInfo"></a>
<a id="pkg_repo_model_pdm"></a>

## PycrossWheelInfo
## pkg_repo_model_pdm

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

Information about a Python wheel.

**FIELDS**

**PARAMETERS**

| Name | Description |
| :------------- | :------------- |
| <a id="PycrossWheelInfo-name_file"></a>name_file | File: A file containing the canonical name of the wheel. |
| <a id="PycrossWheelInfo-wheel_file"></a>wheel_file | File: The wheel file itself. |

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


<a id="pkg_repo_model_poetry"></a>

## pkg_repo_model_poetry

<pre>
pkg_repo_model_poetry(<a href="#pkg_repo_model_poetry-project_file">project_file</a>, <a href="#pkg_repo_model_poetry-lock_file">lock_file</a>)
</pre>



**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="pkg_repo_model_poetry-project_file"></a>project_file | <p align="center"> - </p> | none |
| <a id="pkg_repo_model_poetry-lock_file"></a>lock_file | <p align="center"> - </p> | none |


<a id="pycross_register_for_python_toolchains"></a>
Expand Down
5 changes: 4 additions & 1 deletion examples/external_linking/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ local_repository(
)

load("@jvolkman_rules_pycross//pycross:repositories.bzl", "rules_pycross_dependencies")
load("@python3_10//:defs.bzl", python_interpreter = "interpreter")

rules_pycross_dependencies()
rules_pycross_dependencies(
python_interpreter_target = python_interpreter,
)

load("@jvolkman_rules_pycross//pycross:defs.bzl", "pycross_lock_repo")

Expand Down
5 changes: 4 additions & 1 deletion examples/pdm/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ local_repository(
)

load("@jvolkman_rules_pycross//pycross:repositories.bzl", "rules_pycross_dependencies")
load("@python3_11//:defs.bzl", python_interpreter = "interpreter")

rules_pycross_dependencies()
rules_pycross_dependencies(
python_interpreter_target = python_interpreter,
)

load("@jvolkman_rules_pycross//pycross:defs.bzl", "pycross_lock_repo")

Expand Down
1 change: 1 addition & 0 deletions examples/pkg_repo/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.4.0
9 changes: 9 additions & 0 deletions examples/pkg_repo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@rules_python//python:defs.bzl", "py_binary")

py_binary(
name = "ipython",
srcs = ["ipython.py"],
deps = [
"@pdm//:ipython",
],
)
66 changes: 66 additions & 0 deletions examples/pkg_repo/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
workspace(
name = "jvolkman_rules_pycross_example",
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_python",
sha256 = "9acc0944c94adb23fba1c9988b48768b1bacc6583b52a2586895c5b7491e2e31",
strip_prefix = "rules_python-0.27.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.27.0/rules_python-0.27.0.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains")

py_repositories()

python_register_multi_toolchains(
name = "python",
default_version = "3.12",
python_versions = [
"3.10",
"3.11",
"3.12",
],
)

load("@python//3.12:defs.bzl", python_interpreter = "interpreter")

local_repository(
name = "jvolkman_rules_pycross",
path = "../..",
)

load("@jvolkman_rules_pycross//pycross:repositories.bzl", "rules_pycross_dependencies")

rules_pycross_dependencies(
python_interpreter_target = python_interpreter,
)

load(
"@jvolkman_rules_pycross//pycross:defs.bzl",
"pkg_repo_model_pdm",
"pycross_pkg_repo",
"pycross_register_for_python_toolchains",
)

pycross_register_for_python_toolchains(
name = "pycross_toolchains",
python_toolchains_repo_name = "python",
)

load("@pycross_toolchains//:defs.bzl", "environments")

pycross_pkg_repo(
name = "pdm",
lock_model = pkg_repo_model_pdm(
lock_file = "@//:pdm.lock",
project_file = "@//:pyproject.toml",
),
target_environments = environments,
)

load("@pdm//:defs.bzl", "install_deps")

install_deps()
3 changes: 3 additions & 0 deletions examples/pkg_repo/ipython.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from IPython import start_ipython

start_ipython()
Loading