Comments (5)
Nice !
Thanks for giving us feedback.
If having to write the entire virtualenv path annoys you, this block :
#+BEGIN_SRC elisp :results silent :session poetry_virtual_env
(pyvenv-activate "~/.cache/pypoetry/virtualenvs/my-poetry-virtual-env-xUtoYcEX-py3.7/")
#+END_SRC
could be replaced with this simpler one:
#+BEGIN_SRC elisp :results silent :session poetry_virtual_env
(poetry-venv-workon)
#+END_SRC
It will select the adequate virtualenv automatically.
Maybe even simpler, you could use property lines and just add this line at the top of your org file:
# -*- eval: (poetry-venv-workon); -*-
This will automatically activate the poetry virtualenv when opening your org file.
from poetry.el.
I gave a quick try to your snippet and it works fine for me.
The only thing is that I had to restart the babel session (the one you named 'default').
If the session is started outside of the poetry virtualenv, it stays that way until you restart it.
Maybe the problem you are experiencing could come from that ?
from poetry.el.
I have a very similar question :)
My plan was:
- create a poetry project in a version controlled directory
- literate program in an org file (within my org roam directory)
- run source blocks within the poetry virtual env to test my code
- tangle everything to .py files in the project directory
Is this feasible? I have not figured it out yet (specifically the third point)
from poetry.el.
I have figured this out, in case some people are interested in the process here is a link to the reddit question for more details.
In summary:
* create a poetry project in a version controlled directory
This is the easy part, I just used basic poetry
and git
commands (or poetry.el
and magit
at your convenience).
* literate program in an org file
With babel functionalities, again, pretty straight forward with the documentation.
* run source blocks within the poetry virtual env to test my code
The trickiest part: a session must first be spawned in the corresponding virtual env with:
#+BEGIN_SRC elisp :results silent :session poetry_virtual_env
(pyvenv-activate "~/.cache/pypoetry/virtualenvs/my-poetry-virtual-env-xUtoYcEX-py3.7/")
#+END_SRC
Then following python blocks will execute in this virtual env session:
#+BEGIN_SRC python :results output :session poetry_virtual_env
import sys
print(sys.executable)
#+END_SRC
#+RESULTS:
: ~/.cache/pypoetry/virtualenvs/my-poetry-virtual-env-xUtoYcEX-py3.7/bin/python3
* tangle everything to .py files in the project directory
Tangle
deletes the targeted file by default for each new tangled block. I found this excellent stackexchange answer which appends different blocks using noweb-ref
before tangling. Very elegant :)
Here is a stripped down example:
#+BEGIN_SRC shell :noweb yes :exports none :mkdirp yes :tangle /tmp/accumulated.sh
<<accumulated>>
#+END_SRC
#+BEGIN_SRC shell :noweb-ref accumulated
echo "Hello"
#+END_SRC
#+BEGIN_SRC shell :noweb-ref accumulated
echo "World"
#+END_SRC
Now I can dev in org files and use literate programming functionalities while being able to test the code in the foreign virtual environment with the right dependencies before tangling everything in its corresponding .py
file in the project directory.
Isn't that neat? 😁
from poetry.el.
Very interesting, thank you for the tips!
How does it work if my org file is in a different location than the poetry project?
I also noticed that I don't need to define a session for the code block activating the virtual env: simply running (pyvenv-activate)
in my org file activates the right virtual env and all python blocks execute in this env afterward. Could you please provide some insights on the question? :)
from poetry.el.
Related Issues (20)
- lsp mode awkwardness HOT 7
- Refresh workspace after poetry-add or poetry-remove on lsp-mode HOT 2
- poetry-tracking-mode cannot find poetry executable HOT 1
- Unable to use with errors
- README: not maintained at the moment HOT 1
- VIRTUAL_ENV environment variable not updated when switching projects
- Some errors when calling `poetry add` with ws-butler enabled
- Poetry projects not recognized on windows 10 HOT 3
- Disable tracking mode HOT 3
- Efficiency of `poetry-call` and `poetry-do-call` HOT 3
- Error while running `poetry-add`
- Every command hangs HOT 1
- Poetry-mode runtime error. `env: unknown option --u` HOT 11
- Not getting in buffer completions.
- slow performance on poetry 1.5 HOT 1
- BUG - when I activate poetry-tracking-mode
- Package broken on OSX HOT 3
- Hide poetry venv info in the modeline HOT 1
- Error while opening files with poetry-tracking-mode on
- Incompatible version of Poetry.el on Melpa Stable HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from poetry.el.