Skip to content

Commit

Permalink
Merge pull request #22 from efabless/fix_ipm_update
Browse files Browse the repository at this point in the history
fix update command
  • Loading branch information
jeffdi authored Jul 2, 2024
2 parents 9c14810 + 0a34a4a commit 715fe16
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
45 changes: 45 additions & 0 deletions ipm/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,51 @@ def list_installed_ips(ipm_root):
ip_data = IPInfo.get_installed_ip_info(ipm_root)
IP.create_table(ip_data, local=True, extended=True)

def update_ips(ipm_root, ip_root=None, ip_to_update=None):
"""checks if the ips installed have newer versions
Args:
ipm_root (str): path to common installation path
update (bool, optional): if True, will check and update. Defaults to False.
ip_root (str, optional): path to the project ip dict. Defaults to None.
update_ip (str, optional): Name of the IP to be updated. Defaults to None.
"""
logger = Logger()
root = IPRoot(ipm_root, ip_root)
installed_ips = root.get_dependencies_object()

if ip_to_update:
ip_found = False
for ips in installed_ips["IP"]:
if ip_to_update in ips:
ip_found = True
break
if not ip_found:
logger.print_err(f"The IP '{ip_to_update}' is not installed.")
return

if len(installed_ips["IP"]) > 0:
for ips in installed_ips["IP"]:
for ip_name, ip_version in ips.items():
if ip_to_update and ip_name != ip_to_update:
continue # Skip IPs that do not match the update_ip argument
verified_ip_info = IPInfo.get_verified_ip_info(ip_name)
version = get_latest_version(verified_ip_info["release"])
if version not in ip_version:
logger.print_info(
f"Updating IP {ip_name} to [magenta]{version}[/magenta]…"
)
ip = IP.find_verified_ip(ip_name, version, ipm_root)
root.try_add(ip)
else:
logger.print_info(
f"IP {ip_name} is the newest version [magenta]{version}[/magenta]."
)
else:
logger.print_warn(
f"No IPs in your project to be updated."
)


def check_ips(ipm_root, update=False, ip_root=None):
"""checks if the ips installed have newer versions
Expand Down
8 changes: 5 additions & 3 deletions ipm/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package_check,
rm_ip_from_project,
uninstall_ip,
update_ips,
)


Expand Down Expand Up @@ -183,15 +184,16 @@ def check_cmd(ipm_root):

@click.command("update")
@opt_ipm_root
@click.argument("ip", required=False)
@click.option(
"--ip-root", required=False, default=os.path.join(os.getcwd(), "ip"), help="IP path"
)
def update_cmd(ipm_root, ip_root):
"""Check for new versions of all installed IPs or a specific IP."""
def update_cmd(ipm_root, ip_root, ip):
"""Check for new versions of all installed IPs in project or a specific IP."""
valid = check_ipm_directory(ipm_root)
valid_ip_dir = check_ip_root_dir(ip_root)
if valid and valid_ip_dir:
check_ips(ipm_root, update=True, ip_root=ip_root)
update_ips(ipm_root, ip_root=ip_root, ip_to_update=ip)


@click.command("package-check", hidden=True)
Expand Down

0 comments on commit 715fe16

Please sign in to comment.