Skip to content

Commit e3e8135

Browse files
author
Yalin Li
authored
Update comments in samples and its refernces in docstrings (Azure#22776)
1 parent 830ccf6 commit e3e8135

13 files changed

+25
-42
lines changed

sdk/containerregistry/azure-containerregistry/azure/containerregistry/_container_registry_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, endpoint, credential=None, **kwargs):
4545
4646
.. admonition:: Example:
4747
48-
.. literalinclude:: ../samples/sample_create_client.py
48+
.. literalinclude:: ../samples/sample_hello_world.py
4949
:start-after: [START create_registry_client]
5050
:end-before: [END create_registry_client]
5151
:language: python
@@ -89,7 +89,7 @@ def delete_repository(self, repository, **kwargs):
8989
9090
.. admonition:: Example:
9191
92-
.. literalinclude:: ../samples/sample_create_client.py
92+
.. literalinclude:: ../samples/sample_hello_world.py
9393
:start-after: [START delete_repository]
9494
:end-before: [END delete_repository]
9595
:language: python
@@ -111,7 +111,7 @@ def list_repository_names(self, **kwargs):
111111
112112
.. admonition:: Example:
113113
114-
.. literalinclude:: ../samples/sample_delete_old_tags.py
114+
.. literalinclude:: ../samples/sample_delete_tags.py
115115
:start-after: [START list_repository_names]
116116
:end-before: [END list_repository_names]
117117
:language: python

sdk/containerregistry/azure-containerregistry/azure/containerregistry/aio/_async_container_registry_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(
4747
4848
.. admonition:: Example:
4949
50-
.. literalinclude:: ../samples/async_samples/sample_create_client_async.py
50+
.. literalinclude:: ../samples/async_samples/sample_hello_world_async.py
5151
:start-after: [START create_registry_client]
5252
:end-before: [END create_registry_client]
5353
:language: python
@@ -86,7 +86,7 @@ async def delete_repository(self, repository: str, **kwargs: Any) -> None:
8686
8787
.. admonition:: Example:
8888
89-
.. literalinclude:: ../samples/async_samples/sample_create_client_async.py
89+
.. literalinclude:: ../samples/async_samples/sample_hello_world_async.py
9090
:start-after: [START delete_repository]
9191
:end-before: [END delete_repository]
9292
:language: python
@@ -107,7 +107,7 @@ def list_repository_names(self, **kwargs: Any) -> AsyncItemPaged[str]:
107107
108108
.. admonition:: Example:
109109
110-
.. literalinclude:: ../samples/async_samples/sample_delete_old_tags_async.py
110+
.. literalinclude:: ../samples/async_samples/sample_delete_tags_async.py
111111
:start-after: [START list_repository_names]
112112
:end-before: [END list_repository_names]
113113
:language: python

sdk/containerregistry/azure-containerregistry/samples/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ The async versions of the samples require Python 3.6 or later.
1717
|**File Name**|**Description**|
1818
|-------------|---------------|
1919
|[sample_hello_world.py][hello_world] ([sample_hello_world_async.py][hello_world_async]) |Instantiate a `ContainerRegistryClient` object and iterating through the collection of tags in the repository with anonymous access |
20-
|[sample_delete_tags.py][delete_tags] and [sample_delete_tags_async.py][delete_tags_async] | Delete tags from a repository |
21-
|[sample_delete_images.py][delete_images] and [sample_delete_images_async.py][delete_images_async] | Delete images from a repository |
22-
|[sample_set_image_properties.py][set_image_properties] and [sample_set_image_properties_async.py][set_image_properties_async] | Set read/write/delete properties on an image |
23-
|[sample_list_tags.py][list_tags] and [sample_list_tags_async.py][list_tags_async] | List tags on an image using an anonymous access |
20+
|[sample_delete_tags.py][delete_tags] ([sample_delete_tags_async.py][delete_tags_async]) | Delete tags from a repository |
21+
|[sample_delete_images.py][delete_images] ([sample_delete_images_async.py][delete_images_async]) | Delete images from a repository |
22+
|[sample_set_image_properties.py][set_image_properties] ([sample_set_image_properties_async.py][set_image_properties_async]) | Set read/write/delete properties on an image |
23+
|[sample_list_tags.py][list_tags] ([sample_list_tags_async.py][list_tags_async]) | List tags on an image with anonymous access |
2424

2525
### Prerequisites
2626
* Python 3.6 or later is required to use this package.

sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_delete_images_async.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self):
3333
load_dotenv(find_dotenv())
3434

3535
async def delete_images(self):
36-
# [START list_repository_names]
36+
# Instantiate an instance of ContainerRegistryClient
3737
audience = "https://management.azure.com"
3838
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
3939
credential = DefaultAzureCredential()
@@ -42,16 +42,13 @@ async def delete_images(self):
4242
async with client:
4343
async for repository in client.list_repository_names():
4444
print(repository)
45-
# [END list_repository_names]
4645

47-
# [START list_manifest_properties]
4846
# Keep the three most recent images, delete everything else
4947
manifest_count = 0
5048
async for manifest in client.list_manifest_properties(repository, order_by=ArtifactManifestOrder.LAST_UPDATED_ON_DESCENDING):
5149
manifest_count += 1
5250
if manifest_count > 3:
5351
await client.delete_manifest(repository, manifest.digest)
54-
# [END list_manifest_properties]
5552

5653

5754
async def main():

sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_delete_tags_async.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ async def delete_tags(self):
4444
print(repository)
4545
# [END list_repository_names]
4646

47-
# [START list_tag_properties]
4847
# Keep the three most recent tags, delete everything else
4948
tag_count = 0
5049
async for tag in client.list_tag_properties(repository, order_by=ArtifactTagOrder.LAST_UPDATED_ON_DESCENDING):
5150
tag_count += 1
5251
if tag_count > 3:
5352
await client.delete_tag(repository, tag.name)
54-
# [END list_tag_properties]
5553

5654

5755
async def main():

sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_hello_world_async.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,17 @@
2828
from azure.identity.aio import DefaultAzureCredential
2929

3030

31-
class CreateClientsAsync(object):
31+
class HelloWorldAsync(object):
3232
def __init__(self):
3333
load_dotenv(find_dotenv())
3434

35-
async def create_registry_client(self):
36-
# Instantiate the ContainerRegistryClient
35+
async def basic_sample(self):
36+
# Instantiate an instance of ContainerRegistryClient
3737
# [START create_registry_client]
3838
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
3939
audience = "https://management.azure.com"
4040
client = ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience=audience)
4141
# [END create_registry_client]
42-
43-
async def basic_sample(self):
44-
# Instantiate the client
45-
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
46-
audience = "https://management.azure.com"
47-
client = ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience=audience)
4842
async with client:
4943
# Iterate through all the repositories
5044
async for repository_name in client.list_repository_names():
@@ -59,8 +53,7 @@ async def basic_sample(self):
5953

6054

6155
async def main():
62-
sample = CreateClientsAsync()
63-
await sample.create_registry_client()
56+
sample = HelloWorldAsync()
6457
await sample.basic_sample()
6558

6659

sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_list_tags_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ def __init__(self):
3636
load_dotenv(find_dotenv())
3737

3838
async def list_tags(self):
39-
# Create a new ContainerRegistryClient
39+
# Instantiate an instance of ContainerRegistryClient
4040
audience = "https://management.azure.com"
4141
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
4242
credential = DefaultAzureCredential()
4343
client = ContainerRegistryClient(endpoint, credential, audience=audience)
4444

4545
manifest = await client.get_manifest_properties("library/hello-world", "latest")
4646
print(manifest.repository_name + ": ")
47+
# Iterate through all the tags
4748
for tag in manifest.tags:
4849
print(tag + "\n")
4950

sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_set_image_properties_async.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,19 @@ def __init__(self):
3535
load_dotenv(find_dotenv())
3636

3737
async def set_image_properties(self):
38-
# Create a new ContainerRegistryClient
38+
# Instantiate an instance of ContainerRegistryClient
3939
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
4040
audience = "https://management.azure.com"
4141
credential = DefaultAzureCredential()
4242
client = ContainerRegistryClient(endpoint, credential, audience=audience)
4343

44-
# [START update_manifest_properties]
4544
# Set permissions on the v1 image's "latest" tag
4645
await client.update_manifest_properties(
4746
"library/hello-world",
4847
"latest",
4948
can_write=False,
5049
can_delete=False
5150
)
52-
# [END update_manifest_properties]
5351
# After this update, if someone were to push an update to "myacr.azurecr.io\hello-world:v1", it would fail.
5452
# It's worth noting that if this image also had another tag, such as "latest", and that tag did not have
5553
# permissions set to prevent reads or deletes, the image could still be overwritten. For example,

sdk/containerregistry/azure-containerregistry/samples/sample_delete_images.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ def __init__(self):
3030
load_dotenv(find_dotenv())
3131

3232
def delete_images(self):
33-
# [START list_repository_names]
33+
# Instantiate an instance of ContainerRegistryClient
3434
audience = "https://management.azure.com"
3535
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
3636

3737
with ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience=audience) as client:
3838
for repository in client.list_repository_names():
3939
print(repository)
40-
# [END list_repository_names]
4140

42-
# [START list_manifest_properties]
4341
# Keep the three most recent images, delete everything else
4442
manifest_count = 0
4543
for manifest in client.list_manifest_properties(
@@ -48,7 +46,6 @@ def delete_images(self):
4846
if manifest_count > 3:
4947
print("Deleting {}:{}".format(repository, manifest.digest))
5048
client.delete_manifest(repository, manifest.digest)
51-
# [END list_manifest_properties]
5249

5350

5451
if __name__ == "__main__":

sdk/containerregistry/azure-containerregistry/samples/sample_delete_tags.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ def delete_tags(self):
4040
print(repository)
4141
# [END list_repository_names]
4242

43-
# [START list_tag_properties]
4443
# Keep the three most recent tags, delete everything else
4544
tag_count = 0
4645
for tag in client.list_tag_properties(repository, order_by=ArtifactTagOrder.LAST_UPDATED_ON_DESCENDING):
4746
tag_count += 1
4847
if tag_count > 3:
4948
print("Deleting {}:{}".format(repository, tag.name))
5049
client.delete_tag(repository, tag.name)
51-
# [END list_tag_properties]
5250

5351

5452
if __name__ == "__main__":

0 commit comments

Comments
 (0)