BjornFJohansson / pydna

Clone with Python! Data structures for double stranded DNA & simulation of homologous recombination, Gibson assembly, cut & paste cloning.
Other
166 stars 45 forks source link

Style #196

Closed BjornFJohansson closed 3 months ago

BjornFJohansson commented 9 months ago

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 commented 9 months ago

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

BjornFJohansson commented 9 months ago

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

manulera commented 9 months ago

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 commented 8 months ago

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

manulera commented 8 months ago

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?

BjornFJohansson commented 8 months ago

Will do

BjornFJohansson commented 8 months ago

69b7ec7083 on the dev_bjorn branch has the instructions.

for installing it is simply

pip install pre-commit

manulera commented 7 months ago

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 https://github.com/BjornFJohansson/pydna/commit/69b7ec7083621303f3317f6f0601e255656a7fcb containted the instructions, but I can't see a README with those instructions anymore. Maybe this commit got lost?

BjornFJohansson commented 6 months ago

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