-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from tangkong/mnt_pre_commit
MNT/STY/TST: Add pre-commit hooks, CI job, standardize style
- Loading branch information
Showing
18 changed files
with
530 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[flake8] | ||
exclude = .git,__pycache__,build,dist, | ||
max-line-length = 88 | ||
select = C,E,F,W,B,B950 | ||
extend-ignore = E203, E501, E226, W503, W504 | ||
|
||
# Explanation section: | ||
# B950 | ||
# This takes into account max-line-length but only triggers when the value | ||
# has been exceeded by more than 10% (96 characters). | ||
# E203: Whitespace before ':' | ||
# This is recommended by black in relation to slice formatting. | ||
# E501: Line too long (82 > 79 characters) | ||
# Our line length limit is 88 (above 79 defined in E501). Ignore it. | ||
# E226: Missing whitespace around arithmetic operator | ||
# This is a stylistic choice which you'll find everywhere in pcdsdevices, for | ||
# example. Formulas can be easier to read when operators and operands | ||
# have no whitespace between them. | ||
# | ||
# W503: Line break occurred before a binary operator | ||
# W504: Line break occurred after a binary operator | ||
# flake8 wants us to choose one of the above two. Our choice | ||
# is to make no decision. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: PCDS Standard Testing | ||
|
||
on: | ||
push: | ||
pull_request: | ||
release: | ||
types: | ||
- created | ||
|
||
jobs: | ||
get_changed_files: | ||
name: "get_changed_files" | ||
runs-on: ubuntu-20.04 | ||
outputs: | ||
PROJECT_FILES: ${{ steps.changed_files.outputs.PROJECT_FILES }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
submodules: 'recursive' | ||
|
||
- name: Find all changed files | ||
id: changed_files | ||
if: ${{ github.event_name == 'pull_request' }} | ||
run: | | ||
# Fancy method of saying: | ||
# * What files changed from this PR (the current checked out HEAD) | ||
# * To the base that we're merging into (e.g., origin/master) | ||
# Note that ACMRT = added/copied/modified/renamed/type change | ||
# See more in `man git-diff-tree` under `--diff-filter` | ||
git diff-tree --no-commit-id --name-only --diff-filter=ACM -r -z origin/${{ github.base_ref }} HEAD \ | ||
| tee "$HOME/project_files.txt" | ||
if [ ! -s "$HOME/project_files.txt" ]; then | ||
echo "No source code files changed in this PR. Checking the entire repository." | ||
find "." -print0 -type f \ | ||
> "$HOME/project_files.txt" | ||
fi | ||
# replace nulls with spaces | ||
sed -i 's/\x0/ /g' $HOME/project_files.txt | ||
# set output | ||
echo "PROJECT_FILES=$(<$HOME/project_files.txt)" >> "$GITHUB_OUTPUT" | ||
pre-commit: | ||
needs: | ||
- get_changed_files | ||
name: 'pre-commit checks' | ||
uses: pcdshub/pcds-ci-helpers/.github/workflows/pre-commit.yml@master | ||
with: | ||
args: "--files ${{ needs.get_changed_files.outputs.PROJECT_FILES }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.4.0 | ||
hooks: | ||
- id: no-commit-to-branch | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-ast | ||
- id: check-case-conflict | ||
- id: check-json | ||
- id: check-merge-conflict | ||
- id: check-symlinks | ||
- id: check-xml | ||
- id: check-yaml | ||
exclude: '^(conda-recipe/meta.yaml)$' | ||
- id: debug-statements | ||
|
||
- repo: https://github.com/shellcheck-py/shellcheck-py | ||
rev: v0.10.0.1 | ||
hooks: | ||
- id: shellcheck | ||
args: [-x] # allow source files outside of checked files | ||
|
||
- repo: https://github.com/pycqa/flake8.git | ||
rev: 6.0.0 | ||
hooks: | ||
- id: flake8 | ||
|
||
- repo: https://github.com/timothycrosley/isort | ||
rev: 5.11.5 | ||
hooks: | ||
- id: isort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
disable=SC1091 # allow sourcing files that can't immediately be found (pcds_conda) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,16 @@ | |
Script for the detector group to pull totals out of the elog. | ||
We get DAQ run parameters for all experiments and count them up. | ||
""" | ||
import sys | ||
import logging | ||
import argparse | ||
import logging | ||
import sys | ||
from collections import OrderedDict | ||
import requests | ||
import pytz | ||
|
||
import dateutil.parser as dateparser | ||
import pytz | ||
import requests | ||
from krtc import KerberosTicket | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
krbheaders = KerberosTicket("[email protected]").getAuthHeaders() | ||
tz = pytz.timezone('America/Los_Angeles') | ||
|
@@ -57,10 +57,11 @@ def getExperiments(run_period, after, before): | |
except those whose first run is after the specified time | ||
""" | ||
resp = requests.get( | ||
f"{lgbkprefix}/ws/experiments", | ||
params={"categorize": "instrument_runperiod", | ||
"sortby": "name"}, | ||
headers=krbheaders).json() | ||
f"{lgbkprefix}/ws/experiments", | ||
params={"categorize": "instrument_runperiod", | ||
"sortby": "name"}, | ||
headers=krbheaders | ||
).json() | ||
exps = [] | ||
for k, v in resp["value"].items(): | ||
insexps = map(lambda x: x["_id"], v.get("Run " + str(run_period), [])) | ||
|
@@ -73,27 +74,29 @@ def first_run_exists(exp): | |
return exp.get("first_run", {}).get("begin_time", None) | ||
|
||
def last_run_before_specified_after(exp): | ||
return exp.get("last_run", {}).get("begin_time", None) \ | ||
and dateparser.parse(exp["last_run"]["begin_time"])\ | ||
.astimezone(tz) < after | ||
return (exp.get("last_run", {}).get("begin_time", None) | ||
and dateparser.parse(exp["last_run"]["begin_time"]) | ||
.astimezone(tz) < after) | ||
|
||
def first_run_after_specified_before(exp): | ||
return exp.get("first_run", {}).get("begin_time", None) \ | ||
and dateparser.parse(exp["first_run"]["begin_time"])\ | ||
.astimezone(tz) > before | ||
return (exp.get("first_run", {}).get("begin_time", None) | ||
and dateparser.parse(exp["first_run"]["begin_time"]).astimezone(tz) > before) | ||
|
||
sef = None | ||
if after and before: | ||
sef = lambda x: last_run_exists(x) \ | ||
and not last_run_before_specified_after(x) \ | ||
and first_run_exists(x) \ | ||
and not first_run_after_specified_before(x) | ||
def sef(x): | ||
return (last_run_exists(x) | ||
and not last_run_before_specified_after(x) | ||
and first_run_exists(x) | ||
and not first_run_after_specified_before(x)) | ||
elif after: | ||
sef = lambda x: last_run_exists(x) \ | ||
and not last_run_before_specified_after(x) | ||
def sef(x): | ||
return (last_run_exists(x) | ||
and not last_run_before_specified_after(x)) | ||
elif before: | ||
sef = lambda x: first_run_exists(x) \ | ||
and not first_run_after_specified_before(x) | ||
def sef(x): | ||
return (first_run_exists(x) | ||
and not first_run_after_specified_before(x)) | ||
|
||
if sef: | ||
expsset = set(exps) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.