123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import os
- import shutil
- """
- 1、复制待打包的源码到distribute中;
- 2、生成新的版本号
- 3、添加__init__.py文件
- """
- # 参数
- rel_path = os.path.dirname(os.path.dirname(os.path.dirname( os.path.abspath(__file__))))
- package_path = 'PACKAGE/common/'
- print(rel_path)
- project_name_tmp = (os.path.abspath(__file__).split('/')[-4] + '_common').replace("_","-").split("-")
- project_name = "".join([x.capitalize() for x in project_name_tmp])
- with open(os.path.join(rel_path, package_path, 'ver'),'r+') as f:
- ver = int(f.readline())
- newver = ver + 1
- f.seek(0)
- f.truncate()
- f.write(str(newver))
- version = f"1.0.{newver}"
- # 删除旧的build
- print("\n清空旧的build目录中................")
- try:
- if os.path.exists(os.path.join(rel_path, package_path, r'build')):
- shutil.rmtree(os.path.join(rel_path, package_path, r'build'))
- except Exception as e:
- print(e)
- print(f'error: 清空旧的build目录失败,请手动删除build目录\n')
-
- # 生成对应项目的目录
- print("\n生成项目文件目录中................")
- lib_path = os.path.join(rel_path, package_path, r'distribute', version.replace(".","_"))
- if not os.path.exists(lib_path):
- os.makedirs(lib_path)
- else:
- shutil.rmtree(lib_path)
-
- # 移动文件
- print("\n移动文件中................")
- new_path = os.path.join(lib_path,project_name)
- shutil.copytree(os.path.join(rel_path, 'COMMON'), new_path)
- for dirpath, dirnames, filenames in os.walk(new_path):
- if '__init__.py' not in os.listdir(dirpath) and "__pycache__" not in dirpath:
- with open(f"{dirpath}/__init__.py", 'w') as f:
- pass
-
- shutil.copy(os.path.join(rel_path, package_path, 'template', 'setup.py'), lib_path)
- shutil.copy(os.path.join(rel_path, package_path, 'template','LICENSE'), lib_path)
- shutil.copy(os.path.join(rel_path, package_path, 'template','README.md'), lib_path)
- shutil.copy(os.path.join(rel_path, package_path, 'template','setup_encrypt.py'), lib_path)
- shutil.copy(os.path.join(rel_path, package_path, 'ver'), lib_path)
- # setup(
- # name=project_name,
- # version=version,
- # author='zlwl',
- # packages=find_packages(lib_path+"/src/common"),
- # python_requires='==3.8.16',
- # platforms='Linux'
- # )
|