Skip to content

Commit c31c1d8

Browse files
committed
setup.py: Drop py2 codepath.
Use py3-only subprocess.DEVNULL instead of opening /dev/null .
1 parent 86ad8ab commit c31c1d8

1 file changed

Lines changed: 35 additions & 37 deletions

File tree

setup.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -102,48 +102,46 @@ def run(self):
102102
for suffix in ('', '.asc'):
103103
with open(archive_path + suffix, 'wb') as archive_file:
104104
archive_file.write(urlopen(url + suffix).read())
105-
# py2 does not have subprocess.DEVNULL.
106-
with open(os.devnull, 'wb') as devnull:
107-
# to build/update trustedkeys-libusb.kbx:
108-
# gpg --no-default-keyring --keyring trustedkeys-libusb.kbx --receive-keys ...
105+
# to build/update trustedkeys-libusb.kbx:
106+
# gpg --no-default-keyring --keyring trustedkeys-libusb.kbx --receive-keys ...
107+
subprocess.check_call(
108+
[
109+
'gpgv',
110+
'--keyring', 'trustedkeys-libusb.kbx',
111+
archive_path + '.asc', archive_path,
112+
],
113+
# gnupg will not shut its pie hole.
114+
stderr=subprocess.DEVNULL,
115+
close_fds=True,
116+
)
117+
# This check is for the maintainer to notice a new release, and
118+
# to retrospectively confirm that a release was done with files
119+
# from a certain archive (and not just any signed release).
120+
# It is *not* to check file authenticity (for this, we have gpg).
121+
with open(archive_path, 'rb') as archive_file:
122+
archive_sha256 = hashlib.sha256(archive_file.read()).hexdigest()
123+
if archive_sha256 != CURRENT_WINDOWS_7Z_SHA256:
124+
raise ValueError(
125+
'Windows release sha56 mismatch: %r fetched with a sha256 of %r' % (
126+
url,
127+
archive_sha256,
128+
)
129+
)
130+
for arch_path, out_dir in (
131+
('VS2019/MS32/dll/libusb-1.0.dll', os.path.join(build_dir, 'win32')),
132+
('VS2019/MS64/dll/libusb-1.0.dll', os.path.join(build_dir, 'win_amd64')),
133+
):
109134
subprocess.check_call(
110135
[
111-
'gpgv',
112-
'--keyring', 'trustedkeys-libusb.kbx',
113-
archive_path + '.asc', archive_path,
136+
'7z', 'e', '-aoa',
137+
'-o' + out_dir,
138+
archive_path,
139+
arch_path,
114140
],
115-
# gnupg will not shut its pie hole.
116-
stderr=devnull,
141+
# 7z will not shut its pie hole.
142+
stdout=subprocess.DEVNULL,
117143
close_fds=True,
118144
)
119-
# This check is for the maintainer to notice a new release, and
120-
# to retrospectively confirm that a release was done with files
121-
# from a certain archive (and not just any signed release).
122-
# It is *not* to check file authenticity (for this, we have gpg).
123-
with open(archive_path, 'rb') as archive_file:
124-
archive_sha256 = hashlib.sha256(archive_file.read()).hexdigest()
125-
if archive_sha256 != CURRENT_WINDOWS_7Z_SHA256:
126-
raise ValueError(
127-
'Windows release sha56 mismatch: %r fetched with a sha256 of %r' % (
128-
url,
129-
archive_sha256,
130-
)
131-
)
132-
for arch_path, out_dir in (
133-
('VS2019/MS32/dll/libusb-1.0.dll', os.path.join(build_dir, 'win32')),
134-
('VS2019/MS64/dll/libusb-1.0.dll', os.path.join(build_dir, 'win_amd64')),
135-
):
136-
subprocess.check_call(
137-
[
138-
'7z', 'e', '-aoa',
139-
'-o' + out_dir,
140-
archive_path,
141-
arch_path,
142-
],
143-
# 7z will not shut its pie hole.
144-
stdout=devnull,
145-
close_fds=True,
146-
)
147145
cmdclass['update_libusb'] = update_libusb
148146

149147
long_description = open(

0 commit comments

Comments
 (0)