]> jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/setuptools/command/dist_info.py
init: venv aand flask
[dlqueue.git] / venv / lib / python3.11 / site-packages / setuptools / command / dist_info.py
1 """
2 Create a dist_info directory
3 As defined in the wheel specification
4 """
5
6 import os
7 import shutil
8 import sys
9 from contextlib import contextmanager
10 from distutils import log
11 from distutils.core import Command
12 from pathlib import Path
13
14 from .. import _normalization
15 from ..warnings import SetuptoolsDeprecationWarning
16
17
18 class dist_info(Command):
19 """
20 This command is private and reserved for internal use of setuptools,
21 users should rely on ``setuptools.build_meta`` APIs.
22 """
23
24 description = "DO NOT CALL DIRECTLY, INTERNAL ONLY: create .dist-info directory"
25
26 user_options = [
27 (
28 'egg-base=',
29 'e',
30 "directory containing .egg-info directories"
31 " (default: top of the source tree)"
32 " DEPRECATED: use --output-dir.",
33 ),
34 (
35 'output-dir=',
36 'o',
37 "directory inside of which the .dist-info will be"
38 "created (default: top of the source tree)",
39 ),
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"),
44 ]
45
46 boolean_options = ['tag-date', 'keep-egg-info']
47 negative_opt = {'no-date': 'tag-date'}
48
49 def initialize_options(self):
50 self.egg_base = None
51 self.output_dir = None
52 self.name = None
53 self.dist_info_dir = None
54 self.tag_date = None
55 self.tag_build = None
56 self.keep_egg_info = False
57
58 def finalize_options(self):
59 if self.egg_base:
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
65
66 dist = self.distribution
67 project_dir = dist.src_root or os.curdir
68 self.output_dir = Path(self.output_dir or project_dir)
69
70 egg_info = self.reinitialize_command("egg_info")
71 egg_info.egg_base = str(self.output_dir)
72
73 if self.tag_date:
74 egg_info.tag_date = self.tag_date
75 else:
76 self.tag_date = egg_info.tag_date
77
78 if self.tag_build:
79 egg_info.tag_build = self.tag_build
80 else:
81 self.tag_build = egg_info.tag_build
82
83 egg_info.finalize_options()
84 self.egg_info = egg_info
85
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")
90
91 @contextmanager
92 def _maybe_bkp_dir(self, dir_path: str, requires_bkp: bool):
93 if requires_bkp:
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)
97 try:
98 yield
99 finally:
100 _rm(dir_path, ignore_errors=True)
101 shutil.move(bkp_name, dir_path)
102 else:
103 yield
104
105 def run(self):
106 self.output_dir.mkdir(parents=True, exist_ok=True)
107 self.egg_info.run()
108 egg_info_dir = self.egg_info.egg_info
109 assert os.path.isdir(egg_info_dir), ".egg-info dir should have been created"
110
111 log.info("creating '{}'".format(os.path.abspath(self.dist_info_dir)))
112 bdist_wheel = self.get_finalized_command('bdist_wheel')
113
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)
117
118
119 def _rm(dir_name, **opts):
120 if os.path.isdir(dir_name):
121 shutil.rmtree(dir_name, **opts)
122
123
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)