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

Style #196

Open
BjornFJohansson opened this issue Feb 2, 2024 · 9 comments
Open

Style #196

BjornFJohansson opened this issue Feb 2, 2024 · 9 comments

Comments

@BjornFJohansson
Copy link
Owner

I use pre-commit https://pre-commit.com with this settings file: .pre-commit-config.yaml

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.5.0
  hooks:
  - id: no-commit-to-branch
    args: [--branch, master]
  - id: check-yaml
  - id: end-of-file-fixer
  - id: trailing-whitespace
  - id: debug-statements
  - id: fix-encoding-pragma
  - id: mixed-line-ending
- repo: https://github.com/ambv/black
  rev: 23.12.1
  hooks:
  - id: black
- repo: https://github.com/PyCQA/flake8
  rev: 7.0.0
  hooks:
  - id: flake8
exclude: scripts/|docs/|tests/

This autoformats the code before each commit. The pyproject.toml contains:

[tool.black]
line-length = 119
target-version = ["py38", "py39", "py310", "py311", "py312"]
include = '\.pyi?$'

This means that the line lenght will be 119 which I think is used by the django project.

@manulera , do you agree with this ocr do you have another suggestion?

@manulera
Copy link
Collaborator

manulera commented Feb 5, 2024

Hi @BjornFJohansson, sounds good to me. This was not yet implement in dev_bjorn, right?

@BjornFJohansson
Copy link
Owner Author

Yes I run this before every commit. This means that the code is formatted automatically. Not nicer everywhere, but should be consistent.

@manulera
Copy link
Collaborator

manulera commented Feb 9, 2024

Hi @BjornFJohansson I wonder if there are better ways to do this that don't involve asking the users to install pre-commit. We could add black and flake8 as dev dependencies, and set up a git hook that runs on commit. This SO comment explains how this can be set up.

The advantage of something like this is that we can create a separate file with the rules we want black and flake8 to implement that are also interpreted by the IDE as you write. The IDE would show you the syntax suggestions in real time, and also allow you to format on save, what do you think? I have done this before with a repo.

Also, we could add a github action to check syntax if tests pass?

@BjornFJohansson
Copy link
Owner Author

Sounds like a good idea. Do you have this running already?

@manulera
Copy link
Collaborator

manulera commented Mar 4, 2024

I can give it a go eventually, I will assign myself to the issue.

In the meantime, can you include the instructions on how to install pre-commit and use it in the readme?

@manulera manulera self-assigned this Mar 4, 2024
@BjornFJohansson
Copy link
Owner Author

Will do

@BjornFJohansson
Copy link
Owner Author

69b7ec7 on the dev_bjorn branch has the instructions.

for installing it is simply

pip install pre-commit

@manulera
Copy link
Collaborator

Hi @BjornFJohansson I have some suggestions on how to incorporate this in poetry, so that it comes as you do poetry install. In pyproject.toml:

[tool.poetry.group.dev.dependencies]
autopep8 = "^2.1.0"
black = "^24.4.1"
flake8-bugbear = [
  {version = ">=24.4.21", python = ">=3.8.1"},
]
pre-commit = [
  {version = ">3.6", python = ">=3.9"},
  {version = "<3.6", python = "<3.9"},
]

Let me know where should I target with my PR, and I will add this. Also, you mentioned that 69b7ec7 containted the instructions, but I can't see a README with those instructions anymore. Maybe this commit got lost?

@BjornFJohansson
Copy link
Owner Author

Hi, Ill have a look and get back to you asap.

manulera added a commit that referenced this issue May 13, 2024
@manulera manulera mentioned this issue May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants