折腾:
之前,需要去优化代码目录结构。现在的情况是:
nlp的代码,是自己的一个目录下面的,顶级目录并列的有一些辅助的,比如util,processData,depoy等目录
而之前已有的几个application系统,有Flaks的robotDemo,有Django的Cms的剧本系统等等,都是各自放在另外的代码仓库的,且部署到dev服务器上目录层级较深:
<code>[root@xxx-general-01 yyy]# tree -L 2 . . ├── conf │ └── main.conf ├── crawler │ └── origin_data ├── data ├── deploy ├── nlp │ ├── for_debug │ └── yyy ├── processData │ └── other ├── search │ ├── ... │ └── web_qa.py ├── util │ ├── configs.py │ ├── database.py │ ├── paths.py │ └── __pycache__ └── web ├── server │ ├── for_bacup_mysql │ ├── zzServer │ ├── zzServer.sock │ └── robotDemo ├── tool │ ├── BatchImportScript │ └── BatchImportScript_180717.zip └── www ├── 404.html ├── 50x.html ├── favicon.jpg ├── favicon.png ├── index.html ├── fffWeb ├── nginx-logo.png ├── poweredby.png └── robotDemo </code>
其中可见,web下面放了robotDemo和和xxxServer
并且robotDemo中又单独包含了yyy的整套代码:
现在希望是整合目录,减少目录层级,nlp和web并列,app方面都放web下面
然后理一下整体顺序
先去删除本地pipenv的虚拟环境
然后再去删除xxxRobotDemoServer中的ai的所有代码
然后再去模拟dev线上环境的:
└── web
├── server
│ └── robotDemo
去robotDemo的父级目录中,分别建立对应的server和web,以及和web并列的nlp,util,conf等文件夹
确保本地目录和线上结构一致
不过发现这么弄,就把我之前的项目代码搞混淆了:
所以感觉可以换个方式去:
在xxx的代码中:
去建个web目录,然后把之前的robotDemo和xxxDemoServer的项目代码都放到里面:
刚打算这么做,突然发现也不太好:
<code>➜ server git:(master) ✗ git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: ../../.idea/other.xml Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: ../../.gitignore modified: ../../.idea/yyy modified: ../../.idea/workspace.xml modified: ../../Pipfile modified: ../../Pipfile.lock modified: ../../util/crifanLib/crifanDatetime.py ➜ server git:(master) ✗ pwd /Users/crifan/dev/dev_root/xxx/web/server </code>
导致git中嵌套git:
导致:
中
/Users/crifan/dev/dev_root/uuu/
的主git
嵌套了将要创建的:
/Users/crifan/dev/dev_root/jjjj/web/server/robotDemo
感觉很容易就混乱了。
所以还是单独分离开吧。
然后对于:其他的robotDemo等项目,想要引用xx的代码,就很麻烦了:
只能在代码里面,尽量减少耦合,然后import对应路径,再去引用
而且发布到线上时,代码路径还要根据线上环境修改。
就先这样吧。进来通过减少耦合来解决这个问题。
毕竟另外一个项目llllCmsServer,和zzz基本上没关系,至少和nlp没关系。
此处先去处理:
robotDemo的server,去引用本地的zzz的nlp的dialog的代码
确保能运行起来,再去处理后续的事情
之前删除了虚拟环境,现在再去安装出来,先去修改Pipfile为:
<code>➜ zzzDemoServer git:(master) ✗ cat Pipfile [[source]] #url = "https://pypi.python.org/simple" url = "https://pypi.tuna.tsinghua.edu.cn/simple" verify_ssl = true name = "pypi" [packages] flask = "*" flask-restful = "*" flask-pymongo = "*" gunicorn = "*" pymysql = "*" openpyxl = "*" flask-cors = "*" requests = "*" celery = {extras = ["redis"]} [dev-packages] [requires] python_version = "3.6" </code>
然后才能正常安装:
<code>➜ zzzDemoServer git:(master) ✗ pipenv install Creating a virtualenv for this project... Pipfile: /Users/crifan/dev/dev_root/company/xxx/Pipfile Using /usr/local/bin/python3.6m (3.6.4) to create virtualenv... ⠋Running virtualenv with interpreter /usr/local/bin/python3.6m Using base prefix '/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6' New python executable in /Users/crifan/.local/share/virtualenvs/xxx-SCpLPEyZ/bin/python3.6 Also creating executable in /Users/crifan/.local/share/virtualenvs/xxx/bin/python Installing setuptools, pip, wheel...done. Setting project for xx-SCpLPEyZ to /Users/crifan/dev/dev_root/xxx Virtualenv location: /Users/crifan/.local/share/virtualenvs/xxx-SCpLPEyZ Pipfile.lock (132fcc) out of date, updating to (f83e81)... Locking [dev-packages] dependencies... Locking [packages] dependencies... Updated Pipfile.lock (f83e81)! Installing dependencies from Pipfile.lock (f83e81)... 🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 33/33 — 00:00:17 To activate this project's virtualenv, run pipenv shell. Alternatively, run a command inside the virtualenv with pipenv run. </code>
然后再去调试,确保服务能正常运行。
后来是通过改变导入路径:
<code>import sys # production: online dev server # sys.path.append("../../../nlp/dialog") # development: local debug xxx = "/Users/crifan/dev/dev_root/xxx" sys.path.append(xxxx) sys.path.append(os.path.join(xxx, "nlp")) sys.path.append(os.path.join(xxx, "nlp/dialog")) from DialogueManager import Context from intent import DialogInput from AccessData import AccessData from GenerateResponse import GenerateResponse </code>
从而可以找到:
代码得以继续运行。
然后再去测试接口是没问题的:
然后再测试了next多次后,返回为空的情况:
此处,就是要用到后续的兜底对话的部分,返回兜底的回答,就是seach的代码的整合了,详见之前的:
此处还是先列一下,后期需要注意的事情:
xxx和nlp,以及robotDemo,yyyCms等,都改为fabric部署代码
dev服务器中
目前/root/xxx/nlp下面是xxx
要先去同步代码为 dialog和search
先要去参考:
/root/xxx/search
合并到代码里:
/root/xxx/nlp/search
测试没问题后,再去删除
/root/xxx/nlp/xxx
/root/xx/search
转载请注明:在路上 » 【已解决】优化整个系统的多个项目的代码结构