-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Unify README embedme Usage into a Wrapper Script #21859
Changes from 1 commit
e975267
0f2e4bd
b81b85b
f81fae1
29c6526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
# Python version 3.4 or higher is required to run this script. | ||
|
||
# Use case: Invokes embedme README codesnippet generation and validation regardless of OS. | ||
# | ||
# Flags | ||
# --readme/-r: Path to the README. | ||
# --verify/-v: Flag indicating to only perform a dry-run validation. | ||
# --debug/-d: Flag indicating to perform debug level logging. | ||
# | ||
# For example: Generating README codesnippets for Azure Storage Blobs. | ||
# python eng/scripts/invoke_embedme.py -r sdk/storage/azure-storage-blob/README.md | ||
# | ||
# For example: Valdate README codesnippets for Azure Core. | ||
# python eng/scripts/invoke_embedme.py -r sdk/core/azure-core/README.md -v | ||
# | ||
# The script must be run at the root of azure-sdk-for-java. | ||
|
||
import argparse | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
# From this file get to the root path of the repo. | ||
root_path = os.path.normpath(os.path.abspath(__file__) + '/../../../') | ||
alzimmermsft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# NPX command for Windows OS. | ||
windows_command = 'npx.cmd' | ||
alzimmermsft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# NPX command for Posix OSes. | ||
posix_command = 'npx' | ||
|
||
# Invoke embedme. | ||
def invoke_embedme(readme: str, verify: bool, debug: bool): | ||
command = '' | ||
if os.name == 'nt': | ||
command = windows_command | ||
else: | ||
command = posix_command | ||
|
||
command += ' embedme' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you also need to install this command? I must say it is a little odd that we are using maven to call python to call npm lol :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I don't disagree on this oddity of Maven -> Python -> npm. Hopefully as our own tooling mature further these will be simplified into Maven plugins so that everything at least builds into Maven directly. |
||
|
||
# If the passed README path was relative | ||
command += ' ' + os.path.abspath(readme) | ||
|
||
|
||
if verify: | ||
command += ' --verify' | ||
|
||
if debug: | ||
print('Running embedme command: {}'.format(command)) | ||
|
||
sys.exit(os.system(command)) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Invokes embedme README codesnippet generation and validation regardless of OS.') | ||
parser.add_argument('--readme', '-r', type=str, required=True, help='Path to the README') | ||
parser.add_argument('--verify', '-v', action='store_true', help='Flag indicating to only perform a dry-run validation') | ||
parser.add_argument('--debug', '-d', action='store_true', help='Flag indicating to perform debug level logging') | ||
args = parser.parse_args() | ||
|
||
invoke_embedme(args.readme, args.verify, args.debug) | ||
|
||
if __name__ == '__main__': | ||
main() |
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.
nit. You can easily check this on run-time and throw early instead of the undefined-behavior. But not such a big deal.
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.
Or just switch to that directory based on the path of this script.
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.
This is just a standard comment in all the Python scripts used as tooling, I don't think any check the path used either.