Skip to main content

Snake Nest

Project description

SnakeNest

nest.yaml

application:
  name: test
  spesa:
    - casa
    - sale
    - olio


snake:
  test:
    enable: pollo

Example 1

from snakenest import *
from abc import ABC, abstractmethod


class WorkflowManager(ABC):
    @abstractmethod
    def test(self):
        pass


@Snake(condition={'key': 'snake.test.enable', 'value': 'salame'})
class Test1(WorkflowManager):

    def __init__(self):
        super().__init__()

    def test(self):
        print("Test1")


@Snake(condition={'key': 'snake.test.enable', 'value': 'pollo'})
class Test2(WorkflowManager):
    def __init__(self):
        super().__init__()

    def test(self):
        print("Test2")


class Check:
    @Poisoned()
    def __init__(self, wf: WorkflowManager):
        wf.test()


def print_hi(name):
    Check()


if __name__ == '__main__':
    Nest.initialize()
    print_hi('Clint')

Example 2

from snakenest import *


@Snake(args={"val1": "10", "val2": "22"})
class Config:
    def __init__(self, val1, val2):
        self.val1 = val1
        self.val2 = val2

    def get_val1(self):
        return self.val1

    def get_val2(self):
        return self.val2


@Snake()
class MyCondition:
    def __init__(self):
        pass


@Snake()
class Test:
    @Poisoned()
    def __init__(self, config: Config):
        self.__config = config
        print(f'Test: {self.__config.__dict__}')

    def hello(self, name):
        return f"Test: Hello {name}"

    def getName(self):
        return "test_name"


@Snake(name='testName', args={"q": "10", "b": "${application.spesa:casa}"})
class Pollo:
    def __init__(self, q, b):
        self.q, self.b = q, b

    def hello(self, name):
        return f"Test_named: Hello {name}"

    def getName(self):
        return f'Pollo -> TestNamed: {self.q} - {self.b}'


class Test2:

    @Poisoned()
    def __init__(self, config: Config):
        self.__config = config
        print(f'Test2: {self.__config.__dict__}')

    @Poisoned()
    def getTestName(self, panico, name: Test):
        return name.hello(panico)

    @Poisoned(name='testName')
    def getTestName2(self, name):  # <-- tipo non definito ma injected
        return name.getName()


def print_hi(name):
    t2 = Test2()
    print(f'Hi, {name}, {t2.getTestName("sale")} {t2.getTestName2()} ')


if __name__ == '__main__':
    Nest.initialize()
    print_hi('PyCharm')
    # SnakeNest.clear()

SnakeBus message

class MySubscriber(SnakeNotificationSubscriber):
    def handle_event(self, event_type, data=None):
        print(f'Received: {event_type} data: {data}')


class Service:
    def test(self):
        SnakesBus.publish('eventTest', {'something': 'test_data'})


SnakesBus.subscribe('eventTest', MySubscriber())
Service().test()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snakenest-0.3.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file snakenest-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: snakenest-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.13

File hashes

Hashes for snakenest-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fdaa2e23e9e65411732fbd2d2c548e7fa72a712a3601ac445e1249c88b72da9
MD5 a85a1521df08857ef17573778c168db0
BLAKE2b-256 a524112d289440eaafd8af87a0091ebb11c394170321e5ffb23634aeea5f3bd6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page