Skip to content

Commit 6d9e606

Browse files
Revert monkey patch (#77)
* Revert "Monkey patched print to use logging module" This reverts commit a761c64. * bumped version
1 parent c15d143 commit 6d9e606

File tree

4 files changed

+7
-28
lines changed

4 files changed

+7
-28
lines changed

polyapi/__init__.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import sys
33
import copy
44
import truststore
5-
import logging
6-
import builtins
75
from typing import Any, Dict, Optional, overload, Literal
86
from typing_extensions import TypedDict
97
truststore.inject_into_ssl()
@@ -100,19 +98,4 @@ def copy(self) -> '_PolyCustom':
10098
return new
10199

102100

103-
polyCustom: PolyCustomDict = _PolyCustom()
104-
105-
original_print = print
106-
107-
logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')
108-
109-
def log_prints(*objects, sep=' ', end='\n', file=sys.stdout, flush=False):
110-
message = sep.join(map(str, objects)) + end
111-
if file is sys.stdout:
112-
logging.info(message)
113-
elif file is sys.stderr:
114-
logging.error(message)
115-
else:
116-
original_print(*objects, sep=sep, end=end, file=file, flush=flush)
117-
118-
builtins.print = log_prints
101+
polyCustom: PolyCustomDict = _PolyCustom()

polyapi/execute.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Dict, Optional
22
import requests
33
import os
4-
import sys
4+
import logging
55
from requests import Response
66
from polyapi.config import get_api_key_and_url, get_mtls_config
77
from polyapi.exceptions import PolyApiException
88

9+
logger = logging.getLogger("poly")
910

1011
def direct_execute(function_type, function_id, data) -> Response:
1112
""" execute a specific function id/type
@@ -48,7 +49,7 @@ def direct_execute(function_type, function_id, data) -> Response:
4849
if (resp.status_code < 200 or resp.status_code >= 300):
4950
error_content = resp.content.decode("utf-8", errors="ignore")
5051
if function_type == 'api' and os.getenv("LOGS_ENABLED"):
51-
print(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}", file=sys.stderr)
52+
logger.error(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}")
5253
elif function_type != 'api':
5354
raise PolyApiException(f"{resp.status_code}: {error_content}")
5455

@@ -72,7 +73,7 @@ def execute(function_type, function_id, data) -> Response:
7273
if (resp.status_code < 200 or resp.status_code >= 300) and os.getenv("LOGS_ENABLED"):
7374
error_content = resp.content.decode("utf-8", errors="ignore")
7475
if function_type == 'api' and os.getenv("LOGS_ENABLED"):
75-
print(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}", file=sys.stderr)
76+
logger.error(f"Error executing api function with id: {function_id}. Status code: {resp.status_code}. Request data: {data}, Response: {error_content}")
7677
elif function_type != 'api':
7778
raise PolyApiException(f"{resp.status_code}: {error_content}")
7879

polyapi/schema.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import logging
44
import contextlib
55
import re
6-
import polyapi
7-
import builtins
86
from typing import Dict
97
from jsonschema_gentypes.cli import process_config
108
from jsonschema_gentypes import configuration
@@ -91,12 +89,9 @@ def generate_schema_types(input_data: Dict, root=None):
9189
}
9290

9391
# jsonschema_gentypes prints source to stdout
94-
# no option to suppress so we do this
95-
# Not reverting the print monkeypatch causes print to bypass redirect
96-
builtins.print = polyapi.original_print
92+
# no option to surpress so we do this
9793
with contextlib.redirect_stdout(None):
9894
process_config(config, [tmp_input])
99-
builtins.print = polyapi.log_prints
10095

10196
with open(tmp_output, encoding='utf-8') as f:
10297
output = f.read()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
33

44
[project]
55
name = "polyapi-python"
6-
version = "0.3.9.dev12"
6+
version = "0.3.9.dev13"
77
description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers"
88
authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
99
dependencies = [

0 commit comments

Comments
 (0)