Working with Codespaces
Getting Started with Python on Codespaces
1. Launching a Codespace
Navigate to the GitHub repository.
Click on the green Code button, and select Codespaces.
If a Codespace environment isn’t set up yet, click Create codespace on main.
This will initialize a cloud-based development environment pre-configured for this repository.
2. Initializing the Environment
Once the Codespace is launched:
- Verify Python Version:
- Open the terminal in Codespaces and run:
python3 --version
- Ensure it outputs Python 3.x. If not, install Python 3 using:
sudo apt-get install python3
- Install Dependencies:
- Install the required Python packages listed in
requirements.txt
:
pip install -r requirements.txt
- Verify the Installation:
- Run
pip freeze
to confirm that the dependencies are installed.
3. Running Python Code
- Running the Application:
- The main script seems to be
ds.py
. You can run it with:
python3 ds.py
- Running Tests:
The test file
test_ds.py
is located in the root directory.Run tests using
unittest
:
python3 -m unittest test_ds.py
- Alternatively, if
pytest
is installed:
pytest test_ds.py
- Linting Code:
- Use
pylint
to check the quality ofds.py
:
pylint ds.py
4. Editing Files
- Editing the Code:
Open files (like
ds.py
ortest_ds.py
) using the built-in VS Code editor in Codespaces.Make your edits and save.
- Adding New Files:
- To add new scripts or test files, right-click in the file explorer panel, and select New File.
5. Debugging
Set up breakpoints by clicking in the gutter (left margin) of your code editor.
Use the Debug panel to start a debugging session.
6. Committing Changes
- Stage and Commit Changes:
- Stage your changes:
git add .
- Commit the changes:
git commit -m "Your commit message"
- Push Changes to GitHub:
- Push your changes to the repository:
git push origin main
7. Closing and Reopening Codespaces
When finished, click Stop Codespace to save resources.
To reopen, return to the Codespaces tab in GitHub and select your environment.
Common Commands Summary
Task | Command |
---|---|
Run linting | pylint ds.py |
Install dependencies | pip install -r requirements.txt |
Stage changes | git add . |
Commit changes | git commit -m "Your commit message" |
Push changes | git push origin main |
This guide ensures you’re set up to write, test, and manage Python code effectively in GitHub Codespaces!