CLI: replace `pkg_resources` => `importlib`

This commit is contained in:
Casper da Costa-Luis 2021-10-03 16:43:37 +01:00
parent eae707752c
commit 3ad2549adc
No known key found for this signature in database
GPG Key ID: F5126E5FBD2512AD
1 changed files with 11 additions and 10 deletions

View File

@ -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