Skip to content

Commit

Permalink
feat: pyproject.toml support
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Oct 26, 2024
1 parent 65737b2 commit fb75ed6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
51 changes: 37 additions & 14 deletions mutmut/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,36 +957,59 @@ def should_ignore_for_mutation(self, path):
return False


@lru_cache()
def read_config():
def config_reader():
path=Path("pyproject.toml")
if path.exists():
if sys.version_info >= (3, 11):
from tomllib import loads
else:
from toml import loads
data = loads(path.read_text("utf-8"))

try:
config = data["tool"]["mutmut"]
except KeyError:
pass
else:
def s(key,default):
try:
result=config[key]
except KeyError:
return default
return result
return s

config_parser = ConfigParser()
config_parser.read('setup.cfg')

def s(key, default):
try:
return config_parser.get('mutmut', key)
result= config_parser.get('mutmut', key)
except (NoOptionError, NoSectionError):
return default
if isinstance(default,list):
result=[x for x in result.split("\n") if x]
elif isinstance(default,int):
result=int(result)
return result
return s

@lru_cache()
def read_config():

s=config_reader()

mutmut.config = Config(
do_not_mutate=[
x
for x in s('do_not_mutate', '').split('\n')
if x
],
do_not_mutate=s('do_not_mutate', []),
also_copy=[
Path(y)
for y in [
x
for x in s('also_copy', '').split('\n')
if x
]
for y in s('also_copy', [])
]+[
Path('tests/'),
Path('test/'),
Path('tests.py'),
],
max_stack_depth=int(s('max_stack_depth', '-1'))
max_stack_depth=s('max_stack_depth', -1)
)


Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ click
junit-xml==1.8
setproctitle
textual
toml>=0.10.2; python_version < '3.11'

0 comments on commit fb75ed6

Please sign in to comment.