Resource mentioned in this lesson: uv
Setting Up a Project
00:00
In order to use OpenCode to implement a feature in a Python project, you need a Python project to work with. So, go ahead and from the downloadable materials, download the rpcontacts project. And once you’ve downloaded it, cd into it.
00:18
The project rpcontacts, or in this case the folder, contains a couple of different files and folders already. So, the files include project configuration, project setup, and the folder src for source contains the source code for a simple TUI, text user interface, that allows you to manage your own contacts.
00:42
Now, this project is managed by uv, as you can tell by the file uv.lock. And in order to run your project with uv, you need to have uv installed, which is why it was mentioned as a prerequisite in the previous lesson. And then you just type uv run rpcontacts.
01:00
Once you do, you give it a second, uv installs the dependencies for your project, and then it opens a terminal user interface, a TUI, that should look like what you can see on the screen.
01:12 Now, by using the green button on the top right, or by using the keyboard shortcut A, you should open a modal dialog that allows you to write a name, the phone number, and the email of a contact.
01:27 Let’s go ahead and fill that with filler data. And then you can navigate with your mouse or with your keyboard. Pressing Tab will allow you to cycle through the different focusable elements and then Enter to confirm your selection. Let’s add one more contact.
01:43 There’s no data validation here, as you can tell, but that’s okay for now. And then what you can try to do is you can try to delete a contact. If you select, for example, the second contact, if you make sure it’s highlighted, and you try pressing the keyboard shortcut D, or the button Delete on the top right, the button does not do anything.
02:07 In the same way, the button Clear All in the bottom right also doesn’t do anything. So the buttons have been added to the interface, but their logic hasn’t been implemented yet.
02:19 And that’s exactly the feature that you’re going to add to this project. You’re going to install and set up OpenCode, and then you’re going to use it to make sure that the buttons of your TUI work correctly.
02:32 Now to quit your TUI, you can press the keyboard shortcut Q.
02:37 You’re presented with a modal dialog to confirm, and you can pick Yes.
02:43
Once you do, you might see some output from uv from when it was trying to run your project. And if you see a warning about the build_system.requires and the uv version, that’s perfectly fine and expected, really. So don’t worry about that.
03:00
So using the command uv run rpcontacts allows you to make sure you can actually run your project. And the final thing you need to do is to set up a Git repository so that you can version control your project.
03:14 And the reason you’re doing that, even if you’re not going to collaborate on this project with anyone else, even if you don’t intend to publish it, is because OpenCode is going to be modifying your code.
03:24
And while coding agents like OpenCode tend to yield good results in projects with the complexity of the project rpcontacts that you’re going to be working with, you can’t tell beforehand what changes the agent will make. So having a version control system in place and being used makes it that much more easy to roll back unwanted or unintended changes.
03:50
So go ahead, run git init at the root of your rpcontacts repository, and then you can check that all of your files right now are not being tracked.
04:02
You can add all of them with git add ., and then you can commit them with git commit -m, and then something like "Starting point".
04:14 And by committing, you’re setting a starting point in your version control history that will allow you to easily roll back any unwanted changes that OpenCode makes later on.
04:25 Once you’ve installed your project, made sure you can run it, tried it out, and initialized your Git repository, you’re free to move on to the next lesson where we’re going to install and set up OpenCode.
Become a Member to join the conversation.