rust/hgcli/src/main.rs
changeset 43073 5c9c71cde1c9
parent 35632 fa9747e7fc86
child 43818 ce088b38f92b
equal deleted inserted replaced
43072:058c2468b2f5 43073:5c9c71cde1c9
    99 
    99 
   100 fn set_python_home(env: &Environment) {
   100 fn set_python_home(env: &Environment) {
   101     let raw = cstring_from_os(&env.python_home).into_raw();
   101     let raw = cstring_from_os(&env.python_home).into_raw();
   102     unsafe {
   102     unsafe {
   103         python27_sys::Py_SetPythonHome(raw);
   103         python27_sys::Py_SetPythonHome(raw);
   104     }
       
   105 }
       
   106 
       
   107 fn update_encoding(_py: Python, _sys_mod: &PyModule) {
       
   108     // Call sys.setdefaultencoding("undefined") if HGUNICODEPEDANTRY is set.
       
   109     let pedantry = env::var("HGUNICODEPEDANTRY").is_ok();
       
   110 
       
   111     if pedantry {
       
   112         // site.py removes the sys.setdefaultencoding attribute. So we need
       
   113         // to reload the module to get a handle on it. This is a lesser
       
   114         // used feature and we'll support this later.
       
   115         // TODO support this
       
   116         panic!("HGUNICODEPEDANTRY is not yet supported");
       
   117     }
   104     }
   118 }
   105 }
   119 
   106 
   120 fn update_modules_path(env: &Environment, py: Python, sys_mod: &PyModule) {
   107 fn update_modules_path(env: &Environment, py: Python, sys_mod: &PyModule) {
   121     let sys_path = sys_mod.get(py, "path").unwrap();
   108     let sys_path = sys_mod.get(py, "path").unwrap();
   208 }
   195 }
   209 
   196 
   210 fn run_py(env: &Environment, py: Python) -> PyResult<()> {
   197 fn run_py(env: &Environment, py: Python) -> PyResult<()> {
   211     let sys_mod = py.import("sys").unwrap();
   198     let sys_mod = py.import("sys").unwrap();
   212 
   199 
   213     update_encoding(py, &sys_mod);
       
   214     update_modules_path(&env, py, &sys_mod);
   200     update_modules_path(&env, py, &sys_mod);
   215 
   201 
   216     // TODO consider a better error message on failure to import.
   202     // TODO consider a better error message on failure to import.
   217     let demand_mod = py.import("hgdemandimport")?;
   203     let demand_mod = py.import("hgdemandimport")?;
   218     demand_mod.call(py, "enable", NoArgs, None)?;
   204     demand_mod.call(py, "enable", NoArgs, None)?;