bentoml/bentoctl

minor issues

dtemir opened this issue ยท 4 comments

Logger

Line 87 in registry.py has an issue with logger.log(f"Adding an operator from local file system ({content_path})..."). Seems like logger.log needs two arguments

$ bentoctl operators add heroku-deploy/
Traceback (most recent call last):
  File "/home/damir/miniconda3/envs/bentoml/bin/bentoctl", line 33, in <module>
    sys.exit(load_entry_point('bentoctl', 'console_scripts', 'bentoctl')())
  File "/home/damir/miniconda3/envs/bentoml/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/damir/miniconda3/envs/bentoml/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/damir/miniconda3/envs/bentoml/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/damir/miniconda3/envs/bentoml/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/damir/miniconda3/envs/bentoml/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/damir/miniconda3/envs/bentoml/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/damir/Git/cloud-deployment-tool/bentoctl/cli/operator_management.py", line 77, in add
    operator_name = local_operator_registry.add(name)
  File "/home/damir/Git/cloud-deployment-tool/bentoctl/operator/registry.py", line 87, in add
    logger.log(f"Adding an operator from local file system ({content_path})...")
TypeError: log() missing 1 required positional argument: 'msg'

Reading operators_list.json

Running bentoctl operators throws an error

$ bentoctl operators
OPERATOR FILE /home/damir/bentoctl/operators/operator_list.json
Traceback (most recent call last):
  File "/home/damir/miniconda3/envs/bentoml/bin/bentoctl", line 33, in <module>
    sys.exit(load_entry_point('bentoctl', 'console_scripts', 'bentoctl')())
  File "/home/damir/miniconda3/envs/bentoml/bin/bentoctl", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/home/damir/miniconda3/envs/bentoml/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 167, in load
    module = import_module(match.group('module'))
  File "/home/damir/miniconda3/envs/bentoml/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/damir/Git/cloud-deployment-tool/bentoctl/__init__.py", line 1, in <module>
    from bentoctl.operations import delete_spec as delete
  File "/home/damir/Git/cloud-deployment-tool/bentoctl/operations.py", line 3, in <module>
    from bentoctl.deployment_spec import DeploymentSpec
  File "/home/damir/Git/cloud-deployment-tool/bentoctl/deployment_spec.py", line 18, in <module>
    local_operator_registry = get_local_operator_registry()
  File "/home/damir/Git/cloud-deployment-tool/bentoctl/operator/__init__.py", line 6, in get_local_operator_registry
    return OperatorRegistry(_get_bentoctl_home() / "operators")
  File "/home/damir/Git/cloud-deployment-tool/bentoctl/operator/registry.py", line 40, in __init__
    self.operator_file.read_text(encoding="utf-8")
AttributeError: 'str' object has no attribute 'read_text'

probably because self.operator_file is of type str on Line 35 in registry.py. Something like this works:

class OperatorRegistry:
    def __init__(self, path):
        self.path = Path(path)
        self.operator_file = os.path.join(self.path, "operator_list.json")
        self.operators_list = {}
        if os.path.exists(self.operator_file):
            f = open(self.operator_file)
            self.operators_list = json.load(f)

I just figured I'll put this here to help you guys with the tool. I'll make sure to let you know of any issues I encounter with bentoctl while working on GCP Cloud Run (finally setup my account with them and made everything work, but need to update the README with instructions that the GCP project must already exist and APIs need to be enabled)

@dtemir Good job finding it. Can you make a fix for it?

@dtemir make sure use with format for the file so it will be properly closed after reading

closed with #17