Run a module without any functions
See original GitHub issue- I have searched the issues of this repo and believe that this is not a duplicate.
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:
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 of import_module('{}').{}()
otherwise.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Why is Python running my module when I import it, and how ...
Put the code inside a function and it won't run until you call the function. You should have a main function in your...
Read more >6. Modules — Python 3.11.1 documentation
A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only...
Read more >Importing a module runs code - Python Morsels
When Python imports a module, it runs all the code in that module. ... Then it defines a function called greet , calls...
Read more >When I import my module in python, it automatically runs all of ...
When I import my module in python, it automatically runs all of the defined functions inside of it. How do I prevent it...
Read more >31.4. runpy — Locating and executing Python modules
The runpy module is used to locate and run Python modules without importing them first. Its main use is to implement the -m...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
It allows you to specify not just entry points (python functions), but any script, by setting its path.
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
poetry develop
(because this just installs the package in editable mode).