Pants will load a REPL with all of your specified source code and any of its third-party dependencies, which allows you to import those values.
ctrl-cdoesn't work properly when using Pantsd
When using the Pants daemon (the default),
ctrl-cwill result in the program trying to exit, but never closing. To avoid this, you can exit by typing
ctrl-d, or by running
./pants --no-pantsd repl path/to/file.py.
If you see a log message like this:
[INFO] Sending SIGINT to pantsd with pid 70726, waiting up to 5.0 seconds before sending SIGKILL...
Look for the PID in the message, and run
kill -9 <pid>.
This is fixed in Pants 2.0.
In addition to the default Python shell, Pants supports the improved IPython shell.
To use IPython, run
./pants repl --shell=ipython. To permanently use IPython, add this to your
[repl] shell = "ipython"
You can change IPython's version with
[ipython] version = "ipython>=5.8.0,<6"
IPython does not yet work with Pantsd
When using IPython, use the option
--no-pantsdto turn off the Pants daemon, e.g.
./pants --no-pantsd repl --shell=ipython. We are working to fix this.
$ <<pantscmd>> repl helloworld/greet/greeting.py Python 3.7.6 (default, Feb 26 2020, 08:28:08) [Clang 11.0.0 (clang-1188.8.131.52)] on darwin Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from helloworld.greet.greeting import Greeter >>> Greeter().greet("Pants") 'buenas tardes, Pants!' >>> from translate import Translator >>> Translator(to_lang="fr").translate("Good morning.") 'Salut.'
This will not load any of your code:
$ ./pants --no-pantsd repl --shell=ipython Python 3.6.10 (default, Feb 26 2020, 08:26:13) Type "copyright", "credits" or "license" for more information. IPython 5.8.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In : 21 * 4 Out: 84
Tip: how to exit the REPL
exit()and hit enter, or press
Updated about 3 years ago