@@ -406,53 +406,25 @@ def fallback_deploy_udf(conn_config, component_path, component_name, project_con
406
406
conn .close ()
407
407
408
408
def verify_snow_cli_installation ():
409
- """Verify Snow CLI is installed and available, install if missing ."""
409
+ """Verify Snow CLI is installed and available."""
410
410
try :
411
- # Try to check if snow CLI is installed
411
+ # Only check if snow CLI is installed with basic version command
412
412
result = subprocess .run (["snow" , "--version" ], capture_output = True , text = True )
413
413
version_output = result .stdout .strip ()
414
414
logger .info (f"Snow CLI is installed: { version_output } " )
415
415
416
- # Parse the version number to determine command availability
417
- version_str = version_output .split (": " )[- 1 ] if ": " in version_output else version_output
418
- version_parts = version_str .split ('.' )
419
-
420
- try :
421
- major = int (version_parts [0 ])
422
- minor = int (version_parts [1 ]) if len (version_parts ) > 1 else 0
423
-
424
- logger .info (f"Snow CLI version parsed: { major } .{ minor } " )
425
-
426
- # Use appropriate commands based on version
427
- if major == 0 and minor < 3 :
428
- # For older versions like 0.2.9, check if we can list objects
429
- check_cmd = ["snow" , "object" , "list" , "--help" ]
430
- logger .info ("Using Snow CLI legacy commands (v0.2.x)" )
431
- else :
432
- # For newer versions, we expect snowpark commands
433
- check_cmd = ["snow" , "--help" ]
434
- logger .info ("Using Snow CLI modern commands (v0.3+)" )
435
-
436
- # Check if basic commands work
437
- help_result = subprocess .run (check_cmd , capture_output = True , text = True )
438
- if help_result .returncode != 0 :
439
- logger .warning (f"Snow CLI command check failed: { help_result .stderr } " )
440
- else :
441
- logger .info ("Snow CLI command check passed" )
442
- except (ValueError , IndexError ):
443
- logger .warning (f"Could not parse Snow CLI version: { version_str } " )
444
-
416
+ # Don't try to parse version or run other commands that may not exist
445
417
return True
446
418
447
419
except (subprocess .SubprocessError , FileNotFoundError ):
448
420
logger .warning ("Snow CLI not found. Attempting to install..." )
449
421
450
422
try :
451
- # Install Snow CLI using pip
452
- subprocess .run (["pip" , "install" , "--upgrade" , " snowflake-cli==0.3.0" , "snowflake-cli-labs==0.2.0 " ], check = True )
423
+ # Install Snow CLI using pip - no need to specify exact version
424
+ subprocess .run (["pip" , "install" , "snowflake-cli" ], check = True )
453
425
logger .info ("Successfully installed Snow CLI via pip" )
454
426
455
- # Verify installation
427
+ # Verify installation with minimal command
456
428
result = subprocess .run (["snow" , "--version" ], capture_output = True , text = True )
457
429
logger .info (f"Verified Snow CLI installation: { result .stdout .strip ()} " )
458
430
@@ -462,59 +434,35 @@ def verify_snow_cli_installation():
462
434
return False
463
435
464
436
def deploy_snowpark_projects (root_directory , profile_name , check_git_changes = False , git_ref = 'HEAD~1' ):
465
- """Deploy all Snowpark projects found in the root directory using Snow CLI ."""
437
+ """Deploy all Snowpark projects found in the root directory using direct connection ."""
466
438
logger .info (f"Deploying all Snowpark apps in root directory { root_directory } " )
467
439
468
- # Ensure Snow CLI is installed
469
- if not verify_snow_cli_installation ():
470
- logger .error ("Snow CLI is not available. Cannot proceed with deployment." )
471
- return False
440
+ # Verify Snow CLI exists, but we'll use direct deployment instead
441
+ verify_snow_cli_installation ()
472
442
473
- # Get connection config for environment variables
443
+ # Get connection config
474
444
conn_config = get_connection_config (profile_name )
475
445
if conn_config is None :
476
446
return False
477
447
478
- # Set environment variables for Snow CLI
448
+ # Set environment variables (still useful for some commands)
479
449
os .environ ["SNOWFLAKE_ACCOUNT" ] = conn_config .get ('account' , '' )
480
450
os .environ ["SNOWFLAKE_USER" ] = conn_config .get ('user' , '' )
481
451
os .environ ["SNOWFLAKE_ROLE" ] = conn_config .get ('role' , '' )
482
452
os .environ ["SNOWFLAKE_WAREHOUSE" ] = conn_config .get ('warehouse' , '' )
483
453
os .environ ["SNOWFLAKE_DATABASE" ] = conn_config .get ('database' , '' )
484
454
485
- # Handle password or key-based authentication
486
455
if 'password' in conn_config :
487
456
os .environ ["SNOWFLAKE_PASSWORD" ] = conn_config .get ('password' , '' )
488
457
elif 'private_key_path' in conn_config :
489
458
os .environ ["SNOWFLAKE_PRIVATE_KEY_PATH" ] = conn_config .get ('private_key_path' , '' )
490
-
491
- # Try to get the Snow CLI version to determine command format
492
- try :
493
- version_result = subprocess .run (["snow" , "--version" ], capture_output = True , text = True )
494
- version_output = version_result .stdout .strip ()
495
- version_str = version_output .split (": " )[- 1 ] if ": " in version_output else version_output
496
- version_parts = version_str .split ('.' )
497
- major = int (version_parts [0 ])
498
- minor = int (version_parts [1 ]) if len (version_parts ) > 1 else 0
499
-
500
- # Set command format based on version
501
- if major == 0 and minor < 3 :
502
- # Old Snow CLI (0.2.x) uses different commands
503
- use_legacy_commands = True
504
- logger .info ("Using legacy Snow CLI commands (v0.2.x)" )
505
- else :
506
- use_legacy_commands = False
507
- logger .info ("Using modern Snow CLI commands (v0.3+)" )
508
- except Exception as e :
509
- logger .warning (f"Could not determine Snow CLI version: { str (e )} . Will use fallback." )
510
- use_legacy_commands = True
511
459
512
460
# Stats for summary
513
461
projects_found = 0
514
462
projects_deployed = 0
515
463
projects_skipped = 0
516
464
517
- # Walk the entire directory structure recursively
465
+ # Walk the directory structure
518
466
success = True
519
467
for (directory_path , directory_names , file_names ) in os .walk (root_directory ):
520
468
# Get just the last/final folder name in the directory path
@@ -548,6 +496,7 @@ def deploy_snowpark_projects(root_directory, profile_name, check_git_changes=Fal
548
496
projects_skipped += 1
549
497
should_deploy = False
550
498
499
+ # If the project should be deployed
551
500
if should_deploy :
552
501
# Read the project config
553
502
project_settings = {}
@@ -568,91 +517,31 @@ def deploy_snowpark_projects(root_directory, profile_name, check_git_changes=Fal
568
517
# Save current directory
569
518
current_dir = os .getcwd ()
570
519
571
- # Decide deployment method based on CLI version
572
- deployment_successful = False
520
+ # Skip trying to use Snow CLI snowpark commands, go directly to fallback deployment
521
+ logger . info ( f"Using direct deployment method for { project_name } " )
573
522
574
- try :
575
- # Change to project directory
576
- os .chdir (f"{ directory_path } " )
523
+ # Get function information from project config
524
+ if 'functions' in project_settings .get ('snowpark' , {}) and project_settings ['snowpark' ]['functions' ]:
525
+ function_config = project_settings ['snowpark' ]['functions' ][0 ]
526
+ function_name = function_config .get ('name' , project_name )
577
527
578
- # List directory contents for debugging
579
- logger .info (f"Directory contents of { directory_path } :" )
580
- for item in os .listdir ('.' ):
581
- logger .info (f" - { item } " )
582
-
583
- if use_legacy_commands :
584
- # Legacy Snow CLI (0.2.x) - use native Python UDF deployment
585
- logger .info ("Using fallback deployment method for Snow CLI 0.2.x" )
586
-
587
- # Get function information from project config
588
- if 'functions' in project_settings .get ('snowpark' , {}) and project_settings ['snowpark' ]['functions' ]:
589
- function_config = project_settings ['snowpark' ]['functions' ][0 ]
590
- function_name = function_config .get ('name' , component_name )
591
-
592
- # Use fallback deployment
593
- if fallback_deploy_udf (conn_config , directory_path , function_name , project_settings ):
594
- logger .info (f"Successfully deployed { project_name } using fallback method" )
595
- deployment_successful = True
596
- projects_deployed += 1
597
- else :
598
- logger .error ("No function definition found in project config" )
528
+ # Use direct deployment method
529
+ if fallback_deploy_udf (conn_config , directory_path , function_name , project_settings ):
530
+ logger .info (f"Successfully deployed { project_name } using direct method" )
531
+ projects_deployed += 1
599
532
else :
600
- # Modern Snow CLI (0.3+) - use snowpark commands
601
- # Build the project
602
- logger .info ("Building project with Snow CLI..." )
603
- build_cmd = ["snow" , "snowpark" , "build" , "--temporary-connection" ,
604
- "--account" , os .environ ["SNOWFLAKE_ACCOUNT" ],
605
- "--user" , os .environ ["SNOWFLAKE_USER" ],
606
- "--role" , os .environ ["SNOWFLAKE_ROLE" ],
607
- "--warehouse" , os .environ ["SNOWFLAKE_WAREHOUSE" ],
608
- "--database" , os .environ ["SNOWFLAKE_DATABASE" ]]
609
-
610
- logger .info (f"Executing: { ' ' .join (build_cmd )} " )
611
- build_result = subprocess .run (build_cmd , capture_output = True , text = True )
612
- logger .info (f"Build STDOUT: { build_result .stdout } " )
613
- logger .info (f"Build STDERR: { build_result .stderr } " )
614
-
615
- # Deploy the project
616
- logger .info ("Deploying project with Snow CLI..." )
617
- deploy_cmd = ["snow" , "snowpark" , "deploy" , "--replace" , "--temporary-connection" ,
618
- "--account" , os .environ ["SNOWFLAKE_ACCOUNT" ],
619
- "--user" , os .environ ["SNOWFLAKE_USER" ],
620
- "--role" , os .environ ["SNOWFLAKE_ROLE" ],
621
- "--warehouse" , os .environ ["SNOWFLAKE_WAREHOUSE" ],
622
- "--database" , os .environ ["SNOWFLAKE_DATABASE" ]]
623
-
624
- logger .info (f"Executing: { ' ' .join (deploy_cmd )} " )
625
- deploy_result = subprocess .run (deploy_cmd , capture_output = True , text = True )
626
- logger .info (f"Deploy STDOUT: { deploy_result .stdout } " )
627
- logger .info (f"Deploy STDERR: { deploy_result .stderr } " )
628
-
629
- if build_result .returncode != 0 or deploy_result .returncode != 0 :
630
- logger .error (f"Failed to deploy project in { directory_path } " )
631
- # Try fallback method
632
- logger .info (f"Attempting fallback deployment for { project_name } " )
633
- function_name = project_name
634
- if 'functions' in project_settings .get ('snowpark' , {}) and project_settings ['snowpark' ]['functions' ]:
635
- function_name = project_settings ['snowpark' ]['functions' ][0 ].get ('name' , project_name )
636
-
637
- if fallback_deploy_udf (conn_config , directory_path , function_name , project_settings ):
638
- logger .info (f"Fallback deployment successful for { project_name } " )
639
- deployment_successful = True
640
- projects_deployed += 1
641
- else :
642
- logger .info (f"Successfully deployed project in { directory_path } " )
643
- deployment_successful = True
644
- projects_deployed += 1
645
-
646
- except Exception as e :
647
- logger .error (f"Error processing project in { directory_path } : { str (e )} " )
533
+ logger .error (f"Failed to deploy { project_name } " )
534
+ success = False
535
+ else :
536
+ logger .error (f"No function definition found in project config for { project_name } " )
648
537
success = False
649
- finally :
650
- # Restore original directory
651
- os .chdir (current_dir )
652
538
653
539
except Exception as e :
654
540
logger .error (f"Error processing project in { directory_path } : { str (e )} " )
655
541
success = False
542
+ finally :
543
+ # Restore original directory
544
+ os .chdir (current_dir )
656
545
657
546
# Log summary
658
547
logger .info (f"Deployment summary: Found { projects_found } projects, deployed { projects_deployed } , skipped { projects_skipped } " )
0 commit comments