diff --git a/.gitignore b/.gitignore index 88e053d..0e45a4f 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ build/ dist/ .pytest_cache/ .mypy_cache/ +_version.py # Config file config.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 02a86ee..b4c5e91 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,8 +13,12 @@ stages: - install - quality - test + - publish -.pip cache template: +.pip template: + image: python:3.10-alpine + before_script: + - export PATH="${VIRTUAL_ENV}/bin:$PATH" cache: key: files: @@ -23,27 +27,24 @@ stages: paths: - .cache/pip - ${VIRTUAL_ENV} - -before_script: - - export PATH="${VIRTUAL_ENV}/bin:$PATH" + interruptible: true + allow_failure: false install: - extends: .pip cache template - image: python:3.10-alpine + extends: .pip template stage: install script: - apk add --no-cache gcc g++ yaml-dev python3-dev - python3 -m venv "${VIRTUAL_ENV}" - pip install -r requirements.txt - pip install . + - pip install -U build twine cache: policy: pull-push - interruptible: true needs: [] linting: - extends: .pip cache template - image: python:3.10-alpine + extends: .pip template stage: quality script: - isort -c --df . @@ -51,14 +52,12 @@ linting: - black --check --diff . cache: policy: pull - interruptible: true needs: - job: install artifacts: false tests: - extends: .pip cache template - image: python:3.10-alpine + extends: .pip template stage: test script: - apk add --no-cache libstdc++ @@ -74,7 +73,46 @@ tests: path: coverage.xml junit: report.xml coverage: '/^TOTAL\s+\d+\s+\d+\s+(\d+\.\d+\%)$/' - interruptible: true needs: - job: linting artifacts: false + +publish test: + extends: .pip template + stage: publish + script: + - python -m build + - twine upload --repository testpypi ./dist/* + cache: + policy: pull + artifacts: + name: $CI_JOB_NAME + paths: + - dist + expire_in: 1 week + rules: + - if: $CI_DEFAULT_BRANCH == CI_COMMIT_BRANCH + - if: $CI_COMMIT_TAG + environment: + name: test + url: https://test.pypi.org/project/matrix-alertbot + needs: + - job: tests + artifacts: false + +publish prod: + extends: .pip template + stage: publish + script: + - twine upload ./dist/* + cache: + policy: pull + rules: + - if: $CI_COMMIT_TAG + when: manual + environment: + name: prod + url: https://pypi.org/project/matrix-alertbot + needs: + - job: publish test + artifacts: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f1a90e1..1198fed 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to nio-template +# Contributing to Matrix AlertBot Thank you for taking interest in this little project. Below is some information to help you with contributing. @@ -53,7 +53,7 @@ For html report, the results can be found in `htmlcov` directory. ## What to work on Take a look at the [issues -list](https://git.domainepublic.net/Neutrinet/matrix-alertbot/-/issues). What +list](https://gitlab.domainepublic.net/Neutrinet/matrix-alertbot/-/issues). What feature would you like to see or bug do you want to be fixed? If you would like to talk any ideas over before working on them, you can reach diff --git a/SETUP.md b/SETUP.md index ec2a656..d06bf4e 100644 --- a/SETUP.md +++ b/SETUP.md @@ -146,5 +146,5 @@ Removing a reaction to an alert will also remove the silence. ## Troubleshooting If you had any difficulties with this setup process, please [file an -issue](https://git.domainepublic.net/Neutrinet/matrix-alertbot/-/issues) or come talk +issue](https://gitlab.domainepublic.net/Neutrinet/matrix-alertbot/-/issues) or come talk about it in [the Mattermost channel](https://chat.neutrinet.be/neutrinet/channels/hub-dev). diff --git a/matrix_alertbot/__init__.py b/matrix_alertbot/__init__.py index fd242d0..2eb1389 100644 --- a/matrix_alertbot/__init__.py +++ b/matrix_alertbot/__init__.py @@ -1,8 +1,13 @@ import sys +from importlib.metadata import PackageNotFoundError, version # Check that we're not running on an unsupported Python version. -if sys.version_info < (3, 5): - print("matrix_alertbot requires Python 3.5 or above.") +if sys.version_info < (3, 9): + print("matrix_alertbot requires Python 3.9 or above.") sys.exit(1) -__version__ = "0.0.1" +try: + __version__ = version("matrix_alertbot") +except PackageNotFoundError: + # package is not installed + pass diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9d51eac --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[build-system] +requires = [ + "setuptools>=45", + "setuptools_scm[toml]>=6.2" +] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "matrix_alertbot/_version.py" +local_scheme = "no-local-version" diff --git a/setup.cfg b/setup.cfg index 2001691..955fe76 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,69 @@ +[metadata] +name = matrix-alertbot +url= https://gitlab.domainepublic.net/Neutrinet/matrix-alertbot +description = A matrix bot to manage alerts from Alertmanager +long_description = file: README.md +long_description_content_type = text/markdown; charset=UTF-8 +license_files = LICENSE +classifiers= + License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+) + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 +project_urls = + Documentation = https://gitlab.domainepublic.net/Neutrinet/matrix-alertbot/-/blob/master/README.md + Source = https://gitlab.domainepublic.net/Neutrinet/matrix-alertbot + Tracker = https://gitlab.domainepublic.net/Neutrinet/matrix-alertbot/-/issues + +[options] +zip_safe = False +packages = find: +platforms = any +include_package_data = True +install_requires = + aiohttp>=3.8.1 + aiohttp-prometheus-exporter>=0.2.4 + aiotools>=1.5.9 + diskcache>=5.4.0 + jinja2>=3.1.2 + matrix-nio>=0.19.0 + Markdown>=3.3.7 + pytimeparse2>=1.4.0 + PyYAML>=5.4.1 + typing-extensions>=4.3.0 +python_requires = >=3.9 +setup_requires = + setuptools_scm + +[aliases] +test = pytest + +[options.entry_points] +console_scripts = + matrix-alertbot = matrix_alertbot:main.__main__ + +[options.packages.find] +where = matrix_alertbot + +[options.extras_require] +test = + coverage>=6.4.1 + black>=22.6.0 + flake8>=4.0.1 + flake8-comprehensions>=3.10.0 + isort>=5.10.1 + mypy>=0.961 + pytest>=7.1.2 + pytest-asyncio>=0.18.3 + freezegun>=1.2.1 + types-PyYAML>=6.0.9 + types-setuptools>=62.6.0 +e2e = + matrix-nio[e2e]>=0.19.0 +all = + %(test)s + %(e2e)s + [flake8] # see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes # for error codes. The ones we ignore are: @@ -8,9 +74,9 @@ # E501: Line too long (black enforces this for us) ignore=W503,W504,E203,E731,E501 exclude = - env - .venv - .env + env + .venv + .env [isort] line_length = 88 diff --git a/setup.py b/setup.py index 070cec9..df26131 100644 --- a/setup.py +++ b/setup.py @@ -1,54 +1,6 @@ #!/usr/bin/env python3 -import os -from typing import Tuple -from setuptools import find_packages, setup +import setuptools -from matrix_alertbot import __version__ - - -def read_file(path_segments: Tuple) -> str: - """Read a file from the package. Takes a list of strings to join to - make the path""" - file_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), *path_segments) - with open(file_path) as f: - return f.read() - - -version = __version__ -long_description = read_file(("README.md",)) - - -setup( - name="matrix-alertbot", - version=version, - url="https://github.com/anoadragon453/nio-template", - description="A matrix bot to do amazing things!", - packages=find_packages(exclude=["tests", "tests.*"]), - include_package_data=True, - install_requires=[ - "aiohttp>=3.8.1", - "aiohttp-prometheus-exporter>=0.2.4", - "aiotools>=1.5.9", - "diskcache>=5.4.0", - "jinja2>=3.1.2", - "matrix-nio>=0.19.0", - "Markdown>=3.3.7", - "pytimeparse2>=1.4.0", - "PyYAML>=5.4.1", - "typing-extensions>=4.3.0", - ], - extras_require={ - "e2e": ["matrix-nio[e2e]>=0.19.0"], - }, - classifiers=[ - "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - ], - long_description=long_description, - long_description_content_type="text/markdown", - # Allow the user to run the bot with `matrix-alertbot ...` - scripts=["matrix-alertbot"], -) +if __name__ == "__main__": + setuptools.setup()