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

Apply ruff formatting and linting along with relevant refactoring #371

Merged
merged 16 commits into from
Mar 2, 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
6 changes: 5 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": ["ms-python.python", "ms-python.vscode-pylance"]
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"charliermarsh.ruff"
]
}
}
}
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.6"
hooks:
- id: black
language_version: python3.9
- id: ruff
exclude: tutorials/nbconverted/
- id: ruff-format
exclude: tutorials/nbconverted/
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
Expand Down
34 changes: 23 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ If you are stuck, please feel free to ask any questions or ask for help.
- [Dev environments](#dev-environments)
- [Releases](#releases)

[Style guides](#style-guides)
[Code Quality](#code-quality)

- [Formatting](#formatting)
- [Linting](#linting)
- [Git commit messages](#git-commit-messages)
- [Python style guide](#python-style-guide)
- [Documentation style guide](#documentation-style-guide)
Expand Down Expand Up @@ -189,23 +191,33 @@ Creating a new release includes the following steps:
11. The release will be automatically published to [PyPI](https://pypi.org/project/pycytominer/) via Github Actions.
12. Manually create the release at [conda-forge](https://anaconda.org/conda-forge/pycytominer).

## Style guides
## Code Quality

Please follow all style guides to the best of your abilities.
Please follow the below quality guides to the best of your abilities.
If you have configured your [dev environment](#dev-environments) as described above, the formatting and linting rules will also be enforced automatically using the installed [pre-commit](https://pre-commit.com/) hooks.

### Formatting

We use [ruff](https://docs.astral.sh/ruff/) for formatting Python code, and [prettier](https://prettier.io/) for formatting markdown, json and yaml files.
Ruff includes a python code formatter similar to Black.
We include `ruff` in the poetry dev dependencies so it can be run manually using `ruff format`
Prettier (which is not python-based) is not included in the poetry dev dependencies, but can be installed and run manually.
Alternately, both `ruff format` and `prettier` will be run automatically at commit time with the pre-commit hooks installed.

### Linting

For python code linting, we also use [ruff](https://docs.astral.sh/ruff/), which can perform same linting checks as Flake8.
You can use the command `ruff check` to check for linting errors.
The list of linting rules and exceptions are defined in the `pyproject.toml` file under the `[tool.ruff.lint]` section.
We also include some commented-out rules in that section that we are working towards enabling in the future.
All linting checks will also be run automatically at commit time with the pre-commit hooks as described above.

### Git commit messages

Pycytominer uses [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard for commit messages to aid in automatic changelog generation.
We prepare commit messages that follow this standard using [commitizen](https://commitizen-tools.github.io/commitizen/), which comes with the poetry dev dependencies.

### Python style guide

For python code style, we use [black](https://github.com/psf/black).
Please use black before committing any code.
We will not accept code contributions that do not use black.
Configuring your [dev environment](#dev-environments) as described above will ensure your code is formatted correctly automatically (using a tool called [pre-commit](https://pre-commit.com/)).

### Documentation style guide

We use the [numpy documentation style guide](https://numpydoc.readthedocs.io/en/latest/format.html).
We also use [prettier](https://prettier.io/) for automatic formatting of markdown, json and yaml files.
When writing markdown documentation, please also ensure that each sentence is on a new line.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![Build Status](https://github.com/cytomining/pycytominer/actions/workflows/integration-test.yml/badge.svg?branch=main)](https://github.com/cytomining/pycytominer/actions/workflows/integration-test.yml?query=branch%3Amain)
[![Coverage Status](https://codecov.io/gh/cytomining/pycytominer/branch/main/graph/badge.svg)](https://codecov.io/github/cytomining/pycytominer?branch=main)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![RTD](https://readthedocs.org/projects/pycytominer/badge/?version=latest&style=flat)](https://pycytominer.readthedocs.io/)
[![DOI](https://img.shields.io/badge/DOI-10.48550/arXiv.2311.13417-blue)](https://doi.org/10.48550/arXiv.2311.13417)

Expand Down
8 changes: 3 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@
#
import os
import sys
import pathlib
import dunamai
from datetime import date

sys.path.insert(0, os.path.abspath(".."))

import pycytominer
# Ignore rules regarding import order which is required for sphinx build process
import pycytominer # noqa: E402, RUF100

# -- Project information -----------------------------------------------------

project = pycytominer.__about__.__project__
author = pycytominer.__about__.__author__
copyright = "Copyright 2019 - {date} {author}".format(
date=date.today().year, author=author
)
project_copyright = f"Copyright 2019 - {date.today().year} {author}"

# Get the version from dunamai (the backend of poetry-dynamic-versioning)
auto_version = dunamai.Version.from_git()
Expand Down
Loading
Loading