fastai / nbdev

Create delightful software with Jupyter Notebooks
https://nbdev.fast.ai/
Apache License 2.0
4.9k stars 487 forks source link

nbdev_bump_version destroys literate programming in settings.ini #1334

Open Elijas opened 1 year ago

Elijas commented 1 year ago

Reproduction

  1. Create a new nbdev repository
  2. Examine the settings.ini file, which contains comments and variable substitution
  3. Execute the nbdev_bump_version command
  4. Observe that the settings.ini file now lacks comments, and variables have been replaced with their hardcoded values.

Solution

Just a simple terminal command would suffice

new_version="0.1.2"
sed -i "s/^\(version[[:space:]]*=[[:space:]]*\).*$/\1 ${new_version}/" settings.ini

or in python

import re

new_version = "0.1.2"

with open("settings.ini", "r") as file:
    content = file.read()

content = re.sub(r"^(version\s*=\s*).*?$", r"\1 " + new_version, content, flags=re.MULTILINE)

with open("settings.ini", "w") as file:
    file.write(content)