This is a scaffold project designed to help you practice the concepts learned from the Noah Gift YouTube video.
Follow these steps to set up and use the Python scaffold project:
-
Create a GitHub Repository
- Create a new repository on GitHub.
- Include a
.gitignore
andREADME.md
file when creating the repository.
-
Clone the Repository
- Clone the newly created GitHub repository to your local machine or a cloud-based environment like Cloud9.
-
Create Required Files and Folders
- Using the terminal, navigate to the repository's directory.
- Run the following command to create essential files:
touch Makefile hello.py requirements.txt test_hello.py mkdir data dev notes files notebooks;
-
Create a Virtual Environment
- Create a virtual environment inside the repository using the following commands:
python3 -m venv .venv source ./.venv/bin/activate
- Create a virtual environment inside the repository using the following commands:
-
Edit
requirements.txt
- Open the
requirements.txt
file and add the following Python packages:pylint pytest click black pytest-cov
- Open the
-
Edit
Makefile
-
Open the
Makefile
and add the following commands for various tasks:install: pip install --upgrade pip &&\ pip install -r requirements.txt format: black *.py lint: pylint --disable=R,C hello.py test: python -m pytest -vv --cov=hello test_hello.py all: install lint test
-
-
Edit
hello.py
-
Add the following sample code inside the
hello.py
file:def add(x, y): return x + y # Uncomment and modify the variables as needed # var = result = add(1, 2) print("This is the sum: 1, 2, %s" % result)
-
-
Edit
test_hello.py
-
Add the following code inside the
test_hello.py
file to test thehello.py
code:from hello import add def test_add(): assert add(1, 2) == 3
-
-
Install Dependencies
- In the terminal, run the following command to install the required Python libraries from the
requirements.txt
file:make install
- In the terminal, run the following command to install the required Python libraries from the
-
Code Formatting and Testing [optional]
- To ensure your
hello.py
code is correctly formatted and tested, run the following commands:make format make test
- To ensure your
-
Update Git repo and push changes to git
- Check what changes are made to the repo
git status
- update .gitignore to exclude any not needed files, large files etc
git status
to check the status- looking at the changes needed from the status get the list of items to be added to .gitignore. eg:
ref_*
to ignore any reference repos that were installed
- commit all necessary changes in the repo and push the changes back to the remote repo
git add . git commit "<what are the changes>" git push -u origin main
- Check what changes are made to the repo
Your project directory should have the following structure:
.
├── LICENSE
├── Makefile
├── README.md
├── __pycache__
│ ├── hello.cpython-311.pyc
│ └── test_hello.cpython-311-pytest-7.4.4.pyc
├── hello.py
├── requirements.txt
└── test_hello.py
You've now successfully set up and configured your Python scaffold project. You can start building your Python applications while following best practices for code formatting, linting, and testing.