Skip to content

Commit

Permalink
pre-commit formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
lcvl41 committed Dec 2, 2024
1 parent f7a4d41 commit 3aacb76
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 18 deletions.
5 changes: 3 additions & 2 deletions .github/scripts/generate_pip_deps_from_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
$ python scripts/generate_pip_deps_from_conda.py --compare
"""

import argparse
import pathlib
import re
import sys

if sys.version_info >= (3, 11):
import tomllib
pass
else:
import tomli as tomllib
pass
import yaml

EXCLUDE = {"python"}
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ jobs:
environment-file: environment.yml
use-mamba: true
python-version: "3.9"

- shell: bash -l {0}
run: |
conda info
conda list
- name: Install snowlaps-emulator
shell: bash -l {0}
run: |
pip install -e .
- name: Checkout code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0
fetch-depth: 0

- name: Run tests and generate coverage report
shell: bash -l {0}
run: |
Expand All @@ -58,4 +58,3 @@ jobs:
# snyk test --file=dev-requirements.txt --package-manager=pip --severity-threshold=high
# env:
# SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

77 changes: 77 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
ci:
autofix_prs: false
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
exclude: \.txt$
- id: trailing-whitespace # Remove trailing
# whitespaces
- id: check-merge-conflict
# Fix common spelling mistakes
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: [
'--ignore-words-list', 'alos,inout,vor',
'--ignore-regex', '\bnin\b',
'--'
]
types_or: [python, markdown] # rst,
files: ^(snowlaps|tests)/ # docs

# Replace relative imports
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.1
hooks:
# Run the linter.
- id: ruff
types_or: [ python, pyi ]
args: ["check", "--fix" ]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi ]

# Format the code aggressively using black
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
args: [--line-length=88]

# Automatically upgrade syntax to a minimum version
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py37-plus]

# Various formattings
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
# Eval should never be used (can do arbitrary code
# execution)
- id: python-no-eval
# Enforce the use of type annotations instead of
# docstring type comments
- id: python-use-type-annotations


- repo: local
hooks:
# Generate pip's dev-requirements.txt from conda's
# dev-environment.yml to run snyk (snyk doesn't currently
# support conda)
- id: pip-to-conda
name: Generate pip dependency from conda
language: python
entry: .github/scripts/generate_pip_deps_from_conda.py
files: ^(dev-environment.yml|requirements-dev.txt)$
pass_filenames: false
additional_dependencies: [tomli, pyyaml]
7 changes: 3 additions & 4 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ cd snowlaps

* Contributions

Any contribution to =snowlaps= is welcome! Feel free to add new issues, open pull requests or ask questions in the discussion forum.
Any contribution to =snowlaps= is welcome! Feel free to add new issues, open pull requests or ask questions in the discussion forum.

* Citation

If you use this code, please cite the associated publication:

Chevrollier, L.-A., Wehrlé, A., Cook, J. M., Pirk, N., Benning, L. G., Anesio, A. M., and Tranter, M.: Separating the albedo reducing effect of different light absorbing particles on snow using deep learning, EGUsphere [preprint], https://doi.org/10.5194/egusphere-2024-2583, 2024.
If you use this code, please cite the associated publication:

Chevrollier, L.-A., Wehrlé, A., Cook, J. M., Pirk, N., Benning, L. G., Anesio, A. M., and Tranter, M.: Separating the albedo reducing effect of different light absorbing particles on snow using deep learning, EGUsphere [preprint], https://doi.org/10.5194/egusphere-2024-2583, 2024.
7 changes: 3 additions & 4 deletions data/inputs/snicar_config_for_emulator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ IMPURITIES:
COATED: False
UNIT: 0
CONC: [0 ,0]

SA:
NAME: "sa"
FILE: "snow_algae_empirical_Chevrollier2023.nc"
COATED: False
UNIT: 1
CONC: [0 ,0]
CONC: [0 ,0]

DUST:
NAME: "dust"
Expand All @@ -85,7 +85,7 @@ PLOT:
SAVE: False
SAVEPATH: "./"

BIOOPTICAL:
BIOOPTICAL:
WET_DENSITY: 1060
DRY_DENSITY: 684
ABS_CFF_CALC: True
Expand Down Expand Up @@ -130,4 +130,3 @@ BIOOPTICAL:
SAVE_PATH_NETCDF: "Data/OP_data/480band/lap/"
INFO_NETCDF: "info"
FILENAME_NETCDF: "alg"

2 changes: 1 addition & 1 deletion examples/snowlaps_ex03_compare_with_biosnicar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""
NOTE: this script requires an installation of the main branch of the biosnicar
NOTE: this script requires an installation of the main branch of the biosnicar
model (https://github.com/jmcook1186/biosnicar-py/tree/master)
"""
Expand Down
18 changes: 18 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# let Black deal with line length, Ruff currently doesn't autofix E501
line-length = 150

[lint]
select = [
# pycodestyle
"E",
# Pyflakes
"F",
# pyupgrade
"UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
# isort
"I",
]
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ exclude = test*

[options.entry_points]
console_scripts =
snowlaps-cli = snowlaps.snowlaps:SnowLapsEmulator
snowlaps-cli = snowlaps.snowlaps:SnowLapsEmulator
1 change: 1 addition & 0 deletions tests/test_snowlaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from snowlaps.snowlaps import SnowlapsEmulator


class TestSnowlapsEmulator:
my_emulator = SnowlapsEmulator()

Expand Down

0 comments on commit 3aacb76

Please sign in to comment.