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

Simpler CLI targets #2700

Merged
merged 18 commits into from
Mar 21, 2023
Merged

Simpler CLI targets #2700

merged 18 commits into from
Mar 21, 2023

Conversation

ahopkins
Copy link
Member

@ahopkins ahopkins commented Mar 1, 2023

This simplifies the CLI experience, but should continue to work as it currently does.

Currently, to serve a directory:

sanic /some/path --simple

And, a factory:

sanic path.to.server:create_app --factory

Without the --simple or --factory flags it would fail. This PR will look at the targets passed. If it is a directory, then launch simple server. If it is a function, try calling it.

These are now all possible:

sanic path.to.server:app
sanic /some/path
sanic path.to.server:create_app

The main motivation behind this is the ongoing discussion to encourage the CLI usage more and more.

@ahopkins ahopkins requested a review from a team as a code owner March 1, 2023 21:17
@Tronic
Copy link
Member

Tronic commented Mar 1, 2023

I have a feeling that this is too ambiguous. Many things could be either module or path, e.g.

c:\directory   # unless it checks that after colon only certain characters are used
module.app  # unless it checks that module.app is not a file or directory

Maybe with stronger heuristics for the corner cases, combined with Path(...).exists(). For improving usability, it might also be useful to check by default for app in the module without having to specify that, i.e. sanic mymodule to run mymodule:app.

@ahopkins
Copy link
Member Author

ahopkins commented Mar 1, 2023

Yes, it already does these things.

For improving usability, it might also be useful to check by default for app in the module without having to specify that, i.e. sanic mymodule to run mymodule:app.

This would assume people use app. I'm not opposed. I have added this change.

@ahopkins
Copy link
Member Author

ahopkins commented Mar 1, 2023

FTR, passing a file will not work. Only a directory.

@ahopkins ahopkins marked this pull request as draft March 16, 2023 17:11
@ahopkins
Copy link
Member Author

@Tronic

  1. The implied paths should only be used to serve a directory (i) if it is an existing directory, and (ii) has at least one path seperator in it. This should help to differentiate between a directory that happens to be named as a module. Also, no : splitting if the input startswith C:\. This should help clear up some ambiguity.
  2. sanic somemodule will look for app that is a Sanic instance as per your suggestion.

@ahopkins ahopkins marked this pull request as ready for review March 16, 2023 18:34
@codecov
Copy link

codecov bot commented Mar 16, 2023

Codecov Report

Patch coverage: 57.142% and project coverage change: -0.240 ⚠️

Comparison is base (1a63b9b) 88.912% compared to head (7de036c) 88.673%.

❗ Current head 7de036c differs from pull request most recent head e479cc1. Consider uploading reports for the commit e479cc1 to get more accurate results

Additional details and impacted files
@@              Coverage Diff              @@
##              main     #2700       +/-   ##
=============================================
- Coverage   88.912%   88.673%   -0.240%     
=============================================
  Files           92        87        -5     
  Lines         7017      6860      -157     
  Branches      1196      1180       -16     
=============================================
- Hits          6239      6083      -156     
- Misses         533       536        +3     
+ Partials       245       241        -4     
Impacted Files Coverage Δ
sanic/worker/loader.py 84.705% <57.142%> (-9.961%) ⬇️

... and 13 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

sanic/worker/loader.py Outdated Show resolved Hide resolved
@Tronic
Copy link
Member

Tronic commented Mar 20, 2023

Doing a full review later. The logic is quite complicated and needs some more thought to see that it handles all use cases correctly.

@ahopkins ahopkins requested a review from a team March 20, 2023 21:41
sanic/worker/loader.py Outdated Show resolved Hide resolved
@ahopkins ahopkins merged commit 6e1c787 into main Mar 21, 2023
@ahopkins ahopkins deleted the cli-target branch March 21, 2023 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants