adding "init" command

This commit is contained in:
evilchili 2024-03-25 23:52:29 -07:00
parent 164b69cd60
commit 2e34677d31
3 changed files with 40 additions and 9 deletions

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "poetry-slam"
version = "0.1.0"
version = "1.0"
description = "An opinionated build tool for python poetry projects"
authors = ["evilchili <evilchili@gmail.com>"]
readme = "README.md"
@ -20,6 +20,17 @@ pytest-cov = "^4.0.0"
[tool.poetry.group.dev.dependencies]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
slam = "poetry_slam.cli:app"
### SLAM
[tool.black]
line-length = 120
target-version = ['py310']
@ -39,10 +50,4 @@ remove-duplicate-keys = true # remove all duplicate keys in objects
remove-unused-variables = true # remove unused variables
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
slam = "poetry_slam.cli:app"
### ENDSLAM

View File

@ -72,7 +72,7 @@ class BuildTool:
def test(self, args) -> bool:
old_v = self.verbose
self.verbose = True
returncode = self._exec("pytest", *args)
returncode = self.run("pytest", *args)
self.verbose = old_v
return returncode

View File

@ -34,6 +34,32 @@ def main(
build()
@app.command()
def init():
"""
Add opinionated defaults to your pyproject.toml.
"""
defaults = Path(__file__).parent / "defaults.toml"
target = app_state["build_tool"].project_root / "pyproject.toml"
if not target.exists():
raise RuntimeError(f"Could not find pyproject.toml at '{target}'")
logger.debug(f"Checking for modifications to {target}")
existing = target.read_text()
if "### SLAM" in existing:
logging.info(f"Found what looks like poetry-slam modifications; stopping.")
print(f"Abort: It looks like poetry-slam has already modified {target}.")
else:
backup = Path(str(target) + ".slam-orig")
backup.write_text(existing)
logging.debug(f"Saved backup of {target} to {backup}")
new = Path(str(target) + ".slam-new")
new.write_text(existing + "\n\n" + defaults.read_text())
logging.debug(f"Wrote temporary file {new}")
new.rename(target)
logging.debug(f"Renamed {new} to {target}")
print(f"Added poetry-slam defaults to {target}")
@app.command()
def format():
"""