Skip to content

Commit

Permalink
Lint and fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
d-chambers committed Nov 17, 2024
1 parent 1bd99c9 commit 442f076
Show file tree
Hide file tree
Showing 137 changed files with 1,925 additions and 7,819 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ jobs:
if: github.event_name == 'push' || !contains(github.event.pull_request.labels.*.name, 'no_ci')

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: "get tags"
run: |
git fetch --tags --force # Retrieve annotated tags.
- name: Install uv
uses: astral-sh/setup-uv@v3

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: install linting packages
run: pip install pre-commit
run: uv tool install pre-commit

- name: run all precommits
run: pre-commit run flake8 --files src/**/*
run: uv run pre-commit run --all
46 changes: 32 additions & 14 deletions .github/workflows/on_master_commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ jobs:
with:
fetch-depth: 0 # need this so tags are pulled and versions work

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
- uses: mamba-org/setup-micromamba@v1
with:
miniconda-version: 'latest'
python-version: "3.10"
activate-environment: test
environment-file: .github/test_conda_env.yml
condarc-file: .github/test_condarc.yml
micromamba-version: '1.5.8-0' # versions: https://github.com/mamba-org/micromamba-releases
environment-file: .github/workflows/test_conda_env.yml
init-shell: >-
bash
powershell
cache-environment: true
post-cleanup: 'all'

# Not sure why this is needed but it appears to be the case
- name: fix env
shell: bash -l {0}
run: |
micromamba shell init --shell bash --root-prefix=~/micromamba
eval "$(micromamba shell hook --shell bash)"
micromamba activate test
- name: install obsplus
shell: bash -l {0}
Expand Down Expand Up @@ -58,14 +67,23 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
- uses: mamba-org/setup-micromamba@v1
with:
miniconda-version: 'latest'
python-version: "3.9"
activate-environment: test
environment-file: .github/test_conda_env.yml
condarc-file: .github/test_condarc.yml
micromamba-version: '1.5.8-0' # versions: https://github.com/mamba-org/micromamba-releases
environment-file: .github/workflows/test_conda_env.yml
init-shell: >-
bash
powershell
cache-environment: true
post-cleanup: 'all'

# Not sure why this is needed but it appears to be the case
- name: fix env
shell: bash -l {0}
run: |
micromamba shell init --shell bash --root-prefix=~/micromamba
eval "$(micromamba shell hook --shell bash)"
micromamba activate test
- name: install obsplus
shell: bash -l {0}
Expand Down
45 changes: 29 additions & 16 deletions .github/workflows/release_published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ jobs:
with:
fetch-depth: 0 # need this so tags are pulled and versions work

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
- uses: mamba-org/setup-micromamba@v1
with:
miniconda-version: 'latest'
python-version: "3.10"
activate-environment: test
environment-file: .github/test_conda_env.yml
condarc-file: .github/test_condarc.yml
micromamba-version: '1.5.8-0' # versions: https://github.com/mamba-org/micromamba-releases
environment-file: .github/workflows/test_conda_env.yml
init-shell: >-
bash
powershell
cache-environment: true
post-cleanup: 'all'

- name: install obsplus
# Not sure why this is needed but it appears to be the case
- name: fix env
shell: bash -l {0}
run: |
pip install -e .[dev]
micromamba shell init --shell bash --root-prefix=~/micromamba
eval "$(micromamba shell hook --shell bash)"
micromamba activate test
- name: git config
shell: bash -l {0}
Expand Down Expand Up @@ -54,14 +58,23 @@ jobs:
with:
fetch-depth: 0 # need this so tags are pulled and versions work

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
- uses: mamba-org/setup-micromamba@v1
with:
miniconda-version: 'latest'
python-version: "3.10"
activate-environment: test
environment-file: .github/test_conda_env.yml
condarc-file: .github/test_condarc.yml
micromamba-version: '1.5.8-0' # versions: https://github.com/mamba-org/micromamba-releases
environment-file: .github/workflows/test_conda_env.yml
init-shell: >-
bash
powershell
cache-environment: true
post-cleanup: 'all'

# Not sure why this is needed but it appears to be the case
- name: fix env
shell: bash -l {0}
run: |
micromamba shell init --shell bash --root-prefix=~/micromamba
eval "$(micromamba shell hook --shell bash)"
micromamba activate test
- name: install obsplus
shell: bash -l {0}
Expand Down
38 changes: 16 additions & 22 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,23 @@ jobs:
with:
fetch-depth: 0 # need this so tags are pulled and versions work

- name: Get year week
id: date
run: echo "date=$(date +'%Y:%U')" >> $GITHUB_STATE

- name: setup conda env
uses: conda-incubator/[email protected]
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: test
use-mamba: true
python-version: ${{ matrix.python-version }}

- name: Cache conda env
uses: actions/cache@v3
- uses: mamba-org/setup-micromamba@v1
with:
path: ${{ env.prefix }}
key: ${{ env.cache_key }}-hash${{ hashFiles(env.env_file) }}-${{ steps.date.outputs.date }}-${{ env.CACHE_NUMBER }}
id: cache

- name: Update environment
run: mamba env update -n test -f ${{ env.env_file }}
if: steps.cache.outputs.cache-hit != 'true'
micromamba-version: '1.5.8-0' # versions: https://github.com/mamba-org/micromamba-releases
environment-file: .github/workflows/test_conda_env.yml
init-shell: >-
bash
powershell
cache-environment: true
post-cleanup: 'all'

# Not sure why this is needed but it appears to be the case
- name: fix env
shell: bash -l {0}
run: |
micromamba shell init --shell bash --root-prefix=~/micromamba
eval "$(micromamba shell hook --shell bash)"
micromamba activate test
- name: install obsplus
shell: bash -l {0}
Expand Down
41 changes: 22 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
exclude: scripts/_templates
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
- id: check-merge-conflict
- id: mixed-line-ending
args: ['--fix=lf']

# Ruff is a replacement for flake8 and many other linters (much faster too)
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.8
hooks:
- id: black
language_version: python3
- repo: https://github.com/asottile/blacken-docs
rev: v1.10.0
- id: ruff
args: ["--fix"]
# Run the formatter.
- id: ruff-format

# ensures __future__ import annotations at top of files which require it
# for the typing features they are using.
- repo: https://github.com/frostming/fix-future-annotations
rev: 0.5.0
hooks:
- id: blacken-docs
additional_dependencies: [black==21.5b1]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-black
- flake8-breakpoint
- flake8-docstrings
- id: fix-future-annotations

# strips out all outputs from notebooks.
- repo: https://github.com/kynan/nbstripout
rev: 0.3.9
rev: 0.6.1
hooks:
- id: nbstripout
files: ".ipynb"
8 changes: 5 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
Sphinx configuration for ObsPlus doc build.
"""
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# obsplus documentation build configuration file, created by
# sphinx-quickstart
Expand All @@ -15,7 +17,7 @@

import datetime
import sys
from os.path import dirname, abspath
from os.path import abspath, dirname

year = datetime.datetime.now().year

Expand All @@ -34,7 +36,7 @@
# version is used.
sys.path.insert(0, project_root)

import obsplus
import obsplus # noqa

# load the datasets used by docs here so notebooks don't have to
obsplus.load_dataset("crandall_test")
Expand Down
10 changes: 6 additions & 4 deletions docs/notebooks/datasets/datasets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"outputs": [],
"source": [
"import obspy\n",
"\n",
"import obsplus\n",
"ds = obsplus.load_dataset('crandall_test')"
"\n",
"ds = obsplus.load_dataset(\"crandall_test\")"
]
},
{
Expand Down Expand Up @@ -128,8 +130,8 @@
"source": [
"from pathlib import Path\n",
"\n",
"obsplus.copy_dataset('crandall_test', '.')\n",
"path = Path('.') / 'crandall_test'\n",
"obsplus.copy_dataset(\"crandall_test\", \".\")\n",
"path = Path(\".\") / \"crandall_test\"\n",
"assert path.exists() and path.is_dir()"
]
},
Expand Down Expand Up @@ -169,7 +171,7 @@
"import shutil\n",
"from pathlib import Path\n",
"\n",
"path = Path('crandall_test')\n",
"path = Path(\"crandall_test\")\n",
"if path.exists():\n",
" shutil.rmtree(path)"
]
Expand Down
15 changes: 6 additions & 9 deletions docs/notebooks/datastructures/events_to_pandas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
"metadata": {},
"outputs": [],
"source": [
"import obspy\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"from obspy.clients.fdsn import Client\n",
"\n",
"import obsplus"
]
Expand All @@ -35,7 +32,7 @@
"metadata": {},
"outputs": [],
"source": [
"crandall = obsplus.load_dataset('crandall_test')\n",
"crandall = obsplus.load_dataset(\"crandall_test\")\n",
"cat = crandall.event_client.get_events()\n",
"ev_df = obsplus.events_to_df(cat)\n",
"\n",
Expand Down Expand Up @@ -112,7 +109,7 @@
"outputs": [],
"source": [
"# calculate the max pick_time for each event\n",
"picks.groupby('event_id')['time'].max()"
"picks.groupby(\"event_id\")[\"time\"].max()"
]
},
{
Expand All @@ -129,20 +126,20 @@
"outputs": [],
"source": [
"# get only P picks\n",
"df = picks[picks.phase_hint.str.upper() == 'P']\n",
"df = picks[picks.phase_hint.str.upper() == \"P\"]\n",
"\n",
"# add columns for travel time\n",
"df['travel_time'] = df['time'] - df['event_time']\n",
"df[\"travel_time\"] = df[\"time\"] - df[\"event_time\"]\n",
"\n",
"# filter out stations that aren't used at least 3 times\n",
"station_count = df['station'].value_counts()\n",
"station_count = df[\"station\"].value_counts()\n",
"stations_with_three = station_count[station_count > 2]\n",
"\n",
"# only include picks that are used on at least 3 stations\n",
"df = df[df.station.isin(stations_with_three.index)]\n",
"\n",
"# get stats of travel times\n",
"df.groupby('station')['travel_time'].describe()"
"df.groupby(\"station\")[\"travel_time\"].describe()"
]
},
{
Expand Down
Loading

0 comments on commit 442f076

Please sign in to comment.