Skip to content

Windows compatibility patch #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,37 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox black
pip install -r requirements.txt

- name: Run Tox
run: tox

- name: Run linter
run: black --check .

# On windows we want to test only latest python version.
# Everything else will be tested against Linux
test_on_windows:
runs-on: windows-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
update-environment: false

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run tests
run: pytest

test_python_2:
runs-on: ubuntu-latest

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ WORKDIR /sdk
COPY ./requirements.txt /sdk

RUN pip install --upgrade pip \
&& pip install pytest -r requirements.txt
&& pip install $(grep -ivE "black" requirements.txt)
# black is not available in python2.7 container
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not create a separate requirements.txt for Python 2.7?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or, better yet, use conditionals https://stackoverflow.com/a/35614580

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the approach based on your last suggestion. Thanks!


COPY . /sdk
ENV PYTHONPATH=/sdk
Expand Down
8 changes: 5 additions & 3 deletions backtracepython/child.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ def eprint(*args, **kwargs):


def post_json(full_url, obj):
payload = json.dumps(obj, ignore_nan=True, bigint_as_string=True)
if globs.debug_backtrace:
eprint(full_url)
eprint(json.dumps(obj, indent=2, ignore_nan=True))
payload = json.dumps(obj, ignore_nan=True).encode("utf-8")
data = "Submitting a payload to {},\n {}\n".format(full_url, payload)
eprint(data)

payload = payload.encode("utf-8")
headers = {
"Content-Type": "application/json",
"Content-Length": len(payload),
Expand Down
37 changes: 0 additions & 37 deletions example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +0,0 @@
import os

import backtracepython as backtrace


def open_file(name):
open(name).read()


def main():
backtrace.initialize(
endpoint=os.getenv(
"BACKTRACE_SUBMISSION_URL",
'"https://submit.backtrace.io/your-universe/token/json"',
),
attributes={
"application": "example-app",
"application.version": "1.0.0",
"version": "1.0.0",
},
)

# send an exception from the try/catch block
try:
open_file("not existing file")
except:
backtrace.send_last_exception()

# send a message
backtrace.send_report("test message")

# generate and send unhandled exception
open_file("not existing file")


if __name__ == "__main__":
main()
37 changes: 37 additions & 0 deletions example/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os

import backtracepython as backtrace


def open_file(name):
open(name).read()


def main():
backtrace.initialize(
endpoint=os.getenv(
"BACKTRACE_SUBMISSION_URL",
'"https://submit.backtrace.io/your-universe/token/json"',
),
attributes={
"application": "example-app",
"application.version": "1.0.0",
"version": "1.0.0",
},
)

# send an exception from the try/catch block
try:
open_file("not existing file")
except:
backtrace.send_last_exception()

# send a message
backtrace.send_report("test message")

# generate and send unhandled exception
open_file("not existing file")


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[pytest]
pythonpath = .
faulthandler_timeout = 5
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
six
simplejson==3.19.3
pytest
tox
black
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

from setuptools import find_packages, setup

import backtracepython

setup(
name="backtracepython",
version=backtracepython.version_string,
version="0.3.3",
description="Backtrace.io error reporting tool for Python",
author="Backtrace.io",
author_email="team@backtrace.io",
Expand Down
16 changes: 5 additions & 11 deletions tests/test_basic_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def check_basic_report(obj):

source_code_id = obj["threads"][obj["mainThread"]]["stack"][0]["sourceCode"]
assert obj["sourceCode"][source_code_id]["path"].endswith(
"tests/exe/simple_report.py"
os.path.join(tests_dir, "exe", "simple_report.py")
)
assert obj["sourceCode"][source_code_id]["text"].endswith("\na = b\n")

Expand All @@ -49,7 +49,9 @@ def check_multi_file(obj):

fault_stack = obj["threads"][obj["mainThread"]]["stack"]
source_code_id = fault_stack[-1]["sourceCode"]
assert obj["sourceCode"][source_code_id]["path"].endswith("tests/exe/multi_file.py")
assert obj["sourceCode"][source_code_id]["path"].endswith(
os.path.join(tests_dir, "exe", "multi_file.py")
)
lines = obj["sourceCode"][source_code_id]["text"].split("\n")
assert lines[fault_stack[-1]["line"] - 1] == "call_a_file(True)"

Expand Down Expand Up @@ -91,19 +93,11 @@ def log_message(self, format, *args):
host, port = httpd.server_address

exe_path = os.path.join(exe_dir, exe_name)
stdio_action = None if debug_backtrace else subprocess.PIPE
child = subprocess.Popen(
[sys.executable, exe_path, host, str(port)],
stdout=stdio_action,
stderr=stdio_action,
)
child = subprocess.Popen([sys.executable, exe_path, host, str(port)])

httpd.handle_request()
check_fn(non_local.json_object)
child.wait()
if stdio_action is not None:
child.stdout.close()
child.stderr.close()
httpd.server_close()


Expand Down
Loading