Skip to content

Commit

Permalink
Fixed a bug where stubs for 'training' or 'pricing' were imported ins…
Browse files Browse the repository at this point in the history
…tead of stubs for service
  • Loading branch information
Arondondon committed Nov 18, 2024
1 parent b582e83 commit 92475b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions snet/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def create_service_client(self, org_id: str, service_id: str, group_name=None,
lib_generator.generate_client_library()
else:
path_to_pb_files = self.get_path_to_pb_files(org_id, service_id)
pb_2_file_name = find_file_by_keyword(path_to_pb_files, keyword="pb2.py")
pb_2_grpc_file_name = find_file_by_keyword(path_to_pb_files, keyword="pb2_grpc.py")
pb_2_file_name = find_file_by_keyword(path_to_pb_files, keyword="pb2.py", exclude=['training', 'pricing'])
pb_2_grpc_file_name = find_file_by_keyword(path_to_pb_files, keyword="pb2_grpc.py", exclude=['training', 'pricing'])
if not pb_2_file_name or not pb_2_grpc_file_name:
lib_generator.generate_client_library()

Expand Down Expand Up @@ -145,8 +145,10 @@ def get_path_to_pb_files(self, org_id: str, service_id: str) -> str:

def get_module_by_keyword(self, org_id: str, service_id: str, keyword: str) -> ModuleName:
path_to_pb_files = self.get_path_to_pb_files(org_id, service_id)
file_name = find_file_by_keyword(path_to_pb_files, keyword)
file_name = find_file_by_keyword(path_to_pb_files, keyword, exclude=['training', 'pricing'])
# print(f"File name: {file_name}")
module_name = os.path.splitext(file_name)[0]
# print(f"Module name: {module_name}")
return ModuleName(module_name)

def get_service_metadata(self, org_id, service_id):
Expand Down
2 changes: 1 addition & 1 deletion snet/sdk/service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def get_path_to_pb_files(self, org_id: str, service_id: str) -> str:
def get_services_and_messages_info(self):
# Get proto file filepath and open it
path_to_pb_files = self.get_path_to_pb_files(self.org_id, self.service_id)
proto_file_name = find_file_by_keyword(path_to_pb_files, keyword=".proto")
proto_file_name = find_file_by_keyword(path_to_pb_files, keyword=".proto", exclude=['training', 'pricing'])
proto_filepath = os.path.join(path_to_pb_files, proto_file_name)
with open(proto_filepath, 'r') as file:
proto_content = file.read()
Expand Down
6 changes: 4 additions & 2 deletions snet/sdk/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,12 @@ def __exit__(self, exc_type, exc_value, traceback):
pass


def find_file_by_keyword(directory, keyword):
def find_file_by_keyword(directory, keyword, exclude=None):
if exclude is None:
exclude = []
for root, dirs, files in os.walk(directory):
for file in files:
if keyword in file:
if keyword in file and all(e not in file for e in exclude):
return file


Expand Down

0 comments on commit 92475b3

Please sign in to comment.