We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Can't get option --dirtyreload to work?
In reference to issue #990 I am trying to get a dirty reload to work. Since I have a site with almost 300 pages a full rebuild takes about 4 minutes.
Testscenario:
Use mkdocs 1.16
1. test with `mkdocs serve`, on change of a page the full site gets rebuilt
2. test with `mkdocs serve --dirtyreload`, on change of page nothing happens?
3. test with `mkdocs serve --dirtyreload --livereload`:
the output correctly states that mkdocs is `watching changes`. However on a change the full site is rebuilt and not only the changed file.

What I find strange is that when I only use `--dirtyreload` that I don't see a message taht mkdocs is `watching changes`

Is this an issue with how mkdocs watches for changes when doing `--dirtyreload` or am I doing something wrong. I have to add that I'm running using my own docker container, that's why I explicitly tried whether reload does indeed work without `--dirtyreload`

regards,
Rick


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mkdocs/commands/serve.py`
Content:
```
1 from __future__ import unicode_literals
2 import logging
3 import shutil
4 import tempfile
5 
6 from mkdocs.commands.build import build
7 from mkdocs.config import load_config
8 
9 log = logging.getLogger(__name__)
10 
11 
12 def _livereload(host, port, config, builder, site_dir):
13 
14     # We are importing here for anyone that has issues with livereload. Even if
15     # this fails, the --no-livereload alternative should still work.
16     from livereload import Server
17 
18     server = Server()
19 
20     # Watch the documentation files, the config file and the theme files.
21     server.watch(config['docs_dir'], builder)
22     server.watch(config['config_file_path'], builder)
23 
24     for d in config['theme_dir']:
25         server.watch(d, builder)
26 
27     server.serve(root=site_dir, host=host, port=int(port), restart_delay=0)
28 
29 
30 def _static_server(host, port, site_dir):
31 
32     # Importing here to seperate the code paths from the --livereload
33     # alternative.
34     from tornado import ioloop
35     from tornado import web
36 
37     application = web.Application([
38         (r"/(.*)", web.StaticFileHandler, {
39             "path": site_dir,
40             "default_filename": "index.html"
41         }),
42     ])
43     application.listen(port=int(port), address=host)
44 
45     log.info('Running at: http://%s:%s/', host, port)
46     log.info('Hold ctrl+c to quit.')
47     try:
48         ioloop.IOLoop.instance().start()
49     except KeyboardInterrupt:
50         log.info('Stopping server...')
51 
52 
53 def serve(config_file=None, dev_addr=None, strict=None, theme=None,
54           theme_dir=None, livereload='livereload'):
55     """
56     Start the MkDocs development server
57 
58     By default it will serve the documentation on http://localhost:8000/ and
59     it will rebuild the documentation and refresh the page automatically
60     whenever a file is edited.
61     """
62 
63     # Create a temporary build directory, and set some options to serve it
64     tempdir = tempfile.mkdtemp()
65 
66     def builder():
67         log.info("Building documentation...")
68         config = load_config(
69             config_file=config_file,
70             dev_addr=dev_addr,
71             strict=strict,
72             theme=theme,
73             theme_dir=theme_dir
74         )
75         config['site_dir'] = tempdir
76         live_server = livereload in ['dirty', 'livereload']
77         dirty = livereload == 'dirtyreload'
78         build(config, live_server=live_server, dirty=dirty)
79         return config
80 
81     # Perform the initial build
82     config = builder()
83 
84     host, port = config['dev_addr'].split(':', 1)
85 
86     try:
87         if livereload in ['livereload', 'dirtyreload']:
88             _livereload(host, port, config, builder, tempdir)
89         else:
90             _static_server(host, port, tempdir)
91     finally:
92         shutil.rmtree(tempdir)
93
```

Path: `mkdocs/__main__.py`
Content:
```
1 #!/usr/bin/env python
2 # coding: utf-8
3 
4 from __future__ import unicode_literals
5 import logging
6 import click
7 import socket
8 
9 from mkdocs import __version__
10 from mkdocs import utils
11 from mkdocs import exceptions
12 from mkdocs import config
13 from mkdocs.commands import build, gh_deploy, new, serve
14 
15 log = logging.getLogger(__name__)
16 
17 # Disable the warning that Click displays (as of Click version 5.0) when users
18 # use unicode_literals in Python 2.
19 # See http://click.pocoo.org/dev/python3/#unicode-literals for more details.
20 click.disable_unicode_literals_warning = True
21 
22 
23 class State(object):
24     ''' Maintain logging level.'''
25 
26     def __init__(self, log_name='mkdocs', level=logging.INFO):
27         self.logger = logging.getLogger(log_name)
28         self.logger.propagate = False
29         stream = logging.StreamHandler()
30         formatter = logging.Formatter("%(levelname)-7s -  %(message)s ")
31         stream.setFormatter(formatter)
32         self.logger.addHandler(stream)
33 
34         self.logger.setLevel(level)
35 
36 
37 pass_state = click.make_pass_decorator(State, ensure=True)
38 
39 
40 def verbose_option(f):
41     def callback(ctx, param, value):
42         state = ctx.ensure_object(State)
43         if value:
44             state.logger.setLevel(logging.DEBUG)
45     return click.option('-v', '--verbose',
46                         is_flag=True,
47                         expose_value=False,
48                         help='Enable verbose output',
49                         callback=callback)(f)
50 
51 
52 def quiet_option(f):
53     def callback(ctx, param, value):
54         state = ctx.ensure_object(State)
55         if value:
56             state.logger.setLevel(logging.ERROR)
57     return click.option('-q', '--quiet',
58                         is_flag=True,
59                         expose_value=False,
60                         help='Silence warnings',
61                         callback=callback)(f)
62 
63 
64 def common_options(f):
65     f = verbose_option(f)
66     f = quiet_option(f)
67     return f
68 
69 
70 clean_help = "Remove old files from the site_dir before building (the default)."
71 config_help = "Provide a specific MkDocs config"
72 dev_addr_help = ("IP address and port to serve documentation locally (default: "
73                  "localhost:8000)")
74 strict_help = ("Enable strict mode. This will cause MkDocs to abort the build "
75                "on any warnings.")
76 theme_dir_help = "The theme directory to use when building your documentation."
77 theme_help = "The theme to use when building your documentation."
78 theme_choices = utils.get_theme_names()
79 site_dir_help = "The directory to output the result of the documentation build."
80 reload_help = "Enable the live reloading in the development server (this is the default)"
81 no_reload_help = "Disable the live reloading in the development server."
82 dirty_reload_help = "Enable the live reloading in the development server, but only re-build files that have changed"
83 commit_message_help = ("A commit message to use when commiting to the "
84                        "Github Pages remote branch")
85 remote_branch_help = ("The remote branch to commit to for Github Pages. This "
86                       "overrides the value specified in config")
87 remote_name_help = ("The remote name to commit to for Github Pages. This "
88                     "overrides the value specified in config")
89 force_help = "Force the push to the repository."
90 
91 
92 @click.group(context_settings={'help_option_names': ['-h', '--help']})
93 @click.version_option(__version__, '-V', '--version')
94 @common_options
95 def cli():
96     """
97     MkDocs - Project documentation with Markdown.
98     """
99 
100 
101 @cli.command(name="serve")
102 @click.option('-f', '--config-file', type=click.File('rb'), help=config_help)
103 @click.option('-a', '--dev-addr', help=dev_addr_help, metavar='<IP:PORT>')
104 @click.option('-s', '--strict', is_flag=True, help=strict_help)
105 @click.option('-t', '--theme', type=click.Choice(theme_choices), help=theme_help)
106 @click.option('-e', '--theme-dir', type=click.Path(), help=theme_dir_help)
107 @click.option('--livereload', 'livereload', flag_value='livereload', help=reload_help, default=True)
108 @click.option('--no-livereload', 'livereload', flag_value='no-livereload', help=no_reload_help)
109 @click.option('-d', '--dirtyreload', 'livereload', flag_value='dirty', help=dirty_reload_help)
110 @common_options
111 def serve_command(dev_addr, config_file, strict, theme, theme_dir, livereload):
112     """Run the builtin development server"""
113 
114     logging.getLogger('tornado').setLevel(logging.WARNING)
115 
116     # Don't override config value if user did not specify --strict flag
117     # Conveniently, load_config drops None values
118     strict = strict or None
119 
120     try:
121         serve.serve(
122             config_file=config_file,
123             dev_addr=dev_addr,
124             strict=strict,
125             theme=theme,
126             theme_dir=theme_dir,
127             livereload=livereload
128         )
129     except (exceptions.ConfigurationError, socket.error) as e:  # pragma: no cover
130         # Avoid ugly, unhelpful traceback
131         raise SystemExit('\n' + str(e))
132 
133 
134 @cli.command(name="build")
135 @click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)
136 @click.option('-f', '--config-file', type=click.File('rb'), help=config_help)
137 @click.option('-s', '--strict', is_flag=True, help=strict_help)
138 @click.option('-t', '--theme', type=click.Choice(theme_choices), help=theme_help)
139 @click.option('-e', '--theme-dir', type=click.Path(), help=theme_dir_help)
140 @click.option('-d', '--site-dir', type=click.Path(), help=site_dir_help)
141 @common_options
142 def build_command(clean, config_file, strict, theme, theme_dir, site_dir):
143     """Build the MkDocs documentation"""
144 
145     # Don't override config value if user did not specify --strict flag
146     # Conveniently, load_config drops None values
147     strict = strict or None
148 
149     try:
150         build.build(config.load_config(
151             config_file=config_file,
152             strict=strict,
153             theme=theme,
154             theme_dir=theme_dir,
155             site_dir=site_dir
156         ), dirty=not clean)
157     except exceptions.ConfigurationError as e:  # pragma: no cover
158         # Avoid ugly, unhelpful traceback
159         raise SystemExit('\n' + str(e))
160 
161 
162 @cli.command(name="json")
163 @click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)
164 @click.option('-f', '--config-file', type=click.File('rb'), help=config_help)
165 @click.option('-s', '--strict', is_flag=True, help=strict_help)
166 @click.option('-d', '--site-dir', type=click.Path(), help=site_dir_help)
167 @common_options
168 def json_command(clean, config_file, strict, site_dir):
169     """Build the MkDocs documentation to JSON files
170 
171     Rather than building your documentation to HTML pages, this
172     outputs each page in a simple JSON format. This command is
173     useful if you want to index your documentation in an external
174     search engine.
175     """
176 
177     log.warning("The json command is deprecated and will be removed in a "
178                 "future MkDocs release. For details on updating: "
179                 "http://www.mkdocs.org/about/release-notes/")
180 
181     # Don't override config value if user did not specify --strict flag
182     # Conveniently, load_config drops None values
183     strict = strict or None
184 
185     try:
186         build.build(config.load_config(
187             config_file=config_file,
188             strict=strict,
189             site_dir=site_dir
190         ), dump_json=True, dirty=not clean)
191     except exceptions.ConfigurationError as e:  # pragma: no cover
192         # Avoid ugly, unhelpful traceback
193         raise SystemExit('\n' + str(e))
194 
195 
196 @cli.command(name="gh-deploy")
197 @click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)
198 @click.option('-f', '--config-file', type=click.File('rb'), help=config_help)
199 @click.option('-m', '--message', help=commit_message_help)
200 @click.option('-b', '--remote-branch', help=remote_branch_help)
201 @click.option('-r', '--remote-name', help=remote_name_help)
202 @click.option('--force', is_flag=True, help=force_help)
203 @common_options
204 def gh_deploy_command(config_file, clean, message, remote_branch, remote_name, force):
205     """Deploy your documentation to GitHub Pages"""
206     try:
207         cfg = config.load_config(
208             config_file=config_file,
209             remote_branch=remote_branch,
210             remote_name=remote_name
211         )
212         build.build(cfg, dirty=not clean)
213         gh_deploy.gh_deploy(cfg, message=message, force=force)
214     except exceptions.ConfigurationError as e:  # pragma: no cover
215         # Avoid ugly, unhelpful traceback
216         raise SystemExit('\n' + str(e))
217 
218 
219 @cli.command(name="new")
220 @click.argument("project_directory")
221 @common_options
222 def new_command(project_directory):
223     """Create a new MkDocs project"""
224     new.new(project_directory)
225 
226 if __name__ == '__main__':  # pragma: no cover
227     cli()
228
```
--- 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/mkdocs/__main__.py b/mkdocs/__main__.py
--- a/mkdocs/__main__.py
+++ b/mkdocs/__main__.py
@@ -106,7 +106,7 @@
 @click.option('-e', '--theme-dir', type=click.Path(), help=theme_dir_help)
 @click.option('--livereload', 'livereload', flag_value='livereload', help=reload_help, default=True)
 @click.option('--no-livereload', 'livereload', flag_value='no-livereload', help=no_reload_help)
-@click.option('-d', '--dirtyreload', 'livereload', flag_value='dirty', help=dirty_reload_help)
+@click.option('--dirtyreload', 'livereload', flag_value='dirty', help=dirty_reload_help)
 @common_options
 def serve_command(dev_addr, config_file, strict, theme, theme_dir, livereload):
     """Run the builtin development server"""
diff --git a/mkdocs/commands/serve.py b/mkdocs/commands/serve.py
--- a/mkdocs/commands/serve.py
+++ b/mkdocs/commands/serve.py
@@ -74,7 +74,7 @@
         )
         config['site_dir'] = tempdir
         live_server = livereload in ['dirty', 'livereload']
-        dirty = livereload == 'dirtyreload'
+        dirty = livereload == 'dirty'
         build(config, live_server=live_server, dirty=dirty)
         return config
 
@@ -84,7 +84,7 @@
     host, port = config['dev_addr'].split(':', 1)
 
     try:
-        if livereload in ['livereload', 'dirtyreload']:
+        if livereload in ['livereload', 'dirty']:
             _livereload(host, port, config, builder, tempdir)
         else:
             _static_server(host, port, tempdir)

{"golden_diff": "diff --git a/mkdocs/__main__.py b/mkdocs/__main__.py\n--- a/mkdocs/__main__.py\n+++ b/mkdocs/__main__.py\n@@ -106,7 +106,7 @@\n @click.option('-e', '--theme-dir', type=click.Path(), help=theme_dir_help)\n @click.option('--livereload', 'livereload', flag_value='livereload', help=reload_help, default=True)\n @click.option('--no-livereload', 'livereload', flag_value='no-livereload', help=no_reload_help)\n-@click.option('-d', '--dirtyreload', 'livereload', flag_value='dirty', help=dirty_reload_help)\n+@click.option('--dirtyreload', 'livereload', flag_value='dirty', help=dirty_reload_help)\n @common_options\n def serve_command(dev_addr, config_file, strict, theme, theme_dir, livereload):\n     \"\"\"Run the builtin development server\"\"\"\ndiff --git a/mkdocs/commands/serve.py b/mkdocs/commands/serve.py\n--- a/mkdocs/commands/serve.py\n+++ b/mkdocs/commands/serve.py\n@@ -74,7 +74,7 @@\n         )\n         config['site_dir'] = tempdir\n         live_server = livereload in ['dirty', 'livereload']\n-        dirty = livereload == 'dirtyreload'\n+        dirty = livereload == 'dirty'\n         build(config, live_server=live_server, dirty=dirty)\n         return config\n \n@@ -84,7 +84,7 @@\n     host, port = config['dev_addr'].split(':', 1)\n \n     try:\n-        if livereload in ['livereload', 'dirtyreload']:\n+        if livereload in ['livereload', 'dirty']:\n             _livereload(host, port, config, builder, tempdir)\n         else:\n             _static_server(host, port, tempdir)\n", "issue": "Can't get option --dirtyreload to work?\nIn reference to issue #990 I am trying to get a dirty reload to work. Since I have a site with almost 300 pages a full rebuild takes about 4 minutes.\nTestscenario:\nUse mkdocs 1.16\n1. test with `mkdocs serve`, on change of a page the full site gets rebuilt\n2. test with `mkdocs serve --dirtyreload`, on change of page nothing happens?\n3. test with `mkdocs serve --dirtyreload --livereload`:\nthe output correctly states that mkdocs is `watching changes`. However on a change the full site is rebuilt and not only the changed file.\n\nWhat I find strange is that when I only use `--dirtyreload` that I don't see a message taht mkdocs is `watching changes`\n\nIs this an issue with how mkdocs watches for changes when doing `--dirtyreload` or am I doing something wrong. I have to add that I'm running using my own docker container, that's why I explicitly tried whether reload does indeed work without `--dirtyreload`\n\nregards,\nRick\n\n", "before_files": [{"content": "from __future__ import unicode_literals\nimport logging\nimport shutil\nimport tempfile\n\nfrom mkdocs.commands.build import build\nfrom mkdocs.config import load_config\n\nlog = logging.getLogger(__name__)\n\n\ndef _livereload(host, port, config, builder, site_dir):\n\n    # We are importing here for anyone that has issues with livereload. Even if\n    # this fails, the --no-livereload alternative should still work.\n    from livereload import Server\n\n    server = Server()\n\n    # Watch the documentation files, the config file and the theme files.\n    server.watch(config['docs_dir'], builder)\n    server.watch(config['config_file_path'], builder)\n\n    for d in config['theme_dir']:\n        server.watch(d, builder)\n\n    server.serve(root=site_dir, host=host, port=int(port), restart_delay=0)\n\n\ndef _static_server(host, port, site_dir):\n\n    # Importing here to seperate the code paths from the --livereload\n    # alternative.\n    from tornado import ioloop\n    from tornado import web\n\n    application = web.Application([\n        (r\"/(.*)\", web.StaticFileHandler, {\n            \"path\": site_dir,\n            \"default_filename\": \"index.html\"\n        }),\n    ])\n    application.listen(port=int(port), address=host)\n\n    log.info('Running at: http://%s:%s/', host, port)\n    log.info('Hold ctrl+c to quit.')\n    try:\n        ioloop.IOLoop.instance().start()\n    except KeyboardInterrupt:\n        log.info('Stopping server...')\n\n\ndef serve(config_file=None, dev_addr=None, strict=None, theme=None,\n          theme_dir=None, livereload='livereload'):\n    \"\"\"\n    Start the MkDocs development server\n\n    By default it will serve the documentation on http://localhost:8000/ and\n    it will rebuild the documentation and refresh the page automatically\n    whenever a file is edited.\n    \"\"\"\n\n    # Create a temporary build directory, and set some options to serve it\n    tempdir = tempfile.mkdtemp()\n\n    def builder():\n        log.info(\"Building documentation...\")\n        config = load_config(\n            config_file=config_file,\n            dev_addr=dev_addr,\n            strict=strict,\n            theme=theme,\n            theme_dir=theme_dir\n        )\n        config['site_dir'] = tempdir\n        live_server = livereload in ['dirty', 'livereload']\n        dirty = livereload == 'dirtyreload'\n        build(config, live_server=live_server, dirty=dirty)\n        return config\n\n    # Perform the initial build\n    config = builder()\n\n    host, port = config['dev_addr'].split(':', 1)\n\n    try:\n        if livereload in ['livereload', 'dirtyreload']:\n            _livereload(host, port, config, builder, tempdir)\n        else:\n            _static_server(host, port, tempdir)\n    finally:\n        shutil.rmtree(tempdir)\n", "path": "mkdocs/commands/serve.py"}, {"content": "#!/usr/bin/env python\n# coding: utf-8\n\nfrom __future__ import unicode_literals\nimport logging\nimport click\nimport socket\n\nfrom mkdocs import __version__\nfrom mkdocs import utils\nfrom mkdocs import exceptions\nfrom mkdocs import config\nfrom mkdocs.commands import build, gh_deploy, new, serve\n\nlog = logging.getLogger(__name__)\n\n# Disable the warning that Click displays (as of Click version 5.0) when users\n# use unicode_literals in Python 2.\n# See http://click.pocoo.org/dev/python3/#unicode-literals for more details.\nclick.disable_unicode_literals_warning = True\n\n\nclass State(object):\n    ''' Maintain logging level.'''\n\n    def __init__(self, log_name='mkdocs', level=logging.INFO):\n        self.logger = logging.getLogger(log_name)\n        self.logger.propagate = False\n        stream = logging.StreamHandler()\n        formatter = logging.Formatter(\"%(levelname)-7s -  %(message)s \")\n        stream.setFormatter(formatter)\n        self.logger.addHandler(stream)\n\n        self.logger.setLevel(level)\n\n\npass_state = click.make_pass_decorator(State, ensure=True)\n\n\ndef verbose_option(f):\n    def callback(ctx, param, value):\n        state = ctx.ensure_object(State)\n        if value:\n            state.logger.setLevel(logging.DEBUG)\n    return click.option('-v', '--verbose',\n                        is_flag=True,\n                        expose_value=False,\n                        help='Enable verbose output',\n                        callback=callback)(f)\n\n\ndef quiet_option(f):\n    def callback(ctx, param, value):\n        state = ctx.ensure_object(State)\n        if value:\n            state.logger.setLevel(logging.ERROR)\n    return click.option('-q', '--quiet',\n                        is_flag=True,\n                        expose_value=False,\n                        help='Silence warnings',\n                        callback=callback)(f)\n\n\ndef common_options(f):\n    f = verbose_option(f)\n    f = quiet_option(f)\n    return f\n\n\nclean_help = \"Remove old files from the site_dir before building (the default).\"\nconfig_help = \"Provide a specific MkDocs config\"\ndev_addr_help = (\"IP address and port to serve documentation locally (default: \"\n                 \"localhost:8000)\")\nstrict_help = (\"Enable strict mode. This will cause MkDocs to abort the build \"\n               \"on any warnings.\")\ntheme_dir_help = \"The theme directory to use when building your documentation.\"\ntheme_help = \"The theme to use when building your documentation.\"\ntheme_choices = utils.get_theme_names()\nsite_dir_help = \"The directory to output the result of the documentation build.\"\nreload_help = \"Enable the live reloading in the development server (this is the default)\"\nno_reload_help = \"Disable the live reloading in the development server.\"\ndirty_reload_help = \"Enable the live reloading in the development server, but only re-build files that have changed\"\ncommit_message_help = (\"A commit message to use when commiting to the \"\n                       \"Github Pages remote branch\")\nremote_branch_help = (\"The remote branch to commit to for Github Pages. This \"\n                      \"overrides the value specified in config\")\nremote_name_help = (\"The remote name to commit to for Github Pages. This \"\n                    \"overrides the value specified in config\")\nforce_help = \"Force the push to the repository.\"\n\n\n@click.group(context_settings={'help_option_names': ['-h', '--help']})\n@click.version_option(__version__, '-V', '--version')\n@common_options\ndef cli():\n    \"\"\"\n    MkDocs - Project documentation with Markdown.\n    \"\"\"\n\n\n@cli.command(name=\"serve\")\n@click.option('-f', '--config-file', type=click.File('rb'), help=config_help)\n@click.option('-a', '--dev-addr', help=dev_addr_help, metavar='<IP:PORT>')\n@click.option('-s', '--strict', is_flag=True, help=strict_help)\n@click.option('-t', '--theme', type=click.Choice(theme_choices), help=theme_help)\n@click.option('-e', '--theme-dir', type=click.Path(), help=theme_dir_help)\n@click.option('--livereload', 'livereload', flag_value='livereload', help=reload_help, default=True)\n@click.option('--no-livereload', 'livereload', flag_value='no-livereload', help=no_reload_help)\n@click.option('-d', '--dirtyreload', 'livereload', flag_value='dirty', help=dirty_reload_help)\n@common_options\ndef serve_command(dev_addr, config_file, strict, theme, theme_dir, livereload):\n    \"\"\"Run the builtin development server\"\"\"\n\n    logging.getLogger('tornado').setLevel(logging.WARNING)\n\n    # Don't override config value if user did not specify --strict flag\n    # Conveniently, load_config drops None values\n    strict = strict or None\n\n    try:\n        serve.serve(\n            config_file=config_file,\n            dev_addr=dev_addr,\n            strict=strict,\n            theme=theme,\n            theme_dir=theme_dir,\n            livereload=livereload\n        )\n    except (exceptions.ConfigurationError, socket.error) as e:  # pragma: no cover\n        # Avoid ugly, unhelpful traceback\n        raise SystemExit('\\n' + str(e))\n\n\n@cli.command(name=\"build\")\n@click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)\n@click.option('-f', '--config-file', type=click.File('rb'), help=config_help)\n@click.option('-s', '--strict', is_flag=True, help=strict_help)\n@click.option('-t', '--theme', type=click.Choice(theme_choices), help=theme_help)\n@click.option('-e', '--theme-dir', type=click.Path(), help=theme_dir_help)\n@click.option('-d', '--site-dir', type=click.Path(), help=site_dir_help)\n@common_options\ndef build_command(clean, config_file, strict, theme, theme_dir, site_dir):\n    \"\"\"Build the MkDocs documentation\"\"\"\n\n    # Don't override config value if user did not specify --strict flag\n    # Conveniently, load_config drops None values\n    strict = strict or None\n\n    try:\n        build.build(config.load_config(\n            config_file=config_file,\n            strict=strict,\n            theme=theme,\n            theme_dir=theme_dir,\n            site_dir=site_dir\n        ), dirty=not clean)\n    except exceptions.ConfigurationError as e:  # pragma: no cover\n        # Avoid ugly, unhelpful traceback\n        raise SystemExit('\\n' + str(e))\n\n\n@cli.command(name=\"json\")\n@click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)\n@click.option('-f', '--config-file', type=click.File('rb'), help=config_help)\n@click.option('-s', '--strict', is_flag=True, help=strict_help)\n@click.option('-d', '--site-dir', type=click.Path(), help=site_dir_help)\n@common_options\ndef json_command(clean, config_file, strict, site_dir):\n    \"\"\"Build the MkDocs documentation to JSON files\n\n    Rather than building your documentation to HTML pages, this\n    outputs each page in a simple JSON format. This command is\n    useful if you want to index your documentation in an external\n    search engine.\n    \"\"\"\n\n    log.warning(\"The json command is deprecated and will be removed in a \"\n                \"future MkDocs release. For details on updating: \"\n                \"http://www.mkdocs.org/about/release-notes/\")\n\n    # Don't override config value if user did not specify --strict flag\n    # Conveniently, load_config drops None values\n    strict = strict or None\n\n    try:\n        build.build(config.load_config(\n            config_file=config_file,\n            strict=strict,\n            site_dir=site_dir\n        ), dump_json=True, dirty=not clean)\n    except exceptions.ConfigurationError as e:  # pragma: no cover\n        # Avoid ugly, unhelpful traceback\n        raise SystemExit('\\n' + str(e))\n\n\n@cli.command(name=\"gh-deploy\")\n@click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)\n@click.option('-f', '--config-file', type=click.File('rb'), help=config_help)\n@click.option('-m', '--message', help=commit_message_help)\n@click.option('-b', '--remote-branch', help=remote_branch_help)\n@click.option('-r', '--remote-name', help=remote_name_help)\n@click.option('--force', is_flag=True, help=force_help)\n@common_options\ndef gh_deploy_command(config_file, clean, message, remote_branch, remote_name, force):\n    \"\"\"Deploy your documentation to GitHub Pages\"\"\"\n    try:\n        cfg = config.load_config(\n            config_file=config_file,\n            remote_branch=remote_branch,\n            remote_name=remote_name\n        )\n        build.build(cfg, dirty=not clean)\n        gh_deploy.gh_deploy(cfg, message=message, force=force)\n    except exceptions.ConfigurationError as e:  # pragma: no cover\n        # Avoid ugly, unhelpful traceback\n        raise SystemExit('\\n' + str(e))\n\n\n@cli.command(name=\"new\")\n@click.argument(\"project_directory\")\n@common_options\ndef new_command(project_directory):\n    \"\"\"Create a new MkDocs project\"\"\"\n    new.new(project_directory)\n\nif __name__ == '__main__':  # pragma: no cover\n    cli()\n", "path": "mkdocs/__main__.py"}], "after_files": [{"content": "from __future__ import unicode_literals\nimport logging\nimport shutil\nimport tempfile\n\nfrom mkdocs.commands.build import build\nfrom mkdocs.config import load_config\n\nlog = logging.getLogger(__name__)\n\n\ndef _livereload(host, port, config, builder, site_dir):\n\n    # We are importing here for anyone that has issues with livereload. Even if\n    # this fails, the --no-livereload alternative should still work.\n    from livereload import Server\n\n    server = Server()\n\n    # Watch the documentation files, the config file and the theme files.\n    server.watch(config['docs_dir'], builder)\n    server.watch(config['config_file_path'], builder)\n\n    for d in config['theme_dir']:\n        server.watch(d, builder)\n\n    server.serve(root=site_dir, host=host, port=int(port), restart_delay=0)\n\n\ndef _static_server(host, port, site_dir):\n\n    # Importing here to seperate the code paths from the --livereload\n    # alternative.\n    from tornado import ioloop\n    from tornado import web\n\n    application = web.Application([\n        (r\"/(.*)\", web.StaticFileHandler, {\n            \"path\": site_dir,\n            \"default_filename\": \"index.html\"\n        }),\n    ])\n    application.listen(port=int(port), address=host)\n\n    log.info('Running at: http://%s:%s/', host, port)\n    log.info('Hold ctrl+c to quit.')\n    try:\n        ioloop.IOLoop.instance().start()\n    except KeyboardInterrupt:\n        log.info('Stopping server...')\n\n\ndef serve(config_file=None, dev_addr=None, strict=None, theme=None,\n          theme_dir=None, livereload='livereload'):\n    \"\"\"\n    Start the MkDocs development server\n\n    By default it will serve the documentation on http://localhost:8000/ and\n    it will rebuild the documentation and refresh the page automatically\n    whenever a file is edited.\n    \"\"\"\n\n    # Create a temporary build directory, and set some options to serve it\n    tempdir = tempfile.mkdtemp()\n\n    def builder():\n        log.info(\"Building documentation...\")\n        config = load_config(\n            config_file=config_file,\n            dev_addr=dev_addr,\n            strict=strict,\n            theme=theme,\n            theme_dir=theme_dir\n        )\n        config['site_dir'] = tempdir\n        live_server = livereload in ['dirty', 'livereload']\n        dirty = livereload == 'dirty'\n        build(config, live_server=live_server, dirty=dirty)\n        return config\n\n    # Perform the initial build\n    config = builder()\n\n    host, port = config['dev_addr'].split(':', 1)\n\n    try:\n        if livereload in ['livereload', 'dirty']:\n            _livereload(host, port, config, builder, tempdir)\n        else:\n            _static_server(host, port, tempdir)\n    finally:\n        shutil.rmtree(tempdir)\n", "path": "mkdocs/commands/serve.py"}, {"content": "#!/usr/bin/env python\n# coding: utf-8\n\nfrom __future__ import unicode_literals\nimport logging\nimport click\nimport socket\n\nfrom mkdocs import __version__\nfrom mkdocs import utils\nfrom mkdocs import exceptions\nfrom mkdocs import config\nfrom mkdocs.commands import build, gh_deploy, new, serve\n\nlog = logging.getLogger(__name__)\n\n# Disable the warning that Click displays (as of Click version 5.0) when users\n# use unicode_literals in Python 2.\n# See http://click.pocoo.org/dev/python3/#unicode-literals for more details.\nclick.disable_unicode_literals_warning = True\n\n\nclass State(object):\n    ''' Maintain logging level.'''\n\n    def __init__(self, log_name='mkdocs', level=logging.INFO):\n        self.logger = logging.getLogger(log_name)\n        self.logger.propagate = False\n        stream = logging.StreamHandler()\n        formatter = logging.Formatter(\"%(levelname)-7s -  %(message)s \")\n        stream.setFormatter(formatter)\n        self.logger.addHandler(stream)\n\n        self.logger.setLevel(level)\n\n\npass_state = click.make_pass_decorator(State, ensure=True)\n\n\ndef verbose_option(f):\n    def callback(ctx, param, value):\n        state = ctx.ensure_object(State)\n        if value:\n            state.logger.setLevel(logging.DEBUG)\n    return click.option('-v', '--verbose',\n                        is_flag=True,\n                        expose_value=False,\n                        help='Enable verbose output',\n                        callback=callback)(f)\n\n\ndef quiet_option(f):\n    def callback(ctx, param, value):\n        state = ctx.ensure_object(State)\n        if value:\n            state.logger.setLevel(logging.ERROR)\n    return click.option('-q', '--quiet',\n                        is_flag=True,\n                        expose_value=False,\n                        help='Silence warnings',\n                        callback=callback)(f)\n\n\ndef common_options(f):\n    f = verbose_option(f)\n    f = quiet_option(f)\n    return f\n\n\nclean_help = \"Remove old files from the site_dir before building (the default).\"\nconfig_help = \"Provide a specific MkDocs config\"\ndev_addr_help = (\"IP address and port to serve documentation locally (default: \"\n                 \"localhost:8000)\")\nstrict_help = (\"Enable strict mode. This will cause MkDocs to abort the build \"\n               \"on any warnings.\")\ntheme_dir_help = \"The theme directory to use when building your documentation.\"\ntheme_help = \"The theme to use when building your documentation.\"\ntheme_choices = utils.get_theme_names()\nsite_dir_help = \"The directory to output the result of the documentation build.\"\nreload_help = \"Enable the live reloading in the development server (this is the default)\"\nno_reload_help = \"Disable the live reloading in the development server.\"\ndirty_reload_help = \"Enable the live reloading in the development server, but only re-build files that have changed\"\ncommit_message_help = (\"A commit message to use when commiting to the \"\n                       \"Github Pages remote branch\")\nremote_branch_help = (\"The remote branch to commit to for Github Pages. This \"\n                      \"overrides the value specified in config\")\nremote_name_help = (\"The remote name to commit to for Github Pages. This \"\n                    \"overrides the value specified in config\")\nforce_help = \"Force the push to the repository.\"\n\n\n@click.group(context_settings={'help_option_names': ['-h', '--help']})\n@click.version_option(__version__, '-V', '--version')\n@common_options\ndef cli():\n    \"\"\"\n    MkDocs - Project documentation with Markdown.\n    \"\"\"\n\n\n@cli.command(name=\"serve\")\n@click.option('-f', '--config-file', type=click.File('rb'), help=config_help)\n@click.option('-a', '--dev-addr', help=dev_addr_help, metavar='<IP:PORT>')\n@click.option('-s', '--strict', is_flag=True, help=strict_help)\n@click.option('-t', '--theme', type=click.Choice(theme_choices), help=theme_help)\n@click.option('-e', '--theme-dir', type=click.Path(), help=theme_dir_help)\n@click.option('--livereload', 'livereload', flag_value='livereload', help=reload_help, default=True)\n@click.option('--no-livereload', 'livereload', flag_value='no-livereload', help=no_reload_help)\n@click.option('--dirtyreload', 'livereload', flag_value='dirty', help=dirty_reload_help)\n@common_options\ndef serve_command(dev_addr, config_file, strict, theme, theme_dir, livereload):\n    \"\"\"Run the builtin development server\"\"\"\n\n    logging.getLogger('tornado').setLevel(logging.WARNING)\n\n    # Don't override config value if user did not specify --strict flag\n    # Conveniently, load_config drops None values\n    strict = strict or None\n\n    try:\n        serve.serve(\n            config_file=config_file,\n            dev_addr=dev_addr,\n            strict=strict,\n            theme=theme,\n            theme_dir=theme_dir,\n            livereload=livereload\n        )\n    except (exceptions.ConfigurationError, socket.error) as e:  # pragma: no cover\n        # Avoid ugly, unhelpful traceback\n        raise SystemExit('\\n' + str(e))\n\n\n@cli.command(name=\"build\")\n@click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)\n@click.option('-f', '--config-file', type=click.File('rb'), help=config_help)\n@click.option('-s', '--strict', is_flag=True, help=strict_help)\n@click.option('-t', '--theme', type=click.Choice(theme_choices), help=theme_help)\n@click.option('-e', '--theme-dir', type=click.Path(), help=theme_dir_help)\n@click.option('-d', '--site-dir', type=click.Path(), help=site_dir_help)\n@common_options\ndef build_command(clean, config_file, strict, theme, theme_dir, site_dir):\n    \"\"\"Build the MkDocs documentation\"\"\"\n\n    # Don't override config value if user did not specify --strict flag\n    # Conveniently, load_config drops None values\n    strict = strict or None\n\n    try:\n        build.build(config.load_config(\n            config_file=config_file,\n            strict=strict,\n            theme=theme,\n            theme_dir=theme_dir,\n            site_dir=site_dir\n        ), dirty=not clean)\n    except exceptions.ConfigurationError as e:  # pragma: no cover\n        # Avoid ugly, unhelpful traceback\n        raise SystemExit('\\n' + str(e))\n\n\n@cli.command(name=\"json\")\n@click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)\n@click.option('-f', '--config-file', type=click.File('rb'), help=config_help)\n@click.option('-s', '--strict', is_flag=True, help=strict_help)\n@click.option('-d', '--site-dir', type=click.Path(), help=site_dir_help)\n@common_options\ndef json_command(clean, config_file, strict, site_dir):\n    \"\"\"Build the MkDocs documentation to JSON files\n\n    Rather than building your documentation to HTML pages, this\n    outputs each page in a simple JSON format. This command is\n    useful if you want to index your documentation in an external\n    search engine.\n    \"\"\"\n\n    log.warning(\"The json command is deprecated and will be removed in a \"\n                \"future MkDocs release. For details on updating: \"\n                \"http://www.mkdocs.org/about/release-notes/\")\n\n    # Don't override config value if user did not specify --strict flag\n    # Conveniently, load_config drops None values\n    strict = strict or None\n\n    try:\n        build.build(config.load_config(\n            config_file=config_file,\n            strict=strict,\n            site_dir=site_dir\n        ), dump_json=True, dirty=not clean)\n    except exceptions.ConfigurationError as e:  # pragma: no cover\n        # Avoid ugly, unhelpful traceback\n        raise SystemExit('\\n' + str(e))\n\n\n@cli.command(name=\"gh-deploy\")\n@click.option('-c', '--clean/--dirty', is_flag=True, default=True, help=clean_help)\n@click.option('-f', '--config-file', type=click.File('rb'), help=config_help)\n@click.option('-m', '--message', help=commit_message_help)\n@click.option('-b', '--remote-branch', help=remote_branch_help)\n@click.option('-r', '--remote-name', help=remote_name_help)\n@click.option('--force', is_flag=True, help=force_help)\n@common_options\ndef gh_deploy_command(config_file, clean, message, remote_branch, remote_name, force):\n    \"\"\"Deploy your documentation to GitHub Pages\"\"\"\n    try:\n        cfg = config.load_config(\n            config_file=config_file,\n            remote_branch=remote_branch,\n            remote_name=remote_name\n        )\n        build.build(cfg, dirty=not clean)\n        gh_deploy.gh_deploy(cfg, message=message, force=force)\n    except exceptions.ConfigurationError as e:  # pragma: no cover\n        # Avoid ugly, unhelpful traceback\n        raise SystemExit('\\n' + str(e))\n\n\n@cli.command(name=\"new\")\n@click.argument(\"project_directory\")\n@common_options\ndef new_command(project_directory):\n    \"\"\"Create a new MkDocs project\"\"\"\n    new.new(project_directory)\n\nif __name__ == '__main__':  # pragma: no cover\n    cli()\n", "path": "mkdocs/__main__.py"}]}