From ba0cf6a0a042c72cf564afe675219634c132f867 Mon Sep 17 00:00:00 2001 From: pedroimpulcetto Date: Wed, 8 May 2024 21:40:37 -0300 Subject: [PATCH] chore: improving code for function get_default_path --- src/fastapi_cli/discover.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/fastapi_cli/discover.py b/src/fastapi_cli/discover.py index befcdfd0..b9db4af0 100644 --- a/src/fastapi_cli/discover.py +++ b/src/fastapi_cli/discover.py @@ -18,24 +18,20 @@ def get_default_path() -> Path: - path = Path("main.py") - if path.is_file(): - return path - path = Path("app.py") - if path.is_file(): - return path - path = Path("api.py") - if path.is_file(): - return path - path = Path("app/main.py") - if path.is_file(): - return path - path = Path("app/app.py") - if path.is_file(): - return path - path = Path("app/api.py") - if path.is_file(): - return path + potential_paths = ( + "main.py", + "app.py", + "api.py", + "app/main.py", + "app/app.py", + "app/api.py", + ) + + for full_path in potential_paths: + path = Path(full_path) + if path.is_file(): + return path + raise FastAPICLIException( "Could not find a default file to run, please provide an explicit path" )