dmart 1.4.40.post19__py3-none-any.whl → 1.4.40.post21__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.
dmart/dmart.py CHANGED
@@ -17,12 +17,10 @@ from pathlib import Path
17
17
 
18
18
 
19
19
  script_dir = str(Path(__file__).resolve().parent)
20
- if script_dir not in sys.path:
21
- sys.path.insert(0, script_dir)
22
20
 
23
21
  from hypercorn.config import Config
24
22
  from hypercorn.run import run
25
- from utils.settings import settings
23
+ from dmart.utils.settings import settings
26
24
 
27
25
 
28
26
  commands = """
@@ -48,7 +46,8 @@ commands = """
48
46
  sentinel = object()
49
47
 
50
48
 
51
- def hypercorn_main() -> int:
49
+ def hypercorn_main(args_list: list[str]) -> int:
50
+ from dmart.utils.settings import settings
52
51
  parser = argparse.ArgumentParser()
53
52
  parser.add_argument(
54
53
  "application",
@@ -254,13 +253,17 @@ def hypercorn_main() -> int:
254
253
  default=sentinel,
255
254
  type=int,
256
255
  )
257
- args = parser.parse_args(sys.argv[1:])
256
+ args = parser.parse_args(args_list)
258
257
 
259
258
  if args.config == "hypercorn_config.toml" and not os.path.exists(args.config):
260
259
  config = Config()
261
260
  config.backlog = 2000
262
261
  config.workers = 1
263
262
  config.bind = ["localhost:8282"]
263
+ # Allow child processes to find the application
264
+ script_dir = os.path.dirname(os.path.abspath(__file__))
265
+ if script_dir not in sys.path:
266
+ sys.path.insert(0, script_dir)
264
267
  else:
265
268
  config = Config.from_toml(args.config)
266
269
 
@@ -409,23 +412,25 @@ def print_formatted(data):
409
412
 
410
413
 
411
414
  def main():
412
- sys.argv = sys.argv[1:]
413
- if len(sys.argv) == 0:
415
+ if len(sys.argv) < 2:
414
416
  print("You must provide a command to run:")
415
417
  print(commands)
416
418
  sys.exit(1)
417
419
 
418
- match sys.argv[0]:
420
+ command = sys.argv[1]
421
+ args_list = sys.argv[2:]
422
+
423
+ match command:
419
424
  case "hyper":
420
- hypercorn_main()
425
+ hypercorn_main(args_list)
421
426
  case "cli":
422
427
  config_file = None
423
- if "--config" in sys.argv:
424
- idx = sys.argv.index("--config")
425
- if idx + 1 < len(sys.argv):
426
- config_file = sys.argv[idx + 1]
427
- sys.argv.pop(idx + 1)
428
- sys.argv.pop(idx)
428
+ if "--config" in args_list:
429
+ idx = args_list.index("--config")
430
+ if idx + 1 < len(args_list):
431
+ config_file = args_list[idx + 1]
432
+ args_list.pop(idx + 1)
433
+ args_list.pop(idx)
429
434
 
430
435
  if not config_file:
431
436
  if os.path.exists("cli.ini"):
@@ -483,10 +488,7 @@ def main():
483
488
 
484
489
  last_import_error = None
485
490
  try:
486
- dmart_dir = Path(__file__).resolve().parent
487
- if str(dmart_dir) not in sys.path:
488
- sys.path.append(str(dmart_dir))
489
- import cli # type: ignore
491
+ from dmart import cli # type: ignore
490
492
  cli.main()
491
493
  return
492
494
  except ImportError as e:
@@ -520,17 +522,19 @@ def main():
520
522
  print("Error: cli.py not found.")
521
523
  sys.exit(1)
522
524
  case "serve":
525
+ from dmart.utils.settings import settings
526
+ from dmart.main import main as server
523
527
  open_cxb = False
524
- if "--open-cxb" in sys.argv:
528
+ if "--open-cxb" in args_list:
525
529
  open_cxb = True
526
- sys.argv.remove("--open-cxb")
530
+ args_list.remove("--open-cxb")
527
531
 
528
- if "--cxb-config" in sys.argv:
529
- idx = sys.argv.index("--cxb-config")
530
- if idx + 1 < len(sys.argv):
531
- os.environ["DMART_CXB_CONFIG"] = sys.argv[idx + 1]
532
- sys.argv.pop(idx + 1)
533
- sys.argv.pop(idx)
532
+ if "--cxb-config" in args_list:
533
+ idx = args_list.index("--cxb-config")
534
+ if idx + 1 < len(args_list):
535
+ os.environ["DMART_CXB_CONFIG"] = args_list[idx + 1]
536
+ args_list.pop(idx + 1)
537
+ args_list.pop(idx)
534
538
 
535
539
  if open_cxb:
536
540
  host = settings.listening_host
@@ -544,10 +548,9 @@ def main():
544
548
  import threading
545
549
  threading.Thread(target=open_browser, daemon=True).start()
546
550
 
547
- from main import main as server
548
551
  asyncio.run(server())
549
552
  case "health-check":
550
- from data_adapters.file.health_check import main as health_check
553
+ from dmart.data_adapters.file.health_check import main as health_check
551
554
  parser = argparse.ArgumentParser(
552
555
  description="This created for doing health check functionality",
553
556
  formatter_class=argparse.ArgumentDefaultsHelpFormatter,
@@ -561,7 +564,7 @@ def main():
561
564
  asyncio.run(health_check(args.type, args.space, args.schemas))
562
565
  print(f'total time: {"{:.2f}".format(time.time() - before_time)} sec')
563
566
  case "create-index":
564
- from data_adapters.file.create_index import main as create_index
567
+ from dmart.data_adapters.file.create_index import main as create_index
565
568
  parser = argparse.ArgumentParser(
566
569
  description="Recreate Redis indices based on the available schema definitions",
567
570
  formatter_class=argparse.ArgumentDefaultsHelpFormatter,
@@ -581,7 +584,7 @@ def main():
581
584
 
582
585
  asyncio.run(create_index(args.space, args.schemas, args.subpaths, args.flushall))
583
586
  case "export":
584
- from utils.exporter import main as exporter, exit_with_error, OUTPUT_FOLDER_NAME, validate_config, extract
587
+ from dmart.utils.exporter import main as exporter, exit_with_error, OUTPUT_FOLDER_NAME, validate_config, extract
585
588
  parser = argparse.ArgumentParser()
586
589
  parser.add_argument(
587
590
  "--config", required=True, help="Json config relative path from the script"
@@ -634,11 +637,12 @@ def main():
634
637
  f"Output path: {os.path.abspath(os.path.join(output_path, OUTPUT_FOLDER_NAME))}"
635
638
  )
636
639
  case "settings":
640
+ from dmart.utils.settings import settings
637
641
  print_formatted(settings.model_dump_json())
638
642
  case "set_password":
639
- import set_admin_passwd # noqa: F401
643
+ from dmart import set_admin_passwd # noqa: F401
640
644
  case "archive":
641
- from data_adapters.file.archive import archive
645
+ from dmart.data_adapters.file.archive import archive
642
646
  parser = argparse.ArgumentParser(
643
647
  description="Script for archiving records from different spaces and subpaths."
644
648
  )
@@ -665,10 +669,10 @@ def main():
665
669
  asyncio.run(archive(space, subpath, schema, olderthan))
666
670
  print("Done.")
667
671
  case "json_to_db":
668
- from data_adapters.sql.json_to_db_migration import main as json_to_db_migration
672
+ from dmart.data_adapters.sql.json_to_db_migration import main as json_to_db_migration
669
673
  asyncio.run(json_to_db_migration())
670
674
  case "db_to_json":
671
- from data_adapters.sql.db_to_json_migration import main as db_to_json_migration
675
+ from dmart.data_adapters.sql.db_to_json_migration import main as db_to_json_migration
672
676
  db_to_json_migration()
673
677
  case "help":
674
678
  print("Available commands:")
@@ -739,6 +743,7 @@ def main():
739
743
  import configparser
740
744
  import tempfile
741
745
 
746
+ from dmart.utils.settings import settings
742
747
  dmart_root = Path(__file__).resolve().parent
743
748
  alembic_ini_path = dmart_root / "alembic.ini"
744
749
 
@@ -764,7 +769,7 @@ def main():
764
769
  config.write(temp_config_file)
765
770
  temp_config_path = temp_config_file.name
766
771
 
767
- alembic_cli_args = sys.argv[1:]
772
+ alembic_cli_args = args_list
768
773
  if not alembic_cli_args:
769
774
  alembic_cli_args = ["upgrade", "head"]
770
775
 
@@ -819,4 +824,10 @@ def main():
819
824
  sys.exit(e.returncode)
820
825
 
821
826
  if __name__ == "__main__":
827
+ # If installed as a package, we need to ensure the parent of dmart package
828
+ # is in sys.path for child processes to find 'dmart.dmart'
829
+ dmart_pkg_parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
830
+ if dmart_pkg_parent not in sys.path:
831
+ sys.path.append(dmart_pkg_parent)
832
+
822
833
  main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dmart
3
- Version: 1.4.40.post19
3
+ Version: 1.4.40.post21
4
4
  Requires-Python: >=3.11
5
5
  Requires-Dist: fastapi
6
6
  Requires-Dist: pydantic
@@ -8,7 +8,7 @@ dmart/conftest.py,sha256=0ry_zeCmdBNLbm5q115b-pkOrUFYxdsOUXbIMkr7E5Y,362
8
8
  dmart/curl.pypi.sh,sha256=KQ-kgV3_d5mwqoLd4XOwz5s2wRQ7LDVX3z-kvjvp9hA,15631
9
9
  dmart/curl.sh,sha256=lmHSFVr5ft-lc5Aq9LfvKyWfntrfYbnirhzx1EGjp_A,15743
10
10
  dmart/data_generator.py,sha256=CnE-VHEeX7-lAXtqCgbRqR9WHjTuOgeiZcviYrHAmho,2287
11
- dmart/dmart.py,sha256=q57oMsV93YfdqgJFOxeYhd0eTAwJ_QH8V18qN2hUmt8,32115
11
+ dmart/dmart.py,sha256=eaaggp05-3F0Z-rHgW01TZfFbuk7GhOSbNRtDIEtrWQ,32735
12
12
  dmart/get_settings.py,sha256=Sbe2WCoiK398E7HY4SNLfDN_GmE8knR4M-YJWF31jcg,153
13
13
  dmart/hypercorn_config.toml,sha256=-eryppEG8HBOM_KbFc4dTQePnpyfoW9ZG5aUATU_6yM,50
14
14
  dmart/info.json,sha256=6Kb7MXzVS0PzDZOUXtBoAA3zpxvtRBR0PJnedjBE-v4,123
@@ -483,8 +483,8 @@ dmart/utils/ticket_sys_utils.py,sha256=9QAlW2iiy8KyxQRBDj_WmzS5kKb0aYJmGwd4qzmGV
483
483
  dmart/utils/web_notifier.py,sha256=QM87VVid2grC5lK3NdS1yzz0z1wXljr4GChJOeK86W4,843
484
484
  dmart/utils/templates/activation.html.j2,sha256=XAMKCdoqONoc4ZQucD0yV-Pg5DlHHASZrTVItNS-iBE,640
485
485
  dmart/utils/templates/reminder.html.j2,sha256=aoS8bTs56q4hjAZKsb0jV9c-PIURBELuBOpT_qPZNVU,639
486
- dmart-1.4.40.post19.dist-info/METADATA,sha256=9-7jAI0wwDqco2DUug9vUfTgHoryxFOqTPk0NX70RVU,839
487
- dmart-1.4.40.post19.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
488
- dmart-1.4.40.post19.dist-info/entry_points.txt,sha256=N832M4wG8d2GDw1xztKRVM3TnxpY2QDzvdFE8XaWaG8,43
489
- dmart-1.4.40.post19.dist-info/top_level.txt,sha256=zJo4qk9fUW0BGIR9f4DCfpxaXbvQXH9izIOom6JsyAo,6
490
- dmart-1.4.40.post19.dist-info/RECORD,,
486
+ dmart-1.4.40.post21.dist-info/METADATA,sha256=tDXPuJEXMjftV_fpEETDfHb9kgcYvG_WoPOtBb1_k1M,839
487
+ dmart-1.4.40.post21.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
488
+ dmart-1.4.40.post21.dist-info/entry_points.txt,sha256=N832M4wG8d2GDw1xztKRVM3TnxpY2QDzvdFE8XaWaG8,43
489
+ dmart-1.4.40.post21.dist-info/top_level.txt,sha256=zJo4qk9fUW0BGIR9f4DCfpxaXbvQXH9izIOom6JsyAo,6
490
+ dmart-1.4.40.post21.dist-info/RECORD,,