Replace use of atexit

This commit is contained in:
Kovid Goyal 2025-07-15 14:12:12 +05:30
parent f83e15f7aa
commit b54a0957e3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2,7 +2,6 @@
# License: GPLv3 Copyright: 2009, Kovid Goyal <kovid at kovidgoyal.net>
import atexit
import glob
import os
import shutil
@ -286,9 +285,11 @@ class Sdist(Command):
def run(self, opts):
if not self.e(self.d(self.DEST)):
os.makedirs(self.d(self.DEST))
tdir = tempfile.mkdtemp()
atexit.register(shutil.rmtree, tdir)
tdir = self.j(tdir, f'calibre-{__version__}')
with tempfile.TemporaryDirectory() as tdir:
tdir = self.j(tdir, f'calibre-{__version__}')
self.run_with_tdir(tdir)
def run_with_tdir(self, tdir):
self.info('\tRunning git export...')
os.mkdir(tdir)
subprocess.check_call('git archive HEAD | tar -x -C ' + tdir, shell=True)