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

Refactor codebase into installable "reprostim" Python module (+ reprostim-videocapture) package #124

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e4433a8
Initial doc sketch for how to RF codebase
yarikoptic Dec 11, 2024
baf9691
ReproStim library empty project with hatch, #116.
vmdocua Dec 13, 2024
9e51900
ReproStim library empty project with hatch, #116.
vmdocua Dec 13, 2024
85db7ca
Move Capture to reprostim-videocapture, #116.
vmdocua Dec 13, 2024
6a53de5
Move Capture to reprostim-videocapture, #116.
vmdocua Dec 13, 2024
92d6a7e
Move Capture to reprostim-videocapture, #116.
vmdocua Dec 13, 2024
d6b89c6
Restrict python package distribution only to src/reprostim and related
yarikoptic Dec 13, 2024
6178449
Added base files for intuit auto release
yarikoptic Dec 13, 2024
e54ab28
Added codespell action, #124.
vmdocua Dec 16, 2024
0515d43
Fixed codespell issues, #124.
vmdocua Dec 16, 2024
d43b4af
Fixed codespell issues, #124.
vmdocua Dec 16, 2024
6643b2b
Turned on pre-commit hook, #124.
vmdocua Dec 16, 2024
7bd75d1
Stick to python 3.10 version (as the best for psychopy), and add pyte…
vmdocua Dec 16, 2024
58af70e
Turned on pre-commit hook, #124.
vmdocua Dec 16, 2024
c00d785
License placeholder, #124.
vmdocua Dec 16, 2024
35e64d9
Hatch reprostim cli stub, #124.
vmdocua Dec 18, 2024
32d9188
Hatch reprostim cli stub, #124.
vmdocua Dec 18, 2024
553c852
Hatch reprostim cli stub, #124.
vmdocua Dec 18, 2024
91ee2bb
Update authors and basic dependencies, #124.
vmdocua Dec 18, 2024
bd121c4
Update dependencies and added optional ones like: test, audio, psycho…
vmdocua Dec 18, 2024
be4d726
Update LICENSE.txt
vmdocua Dec 18, 2024
31c0a9e
Update docs/design/rf-library.md
vmdocua Dec 18, 2024
a7d224c
Created stub/placeholder for commands like qr-parse, timesync-stimuli…
vmdocua Dec 18, 2024
a071c88
Created stub/placeholder for commands like qr-parse, timesync-stimuli…
vmdocua Dec 18, 2024
9719819
Normalize code with pre-commit hooks, #124.
vmdocua Dec 18, 2024
32e8994
Reworked parse_qQR.py to "reprostim qr-parse" command, setup logging …
vmdocua Dec 23, 2024
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
16 changes: 16 additions & 0 deletions .autorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"onlyPublishWithReleaseLabel": true,
"baseBranch": "master",
"author": "DANDI Bot <[email protected]>",
"noVersionPrefix": true,
"plugins": [
"git-tag",
[
"exec",
{
"afterRelease": "python -m build && twine upload dist/*"
}
],
"released"
]
}
1 change: 1 addition & 0 deletions .codespell-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
acend
3 changes: 3 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[codespell]
ignore-words = .codespell-ignore
skip = venv,reprostim-capture,build,cmake-build-debug
8 changes: 4 additions & 4 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ jobs:
cd build
cmake ..
make
working-directory: Capture
working-directory: src/reprostim-capture

- name: Test "reprostim-videocapture -h"
run: |
./reprostim-videocapture -V
./reprostim-videocapture -h
working-directory: Capture/build/videocapture
working-directory: src/reprostim-capture/build/videocapture

- name: Test "reprostim-screencapture -h"
run: |
./reprostim-screencapture -V
./reprostim-screencapture -h
working-directory: Capture/build/screencapture
working-directory: src/reprostim-capture/build/screencapture

- name: Run tests with CTest
run: |
ctest --output-on-failure
working-directory: Capture/build
working-directory: src/reprostim-capture/build
22 changes: 22 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Codespell

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

jobs:
codespell:
name: Check for spelling errors
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Codespell
uses: codespell-project/actions-codespell@v2
57 changes: 57 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
name: Test with pytest and hatch

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read

jobs:
pytest:
name: Test with pytest
runs-on: ubuntu-latest
strategy:
matrix:
python:
- '3.10'
steps:
- name: Configure environment
run: |
git config --global user.name "reprostim-test"
git config --global user.email "[email protected]"
uname -a
date -Is
date -u

- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: Install hatch and virtual environment
run: |
pwd
ls -l
pip install --upgrade pip
pip install hatch
hatch env create
shell: bash

- name: Run pytest
run: |
hatch run pytest --cov=. --cov-report=xml
shell: bash

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Auto-release on PR merge

on:
# ATM, this is the closest trigger to a PR merging
push:
branches:
- master

jobs:
auto-release:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download latest auto
run: |
auto_download_url="$(curl -fsSL https://api.github.com/repos/intuit/auto/releases/latest | jq -r '.assets[] | select(.name == "auto-linux.gz") | .browser_download_url')"
wget -O- "$auto_download_url" | gunzip > ~/auto
chmod a+x ~/auto

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Install build & twine
run: python -m pip install build twine

- name: Create release
run: ~/auto shipit -vv
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

# vim:set sts=2:
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,17 @@ Videos/
*.pyc
Capture/C++/VideoCapture
venvs
build/
.coverage*
.dir-locals.el
dist/
*.egg-info
.env.*
!.env.local
.flake8
.idea/
.mypy_cache/
*.pid
*.pyc
.python-version

37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-json
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
# B008 Do not perform function calls in argument defaults.
# A003 class attribute "id" is shadowing a python builtin
args: ["-j8", "--ignore=B008,A003", "--max-line-length=89"]
additional_dependencies:
- flake8-bugbear
- flake8-builtins
- flake8-unused-arguments

exclude: '^src/reprostim-capture/.*|.codespellrc'

default_language_version:
python: python3.10
2 changes: 1 addition & 1 deletion Events/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def listen(command, pyb):
Notes
-----
* This could be set up as a global listener, though that might be overkill just for conveying stimulus events.
* Using `-1` polling to disable timouts, we could use ipoll instead:
* Using `-1` polling to disable timeouts, we could use ipoll instead:
https://docs.micropython.org/en/latest/library/select.html?highlight=poll#select.poll.ipoll
"""

Expand Down
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall -- let's follow the https://reuse.software/spec-3.3/ so there would be LICENSES/ folder.


Copyright (c) 2020-2024 TBD
vmdocua marked this conversation as resolved.
Show resolved Hide resolved

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The A/V out connections from SC can be any standard as long as you have the
appropriate adapters, dongles, etc. However, if your Video out does not
support embedded audio (e.g. VGA), then you will need a separate audio out
set of splitters and cables. The Magewell device has standard audio ports to
accomodate this eventuality.
accommodate this eventuality.

Note: Missing from Schematics A and B, is any connection back to SC that
records subject response information. That's because ReproStim is not
Expand Down Expand Up @@ -123,26 +123,30 @@ subjects.

On Debian

```shell
apt-get install -y ffmpeg libudev-dev libasound-dev libv4l-dev libyaml-cpp-dev libspdlog-dev catch2 v4l-utils libopencv-dev libcurl4-openssl-dev nlohmann-json3-dev cmake g++
```

"Parsing/parse_wQR.py" script requires in zbar to be installed as well:

```shell
apt-get install -y libzbar0

````

## Build

cd Capture
```shell
cd src/reprostim-capture

mkdir build
cd build
cmake ..
make

```

## Subdirectories Structure

### Capture
### src/reprostim-capture

Contains all code needed for setting up video capture. This includes C++
code for interfacing with the video capture device, and scheme for setting
Expand Down Expand Up @@ -188,7 +192,9 @@ it can accidentally produce the same error message ERROR[003].

This is optional step, only for information purposes:

```shell
lsusb
```

And locate line with device, e.g.:

Expand All @@ -198,8 +204,9 @@ In this sample, 2935 is the "Vendor ID", and 0008 is the "Product ID".

Optionally Magewell device name and serial number can be quickly checked with this command:

```shell
lsusb -d 2935: -v | grep -E 'iSerial|iProduct'

```

### 2) Create "udev" rules
Create text file under "/etc/udev/rules.d/189-reprostim.rules" location with
Expand All @@ -217,18 +224,24 @@ Note: we can see that "ATTR{idVendor}" value 2935 is equal to one we got in
step 1) from lsusb utility.

Also sample udev rules configuration added to project under
"Capture/etc/udev/189-reprostim.rules" location.
"src/reprostim-capture/etc/udev/189-reprostim.rules" location.

Note: make sure the file has owner "root", group "root" and 644 permissions:

```shell
ls -l /etc/udev/rules.d/189*
````
```
-rw-r--r-- 1 root root 72 ... /etc/udev/rules.d/189-reprostim.rules
```

### 3) Add user to "plugdev" group
Make sure the user running VideoCapture utility is a member of the
"plugdev" group, e.g.:

```shell
sudo usermod -aG plugdev TODO_user
```

### 4) Restart computer
Restart computer to make changes effect.
Expand Down
38 changes: 38 additions & 0 deletions docs/design/rf-library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ReproStim Python library/CLI

## Current status

This repository collects various sub-projects

- Magewell SDK
- C++ code of ReproStim `reprostim-videocapture` (and `reprostim-screencapture`)
- ReproEvents for MicroPython board
- ReproStim videograbber
- ReproStim stimuli for calibration

## The Goal

Refactor stuff here into cleanly separated and documented libraries etc.

## Approach/Layout

- `src/`
- `reprostim/` - Python library and CLIs for working with ReproStim
- `audio/` - Audio fingerprinting/processing
- `cli/` - CLI entrypoints (for `reprostim CMD`, could be hierarchical like `reprostim qr parse`)
vmdocua marked this conversation as resolved.
Show resolved Hide resolved
- `base.py` - common base commands for CLI
- `cmd_timesync_stimuli.py` - CLI to replace `tools/reprostim-timesync-stimuli`
- `qr/` - QR code utilities
- `__init__.py` - sets up the library
- `reprostim-capture/` - C++ code(s) relating to capturing
- `3rdparty/` - Magewell MWCapture SDK
- `reproevents/` - move MicroPython ReproEvents here (do not strive to make it work)
- `test/` - some global tests possibly for integration testing etc

## Refactor log

| Old | New |
|---------------|-------------------------|
| [x] `Capture` | `src/reprostim-capture` |
| [ ] `Events` | `src/reproevents` |
| [ ] `TBD` | `TODO` |
Loading
Loading