Skip to content

Commit

Permalink
Only append config to pyproject.toml (#700)
Browse files Browse the repository at this point in the history
To avoid modifying existing pyproject settings, precli-init will now
only append precli configuration if it doesn't already exist.

Fixes: #697

Signed-off-by: Eric Brown <eric.brown@securesauce.dev>
  • Loading branch information
ericwb authored Nov 23, 2024
1 parent b5e5f8f commit 4b55876
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions precli/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,12 @@ def main():

# Check if the target file is pyproject.toml and prepare the structure
if path.name == "pyproject.toml":
if path.exists():
with open(path, "rb") as f:
doc = tomllib.load(f)
doc.setdefault("tool", {}).setdefault("precli", {}).update(
config
)
else:
doc = {"tool": {"precli": config}}
doc = {"tool": {"precli": config}}
else:
doc = config

# Write the configuration to the specified file
with open(path, "wb") as f:
with open(path, "ab") as f:
tomli_w.dump(doc, f)

except OSError:
Expand Down

0 comments on commit 4b55876

Please sign in to comment.