Skip to content

Commit c771ec1

Browse files
authored
Add new setup.md document (#37591)
* Add new setup.md document * Fixed broken link in document * Add screenshots * Fixed broken link in document * Fixed broken link in document * Update setup.md * Updated instructions to be more direct
1 parent a88c145 commit c771ec1

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

sdk/cosmos/azure-cosmos/doc/setup.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
This document currently details Python commands for building Azure Cosmos SDK.
2+
3+
### Fork and clone the repository
4+
To build and develop locally, fork and clone the [Azure Cosmos DB SDK repository][cosmos_db_sdk_repo]
5+
6+
### Setup SDK with Pycharm
7+
8+
#### Prerequisites
9+
* [Pycharm][pycharm]
10+
* Azure subscription - [Create a free account][azure_sub]
11+
* Azure [Cosmos DB account][cosmos_account] - SQL API
12+
* [Python 3.6+][python]
13+
14+
#### Add Interpreter
15+
Your Python interpreter might not be the right version(**Python 3.6+**). Change the Python versions in Pycharm.
16+
1. Add local interpreter
17+
18+
![Screenshot 2024-09-11 at 1 28 42 PM](https://github.com/user-attachments/assets/93b0815b-72e7-40ac-b865-c4f00c7627fa)
19+
20+
2. Select the right interpreter version
21+
![Screenshot 2024-09-11 at 1 32 13 PM](https://github.com/user-attachments/assets/a4a881df-6e37-4a09-884c-dcece4daeefd)
22+
23+
#### Install dependent Packages
24+
1. On the bottom left tool bar, go to `Python Packages`
25+
2. Goto `Add Package` > `From Disk`
26+
27+
![Add package 1](https://github.com/user-attachments/assets/915883ff-f4bb-4a0b-94c0-eebeba740dc3)
28+
29+
3. Add Path to dependent packages from disk
30+
* `/<PATH_TO_CLONED_REPO>/azure-sdk-for-python/sdk/cosmos/azure-cosmos`
31+
* azure-core
32+
* azure-cosmos
33+
* `/<PATH_TO_CLONED_REPO>/azure-sdk-for-python/sdk/identity/azure-identity`
34+
* `/<PATH_TO_CLONED_REPO>/azure-sdk-for-python/tools/azure-sdk-tools`
35+
36+
![Add package 2](https://github.com/user-attachments/assets/8c97f03a-8c74-48b5-a194-457815f3260b)
37+
38+
4. Add Path to dependent packages from `PyPl`
39+
* pytest
40+
* pyrebase
41+
* aiohttp
42+
![Pytest install](https://github.com/user-attachments/assets/0c39d706-2c78-4e62-9b0a-9604d088c6f9)
43+
44+
#### Run Cosmos DB Emulator
45+
Azure CosmosDB Emulator is required to run unit tests.
46+
47+
However, the emulator is not ready on MAC OSX yet. Please follow the instructions below to run unit tests on MAC OSX
48+
49+
##### On Windows
50+
1. Download [Azure Cosmos DB emulator][cosmos_db_emulator]
51+
2. Run emulator
52+
53+
##### On MAC
54+
**<u>NOTE:</u>** Unfortunately, Azure Cosmos DB Emulator is not supported on Mac OS. Alternatively, you can manually modify some config variables in `azure-cosmos/test/test_config.py` from your personal Cosmos DB accounts to run unit tests.
55+
56+
**<u>WARNING:</u>** Do not commit your updated `test_config.py`. Always revert the changes before pushing your commit.
57+
58+
1. Open `test_config.py`
59+
2. Replace the default values of `ACCOUNT_KEY` and `ACCOUNT_HOST` to the values from Azure Cosmos DB account(Create new Cosmos DB account if you don't have any)
60+
![test_config](https://github.com/user-attachments/assets/39574123-43bc-48dd-bd85-31097b6625ff)
61+
62+
- `ACCOUNT_KEY`: Primary key from the keys from `Settings` in Azure Cosmos DB account home
63+
![key](https://github.com/user-attachments/assets/145971bc-c28a-4df7-9e88-196fa15254b6)
64+
65+
- `ACCOUNT_HOST`: URI from the overview page of Azure Cosmos DB account
66+
![uri](https://github.com/user-attachments/assets/034a700d-47c7-41ee-90cd-afd534729d37)
67+
68+
3. Update the usage of `credential` in the `setUpClass` in `test_query.py`
69+
- `cls.credential` -> `cls.config.masterKey`
70+
![Screenshot 2024-09-26 at 3 07 40 PM](https://github.com/user-attachments/assets/146cb09e-2123-4784-831b-4e731376ea92)
71+
72+
To run aad tests, follow the steps below to create `RoleAssignment` that uses the `RoleDefinition`
73+
1. Save the following content into a JSON file named `expandedAction.json`
74+
```json
75+
{
76+
"RoleName": "ExpandedRBACActions",
77+
"Type": "CustomRole",
78+
"AssignableScopes": ["/"],
79+
"Permissions": [{
80+
"DataActions": [
81+
"Microsoft.DocumentDB/databaseAccounts/readMetadata",
82+
"Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*",
83+
"Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*"
84+
]
85+
}]
86+
}
87+
```
88+
2. Run the following commands:
89+
- Set account details
90+
- `<subscriptionId>`: Subscription ID to `CosmosDB-SDK-Dev`
91+
- `<resourceGroupName>`: Resource name of your Cosmos DB account
92+
- `<accountName>`: Your Cosmos DB account name
93+
```shell
94+
subscriptionId='<subscriptionId>'
95+
resourceGroupName='<resourceGroupName>'
96+
accountName='<accountName>'
97+
```
98+
99+
- Set subscription
100+
```shell
101+
az account set --subscription $subscriptionId
102+
```
103+
104+
- Create the RoleDefinition
105+
```shell
106+
az cosmosdb sql role definition create --account-name $accountName --resource-group $resourceGroupName --body expandedActions.json
107+
```
108+
109+
- Get the principalId associated with you Azure account. Replace with any other principalId if necessary. You can also get this value from Azure Portal, by visiting the EntraId Users page. It is called 'Object Id' there.
110+
```shell
111+
az ad signed-in-user show --query id -o tsv
112+
```
113+
114+
- Set principalId to a variable
115+
- `<principalId>`: The returned id from the command above
116+
```shell
117+
principalId=<principalId>
118+
```
119+
120+
- Create a RoleAssignment for the principalId that uses the RoleDefinition created above
121+
```shell
122+
az cosmosdb sql role assignment create --account-name $accountName --resource-group $resourceGroupName --role-definition-name "ExpandedRBACActions" --scope "/" --principal-id $principalId
123+
```
124+
#### Run unit tests
125+
The unit tests can be run by right-clicking a specific test file or specific test function in test files
126+
127+
- Run all tests on a test file
128+
![Screenshot 2024-09-26 at 3 08 50 PM](https://github.com/user-attachments/assets/c47760fc-8302-4c52-8826-23c81d13b123)
129+
130+
- Run a single test on a test file
131+
![Screenshot 2024-09-26 at 3 09 38 PM](https://github.com/user-attachments/assets/65d01c13-82b7-4485-9103-fd7b8bde71fb)
132+
133+
<!-- LINKS -->
134+
[cosmos_db_sdk_repo]: https://github.com/Azure/azure-sdk-for-python
135+
[azure_sub]: https://azure.microsoft.com/free/
136+
[cosmos_account]: https://docs.microsoft.com/azure/cosmos-db/account-overview
137+
[python]: https://www.python.org/downloads/
138+
[pycharm]: https://www.jetbrains.com/pycharm/
139+
[cosmos_db_emulator]: https://learn.microsoft.com/azure/cosmos-db/emulator
140+

0 commit comments

Comments
 (0)