Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Mar 3, 2024
1 parent 72bd4b0 commit 00c80dc
Showing 1 changed file with 125 additions and 45 deletions.
170 changes: 125 additions & 45 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import click
from rich import box
from rich.console import Console
from rich.table import Table
from src.managers.package import Client, Package
from src.managers.repository import RepositoryManager
from src.managers.runner import DockerManager
Expand Down Expand Up @@ -78,21 +80,39 @@ def start(repo_url, branch_name, docker_file_name, docker_file_location=None):
dependencies = sorted(toml.dependencies().keys())
dev_dependencies = sorted(toml.dev_dependencies().keys())

report_production_dependencies = []
report_dev_dependencies = []
# report_production_dependencies = []
# report_dev_dependencies = []
messages = []

production_packages = []
development_packages = []

client = Client("https://pypi.org/pypi")

console.print("\n")
console.print("Report ...", style="bold bright_white")
console.print("RED: Manual check should be carried out", style="bright_red")
console.print("YELLOW: The latest available version is not installed", style="bright_yellow")
console.print("GREEN: Using the latest version available is installed", style="bright_green")
# table = Table(box=box.MARKDOWN, show_lines=True, expand=True)
# table.add_column("KEY", style="bold bright_red")
# table.add_column("KEY", style="bold bright_yellow")
# table.add_column("KEY", style="bold bright_green")
# table.add_row("Manual check should be carried out", "The latest available version is not installed",
# "Using the latest version available is installed")
# console.print(table)

# console.print("\n")
# console.print("Report ...", style="bold bright_white")
# console.print("RED: Manual check should be carried out", style="bright_red")
# console.print("YELLOW: The latest available version is not installed", style="bright_yellow")
# console.print("GREEN: Using the latest version available is installed", style="bright_green")

# production dependencies
console.print("\n")
console.print("Production dependencies ...", style="underline bright_white")
table = Table(title="Production Dependencies", box=box.MARKDOWN, show_lines=True)
table.add_column("Package", style="bold bright_white")
table.add_column("Installed Version", style="bold bright_white")
table.add_column("Latest Version", style="bold bright_white")
table.add_column("Status", style="bold bright_white")

# console.print(table)
# console.print("\n")
# console.print("Production dependencies ...", style="underline bright_white")
for dependency in dependencies:
c = client.get(dependency)
if isinstance(c, int):
Expand All @@ -101,33 +121,64 @@ def start(repo_url, branch_name, docker_file_name, docker_file_location=None):
continue

package = Package(c.json())
# latest_version = package.latest_version
# frozen_version = frozen_dependencies.get(dependency.lower())

# if frozen_version is None:
# # deals with cases such as package names that don't exist such as "python"
# messages.append(f"{dependency}")
# continue

# if frozen_version != latest_version:
# if "git+https://" not in frozen_version:
# report_production_dependencies.append(
# (f"{dependency} {frozen_version} -> {latest_version}", "bright_yellow")
# )
# else:
# report_production_dependencies.append(
# (f"{dependency} {frozen_version} -> {latest_version}", "bright_red")
# )
# else:
# report_production_dependencies.append((f"{dependency} == {frozen_version}", "bright_green"))

production_packages.append(package)

# if report_production_dependencies:
# for item in report_production_dependencies:
# console.print(item[0], style=f"{item[1]}")

for package in production_packages:
name = package.name
latest_version = package.latest_version
frozen_version = frozen_dependencies.get(dependency.lower())

if frozen_version is None:
# deals with cases such as package names that don't exist such as "python"
messages.append(f"{dependency}")
continue

if frozen_version != latest_version:
if "git+https://" not in frozen_version:
report_production_dependencies.append(
(f"{dependency} {frozen_version} -> {latest_version}", "bright_yellow")
)
frozen_version = frozen_dependencies.get(name.lower())
if frozen_version and frozen_version != latest_version:
if "git+https://" in frozen_version:
status = "Check"
style = "bright_red"
else:
report_production_dependencies.append(
(f"{dependency} {frozen_version} -> {latest_version}", "bright_red")
)
status = "Outdated"
style = "bright_yellow"
elif not frozen_version:
status = "Check"
style = "magenta"
frozen_version = "Unable to determine version"
else:
report_production_dependencies.append((f"{dependency} == {frozen_version}", "bright_green"))
status = "OK"
style = "bright_green"
table.add_row(name, frozen_version, latest_version, status, style=style)

console.print(table)

if report_production_dependencies:
for item in report_production_dependencies:
console.print(item[0], style=f"{item[1]}")
# development dependencies
table = Table(title="Development Dependencies", box=box.MARKDOWN, show_lines=True)
table.add_column("Package", style="bold bright_white")
table.add_column("Installed Version", style="bold bright_white")
table.add_column("Latest Version", style="bold bright_white")
table.add_column("Status", style="bold bright_white")

# development dependencies
console.print("\n")
console.print("Development dependencies ...", style="underline bright_white")
# console.print("\n")
# console.print("Development dependencies ...", style="underline bright_white")
for dependency in dev_dependencies:
c = client.get(dependency)
if isinstance(c, int):
Expand All @@ -136,25 +187,54 @@ def start(repo_url, branch_name, docker_file_name, docker_file_location=None):
continue

package = Package(c.json())
# latest_version = package.latest_version
# frozen_version = frozen_dependencies.get(dependency.lower())

# if frozen_version is None:
# # deals with cases such as package names that don't exist such as "python"
# messages.append(f"{dependency}")
# continue

# if frozen_version != latest_version:
# if "git+https://" not in frozen_version:
# report_dev_dependencies.append((f"{dependency}
# {frozen_version} -> {latest_version}", "bright_yellow"))
# else:
# report_dev_dependencies.append((f"{dependency} {frozen_version} -> {latest_version}", "bright_red"))
# else:
# report_dev_dependencies.append((f"{dependency} == {frozen_version}", "bright_green"))

development_packages.append(package)

# if report_dev_dependencies:
# for item in report_dev_dependencies:
# console.print(item[0], style=item[1])

for package in development_packages:
name = package.name
latest_version = package.latest_version
frozen_version = frozen_dependencies.get(dependency.lower())

if frozen_version is None:
# deals with cases such as package names that don't exist such as "python"
messages.append(f"{dependency}")
continue

if frozen_version != latest_version:
if "git+https://" not in frozen_version:
report_dev_dependencies.append((f"{dependency} {frozen_version} -> {latest_version}", "bright_yellow"))
frozen_version = frozen_dependencies.get(name.lower())
if frozen_version and frozen_version != latest_version:
if "git+https://" in frozen_version:
status = "Check"
style = "bright_red"
else:
report_dev_dependencies.append((f"{dependency} {frozen_version} -> {latest_version}", "bright_red"))
status = "Outdated"
style = "bright_yellow"
elif not frozen_version:
status = "Check"
style = "magenta"
frozen_version = "Unable to determine version"
else:
report_dev_dependencies.append((f"{dependency} == {frozen_version}", "bright_green"))
status = "OK"
style = "bright_green"

if "git+https://" in frozen_version:
frozen_version = "git+https://"

table.add_row(name, frozen_version, latest_version, status, style=style)

if report_dev_dependencies:
for item in report_dev_dependencies:
console.print(item[0], style=item[1])
console.print(table)

if len(messages) > 0:
console.print("\n")
Expand Down

0 comments on commit 00c80dc

Please sign in to comment.