-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Upload metadata function for track2 #17082
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
include _meta.json | ||
include *.md | ||
include azure/__init__.py | ||
recursive-include tests *.py |
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
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,154 @@ | ||
import os | ||
import json | ||
import tempfile | ||
import unittest | ||
from pathlib import Path | ||
|
||
import pytest | ||
from packaging_tools.auto_codegen import update_servicemetadata | ||
|
||
|
||
""" | ||
Create metadata file | ||
|
||
Update metadata file | ||
|
||
Update MANIFETS.IN | ||
|
||
No need to update MANIFETS.IN | ||
""" | ||
|
||
MANIFEST_TEMP = """recursive-include tests *.py *.yaml | ||
include *.md | ||
include azure/__init__.py | ||
include azure/mgmt/__init__.py | ||
""" | ||
|
||
class TestServiceMetadata(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.sdk_folder = "sdk" | ||
self.data = { | ||
"specFolder": "../azure-rest-api-specs", | ||
"headSha": "e295fe97eee3709668d3e5f7f8b434026b814ef9", | ||
"headRef": "master", | ||
"repoHttpsUrl": "https://github.com/Azure/azure-rest-api-specs", | ||
} | ||
self.config = { | ||
"meta": { | ||
"autorest_options": { | ||
"version": "3.0.6369", | ||
"use": "@autorest/python@5.4.3", | ||
"python": "", | ||
"python-mode": "update", | ||
"sdkrel:python-sdks-folder": "./sdk/.", | ||
"multiapi": "", | ||
"track2": "" | ||
}, | ||
"advanced_options": { | ||
"create_sdk_pull_requests": True, | ||
"sdk_generation_pull_request_base": "integration_branch" | ||
}, | ||
"repotag": "azure-sdk-for-python-track2", | ||
"version": "0.2.0" | ||
}, | ||
"projects": { | ||
"./azure-rest-api-specs/specification/operationalinsights/resource-manager/readme.md": {} | ||
} | ||
|
||
} | ||
self.folder_name = "monitor" | ||
self.package_name = "azure-mgmt-monitor" | ||
self.spec_folder = "./" | ||
self.input_readme = "azure-rest-api-specs/specification/operationalinsights/resource-manager/readme.md" | ||
|
||
def test_metadata(self): | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
# Init directories | ||
self.sdk_folder = str(Path(temp_dir, "sdk")) | ||
self.spec_folder = str(Path(temp_dir, "spec")) | ||
os.makedirs(self.sdk_folder) | ||
os.makedirs(self.spec_folder) | ||
|
||
readme_file = str(Path(self.spec_folder, self.input_readme)) | ||
self.config["projects"][readme_file] = {} | ||
|
||
package_folder = Path(self.sdk_folder, self.folder_name, self.package_name).expanduser() | ||
metadata_file_path = os.path.join(package_folder, "_meta.json") | ||
manifest_file = os.path.join(package_folder, "MANIFEST.in") | ||
os.makedirs(package_folder) | ||
|
||
# Test MANIFEST.in does not exist | ||
update_servicemetadata( | ||
sdk_folder=self.sdk_folder, | ||
data=self.data, | ||
config=self.config, | ||
folder_name=self.folder_name, | ||
package_name=self.package_name, | ||
spec_folder=self.spec_folder, | ||
input_readme=self.input_readme | ||
) | ||
|
||
assert os.path.isfile(metadata_file_path) == True | ||
# Do not create MANIFEST.in, if it does not exist | ||
assert os.path.isfile(manifest_file) == False | ||
|
||
# Test update metadata | ||
with open(metadata_file_path, "w") as f: | ||
json.dump({"autorest": "3.0.0"}, f, indent=2) | ||
update_servicemetadata( | ||
sdk_folder=self.sdk_folder, | ||
data=self.data, | ||
config=self.config, | ||
folder_name=self.folder_name, | ||
package_name=self.package_name, | ||
spec_folder=self.spec_folder, | ||
input_readme=self.input_readme | ||
) | ||
|
||
assert os.path.isfile(metadata_file_path) == True | ||
assert os.path.isfile(manifest_file) == False | ||
with open(metadata_file_path, "r") as f: | ||
md = json.load(f) | ||
assert md["autorest"] == "3.0.6369" | ||
|
||
# Test update MANIFEST.in | ||
with open(manifest_file, "w") as f: | ||
f.write(MANIFEST_TEMP) | ||
update_servicemetadata( | ||
sdk_folder=self.sdk_folder, | ||
data=self.data, | ||
config=self.config, | ||
folder_name=self.folder_name, | ||
package_name=self.package_name, | ||
spec_folder=self.spec_folder, | ||
input_readme=self.input_readme | ||
) | ||
|
||
assert os.path.isfile(metadata_file_path) == True | ||
assert os.path.isfile(manifest_file) == True | ||
with open(manifest_file, "r") as f: | ||
meta_line = "include _meta.json\n" | ||
line = f.readline() | ||
assert meta_line == line | ||
|
||
# Test update MANIFEST.in again | ||
update_servicemetadata( | ||
sdk_folder=self.sdk_folder, | ||
data=self.data, | ||
config=self.config, | ||
folder_name=self.folder_name, | ||
package_name=self.package_name, | ||
spec_folder=self.spec_folder, | ||
input_readme=self.input_readme | ||
) | ||
|
||
assert os.path.isfile(metadata_file_path) == True | ||
assert os.path.isfile(manifest_file) == True | ||
with open(manifest_file, "r") as f: | ||
meta_line = "include _meta.json\n" | ||
line = f.readline() | ||
second_line = f.readline() | ||
assert meta_line == line | ||
assert meta_line != second_line |
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.
If MANIFEST.in doesn't exit, do we nee create one?
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.
I think we don't need to do it at this script. This file should be created from template. If not, it maybe something wrong when creating this package at first time.