Skip to content

Commit

Permalink
[Project] Migrate to Async-Channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Herklos committed Oct 4, 2020
1 parent 6da935e commit a15df55
Show file tree
Hide file tree
Showing 33 changed files with 186 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ steps:
event:
- tag
repo:
- Drakkar-Software/channel
- Drakkar-Software/Async-Channel
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
global:
- GH_REPO=Drakkar-Software/OctoBot-Channels
- DEPLOY_BRANCH=master
- PACKAGE_FOLDER=channel
- PACKAGE_FOLDER=async_channel

install:
- python3 -m pip install --prefer-binary -r dev_requirements.txt -r requirements.txt
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.0.1] - 2020-10-01
### Added
- Logging dynamic implementation
- Project name to 'Async-Channel'

## [2.0.0] - 2020-10-01
### Update
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Channel [2.0.1](https://github.com/Drakkar-Software/channel/blob/master/CHANGELOG.md)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/523d43c62f1d4de08395752367f5fddc)](https://www.codacy.com/gh/Drakkar-Software/channel/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Drakkar-Software/channel&utm_campaign=Badge_Grade)
# Async-Channel [2.0.1](https://github.com/Drakkar-Software/Async-Channel/blob/master/CHANGELOG.md)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/523d43c62f1d4de08395752367f5fddc)](https://www.codacy.com/gh/Drakkar-Software/Async-Channel/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Drakkar-Software/Async-Channel&utm_campaign=Badge_Grade)
[![PyPI](https://img.shields.io/pypi/v/channel.svg)](https://pypi.python.org/pypi/channel/)
[![Build Status](https://api.travis-ci.com/Drakkar-Software/OctoBot-Channels.svg?branch=master)](https://travis-ci.com/Drakkar-Software/OctoBot-Channels)
[![Build Status](https://dev.azure.com/drakkarsoftware/channel/_apis/build/status/Drakkar-Software.channel?branchName=master)](https://dev.azure.com/drakkarsoftware/channel/_build/latest?definitionId=3&branchName=master)
[![Build Status](https://cloud.drone.io/api/badges/Drakkar-Software/channel/status.svg)](https://cloud.drone.io/Drakkar-Software/channel)
[![Build Status](https://cloud.drone.io/api/badges/Drakkar-Software/Async-Channel/status.svg)](https://cloud.drone.io/Drakkar-Software/Async-Channel)
[![Coverage Status](https://coveralls.io/repos/github/Drakkar-Software/OctoBot-Channels/badge.svg?branch=master)](https://coveralls.io/github/Drakkar-Software/OctoBot-Channels?branch=master)
[![Doc Status](https://readthedocs.org/projects/octobot-channels/badge/?version=stable)](https://octobot-channels.readthedocs.io/en/stable/?badge=stable)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Python multi-task communication library. Used by [OctoBot](https://github.com/Drakkar-Software/OctoBot) project.

## Installation
With python3 : `pip install channel`
With python3 : `pip install async-channel`

## Usage
Example
```python
import channel.consumer as consumer
import channel.producer as producer
import channel.channels as channels
import channel.util as util
import async_channel.consumer as consumer
import async_channel.producer as producer
import async_channel.channels as channels
import async_channel.util as util

class AwesomeProducer(producer.Producer):
pass
Expand Down
10 changes: 5 additions & 5 deletions channel/__init__.pxd → async_channel/__init__.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# cython: language_level=3
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -15,13 +15,13 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library.

from channel cimport producer
from channel cimport consumer
from async_channel cimport producer
from async_channel cimport consumer

from channel.producer cimport (
from async_channel.producer cimport (
Producer,
)
from channel.consumer cimport (
from async_channel.consumer cimport (
Consumer,
InternalConsumer,
SupervisedConsumer,
Expand Down
22 changes: 11 additions & 11 deletions channel/__init__.py → async_channel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -14,29 +14,29 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
"""
Define channel project
Define async_channel project
"""

from channel import constants
from channel.constants import (
from async_channel import constants
from async_channel.constants import (
CHANNEL_WILDCARD,
DEFAULT_QUEUE_SIZE,
)

from channel import enums
from channel.enums import ChannelConsumerPriorityLevels
from async_channel import enums
from async_channel.enums import ChannelConsumerPriorityLevels

from channel import producer
from channel.producer import Producer
from async_channel import producer
from async_channel.producer import Producer

from channel import consumer
from channel.consumer import (
from async_channel import consumer
from async_channel.consumer import (
Consumer,
InternalConsumer,
SupervisedConsumer,
)

PROJECT_NAME = "channel"
PROJECT_NAME = "async-channel"
VERSION = "2.0.1" # major.minor.revision

__all__ = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# cython: language_level=3
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -15,13 +15,13 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library.

from channel.channels cimport channel
from channel.channels.channel cimport (
from async_channel.channels cimport channel
from async_channel.channels.channel cimport (
Channel
)

from channel.channels cimport channel_instances
from channel.channels.channel_instances cimport (
from async_channel.channels cimport channel_instances
from async_channel.channels.channel_instances cimport (
ChannelInstances
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -14,20 +14,20 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
"""
Define channel implementation and usage
Define async_channel implementation and usage
"""
from channel.channels import channel_instances
from channel.channels import channel
from async_channel.channels import channel_instances
from async_channel.channels import channel

from channel.channels.channel_instances import (
from async_channel.channels.channel_instances import (
ChannelInstances,
set_chan_at_id,
get_channels,
del_channel_container,
get_chan_at_id,
del_chan_at_id,
)
from channel.channels.channel import (
from async_channel.channels.channel import (
Channel,
set_chan,
del_chan,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# cython: language_level=3, wraparound=False
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
cimport channel.producer as producer
cimport async_channel.producer as producer

cdef class Channel(object):
cdef object logger
Expand Down
26 changes: 14 additions & 12 deletions channel/channels/channel.py → async_channel/channels/channel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -18,9 +18,9 @@
"""
import typing

import channel.util.logging_util as logging
import channel.enums
import channel.channels.channel_instances as channel_instances
import async_channel.util.logging_util as logging
import async_channel.enums
import async_channel.channels.channel_instances as channel_instances


# pylint: disable=undefined-variable, not-callable
Expand All @@ -42,7 +42,9 @@ class Channel:
INSTANCE_KEY = "consumer_instance"

# Channel default consumer priority level
DEFAULT_PRIORITY_LEVEL = channel.enums.ChannelConsumerPriorityLevels.HIGH.value
DEFAULT_PRIORITY_LEVEL = (
async_channel.enums.ChannelConsumerPriorityLevels.HIGH.value
)

def __init__(self):
self.logger = logging.get_logger(self.__class__.__name__)
Expand Down Expand Up @@ -83,7 +85,7 @@ async def new_consumer(
priority_level: int = DEFAULT_PRIORITY_LEVEL,
) -> CONSUMER_CLASS:
"""
Create an appropriate consumer instance for this channel and add it to the consumer list
Create an appropriate consumer instance for this async_channel and add it to the consumer list
Should end by calling '_check_producers_state'
:param callback: method that should be called when consuming the queue
:param consumer_filters: the consumer filters
Expand Down Expand Up @@ -197,7 +199,7 @@ def _should_pause_producers(self) -> bool:
for consumer in self.get_consumers():
if (
consumer.priority_level
< channel.ChannelConsumerPriorityLevels.OPTIONAL.value
< async_channel.ChannelConsumerPriorityLevels.OPTIONAL.value
):
return False
return True
Expand All @@ -214,7 +216,7 @@ def _should_resume_producers(self) -> bool:
for consumer in self.get_consumers():
if (
consumer.priority_level
< channel.ChannelConsumerPriorityLevels.OPTIONAL.value
< async_channel.ChannelConsumerPriorityLevels.OPTIONAL.value
):
return True
return False
Expand Down Expand Up @@ -244,7 +246,7 @@ def unregister_producer(self, producer) -> None:
def get_producers(self) -> typing.Iterable:
"""
Should be overwritten according to the class needs
:return: channel producers iterable
:return: async_channel producers iterable
"""
return self.producers

Expand Down Expand Up @@ -345,13 +347,13 @@ def _check_filters(consumer_filters, expected_filters) -> bool:
"""
try:
for key, value in expected_filters.items():
if value == channel.CHANNEL_WILDCARD:
if value == async_channel.CHANNEL_WILDCARD:
continue
if isinstance(consumer_filters[key], list):
if set(consumer_filters[key]) & {value, channel.CHANNEL_WILDCARD}:
if set(consumer_filters[key]) & {value, async_channel.CHANNEL_WILDCARD}:
continue
return False
if consumer_filters[key] not in [value, channel.CHANNEL_WILDCARD]:
if consumer_filters[key] not in [value, async_channel.CHANNEL_WILDCARD]:
return False
return True
except KeyError:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# cython: language_level=3, boundscheck=False, wraparound=False
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
cimport channel.channels as channels
cimport async_channel.channels as channels

cdef class ChannelInstances:
cdef public dict channels
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -16,7 +16,7 @@
"""
This module defines created Channels interaction methods
"""
import channel.util.logging_util as logging
import async_channel.util.logging_util as logging


class ChannelInstances:
Expand Down Expand Up @@ -46,7 +46,7 @@ def __init__(self):

def set_chan_at_id(chan, name) -> None:
"""
Add a new channel to the channels instances dictionary at chan.id
Add a new async_channel to the channels instances dictionary at chan.id
:param chan: the channel instance
:param name: the channel name
"""
Expand All @@ -66,9 +66,9 @@ def set_chan_at_id(chan, name) -> None:

def get_channels(chan_id) -> dict:
"""
Get channel instances by channel id
Get async_channel instances by async_channel id
:param chan_id: the channel id
:return: the channel instances at channel id
:return: the channel instances at async_channel id
"""
try:
return ChannelInstances.instance().channels[chan_id]
Expand All @@ -78,7 +78,7 @@ def get_channels(chan_id) -> dict:

def del_channel_container(chan_id) -> None:
"""
Delete all channel id instances
Delete all async_channel id instances
:param chan_id: the channel id
"""
ChannelInstances.instance().channels.pop(chan_id, None)
Expand Down
4 changes: 2 additions & 2 deletions channel/constants.py → async_channel/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -14,7 +14,7 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
"""
Define channel global constants
Define async_channel global constants
"""
CHANNEL_WILDCARD = "*"

Expand Down
2 changes: 1 addition & 1 deletion channel/consumer.pxd → async_channel/consumer.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# cython: language_level=3, boundscheck=False, wraparound=False
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand Down
12 changes: 6 additions & 6 deletions channel/consumer.py → async_channel/consumer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Drakkar-Software channel
# Drakkar-Software Async-Channel
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
Expand All @@ -14,12 +14,12 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
"""
Define channel Consumer class
Define async_channel Consumer class
"""
import asyncio

import channel.util.logging_util as logging
import channel.enums
import async_channel.util.logging_util as logging
import async_channel.enums


class Consumer:
Expand All @@ -33,8 +33,8 @@ class Consumer:
def __init__(
self,
callback: object,
size: int = channel.constants.DEFAULT_QUEUE_SIZE,
priority_level: int = channel.enums.ChannelConsumerPriorityLevels.HIGH.value,
size: int = async_channel.constants.DEFAULT_QUEUE_SIZE,
priority_level: int = async_channel.enums.ChannelConsumerPriorityLevels.HIGH.value,
):
self.logger = logging.get_logger(self.__class__.__name__)

Expand Down
Loading

0 comments on commit a15df55

Please sign in to comment.