We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Include man page in Python package
When building the man page with
```
pandoc -t man -o mkosi.1 mkosi.md
```
the output looks rather unpleasing:
```
mkosi  ‐  Build  Legacy‐Free  OS  Images mkosi [options...] build
mkosi [options...] clean mkosi [options...]  summary  mkosi  [op‐
tions...]  shell [command line...]  mkosi [options...] boot [com‐
mand line...]  mkosi [options...] qemu mkosi is a tool for easily
building  legacy‐free OS images.  It’s a fancy wrapper around dnf
‐‐installroot, debootstrap, pacstrap and zypper that may generate
disk  images  with a number of bells and whistles.  The following
output formats are supported: Raw GPT disk image,  with  ext4  as
[...]
```

We should fix that and maybe generate the man page automatically via a commit hook, so that the man page can be included (and installed) when doing a pip install.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mkosi/__main__.py`
Content:
```
1 # SPDX-License-Identifier: LGPL-2.1+
2 # PYTHON_ARGCOMPLETE_OK
3 import os
4 import sys
5 
6 from . import parse_args, complete_step, run_verb, die, MkosiException
7 
8 
9 try:
10     args = parse_args()
11 
12     for job_name, a in args.items():
13         # Change working directory if --directory is passed
14         if a.directory:
15             work_dir = a.directory
16             if os.path.isdir(work_dir):
17                 os.chdir(work_dir)
18             else:
19                 die(f"Error: {work_dir} is not a directory!")
20         with complete_step(f"Processing {job_name}"):
21             run_verb(a)
22 except MkosiException:
23     sys.exit(1)
24
```

Path: `setup.py`
Content:
```
1 #!/usr/bin/python3
2 # SPDX-License-Identifier: LGPL-2.1+
3 
4 from setuptools import setup, Command
5 
6 class BuildManpage(Command):
7     description = ('builds the manpage')
8     user_options = []
9 
10     def initialize_options(self):
11         pass
12     def finalize_options(self):
13         pass
14 
15     def run(self):
16         self.spawn(['pandoc', '-t', 'man', '-s', '-o', 'mkosi.1', 'mkosi.md'])
17 
18 
19 setup(
20     name="mkosi",
21     version="5",
22     description="Create legacy-free OS images",
23     url="https://github.com/systemd/mkosi",
24     maintainer="mkosi contributors",
25     maintainer_email="systemd-devel@lists.freedesktop.org",
26     license="LGPLv2+",
27     python_requires=">=3.6",
28     packages = ["mkosi"],
29     cmdclass = { "man": BuildManpage },
30     entry_points = {"console_scripts": ["mkosi=mkosi.__main__"]},
31 )
32
```
--- 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/mkosi/__main__.py b/mkosi/__main__.py
--- a/mkosi/__main__.py
+++ b/mkosi/__main__.py
@@ -6,18 +6,23 @@
 from . import parse_args, complete_step, run_verb, die, MkosiException
 
 
-try:
-    args = parse_args()
+def main() -> None:
+    try:
+        args = parse_args()
 
-    for job_name, a in args.items():
-        # Change working directory if --directory is passed
-        if a.directory:
-            work_dir = a.directory
-            if os.path.isdir(work_dir):
-                os.chdir(work_dir)
-            else:
-                die(f"Error: {work_dir} is not a directory!")
-        with complete_step(f"Processing {job_name}"):
-            run_verb(a)
-except MkosiException:
-    sys.exit(1)
+        for job_name, a in args.items():
+            # Change working directory if --directory is passed
+            if a.directory:
+                work_dir = a.directory
+                if os.path.isdir(work_dir):
+                    os.chdir(work_dir)
+                else:
+                    die(f"Error: {work_dir} is not a directory!")
+            with complete_step(f"Processing {job_name}"):
+                run_verb(a)
+    except MkosiException:
+        sys.exit(1)
+
+
+if __name__ == "__main__":
+    main()
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -13,7 +13,7 @@
         pass
 
     def run(self):
-        self.spawn(['pandoc', '-t', 'man', '-s', '-o', 'mkosi.1', 'mkosi.md'])
+        self.spawn(['pandoc', '-t', 'man', '-s', '-o', 'man/mkosi.1', 'mkosi.md'])
 
 
 setup(
@@ -27,5 +27,6 @@
     python_requires=">=3.6",
     packages = ["mkosi"],
     cmdclass = { "man": BuildManpage },
-    entry_points = {"console_scripts": ["mkosi=mkosi.__main__"]},
+    data_files = [('share/man/man1', ["man/mkosi.1"])],
+    entry_points = {"console_scripts": ["mkosi=mkosi.__main__:main"]},
 )

{"golden_diff": "diff --git a/mkosi/__main__.py b/mkosi/__main__.py\n--- a/mkosi/__main__.py\n+++ b/mkosi/__main__.py\n@@ -6,18 +6,23 @@\n from . import parse_args, complete_step, run_verb, die, MkosiException\n \n \n-try:\n-    args = parse_args()\n+def main() -> None:\n+    try:\n+        args = parse_args()\n \n-    for job_name, a in args.items():\n-        # Change working directory if --directory is passed\n-        if a.directory:\n-            work_dir = a.directory\n-            if os.path.isdir(work_dir):\n-                os.chdir(work_dir)\n-            else:\n-                die(f\"Error: {work_dir} is not a directory!\")\n-        with complete_step(f\"Processing {job_name}\"):\n-            run_verb(a)\n-except MkosiException:\n-    sys.exit(1)\n+        for job_name, a in args.items():\n+            # Change working directory if --directory is passed\n+            if a.directory:\n+                work_dir = a.directory\n+                if os.path.isdir(work_dir):\n+                    os.chdir(work_dir)\n+                else:\n+                    die(f\"Error: {work_dir} is not a directory!\")\n+            with complete_step(f\"Processing {job_name}\"):\n+                run_verb(a)\n+    except MkosiException:\n+        sys.exit(1)\n+\n+\n+if __name__ == \"__main__\":\n+    main()\ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -13,7 +13,7 @@\n         pass\n \n     def run(self):\n-        self.spawn(['pandoc', '-t', 'man', '-s', '-o', 'mkosi.1', 'mkosi.md'])\n+        self.spawn(['pandoc', '-t', 'man', '-s', '-o', 'man/mkosi.1', 'mkosi.md'])\n \n \n setup(\n@@ -27,5 +27,6 @@\n     python_requires=\">=3.6\",\n     packages = [\"mkosi\"],\n     cmdclass = { \"man\": BuildManpage },\n-    entry_points = {\"console_scripts\": [\"mkosi=mkosi.__main__\"]},\n+    data_files = [('share/man/man1', [\"man/mkosi.1\"])],\n+    entry_points = {\"console_scripts\": [\"mkosi=mkosi.__main__:main\"]},\n )\n", "issue": "Include man page in Python package\nWhen building the man page with\r\n```\r\npandoc -t man -o mkosi.1 mkosi.md\r\n```\r\nthe output looks rather unpleasing:\r\n```\r\nmkosi  \u2010  Build  Legacy\u2010Free  OS  Images mkosi [options...] build\r\nmkosi [options...] clean mkosi [options...]  summary  mkosi  [op\u2010\r\ntions...]  shell [command line...]  mkosi [options...] boot [com\u2010\r\nmand line...]  mkosi [options...] qemu mkosi is a tool for easily\r\nbuilding  legacy\u2010free OS images.  It\u2019s a fancy wrapper around dnf\r\n\u2010\u2010installroot, debootstrap, pacstrap and zypper that may generate\r\ndisk  images  with a number of bells and whistles.  The following\r\noutput formats are supported: Raw GPT disk image,  with  ext4  as\r\n[...]\r\n```\r\n\r\nWe should fix that and maybe generate the man page automatically via a commit hook, so that the man page can be included (and installed) when doing a pip install.\n", "before_files": [{"content": "# SPDX-License-Identifier: LGPL-2.1+\n# PYTHON_ARGCOMPLETE_OK\nimport os\nimport sys\n\nfrom . import parse_args, complete_step, run_verb, die, MkosiException\n\n\ntry:\n    args = parse_args()\n\n    for job_name, a in args.items():\n        # Change working directory if --directory is passed\n        if a.directory:\n            work_dir = a.directory\n            if os.path.isdir(work_dir):\n                os.chdir(work_dir)\n            else:\n                die(f\"Error: {work_dir} is not a directory!\")\n        with complete_step(f\"Processing {job_name}\"):\n            run_verb(a)\nexcept MkosiException:\n    sys.exit(1)\n", "path": "mkosi/__main__.py"}, {"content": "#!/usr/bin/python3\n# SPDX-License-Identifier: LGPL-2.1+\n\nfrom setuptools import setup, Command\n\nclass BuildManpage(Command):\n    description = ('builds the manpage')\n    user_options = []\n\n    def initialize_options(self):\n        pass\n    def finalize_options(self):\n        pass\n\n    def run(self):\n        self.spawn(['pandoc', '-t', 'man', '-s', '-o', 'mkosi.1', 'mkosi.md'])\n\n\nsetup(\n    name=\"mkosi\",\n    version=\"5\",\n    description=\"Create legacy-free OS images\",\n    url=\"https://github.com/systemd/mkosi\",\n    maintainer=\"mkosi contributors\",\n    maintainer_email=\"systemd-devel@lists.freedesktop.org\",\n    license=\"LGPLv2+\",\n    python_requires=\">=3.6\",\n    packages = [\"mkosi\"],\n    cmdclass = { \"man\": BuildManpage },\n    entry_points = {\"console_scripts\": [\"mkosi=mkosi.__main__\"]},\n)\n", "path": "setup.py"}], "after_files": [{"content": "# SPDX-License-Identifier: LGPL-2.1+\n# PYTHON_ARGCOMPLETE_OK\nimport os\nimport sys\n\nfrom . import parse_args, complete_step, run_verb, die, MkosiException\n\n\ndef main() -> None:\n    try:\n        args = parse_args()\n\n        for job_name, a in args.items():\n            # Change working directory if --directory is passed\n            if a.directory:\n                work_dir = a.directory\n                if os.path.isdir(work_dir):\n                    os.chdir(work_dir)\n                else:\n                    die(f\"Error: {work_dir} is not a directory!\")\n            with complete_step(f\"Processing {job_name}\"):\n                run_verb(a)\n    except MkosiException:\n        sys.exit(1)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "mkosi/__main__.py"}, {"content": "#!/usr/bin/python3\n# SPDX-License-Identifier: LGPL-2.1+\n\nfrom setuptools import setup, Command\n\nclass BuildManpage(Command):\n    description = ('builds the manpage')\n    user_options = []\n\n    def initialize_options(self):\n        pass\n    def finalize_options(self):\n        pass\n\n    def run(self):\n        self.spawn(['pandoc', '-t', 'man', '-s', '-o', 'man/mkosi.1', 'mkosi.md'])\n\n\nsetup(\n    name=\"mkosi\",\n    version=\"5\",\n    description=\"Create legacy-free OS images\",\n    url=\"https://github.com/systemd/mkosi\",\n    maintainer=\"mkosi contributors\",\n    maintainer_email=\"systemd-devel@lists.freedesktop.org\",\n    license=\"LGPLv2+\",\n    python_requires=\">=3.6\",\n    packages = [\"mkosi\"],\n    cmdclass = { \"man\": BuildManpage },\n    data_files = [('share/man/man1', [\"man/mkosi.1\"])],\n    entry_points = {\"console_scripts\": [\"mkosi=mkosi.__main__:main\"]},\n)\n", "path": "setup.py"}]}