Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/python-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ jobs:
pip install build
pip install -e .[dev]

- name: Check formatting with black
- name: Check formatting with ruff
run: |
black --check python3/
ruff format --check python3/

- name: Lint with flake8
- name: Lint with ruff
run: |
flake8 python3/
ruff check python3/

- name: Run tests with coverage
env:
Expand Down
19 changes: 19 additions & 0 deletions CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,24 @@ Before starting, you'll need to ensure you have the appropriate version of Pytho
```bash
python3 -m unittest discover python3/tests
```

### Code Quality

This project uses [Ruff](https://docs.astral.sh/ruff/) for linting and formatting.

```bash
# Check formatting
ruff format --check python3/

# Fix formatting
ruff format python3/

# Run linter
ruff check python3/

# Fix auto-fixable lint issues
ruff check --fix python3/
```

- Remember to deactivate the virtual environment when you're done: `deactivate`

22 changes: 18 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ dev = [
"django>=1.8.8",
"flask>=0.10",
"WebTest>=2.0.32",
"black",
"flake8",
"ruff",
"coverage",
]

Expand Down Expand Up @@ -82,5 +81,20 @@ exclude_lines = [
"except Exception:",
]

[tool.black]
target-version = ["py39", "py310", "py311", "py312", "py313"]
[tool.ruff]
target-version = "py39"

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # Pyflakes
"I", # isort
]
ignore = [
"E501", # line too long (handled by formatter)
]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
1 change: 0 additions & 1 deletion python3/raygun4py/middleware/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class Provider(MiddlewareMixin):

def __init__(self, get_response=None):
self.get_response = get_response
config = getattr(settings, "RAYGUN4PY_CONFIG", {})
Expand Down
1 change: 0 additions & 1 deletion python3/raygun4py/middleware/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Provider(object):

def __init__(self, app, apiKey, config=None):
self.app = app
self.config = config if config is not None else {}
Expand Down
11 changes: 4 additions & 7 deletions python3/raygun4py/raygunmsgs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
import os
import logging
import os
import sys

import jsonpickle
Expand All @@ -21,7 +21,6 @@


class RaygunMessageBuilder(object):

def __init__(self, options):
self.raygunMessage = RaygunMessage()
self.options = options
Expand Down Expand Up @@ -55,9 +54,9 @@ def set_environment_details(self, extra_environment_data):
pass

try:
self.raygunMessage.details["environment"][
"architecture"
] = platform.architecture()[0]
self.raygunMessage.details["environment"]["architecture"] = (
platform.architecture()[0]
)
except Exception: # pragma: no cover
pass

Expand Down Expand Up @@ -127,7 +126,6 @@ def set_user(self, user):


class RaygunMessage(object):

def __init__(self):
self.occurredOn = datetime.now(timezone.utc)
self.details = {}
Expand Down Expand Up @@ -335,7 +333,6 @@ def _get_locals(self, frame):


class RaygunLoggerFallbackErrorMessage(object):

def __init__(self, name, message, filename, funcName, lineno):
self.className = "Logger (" + name + ")"
self.message = message
Expand Down
5 changes: 2 additions & 3 deletions python3/tests/middleware/test_django.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import mock
import django
import mock
from django.conf import settings
from django.test.client import RequestFactory
from django.test import SimpleTestCase
from django.test.client import RequestFactory
from raygun4py.middleware.django import Provider

settings.configure(DEBUG=True, RAYGUN4PY_API_KEY="foo", ALLOWED_HOSTS=["testserver"])
django.setup()


class DjangoProviderTests(SimpleTestCase):

def setUp(self):
request_factory = RequestFactory()
self.get_request = request_factory.get("/foo")
Expand Down
6 changes: 2 additions & 4 deletions python3/tests/middleware/test_wsgi.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import mock
import unittest

import mock
from raygun4py.middleware.wsgi import Provider
from webtest import TestApp
from webtest.debugapp import debug_app
from raygun4py.middleware.wsgi import Provider


class TestWSGIMiddleware(unittest.TestCase):

def setUp(self):
self.test_middleware = ExceptionMiddleware(debug_app)
self.raygun_middleware = Provider(self.test_middleware, "XXXXXXXXXX")
Expand All @@ -31,7 +30,6 @@ def test_json_post(self):


class ExceptionMiddleware(object):

def __init__(self, app):
self.app = app
self.raise_on_request = False
Expand Down
6 changes: 3 additions & 3 deletions python3/tests/test_functional.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# coding=utf-8

import unittest
import sys
import logging
import os
import sys
import unittest

from raygun4py import raygunprovider


class TestRaygun4PyFunctional(unittest.TestCase):

def setUp(self):
self.apiKey = os.environ.get("RAYGUN_API_KEY")
if not self.apiKey:
Expand Down
6 changes: 3 additions & 3 deletions python3/tests/test_raygunmsgs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import inspect
import socket
import sys
import unittest
import socket
import inspect

import jsonpickle
from raygun4py import raygunmsgs, raygunprovider


class TestRaygunMessageBuilder(unittest.TestCase):

def setUp(self):
self.builder = raygunmsgs.RaygunMessageBuilder({}).new()
self.request = {
Expand Down
14 changes: 5 additions & 9 deletions python3/tests/test_raygunprovider.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import unittest
import sys
from raygun4py import raygunprovider
from raygun4py import raygunmsgs
from raygun4py import utilities
from raygun4py import __version__
from raygun4py import version as version_file
import logging
import sys
import unittest
from unittest import mock

from raygun4py import __version__, raygunmsgs, raygunprovider, utilities
from raygun4py import version as version_file

class TestRaygunSender(unittest.TestCase):

class TestRaygunSender(unittest.TestCase):
def setUp(self):
self.sender = raygunprovider.RaygunSender("invalidapikey")
self.handler = raygunprovider.RaygunHandler("testkey", "v1.0")
Expand Down Expand Up @@ -124,7 +121,6 @@ def test_merge_custom_data(self):


class TestGroupingKey(unittest.TestCase):

def the_callback(self, raygun_message):
return self.key

Expand Down