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

Establish Python project template used throughout repos. #5

Open
yakutovicha opened this issue Nov 16, 2022 · 5 comments
Open

Establish Python project template used throughout repos. #5

yakutovicha opened this issue Nov 16, 2022 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@yakutovicha
Copy link
Member

yakutovicha commented Nov 16, 2022

Currently, there are multiple ways a Python project can be organized.

Here are the choices

Currently, I am working on a Python cookie-cutter repository to establish those. The issue is to be closed when all choices are made and the template repository reflects them.

The cookie-cutter repository will be largely based on https://github.com/woltapp/wolt-python-package-cookiecutter. I will also create an accompanying template similar to https://github.com/simonw/python-lib-template-repository. The idea is that the latter takes the cookie-cutter one, fills in the values and annihilates himself (see this file for the details).

@yakutovicha
Copy link
Member Author

I believe a lot of inspiration can be taken from this blog post. Not only do they have a nice python-project template, but also they are able to perform bulk actions on already created repositories

@yakutovicha
Copy link
Member Author

setuptools vs flint.

Flit is very simple to set up, it has built-in git integration (no need for the MANIFEST file anymore), and it reads version/description directly from the package __init__.py. So one doesn't need to set the version in multiple places.

So, it seems that for the pure python packages - flit is a better choice.

@yakutovicha
Copy link
Member Author

yakutovicha commented Jan 5, 2023

.pre-commit-config.yaml

I would propose using the following configuration:

---
ci:
    autoupdat_schedule: quarterly

repos:
    - repo: https://github.com/pre-commit/pre-commit-hooks
      rev: v4.4.0
      hooks:
          - id: end-of-file-fixer
            exclude: ^.*data/
          - id: trailing-whitespace
            exclude: miscellaneous/structures/SiO2.xyz
          - id: check-yaml
          - id: check-added-large-files
    - repo: https://github.com/pycqa/isort
      rev: 5.12.0
      hooks:
          - id: isort
            args: [--profile, black, --filter-files]
    - repo: https://github.com/PyCQA/autoflake
      rev: v2.1.1
      hooks:
          - id: autoflake
    - repo: https://github.com/asottile/pyupgrade
      rev: v3.4.0
      hooks:
          - id: pyupgrade
            args: [--py38-plus]
    - repo: https://github.com/psf/black
      rev: 23.3.0
      hooks:
          - id: black
            language_version: python3 # Should be a command that runs python3.6+
    - repo: https://github.com/PyCQA/flake8
      rev: 6.0.0
      hooks:
          - id: flake8
            args: [--count, --show-source, --statistics]
            additional_dependencies:
                - flake8-bugbear
                - flake8-builtins
                - flake8-comprehensions
                - flake8-debugger
                - flake8-logging-format
                - pep8-naming
                - pyflakes
                - tryceratops
    - repo: https://github.com/pre-commit/mirrors-mypy
      rev: v1.3.0
      hooks:
          - id: mypy
            additional_dependencies:
                - types-click-spinner
                - types-requests
                - types-tabulate
                - types-toml
    - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
      rev: 0.2.3
      hooks:
          - id: yamlfmt

if the repo contains notebooks, it makes sense to add the following

    - repo: https://github.com/kynan/nbstripout
      rev: 0.6.1
      hooks:
          - id: nbstripout

    - repo: https://github.com/nbQA-dev/nbQA
      rev: 1.7.0
      hooks:
          - id: nbqa-pyupgrade
            args: [--py38-plus]
          - id: nbqa-isort
            args: [--profile=black]
          - id: nbqa-black

if the repo contains setup.cfg, add the following

    - repo: https://github.com/asottile/setup-cfg-fmt
      rev: v2.2.0
      hooks:
          - id: setup-cfg-fmt

@yakutovicha
Copy link
Member Author

Flake8 configuration file.

It would be great, of course, to make the config below a part of the pyproject.toml. Unfortunately, this is not possible. Nevertheless, this is the content of .flake8 (needed mostly due to the conflicts with black):

[flake8]
extend-ignore =
    E501
    W503
    E203

@yakutovicha
Copy link
Member Author

yakutovicha commented Feb 6, 2023

There is also black for notebooks. Here is a nice way to configure it:

aiidalab/aiidalab-qe#396

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant