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
69 changes: 50 additions & 19 deletions .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
# More info at https://megalinter.io
name: MegaLinter

on:
# Trigger mega-linter at every push. Action will also be visible from Pull Requests to main
# push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions)
on: # yamllint disable-line rule:truthy - false positive
pull_request:

permissions:
contents: read

env: # Comment env block if you don't want to apply fixes
# Apply linter fixes configuration
APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)
APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)
env:
APPLY_FIXES: all
APPLY_FIXES_EVENT: pull_request
APPLY_FIXES_MODE: commit

concurrency:
group: ${{ github.ref || github.run_id }}-${{ github.workflow }}
Expand All @@ -40,8 +37,8 @@ jobs:
name: MegaLinter
runs-on: ubuntu-24.04
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push, comment issues & post new PR
# Remove the ones you do not need
# Give the default GITHUB_TOKEN write permission to commit and push, comment
# issues & post new PR; remove the ones you do not need
contents: write
issues: write
pull-requests: write
Expand All @@ -51,19 +48,19 @@ jobs:
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
fetch-depth: 0 # Required for pushing commits to PRs

# MegaLinter
- name: MegaLinter
id: ml
# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.io/flavors/
uses: oxsecurity/megalinter/flavors/python@e08c2b05e3dbc40af4c23f41172ef1e068a7d651 # 8.8.0
uses: oxsecurity/megalinter/flavors/python@0dcbedd66ea456ba2d54fd350affaa15df8a0da3 # 9.0.1
env:
# All available variables are described in documentation
# https://megalinter.io/configuration/
# https://megalinter.io/latest/configuration/
VALIDATE_ALL_CODEBASE: "true"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE
# .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
GITHUB_COMMENT_REPORTER: "true"
PYTHON_RUFF_ARGUMENTS: --config pyproject.toml --config 'output-format="github"'
PYTHON_RUFF_FORMAT_ARGUMENTS: --config pyproject.toml --config 'output-format="github"'
Expand All @@ -74,19 +71,53 @@ jobs:
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
with:
name: MegaLinter reports
include-hidden-files: "true"
path: |
megalinter-reports
mega-linter.log

# Push new commit if applicable (for now works only on PR from same repository, not from forks)
# Set APPLY_FIXES_IF var for use in future steps
- name: Set APPLY_FIXES_IF var
run: |
printf 'APPLY_FIXES_IF=%s\n' "${{
steps.ml.outputs.has_updated_sources == 1 &&
(
env.APPLY_FIXES_EVENT == 'all' ||
env.APPLY_FIXES_EVENT == github.event_name
) &&
(
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name == github.repository
)
}}" >> "${GITHUB_ENV}"

# Set APPLY_FIXES_IF_* vars for use in future steps
- name: Set APPLY_FIXES_IF_* vars
run: |
printf 'APPLY_FIXES_IF_PR=%s\n' "${{
env.APPLY_FIXES_IF == 'true' &&
env.APPLY_FIXES_MODE == 'pull_request'
}}" >> "${GITHUB_ENV}"
printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{
env.APPLY_FIXES_IF == 'true' &&
env.APPLY_FIXES_MODE == 'commit' &&
(!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref))
}}" >> "${GITHUB_ENV}"

- name: Prepare commit
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix')
if: env.APPLY_FIXES_IF_COMMIT == 'true'
run: sudo chown -Rc $UID .git/

- name: Commit and push applied linter fixes
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix')
uses: stefanzweifel/git-auto-commit-action@778341af668090896ca464160c2def5d1d1a3eb0 # 6.0.1
if: env.APPLY_FIXES_IF_COMMIT == 'true'
with:
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
branch: >-
${{
github.event.pull_request.head.ref ||
github.head_ref ||
github.ref
}}
commit_message: "[MegaLinter] Apply linters fixes"
commit_user_name: newrelic-python-agent-team
commit_user_email: [email protected]
1 change: 1 addition & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ DEFAULT_BRANCH: main # Usually master or main
SHOW_ELAPSED_TIME: true
FILEIO_REPORTER: false
PRINT_ALPACA: false
FLAVOR_SUGGESTIONS: false
CLEAR_REPORT_FOLDER: true
VALIDATE_ALL_CODEBASE: true
IGNORE_GITIGNORED_FILES: true
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ default_install_hook_types:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.12.5
rev: v0.13.1
hooks:
# Run the linter.
- id: ruff-check
Expand All @@ -40,7 +40,7 @@ repos:
stages: [pre-push]

- repo: https://github.com/google/addlicense
rev: 55a521bf81c24480094950caa3566548fa63875e
rev: v1.2.0
hooks:
- id: addlicense
args:
Expand Down
2 changes: 1 addition & 1 deletion newrelic/api/time_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _observe_exception(self, exc_info=None, ignore=None, expected=None, status_c
if getattr(value, "_nr_ignored", None):
return

module, name, fullnames, message_raw = parse_exc_info((exc, value, tb))
_module, name, fullnames, message_raw = parse_exc_info((exc, value, tb))
fullname = fullnames[0]

# In case message is in JSON format for OpenAI models
Expand Down
4 changes: 2 additions & 2 deletions newrelic/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def do_transactions(self):
""" """

for item in _trace_cache.active_threads():
transaction, thread_id, thread_type, frame = item
transaction, _thread_id, _thread_type, _frame = item
print("THREAD", item, file=self.stdout)
if transaction is not None:
transaction.dump(self.stdout)
Expand Down Expand Up @@ -460,7 +460,7 @@ def __thread_run(self):
listener.listen(5)

while True:
client, addr = listener.accept()
client, _addr = listener.accept()

if not self.__console_initialized:
self.__console_initialized = True
Expand Down
3 changes: 3 additions & 0 deletions newrelic/core/attribute_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def __ge__(self, other):
def __repr__(self):
return f"({self.name}, {bin(self.destinations)}, {self.is_wildcard}, {self.is_include})"

def __hash__(self):
return hash((self.name, self.destinations, self.is_include, self.is_wildcard))

def name_match(self, name):
if self.is_wildcard:
return name.startswith(self.name)
Expand Down
2 changes: 1 addition & 1 deletion newrelic/core/stats_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def notice_error(self, error=None, attributes=None, expected=None, ignore=None,
if getattr(value, "_nr_ignored", None):
return

module, name, fullnames, message_raw = parse_exc_info(error)
_module, name, fullnames, message_raw = parse_exc_info(error)
fullname = fullnames[0]

# In the case case of JSON formatting for OpenAI models
Expand Down
2 changes: 1 addition & 1 deletion newrelic/hooks/datastore_memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _nr_datastore_trace_wrapper_(wrapped, instance, args, kwargs):
result = wrapped(*args, **kwargs)

instance_info = transaction._nr_datastore_instance_info
(host, port_path_or_id, db) = instance_info
(host, port_path_or_id, _db) = instance_info
dt.host = host
dt.port_path_or_id = port_path_or_id

Expand Down
2 changes: 1 addition & 1 deletion newrelic/hooks/framework_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _wrap_headers_received(wrapped, instance, args, kwargs):
except:
pass

path, sep, query = start_line.path.partition("?")
path, _sep, query = start_line.path.partition("?")

transaction = WebTransaction(
application=application_instance(),
Expand Down
4 changes: 2 additions & 2 deletions newrelic/hooks/mlmodel_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def create_prediction_event(transaction, class_, instance, args, kwargs, return_
"modelName": model_name,
},
)
features, predictions = np_casted_data_set.shape
_features, _predictions = np_casted_data_set.shape
for prediction_index, prediction in enumerate(np_casted_data_set):
inference_id = uuid.uuid4()

Expand Down Expand Up @@ -346,7 +346,7 @@ def wrap_metric_scorer(wrapped, instance, args, kwargs):

score = wrapped(*args, **kwargs)

y_true, y_pred, args, kwargs = _bind_scorer(*args, **kwargs)
_y_true, y_pred, args, kwargs = _bind_scorer(*args, **kwargs)
model_name = "Unknown"
training_step = "Unknown"
if hasattr(y_pred, "_nr_model_name"):
Expand Down
2 changes: 1 addition & 1 deletion tests/agent_features/test_serverless_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _test():

_test()

out, err = capsys.readouterr()
out, _err = capsys.readouterr()

# Validate that something is printed to stdout
assert out
Expand Down
2 changes: 1 addition & 1 deletion tests/agent_unittests/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_http_payload_compression(server, client_cls, method, threshold):

def test_cert_path(server):
with HttpClient("localhost", server.port, ca_bundle_path=CERT_PATH) as client:
status, data = client.send_request()
client.send_request()


@pytest.mark.parametrize("system_certs_available", (True, False))
Expand Down
18 changes: 9 additions & 9 deletions tests/component_graphqlserver/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _query():

@dt_enabled
def test_middleware(target_application):
framework, version, target_application = target_application
framework, _version, target_application = target_application
_test_middleware_metrics = [
("GraphQL/operation/GraphQLServer/query/<anonymous>/hello", 1),
("GraphQL/resolve/GraphQLServer/hello", 1),
Expand All @@ -207,7 +207,7 @@ def _test():

@dt_enabled
def test_exception_in_middleware(target_application):
framework, version, target_application = target_application
_framework, _version, target_application = target_application
query = "query MyQuery { error_middleware }"
field = "error_middleware"

Expand Down Expand Up @@ -254,7 +254,7 @@ def _test():
@pytest.mark.parametrize("field", ("error", "error_non_null"))
@dt_enabled
def test_exception_in_resolver(target_application, field):
framework, version, target_application = target_application
_framework, _version, target_application = target_application
query = f"query MyQuery {{ {field} }}"

txn_name = "framework_graphql._target_schema_sync:resolve_error"
Expand Down Expand Up @@ -308,7 +308,7 @@ def _test():
],
)
def test_exception_in_validation(target_application, is_graphql_2, query, exc_class):
framework, version, target_application = target_application
_framework, _version, target_application = target_application
if "syntax" in query:
txn_name = "graphql.language.parser:parse"
else:
Expand Down Expand Up @@ -354,7 +354,7 @@ def _test():

@dt_enabled
def test_operation_metrics_and_attrs(target_application):
framework, version, target_application = target_application
framework, _version, target_application = target_application
operation_metrics = [("GraphQL/operation/GraphQLServer/query/MyQuery/library", 1)]
operation_attrs = {"graphql.operation.type": "query", "graphql.operation.name": "MyQuery"}

Expand All @@ -380,7 +380,7 @@ def _test():

@dt_enabled
def test_field_resolver_metrics_and_attrs(target_application):
framework, version, target_application = target_application
framework, _version, target_application = target_application
field_resolver_metrics = [("GraphQL/resolve/GraphQLServer/hello", 1)]
graphql_attrs = {
"graphql.field.name": "hello",
Expand Down Expand Up @@ -426,7 +426,7 @@ def _test():
@dt_enabled
@pytest.mark.parametrize("query,obfuscated", _test_queries)
def test_query_obfuscation(target_application, query, obfuscated):
framework, version, target_application = target_application
_framework, _version, target_application = target_application
graphql_attrs = {"graphql.operation.query": obfuscated}

if callable(query):
Expand Down Expand Up @@ -471,7 +471,7 @@ def _test():
@dt_enabled
@pytest.mark.parametrize("query,expected_path", _test_queries)
def test_deepest_unique_path(target_application, query, expected_path):
framework, version, target_application = target_application
_framework, _version, target_application = target_application
if expected_path == "/error":
txn_name = "framework_graphql._target_schema_sync:resolve_error"
else:
Expand All @@ -486,5 +486,5 @@ def _test():

@validate_transaction_count(0)
def test_ignored_introspection_transactions(target_application):
framework, version, target_application = target_application
_framework, _version, target_application = target_application
response = target_application("{ __schema { types { name } } }")
2 changes: 1 addition & 1 deletion tests/external_httplib2/test_httplib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_httplib2_http_request(server, metrics):
@background_task(name="test_httplib2:test_httplib2_http_request")
def _test():
connection = httplib2.Http()
response, content = connection.request(f"http://localhost:{server.port}", "GET")
connection.request(f"http://localhost:{server.port}", "GET")

_test()

Expand Down
Loading
Loading