Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dev doc page for pull requests #3618

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 76 additions & 18 deletions .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
name: 'Build doc page for artifact'
on:
push:
branches: "*"
pull_request:
branches: [master]
types: [ opened, synchronize, closed ]


permissions:
pull-requests: write

jobs:
create_docs_comment:
name: Create the docs comment on new pull requests
runs-on: ubuntu-latest
if: github.event.action == 'opened'
env:
branch_name: ${{ github.event.pull_request.head.ref }}
steps:
- name: Add or update comment
uses: peter-evans/create-or-update-comment@v4
env:
url: 'http://flairNLP.github.io/flair-dev-docs/${{ env.branch_name }}/'
with:
issue-number: ${{ github.event.pull_request.number }}
body: 'The docs of this branch will be visible [here](${{ env.url }})'
edit-mode: replace

build_docs:
name: Build the docs using Sphinx and publish as artifact
runs-on: ubuntu-latest
if: github.event.action != 'closed'
env:
python-version: 3.9
branch_name: ${{ github.event.pull_request.head.ref }}
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -24,29 +47,64 @@ jobs:
run: pip install -r requirements-dev.txt
- name: Install doc dependencies
run: pip install -r docs/requirements.txt
- name: Fetch git tags
run: git fetch --tags origin
- name: Change config to current branch
env:
BRANCH_NAME: ${{ github.ref_name }}
run: |
sed -i 's/^smv_branch_whitelist = r"^master$"/smv_branch_whitelist = r"^${{ env.BRANCH_NAME }}$"/' docs/conf.py
sed -i 's/^smv_branch_whitelist = r"^master$"/smv_branch_whitelist = r"^${{ env.branch_name }}$"/' docs/conf.py
sed -i 's/^smv_tag_whitelist = r"^v\d+\.\d+\.\d+$"/smv_tag_whitelist = "^$"/' docs/conf.py
cat docs/conf.py
- name: Fetch branch
run: git fetch --depth 1
- name: Build docs
run: |
sphinx-multiversion docs doc_build/
- name: Add redirect to stable doc
env:
BRANCH_NAME: ${{ github.ref_name }}
run: |
cp assets/redirect.html doc_build/index.html
cp assets/redirect.html doc_build/404.html
cp assets/README.md doc_build/README.md
sed -i "s/\[VERSION\]/${{ env.BRANCH_NAME }}/g" doc_build/index.html
sed -i "s/\[VERSION\]/${{ env.BRANCH_NAME }}/g" doc_build/404.html
- name: Archive code coverage results
- name: Publish dev website
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.FLAIR_DEV_DOCS_TOKEN }}
external_repository: 'flairNLP/flair-dev-docs'
destination_dir: './${{ env.branch_name }}'
publish_branch: main
allow_empty_commit: true
publish_dir: './doc_build/${{ env.branch_name }}'
disable_nojekyll: true
user_name: flair-docs-automation
user_email: actions@github.com
- name: Archive website results
uses: actions/upload-artifact@v4
with:
name: website
path: doc_build
path: doc_build
cleanup:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
env:
branch_name: ${{ github.event.pull_request.head.ref }}
steps:
- name: Find existing PR comment
id: find-comment
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: "The docs will be available at"
- name: Delete comment
if: steps.find-comment.outputs.comment-id != ''
uses: detomarco/delete-comments@1.1.0
with:
comment-id: ${{ needs.find-existing-comment.outputs.comment-id }}
- name: Checkout target repository
uses: actions/checkout@v4
with:
repository: flairNLP/flair-dev-docs
token: ${{ secrets.FLAIR_DEV_DOCS_TOKEN }}

- name: Remove folder
run: rm -rf './${{ env.branch_name }}'

- name: Commit and push changes
run: |
git config --global user.name "flair-docs-automation"
git config --global user.email "actions@github.com"
git add .
git commit -m "remove: ${{ github.repository }}@${{ github.sha }}"
git push
6 changes: 3 additions & 3 deletions flair/models/tars_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class FewshotClassifier(flair.nn.Classifier[Sentence], ABC):
def __init__(self) -> None:
self._current_task = None
self._current_task: Optional[str] = None
self._task_specific_attributes: dict[str, dict[str, Any]] = {}
self.label_nearest_map = None
self.tars_model: flair.nn.Classifier[Sentence]
Expand Down Expand Up @@ -223,9 +223,9 @@ def list_existing_tasks(self) -> set[str]:
"""Lists existing tasks in the loaded TARS model on the console."""
return set(self._task_specific_attributes.keys())

def switch_to_task(self, task_name):
def switch_to_task(self, task_name: Optional[str]) -> None:
"""Switches to a task which was previously added."""
if task_name not in self._task_specific_attributes:
if task_name is not None and task_name not in self._task_specific_attributes:
log.error(
"Provided `%s` does not exist in the model. Consider calling `add_and_switch_to_new_task` first.",
task_name,
Expand Down
Loading