serge-sans-paille / pythran

Ahead of Time compiler for numeric kernels
https://pythran.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.98k stars 191 forks source link

Provide support for '--ignore-pythranrc' #2171

Closed serge-sans-paille closed 5 months ago

serge-sans-paille commented 5 months ago

Related to #2170

serge-sans-paille commented 5 months ago

@paugier can you double check this matches your need?

paugier commented 5 months ago

It seems buggy. init_cfg is called without ignore_userfile before the call from run.py. And then there is

    global cfg
    if cfg is not UninitializedConfig:
        return cfg

Moreover, it seems to me that it would be convenient for use in Meson to be able to activate this with an environment variable, for example with something like PYTHRANRC=0 ?

It actually already "works" (~/.pythranrc is ignored), but with a warning "WARNING: user file does not exist: 0". We could just remove the warning for a special value.

serge-sans-paille commented 5 months ago

@paugier I like your idea! Implementation done

paugier commented 5 months ago

Ah I get a traceback :-)

  File "/home/users/augier3pi/dev/pythran/pythran/config.py", line 79, in init_cfg
    paths = get_paths_cfg(sys_file, platform_file, user_file)
  File "/home/users/augier3pi/dev/pythran/pythran/config.py", line 74, in get_paths_cfg
    paths.update((user_config_paths,))
ValueError: dictionary update sequence element #0 has length 0; 2 is required

It works with something like:

    paths = {
        "sys": sys_config_path, "platform": platform_config_path
    }

    user_config_path = os.environ.get('PYTHRANRC', None)
    if user_config_path is None:
        user_config_dir = os.environ.get('XDG_CONFIG_HOME', None)
        if not user_config_dir:
            user_config_dir = os.environ.get('HOME', None)
        if not user_config_dir:
            user_config_dir = '~'
        user_config_path = os.path.expanduser(
            os.path.join(user_config_dir, user_file))
    if user_config_path:
        paths.update(("user", user_config_path,))
    return paths