diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml new file mode 100644 index 0000000..5960fb4 --- /dev/null +++ b/.github/workflows/publish-to-pypi.yml @@ -0,0 +1,97 @@ +name: Publish Python 🐍 distribution 📦 to PyPI + +on: + push: + tags: + - '*' + +jobs: + build: + name: Build distribution 📦 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: >- + Publish Python 🐍 distribution 📦 to PyPI + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/obsender + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + github-release: + name: >- + Sign the Python 🐍 distribution 📦 with Sigstore + and upload them to GitHub Release + needs: + - publish-to-pypi + runs-on: ubuntu-latest + + permissions: + contents: write # IMPORTANT: mandatory for making GitHub Releases + id-token: write # IMPORTANT: mandatory for sigstore + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v3.0.0 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create + "$GITHUB_REF_NAME" + --repo "$GITHUB_REPOSITORY" + --notes "" + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + "$GITHUB_REF_NAME" dist/** + --repo "$GITHUB_REPOSITORY" diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..efca9ba --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,46 @@ +name: tests + +on: + push: + pull_request: + +jobs: + Lint: + runs-on: ubuntu-24.04 + strategy: + fail-fast: true + matrix: + python-version: ["3.8"] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install tox + run: pip install tox + - name: pep8 + run: | + tox -e pep8 + tests: + runs-on: ubuntu-24.04 + strategy: + fail-fast: true + matrix: + python-version: ["3.8", "3.10", "3.12", "3.13"] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install required packages + run: | + sudo apt update + sudo apt install libev-dev -y + - name: Install tox + run: pip install tox + - name: Unit tests + run: | + tox -e ${{ matrix.python-version }} + # - name: Functional tests + # run: | + # tox -e ${{ matrix.python-version }}-functional diff --git a/obsender/config.py b/obsender/config.py index 3aafc53..b8d7c87 100644 --- a/obsender/config.py +++ b/obsender/config.py @@ -53,4 +53,4 @@ CONF = cfg.CONF CONF.register_opts(victoria_metrics_opts, constants.VICTORIA_METRICS_DOMAIN) -#CONF.register_opts(dpp_events_opts, constants.DPP_EVENTS_DOMAIN) +# CONF.register_opts(dpp_events_opts, constants.DPP_EVENTS_DOMAIN) diff --git a/obsender/senders.py b/obsender/senders.py index d612440..7568b0f 100644 --- a/obsender/senders.py +++ b/obsender/senders.py @@ -6,15 +6,15 @@ import uuid from concurrent import futures -#from dpp_client.clients import http +# from dpp_client.clients import http import obsender.vm_client as vm_client -from requests import exceptions as requests_exceptions +# from requests import exceptions as requests_exceptions import six from obsender import common from obsender import constants from obsender import decorators -from obsender import exceptions +# from obsender import exceptions DEFAULT_TIMEOUT = 10 # TODO(d.burmistrov): should be config option @@ -198,7 +198,8 @@ def __init__(self, logger, sender): self._sender = sender def process(self, msg, kwargs): - _msg = "[obsender_sender=%s] %s" % (self._sender.__class__.__name__, msg) + _msg = "[obsender_sender=%s] %s" % ( + self._sender.__class__.__name__, msg) return _msg, kwargs diff --git a/obsender/tests/unit/vm_client/test_push.py b/obsender/tests/unit/vm_client/test_push.py index e30c522..c974423 100644 --- a/obsender/tests/unit/vm_client/test_push.py +++ b/obsender/tests/unit/vm_client/test_push.py @@ -1,5 +1,5 @@ -import socket from functools import partial +import socket import pytest @@ -20,7 +20,8 @@ def mock_sendto(monkeypatch): @pytest.fixture(autouse=True) def mock_monotonic(monkeypatch): - monkeypatch.setattr('obsender.vm_client.push.monotonic', partial(next, iter([1.0, 2.0]))) + monkeypatch.setattr( + 'obsender.vm_client.push.monotonic', partial(next, iter([1.0, 2.0]))) @pytest.fixture diff --git a/obsender/vm_client/helpers.py b/obsender/vm_client/helpers.py index 9d7a746..9c7c2cc 100644 --- a/obsender/vm_client/helpers.py +++ b/obsender/vm_client/helpers.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals -from re import compile, sub +from re import compile +from re import sub SANITIZE_METRIC_NAME_REGEX = ( (compile('\\s+'), '_'), diff --git a/obsender/vm_client/protocol.py b/obsender/vm_client/protocol.py index 176f2ab..4def5af 100644 --- a/obsender/vm_client/protocol.py +++ b/obsender/vm_client/protocol.py @@ -10,8 +10,7 @@ def send(self, *args, **kwargs): class BaseUdpProto(object): - """The base class for the udp client protocol. - """ + """The base class for the udp client protocol.""" def __init__(self, host, port): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) diff --git a/obsender/vm_client/push.py b/obsender/vm_client/push.py index 5de1990..9b5c20a 100644 --- a/obsender/vm_client/push.py +++ b/obsender/vm_client/push.py @@ -1,15 +1,17 @@ from __future__ import unicode_literals -import os from itertools import starmap +import os try: from time import monotonic except ImportError: # pragma: no cover from monotonic import monotonic -from .helpers import env_bool, sanitize_metric_name -from .protocol import NullProto, UdpProto +from .helpers import env_bool +from .helpers import sanitize_metric_name +from .protocol import NullProto +from .protocol import UdpProto ENV_VARS = { 'host': (str, 'PUSH_METRICS_HOST'), @@ -65,9 +67,7 @@ def timer( def duration(self, bucket, value, **tags): # type: (str, float, ...) -> None - """ - Sends duration in ms (float). - """ + """Sends duration in ms (float).""" self.send(bucket, '{:0.6f}|ms'.format(value), **tags) @@ -113,7 +113,5 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.client.duration(self.bucket, elapsed, **self.tags) def set_tail(self, tail): # type: (...) -> None - """ - The only public method - """ + """The only public method""" self.tail = tail