2023-01-20 18:31:05 +08:00
|
|
|
# -------------------------------
|
|
|
|
# Difficult Rocket
|
|
|
|
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
|
|
|
# All rights reserved
|
|
|
|
# -------------------------------
|
|
|
|
import os
|
2023-01-20 20:20:35 +08:00
|
|
|
import sys
|
2023-01-20 18:31:05 +08:00
|
|
|
import shutil
|
|
|
|
import warnings
|
2023-01-23 17:17:39 +08:00
|
|
|
import traceback
|
2023-01-20 18:31:05 +08:00
|
|
|
from setuptools import setup
|
|
|
|
from setuptools_rust import Binding, RustExtension
|
|
|
|
|
2023-01-23 00:01:01 +08:00
|
|
|
sys.path.append('../../../')
|
|
|
|
if '../../../' in sys.path:
|
|
|
|
from Difficult_Rocket import DR_runtime
|
2023-01-20 20:20:35 +08:00
|
|
|
|
|
|
|
package_path = 'Difficult_Rocket_rs'
|
2023-01-20 18:31:05 +08:00
|
|
|
|
|
|
|
setup(
|
|
|
|
name='Difficult_Rocket_rs',
|
2023-01-23 00:01:01 +08:00
|
|
|
version=DR_runtime.DR_Rust_version.__str__(),
|
2023-01-20 20:20:35 +08:00
|
|
|
author='shenjackyuanjie',
|
|
|
|
author_email='3695888@qq.com',
|
2023-01-20 18:31:05 +08:00
|
|
|
rust_extensions=[RustExtension(target="Difficult_Rocket_rs.Difficult_Rocket_rs",
|
2023-01-20 20:20:35 +08:00
|
|
|
# rust_version='2021',
|
2023-01-20 18:31:05 +08:00
|
|
|
binding=Binding.PyO3)],
|
|
|
|
zip_safe=False
|
|
|
|
)
|
|
|
|
|
2023-01-23 00:01:01 +08:00
|
|
|
lib_path = '../lib'
|
2023-01-23 17:17:39 +08:00
|
|
|
build_path = 'build'
|
2023-01-20 18:31:05 +08:00
|
|
|
|
2023-01-20 20:20:35 +08:00
|
|
|
if 'clean' in sys.argv:
|
|
|
|
shutil.rmtree(lib_path, ignore_errors=True)
|
|
|
|
shutil.rmtree(build_path, ignore_errors=True)
|
2023-01-23 00:01:01 +08:00
|
|
|
shutil.rmtree(f'{package_path}.egg-info', ignore_errors=True)
|
2023-01-20 20:20:35 +08:00
|
|
|
sys.exit(0)
|
|
|
|
|
2023-01-20 18:31:05 +08:00
|
|
|
if not os.path.exists(lib_path):
|
|
|
|
os.mkdir(lib_path)
|
|
|
|
|
|
|
|
builds = os.listdir(build_path)
|
2023-01-23 00:01:01 +08:00
|
|
|
print(os.path.abspath('.'))
|
2023-01-20 18:31:05 +08:00
|
|
|
|
2023-01-23 17:17:39 +08:00
|
|
|
try:
|
|
|
|
shutil.copy('src/__init__.py', os.path.join(lib_path, '__init__.py'))
|
|
|
|
except shutil.SameFileError:
|
|
|
|
traceback.print_exc()
|
|
|
|
|
2023-01-20 18:31:05 +08:00
|
|
|
for build_dir in builds:
|
|
|
|
if not os.path.exists(os.path.join(build_path, build_dir, package_path)):
|
|
|
|
warnings.warn(f'package not found at {build_path}/{build_dir}')
|
|
|
|
continue
|
|
|
|
for file in os.listdir(os.path.join(build_path, build_dir, package_path)):
|
2023-01-23 00:01:01 +08:00
|
|
|
# file_name = os.path.join(lib_path, file.replace(package_path, f'{package_path}.{DR_runtime.DR_Rust_version}'))
|
|
|
|
file_name = os.path.join(lib_path, file)
|
|
|
|
shutil.rmtree(file_name, ignore_errors=True)
|
2023-01-23 17:17:39 +08:00
|
|
|
try:
|
|
|
|
shutil.copy(os.path.join(build_path, build_dir, package_path, file), file_name)
|
|
|
|
except (shutil.SameFileError, PermissionError):
|
|
|
|
# print(os.path.exists(os.path))
|
|
|
|
print(os.listdir(lib_path))
|
|
|
|
traceback.print_exc()
|
|
|
|
continue
|
|
|
|
os.remove(file_name)
|
|
|
|
shutil.copy(os.path.join(build_path, build_dir, package_path, file), file_name)
|
2023-01-23 00:01:01 +08:00
|
|
|
# shutil.rmtree(os.path.join(build_path, build_dir))
|
2023-01-20 20:20:35 +08:00
|
|
|
# print(os.path.join(build_path, build_dir))
|