|
|
import os |
|
|
import argparse |
|
|
import requests |
|
|
|
|
|
from colorama import init, Fore, Style |
|
|
|
|
|
|
|
|
from dataflow.cli_funcs import cli_env, cli_init |
|
|
import importlib.metadata |
|
|
|
|
|
PYPI_API_URL = 'https://pypi.org/pypi/open-dataflow/json' |
|
|
from dataflow.version import __version__ |
|
|
|
|
|
def version_and_check_for_updates(): |
|
|
|
|
|
print(Fore.BLUE + "=" * os.get_terminal_size().columns + Style.RESET_ALL) |
|
|
print(f'open-dataflow codebase version: {__version__}') |
|
|
try: |
|
|
response = requests.get(PYPI_API_URL, timeout=5) |
|
|
response.raise_for_status() |
|
|
pypi_data = response.json() |
|
|
cloud_version = pypi_data['info']['version'] |
|
|
|
|
|
print("\tChecking for updates...") |
|
|
print("\tLocal version: ", __version__) |
|
|
print("\tPyPI newest version: ", cloud_version) |
|
|
|
|
|
local_version = __version__ |
|
|
|
|
|
if cloud_version != local_version: |
|
|
print(Fore.YELLOW + f"New version available: {cloud_version}. Your version: {local_version}." + Style.RESET_ALL) |
|
|
print("Run 'pip install --upgrade open-dataflow' to upgrade.") |
|
|
else: |
|
|
print(Fore.GREEN + f"You are using the latest version: {local_version}." + Style.RESET_ALL) |
|
|
except requests.exceptions.RequestException as e: |
|
|
print(Fore.RED + "Failed to check for updates from PyPI. Please check your internet connection." + Style.RESET_ALL) |
|
|
print(f"Error: {e}") |
|
|
print(Fore.BLUE + "=" * os.get_terminal_size().columns + Style.RESET_ALL) |
|
|
def main(): |
|
|
parser = argparse.ArgumentParser(description='Command line interface for DataFlow, with codebase version: ' + __version__) |
|
|
|
|
|
|
|
|
parser.add_argument('-v', '--version', action='store_true', help="Show the version of the tool") |
|
|
|
|
|
subparsers = parser.add_subparsers(dest='command', required=False) |
|
|
|
|
|
|
|
|
parser_init = subparsers.add_parser('init', help='Initialize the scripts and configs in a directory') |
|
|
init_subparsers = parser_init.add_subparsers(dest='subcommand', required=False) |
|
|
|
|
|
|
|
|
parser_init_all = init_subparsers.add_parser('all', help='Initialize all components') |
|
|
parser_init_all.set_defaults(subcommand='all') |
|
|
|
|
|
|
|
|
parser_init_reasoning = init_subparsers.add_parser('reasoning', help='Initialize reasoning components') |
|
|
parser_init_reasoning.set_defaults(subcommand='reasoning') |
|
|
|
|
|
|
|
|
parser_env = subparsers.add_parser('env', help='Show environment information') |
|
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args() |
|
|
if args.version: |
|
|
version_and_check_for_updates() |
|
|
|
|
|
if args.command == 'init': |
|
|
if args.subcommand is None: |
|
|
args.subcommand = 'base' |
|
|
cli_init(subcommand=args.subcommand) |
|
|
|
|
|
from dataflow.cli_funcs.paths import DataFlowPath |
|
|
|
|
|
|
|
|
elif args.command == 'env': |
|
|
cli_env() |
|
|
|
|
|
if __name__ == '__main__': |
|
|
main() |
|
|
|