2011-05-19 08:07:25 -03:00
|
|
|
"""Create the PEP 376-compliant .dist-info directory."""
|
|
|
|
|
|
|
|
# Forked from the former install_egg_info command by Josip Djolonga
|
|
|
|
|
|
|
|
import os
|
2011-09-16 22:31:51 -03:00
|
|
|
import csv
|
2011-05-19 08:07:25 -03:00
|
|
|
import hashlib
|
2011-09-16 22:31:51 -03:00
|
|
|
from shutil import rmtree
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
from packaging import logger
|
2011-09-16 22:31:51 -03:00
|
|
|
from packaging.command.cmd import Command
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
|
|
|
|
class install_distinfo(Command):
|
|
|
|
|
|
|
|
description = 'create a .dist-info directory for the distribution'
|
|
|
|
|
|
|
|
user_options = [
|
2011-11-06 06:52:30 -04:00
|
|
|
('install-dir=', None,
|
|
|
|
"directory where the the .dist-info directory will be created"),
|
2011-05-19 08:07:25 -03:00
|
|
|
('installer=', None,
|
|
|
|
"the name of the installer"),
|
|
|
|
('requested', None,
|
|
|
|
"generate a REQUESTED file"),
|
|
|
|
('no-requested', None,
|
|
|
|
"do not generate a REQUESTED file"),
|
|
|
|
('no-record', None,
|
|
|
|
"do not generate a RECORD file"),
|
|
|
|
('no-resources', None,
|
2011-09-18 15:36:19 -03:00
|
|
|
"do not generate a RESOURCES file"),
|
2011-05-19 08:07:25 -03:00
|
|
|
]
|
|
|
|
|
|
|
|
boolean_options = ['requested', 'no-record', 'no-resources']
|
|
|
|
|
|
|
|
negative_opt = {'no-requested': 'requested'}
|
|
|
|
|
|
|
|
def initialize_options(self):
|
2011-11-06 06:52:30 -04:00
|
|
|
self.install_dir = None
|
2011-05-19 08:07:25 -03:00
|
|
|
self.installer = None
|
|
|
|
self.requested = None
|
|
|
|
self.no_record = None
|
|
|
|
self.no_resources = None
|
2011-08-20 04:19:25 -03:00
|
|
|
self.outfiles = []
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
self.set_undefined_options('install_dist',
|
|
|
|
'installer', 'requested', 'no_record')
|
|
|
|
|
2011-11-06 06:52:30 -04:00
|
|
|
self.set_undefined_options('install_lib', 'install_dir')
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
if self.installer is None:
|
|
|
|
# FIXME distutils or packaging?
|
|
|
|
# + document default in the option help text above and in install
|
|
|
|
self.installer = 'distutils'
|
|
|
|
if self.requested is None:
|
|
|
|
self.requested = True
|
|
|
|
if self.no_record is None:
|
|
|
|
self.no_record = False
|
|
|
|
if self.no_resources is None:
|
|
|
|
self.no_resources = False
|
|
|
|
|
|
|
|
metadata = self.distribution.metadata
|
|
|
|
|
2011-09-12 14:12:42 -03:00
|
|
|
basename = metadata.get_fullname(filesafe=True) + ".dist-info"
|
2011-05-19 08:07:25 -03:00
|
|
|
|
2011-11-06 06:52:30 -04:00
|
|
|
self.install_dir = os.path.join(self.install_dir, basename)
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
def run(self):
|
2011-11-06 06:52:30 -04:00
|
|
|
target = self.install_dir
|
2011-05-19 08:07:25 -03:00
|
|
|
|
2011-09-10 13:10:23 -03:00
|
|
|
if os.path.isdir(target) and not os.path.islink(target):
|
|
|
|
if not self.dry_run:
|
2011-05-19 08:07:25 -03:00
|
|
|
rmtree(target)
|
2011-09-10 13:10:23 -03:00
|
|
|
elif os.path.exists(target):
|
2011-11-06 06:52:30 -04:00
|
|
|
self.execute(os.unlink, (self.install_dir,),
|
2011-09-10 13:10:23 -03:00
|
|
|
"removing " + target)
|
2011-05-19 08:07:25 -03:00
|
|
|
|
2011-09-10 13:10:23 -03:00
|
|
|
self.execute(os.makedirs, (target,), "creating " + target)
|
2011-05-19 08:07:25 -03:00
|
|
|
|
2011-11-06 06:52:30 -04:00
|
|
|
metadata_path = os.path.join(self.install_dir, 'METADATA')
|
2011-09-10 13:10:23 -03:00
|
|
|
self.execute(self.distribution.metadata.write, (metadata_path,),
|
|
|
|
"creating " + metadata_path)
|
|
|
|
self.outfiles.append(metadata_path)
|
2011-05-19 08:07:25 -03:00
|
|
|
|
2011-11-06 06:52:30 -04:00
|
|
|
installer_path = os.path.join(self.install_dir, 'INSTALLER')
|
2011-09-10 13:10:23 -03:00
|
|
|
logger.info('creating %s', installer_path)
|
|
|
|
if not self.dry_run:
|
2011-05-19 08:07:25 -03:00
|
|
|
with open(installer_path, 'w') as f:
|
|
|
|
f.write(self.installer)
|
2011-09-10 13:10:23 -03:00
|
|
|
self.outfiles.append(installer_path)
|
2011-05-19 08:07:25 -03:00
|
|
|
|
2011-09-10 13:10:23 -03:00
|
|
|
if self.requested:
|
2011-11-06 06:52:30 -04:00
|
|
|
requested_path = os.path.join(self.install_dir, 'REQUESTED')
|
2011-09-10 13:10:23 -03:00
|
|
|
logger.info('creating %s', requested_path)
|
|
|
|
if not self.dry_run:
|
2011-05-19 10:52:59 -03:00
|
|
|
open(requested_path, 'wb').close()
|
2011-09-10 13:10:23 -03:00
|
|
|
self.outfiles.append(requested_path)
|
|
|
|
|
|
|
|
if not self.no_resources:
|
|
|
|
install_data = self.get_finalized_command('install_data')
|
|
|
|
if install_data.get_resources_out() != []:
|
2011-11-06 06:52:30 -04:00
|
|
|
resources_path = os.path.join(self.install_dir,
|
2011-09-10 13:10:23 -03:00
|
|
|
'RESOURCES')
|
|
|
|
logger.info('creating %s', resources_path)
|
|
|
|
if not self.dry_run:
|
2011-10-14 11:58:23 -03:00
|
|
|
with open(resources_path, 'w') as f:
|
2011-05-19 08:07:25 -03:00
|
|
|
writer = csv.writer(f, delimiter=',',
|
2011-05-21 14:45:48 -03:00
|
|
|
lineterminator='\n',
|
2011-05-19 08:07:25 -03:00
|
|
|
quotechar='"')
|
2011-09-10 13:10:23 -03:00
|
|
|
for row in install_data.get_resources_out():
|
|
|
|
writer.writerow(row)
|
2011-05-19 08:07:25 -03:00
|
|
|
|
2011-09-10 13:10:23 -03:00
|
|
|
self.outfiles.append(resources_path)
|
2011-05-19 08:07:25 -03:00
|
|
|
|
2011-09-10 13:10:23 -03:00
|
|
|
if not self.no_record:
|
2011-11-06 06:52:30 -04:00
|
|
|
record_path = os.path.join(self.install_dir, 'RECORD')
|
2011-09-10 13:10:23 -03:00
|
|
|
logger.info('creating %s', record_path)
|
|
|
|
if not self.dry_run:
|
2011-05-19 08:07:25 -03:00
|
|
|
with open(record_path, 'w', encoding='utf-8') as f:
|
|
|
|
writer = csv.writer(f, delimiter=',',
|
2011-05-21 14:45:48 -03:00
|
|
|
lineterminator='\n',
|
2011-05-19 08:07:25 -03:00
|
|
|
quotechar='"')
|
|
|
|
|
|
|
|
install = self.get_finalized_command('install_dist')
|
|
|
|
|
|
|
|
for fpath in install.get_outputs():
|
|
|
|
if fpath.endswith('.pyc') or fpath.endswith('.pyo'):
|
|
|
|
# do not put size and md5 hash, as in PEP-376
|
|
|
|
writer.writerow((fpath, '', ''))
|
|
|
|
else:
|
|
|
|
size = os.path.getsize(fpath)
|
2011-05-19 10:09:57 -03:00
|
|
|
with open(fpath, 'rb') as fp:
|
2011-05-19 08:07:25 -03:00
|
|
|
hash = hashlib.md5()
|
2011-05-19 10:09:57 -03:00
|
|
|
hash.update(fp.read())
|
2011-05-19 08:07:25 -03:00
|
|
|
md5sum = hash.hexdigest()
|
|
|
|
writer.writerow((fpath, md5sum, size))
|
|
|
|
|
|
|
|
# add the RECORD file itself
|
|
|
|
writer.writerow((record_path, '', ''))
|
2011-09-10 13:10:23 -03:00
|
|
|
self.outfiles.append(record_path)
|
2011-05-19 08:07:25 -03:00
|
|
|
|
|
|
|
def get_outputs(self):
|
2011-08-20 04:19:25 -03:00
|
|
|
return self.outfiles
|