Skip to content

Commit

Permalink
Chore - Update Linter Configs (#1273)
Browse files Browse the repository at this point in the history
* Add more linter configuration

* Disable flynt fstrings in setup.py

* Run flynt and other linters

* Split pylint config over multiple lines

* Add setup.py disable for flynt
  • Loading branch information
TimPansino authored Dec 16, 2024
1 parent 57ba3fb commit 25e1f1e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Linter
megalinter-reports/
.pre-commit-config.yaml

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
4 changes: 1 addition & 3 deletions newrelic/api/llm_custom_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class WithLlmCustomAttributes(object):
def __init__(self, custom_attr_dict):
transaction = current_transaction()
if not custom_attr_dict or not isinstance(custom_attr_dict, dict):
raise TypeError(
"custom_attr_dict must be a non-empty dictionary. Received type: %s" % type(custom_attr_dict)
)
raise TypeError(f"custom_attr_dict must be a non-empty dictionary. Received type: {type(custom_attr_dict)}")

# Add "llm." prefix to all keys in attribute dictionary
context_attrs = {k if k.startswith("llm.") else f"llm.{k}": v for k, v in custom_attr_dict.items()}
Expand Down
46 changes: 45 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,43 @@ include = '\.pyi?$'
profile = "black"

[tool.pylint.messages_control]
disable = "C0103,C0114,C0115,C0116,C0209,C0302,C0415,E0401,E1120,R0205,R0401,R0801,R0902,R0903,R0904,R0911,R0912,R0913,R0914,R0915,R1705,R1710,R1725,W0201,W0212,W0223,W0402,W0603,W0612,W0613,W0702,W0703,W0706,line-too-long,redefined-outer-name"
disable = [
"C0103",
"C0114",
"C0115",
"C0116",
"C0209",
"C0302",
"C0415",
"E0401",
"E1120",
"R0205",
"R0401",
"R0801",
"R0902",
"R0903",
"R0904",
"R0911",
"R0912",
"R0913",
"R0914",
"R0915",
"R1705",
"R1710",
"R1725",
"W0201",
"W0212",
"W0223",
"W0402",
"W0603",
"W0612",
"W0613",
"W0702",
"W0703",
"W0706",
"line-too-long",
"redefined-outer-name",
]

[tool.pylint.format]
max-line-length = "120"
Expand All @@ -16,3 +52,11 @@ good-names = "exc,val,tb"

[tool.bandit]
skips = ["B110", "B101", "B404"]

[tool.flynt]
line-length = 999999
aggressive = true
transform-concats = true
transform-joins = true
exclude = ["newrelic/packages/", "setup.py"]
# setup.py needs to not immediately crash on Python 2 to log error messages, so disable fstrings
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
if python_version >= (3, 7):
pass
else:
error_msg = "The New Relic Python agent only supports Python 3.7+. We recommend upgrading to a newer version of Python."

error_msg = (
"The New Relic Python agent only supports Python 3.7+. We recommend upgrading to a newer version of Python."
)

try:
# Lookup table for the last agent versions to support each Python version.
last_supported_version_lookup = {
Expand All @@ -36,7 +38,10 @@

if last_supported_version:
python_version_str = "%s.%s" % (python_version[0], python_version[1])
error_msg += " The last agent version to support Python %s was v%s." % (python_version_str, last_supported_version)
error_msg += " The last agent version to support Python %s was v%s." % (
python_version_str,
last_supported_version,
)
except Exception:
pass

Expand Down
13 changes: 9 additions & 4 deletions tests/cross_agent/test_ecs_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
# limitations under the License.

import os

import pytest
import newrelic.common.utilization as u
from fixtures.ecs_container_id.ecs_mock_server import mock_server, bad_response_mock_server
from fixtures.ecs_container_id.ecs_mock_server import (
bad_response_mock_server,
mock_server,
)
from test_pcf_utilization_data import Environ

import newrelic.common.utilization as u


@pytest.mark.parametrize("env_key", ["ECS_CONTAINER_METADATA_URI_V4", "ECS_CONTAINER_METADATA_URI"])
def test_ecs_docker_container_id(env_key, mock_server):
mock_endpoint = "http://localhost:%d" % mock_server.port
mock_endpoint = f"http://localhost:{int(mock_server.port)}"
env_dict = {env_key: mock_endpoint}

with Environ(env_dict):
Expand All @@ -41,7 +46,7 @@ def test_ecs_docker_container_id_bad_uri(env_dict, mock_server):


def test_ecs_docker_container_id_bad_response(bad_response_mock_server):
mock_endpoint = "http://localhost:%d" % bad_response_mock_server.port
mock_endpoint = f"http://localhost:{int(bad_response_mock_server.port)}"
env_dict = {"ECS_CONTAINER_METADATA_URI": mock_endpoint}

with Environ(env_dict):
Expand Down
2 changes: 1 addition & 1 deletion tests/datastore_motor/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def exercise_motor(db):
await collection.options()
collection.watch()

new_name = MONGODB_COLLECTION + "_renamed"
new_name = f"{MONGODB_COLLECTION}_renamed"
await collection.rename(new_name)
await db[new_name].drop()
await collection.drop()
Expand Down
2 changes: 1 addition & 1 deletion tests/datastore_pymongo/test_async_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def _exercise_mongo(db):
await collection.find_one_and_update({"x": 301}, {"$inc": {"x": 300}})
await collection.options()

new_name = MONGODB_COLLECTION + "_renamed"
new_name = f"{MONGODB_COLLECTION}_renamed"
await collection.rename(new_name)
await db[new_name].drop()
await collection.drop()
Expand Down
2 changes: 1 addition & 1 deletion tests/datastore_pymongo/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _exercise_mongo_v4(db):
collection.find_one_and_update({"x": 301}, {"$inc": {"x": 300}})
collection.options()

new_name = MONGODB_COLLECTION + "_renamed"
new_name = f"{MONGODB_COLLECTION}_renamed"
collection.rename(new_name)
db[new_name].drop()
collection.drop()
Expand Down

0 comments on commit 25e1f1e

Please sign in to comment.