softnanolab / softnanotools

Tools for programming
GNU General Public License v3.0
4 stars 0 forks source link

Create pyproject.toml-based project (with versioningit + rye) #34

Open shanilpanara opened 8 months ago

shanilpanara commented 8 months ago

Summary

I'd love to have a different (and simpler - i.e. less files) project template with softnanotools.generate

Different Changes

1. Tree

It would follow a tree structure like so:

.
├── .gitattributes
├── .github
│   └── workflows
│       ├── coverage.yml
│       └── quick-build.yml
├── .gitignore
├── README.md
├── nanoplot
│   └── __init__.py
├── pyproject.toml
└── test
    ├── __init__.py
    └── test_nanoplot.py

Also, what might be your thoughts on doing ./src/<repository_name> instead of ./<repository_name>?

2. pyproject.toml

Where pyproject.toml looks something like:

[tool.poetry]
name = "nanoplot"
version = "0.1.0"
description = "A python wrapper around popular plotting tools (i.e. matplotlib, seaborn...)"
authors = ["Shanil Panara <shanil.panara@nanograb.com>"]
readme = "README.md"
packages = [{include = "nanoplot"}]

[tool.poetry.dependencies]
python = ">=3.10"
softnanotools = "^0.5.1"

[tool.poetry.group.dev.dependencies]
pytest = "*"
pytest-cov = "*"
ruff = "^0.2.0"

[tool.ruff]
ignore-init-module-imports = true
select = ["D", "E", "F"]
ignore = ["D205"]
line-length = 100
target-version = "py310"

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
"docs/*" = ["D"]
"examples/*" = ["D"]
"test/*" = ["D"]
"./*.py" = ["D"]

[tool.ruff.pydocstyle]
convention = "numpy"

[tool.black]
line-length = 100
target-version = ["py310"]

3. .github/workflows/<>

And the workflows must also be updated to use higher versions of python and poetry (I will also create a separate issue for these). but putting here for completeness

Updated workflows should look like:

coverage.yml

# Builds using pip, poetry and tests using pytest

name: Coverage

on:
  push:
    branches: [main, coverage*, test*]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-python@v5
      with:
        python-version: '3.10' 
    - name: Setup environment
      run: pip install --upgrade pip poetry
    - name: Install
      run: poetry install
    - name: Add pytest and run tests
      run: poetry run pytest --cov=nanoplot --cov-report=xml
    - name: Upload coverage to Codecov
      run: |
        curl -Os https://uploader.codecov.io/latest/linux/codecov
        chmod +x codecov
        ./codecov -t ${CODECOV_TOKEN} -f coverage.xml

quick-build.yml

# Builds using pip, poetry and tests using pytest

name: Build

on: push

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        version: ['3.10', '3.11']
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.version }}
    - name: Setup environment
      run: pip install --upgrade pip poetry
    - name: Install
      run: poetry install
    - name: Ruff
      uses: chartboost/ruff-action@v1

Above: note the changes in 2 things

4. Add a dummy test (to avoid failing github CI out of the box)

Finally, (I will also create a separate issue for this), we should add test_dummy for all new projects. Otherwise the default workflow will fail because it isn't able to find any tests.

So test_<repo_name> would now be something like

#!/usr/bin/env python
"""test_nanoplot.py - auto-generated by softnanotools"""
from softnanotools.logger import Logger
logger = Logger(__name__)

def test_dummy():
    """
    >>> assert 1 == 1
    """
    logger.info("Dummy test passed")

if __name__ == '__main__':
    import doctest
    doctest.testmod()
debeshmandal commented 8 months ago

@shanilpanara Have you seen uv - seems like this could be preferred to poetry but haven't tried it myself