Skip to content

Commit

Permalink
Support empty PYTHRANRC
Browse files Browse the repository at this point in the history
This should help reproducible builds.

Related to #2170
  • Loading branch information
serge-sans-paille committed Jan 17, 2024
1 parent 14777c7 commit 21eff79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/MANUAL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ environment variable ``PYTHRANRC``::

PYTHRANRC=/opt/company/pythran/config.pythranrc pythran arc_distance.py

When ``PYTHRANRC`` is set to the empty string, no user-site configuration is
loaded. This can be helpful for reproducible builds.

All the options in the ``.pythranrc`` file can be specified when running pythran by using the command line argument --config= .
For example::

Expand Down
22 changes: 15 additions & 7 deletions pythran/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,38 @@ def get_paths_cfg(
"pythran-default.cfg")

user_config_path = os.environ.get('PYTHRANRC', None)
if not user_config_path:
if user_config_path:
user_config_paths = "user", user_config_path
elif 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(
user_config_paths = "user", os.path.expanduser(
os.path.join(user_config_dir, user_file))
return {"sys": sys_config_path,
"platform": platform_config_path,
"user": user_config_path}
else:
user_config_paths = ()

paths = {"sys": sys_config_path,
"platform": platform_config_path}
paths.update(user_config_paths)
return paths


def init_cfg(sys_file, platform_file, user_file, config_args=None):
paths = get_paths_cfg(sys_file, platform_file, user_file)

sys_config_path = paths["sys"]
platform_config_path = paths["platform"]
user_config_path = paths["user"]
user_config_path = paths.get("user")

cfgp = ConfigParser()
for required in (sys_config_path, platform_config_path):
cfgp.read([required])
cfgp.read([user_config_path])

if user_config_path:
cfgp.read([user_config_path])

if config_args is not None:
update_cfg(cfgp, config_args)
Expand Down

0 comments on commit 21eff79

Please sign in to comment.