Git Product home page Git Product logo

azure-cli-dev-tools's Introduction

Microsoft Azure CLI Dev Tools (azdev)

Python Build Status

The azdev tool is designed to aid new and experienced developers in contributing to Azure CLI command modules and extensions.

Getting Started Videos

1. Cloning Repos

2. Setup with azdev setup

3. Basics with azdev style/test/linter

4. Creating modules with azdev cli create

5. Create extensions with azdev extension create

6. Publishing extensions with azdev extension publish

Setting up your development environment

  1. Install Python 3.6/3.7/3.8 from http://python.org. Please note that the version of Python that comes preinstalled on OSX is 2.7. Currently it's not recommended to use Python 3.9.

  2. Fork and clone the repository or repositories you wish to develop for.

    After forking azure-cli, follow the below commands to set up:

    # Clone your forked repository
    git clone https://github.com/<your-github-name>/azure-cli.git
    
    cd azure-cli
    # Add the Azure/azure-cli repository as upstream
    git remote add upstream https://github.com/Azure/azure-cli.git
    git fetch upstream
    # Reset the default dev branch to track dev branch of Azure/azure-cli so you can use it to track the latest azure-cli code.
    git branch dev --set-upstream-to upstream/dev
    # Develop with a new branch
    git checkout -b <feature_branch>

    You can do the same for azure-cli-extensions except that the default branch for it is main, run git branch main --set-upstream-to upstream/main instead.

    See Authenticating with GitHub from Git about caching your GitHub credentials in Git which is needed when you push the code.

  3. Create a new virtual environment for Python in the root of your clone. You can do this by running:

    Python 3.6+ (all platforms):

    python -m venv env

    or

    python3 -m venv env
  4. Activate the env virtual environment by running:

    Windows CMD.exe:

    env\Scripts\activate.bat

    Windows Powershell:

    env\Scripts\activate.ps1
    

    OSX/Linux (bash):

    source env/bin/activate
  5. Prepare and install azdev

    If you're on Linux, install the dependency packages first by running:

    For apt packages:

    sudo apt install gcc python3-dev

    For rpm packages:

    sudo yum install gcc python3-devel 

    Otherwise you will have psutil installation issues (#269) when you setup azure-cli later.

    Upgrade pip on all platforms:

    python -m pip install -U pip
    

    Install azdev:

    pip install azdev
    
  6. Complete setup by running:

    azdev setup
    

    This will launch the interactive setup process. You can also run with non-interactive options:

    azdev setup --cli /path/to/azure-cli --repo /path/to/azure-cli-extensions
    

    To see more non-interactive options, run azdev setup --help.

Authoring commands and tests

If you are building commands based on a REST API SPEC from azure-rest-api-specs, you can leverage aaz-dev-tools to generate the commands. Otherwise you can run the following commands to create a code template:

azdev extension create <extension-name>

or

azdev cli create <module-name>

If you are working on an extension, before you can run its command, you need to install the extension from the source code by running:

azdev extension add <extension-name>

Run az <command> --help with your command groups or commands for a quick check on the command interface and help messages.

For instructions on manually writing the commands and tests, see more in

Style, linter check and testing

  1. Check code style (Pylint and PEP8):

    azdev style <extension-name/module-name>
    
  2. Run static code checks of the CLI command table:

    azdev linter <extension-name/module-name>
    
  3. Record or replay CLI tests:

    azdev test <extension-name/module-name>
    

    By default, test is running in once mode. If there are no corresponding recording files (in yaml format), it will run live tests and generate recording files. If recording files are found, the tests will be run in playback mode against the recording files. You can use --live to force a test run in live mode and regenerate the recording files.

Submitting a pull request to merge the code

  1. After committing your code locally, push it to your forked repository:
    git push --set-upstream origin <feature_branch>
    
  2. Submit a PR to merge from the feature_branch of your repository into the default branch of Azure/azure-cli or Azure/azure-cli-extensions repositories. See Submitting Pull Requests and Publish Extensions for more details.

Reporting issues and feedback

If you encounter any bugs with the tool please file an issue in the Issues section of our GitHub repo.

Contribute Code

This project has adopted the Microsoft Open Source Code of Conduct.

For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

If you would like to become an active contributor to this project please follow the instructions provided in Microsoft Azure Projects Contribution Guidelines.

License

Azure CLI Dev Tools (azdev)

Copyright (c) Microsoft Corporation
All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

azure-cli-dev-tools's People

Contributors

adewaleo avatar allyw avatar arrownj avatar bebound avatar bquantump avatar bragi92 avatar colbylwilliams avatar dciborow avatar evelyn-ys avatar fengzhou-msft avatar jiasli avatar juliehzl avatar kairu-ms avatar marstr avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar mmyyrroonn avatar msftgits avatar necusjz avatar pan-qi avatar qwordy avatar reanaived avatar strawnsc avatar tjprescott avatar wangzelin007 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-cli-dev-tools's Issues

[Test] Expected errors thrown when "expect_failure=True" should not be displayed.

Tests that previously used code like with self.assertRaises(...): would suppress error messages on the principle that any red text displayed during tests should indicate a failure.

These tests, with ScenarioTest, no longer work with this pattern and instead expect a kwarg expect_failure=True. However, these commands do output the failures in red but the test passes.

expect_failure=True should also prevent these error messages from being displayed to adhere to the same principle.

azdev test is not working

(env) C:\Users\limgu\workspace\azure-cli-extensions>azdev test storage-preview --discover --debug
Command arguments: ['test', 'storage-preview', '--discover', '--debug']
Event: Cli.PreExecute []
Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x000001E17026B268>, <function OutputProducer.on_global_arguments at 0x000001E17034C510>, <function CLIQuery.on_global_arguments at 0x000001E1703750D0>]
Event: CommandInvoker.OnPreCommandTableCreate []
Event: CommandLoader.OnLoadCommandTable []
Event: CommandLoader.OnLoadArguments []
Event: CommandInvoker.OnPostCommandTableCreate []
Event: CommandInvoker.OnCommandTableLoaded []
Event: CommandInvoker.OnPreParseArgs []
Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x000001E17034C598>, <function CLIQuery.handle_query_parameter at 0x000001E170375158>]

=============
| Run Tests |

The tests are set to run against current profile latest.

=====================
| Discovering Tests |

Core Modules:

Command Modules:

Extensions: site-packages, storage-preview
No extension found at: C:\Users\limgu\workspace\azure-cli-extensions\env\Lib\site-packages\azext_*
local variable 'filepath' referenced before assignment
Traceback (most recent call last):
File "c:\users\limgu\workspace\azure-cli-extensions\env\lib\site-packages\knack\cli.py", line 206, in invoke
cmd_result = self.invocation.execute(args)
File "c:\users\limgu\workspace\azure-cli-extensions\env\lib\site-packages\knack\invocation.py", line 188, in execute
cmd_result = parsed_args.func(params)
File "c:\users\limgu\workspace\azure-cli-extensions\env\lib\site-packages\knack\commands.py", line 131, in call
return self.handler(*args, **kwargs)
File "c:\users\limgu\workspace\azure-cli-extensions\env\lib\site-packages\knack\commands.py", line 238, in command_handler
result = op(client, **command_args) if client else op(**command_args)
File "c:\users\limgu\workspace\azure-cli-extensions\env\lib\site-packages\azdev\operations\tests_init
.py", line 43, in run_tests
test_index = get_test_index(profile, discover)
File "c:\users\limgu\workspace\azure-cli-extensions\env\lib\site-packages\azdev\operations\tests_init
.py", line 294, in _get_test_index
test_index = discover_tests(profile)
File "c:\users\limgu\workspace\azure-cli-extensions\env\lib\site-packages\azdev\operations\tests_init
.py", line 227, in _discover_tests
import_name = os.path.basename(filepath)
UnboundLocalError: local variable 'filepath' referenced before assignment

My env folder is under workspace/azure-cli-extensions/ not under workspace.

Running multiple specific tests can result in unwanted tests run


Thought this should have been fixed by: Azure/azure-cli#5520
Related: Azure/azure-cli#5519

Specified four tests, every other test in the file/class was run

C:\Users\wilx\azure-cli>

azdev test --test test_storage_file_batch_upload_scenarios test_storage_file_batch_copy test_storage_blob_batch_copy test_storage_file_batch_upload_scenarios
The tests are set to run against current profile latest.

=============
  Run Tests
=============

Modules: storage
Drive test by nosetests
test_storage_blob_batch_copy (azure.cli.command_modules.storage.tests.latest.test_storage_batch_operations.StorageBatchOperationScenarios) ... SKIP: This is a live only test. A live test will bypass all vcrpy components.
test_storage_blob_batch_delete_scenarios (azure.cli.command_modules.storage.tests.latest.test_storage_batch_operations.StorageBatchOperationScenarios) ... SKIP: This is a live only test. A live test will bypass all vcrpy components.
test_storage_blob_batch_download_scenarios (azure.cli.command_modules.storage.tests.latest.test_storage_batch_operations.StorageBatchOperationScenarios) ... SKIP: This is a live only test. A live test will bypass all vcrpy components.
test_storage_blob_batch_upload_scenarios (azure.cli.command_modules.storage.tests.latest.test_storage_batch_operations.StorageBatchOperationScenarios) ... SKIP: This is a live only test. A live test will bypass all vcrpy components.
test_storage_file_batch_copy (azure.cli.command_modules.storage.tests.latest.test_storage_batch_operations.StorageBatchOperationScenarios) ... SKIP: This is a live only test. A live test will bypass all vcrpy components.
test_storage_file_batch_delete_scenarios (azure.cli.command_modules.storage.tests.latest.test_storage_batch_operations.StorageBatchOperationScenarios) ... SKIP: This is a live only test. A live test will bypass all vcrpy components.
test_storage_file_batch_download_scenarios (azure.cli.command_modules.storage.tests.latest.test_storage_batch_operations.StorageBatchOperationScenarios) ... SKIP: This is a live only test. A live test will bypass all vcrpy components.
test_storage_file_batch_upload_scenarios (azure.cli.command_modules.storage.tests.latest.test_storage_batch_operations.StorageBatchOperationScenarios) ... SKIP: This is a live only test. A live test will bypass all vcrpy components.

----------------------------------------------------------------------
Ran 8 tests in 6.549s

OK (SKIP=8)

Environment summary

Install Method (e.g. pip, interactive script, apt-get, Docker, MSI, edge build) / CLI version (az --version) / OS version / Shell Type (e.g. bash, cmd.exe, Bash on Windows)

Support New Linter Rules

On-going issue to track creation of new linter rules

  • examples in help with invalidate argument names
  • name type arguments without completers
  • arguments in creates that have id_part=name and also have a completer
  • arguments that use hard coded choice lists instead of reflecting on enums
  • update commands that have arguments with default values
  • non-standard command names (get, new, etc)
  • update commands that don't have generic update arguments

Azdev doesn't find extensions when extension directory is set

Configure your virtual environment to point to a third-party extension repo:

azdev configure -e azure-iot-cli-extension
azdev extension list -otable

Nothing is displayed, though I would expect it to the list IoT extension. This works if you point to the azure-cli-extensions repo. This likely has to do with the fact that in the extensions repo, the extensions all live at ROOT/src/azext_* but for IoT (and likely others) the extension lives at ROOT/azext_*. We need to ensure the logic to find the path is robust enough for both (and possibly unanticipated) scenarios.

Azdev does not properly install / copy pylintrc config file.

After installing azdev, I ran:

(cli-venv) [03:02 PM] Work-Mac:azure-cli tosin$ azdev setup -c . -r ../azure-cli-extensions/

When I tried to run style checks I get the following:

(cli-venv) [03:23 PM] Work-Mac:azure-cli tosin$ azdev style core

===============
| Style Check |
===============

Modules: core

Running flake8 on modules...
Running pylint on modules...


 Results 
=========


/Users/tosin/Repos/azure-cli/src/azure-cli-core/azure/cli/core/_help_loaders.py:16:23: E261 at least two spaces before inline comment
/Users/tosin/Repos/azure-cli/src/azure-cli-core/azure/cli/core/_help_loaders.py:20:1: E302 expected 2 blank lines, found 1
...
...
/Users/tosin/Repos/azure-cli/src/azure-cli-core/azure/cli/core/tests/test_help.py:455:117: E231 missing whitespace after ':'
/Users/tosin/Repos/azure-cli/src/azure-cli-core/azure/cli/core/tests/test_help.py:459:5: E303 too many blank lines (2)
/Users/tosin/Repos/azure-cli/src/azure-cli-core/azure/cli/core/tests/test_help.py:460:5: E301 expected 1 blank line, found 0
1     E203 whitespace before ':'
6     E231 missing whitespace after ':'
3     E261 at least two spaces before inline comment
2     E301 expected 1 blank line, found 0
3     E302 expected 2 blank lines, found 1
2     E303 too many blank lines (2)
2     W291 trailing whitespace

Flake8: FAILED

Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/site-packages/pylint/__main__.py", line 7, in <module>
    pylint.run_pylint()
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/site-packages/pylint/__init__.py", line 19, in run_pylint
    Run(sys.argv[1:])
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/site-packages/pylint/lint.py", line 1348, in __init__
    linter.read_config_file(verbose=self.verbose)
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/site-packages/pylint/config.py", line 654, in read_config_file
    raise IOError("The config file {:s} doesn't exist!".format(config_file))
OSError: The config file /Users/tosin/.azdev/env_config/Users/tosin/Repos/cli-venv/config_files/cli_pylintrc doesn't exist!

Pylint: FAILED

I got the command to work by doing the following:

(cli-venv) [03:27 PM] Work-Mac:azure-cli tosin$ cp /Users/tosin/Repos/azure-cli-dev-tools/src/azdev/config/cli_pylintrc /Users/tosin/.azdev/env_config/Users/tosin/Repos/cli-venv/config_files/cli_pylintrc

[Test] When no collision <Mod_name>.<name> format for test argument does not work

Describe the bug

(env365) C:\Users\wilx\azure-cli>azdev test azext_storage_preview.test_storage_blob_update_service_properties
The tests are set to run against current profile latest.
C:\Users\wilx\.azure\testIndex_latest.json
Test 'azext_storage_preview.test_storage_blob_update_service_properties' not found.
No tests set to run.

(env365) C:\Users\wilx\azure-cli>azdev test test_storage_blob_update_service_properties
The tests are set to run against current profile latest.
C:\Users\wilx\.azure\testIndex_latest.json

=============
  Run Tests
=============

Expected behavior
Both long and short formats should work for the azdev test tool in this scenario

Environment summary
Windows dev_setup

Additional context
Add any other context about the problem here.

Restore list of failed tests

With recent changes to the testing infrastructure, running the run_tests script no longer provides the final summary of which tests failed. This was very useful and having to now go back and hunt through the logs is frustrating and time consuming.

[Test] Add `--playback-only` option to skip tests that don't have recording files

The current behavior of run_tests --module is to playback all tests that have recordings and record all tests that do not (and are not live only). When I have to re-record networking tests, often there are a few tests that are very slow and block. During that downtime, I would love to replay the tests that have already been re-recorded and identify which, if any, fail to playback. If I do this by running the module, I'll inevitably have two processes trying to record the same test, and nothing good comes of that.

Consider adding a --playback-only flag to run_tests that will only playback tests, and skips any tests that are live_only (obviously) or aren't but don't have a recording file.

...and the summary of which tests fail at the end of the run would be super super super helpful.

Running `azdev test --test` should rebuild index upon seeing new test


This would help developers who are adding new tests, especially if they are not aware that an index of tests are being kept.

Environment summary

Install Method (e.g. pip, interactive script, apt-get, Docker, MSI, edge build) / CLI version (az --version) / OS version / Shell Type (e.g. bash, cmd.exe, Bash on Windows)

verification commands should set exit-status

For example, when running azdev cli check-versions it would be useful if it exited with status '-1' if there are any modules that need to be updated. It would simplify adding these checks in CI.

Valid Example Failing Linter Test

Describe the bug
A clear and concise description of what the bug is.
The following command fails 'faulty_help_example_parameters_rule' in linter.
az batch pool set --account-endpoint https://accountname.location.batch.azure.com --account-name MyAccount --application-package-references app01#1.0 --pool-id mypool

I believe this is because linter code uses shlex.split(command, comment=True) to split the command. Since we pass in comment=True, the part after hash is considered a comment and linter gives an error that the command is missing --pool-id which is a required parameter. Also according to documentation for --application-package-references, app#1.0 is a valid value for the parameter.

To Reproduce
Steps to reproduce the behavior.
Run the above command through the linter.

Expected behavior
A clear and concise description of what you expected to happen.
Linter will fail with the following error:
'''
Help-Entry: batch pool set -
There is a violation:
"az batch pool set --account-endpoint https://accountname.location.batch.azure.com --account-name MyAccount --application-package-references app01#1.0 --pool-id mypool" is not a valid command.
the following arguments are required: --pool-id.
'''
Environment summary
Install Method (e.g. pip, interactive script, apt-get, Docker, MSI, edge build) / CLI version (az --version) / OS version / Shell Type (e.g. bash, cmd.exe, Bash on Windows)

Additional context
Add any other context about the problem here.

[linter] Linter help_rules.py should lint help objects and not help_entries.

[linter] Linter help_rules.py should lint help objects and not help_entries. We will soon support help.yaml alongside help.py. Linter rules should be independent of help_entry type.

Secondly, linter should handle parsing incorrect datetime's or condition values. ie. monitor --start-time and --condition parameter. Should raise appropriate error.

Linter should also validate parameter values to the extent that this is possible / reasonable. E.g. enum values, true false, etc.

azdev extension publish fails

azdev extension publish eventgrid --storage-account {account} --storage-container {container} --storage-subscription {sub} --update-index --debug

======================
| Publish Extensions |
======================


Building WHLs
===============

Building extension 'E:\Prev190201\CLI1000\azure-cli-extensions\src\eventgrid'...

Uploading WHLs
================

Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "e:\prev190201\cli1000\azure-cli-extensions\src\env\lib\site-packages\knack\cli.py", line 206, in invoke
    cmd_result = self.invocation.execute(args)
  File "e:\prev190201\cli1000\azure-cli-extensions\src\env\lib\site-packages\knack\invocation.py", line 188, in execute
    cmd_result = parsed_args.func(params)
  File "e:\prev190201\cli1000\azure-cli-extensions\src\env\lib\site-packages\knack\commands.py", line 131, in __call__
    return self.handler(*args, **kwargs)
  File "e:\prev190201\cli1000\azure-cli-extensions\src\env\lib\site-packages\knack\commands.py", line 238, in _command_handler
    result = op(client, **command_args) if client else op(**command_args)
  File "e:\prev190201\cli1000\azure-cli-extensions\src\env\lib\site-packages\azdev\operations\extensions\__init__.py", line 284, in publish_extensions
    exists = json.loads(cmd(command).result)['exists']
  File "C:\Users\ahamad.NTDEV\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\ahamad.NTDEV\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\ahamad.NTDEV\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I believe the issue lies here:

packages\azdev\operations\extensions_init_.py", line 284, in publish_extensions
exists = json.loads(cmd(command).result)['exists']

There may be a permissions issue with running the exists command.

cc @ahamad-MS

azdev linter fails with ModuleNotFoundError

call to azdev linter fails. I don't mind taking up this issue when I make linter updates. If this isn't high priority.

(cli-venv) [05:23 PM] Work-Mac:azure-cli tosin$ azdev linter -r faulty_help_example_parameters_rule --ci

==============
| CLI Linter |
==============

Initializing linter with command table and help files...

 Results 
=========

No module named 'azdev.operations.linter.rules'
Traceback (most recent call last):
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke
    cmd_result = self.invocation.execute(args)
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/site-packages/knack/invocation.py", line 188, in execute
    cmd_result = parsed_args.func(params)
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/site-packages/knack/commands.py", line 105, in __call__
    return self.handler(*args, **kwargs)
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/site-packages/knack/commands.py", line 212, in _command_handler
    result = op(client, **command_args) if client else op(**command_args)
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/site-packages/azdev/operations/linter/__init__.py", line 100, in run_linter
    ci=ci_mode)
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/site-packages/azdev/operations/linter/linter.py", line 191, in run
    paths = import_module('{}.rules'.format(PACAKGE_NAME)).__path__
  File "/Users/tosin/Repos/cli-venv/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'azdev.operations.linter.rules'
(cli-venv) [05:24 PM] Work-Mac:azure-cli tosin$ 

Extension publish command

Create a command to build and/or publish an extension.

azdev extension build - simply builds the extension
azdev extension publish - builds and uploads the extension to storage (and possibly other locations in the future). Optionally update the index.

This way the flow is simply:

  1. azdev setup -r azure-cli-extensions
  2. Do you extension development
  3. azdev extension publish ...
  4. Open PR!

Expose pip arguments for azdev setup

It would be useful to add options to azdev setup that are the equivalent of pip options --no-cache-dir and --ignore-installed. Currently, there is no way to apply those.

Simplify configuring Dogfood environment

Common ask from service teams.
I think azdev is the best place for this as this is a dev activity, but i am fine with other places, as long as it saves me the time to searching the outlook for the mail threads with all those endpoints :)

//CC @tjprescott

loading help emits out an error

Notes:

  1. Only repro'd if I have used "azdev" to set up everything
  2. Not repro'd if I run regular "python scripts\dev_setup.py"
  3. If there are examples, the help seemingly works fine
(env) C:\sdk\azure-cli>az mysql -h
C:\sdk\azure-cli\env\lib\site-packages\knack\help_files.py:14: YAMLLoadWarning:
  *** Calling yaml.load() without Loader=... is deprecated.
  *** The default Loader is unsafe.
  *** Please read https://msg.pyyaml.org/load for full details.
  return yaml.load(helps[delimiters])

[linter] does not seem to recognize whl extension

(envnew) C:\Users\wilx\azure-cli>az extension list
[
  {
    "extensionType": "whl",
    "name": "aks-preview",
    "version": "0.1.1"
  },
  {
    "extensionType": "whl",
    "name": "db-up",
    "version": "0.1.4"
  },
  {
    "extensionType": "whl",
    "name": "interactive",
    "version": "0.4.1"
  },
  {
    "extensionType": "whl",
    "name": "subscription",
    "version": "0.1.1"
  }
]

(envnew) C:\Users\wilx\azure-cli>azdev linter db-up

==============
| CLI Linter |
==============

unrecognized names: db-up

azdev linter <MODULE> not working

The linter seems to be running on all modules regardless of what I supply.

(env) D:\GitRepos\github>azdev linter redis

==============
| CLI Linter |
==============

Modules: redis

Initializing linter with command table and help files...

 Results
=========

-  pass: faulty_help_example_parameters_rule
-  pass: faulty_help_example_rule
-  pass: faulty_help_type_rule
-  FAIL: unrecognized_help_entry_rule
    Help-Entry: `network application-gateway rewrite-rule condition create` - Not a recognized command or command-group
    Help-Entry: `network application-gateway rewrite-rule condition update` - Not a recognized command or command-group
    Help-Entry: `network application-gateway rewrite-rule create` - Not a recognized command or command-group
    Help-Entry: `network application-gateway rewrite-rule set create` - Not a recognized command or command-group
    Help-Entry: `network application-gateway rewrite-rule set update` - Not a recognized command or command-group
    Help-Entry: `network application-gateway rewrite-rule update` - Not a recognized command or command-group

-  pass: unrecognized_help_parameter_rule
-  pass: expired_command_group
-  pass: missing_group_help
-  pass: expired_command
-  pass: missing_command_help
-  pass: no_ids_for_list_commands
-  pass: bad_short_option
-  pass: expired_option
-  pass: expired_parameter
-  pass: missing_parameter_help

Note that network command violations should not appear!

`azdev setup` should provide/show defaults

When setting up a new environment with azdev setup, you're prompted for a handful of simple questions:

Do you plan to develop CLI modules? (y/n):
Path (RETURN to auto-find):
Do you plan to develop CLI extensions? (y/n):

For the yes/no options, I'd expect that the default answer be capitalized. as: (Y/n) or (y/N)

For the location, I'd expect it to first run auto-find and show me the value that it found for inspection.

Add command to generate module or extension template

azdev create -n foo -t {module|extension}

This command would generate all of the boilerplate code to create a CLI module or extension. This avoids the pitfalls of people trying to copy-paste an existing example or rely on documentation that is out-of-date. The scaffolded files will have examples for how to do common things and we can use this to enforce best practices.

azdev test --profile FOO uses latest index

(env) D:\github>azdev test --profile 2018-03-01-hybrid

=============
| Run Tests |
=============

The tests are set to run against profile 2018-03-01-hybrid but the current az cloud profile is latest.
SWITCHING TO PROFILE 2018-03-01-hybrid.

test index found: C:\Users\trpresco\.azdev\env_config\github\env\test_index\latest.json

An index should be built for this profile and that should be used.

azdev setup Failed with NoneType Error

I followed the instruction for setting up dev env. Everything worked until the last step where I got the below error (running python27):

PS F:\azure-cli\src\azure-cli> azdev setup
Traceback (most recent call last):
File "c:\python27\lib\runpy.py", line 174, in run_module_as_main
"main", fname, loader, pkg_name)
File "c:\python27\lib\runpy.py", line 72, in run_code
exec code in run_globals
File "C:\PYTHON27\SCRIPTS\azdev.exe_main
.py", line 9, in
File "c:\python27\lib\site-packages\azdev_main
.py", line 40, in main
config_dir=get_azdev_config_dir())
File "c:\python27\lib\site-packages\azdev\utilities\config.py", line 24, in get_azdev_config_dir
_, env_name = os.path.splitdrive(get_env_path())
File "c:\python27\lib\ntpath.py", line 115, in splitdrive
if len(p) > 1:
TypeError: object of type 'NoneType' has no len()

Linter Feedback

My initial feedback:

  1. The exclusions file is too verbose. Consider this:
network nic ip-config create:
    parameters:
        private_ip_address_version:
            rule_exclusions:
            - missing_parameter_help_rule
network nic ip-config update:
    parameters:
        private_ip_address_version:
            rule_exclusions:
            - missing_parameter_help_rule
network nsg rule create:
    parameters:
        access:
            rule_exclusions:
            - missing_parameter_help_rule
        direction:
            rule_exclusions:
            - missing_parameter_help_rule
network nsg rule update:
    parameters:
        access:
            rule_exclusions:
            - missing_parameter_help_rule
        direction:
            rule_exclusions:
            - missing_parameter_help_rule

Five lines per exclusion! JSON would be even longer. Consider a custom format, like so:

network nic ip-config create:
  - private_ip_address_version: missing_parameter_help_rule

network nic ip-config update:
  - private_ip_address_version: missing_parameter_help_rule

network nsg rule create:
   - access: missing_parameter_help_rule
   - direction: missing_parameter_help_rule

network nsg rule update: <command/group/help_entry rules here>
    - access: missing_parameter_help_rule
    - direction: missing_parameter_help_rule, <param rules>

This would be much more readable and doesn't require any keywords.

2. Don't print anything if a rule has no violations. A quiet linter is a happy linter.

  1. Consider a --report flag which will output violations by module.

  2. When a rule violation does occur, print the link or an explanation for how the user is expected to fix it.

5. There is a folder commandlint and cli_linter. Are both of these needed?

Environment summary

Install Method (e.g. pip, interactive script, apt-get, Docker, MSI, edge build) / CLI version (az --version) / OS version / Shell Type (e.g. bash, cmd.exe, Bash on Windows)

azure-cli (2.0.31)

acr (2.0.22)
acs (2.0.30)
advisor (0.5.0)
appservice (0.1.31)
backup (1.1.0)
batch (3.2.0)
batchai (0.2.0)
billing (0.1.8)
cdn (0.0.14)
cloud (2.0.12)
cognitiveservices (0.1.11)
configure (2.0.14)
consumption (0.3.0)
container (0.1.21)
core (2.0.31)
cosmosdb (0.1.20)
dev-tools (0.1.1)
dla (0.0.18)
dls (0.0.20)
eventgrid (0.1.11)
eventhubs (0.1.2)
extension (0.0.12)
feedback (2.1.0)
find (0.2.8)
interactive (0.3.19)
iot (0.1.18)
keyvault (2.0.21)
lab (0.0.20)
monitor (0.1.5)
network (2.0.28)
nspkg (3.0.2)
profile (2.0.22)
rdbms (0.2.1)
redis (0.2.11)
reservations (0.1.1)
resource (2.0.27)
role (2.0.21)
servicebus (0.1.2)
servicefabric (0.0.11)
sql (2.0.25)
storage (2.0.31)
testsdk (0.1.1)
vm (2.0.30)

Extensions:
alias (0.3.0)
subscription (0.1.0)

Python location 'c:\Users\trpresco\Documents\github\azure-cli\env\Scripts\python.exe'
Extensions directory 'C:\Users\trpresco\.azure\cliextensions'

Python (Windows) 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)]

`azdev cli check-versions -m` does not work with short module names

(env) D:\GitRepos\github>azdev cli check-versions -m acs

==============================
| Verify CLI Module Versions |
==============================

MODULES: acs
'azure-cli-acs'
Traceback (most recent call last):
  File "d:\gitrepos\github\env\lib\site-packages\knack\cli.py", line 206, in invoke
    cmd_result = self.invocation.execute(args)
  File "d:\gitrepos\github\env\lib\site-packages\knack\invocation.py", line 188, in execute
    cmd_result = parsed_args.func(params)
  File "d:\gitrepos\github\env\lib\site-packages\knack\commands.py", line 131, in __call__
    return self.handler(*args, **kwargs)
  File "d:\gitrepos\github\env\lib\site-packages\knack\commands.py", line 238, in _command_handler
    result = op(client, **command_args) if client else op(**command_args)
  File "d:\gitrepos\github\azure-cli-dev-tools\azdev\operations\pypi.py", line 184, in verify_versions
    results.update(_compare_module_against_pypi(results, temp_dir, mod, mod_path))
  File "d:\gitrepos\github\azure-cli-dev-tools\azdev\operations\pypi.py", line 362, in _compare_module_against_pypi
    results[mod].update({
KeyError: 'azure-cli-acs'

It works if I specify azure-cli-acs

Add ability to spin up a container with a PR's content

We used to have this feature via GitHub but it was removed. It would be great to be able to quickly test a PR's changes with a command like:
azdev preview --pr 1234

This would launch a Docker container and pip install the CLI that incorporates the PR's changes.

[linter] should validate help example option place-holders

After #8083 is merged, work should be done to validate help example parameter placeholders. Parameter placeholders should be surrounded by curly braces and have CamelCase text. The first character can be a capital letter.

Placeholders like:

  • <some value>
  • [some-value]

Should be replaced with:

  • {SomeValue}

Note that values / Placeholders like:

  • somevalue
  • "somevalue"
  • {SomeValue} (only this must be camel-case)
  • $somevar
  • @some_file.txt
  • $(echo foo)

Also update authoring docs with guidelines on authoring command examples.

cc/ @sptramer

Add Tests for Azdev

Azdev lacks a test SDK like Azure CLI. It will require a decent amount of work to add a test layer here as the old azdev commands had no tests.

Once added, running pytest should be added to the tox.ini file.

No CLI Packages Installed After Azdev Setup

Hi,

I was having issues when running azdev setup on Windows. I followed all the steps outlined in the Readme. When I run azdev setup -c , the process takes less than a minute. And when I do a pip freeze later, the output doesn't contain any cli packages.

I am currently running on Windows and using Python 3.6.5.

Please let me know if I should give any other information.

Thanks!

Spandan

storage test run live results in different recording in different python environments


-test_storage_blob_incremental_copy results in a different recording when run in Python2 vs Python3
-the python3 recording fails when played back in python2

Environment summary

Install Method (e.g. pip, interactive script, apt-get, Docker, MSI, edge build) / CLI version (az --version) / OS version / Shell Type (e.g. bash, cmd.exe, Bash on Windows)

Azdev doesn't detect virtual environment when using conda

I installed azdev on a virtual environment on a Windows machine but when I ran azdev setup I get the following output:

F:\workspace>azdev setup -c azure-cli
This command can only be run from an active virtual environment.

I double checked to make sure the environment was activated and the path to the repo that I provided was correct. I tried running pip freeze in the virtual environment and it showed azdev-0.0.2 as installed. I also made sure that azdev wasn't installed outside the virtual environment so that when we ran the command it wasn't getting confused with some other install of azdev.

Our current workaround for this is to use scripts/dev_setup.py instead.

Thanks!

Spandan

Problems with running tests with the `record_only()` decorator live


  • running azdev test --module <module> --live on tests with the record_only() decorator results in just the recordings being deleted; since none of the tests were run, this shouldn't happen.
  • doing the above results in the messages:
    SKIP: This test is excluded from being run live. To force a recording, please remove the recording file.
    This is inconsistent with the behavior since the recordings are deleted and the tests are not run even when the recordings are missing.

Environment summary

Install Method (e.g. pip, interactive script, apt-get, Docker, MSI, edge build) / CLI version (az --version) / OS version / Shell Type (e.g. bash, cmd.exe, Bash on Windows)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.