Skip to content

Commit

Permalink
Reformat/restyle files according to rules in .pre-commit-config.yaml
Browse files Browse the repository at this point in the history
Reformatted the files in the repository according to rules in a new
file ".pre-commit-config.yaml".  Have to install pre-commit either
through pip or conda and then "pre-commit install" to install the
git hooks.

The pre-commit lints or reformats many file types by using
separate linters and autoformaters that are installed as part of
pre-commit.

Uses "ruff" for Python files, but presently configured only for
autoformatting.  Turned off "ruff" linting because it found over
300 problems, some of which there weren't easy answers for.
  • Loading branch information
timcera committed Jul 27, 2024
1 parent 4145f6e commit 6e1cec2
Show file tree
Hide file tree
Showing 129 changed files with 42,832 additions and 95,084 deletions.
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

0 comments on commit 6e1cec2

Please sign in to comment.