Skip to content

Commit d9bed35

Browse files
committed
flesh out docs a bit
1 parent 44dda2f commit d9bed35

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pip
101101
coverage
102102
precompiling
103103
gazelle
104+
REPL <repl>
104105
Extending <extending>
105106
Contributing <contributing>
106107
support

docs/repl.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,47 @@ for your code.
66

77
## Usage
88

9+
Start the REPL with the following command:
10+
```console
11+
$ bazel run @rules_python//python/bin:repl
12+
Python 3.11.11 (main, Mar 17 2025, 21:02:09) [Clang 20.1.0 ] on linux
13+
Type "help", "copyright", "credits" or "license" for more information.
14+
>>>
15+
```
16+
17+
Settings like `//python/config_settings:python_version` will influence the exact
18+
behaviour.
19+
```console
20+
$ bazel run @rules_python//python/bin:repl --@rules_python//python/config_settings:python_version=3.13
21+
Python 3.13.2 (main, Mar 17 2025, 21:02:54) [Clang 20.1.0 ] on linux
22+
Type "help", "copyright", "credits" or "license" for more information.
23+
>>>
24+
```
25+
26+
See [//python/config_settings](api/rules_python/python/config_settings/index)
27+
and [Environment Variables](environment-variables) for more settings.
928

29+
## Importing Python targets
30+
31+
The `//python/bin:repl_dep` command line flag gives the REPL access to a target
32+
that provides the `PyInfo` provider.
33+
34+
```console
35+
$ bazel run @rules_python//python/bin:repl --@rules_python//python/bin:repl_dep=@rules_python//tools:wheelmaker
36+
Python 3.11.11 (main, Mar 17 2025, 21:02:09) [Clang 20.1.0 ] on linux
37+
Type "help", "copyright", "credits" or "license" for more information.
38+
>>> import tools.wheelmaker
39+
>>>
40+
```
1041

1142
## Customizing the shell
1243

1344
By default, the `//python/bin:repl` target will invoke the shell from the `code`
1445
module. It's possible to switch to another shell by writing a custom "stub" and
1546
pointing the target at the necessary dependencies.
1647

48+
### IPython Example
49+
1750
For an IPython shell, create a file as follows.
1851

1952
```python
@@ -22,7 +55,7 @@ IPython.start_ipython()
2255
```
2356

2457
Assuming the file is called `ipython_stub.py` and the `pip.parse` hub's name is
25-
`my_deps`, then set this up in the .bazelrc file:
58+
`my_deps`, set this up in the .bazelrc file:
2659
```
2760
# Allow the REPL stub to import ipython. In this case, @my_deps is the hub name
2861
# of the pip.parse() call.

docs/toolchains.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,3 +757,13 @@ a fixed version.
757757
The `python` target does not provide access to any modules from `py_*`
758758
targets on its own. Please file a feature request if this is desired.
759759
:::
760+
761+
### Differences from `//python/bin:repl`
762+
763+
The `//python/bin:python` target provides access to the underlying interpreter
764+
without any hermeticity guarantees.
765+
766+
The [`//python/bin:repl` target](repl) provides an environment indentical to
767+
what `py_binary` provides. That means it handles things like the
768+
[`PYTHONSAFEPATH`](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSAFEPATH)
769+
environment variable automatically. The `//python/bin:python` target will not.

0 commit comments

Comments
 (0)