Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: remove i18n, as it is unused and implemented inconsistently #369

Merged
merged 1 commit into from
Feb 29, 2020
Merged
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
1 change: 0 additions & 1 deletion .jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pipeline {
CODECOV_TOKEN = credentials('codecov-token')
}
steps {
sh 'tox -e i18n'
sh 'tox tests/unit'
sh 'codecov'
}
Expand Down
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ github-tag: ## Create and push a tag with the current version
git tag -a v${PKG_VERSION} -m "${PKG_NAME} version v${PKG_VERSION}"
git push -u origin v${PKG_VERSION}

.PHONY: i18n
i18n: ## Update the translations catalog
tox -e i18n

.PHONY: lint
lint: ## Run linting checks on the project source code (isort, flake8, twine)
tox -e lint
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
python_requires='>=3.6',
package_data={
'': ['LICENSE'],
'synse_server': ['locale/*/LC_MESSAGES/*.mo'],
},
entry_points={
'console_scripts': [
Expand All @@ -59,7 +58,5 @@
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
]
)
3 changes: 1 addition & 2 deletions synse_server/api/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from structlog import get_logger

from synse_server import cmd, errors, utils
from synse_server.i18n import _

logger = get_logger()

Expand All @@ -26,7 +25,7 @@ def log_request(request, **kwargs):
kwargs: Any additional fields to add to the structured logs.
"""
logger.debug(
_('processing request'),
'processing request',
method=request.method,
ip=request.ip,
path=request.path,
Expand Down
23 changes: 11 additions & 12 deletions synse_server/api/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from structlog import get_logger

from synse_server import cmd, errors, utils
from synse_server.i18n import _
from synse_server.metrics import Monitor

logger = get_logger()
Expand All @@ -24,7 +23,7 @@
async def connect(request: Request, ws: WebSocketCommonProtocol) -> None:
"""Connect to the WebSocket API."""

logger.info(_('new websocket connection'), source=request.ip)
logger.info('new websocket connection', source=request.ip)
Monitor.ws_session_count.labels(request.ip).inc()

try:
Expand All @@ -41,7 +40,7 @@ def __init__(self, data: str) -> None:
try:
d = json.loads(data)
except Exception as e:
logger.error(_('failed to load payload'), err=e)
logger.error('failed to load payload', err=e)
raise

if 'id' not in d:
Expand Down Expand Up @@ -121,21 +120,21 @@ def __init__(self, ws: WebSocketCommonProtocol) -> None:
self.tasks = []

async def run(self) -> None:
logger.debug(_('running message handler for websocket'), host=self.ws.host)
logger.debug('running message handler for websocket', host=self.ws.host)
async for message in self.ws:
handler_start = time.time()
try:
p = Payload(message)
except Exception as e:
logger.error(_('error loading websocket message'), error=e)
logger.error('error loading websocket message', error=e)
await self.send(**error(ex=e))
continue

logger.debug(_('websocket handler: got message'), payload=p)
logger.debug('websocket handler: got message', payload=p)
try:
await self.dispatch(p)
except Exception as e:
logger.error(_('error generating websocket response'), err=e)
logger.error('error generating websocket response', err=e)
continue

latency = time.time() - handler_start
Expand Down Expand Up @@ -199,15 +198,15 @@ async def dispatch(self, payload: Payload) -> None:

try:
logger.debug(
_('processing websocket request'),
'processing websocket request',
handler=handler, type=payload.event, id=payload.id, data=payload.data,
)
await getattr(self, handler)(payload)
except asyncio.CancelledError:
logger.info(_('websocket request cancelled'), handler=handler)
logger.info('websocket request cancelled', handler=handler)
return
except Exception as e:
logger.exception(_('error processing websocket request'), err=e)
logger.exception('error processing websocket request', err=e)
await self.send(**error(
msg_id=payload.id,
ex=e,
Expand Down Expand Up @@ -424,7 +423,7 @@ async def handle_request_read_stream(self, payload: Payload) -> None:
stop = payload.data.get('stop', False)

if stop:
logger.debug(_('read stream stop request received - terminating stream tasks'))
logger.debug('read stream stop request received - terminating stream tasks')
for t in self.tasks:
t.cancel()
return
Expand All @@ -438,7 +437,7 @@ async def send_readings():
data=reading,
)
except ConnectionClosed:
logger.info(_('websocket raised ConnectionClosed - terminating read stream'))
logger.info('websocket raised ConnectionClosed - terminating read stream')
return

t = asyncio.ensure_future(send_readings())
Expand Down
25 changes: 12 additions & 13 deletions synse_server/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from synse_grpc import api

from synse_server import loop, plugin
from synse_server.i18n import _

logger = get_logger()

Expand Down Expand Up @@ -83,7 +82,7 @@ async def add_transaction(transaction_id: str, device: str, plugin_id: str) -> b
True if successful; False otherwise.
"""
logger.debug(
_('caching transaction'), plugin=plugin_id, id=transaction_id, device=device,
'caching transaction', plugin=plugin_id, id=transaction_id, device=device,
)
return await transaction_cache.set(
transaction_id,
Expand All @@ -105,7 +104,7 @@ async def add_alias(alias: str, device: api.V3Device) -> bool:
True if successful; False otherwise.
"""
logger.debug(
_('adding alias to cache'), alias=alias, device=device.id,
'adding alias to cache', alias=alias, device=device.id,
)

async with alias_cache_lock:
Expand Down Expand Up @@ -140,7 +139,7 @@ async def update_device_cache() -> None:
"default/x:bar": [{...}]
"vaporio/svc:xyz": [{...}, {...}]
"""
logger.info(_('updating the device cache'))
logger.info('updating the device cache')

# Get the list of all devices (including their associated tags) from
# each registered plugin. This device data will be used to generate
Expand All @@ -151,7 +150,7 @@ async def update_device_cache() -> None:
# Synse Server is first starting up, being restarted, or is recovering from a
# networking error.
if not plugin.manager.has_plugins() or not plugin.manager.all_active():
logger.debug(_('refreshing plugins prior to updating device cache'))
logger.debug('refreshing plugins prior to updating device cache')
plugin.manager.refresh()

# A temporary dicts used to collect the data for rebuilding the device cache.
Expand All @@ -161,7 +160,7 @@ async def update_device_cache() -> None:
for p in plugin.manager:
if not p.active:
logger.debug(
_('plugin not active, will not get its devices'),
'plugin not active, will not get its devices',
plugin=p.tag, plugin_id=p.id,
)
continue
Expand Down Expand Up @@ -191,16 +190,16 @@ async def update_device_cache() -> None:

device_count += 1
logger.debug(
_('got devices from plugin'),
'got devices from plugin',
plugin=p.tag, plugin_id=p.id, device_count=device_count,
)

except grpc.RpcError as e:
logger.warning(_('failed to get device(s)'), plugin=p.tag, plugin_id=p.id, error=e)
logger.warning('failed to get device(s)', plugin=p.tag, plugin_id=p.id, error=e)
continue
except Exception:
logger.exception(
_('unexpected error when updating devices for plugin'), plugin_id=p.id)
'unexpected error when updating devices for plugin', plugin_id=p.id)
raise

async with device_cache_lock:
Expand Down Expand Up @@ -240,7 +239,7 @@ async def get_device(device_id: str) -> Union[api.V3Device, None]:
# Every device has a system-generated ID tag in the format 'system/id:<device id>'
# which we can use here to get the device. If the ID tag is not in the cache,
# we take that to mean that there is no such device.
logger.debug(_('looking up device ID in cache'), id=device_id)
logger.debug('looking up device ID in cache', id=device_id)
async with device_cache_lock:
result = await device_cache.get(f'system/id:{device_id}')

Expand All @@ -249,15 +248,15 @@ async def get_device(device_id: str) -> Union[api.V3Device, None]:
# empty, return the first element of the list - there should only be
# one element; otherwise, return None.
if result:
logger.debug(_('got device from cache'))
logger.debug('got device from cache')
device = result[0]
else:
logger.debug(_('failed to lookup device from cache'), id=device_id)
logger.debug('failed to lookup device from cache', id=device_id)

# No device was found from an ID lookup. Try looking up the ID in the
# alias cache.
if not device:
logger.debug(_('device ID not found in cache - checking for alias'), id=device_id)
logger.debug('device ID not found in cache - checking for alias', id=device_id)
device = await get_alias(device_id)

return device
Expand Down
3 changes: 1 addition & 2 deletions synse_server/cmd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from structlog import get_logger

from synse_server.config import options
from synse_server.i18n import _

logger = get_logger()

Expand All @@ -15,6 +14,6 @@ async def config() -> Dict[str, Any]:
Returns:
A dictionary representation of the config response.
"""
logger.info(_('issuing command'), command='CONFIG')
logger.info('issuing command', command='CONFIG')

return {k: v for k, v in options.config.items() if not k.startswith('_')}
3 changes: 1 addition & 2 deletions synse_server/cmd/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from synse_grpc import utils

from synse_server import cache, errors
from synse_server.i18n import _

logger = get_logger()

Expand All @@ -19,7 +18,7 @@ async def info(device_id: str) -> Dict[str, Any]:
Returns:
A dictionary representation of the device info response.
"""
logger.info(_('issuing command'), command='INFO', device_id=device_id)
logger.info('issuing command', command='INFO', device_id=device_id)

device = await cache.get_device(device_id)
if device is None:
Expand Down
9 changes: 4 additions & 5 deletions synse_server/cmd/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import synse_server.utils
from synse_server import errors
from synse_server.i18n import _
from synse_server.plugin import manager

logger = get_logger()
Expand All @@ -21,7 +20,7 @@ async def plugin(plugin_id: str) -> Dict[str, Any]:
Returns:
A dictionary representation of the plugin response.
"""
logger.info(_('issuing command'), command='PLUGIN', plugin_id=plugin_id)
logger.info('issuing command', command='PLUGIN', plugin_id=plugin_id)

# If there are no plugins registered, re-registering to ensure
# the most up-to-date plugin state.
Expand Down Expand Up @@ -63,7 +62,7 @@ async def plugins(refresh: bool) -> List[Dict[str, Any]]:
Returns:
A list of dictionary representations of the plugin summary response(s).
"""
logger.info(_('issuing command'), command='PLUGINS')
logger.info('issuing command', command='PLUGINS')

# If there are no plugins registered, re-registering to ensure
# the most up-to-date plugin state.
Expand All @@ -87,7 +86,7 @@ async def plugin_health() -> Dict[str, Any]:
Returns:
A dictionary representation of the plugin health.
"""
logger.info(_('issuing command'), command='PLUGIN HEALTH')
logger.info('issuing command', command='PLUGIN HEALTH')

# If there are no plugins registered, re-registering to ensure
# the most up-to-date plugin state.
Expand All @@ -104,7 +103,7 @@ async def plugin_health() -> Dict[str, Any]:
with p as client:
health = client.health()
except Exception as e:
logger.warning(_('failed to get plugin health'), plugin=p.tag, error=e)
logger.warning('failed to get plugin health', plugin=p.tag, error=e)
else:
if health.status == api.OK:
healthy.append(p.id)
Expand Down
Loading