From 0666078028c1596911a4614a8a65926c91b40feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cumitbuyuksahin=E2=80=9D?= Date: Fri, 5 Nov 2021 08:34:23 +0100 Subject: [PATCH 1/2] Initial setup --- .github/workflows/check_setup_py.yaml | 33 ++++++ .github/workflows/pytest.yaml | 34 ++++++ .gitignore | 138 ++++++++++++++++++++++ README.rst | 3 + exasol_error_reporting_python/__init__.py | 1 + githooks/install.sh | 44 +++++++ githooks/pre-commit | 11 ++ githooks/pre-push | 43 +++++++ githooks/prohibit_commit_to_main.sh | 8 ++ githooks/update_setup_py.sh | 45 +++++++ pyproject.toml | 29 +++++ setup.py | 26 ++++ tests/__init__.py | 0 tests/test_error_reporting_python.py | 5 + 14 files changed, 420 insertions(+) create mode 100644 .github/workflows/check_setup_py.yaml create mode 100644 .github/workflows/pytest.yaml create mode 100644 .gitignore create mode 100644 README.rst create mode 100644 exasol_error_reporting_python/__init__.py create mode 100755 githooks/install.sh create mode 100755 githooks/pre-commit create mode 100755 githooks/pre-push create mode 100755 githooks/prohibit_commit_to_main.sh create mode 100755 githooks/update_setup_py.sh create mode 100644 pyproject.toml create mode 100644 setup.py create mode 100644 tests/__init__.py create mode 100644 tests/test_error_reporting_python.py diff --git a/.github/workflows/check_setup_py.yaml b/.github/workflows/check_setup_py.yaml new file mode 100644 index 0000000..444f9d7 --- /dev/null +++ b/.github/workflows/check_setup_py.yaml @@ -0,0 +1,33 @@ +name: Check if setup.py is up to date + +on: [push, pull_request] + +jobs: + check_setup_py: + strategy: + fail-fast: false + matrix: + python-version: [3.6] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - uses: abatilo/actions-poetry@v2.0.0 + with: + poetry-version: 1.1.4 + - name: Poetry install + run: poetry install + - name: Run packaging update + run: bash githooks/update_setup_py.sh + - name: Show changes on working copy + run: git status --porcelain=v1 -uno + - name: Show diff on working copy + run: git diff --cached; cat setup.py + - name: Check if setup.py changed + run: | + [ -z "$(git status --porcelain=v1 -uno 2>/dev/null)" ] + - name: Check if setup.py works + run: pip install . diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml new file mode 100644 index 0000000..afe7f13 --- /dev/null +++ b/.github/workflows/pytest.yaml @@ -0,0 +1,34 @@ +name: Run pytest tests + +on: [ push, pull_request ] + +jobs: + integration_tests: + strategy: + fail-fast: false + matrix: + python-version: [3.6, 3.7, 3.8] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - uses: abatilo/actions-poetry@v2.0.0 + with: + poetry-version: 1.1.4 + - name: Poetry install + run: poetry install + - name: Poetry build + run: poetry build + + - name: Checkout test environment + run: git clone https://github.com/exasol/integration-test-docker-environment.git + working-directory: .. + - name: Spawn EXASOL environemnt + run: ./start-test-env spawn-test-environment --environment-name test --database-port-forward 8888 --bucketfs-port-forward 6666 --db-mem-size 4GB + working-directory: ../integration-test-docker-environment + + - name: Poetry run pytest integration tests + run: poetry run pytest tests diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..284db3d --- /dev/null +++ b/.gitignore @@ -0,0 +1,138 @@ +# 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/ +pip-wheel-metadata/ +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/ + +# 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 +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.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 + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__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/ + +# Poetry +poetry.lock + +# PyCharm +.idea + +# Sphinx +doc/_build diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..4cdbd3a --- /dev/null +++ b/README.rst @@ -0,0 +1,3 @@ +# Error Reporting Python + +This project contains a python library for describing Exasol error messages. \ No newline at end of file diff --git a/exasol_error_reporting_python/__init__.py b/exasol_error_reporting_python/__init__.py new file mode 100644 index 0000000..b794fd4 --- /dev/null +++ b/exasol_error_reporting_python/__init__.py @@ -0,0 +1 @@ +__version__ = '0.1.0' diff --git a/githooks/install.sh b/githooks/install.sh new file mode 100755 index 0000000..4dbccf7 --- /dev/null +++ b/githooks/install.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -o errexit +set -o nounset +set -o pipefail + +SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" +REPO_DIR=$(git rev-parse --show-toplevel) +REPO_DIR="$(readlink -f "${REPO_DIR}")" +GIT_DIR="$REPO_DIR/.git" +GIT_DIR="$(readlink -f "${GIT_DIR}")" + +if [[ ! -d "$GIT_DIR" ]]; then + echo "$GIT_DIR is not a git directory." >&2 + exit 1 +else + GITHOOKS_PATH="$GIT_DIR/hooks" +fi + +GITHOOKS_PATH="$(readlink -f "${GITHOOKS_PATH}")" + +copy_hook() { + local SCRIPT_PATH="$SCRIPT_DIR/$1" + local GITHOOK_PATH="$GITHOOKS_PATH/$2" + local RELATIVE_PATH=$(realpath --relative-to="$GITHOOKS_PATH" "$SCRIPT_PATH") + pushd "$GITHOOKS_PATH" > /dev/null + if [ -e "$GITHOOK_PATH" ] || [ -L "$GITHOOK_PATH" ] + then + echo + echo "Going to delete old hook $GITHOOK_PATH" + rm "$GITHOOK_PATH" > /dev/null + fi + echo + echo "Link hook to script" >&2 + echo "Hook-Path: $GITHOOK_PATH" >&2 + echo "Script-path: $SCRIPT_PATH" >&2 + echo + ln -s "$RELATIVE_PATH" "$2" > /dev/null + chmod +x "$SCRIPT_PATH" > /dev/null + popd > /dev/null +} + +copy_hook pre-commit pre-commit +copy_hook pre-commit post-rewrite +copy_hook pre-push pre-push diff --git a/githooks/pre-commit b/githooks/pre-commit new file mode 100755 index 0000000..68b0019 --- /dev/null +++ b/githooks/pre-commit @@ -0,0 +1,11 @@ +#!/bin/bash +set -o errexit +set -o nounset +set -o pipefail + +REPO_DIR=$(git rev-parse --show-toplevel) +GITHOOKS_PATH="$REPO_DIR/githooks" +pushd "$REPO_DIR" +bash "$GITHOOKS_PATH/prohibit_commit_to_main.sh" +bash "$GITHOOKS_PATH/update_setup_py.sh" +popd diff --git a/githooks/pre-push b/githooks/pre-push new file mode 100755 index 0000000..f1ce1e0 --- /dev/null +++ b/githooks/pre-push @@ -0,0 +1,43 @@ +#!/bin/bash +protected_branches=( master main ) +for i in "${protected_branches[@]}" +do + + protected_branch=$i + + policy='[Policy] Never push, force push or delete the '$protected_branch' branch! (Prevented with pre-push hook.)' + + current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') + + push_command=$(ps -ocommand= -p $PPID) + + is_destructive='force|delete|\-f' + + will_remove_protected_branch=':'$protected_branch + + do_exit(){ + echo $policy + exit 1 + } + + if [[ $push_command =~ $is_destructive ]] && [ $current_branch = $protected_branch ]; then + do_exit + fi + + if [[ $push_command =~ $is_destructive ]] && [[ $push_command =~ $protected_branch ]]; then + do_exit + fi + + if [[ $push_command =~ $will_remove_protected_branch ]]; then + do_exit + fi + + if [[ $protected_branch == $current_branch ]]; then + do_exit + fi + +done + +unset do_exit + +exit 0 diff --git a/githooks/prohibit_commit_to_main.sh b/githooks/prohibit_commit_to_main.sh new file mode 100755 index 0000000..ae4f665 --- /dev/null +++ b/githooks/prohibit_commit_to_main.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +branch="$(git rev-parse --abbrev-ref HEAD)" + +if [ "$branch" = "main" ] || [ "$branch" = "master" ]; then + echo "You can't commit directly to main/master branch" + exit 1 +fi diff --git a/githooks/update_setup_py.sh b/githooks/update_setup_py.sh new file mode 100755 index 0000000..58d8182 --- /dev/null +++ b/githooks/update_setup_py.sh @@ -0,0 +1,45 @@ +#!/bin/bash +set -o errexit +set -o nounset +set -o pipefail + +# define colors for use in output +green='\033[0;32m' +no_color='\033[0m' +grey='\033[0;90m' + +# Jump to the current project's root directory (the one containing +# .git/) +ROOT_DIR=$(git rev-parse --show-toplevel || echo) +NO_GIT=FALSE +if [ -z "$ROOT_DIR" ] +then + echo "Did not found git repository, using '$PWD' as ROOT_DIR" + NO_GIT=TRUE + ROOT_DIR=$PWD +fi + + +pushd "$ROOT_DIR" > /dev/null + +echo -e "Generate setup.py ${grey}(pre-commit hook)${no_color}" +if [ -d "dist" ] +then + rm -r "dist" +fi +poetry build > /dev/null +pushd dist > /dev/null +tar_file=$(ls *.tar.gz) +extracted_dir=${tar_file%.tar.gz} +tar -xf $tar_file +cp "$extracted_dir/setup.py" ../setup.py +rm -r "$extracted_dir" +popd > /dev/null + +if [ "$NO_GIT" == "FALSE" ] +then + echo -e "Add generated files ${grey}(pre-commit hook)${no_color}" + git add setup.py +fi + +popd > /dev/null diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a5bf0c7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,29 @@ +[tool.poetry] +name = "exasol-error-reporting-python" +version = "0.1.0" +description = "Exasol Python Error Reporting" +license = "MIT" + +authors = [ + "Umit Buyuksahin ", + "Torsten Kilias " +] + + +readme = 'README.rst' + +repository = "https://github.com/exasol/error-reporting-python" +homepage = "https://github.com/exasol/error-reporting-python" + +keywords = ['exasol', 'python', 'error-reporting'] + + +[tool.poetry.dependencies] +python = ">=3.6.1,<4.0" + +[tool.poetry.dev-dependencies] +pytest = "^5.2" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..730f537 --- /dev/null +++ b/setup.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from setuptools import setup + +packages = \ +['exasol_error_reporting_python'] + +package_data = \ +{'': ['*']} + +setup_kwargs = { + 'name': 'exasol-error-reporting-python', + 'version': '0.1.0', + 'description': 'Exasol Python Error Reporting', + 'long_description': '# Error Reporting Python\n\nThis project contains a python library for describing Exasol error messages.', + 'author': 'Umit Buyuksahin', + 'author_email': 'umit.buyuksahin@exasol.com', + 'maintainer': None, + 'maintainer_email': None, + 'url': 'https://github.com/exasol/error-reporting-python', + 'packages': packages, + 'package_data': package_data, + 'python_requires': '>=3.6.1,<4.0', +} + + +setup(**setup_kwargs) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_error_reporting_python.py b/tests/test_error_reporting_python.py new file mode 100644 index 0000000..17dbc93 --- /dev/null +++ b/tests/test_error_reporting_python.py @@ -0,0 +1,5 @@ +from exasol_error_reporting_python import __version__ + + +def test_version(): + assert __version__ == '0.1.0' From 783c3417625609bb4f6e7d55371727c5f0d7c4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cumitbuyuksahin=E2=80=9D?= Date: Fri, 5 Nov 2021 08:50:49 +0100 Subject: [PATCH 2/2] Added doc folder --- doc/changes/changelog.md | 3 +++ doc/changes/changes_0.1.0.md | 12 +++++++++++ doc/dependencies.md | 20 +++++++++++++++++++ doc/design.md | 0 doc/developer_guide/building_documentation.md | 0 doc/developer_guide/developer_guide.md | 7 +++++++ doc/system_requirements.md | 0 doc/user_guide/user_guide.md | 4 ++++ 8 files changed, 46 insertions(+) create mode 100644 doc/changes/changelog.md create mode 100644 doc/changes/changes_0.1.0.md create mode 100644 doc/dependencies.md create mode 100644 doc/design.md create mode 100644 doc/developer_guide/building_documentation.md create mode 100644 doc/developer_guide/developer_guide.md create mode 100644 doc/system_requirements.md create mode 100644 doc/user_guide/user_guide.md diff --git a/doc/changes/changelog.md b/doc/changes/changelog.md new file mode 100644 index 0000000..387930a --- /dev/null +++ b/doc/changes/changelog.md @@ -0,0 +1,3 @@ +# Changelog + +* [0.1.0](changes_0.1.0.md) \ No newline at end of file diff --git a/doc/changes/changes_0.1.0.md b/doc/changes/changes_0.1.0.md new file mode 100644 index 0000000..6d5491d --- /dev/null +++ b/doc/changes/changes_0.1.0.md @@ -0,0 +1,12 @@ +# error-reporting-python 0.1.0 + +Code Name: Exasol python error code builder + +## Summary + +### Features + + - #1: Added initial project setup + + + \ No newline at end of file diff --git a/doc/dependencies.md b/doc/dependencies.md new file mode 100644 index 0000000..5732ddb --- /dev/null +++ b/doc/dependencies.md @@ -0,0 +1,20 @@ +# Dependencies + +## Run Time Dependencies + +| Dependency | Purpose | License | +|-------------------------------|----------------------------------|--------------------| +| [Python 3][python] | Python version 3.6.1 and above | PSF | + + +## Test Dependencies + +| Dependency | Purpose | License | +|-------------------------------|-----------------------------------|-------------------| +| [Pytest][pytest] | Testing framework | MIT | + + + +[python]: https://docs.python.org + +[pytest]: https://docs.pytest.org/en/stable/ diff --git a/doc/design.md b/doc/design.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/developer_guide/building_documentation.md b/doc/developer_guide/building_documentation.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/developer_guide/developer_guide.md b/doc/developer_guide/developer_guide.md new file mode 100644 index 0000000..736bb45 --- /dev/null +++ b/doc/developer_guide/developer_guide.md @@ -0,0 +1,7 @@ +# Developer Guide + + +In this developer guide we explain how you can build this project. + +* [building_documentation](building_documentation.md) + diff --git a/doc/system_requirements.md b/doc/system_requirements.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/user_guide/user_guide.md b/doc/user_guide/user_guide.md new file mode 100644 index 0000000..9f240fc --- /dev/null +++ b/doc/user_guide/user_guide.md @@ -0,0 +1,4 @@ +# User Guide + + +This user guide provides you with usage examples for this repository. \ No newline at end of file