55from  setuptools  import  setup , find_packages 
66from  setuptools .command .build_py  import  build_py  as  _build_py 
77
8- # Import the bdist_wheel command from wheel 
98try :
109    from  wheel .bdist_wheel  import  bdist_wheel  as  _bdist_wheel 
1110except  ImportError :
1514CARGO_MANIFEST_PATH  =  os .path .abspath (os .path .join (HERE , "../../../Cargo.toml" ))
1615CARGO_TARGET_DIR  =  os .path .abspath (os .path .join (HERE , "../../../target/release" ))
1716BINDINGS_SRC  =  os .path .abspath (os .path .join (HERE , "../../../bindings/qsharp_bridge.py" ))
17+ VERSION  =  os .environ .get ("PACKAGE_VERSION" , "0.1.0" )
1818
1919def  get_lib_filename ():
2020    """ 
@@ -47,39 +47,56 @@ def run(self):
4747            "cargo" , "build" , "--release" ,
4848            "--manifest-path" , CARGO_MANIFEST_PATH 
4949        ])
50- 
5150        # 2. copy the native library from Cargo's output folder into the Python package. 
5251        src_lib  =  os .path .join (CARGO_TARGET_DIR , lib_filename )
5352        dst_dir  =  os .path .join (HERE , "qsharp_bridge" )
5453        dst_lib  =  os .path .join (dst_dir , lib_filename )
5554        self .mkpath (dst_dir )
5655        print (f"Copying native library: { src_lib }   -> { dst_lib }  " )
5756        self .copy_file (src_lib , dst_lib )
58- 
5957        # 3. copy uniFFI bindings file from the bindings/ folder. 
6058        dst_binding  =  os .path .join (dst_dir , "qsharp_bridge.py" )
6159        if  os .path .exists (BINDINGS_SRC ):
6260            print (f"Copying binding file: { BINDINGS_SRC }   -> { dst_binding }  " )
6361            self .copy_file (BINDINGS_SRC , dst_binding )
6462        else :
6563            print ("Warning: Binding file not found at" , BINDINGS_SRC )
66- 
6764        # 4. continue with the standard build process. 
6865        super ().run ()
6966
7067if  _bdist_wheel :
7168    class  bdist_wheel (_bdist_wheel ):
7269        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+                 
7383            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 
7685            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 ()
7794else :
7895    bdist_wheel  =  None 
7996
8097setup (
8198    name = "qsharp-bridge" ,
82-     version = "0.1.0" ,
99+     version = VERSION ,
83100    description = "Cross platform library for accessing Q# features in a simple way" ,
84101    author = "Filip w" ,
85102@@ -91,4 +108,4 @@ def finalize_options(self):
91108        "Programming Language :: Python :: 3" ,
92109    ],
93110    python_requires = ">=3.6" ,
94- )
111+ )
0 commit comments