Skip to content

Commit baecae8

Browse files
Update Megalinter (#1510)
* Update megalinter workflow * Update megalinter version * Fix RUF059: unused-unpacked-variable * Fix PLW1641: eq-without-hash --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 3b30f08 commit baecae8

26 files changed

+104
-69
lines changed

.github/workflows/mega-linter.yml

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@
1717
# More info at https://megalinter.io
1818
name: MegaLinter
1919

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

2523
permissions:
2624
contents: read
2725

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

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

5553
# MegaLinter
5654
- name: MegaLinter
5755
id: ml
58-
# You can override MegaLinter flavor used to have faster performances
59-
# More info at https://megalinter.io/flavors/
60-
uses: oxsecurity/megalinter/flavors/python@e08c2b05e3dbc40af4c23f41172ef1e068a7d651 # 8.8.0
56+
uses: oxsecurity/megalinter/flavors/python@0dcbedd66ea456ba2d54fd350affaa15df8a0da3 # 9.0.1
6157
env:
6258
# All available variables are described in documentation
63-
# https://megalinter.io/configuration/
59+
# https://megalinter.io/latest/configuration/
6460
VALIDATE_ALL_CODEBASE: "true"
6561
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66-
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
62+
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE
63+
# .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
6764
GITHUB_COMMENT_REPORTER: "true"
6865
PYTHON_RUFF_ARGUMENTS: --config pyproject.toml --config 'output-format="github"'
6966
PYTHON_RUFF_FORMAT_ARGUMENTS: --config pyproject.toml --config 'output-format="github"'
@@ -74,19 +71,53 @@ jobs:
7471
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
7572
with:
7673
name: MegaLinter reports
74+
include-hidden-files: "true"
7775
path: |
7876
megalinter-reports
7977
mega-linter.log
8078
81-
# Push new commit if applicable (for now works only on PR from same repository, not from forks)
79+
# Set APPLY_FIXES_IF var for use in future steps
80+
- name: Set APPLY_FIXES_IF var
81+
run: |
82+
printf 'APPLY_FIXES_IF=%s\n' "${{
83+
steps.ml.outputs.has_updated_sources == 1 &&
84+
(
85+
env.APPLY_FIXES_EVENT == 'all' ||
86+
env.APPLY_FIXES_EVENT == github.event_name
87+
) &&
88+
(
89+
github.event_name == 'push' ||
90+
github.event.pull_request.head.repo.full_name == github.repository
91+
)
92+
}}" >> "${GITHUB_ENV}"
93+
94+
# Set APPLY_FIXES_IF_* vars for use in future steps
95+
- name: Set APPLY_FIXES_IF_* vars
96+
run: |
97+
printf 'APPLY_FIXES_IF_PR=%s\n' "${{
98+
env.APPLY_FIXES_IF == 'true' &&
99+
env.APPLY_FIXES_MODE == 'pull_request'
100+
}}" >> "${GITHUB_ENV}"
101+
printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{
102+
env.APPLY_FIXES_IF == 'true' &&
103+
env.APPLY_FIXES_MODE == 'commit' &&
104+
(!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref))
105+
}}" >> "${GITHUB_ENV}"
106+
82107
- name: Prepare commit
83-
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')
108+
if: env.APPLY_FIXES_IF_COMMIT == 'true'
84109
run: sudo chown -Rc $UID .git/
110+
85111
- name: Commit and push applied linter fixes
86-
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')
87112
uses: stefanzweifel/git-auto-commit-action@778341af668090896ca464160c2def5d1d1a3eb0 # 6.0.1
113+
if: env.APPLY_FIXES_IF_COMMIT == 'true'
88114
with:
89-
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
115+
branch: >-
116+
${{
117+
github.event.pull_request.head.ref ||
118+
github.head_ref ||
119+
github.ref
120+
}}
90121
commit_message: "[MegaLinter] Apply linters fixes"
91122
commit_user_name: newrelic-python-agent-team
92123
commit_user_email: 137356142+newrelic-python-agent-team@users.noreply.github.com

.mega-linter.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DEFAULT_BRANCH: main # Usually master or main
2020
SHOW_ELAPSED_TIME: true
2121
FILEIO_REPORTER: false
2222
PRINT_ALPACA: false
23+
FLAVOR_SUGGESTIONS: false
2324
CLEAR_REPORT_FOLDER: true
2425
VALIDATE_ALL_CODEBASE: true
2526
IGNORE_GITIGNORED_FILES: true

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ default_install_hook_types:
2929
repos:
3030
- repo: https://github.com/astral-sh/ruff-pre-commit
3131
# Ruff version.
32-
rev: v0.12.5
32+
rev: v0.13.1
3333
hooks:
3434
# Run the linter.
3535
- id: ruff-check
@@ -40,7 +40,7 @@ repos:
4040
stages: [pre-push]
4141

4242
- repo: https://github.com/google/addlicense
43-
rev: 55a521bf81c24480094950caa3566548fa63875e
43+
rev: v1.2.0
4444
hooks:
4545
- id: addlicense
4646
args:

newrelic/api/time_trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def _observe_exception(self, exc_info=None, ignore=None, expected=None, status_c
252252
if getattr(value, "_nr_ignored", None):
253253
return
254254

255-
module, name, fullnames, message_raw = parse_exc_info((exc, value, tb))
255+
_module, name, fullnames, message_raw = parse_exc_info((exc, value, tb))
256256
fullname = fullnames[0]
257257

258258
# In case message is in JSON format for OpenAI models

newrelic/console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def do_transactions(self):
354354
""" """
355355

356356
for item in _trace_cache.active_threads():
357-
transaction, thread_id, thread_type, frame = item
357+
transaction, _thread_id, _thread_type, _frame = item
358358
print("THREAD", item, file=self.stdout)
359359
if transaction is not None:
360360
transaction.dump(self.stdout)
@@ -460,7 +460,7 @@ def __thread_run(self):
460460
listener.listen(5)
461461

462462
while True:
463-
client, addr = listener.accept()
463+
client, _addr = listener.accept()
464464

465465
if not self.__console_initialized:
466466
self.__console_initialized = True

newrelic/core/attribute_filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ def __ge__(self, other):
209209
def __repr__(self):
210210
return f"({self.name}, {bin(self.destinations)}, {self.is_wildcard}, {self.is_include})"
211211

212+
def __hash__(self):
213+
return hash((self.name, self.destinations, self.is_include, self.is_wildcard))
214+
212215
def name_match(self, name):
213216
if self.is_wildcard:
214217
return name.startswith(self.name)

newrelic/core/stats_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ def notice_error(self, error=None, attributes=None, expected=None, ignore=None,
703703
if getattr(value, "_nr_ignored", None):
704704
return
705705

706-
module, name, fullnames, message_raw = parse_exc_info(error)
706+
_module, name, fullnames, message_raw = parse_exc_info(error)
707707
fullname = fullnames[0]
708708

709709
# In the case case of JSON formatting for OpenAI models

newrelic/hooks/datastore_memcache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _nr_datastore_trace_wrapper_(wrapped, instance, args, kwargs):
6969
result = wrapped(*args, **kwargs)
7070

7171
instance_info = transaction._nr_datastore_instance_info
72-
(host, port_path_or_id, db) = instance_info
72+
(host, port_path_or_id, _db) = instance_info
7373
dt.host = host
7474
dt.port_path_or_id = port_path_or_id
7575

newrelic/hooks/framework_tornado.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _wrap_headers_received(wrapped, instance, args, kwargs):
9191
except:
9292
pass
9393

94-
path, sep, query = start_line.path.partition("?")
94+
path, _sep, query = start_line.path.partition("?")
9595

9696
transaction = WebTransaction(
9797
application=application_instance(),

newrelic/hooks/mlmodel_sklearn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def create_prediction_event(transaction, class_, instance, args, kwargs, return_
284284
"modelName": model_name,
285285
},
286286
)
287-
features, predictions = np_casted_data_set.shape
287+
_features, _predictions = np_casted_data_set.shape
288288
for prediction_index, prediction in enumerate(np_casted_data_set):
289289
inference_id = uuid.uuid4()
290290

@@ -346,7 +346,7 @@ def wrap_metric_scorer(wrapped, instance, args, kwargs):
346346

347347
score = wrapped(*args, **kwargs)
348348

349-
y_true, y_pred, args, kwargs = _bind_scorer(*args, **kwargs)
349+
_y_true, y_pred, args, kwargs = _bind_scorer(*args, **kwargs)
350350
model_name = "Unknown"
351351
training_step = "Unknown"
352352
if hasattr(y_pred, "_nr_model_name"):

0 commit comments

Comments
 (0)