1
1
#!/usr/bin/env python3
2
2
3
3
import os
4
- import sys
5
4
import platform
5
+ import subprocess
6
+ import sys
6
7
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
11
11
from setuptools .command .build_py import build_py
12
12
from setuptools .command .egg_info import egg_info
13
13
from virtme_ng .version import get_version_string
29
29
# Make sure virtme-ng-init submodule has been cloned
30
30
if build_virtme_ng_init and not os .path .exists ("virtme_ng_init/Cargo.toml" ):
31
31
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 )
33
33
34
34
# Always include standard site-packages to PYTHONPATH
35
35
os .environ ['PYTHONPATH' ] = sysconfig .get_paths ()['purelib' ]
36
36
37
37
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
-
88
38
class BuildPy (build_py ):
89
39
def run (self ):
90
40
print (f"BUILD_VIRTME_NG_INIT: { build_virtme_ng_init } " )
@@ -102,28 +52,17 @@ def run(self):
102
52
"--target" , target ,
103
53
"--config" , f"target.{ target } .linker = \" rust-lld\" " ,
104
54
])
105
- check_call (args , cwd = "virtme_ng_init" )
106
- check_call (
55
+ subprocess . check_call (args , cwd = "virtme_ng_init" )
56
+ subprocess . check_call (
107
57
["strip" , os .path .join (root , "bin" , "virtme-ng-init" )],
108
58
cwd = cwd ,
109
59
)
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 )
115
60
116
61
# 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" ]))
127
66
128
67
# Run the rest of virtme-ng build
129
68
build_py .run (self )
@@ -166,26 +105,30 @@ def run(self):
166
105
167
106
data_files = [
168
107
("/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 " ]),
171
110
]
172
111
173
- if which ('argparse-manpage' ):
174
- data_files .append (("/usr/share/man/man1" , ["vng.1" ]))
175
-
176
112
setup (
177
113
name = "virtme-ng" ,
178
114
version = VERSION ,
179
115
author = "Andrea Righi" ,
180
116
author_email = "arighi@nvidia.com" ,
181
117
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" ,
183
119
license = "GPLv2" ,
184
120
long_description = open (
185
121
os .path .join (os .path .dirname (__file__ ), "README.md" ), "r" , encoding = "utf-8"
186
122
).read (),
187
123
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
+ ],
189
132
entry_points = {
190
133
"console_scripts" : [
191
134
"vng = virtme_ng.run:main" ,
@@ -196,9 +139,10 @@ def run(self):
196
139
]
197
140
},
198
141
cmdclass = {
199
- "build_py" : BuildPy ,
142
+ "build_manpages" : build_manpages ,
143
+ "build_py" : get_build_py_cmd (BuildPy ),
144
+ "install" : get_install_cmd (),
200
145
"egg_info" : EggInfo ,
201
- "lint" : LintCommand ,
202
146
},
203
147
packages = packages ,
204
148
package_data = {"virtme.guest" : package_files },
0 commit comments