diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a784718 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,51 @@ +name: Run Tests +on: + - push + - pull_request +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 15 + defaults: + run: + shell: bash -l {0} + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Set up Conda + uses: conda-incubator/setup-miniconda@v2 + with: + python-version: "3.8" + - name: Install dependencies and package + run: pip install -e . mypy + - name: Minimal test, --help should work + run: ctc-segmenter --help + - name: Code quality test, mypy should pass + run: mypy aligner + - name: Make sure the CLI stays fast + id: cli-load-time + run: | + PYTHONPROFILEIMPORTTIME=1 ctc-segmenter -h 2> importtime.txt > /dev/null + CLI_LOAD_TIME="$((/usr/bin/time --format=%E ctc-segmenter -h > /dev/null) 2>&1)" + echo "CLI load time: $CLI_LOAD_TIME" > import-message.txt + PR_HEAD="${{ github.event.pull_request.head.sha }}" + [[ $PR_HEAD ]] && echo "Pull Request HEAD: $PR_HEAD" >> import-message.txt + echo "Imports that take more than 0.1 s:" >> import-message.txt + grep -E 'cumulative|[0-9]{6} ' importtime.txt >> import-message.txt + cat import-message.txt + echo "Full import time log:" + cat importtime.txt + if [[ "$CLI_LOAD_TIME" > "0:01.00" ]]; then \ + echo "ERROR: ctc-segmenter --help is too slow."; \ + echo "Please run 'PYTHONPROFILEIMPORTTIME=1 ctc-segmenter -h 2> importtime.txt; tuna importtime.txt' and tuck away expensive imports so that the CLI doesn't load them until it uses them."; \ + false; \ + fi + - name: Report help speed in PR + if: github.event_name == 'pull_request' + uses: mshick/add-pr-comment@v2 + with: + preformatted: true + message-path: import-message.txt diff --git a/aligner/cli.py b/aligner/cli.py index ba669c9..2996c82 100644 --- a/aligner/cli.py +++ b/aligner/cli.py @@ -12,6 +12,7 @@ app = typer.Typer( pretty_exceptions_show_locals=False, + context_settings={"help_option_names": ["-h", "--help"]}, help="An alignment tool based on CTC segmentation to split long audio into utterances", ) diff --git a/setup.cfg b/setup.cfg index 8c6e724..0b2cb08 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,7 +9,6 @@ ensure_newline_before_comments=True [mypy] ignore_missing_imports = True -plugins = pydantic.mypy [flake8] ignore = E203, E266, E501, W503