We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Can not connect to remote machine in local network
### System information
- **OS Platform and Distribution `Linux Ubuntu 16.04.5`**:
- **MLflow installed from `binary`**: 
- **MLflow version `1.0.0`**:
- **Python version `3.6.6`**: 
- **Exact command to reproduce**:
`mlflow server --host 0.0.0.0`
`mlflow server --host <local_ip_addr>`

### Describe the problem
I am trying to connect remote machine on my local network. But it seems the  `mlflow server` did not listens all network interfaces. I tried to start server with local ip address of machine but it did not work. I am sure I can access to the machine because I have different services running on it. The problem maybe caused by gunicorn.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mlflow/cli.py`
Content:
```
1 from __future__ import print_function
2 
3 import json
4 import os
5 import sys
6 import logging
7 
8 import click
9 from click import UsageError
10 
11 import mlflow.azureml.cli
12 import mlflow.db
13 import mlflow.experiments
14 import mlflow.models.cli
15 import mlflow.projects as projects
16 import mlflow.runs
17 import mlflow.sagemaker.cli
18 import mlflow.store.artifact.cli
19 import mlflow.store.db.utils
20 from mlflow import tracking
21 from mlflow.server import _run_server
22 from mlflow.server.handlers import initialize_backend_stores
23 from mlflow.store.tracking import DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH
24 from mlflow.utils import cli_args
25 from mlflow.utils.logging_utils import eprint
26 from mlflow.utils.process import ShellCommandException
27 from mlflow.utils.uri import is_local_uri
28 
29 _logger = logging.getLogger(__name__)
30 
31 
32 @click.group()
33 @click.version_option()
34 def cli():
35     pass
36 
37 
38 @cli.command()
39 @click.argument("uri")
40 @click.option("--entry-point", "-e", metavar="NAME", default="main",
41               help="Entry point within project. [default: main]. If the entry point is not found, "
42                    "attempts to run the project file with the specified name as a script, "
43                    "using 'python' to run .py files and the default shell (specified by "
44                    "environment variable $SHELL) to run .sh files")
45 @click.option("--version", "-v", metavar="VERSION",
46               help="Version of the project to run, as a Git commit reference for Git projects.")
47 @click.option("--param-list", "-P", metavar="NAME=VALUE", multiple=True,
48               help="A parameter for the run, of the form -P name=value. Provided parameters that "
49                    "are not in the list of parameters for an entry point will be passed to the "
50                    "corresponding entry point as command-line arguments in the form `--name value`")
51 @click.option("--experiment-name", envvar=tracking._EXPERIMENT_NAME_ENV_VAR,
52               help="Name of the experiment under which to launch the run. If not "
53                    "specified, 'experiment-id' option will be used to launch run.")
54 @click.option("--experiment-id", envvar=tracking._EXPERIMENT_ID_ENV_VAR, type=click.STRING,
55               help="ID of the experiment under which to launch the run.")
56 # TODO: Add tracking server argument once we have it working.
57 @click.option("--backend", "-b", metavar="BACKEND",
58               help="Execution backend to use for run. Supported values: 'local', 'databricks', "
59                    "kubernetes (experimental). Defaults to 'local'. If running against "
60                    "Databricks, will run against a Databricks workspace determined as follows: "
61                    "if a Databricks tracking URI of the form 'databricks://profile' has been set "
62                    "(e.g. by setting the MLFLOW_TRACKING_URI environment variable), will run "
63                    "against the workspace specified by <profile>. Otherwise, runs against the "
64                    "workspace specified by the default Databricks CLI profile. See "
65                    "https://github.com/databricks/databricks-cli for more info on configuring a "
66                    "Databricks CLI profile.")
67 @click.option("--backend-config", "-c", metavar="FILE",
68               help="Path to JSON file (must end in '.json') or JSON string which will be passed "
69                    "as config to the backend. The exact content which should be "
70                    "provided is different for each execution backend and is documented "
71                    "at https://www.mlflow.org/docs/latest/projects.html.")
72 @cli_args.NO_CONDA
73 @click.option("--storage-dir", envvar="MLFLOW_TMP_DIR",
74               help="Only valid when ``backend`` is local."
75                    "MLflow downloads artifacts from distributed URIs passed to parameters of "
76                    "type 'path' to subdirectories of storage_dir.")
77 @click.option("--run-id", metavar="RUN_ID",
78               help="If specified, the given run ID will be used instead of creating a new run. "
79                    "Note: this argument is used internally by the MLflow project APIs "
80                    "and should not be specified.")
81 def run(uri, entry_point, version, param_list, experiment_name, experiment_id, backend,
82         backend_config, no_conda, storage_dir, run_id):
83     """
84     Run an MLflow project from the given URI.
85 
86     For local runs, the run will block until it completes.
87     Otherwise, the project will run asynchronously.
88 
89     If running locally (the default), the URI can be either a Git repository URI or a local path.
90     If running on Databricks, the URI must be a Git repository.
91 
92     By default, Git projects run in a new working directory with the given parameters, while
93     local projects run from the project's root directory.
94     """
95     if experiment_id is not None and experiment_name is not None:
96         eprint("Specify only one of 'experiment-name' or 'experiment-id' options.")
97         sys.exit(1)
98 
99     param_dict = {}
100     for s in param_list:
101         index = s.find("=")
102         if index == -1:
103             eprint("Invalid format for -P parameter: '%s'. Use -P name=value." % s)
104             sys.exit(1)
105         name = s[:index]
106         value = s[index + 1:]
107         if name in param_dict:
108             eprint("Repeated parameter: '%s'" % name)
109             sys.exit(1)
110         param_dict[name] = value
111     if backend_config is not None and os.path.splitext(backend_config)[-1] != ".json":
112         try:
113             backend_config = json.loads(backend_config)
114         except ValueError as e:
115             eprint("Invalid backend config JSON. Parse error: %s" % e)
116             raise
117     if backend == "kubernetes":
118         if backend_config is None:
119             eprint("Specify 'backend_config' when using kubernetes mode.")
120             sys.exit(1)
121     try:
122         projects.run(
123             uri,
124             entry_point,
125             version,
126             experiment_name=experiment_name,
127             experiment_id=experiment_id,
128             parameters=param_dict,
129             backend=backend,
130             backend_config=backend_config,
131             use_conda=(not no_conda),
132             storage_dir=storage_dir,
133             synchronous=backend in ("local", "kubernetes") or backend is None,
134             run_id=run_id
135         )
136     except projects.ExecutionException as e:
137         _logger.error("=== %s ===", e)
138         sys.exit(1)
139 
140 
141 def _validate_server_args(gunicorn_opts=None, workers=None, waitress_opts=None):
142     if sys.platform == "win32":
143         if gunicorn_opts is not None or workers is not None:
144             raise NotImplementedError(
145                 "waitress replaces gunicorn on Windows, "
146                 "cannot specify --gunicorn-opts or --workers")
147     else:
148         if waitress_opts is not None:
149             raise NotImplementedError(
150                 "gunicorn replaces waitress on non-Windows platforms, "
151                 "cannot specify --waitress-opts")
152 
153 
154 @cli.command()
155 @click.option("--backend-store-uri", metavar="PATH",
156               default=DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH,
157               help="URI to which to persist experiment and run data. Acceptable URIs are "
158                    "SQLAlchemy-compatible database connection strings "
159                    "(e.g. 'sqlite:///path/to/file.db') or local filesystem URIs "
160                    "(e.g. 'file:///absolute/path/to/directory'). By default, data will be logged "
161                    "to the ./mlruns directory.")
162 @click.option("--default-artifact-root", metavar="URI", default=None,
163               help="Path to local directory to store artifacts, for new experiments. "
164                    "Note that this flag does not impact already-created experiments. "
165                    "Default: " + DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH)
166 @click.option("--port", "-p", default=5000,
167               help="The port to listen on (default: 5000).")
168 def ui(backend_store_uri, default_artifact_root, port):
169     """
170     Launch the MLflow tracking UI for local viewing of run results. To launch a production
171     server, use the "mlflow server" command instead.
172 
173     The UI will be visible at ``http://localhost:5000`` by default.
174     """
175 
176     # Ensure that both backend_store_uri and default_artifact_uri are set correctly.
177     if not backend_store_uri:
178         backend_store_uri = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH
179 
180     if not default_artifact_root:
181         if is_local_uri(backend_store_uri):
182             default_artifact_root = backend_store_uri
183         else:
184             default_artifact_root = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH
185 
186     try:
187         initialize_backend_stores(backend_store_uri, default_artifact_root)
188     except Exception as e:  # pylint: disable=broad-except
189         _logger.error("Error initializing backend store")
190         _logger.exception(e)
191         sys.exit(1)
192 
193     # TODO: We eventually want to disable the write path in this version of the server.
194     try:
195         _run_server(backend_store_uri, default_artifact_root, "127.0.0.1", port, None, 1)
196     except ShellCommandException:
197         eprint("Running the mlflow server failed. Please see the logs above for details.")
198         sys.exit(1)
199 
200 
201 def _validate_static_prefix(ctx, param, value):  # pylint: disable=unused-argument
202     """
203     Validate that the static_prefix option starts with a "/" and does not end in a "/".
204     Conforms to the callback interface of click documented at
205     http://click.pocoo.org/5/options/#callbacks-for-validation.
206     """
207     if value is not None:
208         if not value.startswith("/"):
209             raise UsageError("--static-prefix must begin with a '/'.")
210         if value.endswith("/"):
211             raise UsageError("--static-prefix should not end with a '/'.")
212     return value
213 
214 
215 @cli.command()
216 @click.option("--backend-store-uri", metavar="PATH",
217               default=DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH,
218               help="URI to which to persist experiment and run data. Acceptable URIs are "
219                    "SQLAlchemy-compatible database connection strings "
220                    "(e.g. 'sqlite:///path/to/file.db') or local filesystem URIs "
221                    "(e.g. 'file:///absolute/path/to/directory'). By default, data will be logged "
222                    "to the ./mlruns directory.")
223 @click.option("--default-artifact-root", metavar="URI", default=None,
224               help="Local or S3 URI to store artifacts, for new experiments. "
225                    "Note that this flag does not impact already-created experiments. "
226                    "Default: Within file store, if a file:/ URI is provided. If a sql backend is"
227                    " used, then this option is required.")
228 @cli_args.HOST
229 @cli_args.PORT
230 @cli_args.WORKERS
231 @click.option("--static-prefix", default=None, callback=_validate_static_prefix,
232               help="A prefix which will be prepended to the path of all static paths.")
233 @click.option("--gunicorn-opts", default=None,
234               help="Additional command line options forwarded to gunicorn processes.")
235 @click.option("--waitress-opts", default=None,
236               help="Additional command line options for waitress-serve.")
237 def server(backend_store_uri, default_artifact_root, host, port,
238            workers, static_prefix, gunicorn_opts, waitress_opts):
239     """
240     Run the MLflow tracking server.
241 
242     The server which listen on http://localhost:5000 by default, and only accept connections
243     from the local machine. To let the server accept connections from other machines, you will need
244     to pass ``--host 0.0.0.0`` to listen on all network interfaces
245     (or a specific interface address).
246     """
247 
248     _validate_server_args(gunicorn_opts=gunicorn_opts, workers=workers, waitress_opts=waitress_opts)
249 
250     # Ensure that both backend_store_uri and default_artifact_uri are set correctly.
251     if not backend_store_uri:
252         backend_store_uri = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH
253 
254     if not default_artifact_root:
255         if is_local_uri(backend_store_uri):
256             default_artifact_root = backend_store_uri
257         else:
258             eprint("Option 'default-artifact-root' is required, when backend store is not "
259                    "local file based.")
260             sys.exit(1)
261 
262     try:
263         initialize_backend_stores(backend_store_uri, default_artifact_root)
264     except Exception as e:  # pylint: disable=broad-except
265         _logger.error("Error initializing backend store")
266         _logger.exception(e)
267         sys.exit(1)
268 
269     try:
270         _run_server(backend_store_uri, default_artifact_root, host, port,
271                     static_prefix, workers, gunicorn_opts, waitress_opts)
272     except ShellCommandException:
273         eprint("Running the mlflow server failed. Please see the logs above for details.")
274         sys.exit(1)
275 
276 
277 cli.add_command(mlflow.models.cli.commands)
278 cli.add_command(mlflow.sagemaker.cli.commands)
279 cli.add_command(mlflow.experiments.commands)
280 cli.add_command(mlflow.store.artifact.cli.commands)
281 cli.add_command(mlflow.azureml.cli.commands)
282 cli.add_command(mlflow.runs.commands)
283 cli.add_command(mlflow.db.commands)
284 
285 if __name__ == '__main__':
286     cli()
287
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mlflow/cli.py b/mlflow/cli.py
--- a/mlflow/cli.py
+++ b/mlflow/cli.py
@@ -163,14 +163,17 @@
               help="Path to local directory to store artifacts, for new experiments. "
                    "Note that this flag does not impact already-created experiments. "
                    "Default: " + DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH)
-@click.option("--port", "-p", default=5000,
-              help="The port to listen on (default: 5000).")
-def ui(backend_store_uri, default_artifact_root, port):
+@cli_args.PORT
+@cli_args.HOST
+def ui(backend_store_uri, default_artifact_root, port, host):
     """
     Launch the MLflow tracking UI for local viewing of run results. To launch a production
     server, use the "mlflow server" command instead.
 
-    The UI will be visible at ``http://localhost:5000`` by default.
+    The UI will be visible at http://localhost:5000 by default, and only accept connections
+    from the local machine. To let the UI server accept connections from other machines, you will
+    need to pass ``--host 0.0.0.0`` to listen on all network interfaces (or a specific interface
+    address).
     """
 
     # Ensure that both backend_store_uri and default_artifact_uri are set correctly.
@@ -192,7 +195,7 @@
 
     # TODO: We eventually want to disable the write path in this version of the server.
     try:
-        _run_server(backend_store_uri, default_artifact_root, "127.0.0.1", port, None, 1)
+        _run_server(backend_store_uri, default_artifact_root, host, port, None, 1)
     except ShellCommandException:
         eprint("Running the mlflow server failed. Please see the logs above for details.")
         sys.exit(1)

{"golden_diff": "diff --git a/mlflow/cli.py b/mlflow/cli.py\n--- a/mlflow/cli.py\n+++ b/mlflow/cli.py\n@@ -163,14 +163,17 @@\n               help=\"Path to local directory to store artifacts, for new experiments. \"\n                    \"Note that this flag does not impact already-created experiments. \"\n                    \"Default: \" + DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH)\n-@click.option(\"--port\", \"-p\", default=5000,\n-              help=\"The port to listen on (default: 5000).\")\n-def ui(backend_store_uri, default_artifact_root, port):\n+@cli_args.PORT\n+@cli_args.HOST\n+def ui(backend_store_uri, default_artifact_root, port, host):\n     \"\"\"\n     Launch the MLflow tracking UI for local viewing of run results. To launch a production\n     server, use the \"mlflow server\" command instead.\n \n-    The UI will be visible at ``http://localhost:5000`` by default.\n+    The UI will be visible at http://localhost:5000 by default, and only accept connections\n+    from the local machine. To let the UI server accept connections from other machines, you will\n+    need to pass ``--host 0.0.0.0`` to listen on all network interfaces (or a specific interface\n+    address).\n     \"\"\"\n \n     # Ensure that both backend_store_uri and default_artifact_uri are set correctly.\n@@ -192,7 +195,7 @@\n \n     # TODO: We eventually want to disable the write path in this version of the server.\n     try:\n-        _run_server(backend_store_uri, default_artifact_root, \"127.0.0.1\", port, None, 1)\n+        _run_server(backend_store_uri, default_artifact_root, host, port, None, 1)\n     except ShellCommandException:\n         eprint(\"Running the mlflow server failed. Please see the logs above for details.\")\n         sys.exit(1)\n", "issue": "Can not connect to remote machine in local network\n### System information\r\n- **OS Platform and Distribution `Linux Ubuntu 16.04.5`**:\r\n- **MLflow installed from `binary`**: \r\n- **MLflow version `1.0.0`**:\r\n- **Python version `3.6.6`**: \r\n- **Exact command to reproduce**:\r\n`mlflow server --host 0.0.0.0`\r\n`mlflow server --host <local_ip_addr>`\r\n\r\n### Describe the problem\r\nI am trying to connect remote machine on my local network. But it seems the  `mlflow server` did not listens all network interfaces. I tried to start server with local ip address of machine but it did not work. I am sure I can access to the machine because I have different services running on it. The problem maybe caused by gunicorn.\r\n\n", "before_files": [{"content": "from __future__ import print_function\n\nimport json\nimport os\nimport sys\nimport logging\n\nimport click\nfrom click import UsageError\n\nimport mlflow.azureml.cli\nimport mlflow.db\nimport mlflow.experiments\nimport mlflow.models.cli\nimport mlflow.projects as projects\nimport mlflow.runs\nimport mlflow.sagemaker.cli\nimport mlflow.store.artifact.cli\nimport mlflow.store.db.utils\nfrom mlflow import tracking\nfrom mlflow.server import _run_server\nfrom mlflow.server.handlers import initialize_backend_stores\nfrom mlflow.store.tracking import DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH\nfrom mlflow.utils import cli_args\nfrom mlflow.utils.logging_utils import eprint\nfrom mlflow.utils.process import ShellCommandException\nfrom mlflow.utils.uri import is_local_uri\n\n_logger = logging.getLogger(__name__)\n\n\n@click.group()\n@click.version_option()\ndef cli():\n    pass\n\n\n@cli.command()\n@click.argument(\"uri\")\n@click.option(\"--entry-point\", \"-e\", metavar=\"NAME\", default=\"main\",\n              help=\"Entry point within project. [default: main]. If the entry point is not found, \"\n                   \"attempts to run the project file with the specified name as a script, \"\n                   \"using 'python' to run .py files and the default shell (specified by \"\n                   \"environment variable $SHELL) to run .sh files\")\n@click.option(\"--version\", \"-v\", metavar=\"VERSION\",\n              help=\"Version of the project to run, as a Git commit reference for Git projects.\")\n@click.option(\"--param-list\", \"-P\", metavar=\"NAME=VALUE\", multiple=True,\n              help=\"A parameter for the run, of the form -P name=value. Provided parameters that \"\n                   \"are not in the list of parameters for an entry point will be passed to the \"\n                   \"corresponding entry point as command-line arguments in the form `--name value`\")\n@click.option(\"--experiment-name\", envvar=tracking._EXPERIMENT_NAME_ENV_VAR,\n              help=\"Name of the experiment under which to launch the run. If not \"\n                   \"specified, 'experiment-id' option will be used to launch run.\")\n@click.option(\"--experiment-id\", envvar=tracking._EXPERIMENT_ID_ENV_VAR, type=click.STRING,\n              help=\"ID of the experiment under which to launch the run.\")\n# TODO: Add tracking server argument once we have it working.\n@click.option(\"--backend\", \"-b\", metavar=\"BACKEND\",\n              help=\"Execution backend to use for run. Supported values: 'local', 'databricks', \"\n                   \"kubernetes (experimental). Defaults to 'local'. If running against \"\n                   \"Databricks, will run against a Databricks workspace determined as follows: \"\n                   \"if a Databricks tracking URI of the form 'databricks://profile' has been set \"\n                   \"(e.g. by setting the MLFLOW_TRACKING_URI environment variable), will run \"\n                   \"against the workspace specified by <profile>. Otherwise, runs against the \"\n                   \"workspace specified by the default Databricks CLI profile. See \"\n                   \"https://github.com/databricks/databricks-cli for more info on configuring a \"\n                   \"Databricks CLI profile.\")\n@click.option(\"--backend-config\", \"-c\", metavar=\"FILE\",\n              help=\"Path to JSON file (must end in '.json') or JSON string which will be passed \"\n                   \"as config to the backend. The exact content which should be \"\n                   \"provided is different for each execution backend and is documented \"\n                   \"at https://www.mlflow.org/docs/latest/projects.html.\")\n@cli_args.NO_CONDA\n@click.option(\"--storage-dir\", envvar=\"MLFLOW_TMP_DIR\",\n              help=\"Only valid when ``backend`` is local.\"\n                   \"MLflow downloads artifacts from distributed URIs passed to parameters of \"\n                   \"type 'path' to subdirectories of storage_dir.\")\n@click.option(\"--run-id\", metavar=\"RUN_ID\",\n              help=\"If specified, the given run ID will be used instead of creating a new run. \"\n                   \"Note: this argument is used internally by the MLflow project APIs \"\n                   \"and should not be specified.\")\ndef run(uri, entry_point, version, param_list, experiment_name, experiment_id, backend,\n        backend_config, no_conda, storage_dir, run_id):\n    \"\"\"\n    Run an MLflow project from the given URI.\n\n    For local runs, the run will block until it completes.\n    Otherwise, the project will run asynchronously.\n\n    If running locally (the default), the URI can be either a Git repository URI or a local path.\n    If running on Databricks, the URI must be a Git repository.\n\n    By default, Git projects run in a new working directory with the given parameters, while\n    local projects run from the project's root directory.\n    \"\"\"\n    if experiment_id is not None and experiment_name is not None:\n        eprint(\"Specify only one of 'experiment-name' or 'experiment-id' options.\")\n        sys.exit(1)\n\n    param_dict = {}\n    for s in param_list:\n        index = s.find(\"=\")\n        if index == -1:\n            eprint(\"Invalid format for -P parameter: '%s'. Use -P name=value.\" % s)\n            sys.exit(1)\n        name = s[:index]\n        value = s[index + 1:]\n        if name in param_dict:\n            eprint(\"Repeated parameter: '%s'\" % name)\n            sys.exit(1)\n        param_dict[name] = value\n    if backend_config is not None and os.path.splitext(backend_config)[-1] != \".json\":\n        try:\n            backend_config = json.loads(backend_config)\n        except ValueError as e:\n            eprint(\"Invalid backend config JSON. Parse error: %s\" % e)\n            raise\n    if backend == \"kubernetes\":\n        if backend_config is None:\n            eprint(\"Specify 'backend_config' when using kubernetes mode.\")\n            sys.exit(1)\n    try:\n        projects.run(\n            uri,\n            entry_point,\n            version,\n            experiment_name=experiment_name,\n            experiment_id=experiment_id,\n            parameters=param_dict,\n            backend=backend,\n            backend_config=backend_config,\n            use_conda=(not no_conda),\n            storage_dir=storage_dir,\n            synchronous=backend in (\"local\", \"kubernetes\") or backend is None,\n            run_id=run_id\n        )\n    except projects.ExecutionException as e:\n        _logger.error(\"=== %s ===\", e)\n        sys.exit(1)\n\n\ndef _validate_server_args(gunicorn_opts=None, workers=None, waitress_opts=None):\n    if sys.platform == \"win32\":\n        if gunicorn_opts is not None or workers is not None:\n            raise NotImplementedError(\n                \"waitress replaces gunicorn on Windows, \"\n                \"cannot specify --gunicorn-opts or --workers\")\n    else:\n        if waitress_opts is not None:\n            raise NotImplementedError(\n                \"gunicorn replaces waitress on non-Windows platforms, \"\n                \"cannot specify --waitress-opts\")\n\n\n@cli.command()\n@click.option(\"--backend-store-uri\", metavar=\"PATH\",\n              default=DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH,\n              help=\"URI to which to persist experiment and run data. Acceptable URIs are \"\n                   \"SQLAlchemy-compatible database connection strings \"\n                   \"(e.g. 'sqlite:///path/to/file.db') or local filesystem URIs \"\n                   \"(e.g. 'file:///absolute/path/to/directory'). By default, data will be logged \"\n                   \"to the ./mlruns directory.\")\n@click.option(\"--default-artifact-root\", metavar=\"URI\", default=None,\n              help=\"Path to local directory to store artifacts, for new experiments. \"\n                   \"Note that this flag does not impact already-created experiments. \"\n                   \"Default: \" + DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH)\n@click.option(\"--port\", \"-p\", default=5000,\n              help=\"The port to listen on (default: 5000).\")\ndef ui(backend_store_uri, default_artifact_root, port):\n    \"\"\"\n    Launch the MLflow tracking UI for local viewing of run results. To launch a production\n    server, use the \"mlflow server\" command instead.\n\n    The UI will be visible at ``http://localhost:5000`` by default.\n    \"\"\"\n\n    # Ensure that both backend_store_uri and default_artifact_uri are set correctly.\n    if not backend_store_uri:\n        backend_store_uri = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH\n\n    if not default_artifact_root:\n        if is_local_uri(backend_store_uri):\n            default_artifact_root = backend_store_uri\n        else:\n            default_artifact_root = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH\n\n    try:\n        initialize_backend_stores(backend_store_uri, default_artifact_root)\n    except Exception as e:  # pylint: disable=broad-except\n        _logger.error(\"Error initializing backend store\")\n        _logger.exception(e)\n        sys.exit(1)\n\n    # TODO: We eventually want to disable the write path in this version of the server.\n    try:\n        _run_server(backend_store_uri, default_artifact_root, \"127.0.0.1\", port, None, 1)\n    except ShellCommandException:\n        eprint(\"Running the mlflow server failed. Please see the logs above for details.\")\n        sys.exit(1)\n\n\ndef _validate_static_prefix(ctx, param, value):  # pylint: disable=unused-argument\n    \"\"\"\n    Validate that the static_prefix option starts with a \"/\" and does not end in a \"/\".\n    Conforms to the callback interface of click documented at\n    http://click.pocoo.org/5/options/#callbacks-for-validation.\n    \"\"\"\n    if value is not None:\n        if not value.startswith(\"/\"):\n            raise UsageError(\"--static-prefix must begin with a '/'.\")\n        if value.endswith(\"/\"):\n            raise UsageError(\"--static-prefix should not end with a '/'.\")\n    return value\n\n\n@cli.command()\n@click.option(\"--backend-store-uri\", metavar=\"PATH\",\n              default=DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH,\n              help=\"URI to which to persist experiment and run data. Acceptable URIs are \"\n                   \"SQLAlchemy-compatible database connection strings \"\n                   \"(e.g. 'sqlite:///path/to/file.db') or local filesystem URIs \"\n                   \"(e.g. 'file:///absolute/path/to/directory'). By default, data will be logged \"\n                   \"to the ./mlruns directory.\")\n@click.option(\"--default-artifact-root\", metavar=\"URI\", default=None,\n              help=\"Local or S3 URI to store artifacts, for new experiments. \"\n                   \"Note that this flag does not impact already-created experiments. \"\n                   \"Default: Within file store, if a file:/ URI is provided. If a sql backend is\"\n                   \" used, then this option is required.\")\n@cli_args.HOST\n@cli_args.PORT\n@cli_args.WORKERS\n@click.option(\"--static-prefix\", default=None, callback=_validate_static_prefix,\n              help=\"A prefix which will be prepended to the path of all static paths.\")\n@click.option(\"--gunicorn-opts\", default=None,\n              help=\"Additional command line options forwarded to gunicorn processes.\")\n@click.option(\"--waitress-opts\", default=None,\n              help=\"Additional command line options for waitress-serve.\")\ndef server(backend_store_uri, default_artifact_root, host, port,\n           workers, static_prefix, gunicorn_opts, waitress_opts):\n    \"\"\"\n    Run the MLflow tracking server.\n\n    The server which listen on http://localhost:5000 by default, and only accept connections\n    from the local machine. To let the server accept connections from other machines, you will need\n    to pass ``--host 0.0.0.0`` to listen on all network interfaces\n    (or a specific interface address).\n    \"\"\"\n\n    _validate_server_args(gunicorn_opts=gunicorn_opts, workers=workers, waitress_opts=waitress_opts)\n\n    # Ensure that both backend_store_uri and default_artifact_uri are set correctly.\n    if not backend_store_uri:\n        backend_store_uri = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH\n\n    if not default_artifact_root:\n        if is_local_uri(backend_store_uri):\n            default_artifact_root = backend_store_uri\n        else:\n            eprint(\"Option 'default-artifact-root' is required, when backend store is not \"\n                   \"local file based.\")\n            sys.exit(1)\n\n    try:\n        initialize_backend_stores(backend_store_uri, default_artifact_root)\n    except Exception as e:  # pylint: disable=broad-except\n        _logger.error(\"Error initializing backend store\")\n        _logger.exception(e)\n        sys.exit(1)\n\n    try:\n        _run_server(backend_store_uri, default_artifact_root, host, port,\n                    static_prefix, workers, gunicorn_opts, waitress_opts)\n    except ShellCommandException:\n        eprint(\"Running the mlflow server failed. Please see the logs above for details.\")\n        sys.exit(1)\n\n\ncli.add_command(mlflow.models.cli.commands)\ncli.add_command(mlflow.sagemaker.cli.commands)\ncli.add_command(mlflow.experiments.commands)\ncli.add_command(mlflow.store.artifact.cli.commands)\ncli.add_command(mlflow.azureml.cli.commands)\ncli.add_command(mlflow.runs.commands)\ncli.add_command(mlflow.db.commands)\n\nif __name__ == '__main__':\n    cli()\n", "path": "mlflow/cli.py"}], "after_files": [{"content": "from __future__ import print_function\n\nimport json\nimport os\nimport sys\nimport logging\n\nimport click\nfrom click import UsageError\n\nimport mlflow.azureml.cli\nimport mlflow.db\nimport mlflow.experiments\nimport mlflow.models.cli\nimport mlflow.projects as projects\nimport mlflow.runs\nimport mlflow.sagemaker.cli\nimport mlflow.store.artifact.cli\nimport mlflow.store.db.utils\nfrom mlflow import tracking\nfrom mlflow.server import _run_server\nfrom mlflow.server.handlers import initialize_backend_stores\nfrom mlflow.store.tracking import DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH\nfrom mlflow.utils import cli_args\nfrom mlflow.utils.logging_utils import eprint\nfrom mlflow.utils.process import ShellCommandException\nfrom mlflow.utils.uri import is_local_uri\n\n_logger = logging.getLogger(__name__)\n\n\n@click.group()\n@click.version_option()\ndef cli():\n    pass\n\n\n@cli.command()\n@click.argument(\"uri\")\n@click.option(\"--entry-point\", \"-e\", metavar=\"NAME\", default=\"main\",\n              help=\"Entry point within project. [default: main]. If the entry point is not found, \"\n                   \"attempts to run the project file with the specified name as a script, \"\n                   \"using 'python' to run .py files and the default shell (specified by \"\n                   \"environment variable $SHELL) to run .sh files\")\n@click.option(\"--version\", \"-v\", metavar=\"VERSION\",\n              help=\"Version of the project to run, as a Git commit reference for Git projects.\")\n@click.option(\"--param-list\", \"-P\", metavar=\"NAME=VALUE\", multiple=True,\n              help=\"A parameter for the run, of the form -P name=value. Provided parameters that \"\n                   \"are not in the list of parameters for an entry point will be passed to the \"\n                   \"corresponding entry point as command-line arguments in the form `--name value`\")\n@click.option(\"--experiment-name\", envvar=tracking._EXPERIMENT_NAME_ENV_VAR,\n              help=\"Name of the experiment under which to launch the run. If not \"\n                   \"specified, 'experiment-id' option will be used to launch run.\")\n@click.option(\"--experiment-id\", envvar=tracking._EXPERIMENT_ID_ENV_VAR, type=click.STRING,\n              help=\"ID of the experiment under which to launch the run.\")\n# TODO: Add tracking server argument once we have it working.\n@click.option(\"--backend\", \"-b\", metavar=\"BACKEND\",\n              help=\"Execution backend to use for run. Supported values: 'local', 'databricks', \"\n                   \"kubernetes (experimental). Defaults to 'local'. If running against \"\n                   \"Databricks, will run against a Databricks workspace determined as follows: \"\n                   \"if a Databricks tracking URI of the form 'databricks://profile' has been set \"\n                   \"(e.g. by setting the MLFLOW_TRACKING_URI environment variable), will run \"\n                   \"against the workspace specified by <profile>. Otherwise, runs against the \"\n                   \"workspace specified by the default Databricks CLI profile. See \"\n                   \"https://github.com/databricks/databricks-cli for more info on configuring a \"\n                   \"Databricks CLI profile.\")\n@click.option(\"--backend-config\", \"-c\", metavar=\"FILE\",\n              help=\"Path to JSON file (must end in '.json') or JSON string which will be passed \"\n                   \"as config to the backend. The exact content which should be \"\n                   \"provided is different for each execution backend and is documented \"\n                   \"at https://www.mlflow.org/docs/latest/projects.html.\")\n@cli_args.NO_CONDA\n@click.option(\"--storage-dir\", envvar=\"MLFLOW_TMP_DIR\",\n              help=\"Only valid when ``backend`` is local.\"\n                   \"MLflow downloads artifacts from distributed URIs passed to parameters of \"\n                   \"type 'path' to subdirectories of storage_dir.\")\n@click.option(\"--run-id\", metavar=\"RUN_ID\",\n              help=\"If specified, the given run ID will be used instead of creating a new run. \"\n                   \"Note: this argument is used internally by the MLflow project APIs \"\n                   \"and should not be specified.\")\ndef run(uri, entry_point, version, param_list, experiment_name, experiment_id, backend,\n        backend_config, no_conda, storage_dir, run_id):\n    \"\"\"\n    Run an MLflow project from the given URI.\n\n    For local runs, the run will block until it completes.\n    Otherwise, the project will run asynchronously.\n\n    If running locally (the default), the URI can be either a Git repository URI or a local path.\n    If running on Databricks, the URI must be a Git repository.\n\n    By default, Git projects run in a new working directory with the given parameters, while\n    local projects run from the project's root directory.\n    \"\"\"\n    if experiment_id is not None and experiment_name is not None:\n        eprint(\"Specify only one of 'experiment-name' or 'experiment-id' options.\")\n        sys.exit(1)\n\n    param_dict = {}\n    for s in param_list:\n        index = s.find(\"=\")\n        if index == -1:\n            eprint(\"Invalid format for -P parameter: '%s'. Use -P name=value.\" % s)\n            sys.exit(1)\n        name = s[:index]\n        value = s[index + 1:]\n        if name in param_dict:\n            eprint(\"Repeated parameter: '%s'\" % name)\n            sys.exit(1)\n        param_dict[name] = value\n    if backend_config is not None and os.path.splitext(backend_config)[-1] != \".json\":\n        try:\n            backend_config = json.loads(backend_config)\n        except ValueError as e:\n            eprint(\"Invalid backend config JSON. Parse error: %s\" % e)\n            raise\n    if backend == \"kubernetes\":\n        if backend_config is None:\n            eprint(\"Specify 'backend_config' when using kubernetes mode.\")\n            sys.exit(1)\n    try:\n        projects.run(\n            uri,\n            entry_point,\n            version,\n            experiment_name=experiment_name,\n            experiment_id=experiment_id,\n            parameters=param_dict,\n            backend=backend,\n            backend_config=backend_config,\n            use_conda=(not no_conda),\n            storage_dir=storage_dir,\n            synchronous=backend in (\"local\", \"kubernetes\") or backend is None,\n            run_id=run_id\n        )\n    except projects.ExecutionException as e:\n        _logger.error(\"=== %s ===\", e)\n        sys.exit(1)\n\n\ndef _validate_server_args(gunicorn_opts=None, workers=None, waitress_opts=None):\n    if sys.platform == \"win32\":\n        if gunicorn_opts is not None or workers is not None:\n            raise NotImplementedError(\n                \"waitress replaces gunicorn on Windows, \"\n                \"cannot specify --gunicorn-opts or --workers\")\n    else:\n        if waitress_opts is not None:\n            raise NotImplementedError(\n                \"gunicorn replaces waitress on non-Windows platforms, \"\n                \"cannot specify --waitress-opts\")\n\n\n@cli.command()\n@click.option(\"--backend-store-uri\", metavar=\"PATH\",\n              default=DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH,\n              help=\"URI to which to persist experiment and run data. Acceptable URIs are \"\n                   \"SQLAlchemy-compatible database connection strings \"\n                   \"(e.g. 'sqlite:///path/to/file.db') or local filesystem URIs \"\n                   \"(e.g. 'file:///absolute/path/to/directory'). By default, data will be logged \"\n                   \"to the ./mlruns directory.\")\n@click.option(\"--default-artifact-root\", metavar=\"URI\", default=None,\n              help=\"Path to local directory to store artifacts, for new experiments. \"\n                   \"Note that this flag does not impact already-created experiments. \"\n                   \"Default: \" + DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH)\n@cli_args.PORT\n@cli_args.HOST\ndef ui(backend_store_uri, default_artifact_root, port, host):\n    \"\"\"\n    Launch the MLflow tracking UI for local viewing of run results. To launch a production\n    server, use the \"mlflow server\" command instead.\n\n    The UI will be visible at http://localhost:5000 by default, and only accept connections\n    from the local machine. To let the UI server accept connections from other machines, you will\n    need to pass ``--host 0.0.0.0`` to listen on all network interfaces (or a specific interface\n    address).\n    \"\"\"\n\n    # Ensure that both backend_store_uri and default_artifact_uri are set correctly.\n    if not backend_store_uri:\n        backend_store_uri = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH\n\n    if not default_artifact_root:\n        if is_local_uri(backend_store_uri):\n            default_artifact_root = backend_store_uri\n        else:\n            default_artifact_root = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH\n\n    try:\n        initialize_backend_stores(backend_store_uri, default_artifact_root)\n    except Exception as e:  # pylint: disable=broad-except\n        _logger.error(\"Error initializing backend store\")\n        _logger.exception(e)\n        sys.exit(1)\n\n    # TODO: We eventually want to disable the write path in this version of the server.\n    try:\n        _run_server(backend_store_uri, default_artifact_root, host, port, None, 1)\n    except ShellCommandException:\n        eprint(\"Running the mlflow server failed. Please see the logs above for details.\")\n        sys.exit(1)\n\n\ndef _validate_static_prefix(ctx, param, value):  # pylint: disable=unused-argument\n    \"\"\"\n    Validate that the static_prefix option starts with a \"/\" and does not end in a \"/\".\n    Conforms to the callback interface of click documented at\n    http://click.pocoo.org/5/options/#callbacks-for-validation.\n    \"\"\"\n    if value is not None:\n        if not value.startswith(\"/\"):\n            raise UsageError(\"--static-prefix must begin with a '/'.\")\n        if value.endswith(\"/\"):\n            raise UsageError(\"--static-prefix should not end with a '/'.\")\n    return value\n\n\n@cli.command()\n@click.option(\"--backend-store-uri\", metavar=\"PATH\",\n              default=DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH,\n              help=\"URI to which to persist experiment and run data. Acceptable URIs are \"\n                   \"SQLAlchemy-compatible database connection strings \"\n                   \"(e.g. 'sqlite:///path/to/file.db') or local filesystem URIs \"\n                   \"(e.g. 'file:///absolute/path/to/directory'). By default, data will be logged \"\n                   \"to the ./mlruns directory.\")\n@click.option(\"--default-artifact-root\", metavar=\"URI\", default=None,\n              help=\"Local or S3 URI to store artifacts, for new experiments. \"\n                   \"Note that this flag does not impact already-created experiments. \"\n                   \"Default: Within file store, if a file:/ URI is provided. If a sql backend is\"\n                   \" used, then this option is required.\")\n@cli_args.HOST\n@cli_args.PORT\n@cli_args.WORKERS\n@click.option(\"--static-prefix\", default=None, callback=_validate_static_prefix,\n              help=\"A prefix which will be prepended to the path of all static paths.\")\n@click.option(\"--gunicorn-opts\", default=None,\n              help=\"Additional command line options forwarded to gunicorn processes.\")\n@click.option(\"--waitress-opts\", default=None,\n              help=\"Additional command line options for waitress-serve.\")\ndef server(backend_store_uri, default_artifact_root, host, port,\n           workers, static_prefix, gunicorn_opts, waitress_opts):\n    \"\"\"\n    Run the MLflow tracking server.\n\n    The server which listen on http://localhost:5000 by default, and only accept connections\n    from the local machine. To let the server accept connections from other machines, you will need\n    to pass ``--host 0.0.0.0`` to listen on all network interfaces\n    (or a specific interface address).\n    \"\"\"\n\n    _validate_server_args(gunicorn_opts=gunicorn_opts, workers=workers, waitress_opts=waitress_opts)\n\n    # Ensure that both backend_store_uri and default_artifact_uri are set correctly.\n    if not backend_store_uri:\n        backend_store_uri = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH\n\n    if not default_artifact_root:\n        if is_local_uri(backend_store_uri):\n            default_artifact_root = backend_store_uri\n        else:\n            eprint(\"Option 'default-artifact-root' is required, when backend store is not \"\n                   \"local file based.\")\n            sys.exit(1)\n\n    try:\n        initialize_backend_stores(backend_store_uri, default_artifact_root)\n    except Exception as e:  # pylint: disable=broad-except\n        _logger.error(\"Error initializing backend store\")\n        _logger.exception(e)\n        sys.exit(1)\n\n    try:\n        _run_server(backend_store_uri, default_artifact_root, host, port,\n                    static_prefix, workers, gunicorn_opts, waitress_opts)\n    except ShellCommandException:\n        eprint(\"Running the mlflow server failed. Please see the logs above for details.\")\n        sys.exit(1)\n\n\ncli.add_command(mlflow.models.cli.commands)\ncli.add_command(mlflow.sagemaker.cli.commands)\ncli.add_command(mlflow.experiments.commands)\ncli.add_command(mlflow.store.artifact.cli.commands)\ncli.add_command(mlflow.azureml.cli.commands)\ncli.add_command(mlflow.runs.commands)\ncli.add_command(mlflow.db.commands)\n\nif __name__ == '__main__':\n    cli()\n", "path": "mlflow/cli.py"}]}