FastAPI-fastkit 1.1.1__py3-none-any.whl → 1.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- __version__ = 'v1.1.1'
1
+ __version__ = 'v1.1.2'
@@ -7,10 +7,15 @@ import os
7
7
  import re
8
8
  from typing import Dict, List
9
9
 
10
+ import click
11
+
10
12
  from fastapi_fastkit import console
11
13
  from fastapi_fastkit.backend.package_managers import PackageManagerFactory
12
- from fastapi_fastkit.backend.transducer import copy_and_convert_template_file
13
- from fastapi_fastkit.core.exceptions import BackendExceptions, TemplateExceptions
14
+ from fastapi_fastkit.backend.transducer import (
15
+ copy_and_convert_template,
16
+ copy_and_convert_template_file,
17
+ )
18
+ from fastapi_fastkit.core.exceptions import BackendExceptions
14
19
  from fastapi_fastkit.core.settings import settings
15
20
  from fastapi_fastkit.utils.logging import debug_log, get_logger
16
21
  from fastapi_fastkit.utils.main import (
@@ -697,3 +702,68 @@ def add_new_route(project_dir: str, route_name: str) -> None:
697
702
  debug_log(f"Unexpected error while adding route {route_name}: {e}", "error")
698
703
  handle_exception(e, f"Error adding new route: {str(e)}")
699
704
  raise BackendExceptions(f"Failed to add new route: {str(e)}")
705
+
706
+
707
+ # ------------------------------------------------------------
708
+ # Create Project Folder Functions
709
+ # ------------------------------------------------------------
710
+
711
+
712
+ def ask_create_project_folder(project_name: str) -> bool:
713
+ """
714
+ Ask user whether to create a new project folder.
715
+
716
+ :param project_name: Name of the project
717
+ :return: True if user wants to create a folder, False otherwise
718
+ """
719
+ return click.confirm(
720
+ f"\nCreate a new project folder named '{project_name}'?\n"
721
+ f"Yes: Templates will be placed in './{project_name}/'\n"
722
+ f"No: Templates will be placed in current directory",
723
+ default=True,
724
+ )
725
+
726
+
727
+ def deploy_template_with_folder_option(
728
+ target_template: str, user_local: str, project_name: str, create_folder: bool
729
+ ) -> tuple[str, str]:
730
+ """
731
+ Deploy template based on folder creation option.
732
+
733
+ :param target_template: Path to template directory
734
+ :param user_local: User's workspace directory
735
+ :param project_name: Name of the project
736
+ :param create_folder: Whether to create a new folder
737
+ :return: Tuple of (project_dir, deployment_message)
738
+ """
739
+ if create_folder:
740
+ project_dir = os.path.join(user_local, project_name)
741
+ deployment_message = f"FastAPI template project will deploy at '{user_local}' in folder '{project_name}'"
742
+ copy_and_convert_template(target_template, user_local, project_name)
743
+ else:
744
+ project_dir = user_local
745
+ deployment_message = (
746
+ f"FastAPI template project will deploy directly at '{user_local}'"
747
+ )
748
+ copy_and_convert_template(target_template, user_local, "")
749
+
750
+ click.echo(deployment_message)
751
+ return project_dir, deployment_message
752
+
753
+
754
+ def get_deployment_success_message(
755
+ template: str, project_name: str, user_local: str, create_folder: bool
756
+ ) -> str:
757
+ """
758
+ Get appropriate success message based on deployment option.
759
+
760
+ :param template: Template name used
761
+ :param project_name: Name of the project
762
+ :param user_local: User's workspace directory
763
+ :param create_folder: Whether folder was created
764
+ :return: Success message string
765
+ """
766
+ if create_folder:
767
+ return f"FastAPI project '{project_name}' from '{template}' has been created and saved to {user_local}!"
768
+ else:
769
+ return f"FastAPI project '{project_name}' from '{template}' has been deployed directly to {user_local}!"
fastapi_fastkit/cli.py CHANGED
@@ -1,3 +1,4 @@
1
+ # TODO : add a feature to automatically fix appropriate fastkit output console size
1
2
  # --------------------------------------------------------------------------
2
3
  # The Module defines main and core CLI operations for FastAPI-fastkit.
3
4
  #
@@ -17,14 +18,16 @@ from rich.panel import Panel
17
18
 
18
19
  from fastapi_fastkit.backend.main import (
19
20
  add_new_route,
21
+ ask_create_project_folder,
20
22
  create_venv_with_manager,
23
+ deploy_template_with_folder_option,
21
24
  find_template_core_modules,
22
25
  generate_dependency_file_with_manager,
26
+ get_deployment_success_message,
23
27
  inject_project_metadata,
24
28
  install_dependencies_with_manager,
25
29
  read_template_stack,
26
30
  )
27
- from fastapi_fastkit.backend.transducer import copy_and_convert_template
28
31
  from fastapi_fastkit.core.exceptions import CLIExceptions
29
32
  from fastapi_fastkit.core.settings import FastkitConfig
30
33
  from fastapi_fastkit.utils.logging import get_logger, setup_logging
@@ -191,6 +194,7 @@ def startdemo(
191
194
  """
192
195
  Create a new FastAPI project from templates and inject metadata.
193
196
  """
197
+ # TODO : add --template-name option to specify the template name
194
198
  settings = ctx.obj["settings"]
195
199
 
196
200
  template_dir = settings.FASTKIT_TEMPLATE_ROOT
@@ -258,25 +262,27 @@ def startdemo(
258
262
  print_error("Project creation aborted!")
259
263
  return
260
264
 
265
+ # Ask user whether to create a new project folder
266
+ create_project_folder = ask_create_project_folder(project_name)
267
+
261
268
  try:
262
269
  user_local = settings.USER_WORKSPACE
263
- project_dir = os.path.join(user_local, project_name)
264
-
265
- click.echo(f"FastAPI template project will deploy at '{user_local}'")
266
270
 
267
- copy_and_convert_template(target_template, user_local, project_name)
271
+ project_dir, _ = deploy_template_with_folder_option(
272
+ target_template, user_local, project_name, create_project_folder
273
+ )
268
274
 
269
275
  inject_project_metadata(
270
276
  project_dir, project_name, author, author_email, description
271
277
  )
272
278
 
273
- # Create virtual environment and install dependencies with selected package manager
274
279
  venv_path = create_venv_with_manager(project_dir, package_manager)
275
280
  install_dependencies_with_manager(project_dir, venv_path, package_manager)
276
281
 
277
- print_success(
278
- f"FastAPI project '{project_name}' from '{template}' has been created and saved to {user_local}!"
282
+ success_message = get_deployment_success_message(
283
+ template, project_name, user_local, create_project_folder
279
284
  )
285
+ print_success(success_message)
280
286
 
281
287
  except Exception as e:
282
288
  if settings.DEBUG_MODE:
@@ -323,8 +329,11 @@ def init(
323
329
  ) -> None:
324
330
  """
325
331
  Start a empty FastAPI project setup.
332
+
326
333
  This command will automatically create a new FastAPI project directory and a python virtual environment.
334
+
327
335
  Dependencies will be automatically installed based on the selected stack at venv.
336
+
328
337
  Project metadata will be injected to the project files.
329
338
  """
330
339
  settings = ctx.obj["settings"]
@@ -402,13 +411,15 @@ def init(
402
411
  print_error("Project creation aborted!")
403
412
  return
404
413
 
414
+ # Ask user whether to create a new project folder
415
+ create_project_folder = ask_create_project_folder(project_name)
416
+
405
417
  try:
406
418
  user_local = settings.USER_WORKSPACE
407
- project_dir = os.path.join(user_local, project_name)
408
-
409
- click.echo(f"FastAPI project will deploy at '{user_local}'")
410
419
 
411
- copy_and_convert_template(target_template, user_local, project_name)
420
+ project_dir, _ = deploy_template_with_folder_option(
421
+ target_template, user_local, project_name, create_project_folder
422
+ )
412
423
 
413
424
  inject_project_metadata(
414
425
  project_dir, project_name, author, author_email, description
@@ -439,9 +450,10 @@ def init(
439
450
  venv_path = create_venv_with_manager(project_dir, package_manager)
440
451
  install_dependencies_with_manager(project_dir, venv_path, package_manager)
441
452
 
442
- print_success(
443
- f"FastAPI project '{project_name}' has been created successfully and saved to {user_local}!"
453
+ success_message = get_deployment_success_message(
454
+ template, project_name, user_local, create_project_folder
444
455
  )
456
+ print_success(success_message)
445
457
 
446
458
  print_info(
447
459
  "To start your project, run 'fastkit runserver' at newly created FastAPI project directory"
@@ -457,25 +469,43 @@ def init(
457
469
 
458
470
 
459
471
  @fastkit_cli.command()
460
- @click.argument("project_name")
461
472
  @click.argument("route_name")
473
+ @click.argument("project_dir", default=".")
462
474
  @click.pass_context
463
- def addroute(ctx: Context, project_name: str, route_name: str) -> None:
475
+ def addroute(ctx: Context, route_name: str, project_dir: str) -> None:
464
476
  """
465
477
  Add a new route to the FastAPI project.
478
+
479
+ Examples:\n
480
+ fastkit addroute user . # Add 'user' route to current directory
481
+ fastkit addroute user my_project # Add 'user' route to 'my_project' in workspace
466
482
  """
467
483
  settings = ctx.obj["settings"]
468
- user_local = settings.USER_WORKSPACE
469
- project_dir = os.path.join(user_local, project_name)
484
+
485
+ if project_dir == ".":
486
+ actual_project_dir = os.getcwd()
487
+ project_name = os.path.basename(actual_project_dir)
488
+ else:
489
+ user_local = settings.USER_WORKSPACE
490
+ actual_project_dir = os.path.join(user_local, project_dir)
491
+ project_name = project_dir
470
492
 
471
493
  # Check if project exists
472
- if not os.path.exists(project_dir):
473
- print_error(f"Project '{project_name}' does not exist in '{user_local}'.")
494
+ if not os.path.exists(actual_project_dir):
495
+ if project_dir == ".":
496
+ print_error("Current directory is not a valid project directory.")
497
+ else:
498
+ print_error(
499
+ f"Project '{project_dir}' does not exist in '{settings.USER_WORKSPACE}'."
500
+ )
474
501
  return
475
502
 
476
503
  # Verify it's a fastkit project
477
- if not is_fastkit_project(project_dir):
478
- print_error(f"'{project_name}' is not a FastAPI-fastkit project.")
504
+ if not is_fastkit_project(actual_project_dir):
505
+ if project_dir == ".":
506
+ print_error("Current directory is not a FastAPI-fastkit project.")
507
+ else:
508
+ print_error(f"'{project_dir}' is not a FastAPI-fastkit project.")
479
509
  return
480
510
 
481
511
  # Validate route name
@@ -499,26 +529,34 @@ def addroute(ctx: Context, project_name: str, route_name: str) -> None:
499
529
  {
500
530
  "Project": project_name,
501
531
  "Route Name": route_name,
502
- "Target Directory": project_dir,
532
+ "Target Directory": actual_project_dir,
503
533
  },
504
534
  )
505
535
  console.print(table)
506
536
 
507
- # Confirm before proceeding
508
- confirm = click.confirm(
509
- f"\nDo you want to add route '{route_name}' to project '{project_name}'?",
510
- default=True,
511
- )
537
+ if project_dir == ".":
538
+ confirm_message = (
539
+ f"\nDo you want to add route '{route_name}' to the current project?"
540
+ )
541
+ else:
542
+ confirm_message = f"\nDo you want to add route '{route_name}' to project '{project_name}'?"
543
+
544
+ confirm = click.confirm(confirm_message, default=True)
512
545
  if not confirm:
513
546
  print_error("Operation cancelled!")
514
547
  return
515
548
 
516
549
  # Add the new route
517
- add_new_route(project_dir, route_name)
550
+ add_new_route(actual_project_dir, route_name)
518
551
 
519
- print_success(
520
- f"Successfully added new route '{route_name}' to project `{project_name}`"
521
- )
552
+ if project_dir == ".":
553
+ print_success(
554
+ f"Successfully added new route '{route_name}' to the current project!"
555
+ )
556
+ else:
557
+ print_success(
558
+ f"Successfully added new route '{route_name}' to project '{project_name}'!"
559
+ )
522
560
 
523
561
  except Exception as e:
524
562
  logger = get_logger()
@@ -7,3 +7,4 @@ httpx==0.28.1
7
7
  black==25.1.0
8
8
  isort==6.0.0
9
9
  mypy==1.15.0
10
+ setuptools==80.9.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FastAPI-fastkit
3
- Version: 1.1.1
3
+ Version: 1.1.2
4
4
  Summary: Fast, easy-to-use starter kit for new users of Python and FastAPI
5
5
  Author-Email: bnbong <bbbong9@gmail.com>
6
6
  License: MIT
@@ -1,12 +1,12 @@
1
- fastapi_fastkit-1.1.1.dist-info/METADATA,sha256=4x4qNxfQWxMb3-oQPGgdpeqaP5_wcyega3JORDFPa18,7545
2
- fastapi_fastkit-1.1.1.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
- fastapi_fastkit-1.1.1.dist-info/entry_points.txt,sha256=IONmgb7zWPnJWsCOcpF3u1yP6AWnPjrgWIv49mr1DZE,76
4
- fastapi_fastkit-1.1.1.dist-info/licenses/LICENSE,sha256=2a9cYM3Uy8DW-so6zpYaqUafYT1Dznd3OCWCFe5CKNA,1066
5
- fastapi_fastkit/__init__.py,sha256=1ZueP2wwMdYIORYEtVGG8PZPH1E_ebkqe5CLuByoUL4,23
1
+ fastapi_fastkit-1.1.2.dist-info/METADATA,sha256=FrgnCG-vcT6_4FaUo7oiFNkkqSN9ePAeVXt3magDLLY,7545
2
+ fastapi_fastkit-1.1.2.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
+ fastapi_fastkit-1.1.2.dist-info/entry_points.txt,sha256=IONmgb7zWPnJWsCOcpF3u1yP6AWnPjrgWIv49mr1DZE,76
4
+ fastapi_fastkit-1.1.2.dist-info/licenses/LICENSE,sha256=2a9cYM3Uy8DW-so6zpYaqUafYT1Dznd3OCWCFe5CKNA,1066
5
+ fastapi_fastkit/__init__.py,sha256=SxggpWymF-dg4KVl5WRySAioMDVlBsthmNPWNsFSsio,23
6
6
  fastapi_fastkit/__main__.py,sha256=-FS9yUe4IEgDbJjFC1xso-pFCxRzUJ447j6bYpsBTBM,271
7
7
  fastapi_fastkit/backend/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  fastapi_fastkit/backend/inspector.py,sha256=DKaAAp3jE7mfu7aN18rGiGeYSTZ4mtYRMNks5B53CJU,45213
9
- fastapi_fastkit/backend/main.py,sha256=nmB-iM1hTE63THLaf6hBcSqoobH0tULk-MkghK38i0s,24340
9
+ fastapi_fastkit/backend/main.py,sha256=M2vf-LRTars0jIBZC9TWAsCxzn2uGk9sS2iIJAtQzP0,26776
10
10
  fastapi_fastkit/backend/package_managers/__init__.py,sha256=awSaY-pInI9K4mk1aWqdyKk143AGrcPI4NCy5l_48vw,691
11
11
  fastapi_fastkit/backend/package_managers/base.py,sha256=6IZmIgEgySocVRKH36ffyEMDrnyDYGR3vye7tFjCSRA,4644
12
12
  fastapi_fastkit/backend/package_managers/factory.py,sha256=sfmsAO3WC1IbehQRrAuJx3pDUtfvz3OZEMzd0kkDiZM,5452
@@ -15,7 +15,7 @@ fastapi_fastkit/backend/package_managers/pip_manager.py,sha256=TLXUQEDyVvaVccJlu
15
15
  fastapi_fastkit/backend/package_managers/poetry_manager.py,sha256=VNjrMuotunLHyYmGxJRofH6vesGb5t8ytcklEox9kDg,14248
16
16
  fastapi_fastkit/backend/package_managers/uv_manager.py,sha256=3V6V-xfQqqsLDNb5l9bnfRhkH6RNJZ339Tk-g8FxKSU,12416
17
17
  fastapi_fastkit/backend/transducer.py,sha256=rIqwJCm5nsruw3qYZYSEoevqOXoKs38MLAmexAM3O7Y,7171
18
- fastapi_fastkit/cli.py,sha256=6RyEq3PTjrjy5LeZS2G0thIpBgti4GG8UMt7kTPToWU,21597
18
+ fastapi_fastkit/cli.py,sha256=9qjjNmmJx0Qig4x0bM90HH5_jtgkZg6ZGIzbs6gyQKE,22934
19
19
  fastapi_fastkit/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  fastapi_fastkit/core/exceptions.py,sha256=W29lbDlKE_yKdS-m_QHaWdDB1j3yGge6mVx5mo_jLrU,972
21
21
  fastapi_fastkit/core/settings.py,sha256=_oekl6NllecUoRl5P6RyEgrNNF9Kh_oRxyHziKEeIjY,6085
@@ -145,7 +145,7 @@ fastapi_fastkit/fastapi_project_template/fastapi-empty/.env-tpl,sha256=ER5_3eyFY
145
145
  fastapi_fastkit/fastapi_project_template/fastapi-empty/.gitignore-tpl,sha256=8QwgyX8vpYhDtg1bcrBjf99yiLQRRO1OkBsGMRfggKY,269
146
146
  fastapi_fastkit/fastapi_project_template/fastapi-empty/README.md-tpl,sha256=GiSroiSex15vOtwhJJawk-jDrDY0rESR68LVskSXr6Y,2082
147
147
  fastapi_fastkit/fastapi_project_template/fastapi-empty/pyproject.toml-tpl,sha256=mxBz_EwhfuXPnYRv2ZlGMmNGmVl-sb2hTjkwXgkrmh4,1332
148
- fastapi_fastkit/fastapi_project_template/fastapi-empty/requirements.txt-tpl,sha256=u_Lv5ojdIVZKcpOHjzA5Y5GM6OJIxpPn9DJZDmj1lOM,153
148
+ fastapi_fastkit/fastapi_project_template/fastapi-empty/requirements.txt-tpl,sha256=P4rG83e5hAsmCbr_WzP_WeaOIEea6_28HaENy-084xw,172
149
149
  fastapi_fastkit/fastapi_project_template/fastapi-empty/setup.cfg-tpl,sha256=EbyILNe1b0igngbhHxIiFVjJDPSgnrfhSRJjkCB2dDk,197
150
150
  fastapi_fastkit/fastapi_project_template/fastapi-empty/setup.py-tpl,sha256=XGvDbhww40DWDTiFJwqqd28AdTzX_hDRw2iZlI6Uufc,619
151
151
  fastapi_fastkit/fastapi_project_template/fastapi-empty/src/__init__.py-tpl,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -237,4 +237,4 @@ fastapi_fastkit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
237
237
  fastapi_fastkit/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
238
238
  fastapi_fastkit/utils/logging.py,sha256=oU7BnWInxzl_Gk8kGQ0f6cKdNHZcOVVcSHY4I9MTmR8,6431
239
239
  fastapi_fastkit/utils/main.py,sha256=hbF9HdJSEKRU0Yn69hMCIMzapyezjxTbKjxVTe98olQ,5593
240
- fastapi_fastkit-1.1.1.dist-info/RECORD,,
240
+ fastapi_fastkit-1.1.2.dist-info/RECORD,,