Skip to content
Closed
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
3 changes: 3 additions & 0 deletions rules_py/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
.*.venv/
**/bazel-*
1 change: 1 addition & 0 deletions rules_py/ipython/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.1.0
17 changes: 17 additions & 0 deletions rules_py/ipython/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
load("@rules_py//py:defs.bzl", "py_binary")

compile_pip_requirements(
name = "requirements",
extra_args = ["--allow-unsafe"],
requirements_in = "requirements.in",
requirements_txt = "requirements.txt",
)

py_binary(
name = "ipython",
srcs = ["__main__.py"],
deps = [
"@pypi_ipython//:wheel",
],
)
24 changes: 24 additions & 0 deletions rules_py/ipython/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ipython shell with rules_py

This is a minimal example of using the ipython shell with rules_py. It relies on the hermetic Python 3.9 interpreter
from rules_python and uses `pip_parse` to fetch PyPi dependencies.

This demo shows the interaction of external wheels, as well as the ability to create a simple Python virtual environment
for running locally from the command line or from with an IDE.

To start the interactive shell, at the root of this workspace:

```bash
$ bazel run ipython
```

A Python virtual environment can be created that is suitable for IDE consumption. IDEs such as VSCode and PyCharm can be
configured to use this local venv, therefore using the bazel managed interpreter, pip and fetched PyPi packages.

To create the venv, run the following:

```bash
$ bazel run ipython.venv
```

This will create a venv at the root of the workspace ready for IDE configuration.
50 changes: 50 additions & 0 deletions rules_py/ipython/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
workspace(name = "rules_py_ipython_example")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so far our convention in other Aspect rulesets has been that nested workspaces are under an e2e/ folder, and are just meant to protect us from bugs (minimal commenting and content)
User-facing examples are in the examples/ folder and rely on the root WORKSPACE file.

I know we've had a few different iterations on this. It's nice that you can just bazel test ... from the root here and cover all the examples

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then write_source_files doesn't conform to this?
https://github.com/aspect-build/bazel-examples/tree/main/write_source_files

It's nice that you can just bazel test ... from the root here

"here" being this repo, or the rule set? As a lot of the examples in this repo have their own WORKSAPCE etc, so bazel test ... at the root of this repo would kinda do nothing.


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

http_archive(
name = "rules_py",
sha256 = "bb48980475a4362d5492e08d961a638ad9cded9d12cd712d0bc09e40d75477e2",
strip_prefix = "rules_py-7b5b88fe1dfc525162a3f319da035f298d8a1edc",
url = "https://github.com/aspect-build/rules_py/archive/7b5b88fe1dfc525162a3f319da035f298d8a1edc.zip",
)

load("@rules_py//py:repositories.bzl", "rules_py_dependencies")

rules_py_dependencies()

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

python_register_toolchains(
name = "python39",
python_version = "3.9",
)

load("@rules_python//python:pip.bzl", "package_annotation", "pip_install", "pip_parse")

_PY_WHEEL_RULE_CONTENT = """\
load("@rules_py//py:defs.bzl", "py_wheel")
py_wheel(
name = "wheel",
src = ":whl",
)
"""

_PACKAGES = [
"ipython",
]

_ANNOTATIONS = {
pkg: package_annotation(additive_build_content = _PY_WHEEL_RULE_CONTENT)
for pkg in _PACKAGES
}

pip_parse(
name = "pypi",
annotations = _ANNOTATIONS,
requirements_lock = "//:requirements.txt",
)

load("@pypi//:requirements.bzl", "install_deps")

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

start_ipython()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible for a py_binary entrypoint to run ipython without having to add this shim?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

1 change: 1 addition & 0 deletions rules_py/ipython/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ipython
90 changes: 90 additions & 0 deletions rules_py/ipython/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#
# This file is autogenerated by pip-compile
# To update, run:
#
# bazel run //:requirements.update
#
appnope==0.1.3 \
--hash=sha256:02bd91c4de869fbb1e1c50aafc4098827a7a54ab2f39d9dcba6c9547ed920e24 \
--hash=sha256:265a455292d0bd8a72453494fa24df5a11eb18373a60c7c0430889f22548605e
# via ipython
asttokens==2.0.5 \
--hash=sha256:0844691e88552595a6f4a4281a9f7f79b8dd45ca4ccea82e5e05b4bbdb76705c \
--hash=sha256:9a54c114f02c7a9480d56550932546a3f1fe71d8a02f1bc7ccd0ee3ee35cf4d5
# via stack-data
backcall==0.2.0 \
--hash=sha256:5cbdbf27be5e7cfadb448baf0aa95508f91f2bbc6c6437cd9cd06e2a4c215e1e \
--hash=sha256:fbbce6a29f263178a1f7915c1940bde0ec2b2a967566fe1c65c1dfb7422bd255
# via ipython
decorator==5.1.1 \
--hash=sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330 \
--hash=sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186
# via ipython
executing==0.8.3 \
--hash=sha256:c6554e21c6b060590a6d3be4b82fb78f8f0194d809de5ea7df1c093763311501 \
--hash=sha256:d1eef132db1b83649a3905ca6dd8897f71ac6f8cac79a7e58a1a09cf137546c9
# via stack-data
ipython==8.3.0 \
--hash=sha256:341456643a764c28f670409bbd5d2518f9b82c013441084ff2c2fc999698f83b \
--hash=sha256:807ae3cf43b84693c9272f70368440a9a7eaa2e7e6882dad943c32fbf7e51402
# via -r requirements.in
jedi==0.18.1 \
--hash=sha256:637c9635fcf47945ceb91cd7f320234a7be540ded6f3e99a50cb6febdfd1ba8d \
--hash=sha256:74137626a64a99c8eb6ae5832d99b3bdd7d29a3850fe2aa80a4126b2a7d949ab
# via ipython
matplotlib-inline==0.1.3 \
--hash=sha256:a04bfba22e0d1395479f866853ec1ee28eea1485c1d69a6faf00dc3e24ff34ee \
--hash=sha256:aed605ba3b72462d64d475a21a9296f400a19c4f74a31b59103d2a99ffd5aa5c
# via ipython
parso==0.8.3 \
--hash=sha256:8c07be290bb59f03588915921e29e8a50002acaf2cdc5fa0e0114f91709fafa0 \
--hash=sha256:c001d4636cd3aecdaf33cbb40aebb59b094be2a74c556778ef5576c175e19e75
# via jedi
pexpect==4.8.0 \
--hash=sha256:0b48a55dcb3c05f3329815901ea4fc1537514d6ba867a152b581d69ae3710937 \
--hash=sha256:fc65a43959d153d0114afe13997d439c22823a27cefceb5ff35c2178c6784c0c
# via ipython
pickleshare==0.7.5 \
--hash=sha256:87683d47965c1da65cdacaf31c8441d12b8044cdec9aca500cd78fc2c683afca \
--hash=sha256:9649af414d74d4df115d5d718f82acb59c9d418196b7b4290ed47a12ce62df56
# via ipython
prompt-toolkit==3.0.29 \
--hash=sha256:62291dad495e665fca0bda814e342c69952086afb0f4094d0893d357e5c78752 \
--hash=sha256:bd640f60e8cecd74f0dc249713d433ace2ddc62b65ee07f96d358e0b152b6ea7
# via ipython
ptyprocess==0.7.0 \
--hash=sha256:4b41f3967fce3af57cc7e94b888626c18bf37a083e3651ca8feeb66d492fef35 \
--hash=sha256:5c5d0a3b48ceee0b48485e0c26037c0acd7d29765ca3fbb5cb3831d347423220
# via pexpect
pure-eval==0.2.2 \
--hash=sha256:01eaab343580944bc56080ebe0a674b39ec44a945e6d09ba7db3cb8cec289350 \
--hash=sha256:2b45320af6dfaa1750f543d714b6d1c520a1688dec6fd24d339063ce0aaa9ac3
# via stack-data
pygments==2.12.0 \
--hash=sha256:5eb116118f9612ff1ee89ac96437bb6b49e8f04d8a13b514ba26f620208e26eb \
--hash=sha256:dc9c10fb40944260f6ed4c688ece0cd2048414940f1cea51b8b226318411c519
# via ipython
six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
# via asttokens
stack-data==0.2.0 \
--hash=sha256:45692d41bd633a9503a5195552df22b583caf16f0b27c4e58c98d88c8b648e12 \
--hash=sha256:999762f9c3132308789affa03e9271bbbe947bf78311851f4d485d8402ed858e
# via ipython
traitlets==5.1.1 \
--hash=sha256:059f456c5a7c1c82b98c2e8c799f39c9b8128f6d0d46941ee118daace9eb70c7 \
--hash=sha256:2d313cc50a42cd6c277e7d7dc8d4d7fedd06a2c215f78766ae7b1a66277e0033
# via
# ipython
# matplotlib-inline
wcwidth==0.2.5 \
--hash=sha256:beb4802a9cebb9144e99086eff703a642a13d6a0052920003a230f3294bbe784 \
--hash=sha256:c4d647b99872929fdb7bdcaa4fbe7f01413ed3d98077df798530e5b04f116c83
# via prompt-toolkit

# The following packages are considered to be unsafe in a requirements file:
setuptools==62.1.0 \
--hash=sha256:26ead7d1f93efc0f8c804d9fafafbe4a44b179580a7105754b245155f9af05a8 \
--hash=sha256:47c7b0c0f8fc10eec4cf1e71c6fdadf8decaa74ffa087e68cd1c20db7ad6a592
# via ipython