Skip to content

Commit

Permalink
Use pants.toml as default config if it exists
Browse files Browse the repository at this point in the history
Without this change, users would need to explicitly set `--pants-config-files=pants.toml` every time.

If `pants.toml` exists, we will ignore the default of `pants.ini` unless the user explicitly adds `pants.ini` via `--pants-config-files`.
  • Loading branch information
Eric-Arellano committed Feb 2, 2020
1 parent 43cd952 commit fb49453
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/python/pants/base/build_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import logging
import os
from pathlib import Path
from typing import Optional

from pants.base.build_root import BuildRoot
Expand Down Expand Up @@ -51,7 +52,10 @@ def get_pants_configdir() -> str:


def get_default_pants_config_file() -> str:
"""Return the default location of the pants config file."""
"""Return the default location of the Pants config file."""
default_toml = Path(get_buildroot(), "pants.toml")
if default_toml.is_file():
return str(default_toml)
return os.path.join(get_buildroot(), 'pants.ini')


Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/option/options_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import stat
import sys
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, Iterable, List, Mapping, Optional, Sequence, Set, Tuple, Type

from pants.base.build_environment import get_default_pants_config_file
Expand Down Expand Up @@ -53,8 +54,9 @@ def get_config_file_paths(env, args) -> List[str]:
evars = ['PANTS_GLOBAL_PANTS_CONFIG_FILES', 'PANTS_PANTS_CONFIG_FILES', 'PANTS_CONFIG_FILES']

path_list_values = []
if os.path.isfile(get_default_pants_config_file()):
path_list_values.append(ListValueComponent.create(get_default_pants_config_file()))
default = get_default_pants_config_file()
if Path(default).is_file():
path_list_values.append(ListValueComponent.create(default))
for var in evars:
if var in env:
path_list_values.append(ListValueComponent.create(env[var]))
Expand Down

0 comments on commit fb49453

Please sign in to comment.