Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
moshez committed Jan 19, 2024
1 parent 1ebd1fd commit 03fe1f9
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/silly_pyproject_name/name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import difflib
import pathlib
import logging

from commander_data import COMMAND
from commander_data.common import GIT
from gather.commands import add_argument
import tomlkit

from . import ENTRY_DATA


LOGGER = logging.getLogger(__name__)

def _pyproject_toml(args):
return pathlib.Path(args.env["PWD"]) / "pyproject.toml"

def _load_pyproject(pwd):
return tomlkit.loads((pathlib.Path(pwd) / "pyproject.toml").read_text())


@ENTRY_DATA.register()
def name(args):
name = tomlkit.loads(_pyproject_toml(args).read_text())["project"]["name"]
LOGGER.info("Current name: %s", name)

@ENTRY_DATA.register(
add_argument("--no-dry-run", action="store_true", default=False),
add_argument("new_name"),
)
def rename(args):
toml_file = _pyproject_toml(args)
old_contents = toml_file.read_text()
parsed = tomlkit.loads(old_contents)
parsed["project"]["name"] = args.new_name
new_contents = tomlkit.dumps(parsed)
diffs = difflib.unified_diff(
old_contents.splitlines(),
new_contents.splitlines(),
lineterm="",
)
for a_diff in diffs:
LOGGER.info("Difference: %s", a_diff.rstrip())
if args.no_dry_run:
toml_file.write_text(new_contents)
else:
LOGGER.info("Dry run, not modifying pyproject.toml")

0 comments on commit 03fe1f9

Please sign in to comment.