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
@@ -49,9 +50,10 @@ class dist_info(Command):
49
50
('tag-build=' , 'b' , "Specify explicit tag to add to version number" ),
50
51
('no-date' , 'D' , "Don't include date stamp [default]" ),
51
52
('keep-egg-info' , None , "*TRANSITIONAL* will be removed in the future" ),
53
+ ('use-cached' , None , "*TRANSITIONAL* will be removed in the future" ),
52
54
]
53
55
54
- boolean_options = ['tag-date' , 'keep-egg-info' ]
56
+ boolean_options = ['tag-date' , 'keep-egg-info' , 'use-cached' ]
55
57
negative_opt = {'no-date' : 'tag-date' }
56
58
57
59
def initialize_options (self ):
@@ -62,6 +64,7 @@ def initialize_options(self):
62
64
self .tag_date = None
63
65
self .tag_build = None
64
66
self .keep_egg_info = False
67
+ self .use_cached = False
65
68
66
69
def finalize_options (self ):
67
70
if self .egg_base :
@@ -98,7 +101,10 @@ def _sync_tag_details(self, egg_info):
98
101
self .tag_build = egg_info .tag_build
99
102
100
103
def run (self ):
101
- self .output_dir .mkdir (parents = True , exist_ok = True )
104
+ if self .use_cached and (self .dist_info_dir / "METADATA" ).is_file ():
105
+ return
106
+
107
+ self .mkpath (str (self .output_dir ))
102
108
self .egg_info .run ()
103
109
egg_info_dir = Path (self .egg_info .egg_info )
104
110
dist_info_dir = self .dist_info_dir
@@ -111,18 +117,17 @@ def run(self):
111
117
# METADATA, entry-points.txt
112
118
shutil .copytree (egg_info_dir , dist_info_dir , ignore = lambda _ , __ : _IGNORE )
113
119
metadata_file = dist_info_dir / "METADATA"
114
- shutil .copy2 (egg_info_dir / "PKG-INFO" , metadata_file )
115
- log .debug (f"creating { str (os .path .abspath (metadata_file ))!r} " )
120
+ self .copy_file (egg_info_dir / "PKG-INFO" , metadata_file )
116
121
if self .distribution .dependency_links :
117
- shutil . copy2 (egg_info_dir / "dependency_links.txt" , dist_info_dir )
122
+ self . copy_file (egg_info_dir / "dependency_links.txt" , dist_info_dir )
118
123
119
124
for dest , orig in self ._license_paths ():
120
125
dest = dist_info_dir / dest
121
- dest .parent . mkdir ( exist_ok = True , parents = True )
122
- shutil . copy2 (orig , dest )
126
+ self . mkpath ( str ( dest .parent ) )
127
+ self . copy_file (orig , dest )
123
128
124
129
if not self .keep_egg_info :
125
- shutil . rmtree (egg_info_dir )
130
+ dir_util . remove_tree (egg_info_dir , self . verbose , self . dry_run )
126
131
127
132
def _license_paths (self ):
128
133
for file in self .distribution .metadata .license_files or ():
0 commit comments