cyrx 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cyrx-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: cyrx
3
+ Version: 0.1.0
4
+ Summary: A RandomX cython binding for python.
5
+ Author-email: Vizonex <VizonexBusiness@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: typing-extensions; python_version < "3.12"
10
+ Provides-Extra: tests
11
+ Requires-Dist: pytest; extra == "tests"
12
+
13
+ # cyrx
14
+ A Sequal to pyrx the randomX crypto mining library.
15
+ This one plans to actually have a pypi package associated to it.
16
+ It shares the resemblance of the actual randomx api rather
17
+ than with pyrx which contains only a few functions and that was it for it.
18
+
19
+ ## How to use
20
+ ```python
21
+ from cyrx import get_flags, Cache, VM
22
+
23
+ from binascii import hexlify
24
+
25
+ def main():
26
+ my_key = b"RandomX example key"
27
+ my_input = b"RandomX example input"
28
+
29
+ flags = get_flags()
30
+ my_cache = Cache(flags)
31
+ my_cache.init(my_key)
32
+ my_machine = VM(flags, cache=my_cache)
33
+
34
+ out_hash = my_machine.hash(my_input)
35
+ print(hexlify(out_hash))
36
+
37
+ if __name__ == "__main__":
38
+ main()
39
+ ```
40
+
41
+ ```python
42
+ from cyrx import RXMiner
43
+
44
+ def main() -> None:
45
+ x = RXMiner(2) # 2 threads in this case...
46
+ out = x.run(
47
+ b"d2a4d89503447401ef6e6f30b46635b45b54f25a650c47464b5311f9d6fd4759",
48
+ b"d2a4d89503447401ef6e6f30b4663555",
49
+ )
50
+ assert (
51
+ hexlify(out)
52
+ == b"62894d19b5b129c9c7bab19171dc438446ceade7e0e8e3b1c263969e5463d9dc"
53
+ )
54
+ if __name__ == "__main__":
55
+ main()
56
+ ```
57
+
58
+
59
+ >[!WARNING]
60
+ >
61
+ > One Word of Caution that this library is made for eductaional purposes only
62
+ > it has been put on pypi in order to shortcut some problems that the pyrx
63
+ > library has failed to live up to.
64
+ > The Author of this library is not responsible for any abuse
65
+ > with this library including Crytojacking which is common amongst malware
66
+ > authors & large botnets. Use at your own risk.
67
+
cyrx-0.1.0/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # cyrx
2
+ A Sequal to pyrx the randomX crypto mining library.
3
+ This one plans to actually have a pypi package associated to it.
4
+ It shares the resemblance of the actual randomx api rather
5
+ than with pyrx which contains only a few functions and that was it for it.
6
+
7
+ ## How to use
8
+ ```python
9
+ from cyrx import get_flags, Cache, VM
10
+
11
+ from binascii import hexlify
12
+
13
+ def main():
14
+ my_key = b"RandomX example key"
15
+ my_input = b"RandomX example input"
16
+
17
+ flags = get_flags()
18
+ my_cache = Cache(flags)
19
+ my_cache.init(my_key)
20
+ my_machine = VM(flags, cache=my_cache)
21
+
22
+ out_hash = my_machine.hash(my_input)
23
+ print(hexlify(out_hash))
24
+
25
+ if __name__ == "__main__":
26
+ main()
27
+ ```
28
+
29
+ ```python
30
+ from cyrx import RXMiner
31
+
32
+ def main() -> None:
33
+ x = RXMiner(2) # 2 threads in this case...
34
+ out = x.run(
35
+ b"d2a4d89503447401ef6e6f30b46635b45b54f25a650c47464b5311f9d6fd4759",
36
+ b"d2a4d89503447401ef6e6f30b4663555",
37
+ )
38
+ assert (
39
+ hexlify(out)
40
+ == b"62894d19b5b129c9c7bab19171dc438446ceade7e0e8e3b1c263969e5463d9dc"
41
+ )
42
+ if __name__ == "__main__":
43
+ main()
44
+ ```
45
+
46
+
47
+ >[!WARNING]
48
+ >
49
+ > One Word of Caution that this library is made for eductaional purposes only
50
+ > it has been put on pypi in order to shortcut some problems that the pyrx
51
+ > library has failed to live up to.
52
+ > The Author of this library is not responsible for any abuse
53
+ > with this library including Crytojacking which is common amongst malware
54
+ > authors & large botnets. Use at your own risk.
55
+
@@ -0,0 +1,38 @@
1
+ [project]
2
+ name = "cyrx"
3
+ dynamic = ["version"]
4
+ description = "A RandomX cython binding for python."
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Vizonex", email = "VizonexBusiness@gmail.com" }
8
+ ]
9
+ requires-python = ">=3.10"
10
+
11
+ dependencies = [
12
+ 'typing-extensions; python_version<"3.12"',
13
+ ]
14
+
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ ]
18
+
19
+ [build-system]
20
+ requires = [
21
+ "setuptools",
22
+ "wheel",
23
+ "cython"
24
+ ]
25
+
26
+
27
+ [tool.setuptools.dynamic]
28
+ version = {attr = "cyrx.__version__"}
29
+
30
+ [project.optional-dependencies]
31
+ tests = ["pytest"]
32
+
33
+ [tool.cibuildwheel]
34
+ build-frontend = "build"
35
+ enable = ["cpython-freethreading"]
36
+
37
+
38
+
cyrx-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
cyrx-0.1.0/setup.py ADDED
@@ -0,0 +1,191 @@
1
+ import os
2
+ import shutil
3
+ import subprocess
4
+ import sys
5
+ import platform
6
+
7
+ from setuptools import setup, Extension
8
+ from setuptools.command.build_ext import build_ext
9
+
10
+
11
+ use_system_lib = bool(int(os.environ.get("CYRX_USE_SYSTEM_LIB", 0)))
12
+
13
+ def is_windows_11_arm() -> bool:
14
+ """Checks if we are using windows-11-arm"""
15
+
16
+ is_arm = platform.machine() == "ARM64"
17
+
18
+ version = platform.version()
19
+ build = version.split('.')[2] if len(version.split('.')) > 2 else "0"
20
+ is_win11_build = platform.release() == "10" and int(build) >= 22000
21
+
22
+ return is_arm and is_win11_build
23
+
24
+
25
+ class cyrx_build_ext(build_ext):
26
+ # Brought over from winloop since these can be very useful.
27
+ user_options = build_ext.user_options + [
28
+ ("cython-always", None, "run cythonize() even if .c files are present"),
29
+ (
30
+ "cython-annotate",
31
+ None,
32
+ "Produce a colorized HTML version of the Cython source.",
33
+ ),
34
+ ("cython-directives=", None, "Cythion compiler directives"),
35
+ ]
36
+
37
+ def initialize_options(self):
38
+ self.cython_always = False
39
+ self.cython_annotate = False
40
+ self.cython_directives = None
41
+ super().initialize_options()
42
+
43
+ def add_include_dir(self, dir, force=False):
44
+ if use_system_lib and not force:
45
+ return
46
+ dirs = self.compiler.include_dirs
47
+ dirs.insert(0, dir)
48
+ self.compiler.set_include_dirs(dirs)
49
+
50
+ def build_extensions(self):
51
+ if use_system_lib:
52
+ self.compiler.add_library("randomx")
53
+ build_ext.build_extensions(self)
54
+ return
55
+
56
+ cmake_cmd = shutil.which("cmake")
57
+
58
+ if not cmake_cmd:
59
+ raise RuntimeError("cyrx requires cmake")
60
+
61
+ randomx_dir = os.path.join("vendor")
62
+ build_temp = os.path.abspath(os.path.join(self.build_temp, "cyrx-build"))
63
+ install_dir = os.path.abspath(os.path.join(self.build_temp, "cyrx-install"))
64
+ os.makedirs(build_temp, exist_ok=True)
65
+ os.makedirs(install_dir, exist_ok=True)
66
+
67
+ cmake_args = [
68
+ '-DCMAKE_BUILD_TYPE=Release',
69
+ '-DCMAKE_CONFIGURATION_TYPES=Release',
70
+ f'-DCMAKE_INSTALL_PREFIX={install_dir}',
71
+ ]
72
+
73
+ if is_windows_11_arm():
74
+ cmake_args.append("-DARM64")
75
+
76
+ print(f"Configuring randomx with CMake in {build_temp}")
77
+ subprocess.check_call(
78
+ [cmake_cmd, os.path.abspath(randomx_dir)] + cmake_args, cwd=build_temp
79
+ )
80
+
81
+ print("Building randomx...")
82
+ build_args = ["--build", ".", "--config", "Release"]
83
+
84
+ subprocess.check_call([cmake_cmd] + build_args, cwd=build_temp)
85
+
86
+ install_args = ['--install', '.', '--config', 'Release']
87
+ subprocess.check_call([cmake_cmd] + install_args, cwd=build_temp)
88
+
89
+
90
+ if sys.platform == "win32":
91
+ # Windows libraries
92
+ possible_paths = [
93
+ os.path.join(install_dir, "lib", "randomx.lib"),
94
+ os.path.join(install_dir, "lib", "randomx_static.lib"),
95
+ os.path.join(install_dir, "lib", "librandomx.a"), # MinGW
96
+ ]
97
+ else:
98
+ possible_paths = [
99
+ os.path.join(install_dir, "lib", "librandomx.a"),
100
+ os.path.join(install_dir, "lib64", "librandomx.a"),
101
+ ]
102
+
103
+ lib_path = None
104
+ for path in possible_paths:
105
+ if os.path.exists(path):
106
+ lib_path = path
107
+ break
108
+
109
+
110
+ # print("==== DEBUG ====")
111
+ # print(lib_path)
112
+
113
+ if not lib_path:
114
+ raise RuntimeError(
115
+ f"Could not find installed randomx library in {install_dir}.\n"
116
+ f"Checked: {', '.join(possible_paths)}"
117
+ )
118
+
119
+ self.extensions[0].extra_objects = [lib_path]
120
+
121
+ if sys.platform == "win32":
122
+ self.compiler.add_library("Advapi32")
123
+
124
+ self.add_include_dir("vendor/src")
125
+ self.add_include_dir("vendor/src/asm")
126
+ self.add_include_dir("vendor/src/blake2")
127
+ build_ext.build_extensions(self)
128
+
129
+ def finalize_options(self):
130
+ need_cythonize = self.cython_always
131
+ cfiles = {}
132
+
133
+ for extension in self.distribution.ext_modules:
134
+ for i, sfile in enumerate(extension.sources):
135
+ if sfile.endswith(".pyx"):
136
+ prefix, ext = os.path.splitext(sfile)
137
+ cfile = prefix + ".c"
138
+
139
+ if os.path.exists(cfile) and not self.cython_always:
140
+ extension.sources[i] = cfile
141
+ else:
142
+ if os.path.exists(cfile):
143
+ cfiles[cfile] = os.path.getmtime(cfile)
144
+ else:
145
+ cfiles[cfile] = 0
146
+ need_cythonize = True
147
+
148
+ if need_cythonize:
149
+ # import pkg_resources
150
+
151
+ # Double check Cython presence in case setup_requires
152
+ # didn't go into effect (most likely because someone
153
+ # imported Cython before setup_requires injected the
154
+ # correct egg into sys.path.
155
+ try:
156
+ import Cython # noqa: F401
157
+ except ImportError:
158
+ raise RuntimeError(
159
+ "please install cython to compile cyares from source"
160
+ )
161
+
162
+ from Cython.Build import cythonize
163
+
164
+ directives = {}
165
+ if self.cython_directives:
166
+ for directive in self.cython_directives.split(","):
167
+ k, _, v = directive.partition("=")
168
+ if v.lower() == "false":
169
+ v = False
170
+ if v.lower() == "true":
171
+ v = True
172
+ directives[k] = v
173
+ self.cython_directives = directives
174
+
175
+ self.distribution.ext_modules[:] = cythonize(
176
+ self.distribution.ext_modules,
177
+ compiler_directives=directives,
178
+ annotate=self.cython_annotate,
179
+ emit_linenums=self.debug,
180
+ # Try using a cache to help with compiling as well...
181
+ cache=True,
182
+ )
183
+
184
+ return super().finalize_options()
185
+
186
+
187
+ if __name__ == "__main__":
188
+ setup(
189
+ ext_modules=[Extension("cyrx._cyrx", sources=["src/cyrx/_cyrx.pyx"])],
190
+ cmdclass={"build_ext": cyrx_build_ext},
191
+ )
@@ -0,0 +1,39 @@
1
+ from ._cyrx import (
2
+ CYRX_FLAG_ARGON2,
3
+ CYRX_FLAG_ARGON2_AVX2,
4
+ CYRX_FLAG_ARGON2_SSSE3,
5
+ CYRX_FLAG_DEFAULT,
6
+ CYRX_FLAG_FULL_MEM,
7
+ CYRX_FLAG_HARD_AES,
8
+ CYRX_FLAG_JIT,
9
+ CYRX_FLAG_LARGE_PAGES,
10
+ CYRX_FLAG_SECURE,
11
+ CYRX_FLAG_V2,
12
+ dataset_item_count,
13
+ Cache,
14
+ Dataset,
15
+ RXMiner,
16
+ VM,
17
+ get_flags,
18
+ )
19
+
20
+ __version__ = "0.1.0"
21
+ __author__ = "Vizonex"
22
+ __all__ = (
23
+ "CYRX_FLAG_ARGON2",
24
+ "CYRX_FLAG_ARGON2_AVX2",
25
+ "CYRX_FLAG_ARGON2_SSSE3",
26
+ "CYRX_FLAG_DEFAULT",
27
+ "CYRX_FLAG_FULL_MEM",
28
+ "CYRX_FLAG_HARD_AES",
29
+ "CYRX_FLAG_JIT",
30
+ "CYRX_FLAG_LARGE_PAGES",
31
+ "CYRX_FLAG_SECURE",
32
+ "CYRX_FLAG_V2",
33
+ "dataset_item_count",
34
+ "Cache",
35
+ "Dataset",
36
+ "RXMiner",
37
+ "VM",
38
+ "get_flags",
39
+ )