-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: generate selected libraries #2598
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5d4c972
feat: generate selected libraries
JoeWang1127 c0a0a19
add custom option
JoeWang1127 f32e32b
use get_library_name
JoeWang1127 fc128f9
use string with comma
JoeWang1127 81a3edc
change comment
JoeWang1127 4ceb816
add unit tests
JoeWang1127 40dd5bf
add comment
JoeWang1127 2327a61
remove cli
JoeWang1127 a9ba111
Merge branch 'main' into feat/generate-selected-libraries
JoeWang1127 d2f02c6
add comment
JoeWang1127 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import unittest | ||
|
||
from library_generation.generate_repo import get_target_libraries | ||
from library_generation.model.generation_config import GenerationConfig | ||
from library_generation.model.library_config import LibraryConfig | ||
|
||
|
||
class GenerateRepoTest(unittest.TestCase): | ||
def test_get_target_library_returns_selected_libraries(self): | ||
one_library = GenerateRepoTest.__get_an_empty_library_config() | ||
one_library.api_shortname = "one_library" | ||
another_library = GenerateRepoTest.__get_an_empty_library_config() | ||
another_library.api_shortname = "another_library" | ||
config = GenerateRepoTest.__get_an_empty_generation_config() | ||
config.libraries.extend([one_library, another_library]) | ||
target_libraries = get_target_libraries(config, ["another_library"]) | ||
self.assertEqual([another_library], target_libraries) | ||
|
||
def test_get_target_library_given_null_returns_all_libraries(self): | ||
one_library = GenerateRepoTest.__get_an_empty_library_config() | ||
one_library.api_shortname = "one_library" | ||
another_library = GenerateRepoTest.__get_an_empty_library_config() | ||
another_library.api_shortname = "another_library" | ||
config = GenerateRepoTest.__get_an_empty_generation_config() | ||
config.libraries.extend([one_library, another_library]) | ||
target_libraries = get_target_libraries(config) | ||
self.assertEqual([one_library, another_library], target_libraries) | ||
|
||
@staticmethod | ||
def __get_an_empty_generation_config() -> GenerationConfig: | ||
return GenerationConfig( | ||
gapic_generator_version="", | ||
googleapis_commitish="", | ||
synthtool_commitish="", | ||
owlbot_cli_image="", | ||
template_excludes=[], | ||
path_to_yaml="", | ||
libraries=[], | ||
) | ||
|
||
@staticmethod | ||
def __get_an_empty_library_config() -> LibraryConfig: | ||
return LibraryConfig( | ||
api_shortname="", | ||
name_pretty="", | ||
api_description="", | ||
product_documentation="", | ||
gapic_configs=[], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the list is empty? Does it mean we generate nothing or generate everything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generate nothing.
The rational is if we pass a list, then the libraries will be selected from the list. Therefore, an empty list means no generation.
If we don't pass a list, the default value is None and we generate everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SG. Can you mention the behavior in the comment above? I wonder how it is going to be implemented in
generate_repo.py
later, maybe just no-op if the list is empty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adde comments.
It will not call
generate_composed_library.py
but it will do a repo level post processing, which is no-op if no library is changed.