From 84964ed5aebfef295ba2a7fdf508b532b432fa20 Mon Sep 17 00:00:00 2001 From: Rodja Trappe Date: Fri, 20 Oct 2023 06:54:26 +0200 Subject: [PATCH 1/3] allow parsing of code-workspaces which have // --- livesync/livesync.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/livesync/livesync.py b/livesync/livesync.py index 18344a0..f692049 100755 --- a/livesync/livesync.py +++ b/livesync/livesync.py @@ -2,6 +2,7 @@ import argparse import asyncio import json +import re import sys from pathlib import Path from typing import List @@ -27,7 +28,11 @@ async def async_main() -> None: folders: List[Folder] = [] if source.is_file(): - workspace = json.loads(source.read_text()) + try: + workspace = json.loads(re.sub(r'//.*', '', source.read_text())) + except json.JSONDecodeError: + print(f'Could not parse vscode workspace file: {source}') + sys.exit(1) paths = [Path(f['path']) for f in workspace['folders']] folders = [Folder(p, target) for p in paths if p.is_dir()] else: From 1ab254af11b71152755b4879a8a9ec6f3770c6de Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Thu, 26 Oct 2023 19:37:21 +0200 Subject: [PATCH 2/3] Revert "allow parsing of code-workspaces which have //" This reverts commit 84964ed5aebfef295ba2a7fdf508b532b432fa20. --- livesync/livesync.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/livesync/livesync.py b/livesync/livesync.py index f692049..18344a0 100755 --- a/livesync/livesync.py +++ b/livesync/livesync.py @@ -2,7 +2,6 @@ import argparse import asyncio import json -import re import sys from pathlib import Path from typing import List @@ -28,11 +27,7 @@ async def async_main() -> None: folders: List[Folder] = [] if source.is_file(): - try: - workspace = json.loads(re.sub(r'//.*', '', source.read_text())) - except json.JSONDecodeError: - print(f'Could not parse vscode workspace file: {source}') - sys.exit(1) + workspace = json.loads(source.read_text()) paths = [Path(f['path']) for f in workspace['folders']] folders = [Folder(p, target) for p in paths if p.is_dir()] else: From 3e44cdced9f30452926817c9de98aa0c0608d04d Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Thu, 26 Oct 2023 19:39:19 +0200 Subject: [PATCH 3/3] use pyjson5 for parsing workspace files with comments --- livesync/livesync.py | 5 +++-- requirements.txt | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/livesync/livesync.py b/livesync/livesync.py index 18344a0..0c4ca65 100755 --- a/livesync/livesync.py +++ b/livesync/livesync.py @@ -1,11 +1,12 @@ #!/usr/bin/env python3 import argparse import asyncio -import json import sys from pathlib import Path from typing import List +import pyjson5 + from livesync import Folder, Mutex, Target @@ -27,7 +28,7 @@ async def async_main() -> None: folders: List[Folder] = [] if source.is_file(): - workspace = json.loads(source.read_text()) + workspace = pyjson5.decode(source.read_text()) paths = [Path(f['path']) for f in workspace['folders']] folders = [Folder(p, target) for p in paths if p.is_dir()] else: diff --git a/requirements.txt b/requirements.txt index 2bd9cfd..03334cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ +pathspec +pyjson5 watchfiles -pathspec \ No newline at end of file