renames
This commit is contained in:
312
Expert Mode.ipynb
Normal file
312
Expert Mode.ipynb
Normal file
@@ -0,0 +1,312 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"import json\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"import yaml\n",
|
||||
"from rich import print"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class EmptyClass:\n",
|
||||
" pass\n",
|
||||
"\n",
|
||||
"self = EmptyClass()\n",
|
||||
"self.AD = EmptyClass()\n",
|
||||
"self.AD.app_dir = '/mnt/ad_dev_conf/apps'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Python parents:\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
"Python parents:\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"> - <span style=\"color: #800080; text-decoration-color: #800080\">/mnt/ad_dev_conf/apps/my_repo/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">my_pkg</span>\n",
|
||||
" - <span style=\"color: #800080; text-decoration-color: #800080\">/mnt/ad_dev_conf/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">apps</span>\n",
|
||||
" - <span style=\"color: #800080; text-decoration-color: #800080\">/mnt/ad_dev_conf/apps/my_repo/my_pkg/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">my_sub_pkg</span>\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
" - \u001b[35m/mnt/ad_dev_conf/apps/my_repo/\u001b[0m\u001b[95mmy_pkg\u001b[0m\n",
|
||||
" - \u001b[35m/mnt/ad_dev_conf/\u001b[0m\u001b[95mapps\u001b[0m\n",
|
||||
" - \u001b[35m/mnt/ad_dev_conf/apps/my_repo/my_pkg/\u001b[0m\u001b[95mmy_sub_pkg\u001b[0m\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Module parents:\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
"Module parents:\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"> - <span style=\"color: #800080; text-decoration-color: #800080\">/mnt/ad_dev_conf/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">apps</span>\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
" - \u001b[35m/mnt/ad_dev_conf/\u001b[0m\u001b[95mapps\u001b[0m\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Package parents:\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
"Package parents:\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"> - <span style=\"color: #800080; text-decoration-color: #800080\">/mnt/ad_dev_conf/apps/my_repo/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">my_pkg</span>\n",
|
||||
" - <span style=\"color: #800080; text-decoration-color: #800080\">/mnt/ad_dev_conf/apps/my_repo/my_pkg/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">my_sub_pkg</span>\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
" - \u001b[35m/mnt/ad_dev_conf/apps/my_repo/\u001b[0m\u001b[95mmy_pkg\u001b[0m\n",
|
||||
" - \u001b[35m/mnt/ad_dev_conf/apps/my_repo/my_pkg/\u001b[0m\u001b[95mmy_sub_pkg\u001b[0m\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Top package parents:\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
"Top package parents:\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"> - <span style=\"color: #800080; text-decoration-color: #800080\">/mnt/ad_dev_conf/apps/my_repo/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">my_pkg</span>\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
" - \u001b[35m/mnt/ad_dev_conf/apps/my_repo/\u001b[0m\u001b[95mmy_pkg\u001b[0m\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Imports\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
"Imports\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"> - <span style=\"color: #800080; text-decoration-color: #800080\">/mnt/ad_dev_conf/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">apps</span>\n",
|
||||
" - <span style=\"color: #800080; text-decoration-color: #800080\">/mnt/ad_dev_conf/apps/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">my_repo</span>\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
" - \u001b[35m/mnt/ad_dev_conf/\u001b[0m\u001b[95mapps\u001b[0m\n",
|
||||
" - \u001b[35m/mnt/ad_dev_conf/apps/\u001b[0m\u001b[95mmy_repo\u001b[0m\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"base_path = Path(self.AD.app_dir)\n",
|
||||
"\n",
|
||||
"python_file_parents = set(\n",
|
||||
" f.parent.resolve()\n",
|
||||
" for f in base_path.rglob('*.py')\n",
|
||||
")\n",
|
||||
"print('Python parents:')\n",
|
||||
"print('\\n'.join(f' - {p.as_posix()}' for p in python_file_parents))\n",
|
||||
"\n",
|
||||
"module_parents = set(\n",
|
||||
" p for p in python_file_parents\n",
|
||||
" if not (p / '__init__.py').exists()\n",
|
||||
")\n",
|
||||
"print('Module parents:')\n",
|
||||
"print('\\n'.join(f' - {p.as_posix()}' for p in module_parents))\n",
|
||||
"\n",
|
||||
"package_parents = set(\n",
|
||||
" p for p in python_file_parents\n",
|
||||
" if (p / '__init__.py').exists()\n",
|
||||
")\n",
|
||||
"print('Package parents:')\n",
|
||||
"print('\\n'.join(f' - {p.as_posix()}' for p in package_parents))\n",
|
||||
"\n",
|
||||
"top_packages_dirs = set(\n",
|
||||
" p for p in package_parents\n",
|
||||
" if not (p.parent / '__init__.py').exists()\n",
|
||||
")\n",
|
||||
"print('Top package parents:')\n",
|
||||
"print('\\n'.join(f' - {p.as_posix()}' for p in top_packages_dirs))\n",
|
||||
"\n",
|
||||
"import_dirs = module_parents | set(p.parent for p in top_packages_dirs)\n",
|
||||
"print('Imports')\n",
|
||||
"print('\\n'.join(f' - {p.as_posix()}' for p in import_dirs))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span>\n",
|
||||
" <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">PosixPath</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008000; text-decoration-color: #008000\">'/mnt/ad_dev_conf/apps/my_repo/my_pkg/__init__.py'</span><span style=\"font-weight: bold\">)</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'my_pkg'</span>,\n",
|
||||
" <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">PosixPath</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008000; text-decoration-color: #008000\">'/mnt/ad_dev_conf/apps/my_repo/my_pkg/motion.py'</span><span style=\"font-weight: bold\">)</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'my_pkg'</span>,\n",
|
||||
" <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">PosixPath</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008000; text-decoration-color: #008000\">'/mnt/ad_dev_conf/apps/my_repo/my_pkg/my_sub_pkg/__init__.py'</span><span style=\"font-weight: bold\">)</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'my_pkg'</span>,\n",
|
||||
" <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">PosixPath</span><span style=\"font-weight: bold\">(</span><span style=\"color: #008000; text-decoration-color: #008000\">'/mnt/ad_dev_conf/apps/my_repo/my_pkg/my_sub_pkg/hello.py'</span><span style=\"font-weight: bold\">)</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'my_pkg'</span>\n",
|
||||
"<span style=\"font-weight: bold\">}</span>\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
"\u001b[1m{\u001b[0m\n",
|
||||
" \u001b[1;35mPosixPath\u001b[0m\u001b[1m(\u001b[0m\u001b[32m'/mnt/ad_dev_conf/apps/my_repo/my_pkg/__init__.py'\u001b[0m\u001b[1m)\u001b[0m: \u001b[32m'my_pkg'\u001b[0m,\n",
|
||||
" \u001b[1;35mPosixPath\u001b[0m\u001b[1m(\u001b[0m\u001b[32m'/mnt/ad_dev_conf/apps/my_repo/my_pkg/motion.py'\u001b[0m\u001b[1m)\u001b[0m: \u001b[32m'my_pkg'\u001b[0m,\n",
|
||||
" \u001b[1;35mPosixPath\u001b[0m\u001b[1m(\u001b[0m\u001b[32m'/mnt/ad_dev_conf/apps/my_repo/my_pkg/my_sub_pkg/__init__.py'\u001b[0m\u001b[1m)\u001b[0m: \u001b[32m'my_pkg'\u001b[0m,\n",
|
||||
" \u001b[1;35mPosixPath\u001b[0m\u001b[1m(\u001b[0m\u001b[32m'/mnt/ad_dev_conf/apps/my_repo/my_pkg/my_sub_pkg/hello.py'\u001b[0m\u001b[1m)\u001b[0m: \u001b[32m'my_pkg'\u001b[0m\n",
|
||||
"\u001b[1m}\u001b[0m\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"association = {}\n",
|
||||
"for dir in top_packages_dirs:\n",
|
||||
" associated_modules = list(dir.rglob('*.py'))\n",
|
||||
" # print('\\n'.join(f' - {p.as_posix()}' for p in associated_modules))\n",
|
||||
" for module_file in associated_modules:\n",
|
||||
" association[module_file] = dir.stem\n",
|
||||
"\n",
|
||||
"print(association)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"['hello_sub', 'motion']"
|
||||
]
|
||||
},
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"module_name = 'my_pkg'\n",
|
||||
"\n",
|
||||
"with Path('apps/apps.yaml').open('r') as f:\n",
|
||||
" self.app_config = yaml.load(f, Loader=yaml.SafeLoader)\n",
|
||||
"\n",
|
||||
"self.non_apps = []\n",
|
||||
"\n",
|
||||
"[\n",
|
||||
" app_name\n",
|
||||
" for app_name, app_cfg in self.app_config.items()\n",
|
||||
" if app_cfg['module'].split('.')[0] == module_name\n",
|
||||
"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "ad_dev",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user