Merge branch 'main' into fix/lint_warnings
This commit is contained in:
commit
e511e7eda5
|
@ -1,175 +0,0 @@
|
||||||
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
# Adapted from https://github.com/huggingface/diffusers/blob/main/.github/workflows/pr_style_bot.yml
|
|
||||||
name: PR Style Bot
|
|
||||||
|
|
||||||
on:
|
|
||||||
issue_comment:
|
|
||||||
types: [created]
|
|
||||||
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
env:
|
|
||||||
PYTHON_VERSION: "3.10"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check-permissions:
|
|
||||||
if: >
|
|
||||||
contains(github.event.comment.body, '@bot /style') &&
|
|
||||||
github.event.issue.pull_request != null
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
is_authorized: ${{ steps.check_user_permission.outputs.has_permission }}
|
|
||||||
steps:
|
|
||||||
- name: Check user permission
|
|
||||||
id: check_user_permission
|
|
||||||
uses: actions/github-script@v6
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
const comment_user = context.payload.comment.user.login;
|
|
||||||
const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
username: comment_user
|
|
||||||
});
|
|
||||||
|
|
||||||
const authorized =
|
|
||||||
permission.permission === 'admin' ||
|
|
||||||
permission.permission === 'write';
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`User ${comment_user} has permission level: ${permission.permission}, ` +
|
|
||||||
`authorized: ${authorized} (admins & maintainers allowed)`
|
|
||||||
);
|
|
||||||
|
|
||||||
core.setOutput('has_permission', authorized);
|
|
||||||
|
|
||||||
run-style-bot:
|
|
||||||
needs: check-permissions
|
|
||||||
if: needs.check-permissions.outputs.is_authorized == 'true'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
steps:
|
|
||||||
- name: Extract PR details
|
|
||||||
id: pr_info
|
|
||||||
uses: actions/github-script@v6
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
const prNumber = context.payload.issue.number;
|
|
||||||
const { data: pr } = await github.rest.pulls.get({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
pull_number: prNumber
|
|
||||||
});
|
|
||||||
|
|
||||||
// We capture both the branch ref and the "full_name" of the head repo
|
|
||||||
// so that we can check out the correct repository & branch (including forks).
|
|
||||||
core.setOutput("prNumber", prNumber);
|
|
||||||
core.setOutput("headRef", pr.head.ref);
|
|
||||||
core.setOutput("headRepoFullName", pr.head.repo.full_name);
|
|
||||||
|
|
||||||
- name: Check out PR branch
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
env:
|
|
||||||
HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
|
|
||||||
HEADREF: ${{ steps.pr_info.outputs.headRef }}
|
|
||||||
with:
|
|
||||||
persist-credentials: true
|
|
||||||
# Instead of checking out the base repo, use the contributor's repo name
|
|
||||||
repository: ${{ env.HEADREPOFULLNAME }}
|
|
||||||
ref: ${{ env.HEADREF }}
|
|
||||||
# You may need fetch-depth: 0 for being able to push
|
|
||||||
fetch-depth: 0
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Debug
|
|
||||||
env:
|
|
||||||
HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
|
|
||||||
HEADREF: ${{ steps.pr_info.outputs.headRef }}
|
|
||||||
PRNUMBER: ${{ steps.pr_info.outputs.prNumber }}
|
|
||||||
run: |
|
|
||||||
echo "PR number: ${PRNUMBER}"
|
|
||||||
echo "Head Ref: ${HEADREF}"
|
|
||||||
echo "Head Repo Full Name: ${HEADREPOFULLNAME}"
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
|
||||||
|
|
||||||
- name: Get Ruff Version from pre-commit-config.yaml
|
|
||||||
id: get-ruff-version
|
|
||||||
run: |
|
|
||||||
RUFF_VERSION=$(awk '/repo: https:\/\/github.com\/astral-sh\/ruff-pre-commit/{flag=1;next}/rev:/{if(flag){print $2;exit}}' .pre-commit-config.yaml)
|
|
||||||
echo "ruff_version=${RUFF_VERSION}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Install Ruff
|
|
||||||
env:
|
|
||||||
RUFF_VERSION: ${{ steps.get-ruff-version.outputs.ruff_version }}
|
|
||||||
run: python -m pip install "ruff==${RUFF_VERSION}"
|
|
||||||
|
|
||||||
- name: Ruff check
|
|
||||||
run: ruff check --fix
|
|
||||||
|
|
||||||
- name: Ruff format
|
|
||||||
run: ruff format
|
|
||||||
|
|
||||||
- name: Commit and push changes
|
|
||||||
id: commit_and_push
|
|
||||||
env:
|
|
||||||
HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
|
|
||||||
HEADREF: ${{ steps.pr_info.outputs.headRef }}
|
|
||||||
PRNUMBER: ${{ steps.pr_info.outputs.prNumber }}
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
echo "HEADREPOFULLNAME: ${HEADREPOFULLNAME}, HEADREF: ${HEADREF}"
|
|
||||||
# Configure git with the Actions bot user
|
|
||||||
git config user.name "github-actions[bot]"
|
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
||||||
git config --local lfs.https://github.com/.locksverify false
|
|
||||||
|
|
||||||
# Make sure your 'origin' remote is set to the contributor's fork
|
|
||||||
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${HEADREPOFULLNAME}.git"
|
|
||||||
|
|
||||||
# If there are changes after running style/quality, commit them
|
|
||||||
if [ -n "$(git status --porcelain)" ]; then
|
|
||||||
git add .
|
|
||||||
git commit -m "Apply style fixes"
|
|
||||||
# Push to the original contributor's forked branch
|
|
||||||
git push origin HEAD:${HEADREF}
|
|
||||||
echo "changes_pushed=true" >> $GITHUB_OUTPUT
|
|
||||||
else
|
|
||||||
echo "No changes to commit."
|
|
||||||
echo "changes_pushed=false" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Comment on PR with workflow run link
|
|
||||||
if: steps.commit_and_push.outputs.changes_pushed == 'true'
|
|
||||||
uses: actions/github-script@v6
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
const prNumber = parseInt(process.env.prNumber, 10);
|
|
||||||
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
|
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
issue_number: prNumber,
|
|
||||||
body: `Style fixes have been applied. [View the workflow run here](${runUrl}).`
|
|
||||||
});
|
|
||||||
env:
|
|
||||||
prNumber: ${{ steps.pr_info.outputs.prNumber }}
|
|
|
@ -285,10 +285,20 @@ class OpenCVCamera:
|
||||||
# when other threads are used to save the images.
|
# when other threads are used to save the images.
|
||||||
cv2.setNumThreads(1)
|
cv2.setNumThreads(1)
|
||||||
|
|
||||||
|
backend = (
|
||||||
|
cv2.CAP_V4L2
|
||||||
|
if platform.system() == "Linux"
|
||||||
|
else cv2.CAP_DSHOW
|
||||||
|
if platform.system() == "Windows"
|
||||||
|
else cv2.CAP_AVFOUNDATION
|
||||||
|
if platform.system() == "Darwin"
|
||||||
|
else cv2.CAP_ANY
|
||||||
|
)
|
||||||
|
|
||||||
camera_idx = f"/dev/video{self.camera_index}" if platform.system() == "Linux" else self.camera_index
|
camera_idx = f"/dev/video{self.camera_index}" if platform.system() == "Linux" else self.camera_index
|
||||||
# First create a temporary camera trying to access `camera_index`,
|
# First create a temporary camera trying to access `camera_index`,
|
||||||
# and verify it is a valid camera by calling `isOpened`.
|
# and verify it is a valid camera by calling `isOpened`.
|
||||||
tmp_camera = cv2.VideoCapture(camera_idx)
|
tmp_camera = cv2.VideoCapture(camera_idx, backend)
|
||||||
is_camera_open = tmp_camera.isOpened()
|
is_camera_open = tmp_camera.isOpened()
|
||||||
# Release camera to make it accessible for `find_camera_indices`
|
# Release camera to make it accessible for `find_camera_indices`
|
||||||
tmp_camera.release()
|
tmp_camera.release()
|
||||||
|
@ -311,7 +321,7 @@ class OpenCVCamera:
|
||||||
# Secondly, create the camera that will be used downstream.
|
# Secondly, create the camera that will be used downstream.
|
||||||
# Note: For some unknown reason, calling `isOpened` blocks the camera which then
|
# Note: For some unknown reason, calling `isOpened` blocks the camera which then
|
||||||
# needs to be re-created.
|
# needs to be re-created.
|
||||||
self.camera = cv2.VideoCapture(camera_idx)
|
self.camera = cv2.VideoCapture(camera_idx, backend)
|
||||||
|
|
||||||
if self.fps is not None:
|
if self.fps is not None:
|
||||||
self.camera.set(cv2.CAP_PROP_FPS, self.fps)
|
self.camera.set(cv2.CAP_PROP_FPS, self.fps)
|
||||||
|
|
|
@ -15,6 +15,11 @@ from functools import cache
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
CAP_V4L2 = 200
|
||||||
|
CAP_DSHOW = 700
|
||||||
|
CAP_AVFOUNDATION = 1200
|
||||||
|
CAP_ANY = -1
|
||||||
|
|
||||||
CAP_PROP_FPS = 5
|
CAP_PROP_FPS = 5
|
||||||
CAP_PROP_FRAME_WIDTH = 3
|
CAP_PROP_FRAME_WIDTH = 3
|
||||||
CAP_PROP_FRAME_HEIGHT = 4
|
CAP_PROP_FRAME_HEIGHT = 4
|
||||||
|
|
Loading…
Reference in New Issue