Skip to content
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
82 changes: 11 additions & 71 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,24 @@ on:
branches:
- master

# https://jacobian.org/til/github-actions-poetry/
jobs:
flake8-lint:
run-tests:
name: python
runs-on: ubuntu-latest
name: Lint
steps:
- name: Check out source repository
uses: actions/checkout@v2
- name: Set up Python environment
uses: actions/setup-python@v1
with:
python-version: "3.9"
- name: flake8 Lint
uses: py-actions/flake8@v2
with:
# custom ignores start at w504, before are the default ones
ignore: "E121,E123,E126,E226,E24,E704,W503,W504,E203,E402,E501,F401,F841"
exclude: "logs/*,data/*,furuta/logging/protobuf/*"

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# If you wanted to use multiple Python versions, you'd have specify a matrix in the job and
# reference the matrixe python version here.
- uses: actions/setup-python@v5
with:
python-version: 3.9

# Cache the installation of Poetry itself, e.g. the next step. This prevents the workflow
# from installing Poetry every time, which can be slow. Note the use of the Poetry version
# number in the cache key, and the "-0" suffix: this allows you to invalidate the cache
# manually if/when you want to upgrade Poetry, or if something goes wrong. This could be
# mildly cleaner by using an environment variable, but I don't really care.
- name: cache poetry install
uses: actions/cache@v4
with:
path: ~/.local
key: poetry-1.4.0-0

# Install Poetry. You could do this manually, or there are several actions that do this.
# `snok/install-poetry` seems to be minimal yet complete, and really just calls out to
# Poetry's default install script, which feels correct. I pin the Poetry version here
# because Poetry does occasionally change APIs between versions and I don't want my
# actions to break if it does.
#
# The key configuration value here is `virtualenvs-in-project: true`: this creates the
# venv as a `.venv` in your testing directory, which allows the next step to easily
# cache it.
- uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-create: true
virtualenvs-in-project: true

# Cache your dependencies (i.e. all the stuff in your `pyproject.toml`). Note the cache
# key: if you're using multiple Python versions, or multiple OSes, you'd need to include
# them in the cache key. I'm not, so it can be simple and just depend on the poetry.lock.
- name: cache deps
id: cache-deps
uses: actions/cache@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
enable-cache: true

# Install dependencies. `--no-root` means "install all dependencies but not the project
# itself", which is what you want to avoid caching _your_ code. The `if` statement
# ensures this only runs on a cache miss.
- run: poetry install --no-interaction --no-root
if: steps.cache-deps.outputs.cache-hit != 'true'
- name: Install the project
run: uv sync --locked --all-extras --dev

# Now install _your_ project. This isn't necessary for many types of projects -- particularly
# things like Django apps don't need this. But it's a good idea since it fully-exercises the
# pyproject.toml and makes that if you add things like console-scripts at some point that
# they'll be installed and working.
- run: poetry install --no-interaction
- name: Lint
run: uv run pre-commit run --all-files --config ./.pre-commit-config.yaml

# And finally run tests. I'm using pytest and all my pytest config is in my `pyproject.toml`
# so this line is super-simple. But it could be as complex as you need.
- run: poetry run pytest
- name: Run tests
run: uv run pytest tests
49 changes: 4 additions & 45 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v5.0.0
hooks:
# list of supported hooks: https://pre-commit.com/hooks.html
- id: trailing-whitespace
Expand All @@ -19,35 +19,21 @@ repos:

# python code formatting
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 25.1.0
hooks:
- id: black
args: [--line-length, "99"]

# python import sorting
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 6.0.1
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

# python upgrading syntax to newer version
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
hooks:
- id: pyupgrade
args: [--py38-plus]

# python docstring formatting
- repo: https://github.com/myint/docformatter
rev: v1.7.5
hooks:
- id: docformatter
args: [--in-place, --wrap-summaries=99, --wrap-descriptions=99]

# python check (PEP8), programming errors and code complexity
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 7.3.0
hooks:
- id: flake8
args:
Expand All @@ -57,30 +43,3 @@ repos:
"--exclude",
"logs/*,data/*,furuta/logging/protobuf/*",
]

# yaml formatting
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
types: [yaml]
# # jupyter notebook cell output clearing
# - repo: https://github.com/kynan/nbstripout
# rev: 0.5.0
# hooks:
# - id: nbstripout

# # jupyter notebook linting
# - repo: https://github.com/nbQA-dev/nbQA
# rev: 1.4.0
# hooks:
# - id: nbqa-black
# args: ["--line-length=99"]
# - id: nbqa-isort
# args: ["--profile=black"]
# - id: nbqa-flake8
# args:
# [
# "--extend-ignore=E203,E402,E501,F401,F841",
# "--exclude=logs/*,data/*",
# ]
2 changes: 1 addition & 1 deletion furuta/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class SimpleLogger:
def __init__(self, log_path: (str | Path)):
def __init__(self, log_path: str | Path):
self.output_file = open(log_path, "wb")
self.mcap_writer = Writer(self.output_file)

Expand Down
2 changes: 1 addition & 1 deletion furuta/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, times: np.ndarray, states: dict[str, np.ndarray]):
self.states = states

@classmethod
def from_log_path(cls, log_path: (str | Path)) -> "Plotter":
def from_log_path(cls, log_path: str | Path) -> "Plotter":
loader = Loader()
times, states = loader.load(log_path)
return cls(times, states)
Expand Down
Loading