aap-utils 0.1.23__py3-none-any.whl → 0.2.1__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.
aap_utils/__init__.py CHANGED
@@ -1,3 +1,4 @@
1
- from .register import register_demo
2
- from .register import get_config
3
- from .register import get_mlflow_url
1
+ from .register import register_demo, get_config, get_mlflow_url
2
+
3
+ # CLI should not interfere with normal imports
4
+ __all__ = ["register_demo", "get_config", "get_mlflow_url"]
aap_utils/cli.py ADDED
@@ -0,0 +1,74 @@
1
+ import os
2
+ import re
3
+ import requests
4
+
5
+ API_URL = "http://commit-svc.aiplatform/publish"
6
+
7
+ def extract_default_image():
8
+ """Extracts the image name from KERNEL_IMAGE if available and formats it."""
9
+ kernel_image = os.getenv("KERNEL_IMAGE", "admin/base_kernel_gpu@sha256:3024")
10
+ image_name = kernel_image.split("/")[1].split("@")[0] # Extract "base_kernel_gpu"
11
+ return format_name(image_name)
12
+
13
+ def format_name(name):
14
+ """Ensure the name is lowercase and contains only valid characters."""
15
+ return re.sub(r'[^a-z0-9_]', '_', name.lower())
16
+
17
+ def validate_image_name(image_name):
18
+ """Validate image name format: lowercase, only alphanumeric and underscores."""
19
+ return bool(re.fullmatch(r'[a-z0-9_]+', image_name))
20
+
21
+ def validate_tags(tags):
22
+ """Ensure tags are non-empty, lowercase, contain only valid characters, and no spaces."""
23
+ tag_list = [format_name(tag.strip()) for tag in tags.split(";") if tag.strip()]
24
+ return all(re.fullmatch(r'[a-z0-9_]+', tag) for tag in tag_list) and len(tag_list) > 0
25
+
26
+ def get_username():
27
+ """Retrieve the username from the environment variable KERNEL_AP_USER or prompt for it."""
28
+ username = os.getenv("KERNEL_AP_USER")
29
+ if not username:
30
+ username = input("Enter username (KERNEL_AP_USER not set): ").strip()
31
+ return format_name(username)
32
+
33
+ def publish_env():
34
+ """Handles the 'aap_utils publish env' command and sends a POST request."""
35
+ username = get_username()
36
+ default_image = extract_default_image()
37
+
38
+ while True:
39
+ image_name = input(f"Enter image name [{default_image}]: ").strip() or default_image
40
+ image_name = format_name(image_name)
41
+ if validate_image_name(image_name):
42
+ break
43
+ print("Invalid image name. Use only lowercase letters, numbers, or underscores (_).")
44
+
45
+ while True:
46
+ tags = input("Enter tags (separated by ';'): ").strip()
47
+ formatted_tags = [format_name(tag) for tag in tags.split(";") if tag.strip()]
48
+ if validate_tags(";".join(formatted_tags)):
49
+ break
50
+ print("Invalid tags. Each tag must be lowercase, contain only letters, numbers, or underscores (_), and no spaces.")
51
+
52
+ data = {
53
+ "username": username,
54
+ "imagename": image_name,
55
+ "tags": formatted_tags
56
+ }
57
+
58
+ print(f"Publishing environment: {data}")
59
+
60
+ try:
61
+ response = requests.post(API_URL, json=data)
62
+ if response.status_code == 200:
63
+ print("✅ Successfully published the environment!")
64
+ else:
65
+ print(f"❌ Failed to publish. Server responded with: {response.status_code}, {response.text}")
66
+ except requests.RequestException as e:
67
+ print(f"❌ Error connecting to the server: {e}")
68
+
69
+ def main():
70
+ import sys
71
+ if len(sys.argv) > 2 and sys.argv[1] == "publish" and sys.argv[2] == "env":
72
+ publish_env()
73
+ else:
74
+ print("Usage: aap_utils publish env")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aap_utils
3
- Version: 0.1.23
3
+ Version: 0.2.1
4
4
  Summary: A Python library for registering an IP address for AAP
5
5
  Author: Minh Dang
6
6
  Author-email: danghoangminh86@gmail.com
@@ -0,0 +1,8 @@
1
+ aap_utils/__init__.py,sha256=g6G3i3a5ANDJWqFX2oPsLpP93aTaoTj0gkMQzeqQIJw,172
2
+ aap_utils/cli.py,sha256=ifnQcXX6KbzL-Dm9v-SoLVl_63uXsW70Juq6qeWQhMo,2905
3
+ aap_utils/register.py,sha256=J9tukByU1mcy4SoaJOoGY8jjzL9JMuNTZGtCBSwwon0,3823
4
+ aap_utils-0.2.1.dist-info/METADATA,sha256=boJ_XinydvKnjW3oOZTsEYfA9KOFp6kphvNyGCou6fw,346
5
+ aap_utils-0.2.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ aap_utils-0.2.1.dist-info/entry_points.txt,sha256=K-h2toLoqFxAg4Bx2r7FWggKgYnAX9zp9s4Ms4r-d6s,49
7
+ aap_utils-0.2.1.dist-info/top_level.txt,sha256=Qt5xmL8_0_jhMl9uA3lg-xnvs4nCEyVj1tBE4vnp36M,10
8
+ aap_utils-0.2.1.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ aap_utils = aap_utils.cli:main
@@ -1,6 +0,0 @@
1
- aap_utils/__init__.py,sha256=Px9phm-1DU2yq-wUjKg9zEmRWbcLpWAYG-9AlnNVmCc,105
2
- aap_utils/register.py,sha256=J9tukByU1mcy4SoaJOoGY8jjzL9JMuNTZGtCBSwwon0,3823
3
- aap_utils-0.1.23.dist-info/METADATA,sha256=lp-erim0YMxlnZQ_z_rBBD6enwK_A1QwiN2WZvm-FkI,347
4
- aap_utils-0.1.23.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
5
- aap_utils-0.1.23.dist-info/top_level.txt,sha256=Qt5xmL8_0_jhMl9uA3lg-xnvs4nCEyVj1tBE4vnp36M,10
6
- aap_utils-0.1.23.dist-info/RECORD,,