From 9ae26e2e3bf2bf4e95e32b9c615f49de3f120cf8 Mon Sep 17 00:00:00 2001 From: edouardbruelhart Date: Mon, 11 Nov 2024 11:25:54 +0100 Subject: [PATCH] Init commit --- .editorconfig | 5 + .github/actions/setup-poetry-env/action.yml | 42 +++++ .github/workflows/main.yml | 51 ++++++ .gitignore | 167 ++++++++++++++++++++ .pre-commit-config.yaml | 22 +++ CONTRIBUTING.md | 133 ++++++++++++++++ LICENSE | 33 ++++ Makefile | 35 ++++ README.md | 41 +++++ poetry.toml | 2 + pyproject.toml | 92 +++++++++++ qfieldcloud_fetcher/__init__.py | 0 qfieldcloud_fetcher/foo.py | 17 ++ tests/test_foo.py | 5 + tox.ini | 18 +++ 15 files changed, 663 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/actions/setup-poetry-env/action.yml create mode 100644 .github/workflows/main.yml create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 poetry.toml create mode 100644 pyproject.toml create mode 100644 qfieldcloud_fetcher/__init__.py create mode 100644 qfieldcloud_fetcher/foo.py create mode 100644 tests/test_foo.py create mode 100644 tox.ini diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9395b54 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +max_line_length = 120 + +[*.json] +indent_style = space +indent_size = 4 diff --git a/.github/actions/setup-poetry-env/action.yml b/.github/actions/setup-poetry-env/action.yml new file mode 100644 index 0000000..18738ae --- /dev/null +++ b/.github/actions/setup-poetry-env/action.yml @@ -0,0 +1,42 @@ +name: "setup-poetry-env" +description: "Composite action to setup the Python and poetry environment." + +inputs: + python-version: + required: false + description: "The python version to use" + default: "3.11" + +runs: + using: "composite" + steps: + - name: Set up python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + + - name: Install Poetry + env: + POETRY_VERSION: "1.7.1" + run: curl -sSL https://install.python-poetry.org | python - -y + shell: bash + + - name: Add Poetry to Path + run: echo "$HOME/.local/bin" >> $GITHUB_PATH + shell: bash + + - name: Configure Poetry virtual environment in project + run: poetry config virtualenvs.in-project true + shell: bash + + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v4 + with: + path: .venv + key: venv-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('poetry.lock') }} + + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction + shell: bash diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..6ca2ae4 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,51 @@ +name: Main + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +jobs: + quality: + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} + + - name: Set up the environment + uses: ./.github/actions/setup-poetry-env + + - name: Run checks + run: make check + + tests-and-type-check: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + fail-fast: false + defaults: + run: + shell: bash + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Set up the environment + uses: ./.github/actions/setup-poetry-env + with: + python-version: ${{ matrix.python-version }} + + - name: Run tests + run: poetry run pytest tests --cov --cov-config=pyproject.toml --cov-report=xml + + - name: Check typing + run: poetry run mypy + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f64e26a --- /dev/null +++ b/.gitignore @@ -0,0 +1,167 @@ +docs/source + +# From https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# Vscode config files +.vscode/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..1f33da2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,22 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: "v4.4.0" + hooks: + - id: check-case-conflict + - id: check-merge-conflict + - id: check-toml + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.5.2" + hooks: + - id: ruff + args: [--exit-non-zero-on-fix] + - id: ruff-format + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "v3.0.3" + hooks: + - id: prettier diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..95b7100 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,133 @@ +# Contributing to `qfieldcloud-fetcher` + +Contributions are welcome, and they are greatly appreciated! +Every little bit helps, and credit will always be given. + +You can contribute in many ways: + +# Types of Contributions + +## Report Bugs + +Report bugs at https://github.com/edouardbruelhart/qfieldcloud-fetcher/issues + +If you are reporting a bug, please include: + +- Your operating system name and version. +- Any details about your local setup that might be helpful in troubleshooting. +- Detailed steps to reproduce the bug. + +## Fix Bugs + +Look through the GitHub issues for bugs. +Anything tagged with "bug" and "help wanted" is open to whoever wants to implement a fix for it. + +## Implement Features + +Look through the GitHub issues for features. +Anything tagged with "enhancement" and "help wanted" is open to whoever wants to implement it. + +## Write Documentation + +Cookiecutter PyPackage could always use more documentation, whether as part of the official docs, in docstrings, or even on the web in blog posts, articles, and such. + +## Submit Feedback + +The best way to send feedback is to file an issue at https://github.com/edouardbruelhart/qfieldcloud-fetcher/issues. + +If you are proposing a new feature: + +- Explain in detail how it would work. +- Keep the scope as narrow as possible, to make it easier to implement. +- Remember that this is a volunteer-driven project, and that contributions + are welcome :) + +# Get Started! + +Ready to contribute? Here's how to set up `qfieldcloud-fetcher` for local development. +Please note this documentation assumes you already have `poetry` and `Git` installed and ready to go. + +1. Fork the `qfieldcloud-fetcher` repo on GitHub. + +2. Clone your fork locally: + +```bash +cd +git clone git@github.com:YOUR_NAME/qfieldcloud-fetcher.git +``` + +3. Now we need to install the environment. Navigate into the directory + +```bash +cd qfieldcloud-fetcher +``` + +If you are using `pyenv`, select a version to use locally. (See installed versions with `pyenv versions`) + +```bash +pyenv local +``` + +Then, install and activate the environment with: + +```bash +poetry install +poetry shell +``` + +4. Install pre-commit to run linters/formatters at commit time: + +```bash +poetry run pre-commit install +``` + +5. Create a branch for local development: + +```bash +git checkout -b name-of-your-bugfix-or-feature +``` + +Now you can make your changes locally. + +6. Don't forget to add test cases for your added functionality to the `tests` directory. + +7. When you're done making changes, check that your changes pass the formatting tests. + +```bash +make check +``` + +Now, validate that all unit tests are passing: + +```bash +make test +``` + +9. Before raising a pull request you should also run tox. + This will run the tests across different versions of Python: + +```bash +tox +``` + +This requires you to have multiple versions of python installed. +This step is also triggered in the CI/CD pipeline, so you could also choose to skip this step locally. + +10. Commit your changes and push your branch to GitHub: + +```bash +git add . +git commit -m "Your detailed description of your changes." +git push origin name-of-your-bugfix-or-feature +``` + +11. Submit a pull request through the GitHub website. + +# Pull Request Guidelines + +Before you submit a pull request, check that it meets these guidelines: + +1. The pull request should include tests. + +2. If the pull request adds functionality, the docs should be updated. + Put your new functionality into a function with a docstring, and add the feature to the list in `README.md`. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..85c1608 --- /dev/null +++ b/LICENSE @@ -0,0 +1,33 @@ +GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + A python project to fetch data from EMI QFieldCloud instance and prepare pictures for iNaturalist import. + Copyright (C) 2024 Edouard Brülhart + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a530f78 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +.PHONY: install +install: ## Install the poetry environment and install the pre-commit hooks + @echo "🚀 Creating virtual environment using pyenv and poetry" + @poetry install + @ poetry run pre-commit install + @poetry shell + +.PHONY: check +check: ## Run code quality tools. + @echo "🚀 Checking Poetry lock file consistency with 'pyproject.toml': Running poetry check --lock" + @poetry check --lock + @echo "🚀 Linting code: Running pre-commit" + @poetry run pre-commit run -a + @echo "🚀 Static type checking: Running mypy" + @poetry run mypy + +.PHONY: test +test: ## Test the code with pytest + @echo "🚀 Testing code: Running pytest" + @poetry run pytest --doctest-modules + +.PHONY: build +build: clean-build ## Build wheel file using poetry + @echo "🚀 Creating wheel file" + @poetry build + +.PHONY: clean-build +clean-build: ## clean build artifacts + @rm -rf dist + +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' + +.DEFAULT_GOAL := help diff --git a/README.md b/README.md new file mode 100644 index 0000000..71104a8 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# qfieldcloud-fetcher + +[![Release](https://img.shields.io/github/v/release/edouardbruelhart/qfieldcloud-fetcher)](https://img.shields.io/github/v/release/edouardbruelhart/qfieldcloud-fetcher) +[![Build status](https://img.shields.io/github/actions/workflow/status/edouardbruelhart/qfieldcloud-fetcher/main.yml?branch=main)](https://github.com/edouardbruelhart/qfieldcloud-fetcher/actions/workflows/main.yml?query=branch%3Amain) +[![codecov](https://codecov.io/gh/edouardbruelhart/qfieldcloud-fetcher/branch/main/graph/badge.svg)](https://codecov.io/gh/edouardbruelhart/qfieldcloud-fetcher) +[![Commit activity](https://img.shields.io/github/commit-activity/m/edouardbruelhart/qfieldcloud-fetcher)](https://img.shields.io/github/commit-activity/m/edouardbruelhart/qfieldcloud-fetcher) +[![License](https://img.shields.io/github/license/edouardbruelhart/qfieldcloud-fetcher)](https://img.shields.io/github/license/edouardbruelhart/qfieldcloud-fetcher) + +A python project to fetch data from EMI QFieldCloud instance and prepare pictures for iNaturalist import. + +- **Github repository**: +- **Documentation** + +## Getting started with your project + +First, create a repository on GitHub with the same name as this project, and then run the following commands: + +```bash +git init -b main +git add . +git commit -m "init commit" +git remote add origin git@github.com:edouardbruelhart/qfieldcloud-fetcher.git +git push -u origin main +``` + +Finally, install the environment and the pre-commit hooks with + +```bash +make install +``` + +You are now ready to start development on your project! +The CI/CD pipeline will be triggered when you open a pull request, merge to main, or when you create a new release. + +To finalize the set-up for publishing to PyPI or Artifactory, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/publishing/#set-up-for-pypi). +For activating the automatic documentation with MkDocs, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/mkdocs/#enabling-the-documentation-on-github). +To enable the code coverage reports, see [here](https://fpgmaas.github.io/cookiecutter-poetry/features/codecov/). + +--- + +Repository initiated with [fpgmaas/cookiecutter-poetry](https://github.com/fpgmaas/cookiecutter-poetry). diff --git a/poetry.toml b/poetry.toml new file mode 100644 index 0000000..ab1033b --- /dev/null +++ b/poetry.toml @@ -0,0 +1,2 @@ +[virtualenvs] +in-project = true diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e6bbf62 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,92 @@ +[tool.poetry] +name = "qfieldcloud_fetcher" +version = "0.0.1" +description = "A python project to fetch data from EMI QFieldCloud instance and prepare pictures for iNaturalist import." +authors = ["Edouard Brülhart "] +repository = "https://github.com/edouardbruelhart/qfieldcloud-fetcher" +documentation = "https://edouardbruelhart.github.io/qfieldcloud-fetcher/" +readme = "README.md" +packages = [ + {include = "qfieldcloud_fetcher"} +] + +[tool.poetry.dependencies] +python = ">=3.8,<4.0" + +[tool.poetry.group.dev.dependencies] +pytest = "^7.2.0" +mypy = "^1.5.1" +pre-commit = "^3.4.0" +tox = "^4.11.1" + + + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" + +[tool.mypy] +files = ["qfieldcloud_fetcher"] +disallow_untyped_defs = "True" +disallow_any_unimported = "True" +no_implicit_optional = "True" +check_untyped_defs = "True" +warn_return_any = "True" +warn_unused_ignores = "True" +show_error_codes = "True" + + + +[tool.pytest.ini_options] +testpaths = ["tests"] + +[tool.ruff] +target-version = "py39" +line-length = 120 +fix = true +select = [ + # flake8-2020 + "YTT", + # flake8-bandit + "S", + # flake8-bugbear + "B", + # flake8-builtins + "A", + # flake8-comprehensions + "C4", + # flake8-debugger + "T10", + # flake8-simplify + "SIM", + # isort + "I", + # mccabe + "C90", + # pycodestyle + "E", "W", + # pyflakes + "F", + # pygrep-hooks + "PGH", + # pyupgrade + "UP", + # ruff + "RUF", + # tryceratops + "TRY", +] +ignore = [ + # LineTooLong + "E501", + # DoNotAssignLambda + "E731", +] + +[tool.ruff.format] +preview = true + + + +[tool.ruff.per-file-ignores] +"tests/*" = ["S101"] diff --git a/qfieldcloud_fetcher/__init__.py b/qfieldcloud_fetcher/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/qfieldcloud_fetcher/foo.py b/qfieldcloud_fetcher/foo.py new file mode 100644 index 0000000..8b7396d --- /dev/null +++ b/qfieldcloud_fetcher/foo.py @@ -0,0 +1,17 @@ +def foo(bar: str) -> str: + """Summary line. + + Extended description of function. + + Args: + bar: Description of input argument. + + Returns: + Description of return value + """ + + return bar + + +if __name__ == "__main__": # pragma: no cover + pass diff --git a/tests/test_foo.py b/tests/test_foo.py new file mode 100644 index 0000000..fd513cc --- /dev/null +++ b/tests/test_foo.py @@ -0,0 +1,5 @@ +from qfieldcloud_fetcher.foo import foo + + +def test_foo(): + assert foo("foo") == "foo" diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..a44a21b --- /dev/null +++ b/tox.ini @@ -0,0 +1,18 @@ +[tox] +skipsdist = true +envlist = py38, py39, py310, py311 + +[gh-actions] +python = + 3.8: py38 + 3.9: py39 + 3.10: py310 + 3.11: py311 + +[testenv] +passenv = PYTHON_VERSION +allowlist_externals = poetry +commands = + poetry install -v + pytest --doctest-modules tests --cov --cov-config=pyproject.toml --cov-report=xml + mypy