7
7
import shutil
8
8
from distutils import log
9
9
from distutils .core import Command
10
+ from distutils import dir_util # prefer dir_util for log/cache consistency
10
11
from pathlib import Path
11
12
12
13
from .. import _normalization
@@ -41,9 +42,10 @@ class dist_info(Command):
41
42
('tag-build=' , 'b' , "Specify explicit tag to add to version number" ),
42
43
('no-date' , 'D' , "Don't include date stamp [default]" ),
43
44
('keep-egg-info' , None , "*TRANSITIONAL* will be removed in the future" ),
45
+ ('use-cached' , None , "*TRANSITIONAL* will be removed in the future" ),
44
46
]
45
47
46
- boolean_options = ['tag-date' , 'keep-egg-info' ]
48
+ boolean_options = ['tag-date' , 'keep-egg-info' , 'use-cached' ]
47
49
negative_opt = {'no-date' : 'tag-date' }
48
50
49
51
def initialize_options (self ):
@@ -54,6 +56,7 @@ def initialize_options(self):
54
56
self .tag_date = None
55
57
self .tag_build = None
56
58
self .keep_egg_info = False
59
+ self .use_cached = False
57
60
58
61
def finalize_options (self ):
59
62
if self .egg_base :
@@ -90,7 +93,10 @@ def _sync_tag_details(self, egg_info):
90
93
self .tag_build = egg_info .tag_build
91
94
92
95
def run (self ):
93
- self .output_dir .mkdir (parents = True , exist_ok = True )
96
+ if self .use_cached and (self .dist_info_dir / "METADATA" ).is_file ():
97
+ return
98
+
99
+ self .mkpath (str (self .output_dir ))
94
100
self .egg_info .run ()
95
101
egg_info_dir = Path (self .egg_info .egg_info )
96
102
dist_info_dir = self .dist_info_dir
@@ -103,18 +109,17 @@ def run(self):
103
109
# METADATA, entry-points.txt
104
110
shutil .copytree (egg_info_dir , dist_info_dir , ignore = lambda _ , __ : _IGNORE )
105
111
metadata_file = dist_info_dir / "METADATA"
106
- shutil .copy2 (egg_info_dir / "PKG-INFO" , metadata_file )
107
- log .debug (f"creating { str (os .path .abspath (metadata_file ))!r} " )
112
+ self .copy_file (egg_info_dir / "PKG-INFO" , metadata_file )
108
113
if self .distribution .dependency_links :
109
- shutil . copy2 (egg_info_dir / "dependency_links.txt" , dist_info_dir )
114
+ self . copy_file (egg_info_dir / "dependency_links.txt" , dist_info_dir )
110
115
111
116
for dest , orig in self ._license_paths ():
112
117
dest = dist_info_dir / dest
113
- dest .parent . mkdir ( exist_ok = True , parents = True )
114
- shutil . copy2 (orig , dest )
118
+ self . mkpath ( str ( dest .parent ) )
119
+ self . copy_file (orig , dest )
115
120
116
121
if not self .keep_egg_info :
117
- shutil . rmtree (egg_info_dir )
122
+ dir_util . remove_tree (egg_info_dir , self . verbose , self . dry_run )
118
123
119
124
def _license_paths (self ):
120
125
for file in (self .distribution .metadata .license_files or ()):
0 commit comments