-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
138 lines (111 loc) · 3.92 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from setuptools import setup, find_packages, Command
import subprocess, unittest, os, glob, shutil, stat
class InstallCommand(Command):
description = "installation"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
try:
if not os.path.exists("zkbp_module/curv"):
subprocess.run(["git", "clone", "https://github.com/ZenGo-X/curv.git", "zkbp_module/curv"], check=True)
# if not os.path.exists("@openzeppelin/contracts"):
# openzeppelin_download()
[shutil.copy(file, "zkbp_module/curv/src/cryptographic_primitives/proofs/") for file in glob.glob("zkbp_module/src/proofs/*")]
subprocess.run(["maturin", "develop", "-r", "-m", "./zkbp_module/Cargo.toml"], check=True)
run_test()
except subprocess.CalledProcessError as e:
print(f"An error occurred: {e}")
raise
class ContractCommand(Command):
description = "contract download"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
openzeppelin_download()
def openzeppelin_download():
# Clone the repository with filtering and no checkout
subprocess.run([
"git", "clone", "--filter=blob:none", "--no-checkout",
"https://github.com/OpenZeppelin/openzeppelin-contracts.git",
"@openzeppelin"
], check=True)
# Change directory to the cloned repository
os.chdir("@openzeppelin")
# Set sparse-checkout to cone mode
subprocess.run(["git", "sparse-checkout", "set", "--cone"], check=True)
# Checkout the master branch
subprocess.run(["git", "checkout", "master"], check=True)
# Set sparse-checkout to include only the contracts directory
subprocess.run(["git", "sparse-checkout", "set", "contracts"], check=True)
# Change back to the original directory
os.chdir("..")
class TestCommand(Command):
description = "Run unittests."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
run_test()
def run_test():
test_loader = unittest.TestLoader()
test_suite = test_loader.discover('tests')
test_runner = unittest.TextTestRunner(verbosity=2)
test_runner.run(test_suite)
clean()
def clean():
# Define patterns for files to remove
def remove_readonly(func, path, _):
os.chmod(path, stat.S_IWRITE)
func(path)
patterns = ['tests/Bank*', 'Bank*', 'pyledger/examples/Bank*','pyledger/examples/Issuer*']
for pattern in patterns:
for file in glob.glob(pattern):
try:
os.remove(file)
except Exception as e:
print(f"Error deleting {file}: {e}")
for folder_path in ["zkbp_module/curv", "zkbp_module/target"]:
if os.path.exists(folder_path) and os.path.isdir(folder_path):
try:
shutil.rmtree(folder_path, onerror=remove_readonly)
print(f"Deleted: {folder_path}")
except Exception as e:
print(f"Error deleting {folder_path}: {e}")
class CleanCommand(Command):
description = "Clean up files starting with 'Bank'."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
clean()
setup(
name='pyledger',
version='0.1',
packages=find_packages(),
install_requires=[
'maturin',
'Flask',
'numpy',
'web3==5.18.0',
'py-solc-x',
],
cmdclass={
'init': InstallCommand,
'test': TestCommand,
'clean': CleanCommand,
'contract': ContractCommand
},
author='GT Applied Research JP-MorganChase',
description='Installation of Python package of Padl',
url='https://github.com/yourusername/your-repo',
)