diff --git a/pydbapi/__init__.py b/pydbapi/__init__.py index fedcd70..f8867ff 100644 --- a/pydbapi/__init__.py +++ b/pydbapi/__init__.py @@ -2,15 +2,13 @@ # @Author: chunyang.xu # @Date: 2023-06-02 15:27:41 # @Last Modified by: longfengpili -# @Last Modified time: 2024-08-12 13:45:06 +# @Last Modified time: 2024-08-12 13:49:40 # @github: https://github.com/longfengpili import os import logging.config -from pathlib import Path -from pydbapi.api.pydbmagics import PydbapiMagics from pydbapi.conf import LOGGING_CONFIG logging.config.dictConfig(LOGGING_CONFIG) @@ -21,22 +19,3 @@ # __all__ = ['SqliteDB', 'RedshiftDB', 'MysqlDB', 'SnowflakeDB', # 'SqlParse', 'SqlCompile', 'SqlFileParse', 'ColumnModel', 'ColumnsModel'] - - -# 注册magic命令 -def load_ipython_extension(ipython): - ipython.register_magics(PydbapiMagics) - - -def register_magic(): - # IPython 启动目录及脚本 - ipython_startup_dir = Path.home() / ".ipython" / "profile_default" / "startup" - startup_script_path = ipython_startup_dir / "00-pydbapi-startup.py" - - # 确保启动目录存在 - if not os.path.exists(ipython_startup_dir): - os.makedirs(ipython_startup_dir) - - # 写入启动脚本 - with open(startup_script_path, 'w') as f: - f.write("get_ipython().run_line_magic('load_ext', 'pydbapi')\n") diff --git a/pydbapi/api/pydbmagics.py b/pydbapi/api/pydbapimagic.py similarity index 88% rename from pydbapi/api/pydbmagics.py rename to pydbapi/api/pydbapimagic.py index 3193f6d..e53a9d3 100644 --- a/pydbapi/api/pydbmagics.py +++ b/pydbapi/api/pydbapimagic.py @@ -2,10 +2,10 @@ # @Author: longfengpili # @Date: 2023-11-02 13:36:08 # @Last Modified by: longfengpili -# @Last Modified time: 2024-08-06 10:50:05 +# @Last Modified time: 2024-08-12 13:48:05 # @github: https://github.com/longfengpili - +from pathlib import Path import pandas as pd from IPython.core.error import UsageError @@ -29,6 +29,25 @@ from pydbapi.api import SqliteDB, MysqlDB, RedshiftDB, TrinoDB +# 注册magic命令 +def load_ipython_extension(ipython): + ipython.register_magics(PydbapiMagics) + + +def register_magic(): + # IPython 启动目录及脚本 + ipython_startup_dir = Path.home() / ".ipython" / "profile_default" / "startup" + startup_script_path = ipython_startup_dir / "00-pydbapi-startup.py" + + # 确保启动目录存在 + if not ipython_startup_dir.exists(): + ipython_startup_dir.mkdir(parents=True) + + # 写入启动脚本 + with open(startup_script_path, 'w') as f: + f.write("get_ipython().run_line_magic('load_ext', 'pydbapi')\n") + + @magics_class class PydbapiMagics(Magics): dbtype = Unicode('trino', diff --git a/setup.py b/setup.py index 50e03ab..d302c82 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ # @Author: longfengpili # @Date: 2023-06-02 15:27:41 # @Last Modified by: longfengpili -# @Last Modified time: 2024-08-12 13:45:34 +# @Last Modified time: 2024-08-12 13:50:18 # @github: https://github.com/longfengpili @@ -54,10 +54,10 @@ def run(self): install_requires=requires, entry_points={ 'ipython.extensions': [ - 'pydbapi = pydbapi:load_ipython_extension', + 'pydbapi = pydbapi.api.pydbapimagic:load_ipython_extension', ], 'console_scripts': [ - 'pydbapimagic = pydbapi:register_magic', + 'pydbapimagic = pydbapi.api.pydbapimagic:register_magic', ], }, classifiers=[