diff --git a/pprobe/bootstrap/_hook.py b/pprobe/bootstrap/_hook.py index 17fb4ab..baa6cc8 100644 --- a/pprobe/bootstrap/_hook.py +++ b/pprobe/bootstrap/_hook.py @@ -18,7 +18,7 @@ def find_module(self, fullname, path=None): class MetaPathLoader: def load_module(self, fullname): - # print('load_module {}'.format(fullname)) + Logger.info('load_module {}'.format(fullname)) # ``sys.modules`` 中保存的是已经导入过的 module if fullname in sys.modules: return sys.modules[fullname] @@ -27,12 +27,10 @@ def load_module(self, fullname): # 防止下面执行 import_module 的时候再次触发此 finder # 从而出现递归调用的问题 finder = sys.meta_path.pop(0) - # 导入 module module = importlib.import_module(fullname) - module_hook(fullname, module) - sys.meta_path.insert(0, finder) + return module sys.meta_path.insert(0, MetaPathFinder()) diff --git a/pprobe/bootstrap/sitecustomize.py b/pprobe/bootstrap/sitecustomize.py index 2e3e1e5..dcf4029 100644 --- a/pprobe/bootstrap/sitecustomize.py +++ b/pprobe/bootstrap/sitecustomize.py @@ -1 +1 @@ -import _hook \ No newline at end of file +from pprobe.bootstrap import _hook \ No newline at end of file diff --git a/script/build.sh b/script/build.sh index f30b572..d716385 100644 --- a/script/build.sh +++ b/script/build.sh @@ -8,7 +8,7 @@ project_dir=$(git rev-parse --show-toplevel) cd "${project_dir}" # 清理项目目录 -git clean -dxf +# git clean -dxf # 构建 wheel 包 python setup.py bdist_wheel diff --git a/script/test.sh b/script/test.sh new file mode 100644 index 0000000..ef70a27 --- /dev/null +++ b/script/test.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -euo pipefail + +# 获取项目根目录 +project_dir=$(git rev-parse --show-toplevel) + +# 切换到项目根目录 +cd "${project_dir}" + +cd pprobe/tests + +python xtest_torchvision_model.py -a resnet50 --epochs 1 -b 12 -p 1 --seed 42 --dummy + diff --git a/setup.py b/setup.py index 888613e..5463449 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ from setuptools import setup, find_packages +from setuptools.command.build_py import build_py import os import shutil @@ -18,25 +19,32 @@ def read_requirements(file_path): print("pprobe install_requires:", f.read().splitlines()) return f.read().splitlines() +class build_py_with_pth_file(build_py): + """Include the .pth file for this project, in the generated wheel.""" + def run(self): + super().run() + destination_in_wheel = "pprobe.pth" + location_in_source_tree = "pprobe.pth" + outfile = os.path.join(self.build_lib, destination_in_wheel) + self.copy_file(location_in_source_tree, outfile, preserve_mode=0) setup( name="pprobe", version="1.0.0", - packages=find_packages(exclude=["pprobe/tests"]), - include_package_data=True, - install_requires=read_requirements("./requirements.txt"), - # package_data={ - # '': ['*.pth'], # 添加所有.pth文件到安装中 - # }, - - author="clemente0620", - author_email="clemente0620@gmail.com", description="A hook tool for python", long_description="A hook tool for python", url="https://www.pprobe.com/pprobe", + author="clemente0620", + author_email="clemente0620@gmail.com", classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], + packages=find_packages(exclude=["pprobe/tests"]), + include_package_data=True, + package_data={"": ["*.pth"]}, # 将所有.pth文件包含在安装中 + install_requires=read_requirements("./requirements.txt"), + zip_safe=False, + cmdclass={"build_py": build_py_with_pth_file}, ) \ No newline at end of file