From 3ad2549adc8f4a6997e5ddccbaae1d2ebb268930 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 3 Oct 2021 16:43:37 +0100 Subject: [PATCH] CLI: replace `pkg_resources` => `importlib` --- tqdm/cli.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tqdm/cli.py b/tqdm/cli.py index b5a16142..02653b2c 100644 --- a/tqdm/cli.py +++ b/tqdm/cli.py @@ -245,19 +245,20 @@ Options: if manpath or comppath: from os import path from shutil import copyfile + try: + from importlib import resources + except ImportError: # py<3.9 + import importlib_resources as resources - from pkg_resources import Requirement, resource_filename - - def cp(src, dst): - """copies from src path to dst""" - copyfile(src, dst) - log.info("written:" + dst) + def cp(name, dst): + """copy resource `name` to `dst`""" + with resources.path('tqdm', name) as src: + copyfile(src, dst) + log.info("written:%s", dst) if manpath is not None: - cp(resource_filename(Requirement.parse('tqdm'), 'tqdm/tqdm.1'), - path.join(manpath, 'tqdm.1')) + cp('tqdm.1', path.join(manpath, 'tqdm.1')) if comppath is not None: - cp(resource_filename(Requirement.parse('tqdm'), 'tqdm/completion.sh'), - path.join(comppath, 'tqdm_completion.sh')) + cp('completion.sh', path.join(comppath, 'tqdm_completion.sh')) sys.exit(0) if tee: stdout_write = stdout.write