Skip to content

Commit

Permalink
Merge branch 'main' into share-magic-wormhole
Browse files Browse the repository at this point in the history
  • Loading branch information
Mustaballer authored Aug 10, 2023
2 parents 5fd9868 + 9ee20a3 commit 453d2c2
Show file tree
Hide file tree
Showing 16 changed files with 696 additions and 693 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Semantic Release
name: Semantic Release and PyPi Publish

on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest
Expand All @@ -22,3 +24,20 @@ jobs:
repository_password: ${{ secrets.PYPI_TOKEN }}
git_committer_name: "OpenAdapt Bot"
git_committer_email: "[email protected]"

publish:
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: main
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Build and publish to PyPI
uses: JRubics/[email protected]
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,47 @@



## v0.7.1 (2023-08-10)

### Chore

* chore: add pypi action and oa-atomacos and oa-pynput packages (#456) ([`a62d7f3`](https://github.com/OpenAdaptAI/OpenAdapt/commit/a62d7f3898438b4716e31695d32120b228f84d21))

* chore: suppress identical warnings (#389)

* chore: suppress identical warnings

* add max_num_warnings_per_second to limit number of allowed warnings per cond

* remove MAX_NUM_REPEAT_WARNINGS and check for max num warnings per second in utils.py

* Update openadapt/config.py

* address linting errors and set new variable

* use class for filter_log_messages and track message_timestamps with instance variable

* create logging.py to replace logging class using namespace

* test github actions with empty commit

* replaced variable name with MESSAGES_TO_FILTER

* Update openadapt/logging.py

---------

Co-authored-by: Richard Abrich <[email protected]> ([`7648210`](https://github.com/OpenAdaptAI/OpenAdapt/commit/764821039e3a03cb4dc3ec80b744f61a48c71461))

### Fix

* fix: pypi direct dependency failure (#459)

* remove trf from toml and then ran `poetry update`

* update all neccessary files ([`d638469`](https://github.com/OpenAdaptAI/OpenAdapt/commit/d638469e238eb5fb3d386ca2ad8c64542a10c6c9))


## v0.7.0 (2023-07-28)

### Feature
Expand Down
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,36 @@ The body or footer can begin with **BREAKING CHANGE:** followed by a short descr
- see instructions on how to resolve poetry.lock and pyproject.toml conflicts below
6. Celebrate contributing to OpenAdapt!

### Publishing Direct Dependencies to PyPI

1. **Update Package Name**: Use `oa_<package>` format for consistency. Update it in `setup.py` or `pyproject.toml`.
2. **Update Imports**: Modify import statements to `oa_<package>`.
3. **Update Version Number**: Increment version in `setup.py` or `pyproject.toml`.
4. **Create Distribution**: Run to generate distribution files:
```bash
python setup.py sdist bdist_wheel
```
5. **Install Twine**: Install `twine` if needed:
```bash
pip install twine
```
6. **Upload to PyPI**: Use `twine` to upload files:
```bash
twine upload dist/*
```
7. **Verify on PyPI**: Check PyPI for successful update.

After publishing the updated dependency to PyPI, follow these steps in the OpenAdapt repository:

8. **Update OpenAdapt Repository**: In the OpenAdapt repository, use Poetry to remove the old direct dependency and add the newly published dependency:
```bash
poetry remove <direct_dependency>
poetry add <newly_published_dependency>
```
Make sure to replace `<direct_dependency>` and `<newly_published_dependency>` with the actual names of the dependencies you're updating.
### How to resolve poetry.lock and pyproject.toml conflicts:
How to fix conflicts with poetry.lock and poetry.toml:
1. Edit the poetry.toml file to include the correct dependencies
2. Run ```poetry lock``` to update the poetry.lock file
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pip3 install poetry
poetry install
poetry shell
alembic upgrade head
python -m spacy download en_core_web_trf
pytest
```

Expand Down
1 change: 1 addition & 0 deletions install/install_openadapt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ Set-Location .\OpenAdapt
RunAndCheck "pip install poetry" "Run ``pip install poetry``"
RunAndCheck "poetry install" "Run ``poetry install``"
RunAndCheck "poetry run alembic upgrade head" "Run ``alembic upgrade head``" -SkipCleanup:$true
RunAndCheck "poetry run python -m spacy download en_core_web_trf" "Run ``python -m spacy download en_core_web_trf``" -SkipCleanup:$true
RunAndCheck "poetry run pytest" "Run ``Pytest``" -SkipCleanup:$true
Write-Host "OpenAdapt installed Successfully!" -ForegroundColor Green
Start-Process powershell -Verb RunAs -ArgumentList "-NoExit", "-Command", "Set-Location -Path '$pwd'; poetry shell"
Expand Down
1 change: 1 addition & 0 deletions install/install_openadapt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ cd OpenAdapt
RunAndCheck "pip3.10 install poetry" "Install Poetry"
RunAndCheck "poetry install" "Install Python dependencies"
RunAndCheck "poetry run alembic upgrade head" "Update database"
RunAndCheck "poetry run python -m spacy download en_core_web_trf" "Download spacy en_core_web_trf model"
RunAndCheck "poetry run pytest" "Run tests"
if [ -z "$SKIP_POETRY_SHELL" ]; then
RunAndCheck "poetry shell" "Activate virtual environment"
Expand Down
20 changes: 3 additions & 17 deletions openadapt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
# IGNORES WARNINGS (PICKLING, ETC.)
# TODO: ignore warnings by default on GUI
"IGNORE_WARNINGS": False,
"MAX_NUM_WARNINGS_PER_SECOND": 5,
"WARNING_SUPPRESSION_PERIOD": 1,
"MESSAGES_TO_FILTER": ["Cannot pickle Objective-C objects"],
# ACTION EVENT CONFIGURATIONS
"ACTION_TEXT_SEP": "-",
"ACTION_TEXT_NAME_PREFIX": "<",
Expand Down Expand Up @@ -233,20 +236,3 @@ def obfuscate(val: str, pct_reveal: float = 0.1, char: str = "*") -> str:
):
val = obfuscate(val)
logger.info(f"{key}={val}")


def filter_log_messages(data: dict) -> bool:
"""Filter log messages by ignoring specific strings.
Args:
data (dict): Data from a loguru logger.
Returns:
bool: True if the message should not be ignored, False if it should be ignored.
"""
# TODO: ultimately, we want to fix the underlying issues, but for now,
# we can ignore these messages
messages_to_ignore = [
"Cannot pickle Objective-C objects",
]
return not any(msg in data["message"] for msg in messages_to_ignore)
43 changes: 43 additions & 0 deletions openadapt/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Module for log message filtering, excluding strings & limiting warnings."""

from collections import defaultdict
import time

from openadapt import config

MESSAGE_TIMESTAMPS = defaultdict(list)

# TODO: move utils.configure_logging to here


def filter_log_messages(data: dict) -> bool:
"""Filter log messages based on the defined criteria.
Args:
data: The log message data from a loguru logger.
Returns:
bool: True if the log message should not be ignored, False otherwise.
"""
# TODO: ultimately, we want to fix the underlying issues, but for now,
# we can ignore these messages
for msg in config.MESSAGES_TO_FILTER:
if msg in data["message"]:
if config.MAX_NUM_WARNINGS_PER_SECOND > 0:
current_timestamp = time.time()
MESSAGE_TIMESTAMPS[msg].append(current_timestamp)
timestamps = MESSAGE_TIMESTAMPS[msg]

# Remove timestamps older than 1 second
timestamps = [
ts
for ts in timestamps
if current_timestamp - ts <= config.WARNING_SUPPRESSION_PERIOD
]

if len(timestamps) > config.MAX_NUM_WARNINGS_PER_SECOND:
return False

MESSAGE_TIMESTAMPS[msg] = timestamps

return True
2 changes: 1 addition & 1 deletion openadapt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from loguru import logger
from PIL import Image, ImageChops
from pynput import keyboard
from oa_pynput import keyboard
import numpy as np
import sqlalchemy as sa

Expand Down
2 changes: 1 addition & 1 deletion openadapt/playback.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Utilities for playing back ActionEvents."""

from loguru import logger
from pynput import mouse, keyboard
from oa_pynput import mouse, keyboard

from openadapt.common import KEY_EVENTS, MOUSE_EVENTS
from openadapt.models import ActionEvent
Expand Down
2 changes: 1 addition & 1 deletion openadapt/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from loguru import logger
from pympler import tracker
from pynput import keyboard, mouse
from oa_pynput import keyboard, mouse
from tqdm import tqdm
import fire
import mss.tools
Expand Down
2 changes: 1 addition & 1 deletion openadapt/strategies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import time

from loguru import logger
from pynput import keyboard, mouse
from oa_pynput import keyboard, mouse
import numpy as np

from openadapt import models, playback, utils
Expand Down
5 changes: 4 additions & 1 deletion openadapt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from openadapt import common, config
from openadapt.db import BaseModel
from openadapt.logging import filter_log_messages
from openadapt.models import ActionEvent

EMPTY = (None, [], {}, "")
Expand Down Expand Up @@ -57,7 +58,9 @@ def configure_logging(logger: logger, log_level: str) -> None:
level=log_level,
enqueue=True,
format=logger_format,
filter=config.filter_log_messages if config.IGNORE_WARNINGS else None,
filter=(
filter_log_messages if config.MAX_NUM_WARNINGS_PER_SECOND > 0 else None
),
)
logger.debug(f"{log_level=}")

Expand Down
6 changes: 3 additions & 3 deletions openadapt/window/_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from loguru import logger
import AppKit
import ApplicationServices
import atomacos
import oa_atomacos
import Foundation
import Quartz

Expand Down Expand Up @@ -251,7 +251,7 @@ def deepconvert_objc(object: Any) -> Any | list | dict | Literal[0]:
)
logger.warning(f"{object=}")
if value:
value = atomacos._converter.Converter().convert_value(value)
value = oa_atomacos._converter.Converter().convert_value(value)
return value


Expand All @@ -267,7 +267,7 @@ def get_active_element_state(x: int, y: int) -> dict:
"""
window_meta = get_active_window_meta()
pid = window_meta["kCGWindowOwnerPID"]
app = atomacos._a11y.AXUIElement.from_pid(pid)
app = oa_atomacos._a11y.AXUIElement.from_pid(pid)
el = app.get_element_at_position(x, y)
state = dump_state(el.ref)
state = deepconvert_objc(state)
Expand Down
Loading

0 comments on commit 453d2c2

Please sign in to comment.