ubii.framework.constants module

Global variables are problematic, but global constants are a useful feature especially as fallback for configuration options.

Warning

Keep in mind that assignments to global variables are done when the module is first imported so to make sure to have the “correct” version of the constants defined in this module, import the module, not the individual names

Good:
>>> from ubii.framework import constants
>>> config = constants.GLOBAL_CONFIG
Bad:
>>> from ubii.framework.constants import GLOBAL_GONFIG
ubii.framework.constants.GLOBAL_CONFIG

This is a global UbiiConfig object, typically used as default configuration for client protocols. Use this global config to share configuration changes to values in a global scope.

ubii.framework.constants.UBII_URL_ENV = 'UBII_SERVICE_URL'

Setting this environment variable affects the default_service_url

class ubii.framework.constants.UbiiConfig(SERVER: ~ubii.proto.v1.servers.server_pb_plus.Server = <factory>, CONSTANTS: ~ubii.proto.v1.servers.constants_pb_plus.Constants = <factory>, DEFAULT_SERVICE_URL: str = 'http://localhost:8102/services/json')

Bases: object

Config options for the Ubi interact node.

Note

Uses copies of global attributes from this module as default

i.e. assigning to those values does not change the global defaults from this module

>>> from ubii.framework import constants
>>> config = constants.UbiiConfig()
>>> config.SERVER == constants.default_server
True
>>> config.SERVER.constants_json = "Foo"
>>> config.SERVER == constants.default_server
False
SERVER: Server

needed for all service calls, and typically provided by the master node. To get the config the defaults include the topic for the server configuration service.

CONSTANTS: Constants

includes all meta information about the master node (ip address, ports, etc.) Currently the ubii.proto.Server.constants_json field should be parsed as a ubii.proto.Constants message and updated in your config whenever the Server is updated (at some point the master node might start sending actual proto messages instead of just JSON)

DEFAULT_SERVICE_URL: str

needed to make the first service request (server configuration) before anything else is known (see also UBII_URL_ENV)

ubii.framework.constants.default_service_url

Global variable for url of master node service backend. Read from UBII_URL_ENV environment variable, fallback http://localhost:8102/services/json

ubii.framework.constants.default_server: Server = Server(constants_json=...)

Server with constants_json set to default_contants (converted to JSON)

ubii.framework.constants.default_constants: Constants = Constants(DEFAULT_TOPICS=DefaultTopics(SERVICES=Services(SERVER_CONFIG='/services/server_configuration')))

Constants with default topic for server configuration service set (needed to get all other default topics from master node)