- If you have a code block like this:
if __name__ == "__main__": ...
Then you can run like this:
python3 lambda_function.py # option 1 python3 -m lambda_function # option 2 (equivalent)
This re-evaluates the entire module before executing the function:
python3.8 -m lambda_function -c 'lambda_handler(None, None)'
Open the REPL using SPC o r
(+eval/open-repl-other-window
). To load the
definitions from your script file (e.g. lambda_function.py
) so that you can
run code in the REPL just like in the script file (i.e. same namespace):
from lambda_function import *
If you’ve redefined a function in a file-visiting buffer and would like for the
change to take effect in the REPL, just select the function using vif
and send
it to the REPL with gr
(+eval:region
).
You can also re-evaluate the entire buffer using gR
(+eval/buffer
)
The following standard procedure works OK, but does not integrate with Doom Emacs at all:
virtualenv .venv
. ./.venv/bin/activate
pip install -r requirements.txt
Instead, the python
module in Doom Emacs comes with the pipenv
package,
which provides commands that wrap pipenv
, a package manager that replaces the
standard pip
and virtualenv
. Reference: https://realpython.com/pipenv-guide/
- Create a new virtualenv and install packages
- If you already have a populated
Pipfile
, just runpipenv install
with no arguments usingSPC p &
(projectile-run-async-shell-command-in-root
) and continue to step 2. - If you are fine with using the current system Python version,
SPC m e i
in a python buffer (pipenv-install
) can be used to set things up a. Specify package(s) to install when prompted b. Watch for aPipfile
andPipfile.lock
to appear in the project rootPipfile
will contain a specification of requirements- Commit this file just like you would
requirements.txt
- Commit this file just like you would
Pipfile.lock
will contain a manifest of dependencies- Commit this file if you want reproducible builds
- If you want a specific Python version, run the following shell command
instead of using
pipenv-install
from Emacs:pipenv (--python <version> | --three | --two) install <package>...
- By default, the virtualenv will be created under
$XDG_DATA_HOME/virtualenvs
, but thePIPENV_VENV_IN_PROJECT
option can be set to create a.venv
subdirectory in your project instead
- If you already have a populated
- Activate the virtualenv in Emacs using
SPC m e a
in a python buffer (pipenv-activate
) a. Watch for thevenv:<virtualenv>
lighter to appear in your modeline b. Now useSPC h b i pipenv RET
to view keybindings forpipenv
SPC m e i
(pipenv-install
),SPC m e u
(pipenv-uninstall
), andSPC m e l
(pipenv-lock
) can be used to manage packagesSPC m e r
(pipenv-run
) can be used as an ad-hoc command runner instead ofSPC p !
(projectile-run-command-in-root
)- The
pipenv run
shell command can still be used when outside of the virtualenv (e.g.projectile-run-project
fromREADME.org
)
- The
SPC m e o
(pipenv-open
) can be used to open package modules installed in the virtualenv- The only keybinding I’d actively avoid is
SPC m e s
(pipenv-shell
), which opens ashell-mode
buffer instead of a terminal popup buffer; just run thepipenv shell
shell command in a terminal buffer
- Restart the LSP server using
SPC c l s r
(lsp-workspace-restart
)- This is necessary for the language server to recognize the virtualenv