Skip to content
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
6 changes: 2 additions & 4 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel

jobs:
# This workflow contains a single job called "build"
build:
build-pypi-package:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# sudo python setup.py install clean --all
Expand Down
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"charliermarsh.ruff",
"dbcode.dbcode",
"esbenp.prettier-vscode",
"ms-python.python",
"ms-python.vscode-pylance"
],
"unwantedRecommendations": []
}
26 changes: 26 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"editor.formatOnSave": true,
"files.exclude": {
"**/.git": true,
"**/node_modules": true,
"**/__pycache__": true,
"**/*.pyc": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll.ruff": "explicit"
}
},
"[sql]": {
"editor.defaultFormatter": "dbcode.dbcode", // mtxr.sqltools, dbcode.dbcode, ReneSaarsoo.sql-formatter-vsc
"editor.formatOnSave": true
},
"ruff.lineLength": 128,
"ruff.configuration": {
"format": {
"quote-style": "double"
}
}
}
Empty file removed demo/app_common/ainlp/__init__.py
Empty file.
86 changes: 0 additions & 86 deletions demo/app_common/ainlp/model_bert.py

This file was deleted.

Empty file.
19 changes: 19 additions & 0 deletions demo/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import importlib
import sys

usage = """
Usage: python3 main.py module.name
the `module.name` should be a python package file or package which include a `main()` function
"""

if len(sys.argv) < 2:
print(usage)
exit(-1)

m = importlib.import_module(sys.argv[1])
f_main = getattr(m, "main")

if f_main is None:
print("Given module does not provides a `main()` function!")
else:
f_main()
1 change: 1 addition & 0 deletions demo/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aloha[all]
79 changes: 79 additions & 0 deletions src/aloha/db/oracle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
__all__ = ('OracledbOperator',)

import oracledb
from sqlalchemy import create_engine
from sqlalchemy.sql import text

from .base import PasswordVault
from ..logger import LOG

LOG.debug("oracledb version = %s" % oracledb.__version__)


class OracledbOperator:
def __init__(self, db_config, **kwargs):
"""example of db_config:
{
"host": "192.168.1.100",
"port": 1521,
"user": "PT_INDEX",
"password": "vault_key_or_plain",
"service_name": "orcl", # 推荐使用 service_name
"sid": "orcl", # 或使用 sid
"vault_type": "...",
"vault_config": {...},
"lib_dir": "/opt/oracle/instantclient" # optional, use THICK mode if defined.
}
"""

password_vault = PasswordVault.get_vault(db_config.get('vault_type'), db_config.get('vault_config'))
self._config = {
'host': db_config['host'],
'port': db_config['port'],
'user': db_config['user'],
'password': password_vault.get_password(db_config.get('password')),
}

if 'lib_dir' in db_config: # use Thick mode
try:
oracledb.init_oracle_client(lib_dir=db_config['lib_dir'])
LOG.info("Oracle client initialized in THICK mode from: %s" % db_config["lib_dir"])
except Exception as e:
LOG.warning(f"Warning: {e}")
raise RuntimeError(f"Failed to initialize Oracle client: {e}")

service_name = db_config.get("service_name")
sid = db_config.get("sid")

if service_name: # using service_name (recommended)
dsn = oracledb.makedsn(db_config["host"], db_config["port"], service_name=service_name)
elif sid: # using SID
dsn = oracledb.makedsn(db_config["host"], db_config["port"], sid=sid)
else:
raise ValueError("Oracle config must specify service_name or sid")

self._config["dsn"] = dsn
try:
self.engine = create_engine(
"oracle+oracledb://{user}:{password}@".format(**self._config),
connect_args={"dsn": dsn},
pool_size=20, max_overflow=10, pool_pre_ping=True, **kwargs
)
msg = "OracleDB connected: {host}:{port}".format(**self._config)
print(msg)
except Exception as e:
LOG.error(e)
raise RuntimeError(f"Failed to connect to OracleDB")

@property
def connection(self):
return self.engine

def execute_query(self, sql, *args, **kwargs):
with self.engine.connect() as conn:
cur = conn.execute(text(sql), *args, **kwargs)
return cur

@property
def connection_str(self) -> str:
return "oracle://{user}@{host}:{port}".format(**self._config)
2 changes: 1 addition & 1 deletion src/aloha/db/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, db_config, **kwargs):
LOG.debug("PostgresSQL connected: {host}:{port}/{dbname}".format(**self._config))
except Exception as e:
LOG.error(e)
raise RuntimeError('Failed to connect to PostgresSQL')
raise RuntimeError("Failed to connect to PostgresSQL")

@property
def connection(self):
Expand Down
2 changes: 2 additions & 0 deletions src/aloha/logger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__all__ = ("LOG", "get_logger")

from .logger import get_logger
from ..settings import SETTINGS

Expand Down
4 changes: 0 additions & 4 deletions src/aloha/service/streamer/__init__.py

This file was deleted.

Loading