migrate to pyproject.toml and publish to pypi

This commit is contained in:
HgO 2022-08-14 15:20:49 +02:00
parent 3841c3011f
commit d43ea389af
8 changed files with 145 additions and 73 deletions

1
.gitignore vendored
View file

@ -26,6 +26,7 @@ build/
dist/ dist/
.pytest_cache/ .pytest_cache/
.mypy_cache/ .mypy_cache/
_version.py
# Config file # Config file
config.yaml config.yaml

View file

@ -13,8 +13,12 @@ stages:
- install - install
- quality - quality
- test - test
- publish
.pip cache template: .pip template:
image: python:3.10-alpine
before_script:
- export PATH="${VIRTUAL_ENV}/bin:$PATH"
cache: cache:
key: key:
files: files:
@ -23,27 +27,24 @@ stages:
paths: paths:
- .cache/pip - .cache/pip
- ${VIRTUAL_ENV} - ${VIRTUAL_ENV}
interruptible: true
before_script: allow_failure: false
- export PATH="${VIRTUAL_ENV}/bin:$PATH"
install: install:
extends: .pip cache template extends: .pip template
image: python:3.10-alpine
stage: install stage: install
script: script:
- apk add --no-cache gcc g++ yaml-dev python3-dev - apk add --no-cache gcc g++ yaml-dev python3-dev
- python3 -m venv "${VIRTUAL_ENV}" - python3 -m venv "${VIRTUAL_ENV}"
- pip install -r requirements.txt - pip install -r requirements.txt
- pip install . - pip install .
- pip install -U build twine
cache: cache:
policy: pull-push policy: pull-push
interruptible: true
needs: [] needs: []
linting: linting:
extends: .pip cache template extends: .pip template
image: python:3.10-alpine
stage: quality stage: quality
script: script:
- isort -c --df . - isort -c --df .
@ -51,14 +52,12 @@ linting:
- black --check --diff . - black --check --diff .
cache: cache:
policy: pull policy: pull
interruptible: true
needs: needs:
- job: install - job: install
artifacts: false artifacts: false
tests: tests:
extends: .pip cache template extends: .pip template
image: python:3.10-alpine
stage: test stage: test
script: script:
- apk add --no-cache libstdc++ - apk add --no-cache libstdc++
@ -74,7 +73,46 @@ tests:
path: coverage.xml path: coverage.xml
junit: report.xml junit: report.xml
coverage: '/^TOTAL\s+\d+\s+\d+\s+(\d+\.\d+\%)$/' coverage: '/^TOTAL\s+\d+\s+\d+\s+(\d+\.\d+\%)$/'
interruptible: true
needs: needs:
- job: linting - job: linting
artifacts: false 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

View file

@ -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 Thank you for taking interest in this little project. Below is some information
to help you with contributing. to help you with contributing.
@ -53,7 +53,7 @@ For html report, the results can be found in `htmlcov` directory.
## What to work on ## What to work on
Take a look at the [issues 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? 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 If you would like to talk any ideas over before working on them, you can reach

View file

@ -146,5 +146,5 @@ Removing a reaction to an alert will also remove the silence.
## Troubleshooting ## Troubleshooting
If you had any difficulties with this setup process, please [file an 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). about it in [the Mattermost channel](https://chat.neutrinet.be/neutrinet/channels/hub-dev).

View file

@ -1,8 +1,13 @@
import sys import sys
from importlib.metadata import PackageNotFoundError, version
# Check that we're not running on an unsupported Python version. # Check that we're not running on an unsupported Python version.
if sys.version_info < (3, 5): if sys.version_info < (3, 9):
print("matrix_alertbot requires Python 3.5 or above.") print("matrix_alertbot requires Python 3.9 or above.")
sys.exit(1) sys.exit(1)
__version__ = "0.0.1" try:
__version__ = version("matrix_alertbot")
except PackageNotFoundError:
# package is not installed
pass

10
pyproject.toml Normal file
View file

@ -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"

View file

@ -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] [flake8]
# see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes # see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# for error codes. The ones we ignore are: # for error codes. The ones we ignore are:
@ -8,9 +74,9 @@
# E501: Line too long (black enforces this for us) # E501: Line too long (black enforces this for us)
ignore=W503,W504,E203,E731,E501 ignore=W503,W504,E203,E731,E501
exclude = exclude =
env env
.venv .venv
.env .env
[isort] [isort]
line_length = 88 line_length = 88

View file

@ -1,54 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
from typing import Tuple
from setuptools import find_packages, setup import setuptools
from matrix_alertbot import __version__ if __name__ == "__main__":
setuptools.setup()
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"],
)