From cd8834816e7613dbd5b32af9be438569bcff440b Mon Sep 17 00:00:00 2001 From: carson_git <543983849@qq.com> Date: Mon, 28 Dec 2020 22:23:13 +0800 Subject: [PATCH 1/8] --- ...0\346\234\254\346\233\264\346\226\260.txt" | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 "doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.txt" diff --git "a/doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.txt" "b/doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.txt" new file mode 100644 index 0000000..9be0930 --- /dev/null +++ "b/doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.txt" @@ -0,0 +1,133 @@ + + + + + + +# 应用通过pip进行版本迭代更新 + +难点: + +pip 安装包只会把文件放置在指定目录下。因此,期待用户安装后,可以通过2种方式启动应用。 + +1. 通过python代码启动 + + ```python + import pandas-ui + ``` + +2. 通过命令,在指定目录输出一个bat文件,后续通过bat文件启动 + + + +# 版本检查 + +通过pip检查最新版本号: + +```python +import subprocess +ret = subprocess.run("pip install pandas-ui== -i https://pypi.douban.com/simple/",stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True) + +ret = str(ret.stderr) +``` + +这个指令会返回一个如: + +```shell +ERROR: Could not find a version that satisfies the requirement pandas-ui== (from versions: 0.1.0, 0.2.0)\r\nERROR: No matching distribution found for test-myp== +``` + + + +使用正则表达式,提取其中的版本信息即可: + +```python +import re +cp = re.compile(r'\((from versions: (.*?))\)') + +vs = cp.search(ret).groups()[1].split(',') +new_verson = vs[-1] +``` + + + +与当前版本号对比即可知道是否需要更新。 + + + + + +# 更新 + +通过pip 指令更新: + +```python +subprocess.run("pip install pandas-ui -U -i https://pypi.douban.com/simple/",stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True) +``` + + + +## 更新时机 + +在工具启动时,做检查与更新吧。 + + + +## 更新频率 + +国内镜像,只有豆瓣能在半小时内同步pip,因此暂时考虑使用他的镜像吧 + + + + + + + +# 发布流程 + + + +```shell +pip install --upgrade setuptools +``` + + + +安装帮助上传的工具 + +```shell +pip install twine +``` + + + +使用模板: + +```shell +git clone https://github.com/kennethreitz/setup.py +``` + + + +修改里面的 setup.py + + + +打包: + +```shell +python setup.py sdist +``` + + + +执行上传: + +```shell +twine upload dist/* +``` + + + + + -- Gitee From b9e300cf638e3bfde9666d160704668819817074 Mon Sep 17 00:00:00 2001 From: carson_git <543983849@qq.com> Date: Mon, 28 Dec 2020 22:24:45 +0800 Subject: [PATCH 2/8] --- ...44\270\216\347\211\210\346\234\254\346\233\264\346\226\260.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.txt" => "doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.md" (100%) diff --git "a/doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.txt" "b/doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.md" similarity index 100% rename from "doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.txt" rename to "doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.md" -- Gitee From 269345e66b08ef895fb718db3ff94090e8aef273 Mon Sep 17 00:00:00 2001 From: carson_git <543983849@qq.com> Date: Mon, 28 Dec 2020 22:44:04 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/src/core/Versions.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 py/src/core/Versions.py diff --git a/py/src/core/Versions.py b/py/src/core/Versions.py new file mode 100644 index 0000000..824e257 --- /dev/null +++ b/py/src/core/Versions.py @@ -0,0 +1,29 @@ + +import subprocess +import re +from typing import Tuple + + +class VersionManager(object): + + m_pkg_name = 'pandas-coder' + m_current_version = tuple('0.1.0'.split('.')) + m_version_re = re.compile(r'\((from versions: (.*?))\)') + + def has_updated(self) -> bool: + return self.m_current_version < self.get_last_version() + + def get_last_version(self) -> Tuple: + ret = self._use_pip(f"pip install {self.m_pkg_name}==") + ret = str(ret.stderr) + + vs = self.m_version_re.search(ret).groups()[1].split(',') + last = vs[-1] + return tuple(last.split('.')) + + def update(self): + self._use_pip(f"pip install {self.m_pkg_name} -U") + + def _use_pip(self, cmd: str): + return subprocess.run(f"{cmd} -i https://pypi.douban.com/simple/", + stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) -- Gitee From 8112dea0b7ef98fd60893fb5d4b633183ff19760 Mon Sep 17 00:00:00 2001 From: carson_git <543983849@qq.com> Date: Mon, 28 Dec 2020 22:44:08 +0800 Subject: [PATCH 4/8] --- ...16\347\211\210\346\234\254\346\233\264\346\226\260.md" | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git "a/doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.md" "b/doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.md" index 9be0930..edb2117 100644 --- "a/doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.md" +++ "b/doc/pip\345\256\211\350\243\205\344\270\216\347\211\210\346\234\254\346\233\264\346\226\260.md" @@ -13,7 +13,7 @@ pip 安装包只会把文件放置在指定目录下。因此,期待用户安 1. 通过python代码启动 ```python - import pandas-ui + import pandas-coder ``` 2. 通过命令,在指定目录输出一个bat文件,后续通过bat文件启动 @@ -26,7 +26,7 @@ pip 安装包只会把文件放置在指定目录下。因此,期待用户安 ```python import subprocess -ret = subprocess.run("pip install pandas-ui== -i https://pypi.douban.com/simple/",stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True) +ret = subprocess.run("pip install pandas-coder== -i https://pypi.douban.com/simple/",stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True) ret = str(ret.stderr) ``` @@ -34,7 +34,7 @@ ret = str(ret.stderr) 这个指令会返回一个如: ```shell -ERROR: Could not find a version that satisfies the requirement pandas-ui== (from versions: 0.1.0, 0.2.0)\r\nERROR: No matching distribution found for test-myp== +ERROR: Could not find a version that satisfies the requirement pandas-coder== (from versions: 0.1.0, 0.2.0)\r\nERROR: No matching distribution found for test-myp== ``` @@ -62,7 +62,7 @@ new_verson = vs[-1] 通过pip 指令更新: ```python -subprocess.run("pip install pandas-ui -U -i https://pypi.douban.com/simple/",stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True) +subprocess.run("pip install pandas-coder -U -i https://pypi.douban.com/simple/",stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True) ``` -- Gitee From 80940be7134c465f3faf73e9725d73546159e700 Mon Sep 17 00:00:00 2001 From: carson_git <543983849@qq.com> Date: Wed, 6 Jan 2021 23:07:22 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E9=80=9A=E8=BF=87=E6=96=B0=E5=A2=9E=20star?= =?UTF-8?q?t=20update=20=E5=8C=85=E8=A7=A3=E5=86=B3=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8D=A0=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/main.py | 60 ++++++++++++++++++++++++++--- py/src/core/Versions.py | 37 ++++++++++++------ py/test.py | 33 +++++++++------- startup_py/README.md | 3 ++ startup_py/Versions.py | 40 +++++++++++++++++++ startup_py/__init__.py | 0 startup_py/main.py | 38 ++++++++++++++++++ startup_py/workspace.code-workspace | 8 ++++ 8 files changed, 188 insertions(+), 31 deletions(-) create mode 100644 startup_py/README.md create mode 100644 startup_py/Versions.py create mode 100644 startup_py/__init__.py create mode 100644 startup_py/main.py create mode 100644 startup_py/workspace.code-workspace diff --git a/py/main.py b/py/main.py index af7c4af..da2f1ec 100644 --- a/py/main.py +++ b/py/main.py @@ -1,3 +1,4 @@ +from typing import Tuple from flask import Flask import flask from flask import request @@ -6,11 +7,12 @@ import numpy as np import json import traceback import sys -from src.cusFuns.core.FunsPool import auto_register +from .src.cusFuns.core.FunsPool import auto_register +from .src.core.Versions import VersionManager -from src.helper.utils import json_converter -from src.dataModel.pandasCmd import PandasCmd -from src.core.Proxy import ProxyManager +from .src.helper.utils import json_converter +from .src.dataModel.pandasCmd import PandasCmd +from .src.core.Proxy import ProxyManager import webbrowser import os @@ -46,7 +48,8 @@ def get_data_from_post(): @app.route('/') def index(): - return flask.render_template('index.html') + # return flask.render_template('index.html') + return f'版本号:{VersionManager.m_current_version}' @app.route('/api/get_file_args/ext=', methods=['get']) @@ -200,16 +203,61 @@ def get_cus_funcs_input(): return df2json(m_proxys.get_df_data()) -def main(): +def run(): + port = 5551 # The reloader has not yet run - open the browser if not os.environ.get("WERKZEUG_RUN_MAIN"): + + # vm = VersionManager() + # if vm.has_updated(): + # print(f'发现新版本,开始更新({VersionManager.m_current_version})') + # vm.start_update() + # print(f'更新完成({VersionManager.m_current_version})') + webbrowser.open_new(f'http://localhost:{port}/') # Otherwise, continue as normal app.run(host="localhost", port=port) +def find_arg(args, flag, return_value=True): + try: + idx = args.index(flag) + + if return_value: + return True, args[idx+1] + return idx >= 0, None + except ValueError: + pass + + return False, None + + +def start_update(): + + try: + import pdcoder_start_update + except ImportError: + return + os.system(f'start pdcoder_start_update -dir {os.getcwd()}') + sys.exit() + + +def main(): + args = sys.argv + + has, dir = find_arg(args, '-dir') + if has: + os.chdir(dir) + + has, _ = find_arg(args, '-u', return_value=False) + if has: + start_update() + + run() + + if __name__ == '__main__': main() diff --git a/py/src/core/Versions.py b/py/src/core/Versions.py index 824e257..ed17653 100644 --- a/py/src/core/Versions.py +++ b/py/src/core/Versions.py @@ -1,29 +1,42 @@ import subprocess import re -from typing import Tuple +from typing import List, Tuple class VersionManager(object): - m_pkg_name = 'pandas-coder' - m_current_version = tuple('0.1.0'.split('.')) + # m_pkg_name = 'pandas-coder' + m_pkg_name = 'pdcoder' + m_current_version = tuple('0.3.7'.split('.')) m_version_re = re.compile(r'\((from versions: (.*?))\)') def has_updated(self) -> bool: return self.m_current_version < self.get_last_version() - def get_last_version(self) -> Tuple: - ret = self._use_pip(f"pip install {self.m_pkg_name}==") + def get_versions(self): + ret = self._use_pip(['install', f'{self.m_pkg_name}==']) ret = str(ret.stderr) vs = self.m_version_re.search(ret).groups()[1].split(',') - last = vs[-1] - return tuple(last.split('.')) + assert vs[0] != 'none' '未找到任何版本,请检查网络连接' + return [tuple(v.strip().split('.')) for v in vs] + + def get_last_version(self) -> Tuple: + last = self.get_versions()[-1] + return last + + def start_update(self): + import sys + import os + os.system( + 'pip install pdcoder -U && python main.py') + + sys.exit() - def update(self): - self._use_pip(f"pip install {self.m_pkg_name} -U") + def _use_pip(self, cmds: List[str]): + # cmds = ['pip'] + cmds + ['-i', 'https://pypi.douban.com/simple/'] + cmds = ['pip'] + cmds - def _use_pip(self, cmd: str): - return subprocess.run(f"{cmd} -i https://pypi.douban.com/simple/", - stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + return subprocess.run(cmds, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) diff --git a/py/test.py b/py/test.py index a364b5f..48d5a80 100644 --- a/py/test.py +++ b/py/test.py @@ -1,23 +1,30 @@ # %% +from src.core.Versions import VersionManager +import asyncio -def de_func(title=None): - print(title) - - def wrapper(func): - print(func) +# %% +vm = VersionManager() +# %% +vm.get_versions() +# %% +vm.has_updated() +# %% +vm.m_current_version +# %% +vm.get_last_version() +# %% - return wrapper +# %% -# %% -@de_func -def a(x): - """ - docstring - """ - pass +async def doing(): + ret = vm.get_last_version() + print(ret) +loop = asyncio.get_event_loop() +loop.run_until_complete(doing()) +print('done') # %% diff --git a/startup_py/README.md b/startup_py/README.md new file mode 100644 index 0000000..5503eb8 --- /dev/null +++ b/startup_py/README.md @@ -0,0 +1,3 @@ +# 为什么需要这个项目 + +此项目旨在启动 pdcoder时自动从pip上更新版本 \ No newline at end of file diff --git a/startup_py/Versions.py b/startup_py/Versions.py new file mode 100644 index 0000000..14894e7 --- /dev/null +++ b/startup_py/Versions.py @@ -0,0 +1,40 @@ + +import subprocess +import re +from typing import List, Tuple +from pdcoder.src.core.Versions import VersionManager as vm + + +class VersionManager(object): + + # m_pkg_name = 'pandas-coder' + m_pkg_name = 'pdcoder' + m_current_version = vm.m_current_version + m_version_re = re.compile(r'\((from versions: (.*?))\)') + + def has_updated(self) -> bool: + return self.m_current_version < self.get_last_version() + + def get_versions(self): + ret = self._use_pip(['install', f'{self.m_pkg_name}==']) + ret = str(ret.stderr) + + vs = self.m_version_re.search(ret).groups()[1].split(',') + assert vs[0] != 'none' '未找到任何版本,请检查网络连接' + return [tuple(v.strip().split('.')) for v in vs] + + def get_last_version(self) -> Tuple: + last = self.get_versions()[-1] + return last + + def start_update(self): + import os + os.system( + f'pip install pdcoder -U ') + + def _use_pip(self, cmds: List[str]): + # cmds = ['pip'] + cmds + ['-i', 'https://pypi.douban.com/simple/'] + cmds = ['pip'] + cmds + + return subprocess.run(cmds, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) diff --git a/startup_py/__init__.py b/startup_py/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/startup_py/main.py b/startup_py/main.py new file mode 100644 index 0000000..bf411bf --- /dev/null +++ b/startup_py/main.py @@ -0,0 +1,38 @@ + + +import sys +import os +from .Versions import VersionManager + + +def find_arg(args, flag): + try: + idx = args.index(flag) + find = args[idx+1] + return find + except ValueError: + pass + + return None + + +def main(): + vm = VersionManager() + if vm.has_updated(): + print(f'发现新版本,开始更新') + vm.start_update() + print(f'更新完成()') + + args = sys.argv + + dir = find_arg(args, '-dir') + if dir: + os.system(f'pdcoder -dir {dir}') + + os.system(f'pdcoder') + + sys.exit() + + +if __name__ == "__main__": + pass diff --git a/startup_py/workspace.code-workspace b/startup_py/workspace.code-workspace new file mode 100644 index 0000000..876a149 --- /dev/null +++ b/startup_py/workspace.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +} \ No newline at end of file -- Gitee From 83e6466e4ad415154f753d03999657a47ffe5a60 Mon Sep 17 00:00:00 2001 From: carson_git <543983849@qq.com> Date: Thu, 7 Jan 2021 20:18:47 +0800 Subject: [PATCH 6/8] done --- py/.gitignore | 7 + py/__init__.py | 3 + py/build/build.bat | 1 - py/build/build.py | 82 +++------- py/build/others/startup_linux.sh | 2 +- py/build/others/startup_win.bat | 2 +- ...3\347\273\237\350\246\201\346\261\202.txt" | 16 -- py/main.py | 34 ++--- py/setup.py/.gitignore | 91 +++++++++++ py/setup.py/LICENSE | 7 + py/setup.py/MANIFEST.in | 3 + py/setup.py/README.md | 65 ++++++++ py/setup.py/run.py | 13 ++ py/setup.py/setup.py | 144 ++++++++++++++++++ {startup_py => py/src}/__init__.py | 0 py/src/core/Versions.py | 42 ----- py/test.py | 28 +--- py_updater/.gitignore | 7 + {startup_py => py_updater}/README.md | 0 {startup_py => py_updater}/Versions.py | 9 +- py_updater/__init__.py | 0 {startup_py => py_updater}/main.py | 26 ++-- py_updater/setup.py/.gitignore | 91 +++++++++++ py_updater/setup.py/LICENSE | 7 + py_updater/setup.py/MANIFEST.in | 3 + py_updater/setup.py/README.md | 65 ++++++++ py_updater/setup.py/run.py | 11 ++ py_updater/setup.py/setup.py | 143 +++++++++++++++++ .../workspace.code-workspace | 0 29 files changed, 718 insertions(+), 184 deletions(-) create mode 100644 py/.gitignore create mode 100644 py/__init__.py delete mode 100644 "py/build/others/\347\263\273\347\273\237\350\246\201\346\261\202.txt" create mode 100644 py/setup.py/.gitignore create mode 100644 py/setup.py/LICENSE create mode 100644 py/setup.py/MANIFEST.in create mode 100644 py/setup.py/README.md create mode 100644 py/setup.py/run.py create mode 100644 py/setup.py/setup.py rename {startup_py => py/src}/__init__.py (100%) delete mode 100644 py/src/core/Versions.py create mode 100644 py_updater/.gitignore rename {startup_py => py_updater}/README.md (100%) rename {startup_py => py_updater}/Versions.py (83%) create mode 100644 py_updater/__init__.py rename {startup_py => py_updater}/main.py (46%) create mode 100644 py_updater/setup.py/.gitignore create mode 100644 py_updater/setup.py/LICENSE create mode 100644 py_updater/setup.py/MANIFEST.in create mode 100644 py_updater/setup.py/README.md create mode 100644 py_updater/setup.py/run.py create mode 100644 py_updater/setup.py/setup.py rename {startup_py => py_updater}/workspace.code-workspace (100%) diff --git a/py/.gitignore b/py/.gitignore new file mode 100644 index 0000000..58d66aa --- /dev/null +++ b/py/.gitignore @@ -0,0 +1,7 @@ + + +**/dist +**/__pycache__ +setup.py/pdcopyist +setup.py/pdcopyist.egg-info + diff --git a/py/__init__.py b/py/__init__.py new file mode 100644 index 0000000..2af33e6 --- /dev/null +++ b/py/__init__.py @@ -0,0 +1,3 @@ + + +__version__ = tuple('0.1.0'.split('.')) diff --git a/py/build/build.bat b/py/build/build.bat index af93c97..11193bd 100644 --- a/py/build/build.bat +++ b/py/build/build.bat @@ -1,3 +1,2 @@ -call activate py36 python build.py pause \ No newline at end of file diff --git a/py/build/build.py b/py/build/build.py index b60e059..74198e9 100644 --- a/py/build/build.py +++ b/py/build/build.py @@ -5,6 +5,8 @@ import shutil import os +pkg_name = 'pdcopyist' + is_compileall = False @@ -14,72 +16,36 @@ vinfo = sys.version_info py_num = f'{vinfo.major}{vinfo.minor}' -m_dist_app_path = plib.Path(f'../dist/app{vinfo.major}{vinfo.minor}') -m_dist_src_path = m_dist_app_path / 'src' -m_dist_web_path = m_dist_app_path / 'web' -m_dist_main_path = m_dist_app_path / 'main.py' -m_dist_startup_path = m_dist_app_path / 'startup.bat' - -if is_compileall: - compileall.compile_dir(r'../src') - compileall.compile_file('../main.py') - print('编译完毕') - -if os.path.exists(m_dist_app_path): - shutil.rmtree(m_dist_app_path) - -os.makedirs(m_dist_app_path) - -print('清除旧文件完毕') - - -def to_fileName(file: plib.Path): - arr = file.name.split('.') - return '.'.join([arr[0], arr[1]]) +m_target_path = plib.Path(f'../setup.py/{pkg_name}') +m_src_path = plib.Path(f'../src') +m_target_src_path = m_target_path / 'src' -def to_folder(file: plib.Path): - parts = list(file.parts) - # del parts[-2] - parts[-1] = to_fileName(file) +m_web_path = plib.Path(f'../web') +m_target_web_path = m_target_path / 'web' - parts = [p for p in parts if not all(s in ['.', '/'] for s in p)] +m_main_path = plib.Path(f'../main.py') +m_target_main_path = m_target_path / 'main.py' - parts = plib.Path.joinpath(m_dist_app_path, *parts) - return parts +m_init_path = plib.Path(f'../__init__.py') +m_target_init_path = m_target_path / '__init__.py' +m_other_path = plib.Path(f'others') +# m_target_other_path = m_target_path / 'startup_win.bat' -if is_compileall: - fs = plib.Path('../src').rglob(f'*.cpython-{py_num}.pyc') - fs = [(p, to_folder(p)) for p in fs] - - for f in fs: - if not os.path.exists(f[1].parent): - os.makedirs(f[1].parent) - - shutil.copyfile(f[0], f[1]) - - shutil.copyfile( - f'../__pycache__/main.cpython-{py_num}.pyc', m_dist_main_path) - -else: - fs = plib.Path('../src').rglob(f'*.py') - fs = [(p, to_folder(p)) for p in fs] - - for f in fs: - if not os.path.exists(f[1].parent): - os.makedirs(f[1].parent) - - shutil.copyfile(f[0], f[1]) - - shutil.copyfile(f'../main.py', m_dist_main_path) +# 清空目录 +shutil.rmtree(m_target_path, ignore_errors=True) +os.makedirs(m_target_path) +print('清除旧文件完毕') -shutil.copytree('../web', m_dist_web_path) +shutil.copytree(m_src_path, m_target_src_path) +shutil.copytree(m_web_path, m_target_web_path) +shutil.copyfile(m_main_path, m_target_main_path) +shutil.copyfile(m_init_path, m_target_init_path) -for f in plib.Path('others').glob('*'): - shutil.copyfile(f, m_dist_app_path / f.name) -# shutil.copyfile('../startup.bat', m_dist_startup_path) +for f in m_other_path.glob('*.*'): + shutil.copyfile(f, m_target_path/f.name) -print(f'创建完成-({vinfo})') +print(f'创建完成') diff --git a/py/build/others/startup_linux.sh b/py/build/others/startup_linux.sh index 7a84f97..274464a 100644 --- a/py/build/others/startup_linux.sh +++ b/py/build/others/startup_linux.sh @@ -1 +1 @@ -python main.py \ No newline at end of file +pdcopyist_updater \ No newline at end of file diff --git a/py/build/others/startup_win.bat b/py/build/others/startup_win.bat index bc9d4b2..232d02b 100644 --- a/py/build/others/startup_win.bat +++ b/py/build/others/startup_win.bat @@ -1,2 +1,2 @@ -python main.py +pdcopyist_updater pause \ No newline at end of file diff --git "a/py/build/others/\347\263\273\347\273\237\350\246\201\346\261\202.txt" "b/py/build/others/\347\263\273\347\273\237\350\246\201\346\261\202.txt" deleted file mode 100644 index 418acde..0000000 --- "a/py/build/others/\347\263\273\347\273\237\350\246\201\346\261\202.txt" +++ /dev/null @@ -1,16 +0,0 @@ -python 3.6 或以上 - -python 必需的库: -- flask -- pandas -- openpyxl(加载excel 2007 或以上版本所需) -- xlrd(加载excel 2003 版本所需) -- feather (feather 格式所需) -- webbrowser(应该是py内置的库) - -执行如下语句安装(使用了国内镜像): -pip install pandas flask xlrd openpyxl -i https://mirrors.aliyun.com/pypi/simple/ - - -浏览器要求: -基本上市面上的主流浏览器都支持,IE就不考虑了 \ No newline at end of file diff --git a/py/main.py b/py/main.py index da2f1ec..6d00243 100644 --- a/py/main.py +++ b/py/main.py @@ -8,8 +8,6 @@ import json import traceback import sys from .src.cusFuns.core.FunsPool import auto_register -from .src.core.Versions import VersionManager - from .src.helper.utils import json_converter from .src.dataModel.pandasCmd import PandasCmd from .src.core.Proxy import ProxyManager @@ -48,8 +46,11 @@ def get_data_from_post(): @app.route('/') def index(): - # return flask.render_template('index.html') - return f'版本号:{VersionManager.m_current_version}' + # from . import __version__ + # pd.DataFrame({'a': [1, 2, 3]}).to_csv('test_ret.csv') + # return f'版本号:{__version__}' + + return flask.render_template('index.html') @app.route('/api/get_file_args/ext=', methods=['get']) @@ -209,13 +210,6 @@ def run(): # The reloader has not yet run - open the browser if not os.environ.get("WERKZEUG_RUN_MAIN"): - - # vm = VersionManager() - # if vm.has_updated(): - # print(f'发现新版本,开始更新({VersionManager.m_current_version})') - # vm.start_update() - # print(f'更新完成({VersionManager.m_current_version})') - webbrowser.open_new(f'http://localhost:{port}/') # Otherwise, continue as normal @@ -235,14 +229,11 @@ def find_arg(args, flag, return_value=True): return False, None -def start_update(): - - try: - import pdcoder_start_update - except ImportError: - return - os.system(f'start pdcoder_start_update -dir {os.getcwd()}') - sys.exit() +def copy_bat(): + import pathlib + import shutil + src_path = pathlib.Path(__file__).parent / 'startup_win.bat' + shutil.copyfile(src_path, 'startup_win.bat') def main(): @@ -252,9 +243,10 @@ def main(): if has: os.chdir(dir) - has, _ = find_arg(args, '-u', return_value=False) + has, _ = find_arg(args, '-c', return_value=False) if has: - start_update() + copy_bat() + return run() diff --git a/py/setup.py/.gitignore b/py/setup.py/.gitignore new file mode 100644 index 0000000..7b0eb25 --- /dev/null +++ b/py/setup.py/.gitignore @@ -0,0 +1,91 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject +*.npy +*.pkl diff --git a/py/setup.py/LICENSE b/py/setup.py/LICENSE new file mode 100644 index 0000000..6cd7b79 --- /dev/null +++ b/py/setup.py/LICENSE @@ -0,0 +1,7 @@ +Copyright + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/py/setup.py/MANIFEST.in b/py/setup.py/MANIFEST.in new file mode 100644 index 0000000..4fc9608 --- /dev/null +++ b/py/setup.py/MANIFEST.in @@ -0,0 +1,3 @@ +include README.md LICENSE +recursive-include pdcopyist *.* +prune pdcopyist/**/__pycache__ \ No newline at end of file diff --git a/py/setup.py/README.md b/py/setup.py/README.md new file mode 100644 index 0000000..d53972b --- /dev/null +++ b/py/setup.py/README.md @@ -0,0 +1,65 @@ +📦 setup.py (for humans) +======================= + +This repo exists to provide [an example setup.py] file, that can be used +to bootstrap your next Python project. It includes some advanced +patterns and best practices for `setup.py`, as well as some +commented–out nice–to–haves. + +For example, this `setup.py` provides a `$ python setup.py upload` +command, which creates a *universal wheel* (and *sdist*) and uploads +your package to [PyPi] using [Twine], without the need for an annoying +`setup.cfg` file. It also creates/uploads a new git tag, automatically. + +In short, `setup.py` files can be daunting to approach, when first +starting out — even Guido has been heard saying, "everyone cargo cults +thems". It's true — so, I want this repo to be the best place to +copy–paste from :) + +[Check out the example!][an example setup.py] + +Installation +----- + +```bash +cd your_project + +# Download the setup.py file: +# download with wget +wget https://raw.githubusercontent.com/navdeep-G/setup.py/master/setup.py -O setup.py + +# download with curl +curl -O https://raw.githubusercontent.com/navdeep-G/setup.py/master/setup.py +``` + +To Do +----- + +- Tests via `$ setup.py test` (if it's concise). + +Pull requests are encouraged! + +More Resources +-------------- + +- [What is setup.py?] on Stack Overflow +- [Official Python Packaging User Guide](https://packaging.python.org) +- [The Hitchhiker's Guide to Packaging] +- [Cookiecutter template for a Python package] + +License +------- + +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any means. + + [an example setup.py]: https://github.com/navdeep-G/setup.py/blob/master/setup.py + [PyPi]: https://docs.python.org/3/distutils/packageindex.html + [Twine]: https://pypi.python.org/pypi/twine + [image]: https://farm1.staticflickr.com/628/33173824932_58add34581_k_d.jpg + [What is setup.py?]: https://stackoverflow.com/questions/1471994/what-is-setup-py + [The Hitchhiker's Guide to Packaging]: https://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/creation.html + [Cookiecutter template for a Python package]: https://github.com/audreyr/cookiecutter-pypackage diff --git a/py/setup.py/run.py b/py/setup.py/run.py new file mode 100644 index 0000000..41e83e7 --- /dev/null +++ b/py/setup.py/run.py @@ -0,0 +1,13 @@ + + +import shutil +import os +import pathlib + +os.chdir(pathlib.Path(__file__).parent) + +shutil.rmtree('dist', ignore_errors=True) +os.system('python setup.py sdist') + +# 发布 +os.system('twine upload dist/*') diff --git a/py/setup.py/setup.py b/py/setup.py/setup.py new file mode 100644 index 0000000..ae4c325 --- /dev/null +++ b/py/setup.py/setup.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Note: To use the 'upload' functionality of this file, you must: +# $ pipenv install twine --dev + +import io +import os +import sys +from shutil import rmtree + +from setuptools import find_packages, setup, Command +from pdcopyist import __version__ + +# Package meta-data. +NAME = 'pdcopyist' +DESCRIPTION = 'A visual data manipulation tool that automatically generates python code' +URL = 'https://gitee.com/carson_add/pandas-ui' +EMAIL = '568166495@qq.com' +AUTHOR = 'Carson Liang' +REQUIRES_PYTHON = '>=3.6.0' +VERSION = '.'.join(__version__) + +# What packages are required for this module to be executed? +REQUIRED = [ + 'pandas', 'pdcopyist_updater', 'flask', 'openpyxl', 'xlrd' +] + +# What packages are optional? +EXTRAS = { + 'pd read feather file': ['feather'], +} + +# The rest you shouldn't have to touch too much :) +# ------------------------------------------------ +# Except, perhaps the License and Trove Classifiers! +# If you do change the License, remember to change the Trove Classifier for that! + +here = os.path.abspath(os.path.dirname(__file__)) + +# Import the README and use it as the long-description. +# Note: this will only work if 'README.md' is present in your MANIFEST.in file! +try: + with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = '\n' + f.read() +except FileNotFoundError: + long_description = DESCRIPTION + +# Load the package's __version__.py module as a dictionary. +about = {} +if not VERSION: + project_slug = NAME.lower().replace("-", "_").replace(" ", "_") + with open(os.path.join(here, project_slug, '__version__.py')) as f: + exec(f.read(), about) +else: + about['__version__'] = VERSION + + +class UploadCommand(Command): + """Support setup.py upload.""" + + description = 'Build and publish the package.' + user_options = [] + + @staticmethod + def status(s): + """Prints things in bold.""" + print('\033[1m{0}\033[0m'.format(s)) + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + try: + self.status('Removing previous builds…') + rmtree(os.path.join(here, 'dist')) + except OSError: + pass + + self.status('Building Source and Wheel (universal) distribution…') + os.system( + '{0} setup.py sdist bdist_wheel --universal'.format(sys.executable)) + + self.status('Uploading the package to PyPI via Twine…') + os.system('twine upload dist/*') + + self.status('Pushing git tags…') + os.system('git tag v{0}'.format(about['__version__'])) + os.system('git push --tags') + + sys.exit() + + +# Where the magic happens: +setup( + name=NAME, + version=about['__version__'], + description=DESCRIPTION, + long_description=long_description, + long_description_content_type='text/markdown', + author=AUTHOR, + author_email=EMAIL, + python_requires=REQUIRES_PYTHON, + url=URL, + packages=[NAME], + + entry_points={ + 'console_scripts': [ + f'{NAME} = {NAME}.main:main' + ] + }, + + + # If your package is a single module, use this instead of 'packages': + # py_modules=['mypackage'], + + # entry_points={ + # 'console_scripts': ['mycli=mymodule:cli'], + # }, + + + + install_requires=REQUIRED, + extras_require=EXTRAS, + include_package_data=True, + license='MIT', + classifiers=[ + # Trove classifiers + # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy' + ], + # $ setup.py publish support. + cmdclass={ + 'upload': UploadCommand, + }, +) diff --git a/startup_py/__init__.py b/py/src/__init__.py similarity index 100% rename from startup_py/__init__.py rename to py/src/__init__.py diff --git a/py/src/core/Versions.py b/py/src/core/Versions.py deleted file mode 100644 index ed17653..0000000 --- a/py/src/core/Versions.py +++ /dev/null @@ -1,42 +0,0 @@ - -import subprocess -import re -from typing import List, Tuple - - -class VersionManager(object): - - # m_pkg_name = 'pandas-coder' - m_pkg_name = 'pdcoder' - m_current_version = tuple('0.3.7'.split('.')) - m_version_re = re.compile(r'\((from versions: (.*?))\)') - - def has_updated(self) -> bool: - return self.m_current_version < self.get_last_version() - - def get_versions(self): - ret = self._use_pip(['install', f'{self.m_pkg_name}==']) - ret = str(ret.stderr) - - vs = self.m_version_re.search(ret).groups()[1].split(',') - assert vs[0] != 'none' '未找到任何版本,请检查网络连接' - return [tuple(v.strip().split('.')) for v in vs] - - def get_last_version(self) -> Tuple: - last = self.get_versions()[-1] - return last - - def start_update(self): - import sys - import os - os.system( - 'pip install pdcoder -U && python main.py') - - sys.exit() - - def _use_pip(self, cmds: List[str]): - # cmds = ['pip'] + cmds + ['-i', 'https://pypi.douban.com/simple/'] - cmds = ['pip'] + cmds - - return subprocess.run(cmds, - stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) diff --git a/py/test.py b/py/test.py index 48d5a80..29249ca 100644 --- a/py/test.py +++ b/py/test.py @@ -1,30 +1,6 @@ - -# %% -from src.core.Versions import VersionManager -import asyncio - -# %% -vm = VersionManager() -# %% -vm.get_versions() -# %% -vm.has_updated() -# %% -vm.m_current_version # %% -vm.get_last_version() -# %% - -# %% - - -async def doing(): - ret = vm.get_last_version() - print(ret) - -loop = asyncio.get_event_loop() -loop.run_until_complete(doing()) +import pathlib -print('done') +pathlib.Path('build/build.bat').name # %% diff --git a/py_updater/.gitignore b/py_updater/.gitignore new file mode 100644 index 0000000..1496bec --- /dev/null +++ b/py_updater/.gitignore @@ -0,0 +1,7 @@ + + +**/dist +**/__pycache__ +setup.py/pdcopyist_updater +setup.py/pdcopyist_updater.egg-info + diff --git a/startup_py/README.md b/py_updater/README.md similarity index 100% rename from startup_py/README.md rename to py_updater/README.md diff --git a/startup_py/Versions.py b/py_updater/Versions.py similarity index 83% rename from startup_py/Versions.py rename to py_updater/Versions.py index 14894e7..89591a9 100644 --- a/startup_py/Versions.py +++ b/py_updater/Versions.py @@ -2,14 +2,13 @@ import subprocess import re from typing import List, Tuple -from pdcoder.src.core.Versions import VersionManager as vm +from pdcopyist import __version__ class VersionManager(object): - # m_pkg_name = 'pandas-coder' - m_pkg_name = 'pdcoder' - m_current_version = vm.m_current_version + m_pkg_name = 'pdcopyist' + m_current_version = __version__ m_version_re = re.compile(r'\((from versions: (.*?))\)') def has_updated(self) -> bool: @@ -30,7 +29,7 @@ class VersionManager(object): def start_update(self): import os os.system( - f'pip install pdcoder -U ') + f'pip install {self.m_pkg_name} -U ') def _use_pip(self, cmds: List[str]): # cmds = ['pip'] + cmds + ['-i', 'https://pypi.douban.com/simple/'] diff --git a/py_updater/__init__.py b/py_updater/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/startup_py/main.py b/py_updater/main.py similarity index 46% rename from startup_py/main.py rename to py_updater/main.py index bf411bf..b5b3c57 100644 --- a/startup_py/main.py +++ b/py_updater/main.py @@ -5,15 +5,15 @@ import os from .Versions import VersionManager -def find_arg(args, flag): - try: - idx = args.index(flag) - find = args[idx+1] - return find - except ValueError: - pass +# def find_arg(args, flag): +# try: +# idx = args.index(flag) +# find = args[idx+1] +# return find +# except ValueError: +# pass - return None +# return None def main(): @@ -23,13 +23,13 @@ def main(): vm.start_update() print(f'更新完成()') - args = sys.argv + # args = sys.argv - dir = find_arg(args, '-dir') - if dir: - os.system(f'pdcoder -dir {dir}') + # dir = find_arg(args, '-dir') + # if dir: + # os.system(f'pdcoder -dir {dir}') - os.system(f'pdcoder') + os.system(VersionManager.m_pkg_name) sys.exit() diff --git a/py_updater/setup.py/.gitignore b/py_updater/setup.py/.gitignore new file mode 100644 index 0000000..7b0eb25 --- /dev/null +++ b/py_updater/setup.py/.gitignore @@ -0,0 +1,91 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject +*.npy +*.pkl diff --git a/py_updater/setup.py/LICENSE b/py_updater/setup.py/LICENSE new file mode 100644 index 0000000..6cd7b79 --- /dev/null +++ b/py_updater/setup.py/LICENSE @@ -0,0 +1,7 @@ +Copyright + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/py_updater/setup.py/MANIFEST.in b/py_updater/setup.py/MANIFEST.in new file mode 100644 index 0000000..4fc9608 --- /dev/null +++ b/py_updater/setup.py/MANIFEST.in @@ -0,0 +1,3 @@ +include README.md LICENSE +recursive-include pdcopyist *.* +prune pdcopyist/**/__pycache__ \ No newline at end of file diff --git a/py_updater/setup.py/README.md b/py_updater/setup.py/README.md new file mode 100644 index 0000000..d53972b --- /dev/null +++ b/py_updater/setup.py/README.md @@ -0,0 +1,65 @@ +📦 setup.py (for humans) +======================= + +This repo exists to provide [an example setup.py] file, that can be used +to bootstrap your next Python project. It includes some advanced +patterns and best practices for `setup.py`, as well as some +commented–out nice–to–haves. + +For example, this `setup.py` provides a `$ python setup.py upload` +command, which creates a *universal wheel* (and *sdist*) and uploads +your package to [PyPi] using [Twine], without the need for an annoying +`setup.cfg` file. It also creates/uploads a new git tag, automatically. + +In short, `setup.py` files can be daunting to approach, when first +starting out — even Guido has been heard saying, "everyone cargo cults +thems". It's true — so, I want this repo to be the best place to +copy–paste from :) + +[Check out the example!][an example setup.py] + +Installation +----- + +```bash +cd your_project + +# Download the setup.py file: +# download with wget +wget https://raw.githubusercontent.com/navdeep-G/setup.py/master/setup.py -O setup.py + +# download with curl +curl -O https://raw.githubusercontent.com/navdeep-G/setup.py/master/setup.py +``` + +To Do +----- + +- Tests via `$ setup.py test` (if it's concise). + +Pull requests are encouraged! + +More Resources +-------------- + +- [What is setup.py?] on Stack Overflow +- [Official Python Packaging User Guide](https://packaging.python.org) +- [The Hitchhiker's Guide to Packaging] +- [Cookiecutter template for a Python package] + +License +------- + +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any means. + + [an example setup.py]: https://github.com/navdeep-G/setup.py/blob/master/setup.py + [PyPi]: https://docs.python.org/3/distutils/packageindex.html + [Twine]: https://pypi.python.org/pypi/twine + [image]: https://farm1.staticflickr.com/628/33173824932_58add34581_k_d.jpg + [What is setup.py?]: https://stackoverflow.com/questions/1471994/what-is-setup-py + [The Hitchhiker's Guide to Packaging]: https://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/creation.html + [Cookiecutter template for a Python package]: https://github.com/audreyr/cookiecutter-pypackage diff --git a/py_updater/setup.py/run.py b/py_updater/setup.py/run.py new file mode 100644 index 0000000..70bc6a7 --- /dev/null +++ b/py_updater/setup.py/run.py @@ -0,0 +1,11 @@ + + +import shutil +import os +import pathlib + +os.chdir(pathlib.Path(__file__).parent) + +shutil.rmtree('dist', ignore_errors=True) +os.system('python setup.py sdist') +os.system('twine upload dist/*') diff --git a/py_updater/setup.py/setup.py b/py_updater/setup.py/setup.py new file mode 100644 index 0000000..ced68e9 --- /dev/null +++ b/py_updater/setup.py/setup.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Note: To use the 'upload' functionality of this file, you must: +# $ pipenv install twine --dev + +import io +import os +import sys +from shutil import rmtree + +from setuptools import find_packages, setup, Command + +# Package meta-data. +NAME = 'pdcopyist_updater' +DESCRIPTION = 'A visual data manipulation tool that automatically generates python code' +URL = 'https://gitee.com/carson_add/pandas-ui' +EMAIL = '568166495@qq.com' +AUTHOR = 'Carson Liang' +REQUIRES_PYTHON = '>=3.6.0' +VERSION = '0.1.1' + +# What packages are required for this module to be executed? +REQUIRED = [ + 'pdcopyist' +] + +# What packages are optional? +EXTRAS = { + # 'pd read feather file': ['feather'], +} + +# The rest you shouldn't have to touch too much :) +# ------------------------------------------------ +# Except, perhaps the License and Trove Classifiers! +# If you do change the License, remember to change the Trove Classifier for that! + +here = os.path.abspath(os.path.dirname(__file__)) + +# Import the README and use it as the long-description. +# Note: this will only work if 'README.md' is present in your MANIFEST.in file! +try: + with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = '\n' + f.read() +except FileNotFoundError: + long_description = DESCRIPTION + +# Load the package's __version__.py module as a dictionary. +about = {} +if not VERSION: + project_slug = NAME.lower().replace("-", "_").replace(" ", "_") + with open(os.path.join(here, project_slug, '__version__.py')) as f: + exec(f.read(), about) +else: + about['__version__'] = VERSION + + +class UploadCommand(Command): + """Support setup.py upload.""" + + description = 'Build and publish the package.' + user_options = [] + + @staticmethod + def status(s): + """Prints things in bold.""" + print('\033[1m{0}\033[0m'.format(s)) + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + try: + self.status('Removing previous builds…') + rmtree(os.path.join(here, 'dist')) + except OSError: + pass + + self.status('Building Source and Wheel (universal) distribution…') + os.system( + '{0} setup.py sdist bdist_wheel --universal'.format(sys.executable)) + + self.status('Uploading the package to PyPI via Twine…') + os.system('twine upload dist/*') + + self.status('Pushing git tags…') + os.system('git tag v{0}'.format(about['__version__'])) + os.system('git push --tags') + + sys.exit() + + +# Where the magic happens: +setup( + name=NAME, + version=about['__version__'], + description=DESCRIPTION, + long_description=long_description, + long_description_content_type='text/markdown', + author=AUTHOR, + author_email=EMAIL, + python_requires=REQUIRES_PYTHON, + url=URL, + packages=[NAME], + + entry_points={ + 'console_scripts': [ + f'{NAME} = {NAME}.main:main' + ] + }, + + + # If your package is a single module, use this instead of 'packages': + # py_modules=['mypackage'], + + # entry_points={ + # 'console_scripts': ['mycli=mymodule:cli'], + # }, + + + + install_requires=REQUIRED, + extras_require=EXTRAS, + include_package_data=True, + license='MIT', + classifiers=[ + # Trove classifiers + # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy' + ], + # $ setup.py publish support. + cmdclass={ + 'upload': UploadCommand, + }, +) diff --git a/startup_py/workspace.code-workspace b/py_updater/workspace.code-workspace similarity index 100% rename from startup_py/workspace.code-workspace rename to py_updater/workspace.code-workspace -- Gitee From 2f4a5dfc56b8a2e711e442d89069647112cc674e Mon Sep 17 00:00:00 2001 From: carson_git <543983849@qq.com> Date: Thu, 7 Jan 2021 23:36:40 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=9C=89=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/__init__.py | 2 +- py/main.py | 15 ++++++---- py/src/cusFuns/columnNameChanger/index.py | 3 +- py/src/cusFuns/core/FunsPool.py | 34 ++++++++++++++++------- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/py/__init__.py b/py/__init__.py index 2af33e6..31d06db 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -1,3 +1,3 @@ -__version__ = tuple('0.1.0'.split('.')) +__version__ = tuple('0.1.1'.split('.')) diff --git a/py/main.py b/py/main.py index 6d00243..4f1d62e 100644 --- a/py/main.py +++ b/py/main.py @@ -7,17 +7,21 @@ import numpy as np import json import traceback import sys -from .src.cusFuns.core.FunsPool import auto_register -from .src.helper.utils import json_converter -from .src.dataModel.pandasCmd import PandasCmd -from .src.core.Proxy import ProxyManager + + +from src.cusFuns.core.FunsPool import auto_register +from src.helper.utils import json_converter +from src.dataModel.pandasCmd import PandasCmd +from src.core.Proxy import ProxyManager import webbrowser import os +import pathlib +base_path = pathlib.Path(__file__).parent m_proxys = ProxyManager() -auto_register(r'src/cusFuns') +auto_register(base_path, 'src/cusFuns') app = Flask(__name__, template_folder='./web/templates', @@ -180,6 +184,7 @@ def cus_fun(): @app.route('/api/cus_fun/desc') def get_cus_funcs_desc(): + # auto_register(base_path , 'src/cusFuns') ret = m_proxys.get_cus_funcs_desc() ret = flask.json.dumps(ret, default=json_converter) return ret diff --git a/py/src/cusFuns/columnNameChanger/index.py b/py/src/cusFuns/columnNameChanger/index.py index 085c692..c1290f5 100644 --- a/py/src/cusFuns/columnNameChanger/index.py +++ b/py/src/cusFuns/columnNameChanger/index.py @@ -1,3 +1,4 @@ +import importlib from ..core.DecoratorFuns import dt_handle_func, dt_args, dt_source_code from ..core import Args as ty import pandas as pd @@ -12,4 +13,4 @@ def generate_code(*args, **kwargs): @dt_handle_func('修改列名') @dt_args(org_name=ty.ColumnSelect('待修改列:'), new_name=ty.Input('新列名:', placeholder='输入新的列名')) def change_column_name(df, org_name, new_name): - return df.rename(columns={org_name: new_name}) + return df.rename(columns={org_name: new_name}) \ No newline at end of file diff --git a/py/src/cusFuns/core/FunsPool.py b/py/src/cusFuns/core/FunsPool.py index 558f271..f7d963d 100644 --- a/py/src/cusFuns/core/FunsPool.py +++ b/py/src/cusFuns/core/FunsPool.py @@ -1,6 +1,6 @@ -from typing import Callable, Dict +from typing import Callable, Dict, Union import uuid import pathlib import importlib @@ -8,7 +8,7 @@ import inspect import os -from ..core.DecoratorFuns import CusFunsWrapper, HandleWrapper +from .DecoratorFuns import CusFunsWrapper, HandleWrapper from .UIModl import FunModel @@ -97,7 +97,7 @@ class FunsPool(object): def _register_module(module_path: str): ''' module_path : str - 'src.cusFuns.columnNameChanger.columnNameChanger' + 'src.cusFuns.columnNameChanger.index' ''' module = importlib.import_module(module_path) # [('name',obj)] @@ -118,12 +118,26 @@ def _register_module(module_path: str): FunsPool.get_once().register(cf) -def auto_register(base_folder: str): - files = (p for p in pathlib.Path(base_folder).glob('*/*.py') - if p.parent.parts[-1] != 'core') +def auto_register(package_path: Union[str, pathlib.PurePath], base_folder: Union[str, pathlib.PurePath]): + org_dir = os.getcwd() - for md_name in files: - md_name = str(md_name)[:-3] - md_name = md_name.replace(os.path.sep, '.') + try: + # os.chdir(package_path) + base_folder = pathlib.Path(base_folder) - _register_module(md_name) + # path = pathlib.Path(package_path) / base_folder + files = (p for p in base_folder.glob('*/*.py') + if p.parent.parts[-1] != 'core') + + # print(f'功能池文件:{list(files)}') + + for md_name in files: + md_name = str(md_name)[:-3] + md_name = md_name.replace(os.path.sep, '.') + + _register_module(f'{md_name}') + except Exception: + raise + + finally: + os.chdir(org_dir) -- Gitee From c2aca7b4a12bdbb0c7f3c837f888a127f7855e0b Mon Sep 17 00:00:00 2001 From: carson_git <543983849@qq.com> Date: Fri, 8 Jan 2021 12:14:13 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9C=A8=E5=8C=85?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E4=BB=A5=E5=A4=96=E4=BD=9C=E4=B8=BA=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E7=9B=AE=E5=BD=95=E5=90=AF=E5=8A=A8=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=B1=A0=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/__init__.py | 2 +- py/main.py | 8 ++++---- py/src/cusFuns/core/FunsPool.py | 6 +++--- py_updater/Versions.py | 10 ++++++---- py_updater/main.py | 11 ----------- py_updater/setup.py/setup.py | 2 +- 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/py/__init__.py b/py/__init__.py index 31d06db..9994628 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -1,3 +1,3 @@ -__version__ = tuple('0.1.1'.split('.')) +__version__ = tuple('0.1.2'.split('.')) diff --git a/py/main.py b/py/main.py index 4f1d62e..888813d 100644 --- a/py/main.py +++ b/py/main.py @@ -9,10 +9,10 @@ import traceback import sys -from src.cusFuns.core.FunsPool import auto_register -from src.helper.utils import json_converter -from src.dataModel.pandasCmd import PandasCmd -from src.core.Proxy import ProxyManager +from .src.cusFuns.core.FunsPool import auto_register +from .src.helper.utils import json_converter +from .src.dataModel.pandasCmd import PandasCmd +from .src.core.Proxy import ProxyManager import webbrowser import os diff --git a/py/src/cusFuns/core/FunsPool.py b/py/src/cusFuns/core/FunsPool.py index f7d963d..86b106a 100644 --- a/py/src/cusFuns/core/FunsPool.py +++ b/py/src/cusFuns/core/FunsPool.py @@ -99,7 +99,8 @@ def _register_module(module_path: str): module_path : str 'src.cusFuns.columnNameChanger.index' ''' - module = importlib.import_module(module_path) + pkg = HandleWrapper.__module__.split('.')[0] + module = importlib.import_module(f'.{module_path}', pkg) # [('name',obj)] funcs = [(name, func) for name, func in module.__dict__.items() if isinstance(func, CusFunsWrapper)] @@ -122,10 +123,9 @@ def auto_register(package_path: Union[str, pathlib.PurePath], base_folder: Union org_dir = os.getcwd() try: - # os.chdir(package_path) + os.chdir(package_path) base_folder = pathlib.Path(base_folder) - # path = pathlib.Path(package_path) / base_folder files = (p for p in base_folder.glob('*/*.py') if p.parent.parts[-1] != 'core') diff --git a/py_updater/Versions.py b/py_updater/Versions.py index 89591a9..8ae7b71 100644 --- a/py_updater/Versions.py +++ b/py_updater/Versions.py @@ -27,12 +27,14 @@ class VersionManager(object): return last def start_update(self): - import os - os.system( - f'pip install {self.m_pkg_name} -U ') + # import os + # os.system( + # f'pip install {self.m_pkg_name} -U ') + + self._use_pip(['install', f'{self.m_pkg_name}', '-U']) def _use_pip(self, cmds: List[str]): - # cmds = ['pip'] + cmds + ['-i', 'https://pypi.douban.com/simple/'] + cmds = ['pip'] + cmds + ['-i', 'https://pypi.douban.com/simple/'] cmds = ['pip'] + cmds return subprocess.run(cmds, diff --git a/py_updater/main.py b/py_updater/main.py index b5b3c57..5c324d5 100644 --- a/py_updater/main.py +++ b/py_updater/main.py @@ -5,17 +5,6 @@ import os from .Versions import VersionManager -# def find_arg(args, flag): -# try: -# idx = args.index(flag) -# find = args[idx+1] -# return find -# except ValueError: -# pass - -# return None - - def main(): vm = VersionManager() if vm.has_updated(): diff --git a/py_updater/setup.py/setup.py b/py_updater/setup.py/setup.py index ced68e9..56b0f3d 100644 --- a/py_updater/setup.py/setup.py +++ b/py_updater/setup.py/setup.py @@ -18,7 +18,7 @@ URL = 'https://gitee.com/carson_add/pandas-ui' EMAIL = '568166495@qq.com' AUTHOR = 'Carson Liang' REQUIRES_PYTHON = '>=3.6.0' -VERSION = '0.1.1' +VERSION = '0.2.0' # What packages are required for this module to be executed? REQUIRED = [ -- Gitee