aap-utils 0.1.23__tar.gz → 0.2.1__tar.gz
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-0.1.23 → aap_utils-0.2.1}/PKG-INFO +1 -1
- aap_utils-0.2.1/aap_utils/__init__.py +4 -0
- aap_utils-0.2.1/aap_utils/cli.py +74 -0
- {aap_utils-0.1.23 → aap_utils-0.2.1}/aap_utils.egg-info/PKG-INFO +1 -1
- {aap_utils-0.1.23 → aap_utils-0.2.1}/aap_utils.egg-info/SOURCES.txt +2 -0
- aap_utils-0.2.1/aap_utils.egg-info/entry_points.txt +2 -0
- {aap_utils-0.1.23 → aap_utils-0.2.1}/setup.py +6 -1
- aap_utils-0.1.23/aap_utils/__init__.py +0 -3
- {aap_utils-0.1.23 → aap_utils-0.2.1}/README.md +0 -0
- {aap_utils-0.1.23 → aap_utils-0.2.1}/aap_utils/register.py +0 -0
- {aap_utils-0.1.23 → aap_utils-0.2.1}/aap_utils.egg-info/dependency_links.txt +0 -0
- {aap_utils-0.1.23 → aap_utils-0.2.1}/aap_utils.egg-info/requires.txt +0 -0
- {aap_utils-0.1.23 → aap_utils-0.2.1}/aap_utils.egg-info/top_level.txt +0 -0
- {aap_utils-0.1.23 → aap_utils-0.2.1}/pyproject.toml +0 -0
- {aap_utils-0.1.23 → aap_utils-0.2.1}/setup.cfg +0 -0
@@ -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")
|
@@ -2,9 +2,11 @@ README.md
|
|
2
2
|
pyproject.toml
|
3
3
|
setup.py
|
4
4
|
aap_utils/__init__.py
|
5
|
+
aap_utils/cli.py
|
5
6
|
aap_utils/register.py
|
6
7
|
aap_utils.egg-info/PKG-INFO
|
7
8
|
aap_utils.egg-info/SOURCES.txt
|
8
9
|
aap_utils.egg-info/dependency_links.txt
|
10
|
+
aap_utils.egg-info/entry_points.txt
|
9
11
|
aap_utils.egg-info/requires.txt
|
10
12
|
aap_utils.egg-info/top_level.txt
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
2
2
|
|
3
3
|
setup(
|
4
4
|
name="aap_utils", # The name of your library
|
5
|
-
version="0.1
|
5
|
+
version="0.2.1",
|
6
6
|
description="A Python library for registering an IP address for AAP",
|
7
7
|
author="Minh Dang",
|
8
8
|
author_email="danghoangminh86@gmail.com",
|
@@ -10,6 +10,11 @@ setup(
|
|
10
10
|
install_requires=[
|
11
11
|
"requests", # Any external dependencies (e.g., 'requests')
|
12
12
|
],
|
13
|
+
entry_points={
|
14
|
+
"console_scripts": [
|
15
|
+
"aap_utils=aap_utils.cli:main",
|
16
|
+
],
|
17
|
+
},
|
13
18
|
classifiers=[
|
14
19
|
"Programming Language :: Python :: 3",
|
15
20
|
"License :: OSI Approved :: MIT License",
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|