mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Fix usage of dry-run in packaging bdist_wininst and install_distinfo.
In dry-run mode, packaging commands should log the same info as in real operation and should collect the same files in self.outputs, so that users can run a command in verbose and dry-run mode to see exactly what operations will be done in the real run.
This commit is contained in:
parent
e6db7a3a29
commit
c8f9c81cfa
2 changed files with 38 additions and 39 deletions
|
@ -186,9 +186,8 @@ class bdist_wininst(Command):
|
||||||
os.remove(arcname)
|
os.remove(arcname)
|
||||||
|
|
||||||
if not self.keep_temp:
|
if not self.keep_temp:
|
||||||
if self.dry_run:
|
|
||||||
logger.info('removing %s', self.bdist_dir)
|
logger.info('removing %s', self.bdist_dir)
|
||||||
else:
|
if not self.dry_run:
|
||||||
rmtree(self.bdist_dir)
|
rmtree(self.bdist_dir)
|
||||||
|
|
||||||
def get_inidata(self):
|
def get_inidata(self):
|
||||||
|
|
|
@ -28,7 +28,7 @@ class install_distinfo(Command):
|
||||||
('no-record', None,
|
('no-record', None,
|
||||||
"do not generate a RECORD file"),
|
"do not generate a RECORD file"),
|
||||||
('no-resources', None,
|
('no-resources', None,
|
||||||
"do not generate a RESSOURCES list installed file")
|
"do not generate a RESSOURCES list installed file"),
|
||||||
]
|
]
|
||||||
|
|
||||||
boolean_options = ['requested', 'no-record', 'no-resources']
|
boolean_options = ['requested', 'no-record', 'no-resources']
|
||||||
|
@ -70,13 +70,10 @@ class install_distinfo(Command):
|
||||||
self.distinfo_dir = os.path.join(self.distinfo_dir, basename)
|
self.distinfo_dir = os.path.join(self.distinfo_dir, basename)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# FIXME dry-run should be used at a finer level, so that people get
|
|
||||||
# useful logging output and can have an idea of what the command would
|
|
||||||
# have done
|
|
||||||
if not self.dry_run:
|
|
||||||
target = self.distinfo_dir
|
target = self.distinfo_dir
|
||||||
|
|
||||||
if os.path.isdir(target) and not os.path.islink(target):
|
if os.path.isdir(target) and not os.path.islink(target):
|
||||||
|
if not self.dry_run:
|
||||||
rmtree(target)
|
rmtree(target)
|
||||||
elif os.path.exists(target):
|
elif os.path.exists(target):
|
||||||
self.execute(os.unlink, (self.distinfo_dir,),
|
self.execute(os.unlink, (self.distinfo_dir,),
|
||||||
|
@ -85,12 +82,13 @@ class install_distinfo(Command):
|
||||||
self.execute(os.makedirs, (target,), "creating " + target)
|
self.execute(os.makedirs, (target,), "creating " + target)
|
||||||
|
|
||||||
metadata_path = os.path.join(self.distinfo_dir, 'METADATA')
|
metadata_path = os.path.join(self.distinfo_dir, 'METADATA')
|
||||||
logger.info('creating %s', metadata_path)
|
self.execute(self.distribution.metadata.write, (metadata_path,),
|
||||||
self.distribution.metadata.write(metadata_path)
|
"creating " + metadata_path)
|
||||||
self.outfiles.append(metadata_path)
|
self.outfiles.append(metadata_path)
|
||||||
|
|
||||||
installer_path = os.path.join(self.distinfo_dir, 'INSTALLER')
|
installer_path = os.path.join(self.distinfo_dir, 'INSTALLER')
|
||||||
logger.info('creating %s', installer_path)
|
logger.info('creating %s', installer_path)
|
||||||
|
if not self.dry_run:
|
||||||
with open(installer_path, 'w') as f:
|
with open(installer_path, 'w') as f:
|
||||||
f.write(self.installer)
|
f.write(self.installer)
|
||||||
self.outfiles.append(installer_path)
|
self.outfiles.append(installer_path)
|
||||||
|
@ -98,28 +96,30 @@ class install_distinfo(Command):
|
||||||
if self.requested:
|
if self.requested:
|
||||||
requested_path = os.path.join(self.distinfo_dir, 'REQUESTED')
|
requested_path = os.path.join(self.distinfo_dir, 'REQUESTED')
|
||||||
logger.info('creating %s', requested_path)
|
logger.info('creating %s', requested_path)
|
||||||
|
if not self.dry_run:
|
||||||
open(requested_path, 'wb').close()
|
open(requested_path, 'wb').close()
|
||||||
self.outfiles.append(requested_path)
|
self.outfiles.append(requested_path)
|
||||||
|
|
||||||
|
|
||||||
if not self.no_resources:
|
if not self.no_resources:
|
||||||
install_data = self.get_finalized_command('install_data')
|
install_data = self.get_finalized_command('install_data')
|
||||||
if install_data.get_resources_out() != []:
|
if install_data.get_resources_out() != []:
|
||||||
resources_path = os.path.join(self.distinfo_dir,
|
resources_path = os.path.join(self.distinfo_dir,
|
||||||
'RESOURCES')
|
'RESOURCES')
|
||||||
logger.info('creating %s', resources_path)
|
logger.info('creating %s', resources_path)
|
||||||
|
if not self.dry_run:
|
||||||
with open(resources_path, 'wb') as f:
|
with open(resources_path, 'wb') as f:
|
||||||
writer = csv.writer(f, delimiter=',',
|
writer = csv.writer(f, delimiter=',',
|
||||||
lineterminator='\n',
|
lineterminator='\n',
|
||||||
quotechar='"')
|
quotechar='"')
|
||||||
for tuple in install_data.get_resources_out():
|
for row in install_data.get_resources_out():
|
||||||
writer.writerow(tuple)
|
writer.writerow(row)
|
||||||
|
|
||||||
self.outfiles.append(resources_path)
|
self.outfiles.append(resources_path)
|
||||||
|
|
||||||
if not self.no_record:
|
if not self.no_record:
|
||||||
record_path = os.path.join(self.distinfo_dir, 'RECORD')
|
record_path = os.path.join(self.distinfo_dir, 'RECORD')
|
||||||
logger.info('creating %s', record_path)
|
logger.info('creating %s', record_path)
|
||||||
|
if not self.dry_run:
|
||||||
with open(record_path, 'w', encoding='utf-8') as f:
|
with open(record_path, 'w', encoding='utf-8') as f:
|
||||||
writer = csv.writer(f, delimiter=',',
|
writer = csv.writer(f, delimiter=',',
|
||||||
lineterminator='\n',
|
lineterminator='\n',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue