Skip to content

Commit cefbab5

Browse files
authored
Merge pull request #183 from tamird/restore-bash-completions
Restore bash completions
2 parents 4774e0f + 0cf73c3 commit cefbab5

File tree

8 files changed

+75
-108
lines changed

8 files changed

+75
-108
lines changed

.github/workflows/pylint.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,26 @@ jobs:
1111
matrix:
1212
python-version: ["3.8", "3.9", "3.10"]
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
- name: Set up Python ${{ matrix.python-version }}
16-
uses: actions/setup-python@v3
16+
uses: actions/setup-python@v5
1717
with:
1818
python-version: ${{ matrix.python-version }}
1919
- name: Install dependencies
2020
run: |
21+
set -euxo pipefail
22+
2123
python -m pip install --upgrade pip
22-
pip install -r requirements.txt
23-
pip install pylint
24-
pip install flake8
24+
25+
# Both build and runtime deps. This is the price of using pip.
26+
pip install 'argparse-manpage[setuptools]' argcomplete requests
27+
28+
pip install pylint flake8
2529
- name: Analysing the code with pylint
2630
run: |
27-
python setup.py lint
31+
set -euxo pipefail
32+
33+
pylint vng '**/*.py'
34+
35+
flake8 vng
36+
find . -name '*.py' | xargs flake8

MANIFEST.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ GIT_DESCRIBE := $(shell git describe --always --long --dirty)
77
install: install_from_source
88
install_from_source:
99
@echo "Version: $(GIT_DESCRIBE)"
10-
BUILD_VIRTME_NG_INIT=1 pip3 install --verbose -r requirements.txt $(INSTALL_ARGS) .
10+
BUILD_VIRTME_NG_INIT=1 pip3 install --verbose $(INSTALL_ARGS) .
1111

1212
install_only_top:
1313
@echo "Version: $(GIT_DESCRIBE)"
14-
BUILD_VIRTME_NG_INIT=0 pip3 install --verbose -r requirements.txt $(INSTALL_ARGS) .
14+
BUILD_VIRTME_NG_INIT=0 pip3 install --verbose $(INSTALL_ARGS) .

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,19 @@ To install virtme-ng from source you can clone this git repository and build a
7979
standalone virtme-ng running the following commands:
8080
```
8181
$ git clone --recurse-submodules https://github.com/arighi/virtme-ng.git
82-
$ BUILD_VIRTME_NG_INIT=1 pip3 install --verbose -r requirements.txt .
82+
$ BUILD_VIRTME_NG_INIT=1 pip3 install .
8383
```
8484

8585
If you are in Debian/Ubuntu you may need to install the following packages to
8686
build virtme-ng from source properly:
8787
```
88-
$ sudo apt install python3-pip python3-argcomplete flake8 pylint \
89-
cargo rustc qemu-system-x86
88+
$ sudo apt install python3-pip flake8 pylint cargo rustc qemu-system-x86
9089
```
9190

92-
In recent versions of pip3 you may need to specify `--break-system-packages` to
93-
properly install virtme-ng in your system from source.
91+
If you'd prefer to use `uv`:
92+
```
93+
$ BUILD_VIRTME_NG_INIT=1 uv tool install .
94+
```
9495

9596
* Run from source
9697

pyproject.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[build-system]
2+
requires = [
3+
"argparse-manpage[setuptools]",
4+
"setuptools",
5+
6+
# Runtime dependencies, needed to generate manpages.
7+
"argcomplete",
8+
"requests",
9+
]
10+
11+
[tool.build_manpages]
12+
manpages = [
13+
"""\
14+
man/vng.1\
15+
:pyfile=virtme_ng/run.py\
16+
:function=make_parser\
17+
:author=virtme-ng is written by Andrea Righi <arighi@nvidia.com>\
18+
:author=Based on virtme by Andy Lutomirski <luto@kernel.org>\
19+
:manual_title=virtme-ng\
20+
:description=Quickly run kernels inside a virtualized snapshot of your live system\
21+
""",
22+
]

requirements.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

setup.py

Lines changed: 26 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env python3
22

33
import os
4-
import sys
54
import platform
5+
import subprocess
6+
import sys
67
import sysconfig
7-
from glob import glob
8-
from shutil import which
9-
from subprocess import check_call, CalledProcessError
10-
from setuptools import setup, Command
8+
from argcomplete import shell_integration
9+
from build_manpages import build_manpages, get_build_py_cmd, get_install_cmd
10+
from setuptools import setup
1111
from setuptools.command.build_py import build_py
1212
from setuptools.command.egg_info import egg_info
1313
from virtme_ng.version import get_version_string
@@ -29,62 +29,12 @@
2929
# Make sure virtme-ng-init submodule has been cloned
3030
if build_virtme_ng_init and not os.path.exists("virtme_ng_init/Cargo.toml"):
3131
sys.stderr.write("WARNING: virtme-ng-init submodule not available, trying to clone it\n")
32-
check_call("git submodule update --init --recursive", shell=True)
32+
subprocess.check_call("git submodule update --init --recursive", shell=True)
3333

3434
# Always include standard site-packages to PYTHONPATH
3535
os.environ['PYTHONPATH'] = sysconfig.get_paths()['purelib']
3636

3737

38-
def is_arm_32bit():
39-
arch = platform.machine()
40-
return arch.startswith("arm") and platform.architecture()[0] == "32bit"
41-
42-
43-
def parse_requirements(filename):
44-
with open(filename, 'r', encoding="utf-8") as file:
45-
lines = file.readlines()
46-
return [line.strip() for line in lines if line.strip() and not line.startswith('#')]
47-
48-
49-
class LintCommand(Command):
50-
description = "Run coding style checks"
51-
user_options = []
52-
53-
def initialize_options(self):
54-
pass
55-
56-
def finalize_options(self):
57-
pass
58-
59-
def run(self):
60-
try:
61-
for cmd in ("flake8", "pylint"):
62-
command = [cmd]
63-
for pattern in (
64-
"vng",
65-
"*.py",
66-
"virtme/*.py",
67-
"virtme/*/*.py",
68-
"virtme_ng/*.py",
69-
):
70-
command += glob(pattern)
71-
check_call(command)
72-
except CalledProcessError:
73-
sys.exit(1)
74-
75-
76-
man_command = f"""
77-
argparse-manpage \
78-
--pyfile ./virtme_ng/run.py --function make_parser \
79-
--prog vng --version v{VERSION} \
80-
--author "virtme-ng is written by Andrea Righi <arighi@nvidia.com>" \
81-
--author "Based on virtme by Andy Lutomirski <luto@kernel.org>" \
82-
--project-name virtme-ng --manual-title virtme-ng \
83-
--description "Quickly run kernels inside a virtualized snapshot of your live system" \
84-
--url https://github.com/arighi/virtme-ng > vng.1
85-
"""
86-
87-
8838
class BuildPy(build_py):
8939
def run(self):
9040
print(f"BUILD_VIRTME_NG_INIT: {build_virtme_ng_init}")
@@ -102,28 +52,17 @@ def run(self):
10252
"--target", target,
10353
"--config", f"target.{target}.linker = \"rust-lld\"",
10454
])
105-
check_call(args, cwd="virtme_ng_init")
106-
check_call(
55+
subprocess.check_call(args, cwd="virtme_ng_init")
56+
subprocess.check_call(
10757
["strip", os.path.join(root, "bin", "virtme-ng-init")],
10858
cwd=cwd,
10959
)
110-
# Generate manpage
111-
if which('argparse-manpage'):
112-
env = os.environ.copy()
113-
env["PYTHONPATH"] = os.path.dirname(os.path.abspath(__file__))
114-
check_call(man_command, shell=True, env=env)
11560

11661
# Generate bash autocompletion scripts
117-
completion_command = ''
118-
if which("register-python-argcomplete"):
119-
completion_command = "register-python-argcomplete"
120-
elif which("register-python-argcomplete3"):
121-
completion_command = "register-python-argcomplete3"
122-
else:
123-
print("ERROR: 'register-python-argcomplete' or 'register-python-argcomplete3' not found.")
124-
sys.exit(1)
125-
check_call(completion_command + ' virtme-ng > virtme-ng-prompt', shell=True)
126-
check_call(completion_command + ' vng > vng-prompt', shell=True)
62+
with open("virtme-ng-prompt", "w", encoding="utf-8") as f:
63+
f.write(shell_integration.shellcode(["virtme-ng"]))
64+
with open("vng-prompt", "w", encoding="utf-8") as f:
65+
f.write(shell_integration.shellcode(["vng"]))
12766

12867
# Run the rest of virtme-ng build
12968
build_py.run(self)
@@ -166,26 +105,30 @@ def run(self):
166105

167106
data_files = [
168107
("/etc", ["cfg/virtme-ng.conf"]),
169-
("/usr/share/bash-completion/completions", ["virtme-ng-prompt"]),
170-
("/usr/share/bash-completion/completions", ["vng-prompt"]),
108+
("/usr/share/bash-completion/completions", ["virtme-ng-prompt", "vng-prompt"]),
109+
("/usr/share/man/man1", ["man/vng.1"]),
171110
]
172111

173-
if which('argparse-manpage'):
174-
data_files.append(("/usr/share/man/man1", ["vng.1"]))
175-
176112
setup(
177113
name="virtme-ng",
178114
version=VERSION,
179115
author="Andrea Righi",
180116
author_email="arighi@nvidia.com",
181117
description="Build and run a kernel inside a virtualized snapshot of your live system",
182-
url="https://git.launchpad.net/~arighi/+git/virtme-ng",
118+
url="https://github.com/arighi/virtme-ng",
183119
license="GPLv2",
184120
long_description=open(
185121
os.path.join(os.path.dirname(__file__), "README.md"), "r", encoding="utf-8"
186122
).read(),
187123
long_description_content_type="text/markdown",
188-
install_requires=parse_requirements('requirements.txt'),
124+
install_requires=[
125+
'argcomplete',
126+
'requests',
127+
# `pkg_resources` is removed in python 3.12, moved to setuptools.
128+
#
129+
# TODO: replace pkg_resources with importlib. # pylint: disable=fixme
130+
'setuptools',
131+
],
189132
entry_points={
190133
"console_scripts": [
191134
"vng = virtme_ng.run:main",
@@ -196,9 +139,10 @@ def run(self):
196139
]
197140
},
198141
cmdclass={
199-
"build_py": BuildPy,
142+
"build_manpages": build_manpages,
143+
"build_py": get_build_py_cmd(BuildPy),
144+
"install": get_install_cmd(),
200145
"egg_info": EggInfo,
201-
"lint": LintCommand,
202146
},
203147
packages=packages,
204148
package_data={"virtme.guest": package_files},

virtme_ng/run.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@
2323
)
2424
from select import select
2525
from pathlib import Path
26-
try:
27-
from argcomplete import autocomplete
28-
except ModuleNotFoundError:
29-
def autocomplete(*args, **kwargs):
30-
# pylint: disable=unused-argument
31-
pass
26+
27+
import argcomplete
3228

3329
from virtme.util import SilentError, get_username
3430
from virtme_ng.utils import CONF_FILE, spinner_decorator
@@ -79,6 +75,7 @@ def make_parser():
7975
"""Main virtme-ng command line parser."""
8076

8177
parser = argparse.ArgumentParser(
78+
prog="vng",
8279
formatter_class=argparse.RawTextHelpFormatter,
8380
description="Build and run kernels inside a virtualized snapshot of your live system",
8481
epilog="""\
@@ -1245,7 +1242,7 @@ def dump(kern_source, args):
12451242

12461243
def do_it() -> int:
12471244
"""Main body."""
1248-
autocomplete(_ARGPARSER)
1245+
argcomplete.autocomplete(_ARGPARSER)
12491246
args = _ARGPARSER.parse_args()
12501247

12511248
kern_source = KernelSource()

0 commit comments

Comments
 (0)