Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use entrypoint to generate mkosi instead of symlink #401

Merged
merged 2 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ jobs:
sudo ln -s ~/go/bin/swupd-extract /usr/bin/swupd-extract

- name: Build ${{ matrix.distro }}/${{ matrix.format }}
run: sudo ./mkosi
run: sudo python3 -m mkosi
--debug run
--distribution ${{ matrix.distro }}
--format ${{ matrix.format }}

- name: Build ${{ matrix.distro }}/${{ matrix.format }} UEFI
if: matrix.format != 'directory' && matrix.format != 'tar' && matrix.format != 'plain_squashfs' &&
(matrix.distro != 'clear' || matrix.format != 'gpt_squashfs') && matrix.distro != 'photon'
run: sudo ./mkosi
run: sudo python3 -m mkosi
--debug run
--distribution ${{ matrix.distro }}
--format ${{ matrix.format }}
Expand All @@ -282,7 +282,7 @@ jobs:

- name: Build ${{ matrix.distro }}/${{ matrix.format }} BIOS
if: matrix.format != 'directory' && matrix.format != 'tar' && !contains(matrix.format, 'squashfs')
run: sudo ./mkosi
run: sudo python3 -m mkosi
--debug run
--distribution ${{ matrix.distro }}
--format ${{ matrix.format }}
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ bells and whistles.
For a longer description and available features and options, see the
[man page](mkosi.md).

# Installation

Installing `mkosi` is easy, as it has no runtime Python dependencies (you will
need all the tools to format filesystems and bootstrap the distribution
appropriate for your image, though).

If you just want the current master branch you can run
```shell
python3 -m pip install --user git+https://github.com/systemd/mkosi.git
```

If you want to hack on mkosi do
```shell
# clone either this repository or your fork of it
git clone https://github.com/systemd/mkosi/
cd mkosi
python3 -m pip install --user --editable .
```
This will install mkosi in editable mode to `~/.local/bin/mkosi`, allowing you
to use your own changes right away.

For development you optionally also need [mypy](https://github.com/python/mypy)
and [pytest](https://github.com/pytest-dev/pytest). We check tests and typing in
CI (see `.github/workflows`), but you can run the tests locally as well.

# References

* [Primary mkosi git repository on GitHub](https://github.com/systemd/mkosi/)
Expand Down
1 change: 0 additions & 1 deletion mkosi.py

This file was deleted.

28 changes: 0 additions & 28 deletions mkosi → mkosi/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
# SPDX-License-Identifier: LGPL-2.1+

import argparse
Expand Down Expand Up @@ -59,10 +57,6 @@
__version__ = '5'


if sys.version_info < (3, 6):
sys.exit("Sorry, we need at least Python 3.6.")


# These types are only generic during type checking and not at runtime, leading
# to a TypeError during compilation.
# Let's be as strict as we can with the description for the usage we have.
Expand Down Expand Up @@ -5320,25 +5314,3 @@ def run_verb(args: CommandLineArguments) -> None:

if args.verb == "qemu":
run_qemu(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("Error: %s is not a directory!" % work_dir)
with complete_step('Processing ' + job_name):
run_verb(a)
except MkosiException:
sys.exit(1)


if __name__ == "__main__":
main()
23 changes: 23 additions & 0 deletions mkosi/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-License-Identifier: LGPL-2.1+
# PYTHON_ARGCOMPLETE_OK
import os
import sys

from . import parse_args, complete_step, run_verb, die, MkosiException


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)
11 changes: 4 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/python3
# SPDX-License-Identifier: LGPL-2.1+

import sys

from setuptools import setup, Command

class BuildManpage(Command):
Expand All @@ -17,9 +15,6 @@ def finalize_options(self):
def run(self):
self.spawn(['pandoc', '-t', 'man', '-o', 'mkosi.1', 'mkosi.md'])

if sys.version_info < (3, 6):
sys.exit("Sorry, we need at least Python 3.6.")


setup(
name="mkosi",
Expand All @@ -29,6 +24,8 @@ def run(self):
maintainer="mkosi contributors",
maintainer_email="systemd-devel@lists.freedesktop.org",
license="LGPLv2+",
scripts=["mkosi"],
cmdclass = { "man": BuildManpage }
python_requires=">=3.6",
packages = ["mkosi"],
cmdclass = { "man": BuildManpage },
entry_points = {"console_scripts": ["mkosi=mkosi.__main__"]},
)
7 changes: 1 addition & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

import sys
import os
dir_path = os.path.dirname(os.path.realpath(__file__))

import importlib.util
spec = importlib.util.spec_from_file_location('mkosi', os.path.join(dir_path, '../mkosi.py'))
mkosi_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mkosi_module)
sys.modules['mkosi'] = mkosi_module
import mkosi

from tests.test_config_parser import MkosiConfig

Expand Down
12 changes: 4 additions & 8 deletions tests/test_config_parser.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# SPDX-License-Identifier: LGPL-2.1+

import configparser
import copy
import os
dir_path = os.path.dirname(os.path.realpath(__file__))

import importlib.util
spec = importlib.util.spec_from_file_location('mkosi', os.path.join(dir_path, '../mkosi.py'))
mkosi = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mkosi)

import pytest
import configparser
import copy

import mkosi


class ChangeCwd(object):
Expand Down