|
7 | 7 | import functools |
8 | 8 | import importlib |
9 | 9 | import importlib.metadata |
10 | | -import importlib.util |
11 | | -import io |
12 | 10 | import json |
13 | 11 | import os |
14 | 12 | import platform |
@@ -498,86 +496,25 @@ def compile_app( |
498 | 496 | ) |
499 | 497 |
|
500 | 498 |
|
501 | | -def _can_colorize() -> bool: |
502 | | - """Check if the output can be colorized. |
503 | | -
|
504 | | - Copied from _colorize.can_colorize. |
505 | | -
|
506 | | - https://raw.githubusercontent.com/python/cpython/refs/heads/main/Lib/_colorize.py |
507 | | -
|
508 | | - Returns: |
509 | | - If the output can be colorized |
510 | | - """ |
511 | | - file = sys.stdout |
512 | | - |
513 | | - if not sys.flags.ignore_environment: |
514 | | - if os.environ.get("PYTHON_COLORS") == "0": |
515 | | - return False |
516 | | - if os.environ.get("PYTHON_COLORS") == "1": |
517 | | - return True |
518 | | - if os.environ.get("NO_COLOR"): |
519 | | - return False |
520 | | - if os.environ.get("FORCE_COLOR"): |
521 | | - return True |
522 | | - if os.environ.get("TERM") == "dumb": |
523 | | - return False |
524 | | - |
525 | | - if not hasattr(file, "fileno"): |
526 | | - return False |
527 | | - |
528 | | - if sys.platform == "win32": |
529 | | - try: |
530 | | - import nt |
531 | | - |
532 | | - if not nt._supports_virtual_terminal(): |
533 | | - return False |
534 | | - except (ImportError, AttributeError): |
535 | | - return False |
536 | | - |
537 | | - try: |
538 | | - return os.isatty(file.fileno()) |
539 | | - except io.UnsupportedOperation: |
540 | | - return file.isatty() |
541 | | - |
542 | | - |
543 | 499 | def compile_or_validate_app( |
544 | 500 | compile: bool = False, |
545 | 501 | check_if_schema_up_to_date: bool = False, |
546 | 502 | prerender_routes: bool = False, |
547 | | -) -> bool: |
| 503 | +): |
548 | 504 | """Compile or validate the app module based on the default config. |
549 | 505 |
|
550 | 506 | Args: |
551 | 507 | compile: Whether to compile the app. |
552 | 508 | check_if_schema_up_to_date: If True, check if the schema is up to date. |
553 | 509 | prerender_routes: Whether to prerender routes. |
554 | | -
|
555 | | - Returns: |
556 | | - If the app is compiled successfully. |
557 | 510 | """ |
558 | | - try: |
559 | | - if compile: |
560 | | - compile_app( |
561 | | - check_if_schema_up_to_date=check_if_schema_up_to_date, |
562 | | - prerender_routes=prerender_routes, |
563 | | - ) |
564 | | - else: |
565 | | - validate_app(check_if_schema_up_to_date=check_if_schema_up_to_date) |
566 | | - except Exception as e: |
567 | | - if isinstance(e, click.exceptions.Exit): |
568 | | - return False |
569 | | - |
570 | | - import traceback |
571 | | - |
572 | | - sys_exception = sys.exception() |
573 | | - |
574 | | - try: |
575 | | - colorize = _can_colorize() |
576 | | - traceback.print_exception(e, colorize=colorize) # pyright: ignore[reportCallIssue] |
577 | | - except Exception: |
578 | | - traceback.print_exception(sys_exception) |
579 | | - return False |
580 | | - return True |
| 511 | + if compile: |
| 512 | + compile_app( |
| 513 | + check_if_schema_up_to_date=check_if_schema_up_to_date, |
| 514 | + prerender_routes=prerender_routes, |
| 515 | + ) |
| 516 | + else: |
| 517 | + validate_app(check_if_schema_up_to_date=check_if_schema_up_to_date) |
581 | 518 |
|
582 | 519 |
|
583 | 520 | def get_redis() -> Redis | None: |
|
0 commit comments