Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/ducktools/pythonfinder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from ducktools.lazyimporter import LazyImporter, ModuleImport, FromImport
from ducktools.pythonfinder import list_python_installs, __version__
from ducktools.pythonfinder.shared import purge_caches

_laz = LazyImporter(
[
Expand Down Expand Up @@ -122,6 +123,11 @@ def get_parser():

subparsers = parser.add_subparsers(dest="command", required=False)

clear_cache = subparsers.add_parser(
"clear-cache",
help="Clear the cache of Python install details"
)

online = subparsers.add_parser(
"online",
help="Get links to binaries from python.org"
Expand Down Expand Up @@ -305,7 +311,9 @@ def main():
parser = get_parser()
vals = parser.parse_args(sys.argv[1:])

if vals.command == "online":
if vals.command == "clear-cache":
purge_caches()
elif vals.command == "online":
system = vals.system if vals.system else _laz.platform.system()
machine = vals.machine if vals.machine else _laz.platform.machine()
try:
Expand Down
5 changes: 5 additions & 0 deletions src/ducktools/pythonfinder/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
ModuleImport("json"),
ModuleImport("platform"),
ModuleImport("re"),
ModuleImport("shutil"),
ModuleImport("subprocess"),
ModuleImport("tempfile"),
ModuleImport("zipfile"),
Expand Down Expand Up @@ -84,6 +85,10 @@
INSTALLER_CACHE_PATH = os.path.join(CACHE_FOLDER, "installer_details.json")


def purge_caches(cache_folder=CACHE_FOLDER):
_laz.shutil.rmtree(cache_folder, ignore_errors=True)


def version_str_to_tuple(version):
parsed_version = _laz.re.fullmatch(FULL_PY_VER_RE, version)

Expand Down
Loading