From d9fa625b49fbecb5232a6829bacc416dd2a82c10 Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Tue, 3 Sep 2024 14:24:53 +0200 Subject: [PATCH 01/11] Package upgrade --- .gitignore | 61 +++++++++++++++++++++++++++++++++++++++++++++-- requirements.txt | 2 ++ setup.py | 24 ++++++++++++++----- tests/__init__.py | 2 +- tox.ini | 9 +++++++ 5 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 requirements.txt create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 76c0509..4abffe3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,61 @@ -*.egg-info test_all -build/ +# Byte-compiled files +*.pyc +*.pyo +*.pyd +__pycache__/ + +# Distribution / packaging +*.egg +*.egg-info/ dist/ +build/ +.eggs/ +*.egg-info/ +*.manifest +*.spec + +# Installation directories +pip-log.txt +pip-delete-this-directory.txt + +# pytest +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# pyenv +.python-version + +# virtualenv +venv/ +ENV/ +env/ +.venv/ +env.bak/ +venv.bak/ + +# tox +.tox/ +nox/ +coverage-report/ + +# IDEs and editors +.vscode/ +.idea/ +*.swp +*.swo + +# macOS +.DS_Store + +# Windows +Thumbs.db +Desktop.ini \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3d43198 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +six +simplejson==3.19.3 diff --git a/setup.py b/setup.py index 762a663..20f87f3 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,31 @@ #!/usr/bin/env python -from setuptools import setup +from setuptools import find_packages, setup import backtracepython setup( name='backtracepython', version=backtracepython.version_string, - description='Backtrace error reporting tool for Python', - author='Andrew Kelley', - author_email='akelley@backtrace.io', - packages=['backtracepython'], + description='Backtrace.io error reporting tool for Python', + author='Backtrace.io', + author_email='team@backtrace.io', + packages=find_packages(), test_suite="tests", url='https://github.com/backtrace-labs/backtrace-python', install_requires=[ + 'six', 'simplejson', - ] + ], + extras_require={ + 'test': ['pytest'], + }, + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4', + classifiers=[ + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + ], ) diff --git a/tests/__init__.py b/tests/__init__.py index 14133fe..a9f5db0 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,7 +2,7 @@ import os import subprocess import sys -import unittest +import pytest if sys.version_info.major >= 3: from http.server import HTTPServer diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..e0f8437 --- /dev/null +++ b/tox.ini @@ -0,0 +1,9 @@ +[tox] +envlist = py27, py37, py38, py39, py311 + +[testenv] +deps = + -rrequirements.txt + pytest +commands = + pytest \ No newline at end of file From 8c6838de71198dfd68f5820f7937f81d2a538106 Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Tue, 3 Sep 2024 15:24:19 +0200 Subject: [PATCH 02/11] Change tests to pytest --- .github/workflows/test.yml | 31 +++++++++++++++++++++++ tests/{__init__.py => test_basic_flow.py} | 27 +++++++++----------- 2 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/test.yml rename tests/{__init__.py => test_basic_flow.py} (84%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..9b2dd9b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [2.7, 3.7, 3.8, 3.9, 3.10] # List of Python versions to test against + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox + + - name: Run Tox + run: tox diff --git a/tests/__init__.py b/tests/test_basic_flow.py similarity index 84% rename from tests/__init__.py rename to tests/test_basic_flow.py index a9f5db0..19232e3 100644 --- a/tests/__init__.py +++ b/tests/test_basic_flow.py @@ -1,15 +1,13 @@ -import simplejson as json import os import subprocess import sys -import pytest + +import simplejson as json if sys.version_info.major >= 3: - from http.server import HTTPServer - from http.server import BaseHTTPRequestHandler + from http.server import BaseHTTPRequestHandler, HTTPServer else: - from BaseHTTPServer import HTTPServer - from BaseHTTPServer import BaseHTTPRequestHandler + from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer tests_dir = os.path.dirname(os.path.realpath(__file__)) exe_dir = os.path.join(tests_dir, "exe") @@ -97,15 +95,14 @@ def log_message(self, format, *args): httpd.server_close() -class TestErrorReports(unittest.TestCase): - def test_basic_report(self): - run_one_test(check_basic_report, "simple_report.py") +def test_basic_report(): + run_one_test(check_basic_report, "simple_report.py") - def test_multi_file(self): - run_one_test(check_multi_file, "multi_file.py") +def test_multi_file(): + run_one_test(check_multi_file, "multi_file.py") - def test_send_report(self): - run_one_test(check_send_report, "send_report.py") +def test_send_report(): + run_one_test(check_send_report, "send_report.py") - def test_threads(self): - run_one_test(check_threads, "threads.py") +def test_threads(): + run_one_test(check_threads, "threads.py") From 8a9e1bb9fe5e4310dea0d51375b7057664907162 Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Tue, 3 Sep 2024 16:51:32 +0200 Subject: [PATCH 03/11] Fix tox.ini and try to not update python library --- .github/workflows/test.yml | 2 ++ tox.ini | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b2dd9b..48eb393 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,8 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + update-environment: false + - name: Install dependencies run: | diff --git a/tox.ini b/tox.ini index e0f8437..829cdf8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,6 @@ [tox] -envlist = py27, py37, py38, py39, py311 +envlist = py27, py37, py38, py39, py310 +skipsdist = True [testenv] deps = From 1d2437a3e0cae0c8d298c05f9e0f2d7822ac1e3f Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Tue, 3 Sep 2024 17:46:58 +0200 Subject: [PATCH 04/11] Use docker file to test against python2.7 --- .github/workflows/test.yml | 16 ++++++++++++++-- Dockerfile | 10 ++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 48eb393..6f64a57 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [2.7, 3.7, 3.8, 3.9, 3.10] # List of Python versions to test against + python-version: [3.7, 3.8, 3.9, 3.11] # List of Python versions to test against steps: - name: Checkout code @@ -23,7 +23,6 @@ jobs: python-version: ${{ matrix.python-version }} update-environment: false - - name: Install dependencies run: | python -m pip install --upgrade pip @@ -31,3 +30,16 @@ jobs: - name: Run Tox run: tox + + test_python_2: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Build + run: docker build -t backtrace-python . + + - name: Run Docker Container + run: docker run --rm backtrace-python diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7fb7755 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:2.7-slim + +WORKDIR /sdk +COPY . /sdk + +RUN pip install --upgrade pip \ + && pip install tox \ + && pip install -r requirements.txt # Install project dependencies + +CMD ["tox"] \ No newline at end of file From 30309e6e24839628f90194edb8730736542a86f8 Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Tue, 3 Sep 2024 17:49:59 +0200 Subject: [PATCH 05/11] DO not use tox in python2 docker container --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7fb7755..a6864ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,6 @@ WORKDIR /sdk COPY . /sdk RUN pip install --upgrade pip \ - && pip install tox \ - && pip install -r requirements.txt # Install project dependencies + && pip install -r requirements.txt -CMD ["tox"] \ No newline at end of file +CMD ["python", "testpy.py"] From cb09090a12d2e6547ca69c7802a2630760e211d4 Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Tue, 3 Sep 2024 17:53:45 +0200 Subject: [PATCH 06/11] DO not use tox in python2 docker container --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a6864ef..c561d66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,4 @@ COPY . /sdk RUN pip install --upgrade pip \ && pip install -r requirements.txt -CMD ["python", "testpy.py"] +CMD ["pytest"] From 7bee803aad2fb7eb455bd5699fffb96275656312 Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Tue, 3 Sep 2024 17:57:26 +0200 Subject: [PATCH 07/11] Install pytest --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c561d66..5c768f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,6 @@ WORKDIR /sdk COPY . /sdk RUN pip install --upgrade pip \ - && pip install -r requirements.txt + && pip install pytest -r requirements.txt CMD ["pytest"] From a7f25d7ef92c57d28c9a49a83eeb9439fd90f585 Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Tue, 3 Sep 2024 18:02:06 +0200 Subject: [PATCH 08/11] Set correct classifier for python2 --- tests/test_basic_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_basic_flow.py b/tests/test_basic_flow.py index 19232e3..e211fa6 100644 --- a/tests/test_basic_flow.py +++ b/tests/test_basic_flow.py @@ -38,7 +38,7 @@ def check_multi_file(obj): assert obj['classifiers'][0] == "ValueError" assert obj['attributes']['error.message'] == "Error when decoding true at char 1" else: - assert obj['classifiers'][0] == "ValueError" + assert obj['classifiers'][0] == "JSONDecodeError" assert obj['attributes']['error.message'] == "No JSON object could be decoded" fault_stack = obj['threads'][obj['mainThread']]['stack'] From 3c9571a34671d2421a93cc3638d1aa045bb63b24 Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Tue, 3 Sep 2024 18:03:22 +0200 Subject: [PATCH 09/11] Set correct classifier for python2 --- tests/test_basic_flow.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/test_basic_flow.py b/tests/test_basic_flow.py index e211fa6..540f751 100644 --- a/tests/test_basic_flow.py +++ b/tests/test_basic_flow.py @@ -30,16 +30,13 @@ def check_basic_report(obj): assert obj['attributes']['a'] == 1 assert obj['attributes']['b'] == "bar" -def check_multi_file(obj): - if sys.version_info.major >= 3: - assert obj['classifiers'][0] == "JSONDecodeError" - assert obj['attributes']['error.message'] == "Expecting value: line 1 column 1 (char 0)" - elif obj['langVersion'].startswith("PyPy"): +def check_multi_file(obj): + if obj['langVersion'].startswith("PyPy"): assert obj['classifiers'][0] == "ValueError" assert obj['attributes']['error.message'] == "Error when decoding true at char 1" else: assert obj['classifiers'][0] == "JSONDecodeError" - assert obj['attributes']['error.message'] == "No JSON object could be decoded" + assert obj['attributes']['error.message'] == "Expecting value: line 1 column 1 (char 0)" fault_stack = obj['threads'][obj['mainThread']]['stack'] source_code_id = fault_stack[-1]['sourceCode'] From 66ee76b1902290cb86cc1142b15f14b2afed01c3 Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Wed, 4 Sep 2024 10:33:06 +0200 Subject: [PATCH 10/11] Update Dockerfile Co-authored-by: Sebastian Alex --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5c768f7..7421f06 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,11 @@ FROM python:2.7-slim WORKDIR /sdk -COPY . /sdk +COPY ./requirements.txt /sdk RUN pip install --upgrade pip \ && pip install pytest -r requirements.txt +COPY . /sdk + CMD ["pytest"] From f113ab05cc46f504899f6982802f930df6f754b4 Mon Sep 17 00:00:00 2001 From: Konrad Dysput Date: Wed, 4 Sep 2024 10:33:56 +0200 Subject: [PATCH 11/11] Add eol for gitignore and tox.ini --- .gitignore | 2 +- tox.ini | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 4abffe3..b28b756 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,4 @@ coverage-report/ # Windows Thumbs.db -Desktop.ini \ No newline at end of file +Desktop.ini diff --git a/tox.ini b/tox.ini index 829cdf8..4dd7c9f 100644 --- a/tox.ini +++ b/tox.ini @@ -6,5 +6,6 @@ skipsdist = True deps = -rrequirements.txt pytest + commands = - pytest \ No newline at end of file + pytest