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

Ruff for linting/formatting #26

Merged
merged 8 commits into from
Apr 30, 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
4 changes: 0 additions & 4 deletions .devcontainer/Dockerfile

This file was deleted.

10 changes: 0 additions & 10 deletions .devcontainer/README.md

This file was deleted.

47 changes: 0 additions & 47 deletions .devcontainer/devcontainer.json

This file was deleted.

11 changes: 0 additions & 11 deletions .devcontainer/env.yaml

This file was deleted.

5 changes: 5 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ jobs:
python -m pip install --upgrade pip
pip install ".[dev]"

- name: Lint (ruff)
run: |
ruff check
ruff format --check

- name: Test with pytest
run: |
pytest
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.2
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
12 changes: 3 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.formatting.provider": "none",
"editor.formatOnSave": true,
"python.formatting.blackArgs": [
"--line-length=120"
],
"python.languageServer": "Pylance",
"python.linting.lintOnSave": true,
"python.testing.unittestEnabled": false,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
}
}
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# rashdf
Read data from HEC-RAS HDF files.
[![CI](https://github.com/fema-ffrd/rashdf/actions/workflows/continuous-integration.yml/badge.svg?branch=main)](https://github.com/fema-ffrd/rashdf/actions/workflows/continuous-integration.yml)
[![Release](https://github.com/fema-ffrd/rashdf/actions/workflows/release.yml/badge.svg)](https://github.com/fema-ffrd/rashdf/actions/workflows/release.yml)
[![PyPI version](https://badge.fury.io/py/rashdf.svg)](https://badge.fury.io/py/rashdf)

## Setup
Read data from [HEC-RAS](https://www.hec.usace.army.mil/software/hec-ras/) [HDF](https://github.com/HDFGroup/hdf5) files.

*Pronunciation: `raz·aitch·dee·eff`*

## Install
A prerelease version of `rashdf` is available from PyPI:
```bash
$ pip install rashdf=0.1.0b1
```

## Developer Setup
Create a virtual environment in the project directory:
```
$ python -m venv venv-rashdf
Expand All @@ -13,6 +25,16 @@ $ source ./venv/bin/activate
(venv-rashdf) $
```

Install dev dependencies:
```
(venv-rashdf) $ pip install ".[dev]"
```

Install git hook scripts (used for automatic liniting/formatting)
```
(venv-rashdf) $ pre-commit install
```

With the virtual environment activated, run the tests:
```
(venv-rashdf) $ pytest
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ version = "0.1.0-beta.1"
dependencies = ["h5py", "geopandas"]

[project.optional-dependencies]
dev = ["pytest"]
dev = ["pre-commit", "ruff", "pytest"]

[project.urls]
repository = "https://github.com/fema-ffrd/rashdf"
Expand Down
2 changes: 2 additions & 0 deletions src/rashdf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .base import RasHdf
from .geom import RasGeomHdf
from .plan import RasPlanHdf

__all__ = ["RasHdf", "RasGeomHdf", "RasPlanHdf"]
11 changes: 7 additions & 4 deletions src/rashdf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RasHdf(h5py.File):

def __init__(self, name: str, **kwargs):
"""Open a HEC-RAS HDF file.

Parameters
----------
name : str
Expand All @@ -17,7 +17,9 @@ def __init__(self, name: str, **kwargs):
super().__init__(name, mode="r", **kwargs)

@classmethod
def open_uri(cls, uri: str, fsspec_kwargs: dict = {}, h5py_kwargs: dict = {}) -> 'RasHdf':
def open_uri(
cls, uri: str, fsspec_kwargs: dict = {}, h5py_kwargs: dict = {}
) -> "RasHdf":
"""Open a HEC-RAS HDF file from a URI.

Parameters
Expand All @@ -40,6 +42,7 @@ def open_uri(cls, uri: str, fsspec_kwargs: dict = {}, h5py_kwargs: dict = {}) ->
--------
>>> results_hdf = RasHdf.open_uri("s3://my-bucket/results.hdf")
"""
import fsspec
import fsspec # type: ignore

remote_file = fsspec.open(uri, mode="rb", **fsspec_kwargs)
return cls(remote_file.open(), **h5py_kwargs)
return cls(remote_file.open(), **h5py_kwargs)
Loading