Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/dev-build-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ jobs:
filename: './package_info.json'
key: 'package_version'
value: ${{ steps.release_ver.outputs.value }}
# Build and publish
# Test
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Build package
- name: Run tests
run: |
pip install -r requirements.txt
pip install pytest
pytest
# Build and publish
- name: Build package
run: |
python setup.py sdist
# - name: Publish distribution to Test PyPI
# uses: pypa/gh-action-pypi-publish@master
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/mypy-flake8-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: MyPy & flake8 checks

on:
push:

jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.sha }}
- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip

pip install mypy
python3 -m pip install types-protobuf

flake8_plugins="
flake8
flake8-bugbear
flake8-builtins
flake8-comprehensions
flake8-eradicate
flake8-fixme
flake8-multiline-containers
flake8-print
flake8-return
flake8-quotes
flake8-simplify
pep8-naming
flake8-expression-complexity
flake8-import-order
flake8-annotations-complexity
flake8-annotations-coverage
"
pip install $flake8_plugins
- name: Run MyPy
continue-on-error: true
run: mypy .
- name: Run flake8
run: flake8 .
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ __pycache__/
*.py[cod]
*$py.class
dist
*egg-info
*egg-info
.mypy_cache
all.log
2 changes: 1 addition & 1 deletion package_info.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"package_name": "th2-common",
"package_version": "3.8.2"
"package_version": "3.9.1"
}
Empty file added py.typed
Empty file.
9 changes: 4 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.

aio_pika==6.8.2
uvloop==0.16.0
th2-grpc-common==3.9.0
kubernetes==18.20.0
prometheus_client==0.11.0
th2-common-utils==1.1.0
th2-grpc-common==3.11.1.dev2999890198
kubernetes==24.2.0
prometheus_client==0.14.1
th2-common-utils==1.4.3
58 changes: 58 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[mypy]
disallow_untyped_defs = True
ignore_missing_imports = True
no_implicit_optional = True
warn_return_any = True

[flake8]
filename = *.py
require-plugins =
; Finding likely bugs and design problems in your program.
flake8-bugbear
; Check for python builtins being used as variables or parameters.
flake8-builtins
; Helps you write better list/set/dict comprehensions.
flake8-comprehensions
; Plugin to find commented out or dead code.
flake8-eradicate
; Check for FIXME, TODO and other temporary developer notes.
flake8-fixme
; Plugin to ensure a consistent format for multiline containers.
flake8-multiline-containers
; Check for print statements in python files.
flake8-print
; Plugin that checks return values.
flake8-return
; Extension for checking quotes in python.
flake8-quotes
; Plugin that helps you to simplify code.
flake8-simplify
; Check the PEP-8 naming conventions.
pep8-naming
; Extension for flake8 that validates cognitive functions complexity.
; flake8-cognitive-complexity
; Plugin to validate expressions complexity.
flake8-expression-complexity
; Include checks import order against various Python Style Guides.
flake8-import-order
; Plugin to validate annotations complexity.
flake8-annotations-complexity
; Plugin to validate annotations coverage.
flake8-annotations-coverage
ignore = N803, N806, T100, B010, E126, B024
per-file-ignores =
th2_common/__init__.py: F403, F401, T201
test/conftest.py: F401

import-order-style = google
max-line-length = 120
max-doc-length = 120
indent-size = 2
inline-quotes = '
multiline-quotes = '''
docstring-quotes = """

max-cognitive-complexity = 8

count = True
statistics = True
15 changes: 7 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2021 Exactpro (Exactpro Systems Limited)
# Copyright 2020-2022 Exactpro (Exactpro Systems Limited)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@

import json

from setuptools import setup, find_packages
from setuptools import find_packages, setup

with open('package_info.json', 'r') as file:
package_info = json.load(file)
Expand All @@ -38,12 +38,11 @@
python_requires='>=3.7',
install_requires=[
'aio_pika==6.8.2',
'uvloop==0.16.0',
'th2-grpc-common~=3.9.0',
'kubernetes==18.20.0',
'prometheus_client==0.11.0',
'th2-common-utils==1.1.0'
'th2-grpc-common==3.11.1.dev2999890198',
'kubernetes==24.2.0',
'prometheus_client==0.14.1',
'th2-common-utils>=1.4.3'
],
packages=[''] + find_packages(include=['th2_common', 'th2_common.*']),
package_data={'': ['package_info.json'], 'th2_common.schema.log': ['log4py.conf']}
package_data={'': ['package_info.json'], 'th2_common.schema.log': ['log4py.conf', 'log_config.json']}
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2020 Exactpro (Exactpro Systems Limited)
# Copyright 2022-2022 Exactpro (Exactpro Systems Limited)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2020 Exactpro (Exactpro Systems Limited)
# Copyright 2022-2022 Exactpro (Exactpro Systems Limited)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,14 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from test.fixtures import factory, filtered_messages, grpc_router

from abc import ABC, abstractmethod

from google.protobuf.message import Message


class RoutingStrategy(ABC):

@abstractmethod
def get_endpoint(self, message: Message):
pass
import pytest
56 changes: 56 additions & 0 deletions test/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2022-2022 Exactpro (Exactpro Systems Limited)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path
from test.test_filter_strategy.resources.messages_for_filtering import message_group_batch
from typing import Any, Dict
from unittest.mock import Mock

import pytest
from th2_common.schema.factory.common_factory import CommonFactory
from th2_common.schema.grpc.router.impl.default_grpc_router import DefaultGrpcRouter
from th2_common.schema.message.impl.rabbitmq.group.rabbit_message_group_batch_router import \
RabbitMessageGroupBatchRouter


@pytest.fixture(scope='session')
def factory() -> CommonFactory: # type: ignore
config_path = Path(__file__).parent / 'test_configuration' / 'resources' / 'json_configuration'
factory = CommonFactory(config_path=config_path)

yield factory

factory.close()


@pytest.fixture(scope='session')
def filtered_messages(factory) -> Dict[str, Any]: # type: ignore
message_router_configuration = factory._create_message_router_configuration()
rabbit_message_router = RabbitMessageGroupBatchRouter(connection_manager=Mock(),
configuration=message_router_configuration)

filtered_messages = rabbit_message_router.split_and_filter(
queue_aliases_to_configs=message_router_configuration.queues,
batch=message_group_batch
)

yield filtered_messages


@pytest.fixture(scope='session')
def grpc_router(factory) -> DefaultGrpcRouter: # type: ignore
grpc_configuration = factory._create_grpc_configuration()
grpc_router = DefaultGrpcRouter(grpc_configuration=grpc_configuration, grpc_router_configuration=Mock())

yield grpc_router
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2020 Exactpro (Exactpro Systems Limited)
# Copyright 2022-2022 Exactpro (Exactpro Systems Limited)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Loading