Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added .pre-commit-config.yaml with coding standard rules enforced at each commit #174

Merged
merged 1 commit into from
Aug 14, 2024
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
169 changes: 88 additions & 81 deletions .github/workflows/hsp2-pip-install-test.yml
Original file line number Diff line number Diff line change
@@ -1,87 +1,94 @@
---
name: Python application

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master", "develop", "develop-specact" ]
on: # yamllint disable-line rule:truthy
push:
branches: [master]
pull_request:
branches: [master, develop, develop-specact]

permissions:
contents: read
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "pip"
- name: Install dependencies
run: |
pip install flake8
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --ignore=F821 --show-source --statistics --exclude=build/*
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

test-pytest:
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
pandas-version: [""]
include:
- python-version: "3.11"
pandas-version: "pandas>2.0"
coverage: true
- python-version: "3.11"
pandas-version: "pandas>1.5,<2.0"
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install hsp2
run: |
# install the hsp2 executable
pip install .[dev]
- if: ${{ matrix.pandas-version }}
run: pip install "${{ matrix.pandas-version }}"
- if: ${{ matrix.coverage }}
run: |
# python coverage
NUMBA_DISABLE_JIT=1 pytest --cov --cov-branch --cov-report term-missing
- if: ${{ ! matrix.coverage }}
run: pytest

test-cmd:
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install hsp2
run: |
# install the hsp2 executable
pip install .
- name: Run hsp2
run: |
# TODO: find much shorter test case.
hsp2 import_uci ./tests/test10/HSP2results/test10.uci _temp_test10.h5
hsp2 run _temp_test10.h5

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: pip
- name: Install dependencies
run: |
pip install flake8
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or
# undefined names
flake8 . --count --select=E9,F63,F7,F82 --ignore=F821 \
--show-source --statistics --exclude=build/*
# exit-zero treats all errors as warnings.
# The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 \
--max-line-length=127 --statistics

test-pytest:
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
pandas-version: ['']
include:
- python-version: '3.11'
pandas-version: pandas>2.0
coverage: true
- python-version: '3.11'
pandas-version: pandas>1.5,<2.0
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install hsp2
run: |
# install the hsp2 executable
pip install .[dev]
- if: ${{ matrix.pandas-version }}
run: pip install "${{ matrix.pandas-version }}"
- if: ${{ matrix.coverage }}
run: |
# python coverage
NUMBA_DISABLE_JIT=1 pytest --cov --cov-branch --cov-report \
term-missing
- if: ${{ ! matrix.coverage }}
run: pytest

test-cmd:
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install hsp2
run: |
# install the hsp2 executable
pip install .
- name: Run hsp2
run: |
# TODO: find much shorter test case.
hsp2 import_uci \
./tests/test10/HSP2results/test10.uci \
_temp_test10.h5
hsp2 run _temp_test10.h5
96 changes: 96 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

exclude: |
(?x)^(
.*\.hbn|
.*\.wdm|
.*\.hdf5|
.*\.h5
)$

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-toml
- id: check-xml
- id: end-of-file-fixer
exclude: notebooks/tstoolbox_plot_bash.sh
- id: fix-encoding-pragma
args: [--remove]
- id: mixed-line-ending
- id: trailing-whitespace
exclude: notebooks/tstoolbox_plot_bash.sh

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.5
hooks:
# Run the linter.
# Uncomment the following lines to enable the linter.
# Right now way to many things fail.
# - id: ruff
# types_or: [python, pyi, jupyter]
# args: [--fix]

# Run the linter sort imports.
- id: ruff
types_or: [python, pyi, jupyter]
args: [--select, I, --fix]

# Run the formatter.
- id: ruff-format
types_or: [python, pyi, jupyter]

- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
- id: toml-sort-fix
args: [--in-place, --spaces-indent-inline-array, '4']

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
args: [--format, parsable, --strict]

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.3
hooks:
- id: yamlfmt

- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: shellcheck
args: [-s, bash]

- repo: https://github.com/lovesegfault/beautysh
rev: v6.2.1
hooks:
- id: beautysh
args: [--indent-size, '4']

- repo: https://github.com/asottile/blacken-docs
rev: 1.18.0
hooks:
- id: blacken-docs

- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade

- repo: https://github.com/commitizen-tools/commitizen
rev: v3.28.0
hooks:
- id: commitizen
stages: [commit-msg]
33 changes: 18 additions & 15 deletions HSP2_Driver.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import os, sys
import os
import sys

# print('in HSP2_Driver')
command_line = ""
# print('arg count ' + str(len(sys.argv)))
if len(sys.argv) >= 2:
# see if anything on command line
command_line = sys.argv[1]
print('command line' + command_line)
print("command line" + command_line)

# if given UCI, import to h5 file
# if given WDM, import to h5 file
# if given h5, run HSP2

from PyQt5.QtWidgets import QFileDialog, QApplication
from PyQt5.QtWidgets import QApplication, QFileDialog

application = QApplication(sys.argv)

if command_line == '':
file_filter = "Run HDF5 (*.h5) Full Output;;" \
"Run HDF5 (*.h5) Light Output;;" \
"Import UCI to HDF5 (*.uci);;" \
"Import WDM to HDF5 (*.wdm)"
filename, filetype = QFileDialog.getOpenFileName(None, 'HSP2 Open File...', '', file_filter)
if command_line == "":
file_filter = (
"Run HDF5 (*.h5) Full Output;;"
"Run HDF5 (*.h5) Light Output;;"
"Import UCI to HDF5 (*.uci);;"
"Import WDM to HDF5 (*.wdm)"
)
filename, filetype = QFileDialog.getOpenFileName(
None, "HSP2 Open File...", "", file_filter
)
else:
filename = command_line
filetype = ''
filetype = ""

file_ext = filename[-3:]
dir_name = os.path.dirname(filename)
Expand All @@ -33,12 +38,14 @@
if file_ext.upper() == "UCI":
h5_name = filename[:-3] + "h5"
from hsp2.hsp2tools.readUCI import readUCI

readUCI(filename, h5_name)
# readUCI('HSPF.uci', 'test.h5')

if file_ext.upper() == "WDM":
h5_name = filename[:-3] + "h5"
from hsp2.hsp2tools.readWDM import readWDM

readWDM(filename, h5_name)
# readWDM('GRICM.wdm', 'test.h5')
# readWDM('ZUMBROSCEN.WDM', 'test.h5')
Expand All @@ -52,11 +59,7 @@
io_manager = IOManager(hdf5_instance)

SaveLevel = True
if 'Light' in filetype:
if "Light" in filetype:
SaveLevel = False
main(io_manager, saveall=SaveLevel, jupyterlab=False)
# main('test.h5', saveall=True)




Loading
Loading