├── tests ├── __init__.py ├── test_cli.py └── test_dice.py ├── pytest.ini ├── mypy.ini ├── .flake8 ├── roll_the_dice ├── __init__.py ├── cli.py └── dice.py ├── docker-compose.yml ├── CHANGELOG.md ├── Dockerfile ├── Makefile ├── pyproject.toml ├── .gitignore ├── README.rst └── LICENSE.md /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | addopts=-v -p no:warnings 3 | -------------------------------------------------------------------------------- /mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | python_version = 3.7 3 | 4 | [mypy-typer.*] 5 | ignore_missing_imports = True 6 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | ignore = W503 3 | max-line-length = 90 4 | max-complexity = 18 5 | select = B,C,E,F,W,T4,B9 6 | -------------------------------------------------------------------------------- /roll_the_dice/__init__.py: -------------------------------------------------------------------------------- 1 | from .dice import roll, roll_from_string 2 | 3 | __version__ = "0.0.1" 4 | __all__ = ["roll", "roll_from_string"] 5 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | roll_the_dice: 5 | build: 6 | context: ./ 7 | volumes: 8 | - ./:/opt/roll-the-dice 9 | command: /bin/bash 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # roll-the-dice changelog 2 | 3 | ## 2020-02-07 4 | 5 | Initial commit of example code for blog post [Python CLI Utilities with Poetry and Typer](https://pluralsight.com/tech-blog/python-cli-utilities-with-poetry-and-typer) 6 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.7 2 | 3 | WORKDIR /opt/roll-the-dice 4 | 5 | # install poetry to container 6 | RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python 7 | ENV PATH /root/.poetry/bin:$PATH 8 | 9 | # build project env 10 | COPY ./pyproject.toml /opt/roll-the-dice/pyproject.toml 11 | RUN poetry install 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build 2 | build: 3 | docker-compose build roll_the_dice 4 | 5 | .PHONY: shell 6 | shell: 7 | docker-compose run --rm roll_the_dice /bin/bash 8 | 9 | .PHONY: test 10 | test: 11 | docker-compose run --rm roll_the_dice poetry run pytest 12 | 13 | .PHONY: lint 14 | lint: 15 | docker-compose run --rm roll_the_dice bash -c "poetry run black roll_the_dice/ && poetry run flake8 roll_the_dice/ && poetry run mypy roll_the_dice/" 16 | 17 | .PHONY: wheel 18 | wheel: 19 | docker-compose run --rm roll_the_dice poetry build -f wheel 20 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "roll-the-dice" 3 | version = "0.0.1" 4 | description = "a roll the dice CLI" 5 | readme = "README.rst" 6 | license = "Apache-2.0" 7 | authors = [ 8 | "John Walk " 9 | ] 10 | repository = "https://github.com/pluralsight/tech-blog-roll-the-dice" 11 | classifiers = [ 12 | "Programming Language :: Python :: 3.7" 13 | ] 14 | 15 | [tool.poetry.dependencies] 16 | python = "^3.7" 17 | typer = "^0.0.8" 18 | 19 | [tool.poetry.dev-dependencies] 20 | pytest = "^5.2" 21 | black = { version = "*", allow-prereleases = true } 22 | flake8 = "*" 23 | mypy = "*" 24 | 25 | [tool.poetry.scripts] 26 | rtd = "roll_the_dice.cli:main" 27 | -------------------------------------------------------------------------------- /tests/test_cli.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | import pytest 4 | import typer 5 | 6 | from roll_the_dice.cli import roll_string, roll_num 7 | 8 | 9 | def test_roll_from_str(capsys): 10 | roller = roll_string(dice_str="2D6", rolls=True) 11 | stdout = capsys.readouterr().out 12 | 13 | regex = re.compile( 14 | r"rolling (\d+D\d+)!\n\nyour roll: (\d+)\n\nmade up of (\[[\d, ]+\])" 15 | ) 16 | 17 | roll_str, total, individuals = re.search(regex, stdout).groups() 18 | assert roll_str == "2D6" 19 | assert int(total) in range(1, 13) 20 | assert individuals 21 | 22 | 23 | def test_roll_bad_str(capsys): 24 | with pytest.raises(typer.Exit) as e: 25 | _ = roll_string(dice_str="foo") 26 | 27 | 28 | def test_roll_num(capsys): 29 | # need to provide these kwargs to override the `typer.Option` fields 30 | roller = roll_num(num_dice=1, sides=20) 31 | stdout = capsys.readouterr().out 32 | 33 | regex = re.compile(r"rolling (\d+D\d+)!\n\nyour roll: (\d+)") 34 | 35 | roll_str, total = re.search(regex, stdout).groups() 36 | assert roll_str == "1D20" 37 | -------------------------------------------------------------------------------- /tests/test_dice.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from roll_the_dice.dice import roll, roll_from_string, parse_dice_string 4 | 5 | 6 | def test_roll(): 7 | dice_rolls, dice_roll = roll(num_dice=1, sides=20) 8 | valid_rolls = range(1, 21) 9 | assert dice_roll in valid_rolls 10 | assert all([r in valid_rolls for r in dice_rolls]) 11 | assert len(dice_rolls) == 1 12 | 13 | 14 | def test_roll_from_string(): 15 | dice_rolls, dice_roll, formatted_str = roll_from_string("1D6") 16 | valid_rolls = range(1, 7) 17 | assert dice_roll in valid_rolls 18 | assert all([r in valid_rolls for r in dice_rolls]) 19 | assert len(dice_rolls) == 1 20 | 21 | 22 | def test_parse_single(): 23 | assert parse_dice_string("D20") == (1, 20) 24 | 25 | 26 | def test_parse_multi(): 27 | assert parse_dice_string("2D6") == (2, 6) 28 | 29 | 30 | def test_parse_more_digits(): 31 | assert parse_dice_string("10D100") == (10, 100) 32 | 33 | 34 | def test_parse_multi_strings(): 35 | assert parse_dice_string("2D6+2D8") == (2, 6) 36 | 37 | 38 | def test_parse_lower(): 39 | assert parse_dice_string("d20") == parse_dice_string("D20") 40 | 41 | 42 | def test_bad_parse(): 43 | with pytest.raises(ValueError): 44 | parse_dice_string("foo") 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | poetry.lock 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .coverage 43 | .coverage.* 44 | .cache 45 | nosetests.xml 46 | coverage.xml 47 | *.cover 48 | .hypothesis/ 49 | .pytest_cache/ 50 | 51 | # Translations 52 | *.mo 53 | *.pot 54 | 55 | # Django stuff: 56 | *.log 57 | local_settings.py 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # dotenv 85 | .env 86 | 87 | # virtualenv 88 | .venv 89 | venv/ 90 | ENV/ 91 | 92 | # Spyder project settings 93 | .spyderproject 94 | .spyproject 95 | 96 | # vs code 97 | .vscode/ 98 | 99 | # Rope project settings 100 | .ropeproject 101 | 102 | # mkdocs documentation 103 | /site 104 | 105 | # mypy 106 | .mypy_cache/ 107 | -------------------------------------------------------------------------------- /roll_the_dice/cli.py: -------------------------------------------------------------------------------- 1 | import typer 2 | 3 | from .dice import roll, roll_from_string 4 | 5 | app = typer.Typer() 6 | 7 | 8 | @app.command("hello") 9 | def hello_world(): 10 | """our first CLI with typer! 11 | """ 12 | typer.echo("Opening blog post...") 13 | typer.launch( 14 | "https://pluralsight.com/tech-blog/python-cli-utilities-with-poetry-and-typer" 15 | ) 16 | 17 | 18 | @app.command("roll-str") 19 | def roll_string( 20 | dice_str: str, 21 | rolls: bool = typer.Option( 22 | False, help="set to display individual rolls", show_default=True 23 | ), 24 | ): 25 | """Rolls the dice from a formatted string. 26 | 27 | We supply a formatted string DICE_STR describing the roll, e.g. '2D6' 28 | for two six-sided dice. 29 | """ 30 | try: 31 | rolls_list, total, formatted_roll = roll_from_string(dice_str) 32 | except ValueError: 33 | typer.echo(f"invalid roll string: {dice_str}") 34 | raise typer.Exit(code=1) 35 | 36 | typer.echo(f"rolling {formatted_roll}!\n") 37 | typer.echo(f"your roll: {total}\n") 38 | if rolls: 39 | typer.echo(f"made up of {rolls_list}\n") 40 | 41 | 42 | @app.command("roll-num") 43 | def roll_num( 44 | num_dice: int = typer.Option( 45 | 1, "-n", "--num-dice", help="number of dice to roll", show_default=True, min=1 46 | ), 47 | sides: int = typer.Option( 48 | 20, "-d", "--sides", help="number-sided dice to roll", show_default=True, min=1 49 | ), 50 | rolls: bool = typer.Option( 51 | False, help="set to display individual rolls", show_default=True 52 | ), 53 | ): 54 | """Rolls the dice from numeric inputs. 55 | 56 | We supply the number and side-count of dice to roll with option arguments. 57 | """ 58 | rolls_list, total = roll(num_dice=num_dice, sides=sides) 59 | 60 | typer.echo(f"rolling {num_dice}D{sides}!\n") 61 | typer.echo(f"your roll: {total}\n") 62 | if rolls: 63 | typer.echo(f"made up of {rolls_list}\n") 64 | 65 | 66 | def main(): 67 | app() 68 | -------------------------------------------------------------------------------- /roll_the_dice/dice.py: -------------------------------------------------------------------------------- 1 | import re 2 | from typing import Tuple, List 3 | import random 4 | 5 | 6 | def roll(num_dice: int = 1, sides: int = 20) -> Tuple[List[int], int]: 7 | """rolls some dice given numeric inputs. 8 | 9 | Args: 10 | num_dice (optional): number of dice to roll. Defaults to 1 for a 11 | single die. 12 | sides (optional): size of die (e.g, 6 for a D6 die). Defaults to 20 13 | rolling a D20. 14 | 15 | Returns: 16 | sorted (descending) list of individual rolls and their total. 17 | """ 18 | rolls = sorted( 19 | [random.choice(range(1, sides + 1)) for _ in range(num_dice)], reverse=True 20 | ) 21 | return (rolls, sum(rolls)) 22 | 23 | 24 | def parse_dice_string(dice_string: str) -> Tuple[int, int]: 25 | """parses formatted string to a dice roll, e.g. "2D6" for rolling two 26 | six-sided dice. 27 | 28 | Args: 29 | dice_string: formatted string for roll. 30 | 31 | Returns: 32 | tuple of the count and sides for the roll. 33 | 34 | Raises: 35 | :py:class:`ValueError`: for bad strings. 36 | """ 37 | hit = re.search(r"(\d*)[dD](\d+)", dice_string) 38 | if not hit: 39 | raise ValueError("bad string") 40 | 41 | count, sides = hit.groups() 42 | count_int = int(count or 1) 43 | sides_int = int(sides) 44 | return (count_int, sides_int) 45 | 46 | 47 | def roll_from_string(dice_string: str) -> Tuple[List[int], int, str]: 48 | """rolls dice from a formatted string, e.g. "2D6" for rolling two six-sided 49 | dice. Allows skipping the count digit for single rolls, e.g. "D20" and 50 | "1D20" returns the same. Will return a cleaned version of the roll s 51 | string along with the results. 52 | 53 | Args: 54 | dice_string: formatted string for roll. 55 | 56 | Returns: 57 | sorted list of dice rolls, their total, and the formatted roll string 58 | 59 | Raises: 60 | :py:class:`ValueError`: for bad string formats 61 | (from :py:func:`~roll_the_dice.dice.parse_dice_string`). 62 | """ 63 | count, sides = parse_dice_string(dice_string) 64 | rolls, total = roll(num_dice=count, sides=sides) 65 | return (rolls, total, f"{count}D{sides}") 66 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | roll-the-dice 2 | ============= 3 | 4 | Generate random dice rolls from numeric inputs or DND Player's Guide-style roll strings (e.g., "2D6" for rolling two six-sided dice). 5 | Example code for a small Python package built with `poetry` and incorporating an entrypoint to a small command line utility built with `typer`. 6 | 7 | Used for the blog post `Python CLI Utilities with Poetry and Typer `_. 8 | 9 | Features 10 | -------- 11 | 12 | * Generate random rolls from numeric inputs or formatted strings 13 | * builds a CLI utility installable via `pip` for dice rolls from the command line 14 | * code formatting with `black`, `flake8` and `mypy` 15 | * Dockerized build environment 16 | 17 | Command-Line Utility 18 | -------------------- 19 | 20 | The package also builds a command-line utility, `rtd`, that can be used directly from the terminal once `pip`-installed (alternately, it can be run within the `poetry` environment with `poetry run rtd [OPTIONS] COMMAND [ARGS]`). 21 | 22 | `rtd roll-str` 23 | ^^^^^^^^^^ 24 | 25 | A command to roll dice from a formatted string. 26 | 27 | .. code-block:: 28 | 29 | Usage: rtd roll-str [OPTIONS] DICE_STR 30 | 31 | Rolls the dice from a formatted string. 32 | 33 | We supply a formatted string DICE_STR describing the roll, e.g. '2D6' for 34 | two six-sided dice. 35 | 36 | Options: 37 | --rolls / --no-rolls set to display individual rolls [default: False] 38 | --help Show this message and exit. 39 | 40 | `rtd roll-num` 41 | ^^^^^^^^^^ 42 | 43 | A command to roll dice from numeric inputs. 44 | 45 | .. code-block:: 46 | 47 | Usage: rtd roll-num [OPTIONS] 48 | 49 | Rolls the dice from numeric inputs. 50 | 51 | We supply the number and side-count of dice to roll with option arguments. 52 | 53 | Options: 54 | -n, --num-dice INTEGER RANGE number of dice to roll [default: 1] 55 | -d, --sides INTEGER RANGE number-sided dice to roll [default: 20] 56 | --rolls / --no-rolls set to display individual rolls [default: 57 | False] 58 | --help Show this message and exit. 59 | 60 | `make` targets 61 | -------------- 62 | 63 | This package includes a `Makefile` for package build tasks in the Dockerized build environment. 64 | To use them, simply run `make ` from the root of the directory: 65 | 66 | ======= =============================================== 67 | target task 68 | ======= =============================================== 69 | `build` builds the Docker environment for the package 70 | `shell` runs BASH shell in the package Docker container 71 | `test` runs `pytest` unit testing 72 | `lint` runs `black`, `flake8`, and `mypy` linting 73 | `wheel` builds a `wheel` file of the package 74 | ======= =============================================== 75 | 76 | License 77 | ------- 78 | 79 | This code is licensed under the `Apache 2.0 license `_. 80 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------