Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working version for validate command CLI #152

Merged
merged 21 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b0a7be7
first version of the JSON schema. Fixes issue #27
maximilien Jan 22, 2025
a35bc9c
Merge branch 'i-am-bee:main' into main
maximilien Jan 23, 2025
e287d40
addressing feedback from review
maximilien Jan 23, 2025
8b230b6
addressed steps and agents definition
maximilien Jan 23, 2025
91776e2
made agents also array
maximilien Jan 23, 2025
be36a00
first version of the agent schema that validares the agents used in POC0
maximilien Jan 24, 2025
2626728
Merge branch 'i-am-bee:main' into main
maximilien Jan 24, 2025
39cf195
added code section
maximilien Jan 24, 2025
876f97c
included suggestions and changes from @akihikokuroda's PR #139 review…
maximilien Jan 24, 2025
a9b2597
Merge branch 'i-am-bee:main' into main
maximilien Jan 24, 2025
286bbc5
Merge branch 'i-am-bee:main' into main
maximilien Jan 28, 2025
a452398
Merge branch 'i-am-bee:main' into main
maximilien Jan 28, 2025
b5d0f8d
[DRAFT] first PR for validate command and includes the Python CLI str…
maximilien Jan 29, 2025
a726ca0
fix correct CLI python file
maximilien Jan 29, 2025
7e52f77
fix all the peotry issues by moving code to bee-hive cli directory. N…
maximilien Jan 30, 2025
d5e1c39
supress doctopt warnings and ignore bee-hive/poetry.lock
maximilien Jan 30, 2025
ff791f9
resolved conflict
maximilien Jan 30, 2025
d3befae
Merge branch 'maximilien-issue132'
maximilien Jan 30, 2025
7fb7dbe
resolved conflicts ...
maximilien Jan 30, 2025
2078464
moving to docopt-ng
maximilien Jan 30, 2025
9f709f8
removing bee-hive/poetry.lock
maximilien Jan 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bee-hive/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.8
Copy link
Collaborator

@planetf1 planetf1 Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed
(optional to tidy up - or can be later PR)
Comes from pyenv?

3 changes: 3 additions & 0 deletions bee-hive/beeAI
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python3 ./cli/beeAI.py $@
43 changes: 43 additions & 0 deletions bee-hive/cli/beeAI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

# Copyright © 2025 IBM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""BeeAI

Usage:
beeAI validate SCHEMA_FILE YAML_FILE [options]

beeAI (-h | --help)
beeAI (-v | --version)

Options:
--verbose Show all output.

-h --help Show this screen.
-v --version Show version.

"""
import os, sys, traceback

from docopt import docopt
from cli import *

if __name__ == '__main__':
args = docopt(__doc__, version='beeAI CLI v0.0.0')
command = CLI(args).command()
rc = command.execute()
if rc != 0:
Console.error("executing command: {rc}".format(rc=rc))
sys.exit(rc)
30 changes: 30 additions & 0 deletions bee-hive/cli/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright © 2025 IBM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import io, sys

from commands import *
from common import *

class CLI:
def __init__(self, args):
self.args = args
if self.args['--verbose']:
VERBOSE = True

def command(self):
if self.args.get('validate') and self.args['validate']:
return Validate(self.args)
else:
raise Exception("Invalid command")
78 changes: 78 additions & 0 deletions bee-hive/cli/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright © 2025 IBM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import io, sys, yaml, json, jsonschema

from common import Console

# Base class for all commands
class Command:
def __init__(self, args):
self.args = args

def println(self, msg):
self.print(msg + "\n")

def print(self, msg):
Console.print(msg)

def warn(self, msg):
Console.warn(msg)

def verbose(self):
return self.args['--verbose']

def execute(self):
func = self.dispatch()
rc = func()
if rc == None:
return 0
else:
if isinstance(rc, int):
return rc
else:
return 1

def dispatch(self):
if self.args['validate']:
return self.validate
else:
raise Exception("Invalid subcommand")

# validate command group
class Validate(Command):
def __init__(self, args):
self.args = args
super().__init__(self.args)

def SCHEMA_FILE(self):
return self.args['SCHEMA_FILE']

def YAML_FILE(self):
return self.args['SCHEMA_FILE']

def name(self):
return "validate"

def validate(self):
Console.print("validate {yaml_file} with schema {schema_file}".format(yaml_file=self.YAML_FILE(), schema_file=self.SCHEMA_FILE()))
with open(self.SCHEMA_FILE(), 'r') as f:
schema = json.load(f)
with open(self.YAML_FILE(), 'r') as f:
yamls = yaml.safe_load_all(f)
for yaml_data in yamls:
json_data = json.dumps(yaml_data, indent=4)
jsonschema.validate(yaml_data, schema)
Console.print("YAML file is valid.")
return 0
62 changes: 62 additions & 0 deletions bee-hive/cli/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright © 2025 IBM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from random import randint

VERBOSE=False

class Colors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

class Console:
def verbose(msg):
if VERBOSE:
print(f"{Colors.OKBLUE}{msg}{Colors.ENDC}".format(msg=str(msg)))

def print(msg=''):
print(msg)

def println(no=1):
for i in range(no):
print()

def ok(msg):
print(f"{Colors.OKGREEN}{msg}{Colors.ENDC}".format(msg=str(msg)))

def error(msg):
Console.fail(msg)

def fail(msg):
print(f"{Colors.FAIL}Error: {msg}{Colors.ENDC}".format(msg=str(msg)))

def warn(msg):
print(f"{Colors.WARNING}Warning: {msg}{Colors.ENDC}".format(msg=str(msg)))

def progress(count, total, status=''):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))

percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)

sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', status))
sys.stdout.flush()
Loading