You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kibble.apache.org by GitBox <gi...@apache.org> on 2020/10/28 03:42:19 UTC

[GitHub] [kibble] skekre98 opened a new pull request #89: Kibble cli init

skekre98 opened a new pull request #89:
URL: https://github.com/apache/kibble/pull/89


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] skekre98 commented on pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
skekre98 commented on pull request #89:
URL: https://github.com/apache/kibble/pull/89#issuecomment-718160517


   Hi @turbaszek, how are you building the actual cli? I was testing by running `python __main__.py` 😅. In other words how can I run `kibble version` or other commands with `kibble`? 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] skekre98 commented on pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
skekre98 commented on pull request #89:
URL: https://github.com/apache/kibble/pull/89#issuecomment-724129656


   Hi @turbaszek, this is still in progress. I have been caught up with work the past few days. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] turbaszek commented on pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
turbaszek commented on pull request #89:
URL: https://github.com/apache/kibble/pull/89#issuecomment-720645027


   @skekre98 could you please rebase? 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] turbaszek commented on pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
turbaszek commented on pull request #89:
URL: https://github.com/apache/kibble/pull/89#issuecomment-717755549


   Also the click library should be added to required dependencies in `setup.py`:
   ```
   ➜ kibble version
   Traceback (most recent call last):
     File "/Users/turbaszek/.pyenv/versions/kibble/bin/kibble", line 33, in <module>
       sys.exit(load_entry_point('apache-kibble', 'console_scripts', 'kibble')())
     File "/Users/turbaszek/.pyenv/versions/kibble/bin/kibble", line 25, in importlib_load_entry_point
       return next(matches).load()
     File "/Users/turbaszek/.pyenv/versions/3.8.0/lib/python3.8/importlib/metadata.py", line 75, in load
       module = import_module(match.group('module'))
     File "/Users/turbaszek/.pyenv/versions/3.8.0/lib/python3.8/importlib/__init__.py", line 127, in import_module
       return _bootstrap._gcd_import(name[level:], package, level)
     File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
     File "<frozen importlib._bootstrap>", line 991, in _find_and_load
     File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
     File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
     File "<frozen importlib._bootstrap_external>", line 783, in exec_module
     File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
     File "/Users/turbaszek/code/kibble/kibble/__main__.py", line 17, in <module>
       import click
   ModuleNotFoundError: No module named 'click'
   ```
   Adding this `click==7.1.2` to setup.py  `INSTALL_REQUIREMENTS` should solve the issue 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] turbaszek commented on a change in pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #89:
URL: https://github.com/apache/kibble/pull/89#discussion_r513231592



##########
File path: kibble/__main__.py
##########
@@ -14,11 +14,24 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import click
+from version import kibble_version
 
 
-def main():
-    print("Hello to kibble!")

Review comment:
       By removing `main` you had to adjust the setup.py which uses this function as entry point:
   ```
   ➜ kibble version
   Traceback (most recent call last):
     File "/Users/turbaszek/.pyenv/versions/kibble/bin/kibble", line 33, in <module>
       sys.exit(load_entry_point('apache-kibble', 'console_scripts', 'kibble')())
     File "/Users/turbaszek/.pyenv/versions/kibble/bin/kibble", line 25, in importlib_load_entry_point
       return next(matches).load()
     File "/Users/turbaszek/.pyenv/versions/3.8.0/lib/python3.8/importlib/metadata.py", line 77, in load
       return functools.reduce(getattr, attrs, module)
   AttributeError: module 'kibble.__main__' has no attribute 'main'
   ```
   
   I would suggest to leave this function as in future we may need to do more than just starting the cli. For now I would suggest:
   ```py
   def main():
       cli()
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] skekre98 closed pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
skekre98 closed pull request #89:
URL: https://github.com/apache/kibble/pull/89


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] skekre98 commented on pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
skekre98 commented on pull request #89:
URL: https://github.com/apache/kibble/pull/89#issuecomment-725804334


   Got it, I've noticed this PR has quite a lot of fluff so I'm going to go ahead and close this one and open a new one with the correct changes. Apologies for the misunderstanding 😅  


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] turbaszek commented on pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
turbaszek commented on pull request #89:
URL: https://github.com/apache/kibble/pull/89#issuecomment-718516167


   > Hi @turbaszek, how are you building the actual cli? I was testing by running `python __main__.py` 😅. In other words how can I run `kibble version` or other commands with `kibble`?
   
   Here are basic information:
   https://github.com/apache/kibble/blob/main/CONTRIBUTING.md#development-installation
   
   You need to install `kibble` package, the `-e` flag is for editable installation.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] turbaszek commented on a change in pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #89:
URL: https://github.com/apache/kibble/pull/89#discussion_r513230672



##########
File path: kibble/__main__.py
##########
@@ -14,11 +14,24 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import click
+from version import kibble_version

Review comment:
       Also please use absolute import `from kibble.version import kibble_version`:
   ```
   ➜ kibble version
   Traceback (most recent call last):
     File "/Users/turbaszek/.pyenv/versions/kibble/bin/kibble", line 33, in <module>
       sys.exit(load_entry_point('apache-kibble', 'console_scripts', 'kibble')())
     File "/Users/turbaszek/.pyenv/versions/kibble/bin/kibble", line 25, in importlib_load_entry_point
       return next(matches).load()
     File "/Users/turbaszek/.pyenv/versions/3.8.0/lib/python3.8/importlib/metadata.py", line 75, in load
       module = import_module(match.group('module'))
     File "/Users/turbaszek/.pyenv/versions/3.8.0/lib/python3.8/importlib/__init__.py", line 127, in import_module
       return _bootstrap._gcd_import(name[level:], package, level)
     File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
     File "<frozen importlib._bootstrap>", line 991, in _find_and_load
     File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
     File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
     File "<frozen importlib._bootstrap_external>", line 783, in exec_module
     File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
     File "/Users/turbaszek/code/kibble/kibble/__main__.py", line 18, in <module>
       from version import kibble_version
   ModuleNotFoundError: No module named 'version'
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] turbaszek commented on pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
turbaszek commented on pull request #89:
URL: https://github.com/apache/kibble/pull/89#issuecomment-717748488


   > I have currently left the setup function open since I believe the set up workflow is a work in progress.
   
   @skekre98 it would be awesome to rewrite it to using click 👍 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] turbaszek commented on a change in pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #89:
URL: https://github.com/apache/kibble/pull/89#discussion_r516170129



##########
File path: setup.py
##########
@@ -38,6 +38,7 @@
     "python-dateutil==2.8.1",
     "PyYAML==5.3.1",
     "tenacity==6.2.0",
+    "click==7.1.2",

Review comment:
       Let's keep this list in alphabetical order 👌 

##########
File path: kibble/__main__.py
##########
@@ -14,10 +14,104 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import os
+import yaml
+import click
+from kibble.version import kibble_version
+from kibble.configuration import KibbleConfigParser
+
+from kibble.settings import KIBBLE_YAML
+
+KIBBLE_VERSION = "0.1.0"  # ABI/API compat demarcation.
+KIBBLE_DB_VERSION = 2  # Second database revision
+
+
+def get_kibble_yaml() -> str:
+    """Resolve path to kibble config yaml"""
+    kibble_yaml = KIBBLE_YAML
+    if os.path.exists(kibble_yaml):
+        print(f"{kibble_yaml} already exists! Writing to {kibble_yaml}.tmp instead")
+        kibble_yaml = kibble_yaml + ".tmp"
+    return kibble_yaml
+
+
+def save_config(mlserver: str, conn_uri: str, dbname: str):
+    """Save kibble config to yaml file"""
+    if ":" in mlserver:
+        try:
+            mailhost, mailport = mlserver.split(":")
+        except ValueError:
+            raise ValueError(
+                "mailhost argument must be in form of `host:port` or `host`"
+            )
+    else:
+        mailhost = mlserver
+        mailport = 25
+
+    if ":" in conn_uri:
+        try:
+            hostname, port = conn_uri.split(":")
+        except ValueError:
+            raise ValueError(
+                "conn_uri argument must be in form of `host:port` or `host`"
+            )
+    else:
+        hostname = elasticsearch
+        port = 98200
+
+    config = {
+        "api": {"version": KIBBLE_VERSION, "database": KIBBLE_DB_VERSION},
+        "elasticsearch": {
+            "host": hostname,
+            "port": int(port),
+            "ssl": False,
+            "dbname": dbname,
+        },
+        "mail": {
+            "mailhost": mailhost,
+            "mailport": int(mailport),
+            "sender": "Kibble <no...@kibble.kibble>",
+        },
+        "accounts": {"allowSignup": True, "verify": True},
+    }
+
+    kibble_yaml = get_kibble_yaml()
+    print(f"Writing Kibble config to {kibble_yaml}")
+    with open(kibble_yaml, "w") as f:
+        f.write(yaml.dump(config, default_flow_style=False))
+        f.close()
+
+
+@click.group()
+def cli():
+    """A simple command line tool for kibble"""
+
+
+@cli.command("version", short_help="displays the current kibble version")
+def version():
+    click.echo(kibble_version)
+
+
+@cli.command("setup", short_help="starts the setup process for kibble")
+def setup():
+    click.echo("Welcome to the Apache Kibble setup script!")
+    conf = KibbleConfigParser()
+    conf.read("kibble.ini")
+    conn_uri = conf.get("elasticsearch", "conn_uri")
+    click.echo(f"Elasticsearch: {conn_uri}")
+
+    # Create Kibble configuration file
+    save_config(
+        mlserver=conf.get("mail", "mailhost"),
+        conn_uri=conn_uri,
+        dbname=conf.get("elasticsearch", "dbname"),
+    )

Review comment:
       The setup command should do much more than this (especially that after #83 we can abandon saving the config). The `setup` command should perform whole logic of:
   https://github.com/apache/kibble/blob/6959f3c51a594941abc08face115cf3057aaed88/kibble/setup/setup.py#L233-L276
   
   Also it should parse the arguments using click not argparse - that's the main point of using click 👍 
   

##########
File path: kibble/__main__.py
##########
@@ -14,10 +14,104 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import os
+import yaml
+import click
+from kibble.version import kibble_version
+from kibble.configuration import KibbleConfigParser
+
+from kibble.settings import KIBBLE_YAML
+
+KIBBLE_VERSION = "0.1.0"  # ABI/API compat demarcation.
+KIBBLE_DB_VERSION = 2  # Second database revision
+
+
+def get_kibble_yaml() -> str:
+    """Resolve path to kibble config yaml"""
+    kibble_yaml = KIBBLE_YAML
+    if os.path.exists(kibble_yaml):
+        print(f"{kibble_yaml} already exists! Writing to {kibble_yaml}.tmp instead")
+        kibble_yaml = kibble_yaml + ".tmp"
+    return kibble_yaml
+
+
+def save_config(mlserver: str, conn_uri: str, dbname: str):
+    """Save kibble config to yaml file"""
+    if ":" in mlserver:
+        try:
+            mailhost, mailport = mlserver.split(":")
+        except ValueError:
+            raise ValueError(
+                "mailhost argument must be in form of `host:port` or `host`"
+            )
+    else:
+        mailhost = mlserver
+        mailport = 25
+
+    if ":" in conn_uri:
+        try:
+            hostname, port = conn_uri.split(":")
+        except ValueError:
+            raise ValueError(
+                "conn_uri argument must be in form of `host:port` or `host`"
+            )
+    else:
+        hostname = elasticsearch
+        port = 98200
+
+    config = {
+        "api": {"version": KIBBLE_VERSION, "database": KIBBLE_DB_VERSION},
+        "elasticsearch": {
+            "host": hostname,
+            "port": int(port),
+            "ssl": False,
+            "dbname": dbname,
+        },
+        "mail": {
+            "mailhost": mailhost,
+            "mailport": int(mailport),
+            "sender": "Kibble <no...@kibble.kibble>",
+        },
+        "accounts": {"allowSignup": True, "verify": True},
+    }
+
+    kibble_yaml = get_kibble_yaml()
+    print(f"Writing Kibble config to {kibble_yaml}")
+    with open(kibble_yaml, "w") as f:
+        f.write(yaml.dump(config, default_flow_style=False))
+        f.close()
+
+
+@click.group()
+def cli():
+    """A simple command line tool for kibble"""
+
+
+@cli.command("version", short_help="displays the current kibble version")
+def version():
+    click.echo(kibble_version)
+
+
+@cli.command("setup", short_help="starts the setup process for kibble")
+def setup():
+    click.echo("Welcome to the Apache Kibble setup script!")
+    conf = KibbleConfigParser()
+    conf.read("kibble.ini")
+    conn_uri = conf.get("elasticsearch", "conn_uri")
+    click.echo(f"Elasticsearch: {conn_uri}")
+
+    # Create Kibble configuration file
+    save_config(
+        mlserver=conf.get("mail", "mailhost"),
+        conn_uri=conn_uri,
+        dbname=conf.get("elasticsearch", "dbname"),
+    )

Review comment:
       The argparser is implementing a cli. But we would like to migrate to click as it's easier to use. So we need to preserve whole logic of this argument parser (cli):
   https://github.com/apache/kibble/blob/6959f3c51a594941abc08face115cf3057aaed88/kibble/setup/setup.py#L41-L87
   
   So we need to use `@click.option` decorators for every option in existing cli

##########
File path: kibble/__main__.py
##########
@@ -14,10 +14,104 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import os
+import yaml
+import click
+from kibble.version import kibble_version
+from kibble.configuration import KibbleConfigParser
+
+from kibble.settings import KIBBLE_YAML
+
+KIBBLE_VERSION = "0.1.0"  # ABI/API compat demarcation.
+KIBBLE_DB_VERSION = 2  # Second database revision
+
+
+def get_kibble_yaml() -> str:
+    """Resolve path to kibble config yaml"""
+    kibble_yaml = KIBBLE_YAML
+    if os.path.exists(kibble_yaml):
+        print(f"{kibble_yaml} already exists! Writing to {kibble_yaml}.tmp instead")
+        kibble_yaml = kibble_yaml + ".tmp"
+    return kibble_yaml
+
+
+def save_config(mlserver: str, conn_uri: str, dbname: str):
+    """Save kibble config to yaml file"""
+    if ":" in mlserver:
+        try:
+            mailhost, mailport = mlserver.split(":")
+        except ValueError:
+            raise ValueError(
+                "mailhost argument must be in form of `host:port` or `host`"
+            )
+    else:
+        mailhost = mlserver
+        mailport = 25
+
+    if ":" in conn_uri:
+        try:
+            hostname, port = conn_uri.split(":")
+        except ValueError:
+            raise ValueError(
+                "conn_uri argument must be in form of `host:port` or `host`"
+            )
+    else:
+        hostname = elasticsearch
+        port = 98200
+
+    config = {
+        "api": {"version": KIBBLE_VERSION, "database": KIBBLE_DB_VERSION},
+        "elasticsearch": {
+            "host": hostname,
+            "port": int(port),
+            "ssl": False,
+            "dbname": dbname,
+        },
+        "mail": {
+            "mailhost": mailhost,
+            "mailport": int(mailport),
+            "sender": "Kibble <no...@kibble.kibble>",
+        },
+        "accounts": {"allowSignup": True, "verify": True},
+    }
+
+    kibble_yaml = get_kibble_yaml()
+    print(f"Writing Kibble config to {kibble_yaml}")
+    with open(kibble_yaml, "w") as f:
+        f.write(yaml.dump(config, default_flow_style=False))
+        f.close()
+
+
+@click.group()
+def cli():
+    """A simple command line tool for kibble"""
+
+
+@cli.command("version", short_help="displays the current kibble version")
+def version():
+    click.echo(kibble_version)
+
+
+@cli.command("setup", short_help="starts the setup process for kibble")
+def setup():
+    click.echo("Welcome to the Apache Kibble setup script!")
+    conf = KibbleConfigParser()
+    conf.read("kibble.ini")
+    conn_uri = conf.get("elasticsearch", "conn_uri")
+    click.echo(f"Elasticsearch: {conn_uri}")
+
+    # Create Kibble configuration file
+    save_config(
+        mlserver=conf.get("mail", "mailhost"),
+        conn_uri=conn_uri,
+        dbname=conf.get("elasticsearch", "dbname"),
+    )

Review comment:
       @skekre98 we are using it to set default values like that:
   https://github.com/apache/kibble/blob/6959f3c51a594941abc08face115cf3057aaed88/kibble/setup/setup.py#L47
   
   We don't have to create `KibbleConfigParser` instance every time we want to access it. It's enough to use the `conf` object:
   https://github.com/apache/kibble/blob/6959f3c51a594941abc08face115cf3057aaed88/kibble/configuration.py#L32-L33
   
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] skekre98 commented on a change in pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
skekre98 commented on a change in pull request #89:
URL: https://github.com/apache/kibble/pull/89#discussion_r516175516



##########
File path: kibble/__main__.py
##########
@@ -14,10 +14,104 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import os
+import yaml
+import click
+from kibble.version import kibble_version
+from kibble.configuration import KibbleConfigParser
+
+from kibble.settings import KIBBLE_YAML
+
+KIBBLE_VERSION = "0.1.0"  # ABI/API compat demarcation.
+KIBBLE_DB_VERSION = 2  # Second database revision
+
+
+def get_kibble_yaml() -> str:
+    """Resolve path to kibble config yaml"""
+    kibble_yaml = KIBBLE_YAML
+    if os.path.exists(kibble_yaml):
+        print(f"{kibble_yaml} already exists! Writing to {kibble_yaml}.tmp instead")
+        kibble_yaml = kibble_yaml + ".tmp"
+    return kibble_yaml
+
+
+def save_config(mlserver: str, conn_uri: str, dbname: str):
+    """Save kibble config to yaml file"""
+    if ":" in mlserver:
+        try:
+            mailhost, mailport = mlserver.split(":")
+        except ValueError:
+            raise ValueError(
+                "mailhost argument must be in form of `host:port` or `host`"
+            )
+    else:
+        mailhost = mlserver
+        mailport = 25
+
+    if ":" in conn_uri:
+        try:
+            hostname, port = conn_uri.split(":")
+        except ValueError:
+            raise ValueError(
+                "conn_uri argument must be in form of `host:port` or `host`"
+            )
+    else:
+        hostname = elasticsearch
+        port = 98200
+
+    config = {
+        "api": {"version": KIBBLE_VERSION, "database": KIBBLE_DB_VERSION},
+        "elasticsearch": {
+            "host": hostname,
+            "port": int(port),
+            "ssl": False,
+            "dbname": dbname,
+        },
+        "mail": {
+            "mailhost": mailhost,
+            "mailport": int(mailport),
+            "sender": "Kibble <no...@kibble.kibble>",
+        },
+        "accounts": {"allowSignup": True, "verify": True},
+    }
+
+    kibble_yaml = get_kibble_yaml()
+    print(f"Writing Kibble config to {kibble_yaml}")
+    with open(kibble_yaml, "w") as f:
+        f.write(yaml.dump(config, default_flow_style=False))
+        f.close()
+
+
+@click.group()
+def cli():
+    """A simple command line tool for kibble"""
+
+
+@cli.command("version", short_help="displays the current kibble version")
+def version():
+    click.echo(kibble_version)
+
+
+@cli.command("setup", short_help="starts the setup process for kibble")
+def setup():
+    click.echo("Welcome to the Apache Kibble setup script!")
+    conf = KibbleConfigParser()
+    conf.read("kibble.ini")
+    conn_uri = conf.get("elasticsearch", "conn_uri")
+    click.echo(f"Elasticsearch: {conn_uri}")
+
+    # Create Kibble configuration file
+    save_config(
+        mlserver=conf.get("mail", "mailhost"),
+        conn_uri=conn_uri,
+        dbname=conf.get("elasticsearch", "dbname"),
+    )

Review comment:
       I see, so is it taking in more arguments than what is in `kibble.ini`?

##########
File path: kibble/__main__.py
##########
@@ -14,10 +14,104 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import os
+import yaml
+import click
+from kibble.version import kibble_version
+from kibble.configuration import KibbleConfigParser
+
+from kibble.settings import KIBBLE_YAML
+
+KIBBLE_VERSION = "0.1.0"  # ABI/API compat demarcation.
+KIBBLE_DB_VERSION = 2  # Second database revision
+
+
+def get_kibble_yaml() -> str:
+    """Resolve path to kibble config yaml"""
+    kibble_yaml = KIBBLE_YAML
+    if os.path.exists(kibble_yaml):
+        print(f"{kibble_yaml} already exists! Writing to {kibble_yaml}.tmp instead")
+        kibble_yaml = kibble_yaml + ".tmp"
+    return kibble_yaml
+
+
+def save_config(mlserver: str, conn_uri: str, dbname: str):
+    """Save kibble config to yaml file"""
+    if ":" in mlserver:
+        try:
+            mailhost, mailport = mlserver.split(":")
+        except ValueError:
+            raise ValueError(
+                "mailhost argument must be in form of `host:port` or `host`"
+            )
+    else:
+        mailhost = mlserver
+        mailport = 25
+
+    if ":" in conn_uri:
+        try:
+            hostname, port = conn_uri.split(":")
+        except ValueError:
+            raise ValueError(
+                "conn_uri argument must be in form of `host:port` or `host`"
+            )
+    else:
+        hostname = elasticsearch
+        port = 98200
+
+    config = {
+        "api": {"version": KIBBLE_VERSION, "database": KIBBLE_DB_VERSION},
+        "elasticsearch": {
+            "host": hostname,
+            "port": int(port),
+            "ssl": False,
+            "dbname": dbname,
+        },
+        "mail": {
+            "mailhost": mailhost,
+            "mailport": int(mailport),
+            "sender": "Kibble <no...@kibble.kibble>",
+        },
+        "accounts": {"allowSignup": True, "verify": True},
+    }
+
+    kibble_yaml = get_kibble_yaml()
+    print(f"Writing Kibble config to {kibble_yaml}")
+    with open(kibble_yaml, "w") as f:
+        f.write(yaml.dump(config, default_flow_style=False))
+        f.close()
+
+
+@click.group()
+def cli():
+    """A simple command line tool for kibble"""
+
+
+@cli.command("version", short_help="displays the current kibble version")
+def version():
+    click.echo(kibble_version)
+
+
+@cli.command("setup", short_help="starts the setup process for kibble")
+def setup():
+    click.echo("Welcome to the Apache Kibble setup script!")
+    conf = KibbleConfigParser()
+    conf.read("kibble.ini")
+    conn_uri = conf.get("elasticsearch", "conn_uri")
+    click.echo(f"Elasticsearch: {conn_uri}")
+
+    # Create Kibble configuration file
+    save_config(
+        mlserver=conf.get("mail", "mailhost"),
+        conn_uri=conn_uri,
+        dbname=conf.get("elasticsearch", "dbname"),
+    )

Review comment:
       Oh got it. So we are not trying to use KibbleConfigParser? Apologies for the misunderstanding.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kibble] turbaszek commented on pull request #89: Kibble cli init

Posted by GitBox <gi...@apache.org>.
turbaszek commented on pull request #89:
URL: https://github.com/apache/kibble/pull/89#issuecomment-723564225


   Hey @skekre98 any update on this one?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org