#!python
#
# Copyright 2025 Hillbot Inc.
# Copyright 2020-2024 UCSD SU Lab
#
# 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 subprocess
import argparse
import sys


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("command", type=str)

    args, rest = parser.parse_known_args()
    if args.command == "install":
        package = rest[0]
        args = [
            sys.executable,
            "-m",
            "pip",
            "install",
            "--user",
            f"git+https://github.com/sapien-sim/{package}",
        ]

        subprocess.run(args, check=True)

    elif args.command == "uninstall":
        package = rest[0]
        args = [
            sys.executable,
            "-m",
            "pip",
            "uninstall",
            f"sapien_{package}",
        ]

        subprocess.run(args, check=True)

    elif args.command == "show":
        from sapien.show_anything import show_anything

        show_anything(*rest)

    elif args.command == "info":
        import warnings

        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            import sapien
            import platform

            sapien.render.set_log_level("critical")
            info = ""
            info += "Python: " + platform.python_version() + "\n"
            info += "Platform: " + platform.platform() + "\n"
            info += "sapien: " + sapien.__version__ + "\n"

            if "--all" in rest:
                info += sapien.render.get_device_summary() + "\n"

            print(info)
