diff --git a/.github/workflows/spelling.yml b/.github/workflows/spelling.yml index 07c86ed4a28..9556c8c3683 100644 --- a/.github/workflows/spelling.yml +++ b/.github/workflows/spelling.yml @@ -5,16 +5,149 @@ on: push: branches: - main + jobs: pyspelling: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - name: Check for skip label and get changed files + id: check-files + uses: actions/github-script@v6 + with: + script: | + let skipCheck = false; + let changedFiles = []; + + if (context.eventName === 'pull_request') { + // Check for skip label + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + skipCheck = labels.some(label => label.name === 'skip-spell-check'); + + if (!skipCheck) { + // Get changed files in PR + const { data: files } = await github.rest.pulls.listFiles({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + changedFiles = files + .filter(file => file.filename.match(/\.(py|rst|md)$/)) + .map(file => file.filename); + } + } else { + // For push events, we'll still need to use git diff + // We'll handle this after checkout + } + + core.setOutput('skip', skipCheck.toString()); + core.setOutput('files', changedFiles.join('\n')); + core.setOutput('is-pr', (context.eventName === 'pull_request').toString()); + + - uses: actions/checkout@v4 + if: steps.check-files.outputs.skip != 'true' + with: + fetch-depth: 0 + + - name: Get changed files for push event + if: | + steps.check-files.outputs.skip != 'true' && + steps.check-files.outputs.is-pr != 'true' + id: push-files + run: | + CHANGED_FILES=$(git diff --name-only HEAD^..HEAD -- '*.py' '*.rst' '*.md') + echo "files<> $GITHUB_OUTPUT + echo "$CHANGED_FILES" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Check if relevant files changed + if: steps.check-files.outputs.skip != 'true' + id: check + run: | + if [ "${{ steps.check-files.outputs.is-pr }}" == "true" ]; then + FILES="${{ steps.check-files.outputs.files }}" + else + FILES="${{ steps.push-files.outputs.files }}" + fi + + if [ -z "$FILES" ]; then + echo "skip=true" >> $GITHUB_OUTPUT + echo "No relevant files changed (*.py, *.rst, *.md), skipping spell check" + else + echo "skip=false" >> $GITHUB_OUTPUT + echo "Found changed files to check:" + echo "$FILES" + fi + - uses: actions/setup-python@v4 + if: | + steps.check-files.outputs.skip != 'true' && + steps.check.outputs.skip != 'true' with: python-version: '3.9' cache: 'pip' - - run: pip install pyspelling - - run: sudo apt-get install aspell aspell-en - - run: pyspelling + - name: Install dependencies + if: | + steps.check-files.outputs.skip != 'true' && + steps.check.outputs.skip != 'true' + run: | + pip install pyspelling + sudo apt-get install aspell aspell-en + + - name: Run spell check on each file + id: spellcheck + if: | + steps.check-files.outputs.skip != 'true' && + steps.check.outputs.skip != 'true' + run: | + if [ "${{ steps.check-files.outputs.is-pr }}" == "true" ]; then + mapfile -t FILES <<< "${{ steps.check-files.outputs.files }}" + else + mapfile -t FILES <<< "${{ steps.push-files.outputs.files }}" + fi + + # Check each file individually + FINAL_EXIT_CODE=0 + SPELLCHECK_LOG="" + for file in "${FILES[@]}"; do + if [ -n "$file" ]; then + echo "Checking spelling in $file" + python3 -c "import yaml; config = yaml.safe_load(open('.pyspelling.yml')); new_matrix = [matrix.copy() for matrix in config['matrix'] if (('python' in matrix['name'].lower() and '$file'.endswith('.py')) or ('rest' in matrix['name'].lower() and '$file'.endswith('.rst')) or ('markdown' in matrix['name'].lower() and '$file'.endswith('.md'))) and not matrix.update({'sources': ['$file']})]; config['matrix'] = new_matrix; yaml.dump(config, open('temp_config.yml', 'w'))" + + if OUTPUT=$(pyspelling -c temp_config.yml 2>&1); then + echo "No spelling errors found in $file" + else + FINAL_EXIT_CODE=1 + echo "Spelling errors found in $file:" + echo "$OUTPUT" + SPELLCHECK_LOG+="### $file\n$OUTPUT\n\n" + fi + fi + done + + # Save the results to GITHUB_OUTPUT + echo "spell_failed=$FINAL_EXIT_CODE" >> $GITHUB_OUTPUT + echo "spell_log<> $GITHUB_OUTPUT + echo "$SPELLCHECK_LOG" >> $GITHUB_OUTPUT + echo "SPELLEOF" >> $GITHUB_OUTPUT + + if [ $FINAL_EXIT_CODE -ne 0 ]; then + echo "Spell check failed! See above for details." + echo + echo "Here are a few tips:" + echo "- All PyTorch API objects must be in double backticks or use an intersphinx directive." + echo " Example: ``torch.nn``, :func:" + echo "- Consult en-wordlist.txt for spellings of some of the words." + echo " You can add a word to en-wordlist.txt if:" + echo " 1) It's a common abbreviation, like RNN." + echo " 2) It's a word widely accepted in the industry." + echo "- Please do not add words like 'dtype', 'torch.nn.Transformer' to pass spellcheck." + echo " Instead wrap it in double backticks or use an intersphinx directive." + echo + exit 1 + fi diff --git a/.pyspelling.yml b/.pyspelling.yml index 1afe6dbb45e..bce797e6559 100644 --- a/.pyspelling.yml +++ b/.pyspelling.yml @@ -2,10 +2,7 @@ spellchecker: aspell matrix: - name: python sources: - - beginner_source/*.py - - intermediate_source/*.py - - advanced_source/*.py - - recipes_source/*/*.py + - "**/*.py" dictionary: wordlists: - en-wordlist.txt @@ -56,7 +53,7 @@ matrix: - pyspelling.filters.url: - name: reST sources: - - beginner_source/*.rst + - "**/*.rst" dictionary: wordlists: - en-wordlist.txt @@ -119,3 +116,48 @@ matrix: - open: '\.\.\s+(image|include|only)::' close: '$' - pyspelling.filters.url: +- name: markdown + sources: + - '**/*.md' + dictionary: + wordlists: + - en-wordlist.txt + pipeline: + - pyspelling.filters.markdown: + markdown_extensions: + - markdown.extensions.extra: + - markdown.extensions.admonition: + - markdown.extensions.codehilite: + - markdown.extensions.meta: + - markdown.extensions.tables: + - markdown.extensions.toc: + - pyspelling.filters.html: + comments: false + ignores: + - code + - pre + - tt + - img + - a + - table + - thead + - tbody + - th + - tr + - td + - pyspelling.filters.context: + context_visible_first: true + delimiters: + # Ignore code blocks + - open: '```[a-z]*\n' + close: '```\n' + # Ignore inline code + - open: '`' + close: '`' + # Ignore links + - open: '\[([^]]*)\]' + close: '\([^)]*\)' + # Ignore HTML comments + - open: '' + - pyspelling.filters.url: diff --git a/README.md b/README.md index af84d9ebe79..f17f7f5e3d9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ All the tutorials are now presented as sphinx style documentation at: # Asking a question -If you have a question about a tutorial, post in https://dev-discuss.pytorch.org/ rather than creating an issue in this repo. Your question will be answered much faster on the dev-discuss forum. +If you hve a qestion about a tutorial, post in https://dev-discuss.pytorch.org/ rather than creating an issue in this repo. Your question will be answered much faster on the dev-discuss forum. # Submitting an issue @@ -20,7 +20,7 @@ You can submit the following types of issues: We use sphinx-gallery's [notebook styled examples](https://sphinx-gallery.github.io/stable/tutorials/index.html) to create the tutorials. Syntax is very simple. In essence, you write a slightly well formatted Python file and it shows up as an HTML page. In addition, a Jupyter notebook is autogenerated and available to run in Google Colab. -Here is how you can create a new tutorial (for a detailed description, see [CONTRIBUTING.md](./CONTRIBUTING.md)): +Here is how you can ceate a new tutorial (for a detailed description, see [CONTRIBUTING.md](./CONTRIBUTING.md)): NOTE: Before submitting a new tutorial, read [PyTorch Tutorial Submission Policy](./tutorial_submission_policy.md). diff --git a/beginner_source/colab.rst b/beginner_source/colab.rst index 812255704e7..329f4884666 100644 --- a/beginner_source/colab.rst +++ b/beginner_source/colab.rst @@ -10,8 +10,8 @@ run PyTorch tutorials in Google Colab. PyTorch Version in Google Colab ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -When you are running a tutorial that requires a version of PyTorch that has -just been released, that version might not be yet available in Google Colab. +Wen you are running a tutorial that requires a version of PyTorch that has +jst been released, that version might not be yet available in Google Colab. To check that you have the required ``torch`` and compatible domain libraries installed, run ``!pip list``. @@ -27,7 +27,7 @@ Using Tutorial Data from Google Drive in Colab ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We've added a new feature to tutorials that allows users to open the -notebook associated with a tutorial in Google Colab. You may need to +ntebook associated with a tutorial in Google Colab. You may need to copy data to your Google drive account to get the more complex tutorials to work. diff --git a/beginner_source/introyt/tensors_deeper_tutorial.py b/beginner_source/introyt/tensors_deeper_tutorial.py index d7293dfe295..b9019469995 100644 --- a/beginner_source/introyt/tensors_deeper_tutorial.py +++ b/beginner_source/introyt/tensors_deeper_tutorial.py @@ -44,7 +44,7 @@ ########################################################################## -# Let’s unpack what we just did: +# Let’s upack what we just did: # # - We created a tensor using one of the numerous factory methods # attached to the ``torch`` module. @@ -85,7 +85,7 @@ ######################################################################### -# The factory methods all do just what you’d expect - we have a tensor +# The fctory methods all do just what you’d expect - we have a tensor # full of zeros, another full of ones, and another with random values # between 0 and 1. #