File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
src/ducktools/pythonfinder Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 2828
2929from ducktools .lazyimporter import LazyImporter , ModuleImport , FromImport
3030from ducktools .pythonfinder import list_python_installs , __version__
31+ from ducktools .pythonfinder .shared import purge_caches
3132
3233_laz = LazyImporter (
3334 [
@@ -122,6 +123,11 @@ def get_parser():
122123
123124 subparsers = parser .add_subparsers (dest = "command" , required = False )
124125
126+ clear_cache = subparsers .add_parser (
127+ "clear-cache" ,
128+ help = "Clear the cache of Python install details"
129+ )
130+
125131 online = subparsers .add_parser (
126132 "online" ,
127133 help = "Get links to binaries from python.org"
@@ -305,7 +311,9 @@ def main():
305311 parser = get_parser ()
306312 vals = parser .parse_args (sys .argv [1 :])
307313
308- if vals .command == "online" :
314+ if vals .command == "clear-cache" :
315+ purge_caches ()
316+ elif vals .command == "online" :
309317 system = vals .system if vals .system else _laz .platform .system ()
310318 machine = vals .machine if vals .machine else _laz .platform .machine ()
311319 try :
Original file line number Diff line number Diff line change 3939 ModuleImport ("json" ),
4040 ModuleImport ("platform" ),
4141 ModuleImport ("re" ),
42+ ModuleImport ("shutil" ),
4243 ModuleImport ("subprocess" ),
4344 ModuleImport ("tempfile" ),
4445 ModuleImport ("zipfile" ),
8485INSTALLER_CACHE_PATH = os .path .join (CACHE_FOLDER , "installer_details.json" )
8586
8687
88+ def purge_caches (cache_folder = CACHE_FOLDER ):
89+ _laz .shutil .rmtree (cache_folder , ignore_errors = True )
90+
91+
8792def version_str_to_tuple (version ):
8893 parsed_version = _laz .re .fullmatch (FULL_PY_VER_RE , version )
8994
You can’t perform that action at this time.
0 commit comments