plenoptic-org / plenoptic

Visualize/test models for visual representation by synthesizing images.
https://plenoptic.readthedocs.io/en/latest/
MIT License
61 stars 9 forks source link

Consistent formatting (Python Black) #51

Open billbrod opened 4 years ago

billbrod commented 4 years ago

Given that we have different authors with different styles, our formatting/conventions are not consistent. We should look into using something like yapf or black to make our code consistent and maybe pydocstyle for our documentation.

billbrod commented 3 years ago

As part of this, also:

billbrod commented 3 years ago

After everything else has stabilized, run this on everything.

NickleDave commented 10 months ago

Chiming in here from the pyOpenSci review.
We do require this--indirectly--by asking that linting checks pass.
As you comment above, I would address other issues first and then add linting. There are many ways to skin this cat, see https://learn.scientific-python.org/development/guides/style/ I use a nox session so anyone can run linting checks locally without learning the pre-commit CLI but you could also just let contributors remain mostly blissfully ignorant of linting, and run pre-commit in CI on PRs, etc. How you do it is up to you but there should be some linting checks.

billbrod commented 9 months ago

I'm also looking into ruff for this, which might be nicer.

As mentioned above, will need linters to be added to CI as well (see #190 )

hmd101 commented 4 months ago

Summary of Considerations so far:

We are currently looking at Ruff, nox and pre-commit hook to introduce formatting conventions. Below is a list of considerations aimed at guiding the decision process, as well as a list of their respective configurations and a brief explanation of each.

Ruff Linting:

Flake8:

Considered Configurations for Ruff:

(in pyproject.toml; Legend: ✅: common and included, ❓ common but not included)

TL;DR:

More details:

Nox & Pre-commit Hooks:

TL;DR:

Nox

Nox is a Python-based task runner that is used to automate various development workflows, such as testing, building, and deploying applications. It allows you to define sessions, which are Python functions in the noxfile.py decorated with @nox.session with various parameters, such as name, by which these sessions can then be executed via the command line. This easily allows to test code by running pre-defined tasks with a single command across multiple Python versions without manually setting up environments.

Example: Based on the following noxfile.py , the command nox -s tests would run the session named "tests” below. nox without any commands would run all the sessions defined in the noxfile.py .

@nox.session(name="tests", python=["3.10", "3.11", "3.12"])
def tests(session):
    # run tests
    session.install("pytest")
    session.run("pytest")

Pre-Commit

Hook: A pre-commit hook can be added to run Ruff linting on code before it is committed. This ensures that developers catch and fix linting issues early in the development process. It only runs when installed and can be bypassed with git commit -m <my commit message> --no-verify.

Considered Configurations: (in .pre-commit.yaml: (Legend: ✅: included, ❓: recommended, but not included)

CI Pipeline:

Finally, the CI configuration ci.yml has been updated to include a step each for running Ruff formatting and linting check on all new commits and pull requests. Two separate actions were chosen to signal the developer which combination of the two might be causing an error.

hmd101 commented 1 month ago

Now, that the ruff linter and formatter have been introduced (see PR #266), possible next steps to consider are as follows:

Note that if additional linting rules are to be introduced (e.g., B), each rule should be introduced in a separate PR. Therefore, we may want to consider closing this big issue and using my notes below and putting them in separate smaller issues.

Next steps:

0. restructure contributing file (see issue #296)

1.Ruff Linting

Include the following linting rules (in pyproject.toml ) and resolve linting errors:

2. Nox:

We might want to consider to include nox sessions for:

3. Pre-commit

We might want to add the following to .pre-commit-config.yaml :