Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
BurtBiel committed Mar 17, 2016
2 parents 7bc62e0 + e39267f commit 0a565a1
Show file tree
Hide file tree
Showing 18 changed files with 324 additions and 84 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ RUN apt-get update -qq && \
jq && \
rm -rf /var/lib/apt/lists/*

RUN pip3 install azure==2.0.0rc1

ENV AZURECLITEMP /opt/azure-cli
ENV PYTHONPATH $PYTHONPATH:$AZURECLITEMP/src
ENV PATH $PATH:$AZURECLITEMP

RUN mkdir -p $AZURECLITEMP
COPY src $AZURECLITEMP/src
COPY az.completion.sh $AZURECLITEMP/
COPY requirements.txt $AZURECLITEMP/
COPY az $AZURECLITEMP/

RUN pip3 install -r $AZURECLITEMP/requirements.txt

RUN chmod +x $AZURECLITEMP/az
RUN ln /usr/bin/python3 /usr/bin/python
RUN echo "source $AZURECLITEMP/az.completion.sh" >> ~/.bashrc
RUN az

ENV EDITOR vim
ENV EDITOR vim
6 changes: 4 additions & 2 deletions Dockerfile-2.7
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ RUN apt-get update -qq && \
vim \
jq && \
rm -rf /var/lib/apt/lists/* && \
pip install azure==2.0.0rc1 && \
pip install --upgrade requests && \
pip install cryptography && \
pip install pyopenssl ndg-httpsclient pyasn1
Expand All @@ -24,10 +23,13 @@ ENV PATH $PATH:$AZURECLITEMP
RUN mkdir -p $AZURECLITEMP
COPY src $AZURECLITEMP/src
COPY az.completion.sh $AZURECLITEMP/
COPY requirements.txt $AZURECLITEMP/
COPY az $AZURECLITEMP/

RUN pip install -r $AZURECLITEMP/requirements.txt

RUN chmod +x $AZURECLITEMP/az
RUN echo "source $AZURECLITEMP/az.completion.sh" >> ~/.bashrc
RUN az

ENV EDITOR vim
ENV EDITOR vim
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include *.rst
exclude src/azure/__init__.py
2 changes: 1 addition & 1 deletion src/README.rst → README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Microsoft Azure Command-Line Tools
==================================

This is the Microsoft Azure Service Bus Runtime Client Library.
This is the Microsoft Azure CLI.

This package has [not] been tested [much] with Python 2.7, 3.4 and 3.5.

Expand Down
10 changes: 10 additions & 0 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<LaunchProvider>Standard Python launcher</LaunchProvider>
<InterpreterId>{1dd9c42b-5980-42ce-a2c3-46d3bf0eede4}</InterpreterId>
<InterpreterVersion>3.5</InterpreterVersion>
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
<CommandLineArguments>vm list-all --query "[*].name"</CommandLineArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
Expand All @@ -32,6 +34,12 @@
<Compile Include="azure\cli\commands\_auto_command.py" />
<Compile Include="azure\cli\commands\_command_creation.py" />
<Compile Include="azure\cli\commands\__init__.py" />
<Compile Include="azure\cli\extensions\experimental.py" />
<Compile Include="azure\cli\extensions\query.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="azure\cli\extensions\transform.py" />
<Compile Include="azure\cli\extensions\__init__.py" />
<Compile Include="azure\cli\main.py" />
<Compile Include="azure\cli\tests\test_argparse.py">
<SubType>Code</SubType>
Expand All @@ -42,6 +50,7 @@
<Compile Include="azure\cli\_debug.py" />
<Compile Include="azure\cli\_help.py" />
<Compile Include="azure\cli\_help_files.py" />
<Compile Include="azure\cli\extensions\_event_dispatcher.py" />
<Compile Include="azure\cli\_locale.py" />
<Compile Include="azure\cli\tests\test_profile.py" />
<Compile Include="azure\cli\_argparse.py" />
Expand All @@ -63,6 +72,7 @@
<Folder Include="azure" />
<Folder Include="azure\cli" />
<Folder Include="azure\cli\commands" />
<Folder Include="azure\cli\extensions\" />
<Folder Include="azure\cli\tests\" />
</ItemGroup>
<ItemGroup>
Expand Down
146 changes: 88 additions & 58 deletions doc/configuring_your_machine.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,105 @@ Setting up your development environment
The Azure Python CLI projects sources are located on GitHub (https://github.com/Azure/azure-cli/). In order to contribute to the project, you are expected to:
- Have a GitHub account. For Microsoft contributors, follow the guidelines on https://opensourcehub.microsoft.com/ to create, configure and link your account
- Fork the https://github.com/Azure/azure-cli/ repository into your private GitHub account
- Create pull requests against the httips://github.com/azure/azure-cli repository to get your code changes merged into the project repository.
- Create pull requests against the https://github.com/azure/azure-cli repository to get your code changes merged into the project repository.

##Docker Setup
If you have not previously done so, configure your Docker client engine [here](https://docs.docker.com/engine/installation/).

Then:
+ Run `docker login` (contact the team for credentials).
+ Run `docker pull azuresdk/azure-cli-python:latest`
+ Run `docker run -i -t azuresdk/azure-cli-python:latest`

##Preparing your machine
+ Install Python 3.5.x from http://python.org. Please note that the version of Python that comes preinstalled on OSX is 2.7.
+ Clone your repository and check out the master branch
+ Create a new virtual environment “env” for Python 3.5 in the root of your clone. You can do this by running:

Windows
```BatchFile
python.exe -m venv <clone root>\env
```
OSX/Ubuntu
```Shell
python –m venv <clone root>/env
```

+ Activate the env virtual environment by running:

Windows:
```BatchFile
<clone root>\env\scripts\activate.bat
```
OSX/Ubuntu (bash):
```Shell
. <clone root>/env/bin/activate
```

+ Install the dependencies including the latest autorest generated azure sdk.
```Shell
pip install -r requirements.txt
```
+ Add <clone root>\src to your PYTHONPATH environment variable:

Windows:
```BatchFile
set PYTHONPATH=<clone root>\src;%PYTHONPATH%
```
OSX/Ubuntu (bash):
```Shell
export PYTHONPATH=<clone root>/src:${PYTHONPATH}
```
+ Hook-up tab completion
Open Bash/zsh window and run
```
source ./az.completion.sh
```
1. Install Python 3.5.x from http://python.org. Please note that the version of Python that comes preinstalled on OSX is 2.7.
2. Clone your repository and check out the master branch.
3. Create a new virtual environment “env” for Python 3.5 in the root of your clone. You can do this by running:

#####Windows
```BatchFile
python -m venv <clone root>\env
```
#####OSX/Ubuntu (bash)
```Shell
python –m venv <clone root>/env
```
4. Activate the env virtual environment by running:

#####Windows
```BatchFile
<clone root>\env\scripts\activate.bat
```
#####OSX/Ubuntu (bash)
```Shell
. <clone root>/env/bin/activate
```

5. Install the dependencies including the latest autorest generated Azure SDK.
```Shell
pip install -r requirements.txt
```
6. Add `<clone root>\src` to your PYTHONPATH environment variable:

#####Windows
```BatchFile
set PYTHONPATH=<clone root>\src;%PYTHONPATH%
```
#####OSX/Ubuntu (bash)
```Shell
export PYTHONPATH=<clone root>/src:${PYTHONPATH}
```
7. Setup tab completion (OSX/Ubuntu ONLY).

Open Bash or zsh window and run:

```Shell
source ./az.completion.sh
```

##Configuring your IDE
###Visual Studio (Windows only)
+ Install Python Tools for Visual Studio. As of 2/18/2016, the current version (PTVS 2.2) can be found here.
+ Open the azure-cli.pyproj project
####Visual Studio (Windows only)
1. Install Python Tools for Visual Studio. As of 2/18/2016, the current version (PTVS 2.2) can be found at http://microsoft.github.io/PTVS/.
2. Open the azure-cli.pyproj project
You should now be able to launch your project by pressing F5/start debugging

###Visual Studio Code (Any platform)
####Visual Studio Code (Any platform)
Experimental steps – still haven’t been able to get virtual environments to work well with VSCode
+ Install VS Code
+ Install (one of) the python extension(s) (https://marketplace.visualstudio.com/items?itemName=donjayamanne.python)

1. Install VS Code
2. Install (one of) the python extension(s) (https://marketplace.visualstudio.com/items?itemName=donjayamanne.python)
Debugging should now work (including stepping and setting breakpoints).

The repo has a launch.json file that will launch the version of Python that is first on your path.

##Running unit tests:

###Command line:
If you have configured your PYTHONPATH correctly (see above), you should be able to run all unit tests by executing python -m unittest from your <clone root>/src directory.
##Running CLI
####Command line
1. Activate your virtual environment if not already done

###VS Code:
<Working on it>
#####Windows:
```BatchFile
<clone root>\env\scripts\activate.bat
```
2. Invoke the CLI using:

###Visual Studio
<Working on it>
#####Windows:
```BatchFile
<clone root>\az.bat [commands]
```
which is equivalent to the following:
```BatchFile
<clone root>\src\python -m azure.cli [commands]
```

##Running Unit Tests:
####Command line
#####Windows:
Provided your PYTHONPATH was set correcltly, from `<clone root>` run:
```BatchFile
python -m unittest discover -s src\azure\cli\tests
```
####VS Code
Under construction...

####Visual Studio
Select `Test > Windows > Test Explorer` and click `Run All` in the Test Explorer pane.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
applicationinsights==0.10.0
azure==2.0.0rc1
jmespath
mock==1.3.0
pylint==1.5.4
pyyaml==3.11
Expand Down
File renamed without changes.
31 changes: 16 additions & 15 deletions src/setup.py → setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# If we have source, validate that our version numbers match
# This should prevent uploading releases with mismatched versions.
try:
with open('azure/cli/__init__.py', 'r', encoding='utf-8') as f:
with open('src/azure/cli/__init__.py', 'r', encoding='utf-8') as f:
content = f.read()
except OSError:
pass
Expand All @@ -42,6 +42,8 @@
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
CLASSIFIERS = [
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
Expand All @@ -52,19 +54,11 @@
#'License :: OSI Approved :: MIT License',
]

# The azure-mgmt requirement should always be pinned to ensure
# that installing a specific azure-cli version will target the
# expected Azure API versions
#
# Alternatively, the more specific requirements such as
# azure-mgmt-resource may be specified in place of the roll-up
# packages.
#
# Common azure package dependencies will be pulled in by these
# references, so do not specify azure-common or -nspkg here.
DEPENDENCIES = [
'azure-mgmt==0.20.2',
'azure-storage==0.20.3',
'applicationinsights',
'azure==2.0.0rc1',
'six',
'jmespath',
]

with open('README.rst', 'r', encoding='utf-8') as f:
Expand All @@ -77,13 +71,20 @@
long_description=README,
license='TBD',
author='Microsoft Corporation',
author_email='SOMEBODY@microsoft.com',
author_email='azpycli@microsoft.com',
url='https://github.com/Azure/azure-cli',
classifiers=CLASSIFIERS,
zip_safe=False,
scripts=[
'az',
'az.completion.sh',
'az.bat',
],
package_dir = {'':'src'},
packages=[
'azure.cli',
'azure.cli.commands',
'azure.cli.extensions',
],
package_data={'azure.cli': ['locale/**/*.txt']},
install_requires=DEPENDENCIES,
)
2 changes: 0 additions & 2 deletions src/MANIFEST.in

This file was deleted.

22 changes: 21 additions & 1 deletion src/azure/cli/_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ._locale import L
from ._logging import logger
from ._output import OutputProducer
from azure.cli.extensions import event_dispatcher

# Named arguments are prefixed with one of these strings
ARG_PREFIXES = sorted(('-', '--', '/'), key=len, reverse=True)
Expand Down Expand Up @@ -74,6 +75,11 @@ def __init__(self, prog):
self.complete_args = {'--complete'}
self.global_args = {'--verbose', '--debug'}

def add_global_param(self, spec, desc):
# TODO: Keep track of all global args to allow help
# and statement completion to pick them up
pass

def add_command(self,
handler,
name=None,
Expand Down Expand Up @@ -279,7 +285,21 @@ def _execute(self, m, out, handler, parsed, others, output_format): #pylint: dis
old_stdout = sys.stdout
try:
sys.stdout = out
return ArgumentParserResult(handler(parsed, others), output_format)
event_data = {
'handler': handler,
'command_metadata': m,
'args': parsed,
'unexpected': others
}

# Let any event handlers that want to modify/munge the parameters do so...
event_dispatcher.raise_event(event_dispatcher.PARSING_PARAMETERS, event_data)

# Let any event handlers that want to know that we are about to execute do their
# thing...
event_dispatcher.raise_event(event_dispatcher.EXECUTING_COMMAND, event_data)

return ArgumentParserResult(event_data['handler'](parsed, others), output_format)
except IncorrectUsageError as ex:
print(str(ex), file=out)
return ArgumentParserResult(self._display_usage(m, out))
Expand Down
Loading

0 comments on commit 0a565a1

Please sign in to comment.