diff --git a/.coveragerc b/.coveragerc index b2ddda4..4fa2401 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,4 @@ [report] omit = */python?.?/* - */site-packages/nose/* *__init__* \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 27c3744..726f872 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,26 +6,9 @@ on: - master jobs: - deploy_docs: - - runs-on: ubuntu-latest - - steps: - - name: Check-out - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Build distribution - run: python setup.py sdist bdist_wheel - - name: Deploy - run: twine upload -r pypi dist/* - env: - TWINE_USERNAME: ${{ secrets.DEPLOY_USER }} - TWINE_PASSWORD: ${{ secrets.DEPLOY_PASSWORD }} + pypi: + name: Pypi + uses: Bernardo-MG/github-workflow/.github/workflows/python_deploy_pypi.yml@v1 + secrets: + username: ${{ secrets.DEPLOY_USER }} + password: ${{ secrets.DEPLOY_PASSWORD }} diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml deleted file mode 100644 index 0d59f74..0000000 --- a/.github/workflows/deploy_docs.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Doc deployment - -on: - push: - branches: - - develop - - master - -jobs: - deploy_docs: - - runs-on: ubuntu-latest - - steps: - - name: Extract branch name - shell: bash - run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - id: extract_branch - - name: Check-out - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Install sshpass - run: sudo apt-get install sshpass - - name: Tests docs - run: python setup.py test -p docs - - name: Build docs - run: python setup.py build_docs - - name: Deploy development docs - if: steps.extract_branch.outputs.branch == 'develop' - run: | - cd ./build/sphinx/html - sshpass -p "${{ secrets.DEPLOY_DOCS_DEVELOP_PASSWORD }}" scp -o 'StrictHostKeyChecking no' -P "${{ secrets.DEPLOY_DOCS_PORT }}" -r ./* "${{ secrets.DEPLOY_DOCS_DEVELOP_USER }}@${{ secrets.DEPLOY_DOCS_HOST }}:${{ secrets.DEPLOY_DOCS_DEVELOP_PATH }}"; - - name: Deploy release docs - if: steps.extract_branch.outputs.branch == 'master' - run: | - cd ./build/sphinx/html - sshpass -p "${{ secrets.DEPLOY_DOCS_PASSWORD }}" scp -o 'StrictHostKeyChecking no' -P "${{ secrets.DEPLOY_DOCS_PORT }}" -r ./* "${{ secrets.DEPLOY_DOCS_USER }}@${{ secrets.DEPLOY_DOCS_HOST }}:${{ secrets.DEPLOY_DOCS_PATH }}"; diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index a3afbe3..95578ec 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -1,26 +1,80 @@ -name: Testing and validation +name: Tests and docs on: [push, pull_request] jobs: - test: + tests: + name: Tests + uses: Bernardo-MG/github-workflow/.github/workflows/python_testing.yml@develop + setup_docs: + name: Doc deployment preparation + needs: tests + outputs: + branchName: ${{ steps.extract_branch.outputs.branchName }} runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + steps: + - name: Install sshpass + run: sudo apt-get install sshpass + - name: Extract branch name + uses: bernardo-mg/extract-branch-name-action@v1 + id: extract_branch + + deploy_docs: + name: Deploy development docs + environment: deployment_site + needs: setup_docs + runs-on: ubuntu-latest + if: ${{ needs.setup_docs.outputs.branchName == 'master' }} + steps: + - name: Check-out + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9 + cache: 'pip' + - name: Update pip + run: python -m pip install --upgrade pip + - name: Install dependencies + run: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Install sshpass + run: sudo apt-get install sshpass + - name: Tests docs + run: python setup.py test -p docs + - name: Build docs + run: python setup.py build_docs + - name: Deploy docs + run: | + cd ./build/sphinx/html + sshpass -p ${{ secrets.DEPLOY_DOCS_PASSWORD }} scp -o StrictHostKeyChecking=no -P ${{ secrets.DEPLOY_DOCS_PORT }} -r ./* ${{ secrets.DEPLOY_DOCS_USER }}'@'${{ secrets.DEPLOY_DOCS_HOST }}':'${{ secrets.DEPLOY_DOCS_PATH }}; + + deploy_develop_docs: + name: Deploy development docs + environment: deployment_site + needs: setup_docs + runs-on: ubuntu-latest + if: ${{ needs.setup_docs.outputs.branchName == 'develop' }} steps: - name: Check-out uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python-version }} + python-version: 3.9 + cache: 'pip' + - name: Update pip + run: python -m pip install --upgrade pip - name: Install dependencies + run: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Install sshpass + run: sudo apt-get install sshpass + - name: Tests docs + run: python setup.py test -p docs + - name: Build docs + run: python setup.py build_docs + - name: Deploy docs run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Run all tests - run: python setup.py test -p py${{ matrix.python-version }} + cd ./build/sphinx/html + sshpass -p ${{ secrets.DEPLOY_DOCS_DEVELOP_PASSWORD }} scp -o StrictHostKeyChecking=no -P ${{ secrets.DEPLOY_DOCS_PORT }} -r ./* ${{ secrets.DEPLOY_DOCS_DEVELOP_USER }}'@'${{ secrets.DEPLOY_DOCS_HOST }}':'${{ secrets.DEPLOY_DOCS_DEVELOP_PATH }}; diff --git a/.gitignore b/.gitignore index 18ffc25..1cef179 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,6 @@ htmlcov/ .tox/ .coverage .cache -nosetests.xml coverage.xml # Translations diff --git a/README.rst b/README.rst index 9c69cb1..63b04fa 100644 --- a/README.rst +++ b/README.rst @@ -19,10 +19,10 @@ operating with it on any Python application. :alt: Dice Notation Tools for Python Pypi package page .. image:: https://img.shields.io/badge/docs-release-blue.svg - :target: http://docs.bernardomg.com/dice-notation-python + :target: https://docs.bernardomg.com/dice-notation-python :alt: Dice Notation Tools for Python latest documentation .. image:: https://img.shields.io/badge/docs-develop-blue.svg - :target: http://docs.bernardomg.com/development/dice-notation-python + :target: https://docs.bernardomg.com/development/dice-notation-python :alt: Dice Notation Tools for Python development documentation Features @@ -146,9 +146,9 @@ License The project has been released under the `MIT License`_. .. _GitHub project page: https://github.com/Bernardo-MG/dice-notation-python -.. _latest docs: http://docs.bernardomg.com/dice-notation-python -.. _development docs: http://docs.bernardomg.com/development/dice-notation-python +.. _latest docs: https://docs.bernardomg.com/dice-notation-python +.. _development docs: https://docs.bernardomg.com/development/dice-notation-python .. _Pypi package: https://pypi.python.org/pypi/dice-notation -.. _MIT License: http://www.opensource.org/licenses/mit-license.php +.. _MIT License: https://opensource.org/licenses/mit-license.php .. _project issues tracker: https://github.com/Bernardo-MG/dice-notation-python/issues -.. _Sphinx: http://sphinx-doc.org/ +.. _Sphinx: https://www.sphinx-doc.org diff --git a/dice_notation/__init__.py b/dice_notation/__init__.py index 5c539a2..64ff6e4 100644 --- a/dice_notation/__init__.py +++ b/dice_notation/__init__.py @@ -7,5 +7,5 @@ :license: MIT, see LICENSE for more details. """ -__version__ = '1.2.0' +__version__ = '1.2.1' __license__ = 'MIT' diff --git a/dice_notation/parser/DiceNotationListener.py b/dice_notation/parser/DiceNotationListener.py index d065ad4..d55f7c5 100644 --- a/dice_notation/parser/DiceNotationListener.py +++ b/dice_notation/parser/DiceNotationListener.py @@ -2,7 +2,7 @@ from antlr4 import * import logging -from dice_notation.dice import Dice +from dice_notation.dice import RollableDice from dice_notation.algebra import BinaryOperation, Number # This class defines a complete listener for a parse tree produced by DiceNotationParser. @@ -125,7 +125,7 @@ def exitDice(self, ctx): sides = int(next(digits).getText()) - dice = Dice(quantity, sides) + dice = RollableDice(quantity, sides) self._nodes.append(dice) diff --git a/docs/source/conf.py b/docs/source/conf.py index bf6115f..d2a4f8f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -93,7 +93,8 @@ html_theme_path = sphinx_docs_theme.get_html_theme_path() # Removes permalink markers -html_add_permalinks = '' +html_permalinks = False +html_permalinks_icon = '' # Theme options. html_theme_options = { diff --git a/requirements.txt b/requirements.txt index 05e3c8b..6b4aabf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,17 +1,17 @@ # Installation and deployment -setuptools==54.2.0 -wheel==0.36.2 -twine==3.4.1 -bernardomg.tox-test-command==1.1.6 -bernardomg.version-extractor==1.0.3 +setuptools==59.6.0 +wheel==0.37.1 +twine==3.8.0 +bernardomg.tox-test-command==1.2.0 +bernardomg.version-extractor==1.1.0 # Testing -tox==3.23.0 +tox==3.24.5 # Documentation -Sphinx==3.5.3 +Sphinx==4.4.0 sphinx-docs-theme==1.0.7 -Pygments==2.8.1 +Pygments==2.11.2 # Parsing -antlr4-python3-runtime==4.7.2 +antlr4-python3-runtime==4.9.3 diff --git a/tests/parser/dice/test_dice_parser_dice_roll.py b/tests/parser/dice/test_dice_parser_dice_roll.py new file mode 100644 index 0000000..b6bf5f8 --- /dev/null +++ b/tests/parser/dice/test_dice_parser_dice_roll.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +import sys +import unittest + +from dice_notation.parser import DiceParser + +""" +Dice parser tests for expressions only containing dice. +""" + +__author__ = 'Bernardo Martínez Garrido' +__license__ = 'MIT' + + +class TestSimpleDice(unittest.TestCase): + """ + Tests that simple dice expressions can be parsed. + """ + + def setUp(self): + """ + Initializes parser. + """ + self.parser = DiceParser() + + def test_minimalDice(self): + """ + Tests that the minimal dice can be rolled. + """ + result = self.parser.parse("1d1").roll() + + self.assertEqual(1, result) diff --git a/tox.ini b/tox.ini index 1214a75..cc7eb26 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{3.6,3.7,3.8,3.9}, + py{3.6,3.7,3.8,3.9,3.10}, check, docs skip_missing_interpreters = @@ -10,9 +10,9 @@ skip_missing_interpreters = # Default environment deps = -r{toxinidir}/requirements.txt - nose + pytest commands = - nosetests + pytest [testenv:check] # Checks code rules