Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
<!-- Verify that you have linted and formatted your Python code correctly -->

```bash
pip install flake8
flake8 --verbose <folder-name>/app.py
pip install flake8 black
```

```bash
flake8 --verbose *.py

pip install black
black --verbose <folder-name>/app.py
black --verbose --line-length 79 *.py
```
44 changes: 35 additions & 9 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,60 @@
name: Validate Python projects
on:
push:
pull_request:
paths:
- '**.py'
branches:
- main
jobs:
index:
name: Generate matrix of project directories
runs-on: ubuntu-latest
outputs:
projects: ${{ steps.set_output.outputs.matches }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: List directories
run: find -name '*.py' -type 'f' -printf '%h\n' | uniq
- name: Set output
id: set_output
run: echo "matches=$(find -name '*.py' -type 'f' -printf '%h\n' | uniq | jq --null-input --raw-input --compact-output --sort-keys '[inputs|select(length > 0)]')" >> $GITHUB_OUTPUT
validate:
name: Validate Python project
needs: index
runs-on: ubuntu-latest
container: python:3.7
strategy:
matrix:
project-directory:
- ./001-quickstart
- ./002-quickstart-async
- ./003-how-to
- ./004-create-db
- ./005-create-container
project-directory: ${{ fromJson(needs.index.outputs.projects) }}
defaults:
run:
working-directory: ${{ matrix.project-directory }}
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Check Python version
uses: actions/checkout@v4
- name: Output Python version
run: python --version
- name: Install packages
run: pip install black flake8
- name: Lint with flake8
run: flake8 --count --verbose *.py
- name: Check format with black
run: black --check --verbose --line-length 79 *.py
run: black --check --verbose --line-length 79 *.py
summarize:
name: Summarize all validation jobs
needs:
- index
- validate
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: Evaluate status of jobs
if: >-
${{
contains(needs.*.result, 'failure')
|| contains(needs.*.result, 'cancelled')
|| contains(needs.*.result, 'skipped')
}}
run: exit 1
42 changes: 2 additions & 40 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@

## Getting started

This repo has a prebuilt development environment making it easy to get started.
This repo has a [devcontainer](https://containers.dev) environment making it easy to get started.

### Pull the repo

Open the repo in a [development container](https://containers.dev) using either Visual Studio Code or GitHub Codespaces.

- **Visual Studio Code**: Clone this repo to your local machine and open the folder using the [Dev containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).

- **GitHub Codespaces**: Open this repo in the browser with a [GitHub codespace](https://docs.github.com/en/codespaces/overview).
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/Azure-Samples/cosmos-db-nosql-python-samples?quickstart=1)

### Run the app

Expand All @@ -30,26 +24,6 @@ pip install azure-cosmos
python 001-quickstart/app.py
```

The application should output a single JSON object.

```json
{
"id": "70b63682-b93a-4c77-aad2-65501347265f",
"categoryId": "61dba35b-4f02-45c5-b648-c6badc0cbd79",
"categoryName": "gear-surf-surfboards",
"name": "Yamba Surfboard",
"quantity": 12,
"sale": false,
"_rid": "yzN6AIfJxe0BAAAAAAAAAA==",
"_self": "dbs/yzN6AA==/colls/yzN6AIfJxe0=/docs/yzN6AIfJxe0BAAAAAAAAAA==/",
"_etag": "\"2a00ccd4-0000-0200-0000-63650e420000\"",
"_attachments": "attachments/",
"_ts": 16457527130
}
```

> **💡 TIP**: The fields assigned by Azure Cosmos DB (ex. `id`) will vary from this sample output.

### Validate any changes you make

If you change the code, run the linter and code formatter.
Expand All @@ -71,15 +45,3 @@ If you use a self-signed certificate to connect your Cosmos DB instance (Cosmos-
```bash
export REQUESTS_CA_BUNDLE='/etc/ssl/certs/emulatorcert.pem'
```

## Samples

This project contains multiple samples used in [Azure Cosmos DB for NoSQL](https://learn.microsoft.com/azure/cosmos-db/nosql/) documentation.

| Sample | Documentation |
| --- | --- |
| [001-quickstart](001-quickstart/app.py) | [Quickstart: Azure Cosmos DB for NoSQL client library for Python](https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-python?tabs=azure-portal%2Clinux%2Csync) |
| [002-quickstart-async](002-quickstart-async/app.py) | [Quickstart: Azure Cosmos DB for NoSQL client library for Python](https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-python?tabs=azure-portal%2Clinux%2Casync) |
| [[003-how-to](003-how-to/app.py)] | [Get started with Azure Cosmos DB for NoSQL using Python](https://learn.microsoft.com/azure/cosmos-db/nosql/how-to-python-get-started) |
| [[004-create-db](003-how-to/app.py)] | [Create a database in Azure Cosmos DB for NoSQL using Python](https://learn.microsoft.com/azure/cosmos-db/nosql/how-to-python-create-database) |
| [[005-create-container](003-how-to/app.py)] | [Create a container in Azure Cosmos DB for NoSQL using Python](https://learn.microsoft.com/azure/cosmos-db/nosql/how-to-python-create-container) |