From 4dec59db6ea837d63445277e92ab11a613d64e66 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Tue, 30 Aug 2022 11:48:31 +0200 Subject: [PATCH] import of project template --- .flake8 | 2 + .gitignore | 64 +++++++++++++++++ .pre-commit-config.yaml | 38 +++++++++++ CHANGES.md | 4 ++ CONTRIBUTING.md | 117 ++++++++++++++++++++++++++++++++ LICENSE | 10 +++ Makefile | 99 +++++++++++++++++++++++++++ README.md | 26 +++++++ pyproject.toml | 82 ++++++++++++++++++++++ src/sensospot_tools/__init__.py | 10 +++ tests/test_sensospot_tools.py | 41 +++++++++++ tox.ini | 14 ++++ 12 files changed, 507 insertions(+) create mode 100644 .flake8 create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 CHANGES.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 src/sensospot_tools/__init__.py create mode 100644 tests/test_sensospot_tools.py create mode 100644 tox.ini diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..ef9877f --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +per-file-ignores = tests/*:S101 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d77a72 --- /dev/null +++ b/.gitignore @@ -0,0 +1,64 @@ +# ---> Python +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +.venv +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# 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/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Mac Stuff +.DS_Store + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4a4a681 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,38 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 + hooks: + - id: check-added-large-files + - id: check-byte-order-marker + - id: check-json + - id: check-merge-conflict + - id: check-toml + - id: debug-statements + - id: detect-private-key +- repo: local + hooks: + - id: isort-project + name: isort_project + entry: isort -rc src + language: system + pass_filenames: false + - id: isort-test + name: isort_test + entry: isort -rc tests + language: system + pass_filenames: false + - id: black + name: black + entry: black src tests + language: system + pass_filenames: false + - id: flake8 + name: flake8 + entry: flake8 src tests + language: system + pass_filenames: false + - id: pytest + name: pytest + entry: pytest tests + pass_filenames: false + language: system diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 0000000..2fd3f54 --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,4 @@ +0.0.1 - first version +---------------------- + + - setting up the project diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..bc37b0b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,117 @@ +Contributing +============ + +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://git.cpi.imtek.uni-freiburg.de/holgi/sensospot_tools.git/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 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 + +Sensospot Tools could always use more documentation, whether as part of the +official Sensospot Tools 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://git.cpi.imtek.uni-freiburg.de/holgi/sensospot_tools.git/issues. + +If you are proposing a 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 `sensospot_tools` for local development. + +1. Fork the `sensospot_tools` repo on GitHub. +2. Clone your fork locally:: + + `$ git clone git@github.com:your_name_here/sensospot_tools.git` + +3. Install your local copy into a virtualenv. + + `$ cd sensospot_tools/` + `$ make devenv` + +4. Create a branch for local development:: + + `$ git checkout -b name-of-your-bugfix-or-feature` + + Now you can make your changes locally. + +5. When you're done making changes, check that your changes passes the linters and the + tests, including testing other Python versions with tox:: + + ``` + $ make lint + $ make coverage + $ make tox + ``` + +6. Commit your changes and push your branch to GitHub:: + + ``` + $ git add . + $ git commit -m "Your detailed description of your changes." + $ git push origin name-of-your-bugfix-or-feature + ``` + +7. 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 and CHANGES.md + +Tips +---- + +To run a quick set of tests without coverage report + + $ make test + +Deploying +--------- + +A reminder for the maintainers on how to deploy. +Bump the version in `sensospot_tools/__init__.py` and +make sure all your changes are committed (including an entry in CHANGES.md). + + $ git tag + $ git push + $ git push --tags + $ flit publish + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a3dfb3e --- /dev/null +++ b/LICENSE @@ -0,0 +1,10 @@ +/* +* ---------------------------------------------------------------------------- +* "THE BEER-WARE LICENSE" (Revision 42): +* frey@imtek.de wrote this file. As long as you retain this notice you +* can do whatever you want with this stuff. If we meet some day, and you think +* this stuff is worth it, you can buy me a beer in return. Holger Frey +* ---------------------------------------------------------------------------- +*/ + + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..99d9b0f --- /dev/null +++ b/Makefile @@ -0,0 +1,99 @@ +.PHONY: clean clean-test clean-pyc clean-build docs help +.DEFAULT_GOAL := help + +define BROWSER_PYSCRIPT +import os, webbrowser, sys + +try: + from urllib import pathname2url +except: + from urllib.request import pathname2url + +webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) +endef +export BROWSER_PYSCRIPT + +define PRINT_HELP_PYSCRIPT +import re, sys + +for line in sys.stdin: + match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) + if match: + target, help = match.groups() + print("%-20s %s" % (target, help)) +endef +export PRINT_HELP_PYSCRIPT + +BROWSER := python -c "$$BROWSER_PYSCRIPT" + +help: + @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) + +clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts + +clean-build: ## remove build artifacts + rm -fr build/ + rm -fr dist/ + rm -fr .eggs/ + find . -name '*.egg-info' -exec rm -fr {} + + find . -name '*.egg' -exec rm -f {} + + +clean-pyc: ## remove Python file artifacts + find . -name '*.pyc' -exec rm -f {} + + find . -name '*.pyo' -exec rm -f {} + + find . -name '*~' -exec rm -f {} + + find . -name '__pycache__' -exec rm -fr {} + + +clean-test: ## remove test and coverage artifacts + rm -fr .pytest_cache/ + rm -fr .tox/ + rm -f .coverage + rm -fr htmlcov/ + +lint: ## reformat with black and check style with flake8 + isort src + isort tests + black src tests + flake8 src + flake8 --ignore S101 tests + +test: lint ## run tests quickly, stop on first error + pytest tests -x -l --last-failed --disable-warnings -m "not functional" + +testfunctional: lint ## run functional tests, stop on first error + pytest tests -x -l -m "functional" + +testall: lint ## run all tests + pytest tests -l + +coverage: lint ## functional test suite, check code coverage and open coverage report + pytest tests --cov=sensospot_tools -l -m "functional" + coverage html + $(BROWSER) htmlcov/index.html + +coverall: lint ## full test suite, check code coverage and open coverage report + pytest tests --cov=sensospot_tools -l + coverage html + $(BROWSER) htmlcov/index.html + +tox: ## run fully isolated tests with tox + tox + +install: ## install updated project.toml with flint + flit install --pth-file + +devenv: ## setup development environment + python3 -m venv --prompt sensospot_tools .venv + .venv/bin/pip3 install --upgrade pip + .venv/bin/pip3 install "flit>3.2" + .venv/bin/flit install --pth-file + +repo: devenv ## complete project setup with development environment and git repo + git init . + git add . + git commit -m "import of project template" + git branch -m main + git remote add origin https://git.cpi.imtek.uni-freiburg.de/holgi/sensospot_tools.git + git push -u origin main --no-verify + + .venv/bin/pre-commit install --install-hooks diff --git a/README.md b/README.md new file mode 100644 index 0000000..709a6a6 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +Sensospot Tools +=============== + +Some small tools for working with parsed Sensospot data. + +## Example: + +```python + + import sensospot_tools + + sensospot_tools.run() +``` + + +## Development + +To install the development version of Sensospot Tools: + + git clone https://git.cpi.imtek.uni-freiburg.de/holgi/sensospot_tools.git + + # create a virtual environment and install all required dev dependencies + cd sensospot_tools + make devenv + +To run the tests, use `make tests` or `make coverage` for a complete report. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4069451 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,82 @@ + + +[build-system] +requires = ["flit_core>=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "sensospot_tools" +readme = "README.md" +license = { file = "LICENSE" } +requires-python = ">=3.9" +dynamic = ["version", "description"] + +authors = [ + {name = "Holger Frey", email = "frey@imtek.de"}, +] + +# see https://pypi.org/classifiers/ +classifiers = [ + "Development Status :: 2 - Pre-Alpha", + "Intended Audience :: Developers", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3 :: Only", + "License :: Freely Distributable", +] + +dependencies = [ + +] +[project.urls] +Source = "https://git.cpi.imtek.uni-freiburg.de/holgi/sensospot_tools.git" + +# [project.scripts] +# script_name = "sensospot_tools:function" + +[project.optional-dependencies] +test = [ + "pytest >=4.0.0", + "pytest-cov", + "pytest-mock", + "pytest-randomly", + "tox", +] +dev = [ + "black", + "flake8", + "flake8-comprehensions", + "flake8-bandit", + "isort >= 5.0.0", + "keyring", + "pre-commit", +] + +[tool.black] +line-length = 79 +target-version = ['py39', 'py310'] +include = '\.pyi?$' +extend-exclude = ''' +# A regex preceded with ^/ will apply only to files and directories +# in the root of the project. +^/.git +^/.tox +^/.venv +^/.build +^/.dist +''' + +[tool.isort] +line_length=79 +multi_line_output=3 +length_sort="True" +include_trailing_comma="True" + +[tool.pytest.ini_options] +markers = [ + "functional: marks tests as functional (deselect with '-m \"not functional\"')", +] +addopts = [ + "--strict-markers", +] diff --git a/src/sensospot_tools/__init__.py b/src/sensospot_tools/__init__.py new file mode 100644 index 0000000..b62e5d4 --- /dev/null +++ b/src/sensospot_tools/__init__.py @@ -0,0 +1,10 @@ +""" Sensospot Tools + +Some small tools for working with parsed Sensospot data. +""" + +__version__ = "0.0.1" + + +def test(): + print("works") diff --git a/tests/test_sensospot_tools.py b/tests/test_sensospot_tools.py new file mode 100644 index 0000000..eaef6ad --- /dev/null +++ b/tests/test_sensospot_tools.py @@ -0,0 +1,41 @@ +""" Stub file for testing the project + +There are three predefined ways to run tests: + +make test: + runs only unit tests, that are not marked with "fun" (for functional test) + in a random order. If a test failed before, only the failed tests will be + run. This is intended to be the default testing method while developing. + +make testall: + runs unit tests and functional tests in random order. Will give a complete + overview of the test suite. + +make coverage: + runs only tests marked with "fun" (for functional tests) and generates a + coverage report for the test run. The idea is to check the test coverage + only on functinal tests to see if a) everything is as much covered as + possible and b) to find dead code that is not called in end-to-end tests. + +all three test strategies will run "make lint" before to catch easily made +mistakes. +""" + +import pytest + + +def test_example_unittest(): + """example unittest - try importing the project + + will be run by 'make test' and 'make testall' but not 'make coverage' + """ + import sensospot_tools # noqa: F401 + + +@pytest.mark.functional +def test_example_functional_test(): + """example unittest + + will be by 'make coverage' and 'make testall' but not 'make test' + """ + assert True diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..4e8a206 --- /dev/null +++ b/tox.ini @@ -0,0 +1,14 @@ +[tox] +envlist = py39, py310 +isolated_build = True + +[testenv] +deps = + pytest + pytest-cov + pytest-mock + setuptools>=41.2.0 + pip>=20.0.2 + +changedir = {toxinidir}/tests +commands = pytest --cov=sensospot_tools