Skip to content

Commit

Permalink
cli refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
clemente0731 committed Mar 27, 2024
1 parent c67267d commit 9a5643c
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
3 changes: 1 addition & 2 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ def main():
os.environ['PYTHONPATH'] = boot_dir
# 执行后面的 python 程序命令
# sys.executable 是 python 解释器程序的绝对路径 ``which python``
# >>> sys.executable
# '/usr/local/var/pyenv/versions/3.5.1/bin/python3.5'

print("sys.executable", sys.executable)
print("sys.argv", sys.argv)
os.execl(sys.executable, sys.executable, *args)
Expand Down
Empty file added requirements.txt
Empty file.
119 changes: 119 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from setuptools import setup, find_packages
import os
import shutil


def move_configs_and_requirements():
"""将配置和依赖项移动到 benchflow 文件夹中。
如果已存在名为 `benchflow` 的目录,则删除该目录及其内容。然后将名为 `configs` 和 `requirements` 以及 `patch`
的子文件夹分别复制到 `benchflow` 中。
Args:
None
Returns:
None
"""
# 删除已经存在的目标目录
if os.path.exists("benchflow/configs"):
shutil.rmtree("benchflow/configs")

if os.path.exists("benchflow/requirements"):
shutil.rmtree("benchflow/requirements")

if os.path.exists("benchflow/patch"):
shutil.rmtree("benchflow/patch")

# 移动configs目录到benchflow目录下
shutil.copytree("configs", "benchflow/configs")
# 移动requirements目录到benchflow目录下
shutil.copytree("requirements", "benchflow/requirements")
# 移动patch目录到benchflow目录下
shutil.copytree("patch", "benchflow/patch")


def clean_pycache():
"""
清理当前目录及其子目录下所有以 .pyc、.pyo 和 __pycache__ 结尾的文件和文件夹。
Args:
None
Returns:
None
"""
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
if (
name.endswith(".pyc")
or name.endswith(".pyo")
or name.endswith("__pycache__")
):
os.remove(os.path.join(root, name))
print(f"Removed pycache file: {os.path.join(root, name)}")
for name in dirs:
if name == "__pycache__":
os.rmdir(os.path.join(root, name))
print(f"Removed pycache directory: {os.path.join(root, name)}")


def read_requirements(file_path):
"""
读取依赖项列表文件
Args:
file_path (str): 文件路径,要求该文件包含一行以换行符分隔的软件包名称
Returns:
list[str]: 返回一个包含所有依赖项名称的列表
"""
with open(file_path) as f:
print("benchflow install_requires:", f.read().splitlines())
return f.read().splitlines()


def pre_setup():
"""
移动配置文件和依赖项,并清理 pycache 文件
Args:
无参
Returns:
None
Raises:
无异常处理
"""
clean_pycache()
move_configs_and_requirements()


pre_setup()

setup(
name="pthook",
version="1.0.0",
packages=find_packages(exclude=["tests"]),
include_package_data=True,
install_requires=read_requirements("./requirements.txt"),
entry_points={
"console_scripts": [
"pthook = pthook:pthook",
],
},
author="clemente0620",
author_email="[email protected]",
description="A hook tool for pytorch",
long_description="A hook tool for pytorch, providing all the AI CHIPS to run torch",
url="https://www.pthook.com/pthook",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)
Empty file added tests/xtest_hook.py
Empty file.

0 comments on commit 9a5643c

Please sign in to comment.