-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run a module without any functions #322
Comments
This was proposed in #241 and implemented in #304. While it's waiting to be merged (or even rejected), you can just wrap your code in a function and call it immediately after that. If that other proposal fits your needs as well, consider closing this one, just to keep all the discussion in one place ;) |
Thanks for the links! Haven't seen those. I haven't tried the PR, but it seems it's about distribution, not running? I don't think it'll make [tool.poetry.scripts]
main = { path = "main" } And this print("Hello world!") Or am I missing something? |
It allows you to specify not just entry points (python functions), but any script, by setting its path. [tool.poetry.scripts]
main = { path = "main.py" } ~/project $ poetry run main Edit: yes, this will make that script available when you install this package, but it will also be made available in your environment when you do |
Okay, sorry, wasn't evident from the PR's diff. Last question, is it run inside Poetry's virtual environment? |
I'm not sure, really. I haven't played much with that fork. But I still think you should just wrap it in a function, hahah |
Have already done that, of course 😄 Not a fan of wasting horizontal space for nothing though. Just checking whether that PR covers my usecase before closing. |
Thanks for the clarification! I wanted to run a script directly, too, but I wasn't aware of the |
@RaptDept Maybe it's not as visible as it should, but it's there: https://poetry.eustace.io/docs/pyproject/#scripts |
Oh, I misunderstood. I didn't realize the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Closing this issue automatically because it has not had any activity since it has been marked as stale. If you think it is still relevant and should be addressed, feel free to open a new one. |
I'm still confused how to achieve what OP wanted or if it's even possible. |
It's not ready yet, but there's 2 things coming (maybe?) that may help: |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue
I'm writing a simple one-off script, without any functions, and I'd like to run it through Poetry, in its virtual environment. However, it appears this currently isn't possible, as Poetry expects a callable:
https://github.com/sdispater/poetry/blob/af8f86cda703144e9261b700d3165433aa2d3603/poetry/console/commands/run.py#L35-L37
My Python is rusty, so maybe there's a way around this (which makes it a documentation concern), but if there isn't, I suggest adding a quick heuristic, checking for the presence of a colon, and just executing
import_module('{}')
instead ofimport_module('{}').{}()
otherwise.The text was updated successfully, but these errors were encountered: