diff --git a/.gitignore b/.gitignore index d4550713f..1ffd0a91e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # Linter megalinter-reports/ +.pre-commit-config.yaml # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/newrelic/api/llm_custom_attributes.py b/newrelic/api/llm_custom_attributes.py index 37745ba06..7879c595b 100644 --- a/newrelic/api/llm_custom_attributes.py +++ b/newrelic/api/llm_custom_attributes.py @@ -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()} diff --git a/pyproject.toml b/pyproject.toml index 65be1548b..1f4cd146e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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 diff --git a/setup.py b/setup.py index 02132b962..fdefc158d 100644 --- a/setup.py +++ b/setup.py @@ -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 = { @@ -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 diff --git a/tests/cross_agent/test_ecs_data.py b/tests/cross_agent/test_ecs_data.py index 9ec32d3b5..c113fe790 100644 --- a/tests/cross_agent/test_ecs_data.py +++ b/tests/cross_agent/test_ecs_data.py @@ -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): @@ -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): diff --git a/tests/datastore_motor/test_collection.py b/tests/datastore_motor/test_collection.py index 42ec33f75..f5de7c7bb 100644 --- a/tests/datastore_motor/test_collection.py +++ b/tests/datastore_motor/test_collection.py @@ -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() diff --git a/tests/datastore_pymongo/test_async_collection.py b/tests/datastore_pymongo/test_async_collection.py index b841bee9e..c3716f4df 100644 --- a/tests/datastore_pymongo/test_async_collection.py +++ b/tests/datastore_pymongo/test_async_collection.py @@ -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() diff --git a/tests/datastore_pymongo/test_collection.py b/tests/datastore_pymongo/test_collection.py index ccf92e6b8..500f814e9 100644 --- a/tests/datastore_pymongo/test_collection.py +++ b/tests/datastore_pymongo/test_collection.py @@ -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()