Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge branch 'HumanSignal:master' into yolo-predictions
Browse files Browse the repository at this point in the history
  • Loading branch information
carbaro authored Feb 9, 2024
2 parents 04fe3c2 + 7deee93 commit 6237dcb
Show file tree
Hide file tree
Showing 22 changed files with 675 additions and 171 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
name: "PyPI"
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action@v2.1.0
- uses: hmarr/debug-action@v3.0.0

- name: Checkout
uses: actions/checkout@v4
Expand All @@ -63,12 +63,12 @@ jobs:
sed -i "s/^__version__[ ]*=.*/__version__ = '${version}'/g" ${{ env.PYTHON_VERSION_FILE }}
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Configure pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('./requirements.txt') }}
Expand All @@ -93,7 +93,7 @@ jobs:

- name: Attach artifacts to release
if: inputs.release-id
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
Expand All @@ -113,7 +113,7 @@ jobs:
- name: Upload to artifact
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Dist
path: dist/
103 changes: 103 additions & 0 deletions .github/workflows/jira-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: "/jira command"

on:
repository_dispatch:
types: [ jira-command ]

concurrency:
group: ${{ github.workflow }}-${{ github.event.client_payload.github.payload.issue.number }}-${{ github.event.client_payload.slash_command.command }}-${{ github.event.client_payload.slash_command.args.unnamed.arg1 || github.event.client_payload.slash_command.args.all }}

jobs:
create:
if: ${{ github.event.client_payload.slash_command.args.unnamed.arg1 == 'create' }}
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: hmarr/[email protected]

- name: Add Workflow link to command comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
- name: Check user's membership
uses: actions/github-script@v7
id: check-membership
env:
ACTOR: ${{ github.actor }}
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const { repo, owner } = context.repo;
const actor = process.env.ACTOR;
const { data: membership } = await github.rest.orgs.getMembershipForUser({
org: owner,
username: actor,
});
if (membership.state != "active") {
const error = `Unfortunately you don't have membership in ${owner} organization, Jira Issue was not created`;
core.setOutput("error", error);
core.setFailed(error);
}
- name: Checkout Actions Hub
uses: actions/checkout@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: HumanSignal/actions-hub
path: ./.github/actions-hub

- name: Jira Create Issue
id: jira-create-issue
uses: ./.github/actions-hub/actions/jira-create-issue
with:
jira_server: ${{ vars.JIRA_SERVER }}
jira_username: ${{ secrets.JIRA_USERNAME }}
jira_token: ${{ secrets.JIRA_TOKEN }}
summary: ${{ github.event.client_payload.github.payload.issue.title }}
description: ${{ github.event.client_payload.github.payload.issue.body }}
project: ${{ github.event.client_payload.slash_command.args.unnamed.arg3 || 'TRIAG' }}
type: ${{ github.event.client_payload.slash_command.args.unnamed.arg2 || 'task' }}

- name: Add reaction to command comment on success
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Jira issue [${{ steps.jira-create-issue.outputs.key }}](${{ steps.jira-create-issue.outputs.link }}) is created
reactions: "+1"

- name: Add reaction to command comment on failure
uses: peter-evans/create-or-update-comment@v4
if: failure()
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> **Error**: failed to execute "${{ github.event.client_payload.slash_command.args.unnamed.arg1 }}" command
> ${{ steps.check-membership.outputs.error }}
reactions: "-1"

help:
if: github.event.client_payload.slash_command.args.unnamed.arg1 == 'help' || !contains(fromJson('["create"]'), github.event.client_payload.slash_command.args.unnamed.arg1)
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Update comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Command | Description
> --- | ---
> /jira create [task|bug|story] `PROJECT` | Create a Jira issue in project `PROJECT`
reaction-type: hooray
4 changes: 2 additions & 2 deletions .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
pull-requests: write
steps:

- uses: hmarr/debug-action@v2.1.0
- uses: hmarr/debug-action@v3.0.0

- name: "Validate PR's title"
uses: thehanimo/[email protected]
Expand All @@ -36,7 +36,7 @@ jobs:
configuration_path: ".github/pr-title-checker-config.json"

- name: "Set PR's label based on title"
uses: release-drafter/release-drafter@v5.25.0
uses: release-drafter/release-drafter@v6.0.0
with:
disable-releaser: true
config-name: autolabeler.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-cut-off-release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
contents: write
pull-requests: write
steps:
- uses: hmarr/debug-action@v2.1.0
- uses: hmarr/debug-action@v3.0.0

- name: Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
needs:
- build-pypi
steps:
- uses: hmarr/debug-action@v2.1.0
- uses: hmarr/debug-action@v3.0.0

- name: DispatchEvent
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-set-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
permissions:
contents: write
steps:
- uses: hmarr/debug-action@v2.1.0
- uses: hmarr/debug-action@v3.0.0

- name: Checkout
uses: actions/checkout@v4
Expand All @@ -41,7 +41,7 @@ jobs:

- name: Get GitHub user details
id: get-github-user
uses: actions/github-script@v6
uses: actions/github-script@v7
env:
ACTOR_USERNAME: ${{ github.event.sender.login }}
with:
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/slash-command-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Slash Command Dispatch
on:
issue_comment:
types: [created]

env:
commands_list: |
jira
issue_commands_list: |
jira
jobs:
slashCommandDispatch:
if: startsWith(github.event.comment.body, '/')
timeout-minutes: 1
runs-on: ubuntu-latest
steps:
- uses: hmarr/[email protected]

- name: 'Validate command'
id: determine_command
uses: actions/github-script@v7
env:
COMMANDS_LIST: ${{ env.commands_list }}
ISSUE_COMMANDS_LIST: ${{ env.issue_commands_list }}
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const body = context.payload.comment.body.toLowerCase().trim()
const commands_list = process.env.COMMANDS_LIST.split("\n")
const issue_commands_list = process.env.ISSUE_COMMANDS_LIST.split("\n")
console.log("Detected PR comment: " + body)
console.log("Commands list: " + commands_list)
console.log("Issue commands list: " + issue_commands_list)
commandArray = body.split(/\s+/)
const contextCommand = commandArray[0].split('/')[1].trim();
console.log("contextCommand: " + contextCommand)
core.setOutput('command_state', 'known')
core.setOutput('is_issue_command', 'false')
if (! commands_list.includes(contextCommand)) {
core.setOutput('command_state', 'unknown')
core.setOutput('command', contextCommand)
}
if (issue_commands_list.includes(contextCommand)) {
core.setOutput('is_issue_command', 'true')
}
- name: Slash Command Dispatch for Issues
id: scd_issues
if: ${{ steps.determine_command.outputs.command_state != 'unknown' && steps.determine_command.outputs.is_issue_command == 'true' }}
uses: peter-evans/slash-command-dispatch@v4
with:
token: ${{ secrets.GIT_PAT }}
reaction-token: ${{ secrets.GIT_PAT }}
issue-type: "issue"
reactions: true
commands: ${{ env.issue_commands_list }}

- name: Slash Command Dispatch for PRs
id: scd_prs
if: ${{ steps.determine_command.outputs.command_state != 'unknown' && steps.determine_command.outputs.is_issue_command != 'true' }}
uses: peter-evans/slash-command-dispatch@v4
with:
token: ${{ secrets.GIT_PAT }}
reaction-token: ${{ secrets.GIT_PAT }}
issue-type: "pull-request"
reactions: true
commands: ${{ env.commands_list }}

- name: Edit comment with error message
if: ${{ steps.determine_command.outputs.command_state == 'unknown' }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
body: |
> '/${{ steps.determine_command.outputs.command }}' is an unknown command.
> See '/help'
reactions: eyes, confused
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'

- uses: actions/cache@v3
- uses: actions/cache@v4
name: Configure pip cache
id: pip-cache
with:
Expand All @@ -59,7 +59,7 @@ jobs:
pytest --junitxml report.xml --cov=. -m "not integration_tests"
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion .github/workflows/update-draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
rc-version: ${{ steps.create-draft-release.outputs.rc-version }}
steps:
- name: Create release draft
uses: actions/github-script@v6
uses: actions/github-script@v7
id: create-draft-release
env:
TARGET_COMMITISH: "${{ github.ref_name }}"
Expand Down
2 changes: 1 addition & 1 deletion label_studio_converter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
except ModuleNotFoundError as e:
print(e)

__version__ = '0.0.58.dev'
__version__ = '0.0.59.dev'
32 changes: 30 additions & 2 deletions label_studio_converter/converter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Optional

import os
import io
import math
import re
import logging
import ujson as json
import ijson
Expand Down Expand Up @@ -374,6 +377,31 @@ def iter_from_json_file(self, json_file):
if item is not None:
yield item

def _maybe_matching_tag_from_schema(self, from_name: str) -> Optional[str]:
"""If the from name exactly matches an output tag from the schema, return that tag.
Otherwise, certain tags (like those from Repeater) contain
placeholders like {{idx}}. Such placeholders are mapped to a regex in self._schema.
For example, if "my_output_tag_{{idx}}" is a tag in the schema,
then the from_name "my_output_tag_0" should match it, and we should return "my_output_tag_{{idx}}".
"""

for tag_name, tag_info in self._schema.items():
if tag_name == from_name:
return tag_name

if not tag_info.get('regex'):
continue

tag_name_pattern = tag_name
for variable, regex in tag_info['regex'].items():
tag_name_pattern = tag_name_pattern.replace(variable, regex)

if re.compile(tag_name_pattern).match(from_name):
return tag_name

return None

def annotation_result_from_task(self, task):
has_annotations = 'completions' in task or 'annotations' in task
if not has_annotations:
Expand Down Expand Up @@ -412,9 +440,9 @@ def annotation_result_from_task(self, task):

# get results only as output
for r in result:
if 'from_name' in r and r['from_name'] in self._output_tags:
if 'from_name' in r and (tag_name := self._maybe_matching_tag_from_schema(r['from_name'])):
v = deepcopy(r['value'])
v['type'] = self._schema[r['from_name']]['type']
v['type'] = self._schema[tag_name]['type']
if 'original_width' in r:
v['original_width'] = r['original_width']
if 'original_height' in r:
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""All tests for label-studio-converter should be written using pytest"""
Binary file added tests/data/test_brush/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6237dcb

Please sign in to comment.