Skip to content
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

Closed
1 task done
alecmev opened this issue Jul 22, 2018 · 14 comments
Closed
1 task done

Run a module without any functions #322

alecmev opened this issue Jul 22, 2018 · 14 comments

Comments

@alecmev
Copy link

alecmev commented Jul 22, 2018

  • 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:

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 of import_module('{}').{}() otherwise.

@cauebs
Copy link
Contributor

cauebs commented Jul 22, 2018

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 ;)

@alecmev
Copy link
Author

alecmev commented Jul 22, 2018

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 poetry run main work with this pyproject.toml:

[tool.poetry.scripts]
main = { path = "main" }

And this main.py:

print("Hello world!")

Or am I missing something?

@cauebs
Copy link
Contributor

cauebs commented Jul 22, 2018

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 poetry develop (because this just installs the package in editable mode).

@alecmev
Copy link
Author

alecmev commented Jul 23, 2018

Okay, sorry, wasn't evident from the PR's diff. Last question, is it run inside Poetry's virtual environment?

@cauebs
Copy link
Contributor

cauebs commented Jul 23, 2018

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

@alecmev
Copy link
Author

alecmev commented Jul 23, 2018

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.

@RaptDept
Copy link
Contributor

Thanks for the clarification! I wanted to run a script directly, too, but I wasn't aware of the path parameter for tool.poetry.scripts. I don't think it's documented yet.

@cauebs
Copy link
Contributor

cauebs commented Jul 30, 2018

@RaptDept Maybe it's not as visible as it should, but it's there: https://poetry.eustace.io/docs/pyproject/#scripts

@RaptDept
Copy link
Contributor

Oh, I misunderstood. I didn't realize the path feature was still in a pending PR.

@stale
Copy link

stale bot commented Nov 13, 2019

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.

@stale stale bot added the stale label Nov 13, 2019
@stale
Copy link

stale bot commented Nov 20, 2019

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.

@stale stale bot closed this as completed Nov 20, 2019
@dimaqq
Copy link
Contributor

dimaqq commented Nov 16, 2021

I'm still confused how to achieve what OP wanted or if it's even possible.
The docs are so skimpy, they are hardly helpful 😭
If someone knows, please shed some light 💡

@wohali
Copy link

wohali commented Jan 22, 2024

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants