Path: blob/main/test/lib/python3.9/site-packages/setuptools/command/dist_info.py
4799 views
"""1Create a dist_info directory2As defined in the wheel specification3"""45import os6import re7import warnings8from inspect import cleandoc910from distutils.core import Command11from distutils import log12from setuptools.extern import packaging131415class dist_info(Command):1617description = 'create a .dist-info directory'1819user_options = [20('egg-base=', 'e', "directory containing .egg-info directories"21" (default: top of the source tree)"),22]2324def initialize_options(self):25self.egg_base = None2627def finalize_options(self):28pass2930def run(self):31egg_info = self.get_finalized_command('egg_info')32egg_info.egg_base = self.egg_base33egg_info.finalize_options()34egg_info.run()35name = _safe(self.distribution.get_name())36version = _version(self.distribution.get_version())37base = self.egg_base or os.curdir38dist_info_dir = os.path.join(base, f"{name}-{version}.dist-info")39log.info("creating '{}'".format(os.path.abspath(dist_info_dir)))4041bdist_wheel = self.get_finalized_command('bdist_wheel')42bdist_wheel.egg2dist(egg_info.egg_info, dist_info_dir)434445def _safe(component: str) -> str:46"""Escape a component used to form a wheel name according to PEP 491"""47return re.sub(r"[^\w\d.]+", "_", component)484950def _version(version: str) -> str:51"""Convert an arbitrary string to a version string."""52v = version.replace(' ', '.')53try:54return str(packaging.version.Version(v)).replace("-", "_")55except packaging.version.InvalidVersion:56msg = f"""Invalid version: {version!r}.57!!\n\n58###################59# Invalid version #60###################61{version!r} is not valid according to PEP 440.\n62Please make sure specify a valid version for your package.63Also note that future releases of setuptools may halt the build process64if an invalid version is given.65\n\n!!66"""67warnings.warn(cleandoc(msg))68return _safe(v).strip("_")697071