diff --git a/python/online/fxreader/pr34/commands.py b/python/online/fxreader/pr34/commands.py index c991081..9871644 100644 --- a/python/online/fxreader/pr34/commands.py +++ b/python/online/fxreader/pr34/commands.py @@ -4012,6 +4012,28 @@ class Command(enum.StrEnum): vpn = 'vpn' backup = 'backup' pip_resolve = 'pip_resolve' + pip_check_conflicts = 'pip_check_conflicts' + +def pip_check_conflicts( + args: list[str], +) -> None: + from .commands_typed.pip import pip_check_conflicts + from .commands_typed.argparse import parse_args as pr34_parse_args + parser = argparse.ArgumentParser() + parser.add_argument( + '-p', + dest='venv_path', + type=pathlib.Path, + help='venv path', + default=None, + ) + + options, argv = pr34_parse_args(parser, args) + + res = pip_check_conflicts(options.venv_path) + logger.info(dict(res=res)) + + assert res.status == 'ok' def pip_resolve( args: list[str], @@ -4154,6 +4176,8 @@ def commands_cli( desktop_services(args) elif options.command is Command.pip_resolve: pip_resolve(args) + elif options.command is Command.pip_check_conflicts: + pip_check_conflicts(args) elif options.command is Command.pm_service: pm_service(args) elif options.command is Command.backup: diff --git a/python/online/fxreader/pr34/commands_typed/pip.py b/python/online/fxreader/pr34/commands_typed/pip.py index 53419dd..23739bf 100644 --- a/python/online/fxreader/pr34/commands_typed/pip.py +++ b/python/online/fxreader/pr34/commands_typed/pip.py @@ -1,4 +1,5 @@ import contextlib +import glob import pathlib import sys import enum @@ -522,3 +523,42 @@ def pip_resolve( ) else: raise NotImplementedError + +class pip_check_conflicts_t: + @dataclasses.dataclass + class res_t: + status : Literal['ok', 'error'] + duplicates: list[str] + +def pip_check_conflicts( + venv_path: Optional[pathlib.Path] = None, +) -> pip_check_conflicts_t.res_t: + assert sys.platform == 'linux' + if venv_path is None: + venv_path = pathlib.Path( + sys.executable, + ).parent / '..' + + # records = glob.glob( + # str(venv_path / '*' / 'site-packages' / '*.dist-info' / 'RECORD'), + # recursive=True, + # ) + + duplicates = [ + line + for line in subprocess.check_output(r''' + cat $(find $VENV_PATH/lib/*/*/*.dist-info/RECORD) | sort | uniq -c | (grep -v -P '^\s+1\s'; true;) + ''', shell=True, env=dict( + VENV_PATH=str(venv_path), + )).decode('utf-8').splitlines() + if line.strip() != '' + ] + + return pip_check_conflicts_t.res_t( + status=( + 'error' + if len(duplicates) > 0 + else 'ok' + ), + duplicates=duplicates + ) diff --git a/python/pyproject.toml b/python/pyproject.toml index 6668525..9b3457f 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = 'online.fxreader.pr34' -version = '0.1.5.16+27.6' +version = '0.1.5.16+27.7' dependencies = [ #"-r requirements.txt", diff --git a/releases/whl/online_fxreader_pr34-0.1.5.16+27.7-py3-none-any.whl b/releases/whl/online_fxreader_pr34-0.1.5.16+27.7-py3-none-any.whl new file mode 100644 index 0000000..85091be --- /dev/null +++ b/releases/whl/online_fxreader_pr34-0.1.5.16+27.7-py3-none-any.whl @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57974bc5af7c567f214cd720c2e231ab8435f677fba3d997163989f6d254f712 +size 71536