Skip to content

Commit 3c54ba6

Browse files
committed
Use Python packaging version parser
Was doing my own version compare but ultimately not robust enough.
1 parent 3860223 commit 3c54ba6

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ https://github.com/bulletmark/debugpy-run.
5353
Arch users can install [debugpy-run from the
5454
AUR](https://aur.archlinux.org/packages/debugpy-run/).
5555

56-
Python 3.6 or later is required. Note [debugpy-run is on
57-
PyPI](https://pypi.org/project/debugpy-run/) so just ensure that
58-
`python3-pip` and `python3-wheel` are installed then type the following
59-
to install (or upgrade):
56+
Python 3.6 or later is required. Also, the Python
57+
[packaging](https://pypi.org/project/packaging/) module is required.
58+
Note [debugpy-run is on PyPI](https://pypi.org/project/debugpy-run/) so
59+
just ensure that `python3-pip` and `python3-wheel` are installed then
60+
type the following to install (or upgrade):
6061

6162
```
6263
$ sudo pip3 install -U debugpy-run

debugpy_run.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
import subprocess
1313
import re
1414
from pathlib import Path
15+
from packaging import version
16+
1517

1618
PROG = 'debugpy'
19+
EXTNAME = 'ms-python.python'
1720

1821
def find_ext_debugger():
1922
'Find where debugger is located in extensions'
2023
pdirs = list(Path('~').expanduser().glob(
21-
'.vscode*/extensions/ms-python.python-*'))
24+
f'.vscode*/extensions/{EXTNAME}-*'))
2225

26+
# Filter out to dirs only
2327
if pdirs:
2428
pdirs = [d for d in pdirs if d.is_dir()]
2529

@@ -28,9 +32,9 @@ def find_ext_debugger():
2832

2933
def sortdir(val):
3034
'Calculate a sort hash for given dir'
31-
valstr = re.sub(r'^.*?([0-9])', r'\1', str(val))
32-
v = valstr.split('.', maxsplit=3)
33-
return f'{v[0]}.{int(v[1]):02}.{v[2]}'
35+
sval = re.sub(f'^.*/{EXTNAME}-', '', str(val))
36+
sval = re.sub('/.*$', '', sval)
37+
return version.parse(sval)
3438

3539
extdir = sorted(pdirs, reverse=True, key=sortdir)[0]
3640
pkg = extdir / f'pythonFiles/lib/python/{PROG}'

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setup(
1313
name=name,
14-
version='1.5',
14+
version='1.5.1',
1515
description='Finds and runs debugpy for VS Code "remote attach" '
1616
'command line debugging.',
1717
long_description=here.joinpath('README.md').read_text(),
@@ -23,6 +23,7 @@
2323
license='GPLv3',
2424
py_modules=[module],
2525
python_requires='>=3.6',
26+
install_requires=['packaging'],
2627
classifiers=[
2728
'Programming Language :: Python :: 3',
2829
],

0 commit comments

Comments
 (0)