UGRC's default Python project configuration/template
- Create new environment for the project
- With python 3 (without arcpy)
python -m venv .env- activate the environment
source .env/bin/activate
- With conda
conda create --name PROJECT_NAME python=3.11
- With python 3 (without arcpy)
- Rename
src/projectnamefolder to your desired project name - Edit the
setup.py:name, url, project_urls, keywords, and entry_pointsto reflect your new project name - Edit the
pyproject.toml --cov=projectnameto reflect your new project name - Edit the
test_projectname.pyto match your project name.- You will have one
test_filename.pyfile for each file in yoursrcdirectory and you will write tests for the specific file in thetest_filename.pyfile - If you are using arcpy, you should mock out the arcpy module in any test that directly imports arcpy or tests any of your code that imports arcpy. Add
import mock_arcpyto the imports in your test file before importing arcpy or any of your modules that you're testing. This effectively replaces all of arcpy in the test environment with a Mock object; you can then create customreturn_values andside_effectsfor whatever functions you need, and the tests will run appropriately in GitHub Actions (which doesn't have arcpy installed).
- You will have one
- Set up Codecov to create coverage reports from GitHub Actions:
- Navigate to codecov.io, logging in with your GitHub account if necessary.
- Select your new repo and and copy the Upload Token.
- Create a new repository secret (github repository Settings -> Secrets -> Actions secrets -> New repository secret) named
CODECOV_TOKENand paste the Upload Token as the Value
- Install an editable package for development
pip install -e ".[tests]"- Add any project requirements to the
setup.py:install_requiresarray - If you specify
arcgisversion 2.0.0 or greater, uncomment the section in.github/workflows/ci.ymlso that GitHub Actions installs the necessary dependencies.
- Run the tests
- VSCode ->
Python: Run All TestsorPython: Debug All Tests ptw- Pytest Watch will restart the tests every time you save a file
- VSCode ->
- Bring your test code coverage to 80% or above!
- Replace the title of this markdown file with your project name
- Replace
pythonin the badge links at the top of this page with your new repository name