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

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

Open
shanilpanara opened this issue Feb 4, 2024 · 1 comment
Open

Comments

@shanilpanara
Copy link
Member

shanilpanara commented Feb 4, 2024

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 <[email protected]>"]
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

  • upgraded actions/checkout@v4 and actions/setup-python@v5
  • the use of poetry

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
Copy link
Member

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

@shanilpanara shanilpanara changed the title Create a simpler "project" which uses pyproject.toml and poetry Create pyproject.toml-based project (with versioningit + rye) Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants