mkdir example-lab
cd example-lab
touch README.md
python3 -m venv .venv
python3 with more specific version as needed.Mac/Linux
source .venv/bin/activate
Windows
source .venv/Scripts/activate
mkdir example_lab
touch example_lab/example_script.py
Note the underscore vs hyphen
For example:
pip install favorite-library
pip freeze > requirements.txt
Should result in this file tree:
└── example-lab
├── README.md
├── requirements.txt
└── example_lab
└── example_script.py
Many labs will require automated testing. If your lab requires it then install pytest or pytest-watch.
pip install pytest# or pytest-watch
pip freeze > requirements.txt
touch tests/__init__.py(Note: 2 underscores on both sides.)
touch tests/test_example.py
Should result in a file tree like this:
└── example-lab
├── README.md
├── requirements.txt
├── example_lab
│ └── example_script.py
└── tests
├── __init__.py
└── test_example.py
Initialize local Git repository
git init
touch .gitignore
.venv folder to .gitignoregit add .
git commit -m “first commit”
example-lab on Github. Do NOT initialize with README, license or gitignore.
git remote add origin the_url_you_copied_that_ends_with_git
git push -u origin main
Now everything is wired up between local machine and Github.
This step is optional early in course. Instructor will inform you when it is required.
Setup “Github Actions” so that your code can be properly tested in Github as you make new pushes to your branches and pull requests to master
Github will now run all of your automated tests and check formatting every time you push code to a branch or try to merge a pull request. In fact, it will block pull requests until your tests are all passing.
name: Run Python Tests
on:
push:
branches:
- main
paths:
- 'python/**'
pull_request:
branches:
- main
paths:
- 'python/**'
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
working-directory: ./python
- name: Test with pytest
run: pytest -vv
working-directory: ./python