5
5
from setuptools import setup , find_packages
6
6
from setuptools .command .build_py import build_py as _build_py
7
7
8
- # Import the bdist_wheel command from wheel
9
8
try :
10
9
from wheel .bdist_wheel import bdist_wheel as _bdist_wheel
11
10
except ImportError :
15
14
CARGO_MANIFEST_PATH = os .path .abspath (os .path .join (HERE , "../../../Cargo.toml" ))
16
15
CARGO_TARGET_DIR = os .path .abspath (os .path .join (HERE , "../../../target/release" ))
17
16
BINDINGS_SRC = os .path .abspath (os .path .join (HERE , "../../../bindings/qsharp_bridge.py" ))
17
+ VERSION = os .environ .get ("PACKAGE_VERSION" , "0.1.0" )
18
18
19
19
def get_lib_filename ():
20
20
"""
@@ -47,39 +47,56 @@ def run(self):
47
47
"cargo" , "build" , "--release" ,
48
48
"--manifest-path" , CARGO_MANIFEST_PATH
49
49
])
50
-
51
50
# 2. copy the native library from Cargo's output folder into the Python package.
52
51
src_lib = os .path .join (CARGO_TARGET_DIR , lib_filename )
53
52
dst_dir = os .path .join (HERE , "qsharp_bridge" )
54
53
dst_lib = os .path .join (dst_dir , lib_filename )
55
54
self .mkpath (dst_dir )
56
55
print (f"Copying native library: { src_lib } -> { dst_lib } " )
57
56
self .copy_file (src_lib , dst_lib )
58
-
59
57
# 3. copy uniFFI bindings file from the bindings/ folder.
60
58
dst_binding = os .path .join (dst_dir , "qsharp_bridge.py" )
61
59
if os .path .exists (BINDINGS_SRC ):
62
60
print (f"Copying binding file: { BINDINGS_SRC } -> { dst_binding } " )
63
61
self .copy_file (BINDINGS_SRC , dst_binding )
64
62
else :
65
63
print ("Warning: Binding file not found at" , BINDINGS_SRC )
66
-
67
64
# 4. continue with the standard build process.
68
65
super ().run ()
69
66
70
67
if _bdist_wheel :
71
68
class bdist_wheel (_bdist_wheel ):
72
69
def finalize_options (self ):
70
+ self .plat_name_supplied = True
71
+
72
+ # Set the platform tag based on the system
73
+ if sys .platform .startswith ('linux' ):
74
+ self .plat_name = "py3-none-linux_x86_64"
75
+ elif sys .platform .startswith ('darwin' ):
76
+ self .plat_name = "py3-none-macosx_11_0_universal2"
77
+ elif sys .platform .startswith ('win' ):
78
+ self .plat_name = "py3-none-win_amd64"
79
+ else :
80
+ # Fall back to default behavior for unknown platforms
81
+ self .plat_name_supplied = False
82
+
73
83
super ().finalize_options ()
74
- # mark the wheel as not pure so that a platform tag is used
75
- # I am not sure I know what I am doing, but this sounds right
84
+ # We still need to mark it as not pure Python
76
85
self .root_is_pure = False
86
+
87
+ def get_tag (self ):
88
+ # Override the tag generation to use our custom platform tag
89
+ if self .plat_name_supplied :
90
+ # Use py3 instead of cpXY to support any Python 3.x version
91
+ return ('py3' , 'none' , self .plat_name .split ('-' )[- 1 ])
92
+ # Fall back to default behavior
93
+ return super ().get_tag ()
77
94
else :
78
95
bdist_wheel = None
79
96
80
97
setup (
81
98
name = "qsharp-bridge" ,
82
- version = "0.1.0" ,
99
+ version = VERSION ,
83
100
description = "Cross platform library for accessing Q# features in a simple way" ,
84
101
author = "Filip w" ,
85
102
author_email = "contact@strathweb.com" ,
@@ -91,4 +108,4 @@ def finalize_options(self):
91
108
"Programming Language :: Python :: 3" ,
92
109
],
93
110
python_requires = ">=3.6" ,
94
- )
111
+ )
0 commit comments