Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions hands_on/diff_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os

from exercise_utils.file import create_or_update_file, append_to_file
from exercise_utils.git import add, init, commit, tag

__requires_git__ = True
__requires_github__ = False


def download(verbose: bool):
os.makedirs("things")
os.chdir("things")
init(verbose)
create_or_update_file(
"fruits.txt",
"""
apples
bananas
cherries
dragon fruits
""",
)
add(["fruits.txt"], verbose)
commit("Add fruits.txt", verbose)
append_to_file("fruits.txt",
"""
elderberries
figs
"""
)
add(["fruits.txt"], verbose)
commit("Add elderberries and figs to fruits.txt", verbose)

create_or_update_file(
"colours.txt",
"a file for colours\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"a file for colours\n",
"a file for colours",

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think here should remove the escape sequence. The targeted colour.txt should be

a file for colours
blue
red
white

While if removed, will be

a file for coloursblue
red
white

)
create_or_update_file(
"shapes.txt",
"a file for shapes\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"a file for shapes\n",
"a file for shapes",

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason as colour.txt, here I think we should keep the \n

)
add(["colours.txt", "shapes.txt"], verbose)
commit("Add colours.txt, shapes.txt", verbose)

tag("v0.9", verbose)

# Replace the whole contents of fruits.txt
create_or_update_file("fruits.txt",
"""
apples, apricots
bananas
blueberries
cherries
dragon fruits
figs
"""
)
add(["fruits.txt"], verbose)
commit("Update fruits list", verbose)

append_to_file("colours.txt",
"""
blue
red
white
"""
)
add(["colours.txt"], verbose)
commit("colours.txt: Add some colours", verbose)

append_to_file("shapes.txt",
"""
circle
oval
rectangle
square
"""
)
add(["shapes.txt"], verbose)
commit("shapes.txt: Add some shapes", verbose)