2 Create a dist_info directory
3 As defined in the wheel specification
9 from contextlib
import contextmanager
10 from distutils
import log
11 from distutils
.core
import Command
12 from pathlib
import Path
14 from .. import _normalization
15 from ..warnings
import SetuptoolsDeprecationWarning
18 class dist_info(Command
):
20 This command is private and reserved for internal use of setuptools,
21 users should rely on ``setuptools.build_meta`` APIs.
24 description
= "DO NOT CALL DIRECTLY, INTERNAL ONLY: create .dist-info directory"
30 "directory containing .egg-info directories"
31 " (default: top of the source tree)"
32 " DEPRECATED: use --output-dir.",
37 "directory inside of which the .dist-info will be"
38 "created (default: top of the source tree)",
40 ('tag-date', 'd', "Add date stamp (e.g. 20050528) to version number"),
41 ('tag-build=', 'b', "Specify explicit tag to add to version number"),
42 ('no-date', 'D', "Don't include date stamp [default]"),
43 ('keep-egg-info', None, "*TRANSITIONAL* will be removed in the future"),
46 boolean_options
= ['tag-date', 'keep-egg-info']
47 negative_opt
= {'no-date': 'tag-date'}
49 def initialize_options(self
):
51 self
.output_dir
= None
53 self
.dist_info_dir
= None
56 self
.keep_egg_info
= False
58 def finalize_options(self
):
60 msg
= "--egg-base is deprecated for dist_info command. Use --output-dir."
61 SetuptoolsDeprecationWarning
.emit(msg
, due_date
=(2023, 9, 26))
62 # This command is internal to setuptools, therefore it should be safe
63 # to remove the deprecated support soon.
64 self
.output_dir
= self
.egg_base
or self
.output_dir
66 dist
= self
.distribution
67 project_dir
= dist
.src_root
or os
.curdir
68 self
.output_dir
= Path(self
.output_dir
or project_dir
)
70 egg_info
= self
.reinitialize_command("egg_info")
71 egg_info
.egg_base
= str(self
.output_dir
)
74 egg_info
.tag_date
= self
.tag_date
76 self
.tag_date
= egg_info
.tag_date
79 egg_info
.tag_build
= self
.tag_build
81 self
.tag_build
= egg_info
.tag_build
83 egg_info
.finalize_options()
84 self
.egg_info
= egg_info
86 name
= _normalization
.safer_name(dist
.get_name())
87 version
= _normalization
.safer_best_effort_version(dist
.get_version())
88 self
.name
= f
"{name}-{version}"
89 self
.dist_info_dir
= os
.path
.join(self
.output_dir
, f
"{self.name}.dist-info")
92 def _maybe_bkp_dir(self
, dir_path
: str, requires_bkp
: bool):
94 bkp_name
= f
"{dir_path}.__bkp__"
95 _rm(bkp_name
, ignore_errors
=True)
96 _copy(dir_path
, bkp_name
, dirs_exist_ok
=True, symlinks
=True)
100 _rm(dir_path
, ignore_errors
=True)
101 shutil
.move(bkp_name
, dir_path
)
106 self
.output_dir
.mkdir(parents
=True, exist_ok
=True)
108 egg_info_dir
= self
.egg_info
.egg_info
109 assert os
.path
.isdir(egg_info_dir
), ".egg-info dir should have been created"
111 log
.info("creating '{}'".format(os
.path
.abspath(self
.dist_info_dir
)))
112 bdist_wheel
= self
.get_finalized_command('bdist_wheel')
114 # TODO: if bdist_wheel if merged into setuptools, just add "keep_egg_info" there
115 with self
._maybe
_bkp
_dir
(egg_info_dir
, self
.keep_egg_info
):
116 bdist_wheel
.egg2dist(egg_info_dir
, self
.dist_info_dir
)
119 def _rm(dir_name
, **opts
):
120 if os
.path
.isdir(dir_name
):
121 shutil
.rmtree(dir_name
, **opts
)
124 def _copy(src
, dst
, **opts
):
125 if sys
.version_info
< (3, 8):
126 opts
.pop("dirs_exist_ok", None)
127 shutil
.copytree(src
, dst
, **opts
)