Skip to content

Commit 5f3eaca

Browse files
authored
Add MegaLinter (AliceO2Group#679)
* Add MegaLinter * Fix YAML * Fix formatting * Add Flake8 config file * Check only modified files * Allow formatting commits on push events * Integrate alisw/pull-request * Comments by Timo
1 parent 0152ece commit 5f3eaca

File tree

7 files changed

+195
-50
lines changed

7 files changed

+195
-50
lines changed

.flake8

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 120
3+
extend-ignore = E203

.github/workflows/mega-linter.yml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
# MegaLinter GitHub Action configuration file
3+
# More info at https://megalinter.github.io
4+
name: MegaLinter
5+
6+
'on': [pull_request_target]
7+
8+
env: # Comment env block if you do not want to apply fixes
9+
# Apply linter fixes configuration
10+
APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)
11+
PR_NUMBER: ${{ github.event.pull_request.number }}
12+
13+
concurrency:
14+
group: ${{ github.ref }}-${{ github.workflow }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build:
19+
name: MegaLinter
20+
runs-on: ubuntu-latest
21+
steps:
22+
# Git Checkout
23+
- name: Checkout Code
24+
uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 0
27+
28+
# MegaLinter
29+
- name: MegaLinter
30+
id: ml
31+
# You can override MegaLinter flavor used to have faster performances
32+
# More info at https://megalinter.github.io/flavors/
33+
uses: megalinter/megalinter@v5
34+
env:
35+
# All available variables are described in documentation
36+
# https://megalinter.github.io/configuration/
37+
VALIDATE_ALL_CODEBASE: false # ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} # Validates all source when push on master, else just the git diff with master. Override with true if you always want to lint all sources
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
40+
# DISABLE: COPYPASTE,SPELL # Uncomment to disable copy-paste and spell checks
41+
42+
# Create or delete the cleanup branch
43+
- name: Update cleanup branch
44+
if: ${{ github.event.repository.owner.login == 'AliceO2Group' }}
45+
env:
46+
REMOTE_URL: "https://alibuild:${{ secrets.ALIBUILD_GITHUB_TOKEN }}@\
47+
github.com/alibuild/${{ github.event.repository.name }}"
48+
run: |
49+
# An empty CLEANUP_COMMIT means delete the branch.
50+
CLEANUP_COMMIT=""
51+
if [ "${{ steps.ml.outputs.has_updated_sources }}" = 1 ]
52+
then
53+
CLEANUP_COMMIT="HEAD"
54+
git commit -am "MegaLinter fixes"
55+
fi
56+
git push -f "$REMOTE_URL" "$CLEANUP_COMMIT:refs/heads/alibot-cleanup-ml-$PR_NUMBER"
57+
58+
- name: Create pull request with applied fixes
59+
uses: alisw/pull-request@v2
60+
if: steps.ml.outputs.has_updated_sources == 1 && ${{ github.event.repository.owner.login == 'AliceO2Group' }}
61+
with:
62+
source_branch: 'alibuild:alibot-cleanup-ml-${{ env.PR_NUMBER }}'
63+
destination_branch: '${{ github.event.pull_request.head.label }}'
64+
github_token: ${{ secrets.ALIBUILD_GITHUB_TOKEN }}
65+
pr_title: >-
66+
[MegaLinter] Apply linters automatic fixes to
67+
#${{ env.PR_NUMBER }}
68+
pr_body: >-
69+
Your PR ${{ github.event.repository.full_name }}#${{ env.PR_NUMBER }}
70+
cannot be merged as is. You should either run MegaLinter
71+
yourself and update the pull request, or merge this PR in yours.
72+
73+
You can find how to run MegaLinter locally at
74+
<https://megalinter.github.io/latest/mega-linter-runner/>.
75+
continue-on-error: true # We do not create PRs if the branch is not there.
76+
77+
- name: Exit with error if the PR is not clean
78+
run: |
79+
case "${{ steps.ml.outputs.has_updated_sources }}" in
80+
0) echo 'PR clean' ; exit 0 ;;
81+
1) echo 'PR not clean' ; exit 1 ;;
82+
esac

.github/workflows/stale.yml

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
---
12
name: "Close stale PRs"
23
on:
34
schedule:
4-
- cron: "0 0 * * *"
5+
- cron: "0 0 * * *"
56

67
jobs:
78
stale:
89
runs-on: ubuntu-latest
910
steps:
10-
- uses: actions/stale@v1
11-
with:
12-
repo-token: ${{ secrets.GITHUB_TOKEN }}
13-
stale-pr-message: 'This PR has not been updated in the last 30 days. Is it still needed? Unless further action is taken, it will be closed in 5 days.'
14-
stale-pr-label: stale
15-
days-before-stale: 30
16-
days-before-close: 5
11+
- uses: actions/stale@v1
12+
with:
13+
repo-token: ${{ secrets.GITHUB_TOKEN }}
14+
stale-pr-message: 'This PR has not been updated in the last 30 days. Is it still needed? Unless further action is taken, it will be closed in 5 days.'
15+
stale-pr-label: stale
16+
days-before-stale: 30
17+
days-before-close: 5

.mega-linter.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
# Configuration file for Mega-Linter
3+
# See all available variables at https://megalinter.github.io/configuration/ and in linters documentation
4+
5+
APPLY_FIXES: all # all, none, or list of linter keys
6+
DEFAULT_BRANCH: master # Usually master or main
7+
# ENABLE: # If you use ENABLE variable, all other languages/formats/tooling-formats will be disabled by default
8+
# ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default
9+
DISABLE:
10+
- C
11+
- COPYPASTE # abusive copy-pastes
12+
- SPELL # spelling mistakes
13+
DISABLE_LINTERS:
14+
- CPP_CPPLINT
15+
- BASH_EXEC
16+
- BASH_SHFMT
17+
- JSON_PRETTIER
18+
- YAML_V8R
19+
- YAML_PRETTIER
20+
SHOW_ELAPSED_TIME: true
21+
FILEIO_REPORTER: false
22+
GITHUB_COMMENT_REPORTER: false
23+
UPDATED_SOURCES_REPORTER: false
24+
PRINT_ALPACA: false # Don't print ASCII alpaca in the log

EventFiltering/PWGUD/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Checks for diffractive events and fills table `DiffractionFilters`. The table is
44

55
The diffractive event filter is contained in the following set of files:
66

7-
### cutHolder.cxx, cutHolder.h
7+
## cutHolder.cxx, cutHolder.h
88
`cutHolder` is a buffer for the various cut parameters. Is used to create a configurable which values can be set by command line options.
99

10-
### diffHelpers.h
10+
## diffHelpers.h
1111
Contains helper functions for the diffractive event selection and the actual filter logics for the various types of events. Currently implemented are:
1212

1313
- DGSelector: a filter for Double Gap (DG) events
1414

15-
### diffractionFilter.cxx
15+
## diffractionFilter.cxx
1616
Contains the actual filter tasks. Currently implemented are:
1717
- DGFilterRun3: filter task for DG events in Run 3 data

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# O2Physics
2+
13
Documentation for the ALICE Analysis framework is available at:
24

3-
https://aliceo2group.github.io/analysis-framework/
5+
<https://aliceo2group.github.io/analysis-framework/>

Scripts/update_ccdb.py

+71-38
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,35 @@
2222
TODO add support for 3 files update
2323
"""
2424

25+
import argparse
2526
import subprocess
2627
from datetime import datetime
28+
2729
import matplotlib.pyplot as plt
28-
import argparse
2930

3031

3132
def convert_timestamp(ts):
3233
"""
3334
Converts the timestamp in milliseconds in human readable format
3435
"""
35-
return datetime.utcfromtimestamp(ts/1000).strftime('%Y-%m-%d %H:%M:%S')
36+
return datetime.utcfromtimestamp(ts / 1000).strftime("%Y-%m-%d %H:%M:%S")
3637

3738

3839
def get_ccdb_obj(path, timestamp, dest="/tmp/", verbose=0):
3940
"""
4041
Gets the ccdb object from 'path' and 'timestamp' and downloads it into 'dest'
4142
"""
4243
if verbose:
43-
print("Getting obj", path, "with timestamp",
44-
timestamp, convert_timestamp(timestamp))
45-
cmd = f"o2-ccdb-downloadccdbfile --path {path} --dest {dest} --timestamp {timestamp}"
44+
print(
45+
"Getting obj",
46+
path,
47+
"with timestamp",
48+
timestamp,
49+
convert_timestamp(timestamp),
50+
)
51+
cmd = (
52+
f"o2-ccdb-downloadccdbfile --path {path} --dest {dest} --timestamp {timestamp}"
53+
)
4654
subprocess.run(cmd.split())
4755

4856

@@ -61,7 +69,7 @@ def get_ccdb_obj_validity(path, dest="/tmp/", verbose=0):
6169
print(*output, "\n")
6270
print("err:")
6371
print(error)
64-
result = list(filter(lambda x: x.startswith('Valid-'), output))
72+
result = list(filter(lambda x: x.startswith("Valid-"), output))
6573
ValidFrom = result[0].split()
6674
ValidUntil = result[1].split()
6775
return [int(ValidFrom[-1]), int(ValidUntil[-1])]
@@ -71,12 +79,18 @@ def upload_ccdb_obj(path, timestamp_from, timestamp_until, dest="/tmp/", meta=""
7179
"""
7280
Uploads a new object to CCDB in the 'path' using the validity timestamp specified
7381
"""
74-
print("Uploading obj", path, "with timestamp", [timestamp_from, timestamp_until],
75-
convert_timestamp(timestamp_from), convert_timestamp(timestamp_until))
82+
print(
83+
"Uploading obj",
84+
path,
85+
"with timestamp",
86+
[timestamp_from, timestamp_until],
87+
convert_timestamp(timestamp_from),
88+
convert_timestamp(timestamp_until),
89+
)
7690
key = path.split("/")[-1]
7791
cmd = f"o2-ccdb-upload -f {dest}{path}/snapshot.root "
7892
cmd += f"--key {key} --path {path} "
79-
cmd += f"--starttimestamp {timestamp_from} --endtimestamp {timestamp_until} --meta \"{meta}\""
93+
cmd += f'--starttimestamp {timestamp_from} --endtimestamp {timestamp_until} --meta "{meta}"'
8094
subprocess.run(cmd.split())
8195

8296

@@ -87,9 +101,9 @@ def main(path, timestamp_from, timestamp_until, verbose=0, show=False):
87101
Gets the object from CCDB specified in 'path' and for 'timestamp_until+1'
88102
If required plots the situation before and after the update
89103
"""
90-
get_ccdb_obj(path, timestamp_from-1)
104+
get_ccdb_obj(path, timestamp_from - 1)
91105
val_before = get_ccdb_obj_validity(path, verbose=verbose)
92-
get_ccdb_obj(path, timestamp_until+1)
106+
get_ccdb_obj(path, timestamp_until + 1)
93107
val_after = get_ccdb_obj_validity(path, verbose=verbose)
94108
overlap_before = val_before[1] > timestamp_from
95109
overlap_after = val_after[0] < timestamp_until
@@ -98,48 +112,67 @@ def main(path, timestamp_from, timestamp_until, verbose=0, show=False):
98112
print("Previous objects overalps")
99113
if overlap_after:
100114
print("Next objects overalps")
101-
trimmed_before = val_before if not overlap_before else [
102-
val_before[0], timestamp_from - 1]
103-
trimmed_after = val_after if not overlap_after else [
104-
timestamp_until+1, val_after[1]]
115+
trimmed_before = (
116+
val_before if not overlap_before else [val_before[0], timestamp_from - 1]
117+
)
118+
trimmed_after = (
119+
val_after if not overlap_after else [timestamp_until + 1, val_after[1]]
120+
)
105121
if show:
106122
fig, ax = plt.subplots()
107123
fig
108124

109125
def bef_af(v, y):
110126
return [v[0] - 1] + v + [v[1] + 1], [0, y, y, 0]
127+
111128
if True:
112-
ax.plot(*bef_af(val_before, 0.95), label='before')
113-
ax.plot(*bef_af(val_after, 1.05), label='after')
129+
ax.plot(*bef_af(val_before, 0.95), label="before")
130+
ax.plot(*bef_af(val_after, 1.05), label="after")
114131
if False:
115-
ax.plot(*bef_af(trimmed_before, 0.9), label='trimmed before')
116-
ax.plot(*bef_af(trimmed_after, 1.1), label='trimmed after')
117-
ax.plot(*bef_af([timestamp_from, timestamp_until], 1), label='object')
132+
ax.plot(*bef_af(trimmed_before, 0.9), label="trimmed before")
133+
ax.plot(*bef_af(trimmed_after, 1.1), label="trimmed after")
134+
ax.plot(*bef_af([timestamp_from, timestamp_until], 1), label="object")
118135
xlim = 10000000
119-
plt.xlim([timestamp_from-xlim, timestamp_until+xlim])
136+
plt.xlim([timestamp_from - xlim, timestamp_until + xlim])
120137
plt.ylim(0, 2)
121-
plt.xlabel('Timestamp')
122-
plt.ylabel('Validity')
138+
plt.xlabel("Timestamp")
139+
plt.ylabel("Validity")
123140
plt.legend()
124141
plt.show()
125142

126143

127144
if __name__ == "__main__":
128145
parser = argparse.ArgumentParser(
129-
description="Uploads timestamp non overlapping objects to CCDB."
130-
"Basic example: `./update_ccdb.py qc/TOF/TOFTaskCompressed/hDiagnostic 1588956517161 1588986517161 --show --verbose`")
131-
parser.add_argument('path', metavar='path_to_object', type=str,
132-
help='Path of the object in the CCDB repository')
133-
parser.add_argument('timestamp_from', metavar='from_timestamp', type=int,
134-
help='Timestamp of start for the new object to use')
135-
parser.add_argument('timestamp_until', metavar='until_timestamp', type=int,
136-
help='Timestamp of stop for the new object to use')
137-
parser.add_argument('--verbose', '-v', action='count', default=0)
138-
parser.add_argument('--show', '-s', action='count', default=0)
146+
description="Uploads timestamp non overlapping objects to CCDB. "
147+
"Basic example: `./update_ccdb.py qc/TOF/TOFTaskCompressed/hDiagnostic "
148+
"1588956517161 1588986517161 --show --verbose`"
149+
)
150+
parser.add_argument(
151+
"path",
152+
metavar="path_to_object",
153+
type=str,
154+
help="Path of the object in the CCDB repository",
155+
)
156+
parser.add_argument(
157+
"timestamp_from",
158+
metavar="from_timestamp",
159+
type=int,
160+
help="Timestamp of start for the new object to use",
161+
)
162+
parser.add_argument(
163+
"timestamp_until",
164+
metavar="until_timestamp",
165+
type=int,
166+
help="Timestamp of stop for the new object to use",
167+
)
168+
parser.add_argument("--verbose", "-v", action="count", default=0)
169+
parser.add_argument("--show", "-s", action="count", default=0)
139170

140171
args = parser.parse_args()
141-
main(path=args.path,
142-
timestamp_from=args.timestamp_from,
143-
timestamp_until=args.timestamp_until,
144-
verbose=args.verbose,
145-
show=args.show)
172+
main(
173+
path=args.path,
174+
timestamp_from=args.timestamp_from,
175+
timestamp_until=args.timestamp_until,
176+
verbose=args.verbose,
177+
show=args.show,
178+
)

0 commit comments

Comments
 (0)