Skip to content

Commit c77994b

Browse files
committed
progress
1 parent 041be0d commit c77994b

File tree

8 files changed

+303
-188
lines changed

8 files changed

+303
-188
lines changed

noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def install_python_libs(session: nox.Session):
5353
)
5454

5555
session.install("packaging")
56+
session.install("debugpy")
5657

5758
# Download get-pip script
5859
session.run(

python_files/testing_tools/socket_manager.py

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,26 @@ def __exit__(self, *_):
2020
self.close()
2121

2222
def connect(self):
23-
if sys.platform == "win32":
24-
self._writer = open(self.name, "w", encoding="utf-8") # noqa: SIM115, PTH123
25-
# reader created in read method
26-
else:
27-
self._socket = _SOCKET(socket.AF_UNIX, socket.SOCK_STREAM)
28-
self._socket.connect(self.name)
23+
self._writer = open(self.name, "w", encoding="utf-8") # noqa: SIM115, PTH123
24+
# reader created in read method
2925
return self
3026

3127
def close(self):
32-
if sys.platform == "win32":
33-
self._writer.close()
34-
else:
35-
# add exception catch
36-
self._socket.close()
28+
self._writer.close()
29+
self._reader.close()
3730

3831
def write(self, data: str):
39-
if sys.platform == "win32":
40-
try:
41-
# for windows, is should only use \n\n
42-
request = (
43-
f"""content-length: {len(data)}\ncontent-type: application/json\n\n{data}"""
44-
)
45-
self._writer.write(request)
46-
self._writer.flush()
47-
except Exception as e:
48-
print("error attempting to write to pipe", e)
49-
raise (e)
50-
else:
51-
# must include the carriage-return defined (as \r\n) for unix systems
32+
33+
try:
34+
# for windows, is should only use \n\n
5235
request = (
53-
f"""content-length: {len(data)}\r\ncontent-type: application/json\r\n\r\n{data}"""
36+
f"""content-length: {len(data)}\ncontent-type: application/json\n\n{data}"""
5437
)
55-
self._socket.send(request.encode("utf-8"))
38+
self._writer.write(request)
39+
self._writer.flush()
40+
except Exception as e:
41+
print("error attempting to write to pipe", e)
42+
raise (e)
5643

5744
def read(self, bufsize=1024) -> str:
5845
"""Read data from the socket.
@@ -63,17 +50,10 @@ def read(self, bufsize=1024) -> str:
6350
Returns:
6451
data (str): Data received from the socket.
6552
"""
66-
if sys.platform == "win32":
67-
# returns a string automatically from read
68-
if not hasattr(self, "_reader"):
69-
self._reader = open(self.name, encoding="utf-8") # noqa: SIM115, PTH123
70-
return self._reader.read(bufsize)
71-
else:
72-
# receive bytes and convert to string
73-
while True:
74-
part: bytes = self._socket.recv(bufsize)
75-
data: str = part.decode("utf-8")
76-
return data
53+
# returns a string automatically from read
54+
if not hasattr(self, "_reader"):
55+
self._reader = open(self.name, encoding="utf-8") # noqa: SIM115, PTH123
56+
return self._reader.read(bufsize)
7757

7858

7959
class SocketManager:

python_files/tests/pytestadapter/helpers.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ def parse_rpc_message(data: str) -> Tuple[Dict[str, str], str]:
128128
print("json decode error")
129129

130130

131+
def _listen_on_fifo(pipe_name: str, result: List[str], completed: threading.Event):
132+
# Open the FIFO for reading
133+
with open(pipe_name) as fifo:
134+
print("Waiting for data...")
135+
while True:
136+
if completed.is_set():
137+
break # Exit loop if completed event is set
138+
data = fifo.read() # This will block until data is available
139+
if len(data) == 0:
140+
# If data is empty, assume EOF
141+
break
142+
print(f"Received: {data}")
143+
result.append(data)
144+
145+
131146
def _listen_on_pipe_new(listener, result: List[str], completed: threading.Event):
132147
"""Listen on the named pipe or Unix domain socket for JSON data from the server.
133148
@@ -307,14 +322,19 @@ def runner_with_cwd_env(
307322
# if additional environment variables are passed, add them to the environment
308323
if env_add:
309324
env.update(env_add)
310-
server = UnixPipeServer(pipe_name)
311-
server.start()
325+
# server = UnixPipeServer(pipe_name)
326+
# server.start()
327+
#################
328+
# Create the FIFO (named pipe) if it doesn't exist
329+
# if not pathlib.Path.exists(pipe_name):
330+
os.mkfifo(pipe_name)
331+
#################
312332

313333
completed = threading.Event()
314334

315335
result = [] # result is a string array to store the data during threading
316336
t1: threading.Thread = threading.Thread(
317-
target=_listen_on_pipe_new, args=(server, result, completed)
337+
target=_listen_on_fifo, args=(pipe_name, result, completed)
318338
)
319339
t1.start()
320340

@@ -364,14 +384,20 @@ def generate_random_pipe_name(prefix=""):
364384

365385
# For Windows, named pipes have a specific naming convention.
366386
if sys.platform == "win32":
367-
return f"\\\\.\\pipe\\{prefix}-{random_suffix}-sock"
387+
return f"\\\\.\\pipe\\{prefix}-{random_suffix}"
368388

369389
# For Unix-like systems, use either the XDG_RUNTIME_DIR or a temporary directory.
370390
xdg_runtime_dir = os.getenv("XDG_RUNTIME_DIR")
371391
if xdg_runtime_dir:
372-
return os.path.join(xdg_runtime_dir, f"{prefix}-{random_suffix}.sock") # noqa: PTH118
392+
return os.path.join(xdg_runtime_dir, f"{prefix}-{random_suffix}") # noqa: PTH118
373393
else:
374-
return os.path.join(tempfile.gettempdir(), f"{prefix}-{random_suffix}.sock") # noqa: PTH118
394+
return os.path.join(tempfile.gettempdir(), f"{prefix}-{random_suffix}") # noqa: PTH118
395+
396+
397+
async def create_fifo(pipe_name: str) -> None:
398+
# Create the FIFO (named pipe) if it doesn't exist
399+
if not pathlib.Path.exists(pipe_name):
400+
os.mkfifo(pipe_name)
375401

376402

377403
class UnixPipeServer:

python_files/vscode_pytest/__init__.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@
2020

2121
import pytest
2222

23-
script_dir = pathlib.Path(__file__).parent.parent
24-
sys.path.append(os.fspath(script_dir))
25-
sys.path.append(os.fspath(script_dir / "lib" / "python"))
26-
from testing_tools import socket_manager # noqa: E402
23+
24+
# sys.path.append("/Users/eleanorboyd/vscode-python/.nox/install_python_libs/lib/python3.10")
25+
# sys.path.append("/Users/eleanorboyd/vscode-python-debugger")
26+
# sys.path.append("/Users/eleanorboyd/vscode-python-debugger/bundled")
27+
# sys.path.append("/Users/eleanorboyd/vscode-python-debugger/bundled/libs")
28+
29+
# import debugpy # noqa: E402
30+
31+
# debugpy.connect(5678)
32+
# debugpy.breakpoint() # noqa: E702
2733

2834
if TYPE_CHECKING:
2935
from pluggy import Result
@@ -872,6 +878,7 @@ def send_post_request(
872878
payload -- the payload data to be sent.
873879
cls_encoder -- a custom encoder if needed.
874880
"""
881+
print("EJFB into send post request!")
875882
if not TEST_RUN_PIPE:
876883
error_msg = (
877884
"PYTEST ERROR: TEST_RUN_PIPE is not set at the time of pytest starting. "
@@ -886,9 +893,10 @@ def send_post_request(
886893

887894
if __writer is None:
888895
try:
889-
__writer = socket_manager.PipeManager(TEST_RUN_PIPE)
890-
__writer.connect()
896+
print("EJFB attemping writer open")
897+
__writer = open(TEST_RUN_PIPE, "w", encoding="utf-8", newline="\r\n") # noqa: SIM115, PTH123
891898
except Exception as error:
899+
print("EJFB error in writer open")
892900
error_msg = f"Error attempting to connect to extension named pipe {TEST_RUN_PIPE}[vscode-pytest]: {error}"
893901
print(error_msg, file=sys.stderr)
894902
print(
@@ -905,10 +913,16 @@ def send_post_request(
905913
"params": payload,
906914
}
907915
data = json.dumps(rpc, cls=cls_encoder)
908-
916+
print(f"EJFB Plugin info[vscode-pytest]: sending data: \n{data}\n")
909917
try:
910918
if __writer:
911-
__writer.write(data)
919+
request = f"""content-length: {len(data)}\ncontent-type: application/json\n\n{data}"""
920+
__writer.write(request)
921+
__writer.flush()
922+
print(
923+
f"EJFB Plugin info[vscode-pytest]: data sent successfully[vscode-pytest]: \n{data}\n"
924+
)
925+
# __writer.close()
912926
else:
913927
print(
914928
f"Plugin error connection error[vscode-pytest], writer is None \n[vscode-pytest] data: \n{data} \n",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# def send_post_request():
2+
# return

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ microvenv
1313
importlib_metadata
1414
packaging
1515
tomli
16+
debugpy

0 commit comments

Comments
 (0)