setup.py
changeset 44487 06b0aa048007
parent 44485 5cbe2c0ebc53
child 44588 2a98b0cd4995
equal deleted inserted replaced
44486:b55bec1ea972 44487:06b0aa048007
   133         raise SystemExit(
   133         raise SystemExit(
   134             "Couldn't import standard bz2 (incomplete Python install)."
   134             "Couldn't import standard bz2 (incomplete Python install)."
   135         )
   135         )
   136 
   136 
   137 ispypy = "PyPy" in sys.version
   137 ispypy = "PyPy" in sys.version
   138 
       
   139 hgrustext = os.environ.get('HGWITHRUSTEXT')
       
   140 # TODO record it for proper rebuild upon changes
       
   141 # (see mercurial/__modulepolicy__.py)
       
   142 if hgrustext != 'cpython' and hgrustext is not None:
       
   143     if hgrustext:
       
   144         printf('unkown HGWITHRUSTEXT value: %s' % hgrustext, file=sys.stderr)
       
   145     hgrustext = None
       
   146 
   138 
   147 import ctypes
   139 import ctypes
   148 import errno
   140 import errno
   149 import stat, subprocess, time
   141 import stat, subprocess, time
   150 import re
   142 import re
   476             self.make_file([pofile], mobuildfile, spawn, (cmd,))
   468             self.make_file([pofile], mobuildfile, spawn, (cmd,))
   477 
   469 
   478 
   470 
   479 class hgdist(Distribution):
   471 class hgdist(Distribution):
   480     pure = False
   472     pure = False
   481     rust = hgrustext is not None
   473     rust = False
       
   474     no_rust = False
   482     cffi = ispypy
   475     cffi = ispypy
   483 
   476 
   484     global_options = Distribution.global_options + [
   477     global_options = Distribution.global_options + [
   485         ('pure', None, "use pure (slow) Python code instead of C extensions"),
   478         ('pure', None, "use pure (slow) Python code instead of C extensions"),
   486         ('rust', None, "use Rust extensions additionally to C extensions"),
   479         ('rust', None, "use Rust extensions additionally to C extensions"),
       
   480         (
       
   481             'no-rust',
       
   482             None,
       
   483             "do not use Rust extensions additionally to C extensions",
       
   484         ),
   487     ]
   485     ]
       
   486 
       
   487     negative_opt = Distribution.negative_opt.copy()
       
   488     boolean_options = ['pure', 'rust', 'no-rust']
       
   489     negative_opt['no-rust'] = 'rust'
       
   490 
       
   491     def _set_command_options(self, command_obj, option_dict=None):
       
   492         command_obj.boolean_options += self.boolean_options
       
   493         return Distribution._set_command_options(
       
   494             self, command_obj, option_dict=option_dict
       
   495         )
       
   496 
       
   497     def parse_command_line(self):
       
   498         ret = Distribution.parse_command_line(self)
       
   499         if not (self.rust or self.no_rust):
       
   500             hgrustext = os.environ.get('HGWITHRUSTEXT')
       
   501             # TODO record it for proper rebuild upon changes
       
   502             # (see mercurial/__modulepolicy__.py)
       
   503             if hgrustext != 'cpython' and hgrustext is not None:
       
   504                 if hgrustext:
       
   505                     msg = 'unkown HGWITHRUSTEXT value: %s' % hgrustext
       
   506                     printf(msg, file=sys.stderr)
       
   507                 hgrustext = None
       
   508             self.rust = hgrustext is not None
       
   509             self.no_rust = not self.rust
       
   510         return ret
   488 
   511 
   489     def has_ext_modules(self):
   512     def has_ext_modules(self):
   490         # self.ext_modules is emptied in hgbuildpy.finalize_options which is
   513         # self.ext_modules is emptied in hgbuildpy.finalize_options which is
   491         # too late for some cases
   514         # too late for some cases
   492         return not self.pure and Distribution.has_ext_modules(self)
   515         return not self.pure and Distribution.has_ext_modules(self)