Skip to content

Commit 86a0963

Browse files
committed
REF: Rename project_name to project_id
BREAKING CHANGE: Swap the `project_name` argument with `project_id`
1 parent ab2639b commit 86a0963

32 files changed

+131
-132
lines changed

.github/workflows/python-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ jobs:
5858

5959
- name: Run tests
6060
env:
61-
TEST_PROJECT_NAME: ${{ secrets.TEST_PROJECT_NAME }}
62-
GOOGLE_CLOUD_PROJECT: ${{ secrets.TEST_PROJECT_NAME }}
61+
TEST_PROJECT_ID: ${{ secrets.TEST_PROJECT_ID }}
62+
GOOGLE_CLOUD_PROJECT: ${{ secrets.TEST_PROJECT_ID }}
6363
run: tox -vv -e py
6464

6565
- name: Upload coverage to Codecov

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ jobs:
6262

6363
- name: Run tests
6464
env:
65-
TEST_PROJECT_NAME: ${{ secrets.TEST_PROJECT_NAME }}
66-
GOOGLE_CLOUD_PROJECT: ${{ secrets.TEST_PROJECT_NAME }}
65+
TEST_PROJECT_ID: ${{ secrets.TEST_PROJECT_ID }}
66+
GOOGLE_CLOUD_PROJECT: ${{ secrets.TEST_PROJECT_ID }}
6767
run: tox -vv -e py
6868

6969
- name: Upload coverage to Codecov

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Then run the tests to check everything's working.
8686
These environment variables need to be set to run the tests:
8787

8888
- `GOOGLE_APPLICATION_CREDENTIALS=/absolute/path/to/service/account/file.json`
89-
- `TEST_PROJECT_NAME=<name-of-google-cloud-project-to-run-pub-sub-tests-on>`
89+
- `TEST_PROJECT_ID=<id-of-google-cloud-project-to-run-pub-sub-tests-on>`
9090

9191
Then, from the repository root, run
9292

octue/cli.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ def ask():
101101
)
102102
@click.option(
103103
"-p",
104-
"--project-name",
104+
"--project-id",
105105
type=str,
106106
default=None,
107-
help="The name of the Google Cloud project the service is deployed in. If not provided, the project name is "
107+
help="The ID of the Google Cloud project the service is deployed in. If not provided, the project ID is "
108108
"detected from the local Google application credentials if present.",
109109
)
110110
@click.option(
@@ -122,7 +122,7 @@ def ask():
122122
"`OCTUE_SERVICE_CONFIGURATION_PATH` environment variable is used if present, otherwise the local path `octue.yaml` "
123123
"is used.",
124124
)
125-
def remote(sruid, input_values, input_manifest, project_name, asynchronous, service_config):
125+
def remote(sruid, input_values, input_manifest, project_id, asynchronous, service_config):
126126
"""Ask a question to a remote Octue Twined service.
127127
128128
SRUID should be a valid service revision unique identifier for an existing Octue Twined service e.g.
@@ -142,12 +142,12 @@ def remote(sruid, input_values, input_manifest, project_name, asynchronous, serv
142142
if input_manifest:
143143
input_manifest = Manifest.deserialise(input_manifest, from_string=True)
144144

145-
if not project_name:
146-
_, project_name = auth.default()
145+
if not project_id:
146+
_, project_id = auth.default()
147147

148148
child = Child(
149149
id=sruid,
150-
backend={"name": "GCPPubSubBackend", "project_name": project_name},
150+
backend={"name": "GCPPubSubBackend", "project_id": project_id},
151151
service_registries=service_registries,
152152
)
153153

@@ -238,12 +238,12 @@ def local(input_values, input_manifest, attributes, service_config):
238238
backend = service_backends.get_backend(backend_configuration_values.pop("name"))(**backend_configuration_values)
239239
else:
240240
# If no backend details are provided, use Google Pub/Sub with the default project.
241-
_, project_name = auth.default()
242-
backend = service_backends.get_backend()(project_name=project_name)
241+
_, project_id = auth.default()
242+
backend = service_backends.get_backend()(project_id=project_id)
243243

244244
answer = answer_question(
245245
question=question,
246-
project_name=backend.project_name,
246+
project_id=backend.project_id,
247247
service_configuration=service_configuration,
248248
)
249249

@@ -555,11 +555,11 @@ def diagnostics(cloud_path, local_path, download_datasets):
555555
# @click.argument("question_uuid", type=str)
556556
# @click.option(
557557
# "-p",
558-
# "--project-name",
558+
# "--project-id",
559559
# type=str,
560560
# default=None,
561-
# help="If asking a remote question, the name of the Google Cloud project the service is deployed in. If not "
562-
# "provided, the project name is detected from the local Google application credentials if present.",
561+
# help="If asking a remote question, the ID of the Google Cloud project the service is deployed in. If not "
562+
# "provided, the project ID is detected from the local Google application credentials if present.",
563563
# )
564564
# @click.option(
565565
# "-c",
@@ -570,17 +570,17 @@ def diagnostics(cloud_path, local_path, download_datasets):
570570
# "`OCTUE_SERVICE_CONFIGURATION_PATH` environment variable is used if present, otherwise the local path `octue.yaml` "
571571
# "is used.",
572572
# )
573-
# def cancel(question_uuid, project_name, service_config):
573+
# def cancel(question_uuid, project_id, service_config):
574574
# """Cancel a question running on an Octue Twined service.
575575
#
576576
# QUESTION_UUID: The question UUID of a running question
577577
# """
578578
# service_configuration = ServiceConfiguration.from_file(path=service_config)
579579
#
580-
# if not project_name:
581-
# _, project_name = auth.default()
580+
# if not project_id:
581+
# _, project_id = auth.default()
582582
#
583-
# child = Child(id=None, backend={"name": "GCPPubSubBackend", "project_name": project_name})
583+
# child = Child(id=None, backend={"name": "GCPPubSubBackend", "project_id": project_id})
584584
# child.cancel(question_uuid=question_uuid, event_store_table_id=service_configuration.event_store_table_id)
585585

586586

@@ -673,8 +673,8 @@ def start(service_config, revision_tag, timeout, no_rm):
673673
backend = service_backends.get_backend(backend_configuration_values.pop("name"))(**backend_configuration_values)
674674
else:
675675
# If no backend details are provided, use Google Pub/Sub with the default project.
676-
_, project_name = auth.default()
677-
backend = service_backends.get_backend()(project_name=project_name)
676+
_, project_id = auth.default()
677+
backend = service_backends.get_backend()(project_id=project_id)
678678

679679
service = Service(service_id=service_sruid, backend=backend, run_function=run_function)
680680

octue/cloud/emulators/_pub_sub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def __init__(self, request):
469469

470470
def get_pub_sub_resource_name(path):
471471
"""Get the Pub/Sub resource name of the topic or subscription (e.g. "octue.services.<uuid>") from its path (e.g.
472-
"projects/<project-name>/topics/octue.services.<uuid>").
472+
"projects/<project-id>/topics/octue.services.<uuid>").
473473
474474
:param str path:
475475
:return str:

octue/cloud/events/answer_question.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
logger = logging.getLogger(__name__)
99

1010

11-
def answer_question(question, project_name, service_configuration):
11+
def answer_question(question, project_id, service_configuration):
1212
"""Answer a question received by a service.
1313
1414
:param dict question: a question event and its attributes
15-
:param str project_name: the name of the project the service is running on
15+
:param str project_id: the name of the project the service is running on
1616
:param octue.configuration.ServiceConfiguration service_configuration:
1717
:return dict: the result event
1818
"""
1919
service_namespace, service_name, service_revision_tag = get_sruid_parts(service_configuration)
2020
service_sruid = create_sruid(namespace=service_namespace, name=service_name, revision_tag=service_revision_tag)
21-
service = Service(service_id=service_sruid, backend=GCPPubSubBackend(project_name=project_name))
21+
service = Service(service_id=service_sruid, backend=GCPPubSubBackend(project_id=project_id))
2222

2323
runner = Runner.from_configuration(
2424
service_configuration=service_configuration,
25-
project_name=project_name,
25+
project_id=project_id,
2626
service_id=service_sruid,
2727
)
2828

octue/cloud/pub_sub/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def services_topic(self):
107107
:raise octue.exceptions.ServiceNotFound: if the topic doesn't exist in the project
108108
:return octue.cloud.pub_sub.topic.Topic: the Octue services topic for the project
109109
"""
110-
topic = Topic(name=OCTUE_SERVICES_TOPIC_NAME, project_name=self.backend.project_name)
110+
topic = Topic(name=OCTUE_SERVICES_TOPIC_NAME, project_id=self.backend.project_id)
111111

112112
if not topic.exists():
113113
raise octue.exceptions.ServiceNotFound(

octue/cloud/pub_sub/subscription.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class Subscription:
2424
"""A candidate subscription to use with Google Pub/Sub. The subscription represented by an instance of this class
2525
does not necessarily already exist on the Google Pub/Sub servers.
2626
27-
:param str name: the name of the subscription excluding "projects/<project_name>/subscriptions/<namespace>"
27+
:param str name: the name of the subscription excluding "projects/<project_id>/subscriptions/<namespace>"
2828
:param octue.cloud.pub_sub.topic.Topic topic: the topic the subscription is attached to
29-
:param str|None project_name: the name of the Google Cloud project that the subscription belongs to; if `None`, the project name of the topic is used
29+
:param str|None project_id: the ID of the Google Cloud project that the subscription belongs to; if `None`, the project ID of the topic is used
3030
:param str|None filter: if provided, only receive messages matching the filter (see here for filter syntax: https://cloud.google.com/pubsub/docs/subscription-message-filter#filtering_syntax)
3131
:param int ack_deadline: the time in seconds after which, if the subscriber hasn't acknowledged a message, to retry sending it to the subscription
3232
:param int message_retention_duration: unacknowledged message retention time in seconds
@@ -42,7 +42,7 @@ def __init__(
4242
self,
4343
name,
4444
topic,
45-
project_name=None,
45+
project_id=None,
4646
filter=None,
4747
ack_deadline=600,
4848
message_retention_duration=600,
@@ -55,7 +55,7 @@ def __init__(
5555
self.name = name
5656
self.topic = topic
5757
self.filter = filter
58-
self.path = self.generate_subscription_path(project_name or self.topic.project_name, self.name)
58+
self.path = self.generate_subscription_path(project_id or self.topic.project_id, self.name)
5959
self.ack_deadline = ack_deadline
6060
self.message_retention_duration = Duration(seconds=message_retention_duration)
6161

@@ -182,14 +182,14 @@ def exists(self, timeout=5):
182182
return False
183183

184184
@staticmethod
185-
def generate_subscription_path(project_name, subscription_name):
186-
"""Generate a full subscription path in the format `projects/<project_name>/subscriptions/<subscription_name>`.
185+
def generate_subscription_path(project_id, subscription_name):
186+
"""Generate a full subscription path in the format `projects/<project_id>/subscriptions/<subscription_name>`.
187187
188-
:param str project_name:
188+
:param str project_id:
189189
:param str subscription_name:
190190
:return str:
191191
"""
192-
return f"projects/{project_name}/subscriptions/{subscription_name}"
192+
return f"projects/{project_id}/subscriptions/{subscription_name}"
193193

194194
def _create_proto_message_subscription(self):
195195
"""Create a Proto message subscription from the instance to be sent to the Pub/Sub API.

octue/cloud/pub_sub/topic.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ class Topic:
1717
called.
1818
1919
:param str name: the name to give the topic
20-
:param str project_name: the name of the GCP project the topic should exist in
20+
:param str project_id: the name of the GCP project the topic should exist in
2121
:return None:
2222
"""
2323

24-
def __init__(self, name, project_name):
24+
def __init__(self, name, project_id):
2525
self.name = name
26-
self.project_name = project_name
27-
self.path = self.generate_topic_path(self.project_name, self.name)
26+
self.project_id = project_id
27+
self.path = self.generate_topic_path(self.project_id, self.name)
2828
self._created = False
2929

3030
@cached_property
@@ -112,14 +112,14 @@ def exists(self, timeout=10):
112112
return False
113113

114114
@staticmethod
115-
def generate_topic_path(project_name, topic_name):
116-
"""Generate a full topic path in the format `projects/<project_name>/topics/<topic_name>`.
115+
def generate_topic_path(project_id, topic_name):
116+
"""Generate a full topic path in the format `projects/<project_id>/topics/<topic_name>`.
117117
118-
:param str project_name:
118+
:param str project_id:
119119
:param str topic_name:
120120
:return str:
121121
"""
122-
return f"projects/{project_name}/topics/{topic_name}"
122+
return f"projects/{project_id}/topics/{topic_name}"
123123

124124
def _log_creation(self):
125125
"""Log the creation of the topic.

octue/cloud/storage/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ def __init__(self, credentials=OCTUE_MANAGED_CREDENTIALS):
4242
warnings.simplefilter("ignore", category=ResourceWarning)
4343

4444
if credentials == OCTUE_MANAGED_CREDENTIALS:
45-
self.credentials, self.project_name = auth.default()
45+
self.credentials, self.project_id = auth.default()
4646
else:
4747
self.credentials = credentials
4848

49-
self.client = Client(project=self.project_name, credentials=self.credentials)
49+
self.client = Client(project=self.project_id, credentials=self.credentials)
5050

5151
def create_bucket(self, name, location=None, allow_existing=False, timeout=_DEFAULT_TIMEOUT):
5252
"""Create a new bucket. If the bucket already exists, and `allow_existing` is `True`, do nothing; if it is

octue/resources/service_backends.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ class ServiceBackend(ABC):
3939
class GCPPubSubBackend(ServiceBackend):
4040
"""A dataclass containing the details needed to use Google Cloud Pub/Sub as a Service backend.
4141
42-
:param str project_name: the name of the project to use for Pub/Sub
42+
:param str project_id: the name of the project to use for Pub/Sub
4343
:return None:
4444
"""
4545

46-
def __init__(self, project_name):
47-
if project_name is None:
46+
def __init__(self, project_id):
47+
if project_id is None:
4848
raise exceptions.CloudLocationNotSpecified(
49-
"`project_name` must be specified for a service to connect to the correct service - received None."
49+
"`project_id` must be specified for a service to connect to the correct service - received None."
5050
)
5151

52-
self.project_name = project_name
52+
self.project_id = project_id
5353

5454
def __repr__(self):
55-
return f"<{type(self).__name__}(project_name={self.project_name!r})>"
55+
return f"<{type(self).__name__}(project_id={self.project_id!r})>"
5656

5757

5858
AVAILABLE_BACKENDS = {

octue/runner.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Runner:
4646
:param str|None output_location: the path to a cloud directory to save output datasets at
4747
:param bool use_signed_urls_for_output_datasets: if `True`, use signed URLs instead of cloud URIs for dataset paths in the output manifest
4848
:param str|None diagnostics_cloud_path: the path to a cloud directory to store diagnostics (this includes the configuration, input values and manifest, and logs for each question)
49-
:param str|None project_name: name of Google Cloud project to get credentials from
49+
:param str|None project_id: name of Google Cloud project to get credentials from
5050
:param str|None service_id: the ID of the service being run
5151
:param bool delete_local_files: if `True`, delete any files downloaded and registered temporary directories created during an analysis once it's finished
5252
:return None:
@@ -62,7 +62,7 @@ def __init__(
6262
output_location=None,
6363
use_signed_urls_for_output_datasets=False,
6464
diagnostics_cloud_path=None,
65-
project_name=None,
65+
project_id=None,
6666
service_id=None,
6767
service_registries=None,
6868
delete_local_files=False,
@@ -105,14 +105,14 @@ def __init__(
105105
self.service_id = service_id
106106
self.service_registries = service_registries
107107
self.delete_local_files = delete_local_files
108-
self._project_name = project_name
108+
self._project_id = project_id
109109

110110
@classmethod
111-
def from_configuration(cls, service_configuration, project_name=None, service_id=None, **overrides):
111+
def from_configuration(cls, service_configuration, project_id=None, service_id=None, **overrides):
112112
"""Instantiate a runner from a service configuration.
113113
114114
:param octue.configuration.ServiceConfiguration service_configuration:
115-
:param str|None project_name: name of Google Cloud project to get credentials from
115+
:param str|None project_id: name of Google Cloud project to get credentials from
116116
:param str|None service_id: the ID of the service being run
117117
:param overrides: optional keyword arguments to override the `Runner` instantiation parameters extracted from the service configuration
118118
:return octue.runner.Runner: a runner configured with the given service configuration
@@ -126,7 +126,7 @@ def from_configuration(cls, service_configuration, project_name=None, service_id
126126
"output_location": service_configuration.output_location,
127127
"use_signed_urls_for_output_datasets": service_configuration.use_signed_urls_for_output_datasets,
128128
"diagnostics_cloud_path": service_configuration.diagnostics_cloud_path,
129-
"project_name": project_name,
129+
"project_id": project_id,
130130
"service_id": service_id,
131131
"service_registries": service_configuration.service_registries,
132132
"delete_local_files": service_configuration.delete_local_files,
@@ -287,15 +287,15 @@ def _populate_environment_with_google_cloud_secrets(self):
287287
if not missing_credentials:
288288
return
289289

290-
google_cloud_credentials, project_name = auth.default()
290+
google_cloud_credentials, project_id = auth.default()
291291
secrets_client = secretmanager.SecretManagerServiceClient(credentials=google_cloud_credentials)
292292

293293
if google_cloud_credentials is None:
294-
project_name = self._project_name
294+
project_id = self._project_id
295295

296296
for credential in missing_credentials:
297297
secret_path = secrets_client.secret_version_path(
298-
project=project_name,
298+
project=project_id,
299299
secret=credential["name"],
300300
secret_version="latest",
301301
)

octue/templates/template-child-services/elevation_service/octue.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ services:
44
configuration_values:
55
backend:
66
name: "GCPPubSubBackend"
7-
project_name: "octue-sdk-python"
7+
project_id: "octue-sdk-python"

octue/templates/template-child-services/elevation_service/twine.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
"type": "string",
1515
"pattern": "^(GCPPubSubBackend)$"
1616
},
17-
"project_name": {
17+
"project_id": {
1818
"description": "Name of the Google Cloud Platform (GCP) project the service should exist in.",
1919
"type": "string"
2020
}
2121
},
22-
"required": ["name", "project_name"]
22+
"required": ["name", "project_id"]
2323
}
2424
}
2525
},

0 commit comments

Comments
 (0)