diff --git a/.cursorignore b/.cursorignore new file mode 100644 index 0000000..675d8d4 --- /dev/null +++ b/.cursorignore @@ -0,0 +1,21 @@ +*.json +*.csv +*.txt +*.md +*.ipynb +*.Rmd +*.Rproj +*.Rproj.user +*.parquet +*.ckpt +*.h5ad +site/ +*.lamindb +*.lndb +*.out +*.html +*.pdf +*.npy +*.npz +*.whl +*.gz diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 1e9d2a1..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,12 +0,0 @@ -# These are supported funding model platforms - -github: [rochacbruno] -patreon: # Replace with a single Patreon username -open_collective: # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 28a2255..0c8c59c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,12 +18,12 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.9] + python-version: [3.11] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install UV @@ -38,12 +38,12 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.9] + python-version: [3.11] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install UV @@ -54,6 +54,9 @@ jobs: run: uv run task test - name: "Upload coverage to Codecov" uses: codecov/codecov-action@v3 + with: + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} # with: # fail_ci_if_error: true @@ -62,12 +65,12 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.9] + python-version: [3.11] os: [macos-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install UV @@ -82,12 +85,12 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.9] + python-version: [3.11] os: [windows-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install Pip diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c38b48e..9af5053 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: permissions: contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: # by default, it uses a depth of 1 # this fetches all history so that we can read each commit @@ -32,21 +32,19 @@ jobs: deploy: needs: release - runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + python-version: ["3.11"] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + - uses: actions/checkout@v4 + - name: Install uv + uses: astral-sh/setup-uv@v3 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Build and publish + run: | + uv build && uv publish -u __token__ -p ${{ secrets.POETRY_TOKEN }} diff --git a/.gitignore b/.gitignore index 2d0fadb..62d9600 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,5 @@ dmypy.json # templates .github/templates/* + +.DS_Store diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0d0dd72..7b14d02 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,7 +87,6 @@ clean: ## Clean unused files. virtualenv: ## Create a virtual environment. release: ## Create a new tag for release. docs: ## Build the documentation. -switch-to-poetry: ## Switch to poetry package manager. init: ## Initialize the project based on an application template. ``` diff --git a/Containerfile b/Containerfile index 83bb605..df32a3d 100644 --- a/Containerfile +++ b/Containerfile @@ -1,5 +1,5 @@ -FROM python:3.7-slim +FROM python:3.11-slim COPY . /app WORKDIR /app -RUN pip install . +RUN uv sync --all-extras --dev CMD ["project_name"] diff --git a/LICENSE b/LICENSE index fdddb29..346d86c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,24 +1,21 @@ -This is free and unencumbered software released into the public domain. +MIT License -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. +Copyright (c) 2024 jérémie kalfon, laura cantini, gabriel peyré -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -For more information, please refer to +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 21f444c..153e812 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,6 @@ A low dependency and really simple to start project template for Python Projects. -See also -- [Flask-Project-Template](https://github.com/rochacbruno/flask-project-template/) for a full feature Flask project including database, API, admin interface, etc. -- [FastAPI-Project-Template](https://github.com/rochacbruno/fastapi-project-template/) The base to start an openapi project featuring: SQLModel, Typer, FastAPI, JWT Token Auth, Interactive Shell, Management Commands. - ### HOW TO USE THIS TEMPLATE > **DO NOT FORK** this is meant to be used from **[Use this template](https://github.com/rochacbruno/python-project-template/generate)** feature. @@ -25,28 +21,19 @@ See also ### What is included on this template? -- 🖼️ Templates for starting multiple application types: - * **Basic low dependency** Python program (default) [use this template](https://github.com/rochacbruno/python-project-template/generate) - * **Flask** with database, admin interface, restapi and authentication [use this template](https://github.com/rochacbruno/flask-project-template/generate). - **or Run `make init` after cloning to generate a new project based on a template.** -- 📦 A basic [setup.py](setup.py) file to provide installation, packaging and distribution for your project. +- 📦 A basic [pyproject.toml](pyproject.toml) file to provide installation, packaging and distribution for your project. Template uses setuptools because it's the de-facto standard for Python packages, you can run `make switch-to-poetry` later if you want. -- 🤖 A [Makefile](Makefile) with the most useful commands to install, test, lint, format and release your project. - 📃 Documentation structure using [mkdocs](http://www.mkdocs.org) - 💬 Auto generation of change log using **gitchangelog** to keep a HISTORY.md file automatically based on your commit history on every release. - 🐋 A simple [Containerfile](Containerfile) to build a container image for your project. `Containerfile` is a more open standard for building container images than Dockerfile, you can use buildah or docker with this file. - 🧪 Testing structure using [pytest](https://docs.pytest.org/en/latest/) -- ✅ Code linting using [flake8](https://flake8.pycqa.org/en/latest/) +- ✅ Code linting using [ruff]() - 📊 Code coverage reports using [codecov](https://about.codecov.io/sign-up/) -- 🛳️ Automatic release to [PyPI](https://pypi.org) using [twine](https://twine.readthedocs.io/en/latest/) and github actions. +- 🛳️ Automatic release to [PyPI](https://pypi.org) using [uv] and github actions. - 🎯 Entry points to execute your program using `python -m ` or `$ project_name` with basic CLI argument parsing. - 🔄 Continuous integration using [Github Actions](.github/workflows/) with jobs to lint, test and release your project on Linux, Mac and Windows environments. -> Curious about architectural decisions on this template? read [ABOUT_THIS_TEMPLATE.md](ABOUT_THIS_TEMPLATE.md) -> If you want to contribute to this template please open an [issue](https://github.com/rochacbruno/python-project-template/issues) or fork and send a PULL REQUEST. - -[❤️ Sponsor this project](https://github.com/sponsors/rochacbruno/) diff --git a/config/main.yml b/config/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/data/main/nothing.parquet b/data/main/nothing.parquet new file mode 100644 index 0000000..e69de29 diff --git a/data/mine/nothing.parquet b/data/mine/nothing.parquet new file mode 100644 index 0000000..e69de29 diff --git a/makefile b/makefile new file mode 100644 index 0000000..8a01aa5 --- /dev/null +++ b/makefile @@ -0,0 +1,89 @@ +.ONESHELL: +ENV_PREFIX=$(shell python -c "if __import__('pathlib').Path('.venv/bin/pip').exists(): print('.venv/bin/')") +USING_POETRY=$(shell grep "tool.poetry" pyproject.toml && echo "yes") + +.PHONY: help +help: ## Show the help. + @echo "Usage: make " + @echo "" + @echo "Targets:" + @fgrep "##" Makefile | fgrep -v fgrep + + +.PHONY: show +show: ## Show the current environment. + @echo "Current environment:" + @echo "Running using $(ENV_PREFIX)" + @$(ENV_PREFIX)python -V + @$(ENV_PREFIX)python -m site + +.PHONY: install +install: ## Install the project in dev mode. + $(ENV_PREFIX)uv sync --all-extras --dev + +.PHONY: fmt +fmt: ## Format code using black & isort. + $(ENV_PREFIX)uv run ruff format project_name/ tests/ + +.PHONY: lint +lint: ## Run pep8, black, mypy linters. +#most are due to flashattention... + $(ENV_PREFIX)uv run ruff check --fix project_name/ tests/ + +.PHONY: test +test: lint ## Run tests and generate coverage report. + $(ENV_PREFIX)uv run pytest -v --cov-config .coveragerc --cov=project_name -l --tb=short --maxfail=1 tests/ + $(ENV_PREFIX)uv run coverage xml + $(ENV_PREFIX)uv run coverage html + +.PHONY: clean +clean: ## Clean unused files. + @find ./ -name '*.pyc' -exec rm -f {} \; + @find ./ -name '__pycache__' -exec rm -rf {} \; + @find ./ -name 'Thumbs.db' -exec rm -f {} \; + @find ./ -name '*~' -exec rm -f {} \; + @rm -rf .cache + @rm -rf .pytest_cache + @rm -rf .mypy_cache + @rm -rf build + @rm -rf dist + @rm -rf *.egg-info + @rm -rf htmlcov + @rm -rf .tox/ + @rm -rf docs/_build + +.PHONY: virtualenv +virtualenv: ## Create a virtual environment. + @echo "creating virtualenv ..." + @rm -rf .venv + @uv venv + @source .venv/bin/activate + @make install + @echo "!!! Please run 'source .venv/bin/activate' to enable the environment !!!" + +.PHONY: release +release: ## Create a new tag for release. + @echo "WARNING: This operation will create s version tag and push to github" + @read -p "Version? (provide the next x.y.z semver) : " TAG + @echo "$${TAG}" > project_name/VERSION + @sed -i 's/^version = .*/version = "'$${TAG}'"/' pyproject.toml + @sed -i 's/__version__ = .*/__version__ = "'$${TAG}'"/' project_name/__init__.py + @$(ENV_PREFIX)gitchangelog > HISTORY.md + @git add project_name/VERSION HISTORY.md pyproject.toml + @git commit -m "release: version $${TAG} 🚀" + @echo "creating git tag : $${TAG}" + @git tag $${TAG} + @git push -u origin HEAD --tags + @echo "Github Actions will detect the new tag and release the new version." + @mkdocs gh-deploy + @echo "Documentation deployed to https://author_name.github.io/project_name/" + +.PHONY: docs +docs: ## Build the documentation. + @echo "building documentation ..." + @$(ENV_PREFIX)mkdocs build + URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL || open $$URL + +.PHONY: init +init: ## Initialize the project based on an application template. + @./.github/init.sh diff --git a/notebooks/example.ipynb b/notebooks/example.ipynb new file mode 100644 index 0000000..e69de29 diff --git a/notebooks/test_notebooks/test.ipynb b/notebooks/test_notebooks/test.ipynb new file mode 100644 index 0000000..c55a287 --- /dev/null +++ b/notebooks/test_notebooks/test.ipynb @@ -0,0 +1,10 @@ +{ + "cells": [], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/project_name/__init__.py b/project_name/__init__.py index e69de29..9b7ff20 100644 --- a/project_name/__init__.py +++ b/project_name/__init__.py @@ -0,0 +1,3 @@ +from importlib.metadata import version + +__version__ = version("project_name") diff --git a/pyproject.toml b/pyproject.toml index badd361..c542a99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "project_name" version = "0.1.0" description = "project_description" readme = "README.md" -requires-python = ">=3.8" +requires-python = ">=3.10" authors = [ { name = "author_name", email = "author_email@exemplo.com" } ] @@ -18,15 +18,12 @@ dependencies = [ [project.urls] homepage = "https://github.com/author_name/project_urlname/" -# Dependências de produção (adicione suas dependências aqui quando necessário) [dependency-groups] dev = [] -# Scripts de entrada [project.scripts] project_name = "project_name.__main__:main" -# Dependências opcionais para desenvolvimento e testes [project.optional-dependencies] test = [ "pip-tools", @@ -38,6 +35,13 @@ test = [ "pytest-cov", "mypy", "gitchangelog", + "codecov", + "mkdocs>=1.5.3", + "mkdocs-git-revision-date-localized-plugin>=1.0.0", + "mkdocstrings>=0.22.0", + "mkdocs-git-authors-plugin>=0.4.0", + "mkdocs-jupyter>=0.2.0", + "mkdocstrings-python>=0.10.0", ] [tool.pytest.ini_options] @@ -46,14 +50,40 @@ addopts = "-ra -q -vv" pythonpath = ["/tests"] [tool.ruff] -line-length = 79 +line-length = 88 indent-width = 4 -target-version = "py310" +target-version = "py311" + +[tool.ruff.lint] +select = ["E", "F", "I"] +ignore = ["E501", "E203", "E266", "E265", "F401", "F403", "E722", "E741", "E731", "E721"] [tool.taskipy.tasks] -lint = "uvx ruff check tests" +lint = "uvx ruff check --fix tests/ project_name/" +install = "uv sync --all-extras --dev" +fmt = "uvx ruff format hackaton_owkin_gbm/ tests/" test = """ - uv run --extra test pytest -s - uv run --extra test coverage xml - uv run --extra test coverage html + uvx --extra test pytest -s -v --cov-config .coveragerc --cov=hackaton_owkin_gbm -l --tb=short --maxfail=1 tests/ + uvx --extra test coverage xml + uvx --extra test coverage html + """ +show = """ + python -V + python -m site + """ +clean = """ + find . -type d -name "__pycache__" -exec rm -rf {} + + find . -type f -name "*.pyc" -delete + find . -type f -name ".coverage" -delete + find . -type f -name "coverage.xml" -delete + find . -type d -name "htmlcov" -exec rm -rf {} + + find . -type d -name ".pytest_cache" -exec rm -rf {} + + find . -type d -name ".mypy_cache" -exec rm -rf {} + + find . -type d -name "dist" -exec rm -rf {} + + find . -type d -name "build" -exec rm -rf {} + + find . -type d -name "*.egg-info" -exec rm -rf {} + + """ +docs = """ + mkdocs build + python -c "import webbrowser; webbrowser.open('site/index.html')" """ diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 0000000..dbf270a --- /dev/null +++ b/tools/README.md @@ -0,0 +1,3 @@ +# Tools used for the project + +typically other packages as gitmodules that cannot be installed easily with uv \ No newline at end of file