Skip to content

Commit

Permalink
chore: add pypi action and oa-atomacos and oa-pynput packages (OpenAd…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mustaballer authored Aug 9, 2023
1 parent 7648210 commit a62d7f3
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
if: steps.cache-deps.outputs.cache-hit != 'true'

- name: Check formatting with Black
run: poetry run black --check .
run: poetry run black --preview --check .

- name: Run Flake8
run: poetry run flake8
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 }}
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
2 changes: 1 addition & 1 deletion openadapt/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,6 @@ def process_events(
f"{num_total=}"
)
logger.info(
f"{pct_action_events=} {pct_window_events=} {pct_screenshots=} " f"{pct_total=}"
f"{pct_action_events=} {pct_window_events=} {pct_screenshots=} {pct_total=}"
)
return action_events, window_events, screenshots
1 change: 1 addition & 0 deletions openadapt/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# TODO: move utils.configure_logging to here


def filter_log_messages(data: dict) -> bool:
"""Filter log messages based on the defined criteria.
Expand Down
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
8 changes: 5 additions & 3 deletions openadapt/scrub.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ def scrub_dict(
scrubbed_dict[key] = scrubbed_text
elif isinstance(value, list):
scrubbed_list = [
_scrub_list_item(item, key, list_keys, force_scrub_children)
if _should_scrub_list_item(item, key, list_keys)
else item
(
_scrub_list_item(item, key, list_keys, force_scrub_children)
if _should_scrub_list_item(item, key, list_keys)
else item
)
for item in value
]
scrubbed_dict[key] = scrubbed_list
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -81,7 +81,7 @@ def run(self) -> None:
[action_event],
drop_constant=False,
)[0]
logger.info(f"action_event=\n" f"{pformat(action_event_dict)}")
logger.info(f"action_event=\n{pformat(action_event_dict)}")
try:
playback.play_action_event(
action_event,
Expand Down
8 changes: 5 additions & 3 deletions openadapt/strategies/stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,11 @@ def get_window_state_diffs(
ignore_window_ids.add(last_window_id)
logger.info(f"ignoring {first_window_title=} {last_window_title=}")
window_event_states = [
action_event.window_event.state
if action_event.window_event.state["window_id"] not in ignore_window_ids
else {}
(
action_event.window_event.state
if action_event.window_event.state["window_id"] not in ignore_window_ids
else {}
)
for action_event in action_events
]
diffs = [
Expand Down
22 changes: 6 additions & 16 deletions openadapt/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
MAX_TABLE_STR_LEN = 1024
PROCESS_EVENTS = True
IMG_WIDTH_PCT = 60
CSS = string.Template(
"""
CSS = string.Template("""
table {
outline: 1px solid black;
}
Expand Down Expand Up @@ -70,8 +69,7 @@
.screenshot:active img:nth-child(3) {
display: block;
}
"""
).substitute(
""").substitute(
IMG_WIDTH_PCT=IMG_WIDTH_PCT,
)

Expand Down Expand Up @@ -164,18 +162,12 @@ def dict2html(
children = indicate_missing(children, all_children, "...")
html_str = "\n".join(children)
elif isinstance(obj, dict):
rows_html = "\n".join(
[
f"""
rows_html = "\n".join([f"""
<tr>
<th>{format_key(key, value)}</th>
<td>{dict2html(value, max_children)}</td>
</tr>
"""
for key, value in obj.items()
if value not in EMPTY
]
)
""" for key, value in obj.items() if value not in EMPTY])
html_str = f"<table>{rows_html}</table>"
else:
html_str = html.escape(str(obj))
Expand Down Expand Up @@ -297,13 +289,11 @@ def main() -> None:
</table>
""",
),
Div(
text=f"""
Div(text=f"""
<table>
{dict2html(action_event_dict)}
</table>
"""
),
"""),
),
]
)
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
100 changes: 46 additions & 54 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ homepage = "https://openadapt.ai/"

[tool.poetry.dependencies]
python = "3.10.x"
atomacos = {git = "https://github.com/abrichr/atomacos.git", markers = "sys_platform == 'darwin'"}
pynput = {git = "https://github.com/abrichr/pynput.git"}
alembic = "1.8.1"
black = "23.3.0"
pygetwindow = {version = "<0.0.5", markers = "sys_platform == 'win32'"}
Expand Down Expand Up @@ -83,6 +81,8 @@ pympler = "^1.0.1"
psutil = "^5.9.5"
pyobjc-framework-avfoundation = {version = "^9.2", markers = "sys_platform == 'darwin'"}
fastapi = "0.98.0"
oa-pynput = "^1.7.7"
oa-atomacos = {version = "3.2.0", markers = "sys_platform == 'darwin'"}

[tool.poetry.dependencies.en_core_web_trf]
url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_trf-3.5.0/en_core_web_trf-3.5.0.tar.gz"
Expand Down
Loading

0 comments on commit a62d7f3

Please sign in to comment.