Skip to content

Commit

Permalink
feat: pip pack (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
QiE2035 authored Apr 16, 2024
1 parent f5e12a1 commit ac248d1
Show file tree
Hide file tree
Showing 19 changed files with 300 additions and 49 deletions.
33 changes: 32 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,31 @@ jobs:
name: MAA-nupkgs
path: "tools/nupkgs/*.nupkg"

pip_pack:
needs: [meta, windows, ubuntu, macos]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: assets

- name: Pip Pack
working-directory: tools/pip_pack
run: |
tag=${{ needs.meta.outputs.tag }}
pip install --upgrade wheel build tomlkit
python pip_pack.py $tag
- uses: actions/upload-artifact@v3
if: always()
with:
name: MAA-pip-pkgs
path: "tools/pip_pack/wheel/*.whl"

release:
if: ${{ needs.meta.outputs.is_release == 'true' }}
needs: [meta, windows, ubuntu, macos, nuget_pack]
needs: [meta, windows, ubuntu, macos, nuget_pack, pip_pack]
runs-on: ubuntu-latest
env:
NUGET_PACKAGE_SOURCE: https://api.nuget.org/v3/index.json # https://apiint.nugettest.org/v3/index.json
Expand All @@ -325,6 +347,15 @@ jobs:
-SkipDuplicate
rm -r assets/MAA-nupkgs
- name: Publish Pip Packages
run: |
pip install --upgrade twine
python -m twine upload \
assets/MAA-pip-pkgs/*.whl \
--username __token__\
--password ${{ secrets.PYPI_TOKEN }}
rm -r assets/MAA-pip-pkgs
- run: |
cd assets
for f in *; do
Expand Down
3 changes: 3 additions & 0 deletions source/binding/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.py]

end_of_line = lf
18 changes: 10 additions & 8 deletions source/binding/Python/maa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
__all__ = [
"library",
"resource",
"controller",
"instance",
"toolkit",
"custom_controller",
]
import os

from .library import Library

__PATH = os.path.join(os.path.dirname(__file__), "bin")

if os.path.exists(__PATH):
ver = Library.open(__PATH)
if ver:
print("MaaFw version: ", ver)
5 changes: 3 additions & 2 deletions source/binding/Python/maa/buffer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import copy
import ctypes
from typing import List, Optional, Tuple, Union

import numpy
import copy
from typing import List, Tuple, Union, Optional
from PIL import Image

from .define import *
Expand Down
3 changes: 1 addition & 2 deletions source/binding/Python/maa/callback_agent.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import ctypes
import json
from typing import Callable, Any, Optional
from typing import Any, Callable, Optional

from .define import MaaApiCallback


Callback = Callable[[str, Any, Any], None]


Expand Down
9 changes: 4 additions & 5 deletions source/binding/Python/maa/context.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ctypes
import numpy
import json

from typing import Dict, Optional, Tuple

from .library import Library
from .define import MaaBool
import numpy

from .buffer import *
from .define import MaaBool
from .library import Library


class SyncContext:
Expand Down Expand Up @@ -211,7 +211,6 @@ def screencap(self) -> Optional[numpy.ndarray]:
return None
return image_buffer.get()


_api_properties_initialized: bool = False

@staticmethod
Expand Down
18 changes: 12 additions & 6 deletions source/binding/Python/maa/controller.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from ctypes import c_int32
import json
from abc import ABC
from typing import Any, Dict, Optional, Union
from ctypes import c_int32
import os
from pathlib import Path
import json
from typing import Any, Dict, Optional, Union

from .custom_controller import CustomControllerAgent
from .buffer import ImageBuffer
from .callback_agent import Callback, CallbackAgent
from .custom_controller import CustomControllerAgent
from .define import *
from .future import Future
from .library import Library
from .buffer import ImageBuffer

__all__ = [
"AdbController",
Expand Down Expand Up @@ -236,6 +237,11 @@ def _set_api_properties():


class AdbController(Controller):
AGENT_BINARY_PATH = os.path.join(
os.path.dirname(__file__),
"../MaaAgentBinary",
)

def __init__(
self,
adb_path: Union[str, Path],
Expand All @@ -245,7 +251,7 @@ def __init__(
| MaaAdbControllerTypeEnum.Screencap_FastestWay
),
config: Dict[str, Any] = {},
agent_path: Union[str, Path] = "share/MaaAgentBinary",
agent_path: Union[str, Path] = AGENT_BINARY_PATH,
callback: Optional[Callback] = None,
callback_arg: Any = None,
):
Expand Down
2 changes: 1 addition & 1 deletion source/binding/Python/maa/custom_action.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ctypes
from abc import ABC, abstractmethod

from .define import *
from .buffer import RectBuffer
from .context import SyncContext
from .define import *


class CustomAction(ABC):
Expand Down
3 changes: 1 addition & 2 deletions source/binding/Python/maa/custom_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from abc import ABC, abstractmethod
from typing import Optional


from .define import *
from .buffer import ImageBuffer, StringBuffer
from .define import *


class CustomControllerAgent(ABC):
Expand Down
9 changes: 5 additions & 4 deletions source/binding/Python/maa/custom_recognizer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Tuple
import numpy
import ctypes
from abc import ABC, abstractmethod
from typing import Tuple

from .define import *
from .buffer import RectBuffer, StringBuffer, ImageBuffer
import numpy

from .buffer import ImageBuffer, RectBuffer, StringBuffer
from .context import SyncContext
from .define import *


class CustomRecognizer(ABC):
Expand Down
1 change: 0 additions & 1 deletion source/binding/Python/maa/define.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import numpy


MaaApiCallback = ctypes.CFUNCTYPE(
None, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p
)
Expand Down
2 changes: 1 addition & 1 deletion source/binding/Python/maa/future.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ctypes
from typing import Union

from .define import MaaStatus, MaaStatusEnum, MaaId
from .define import MaaId, MaaStatus, MaaStatusEnum


class Status:
Expand Down
14 changes: 7 additions & 7 deletions source/binding/Python/maa/instance.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import asyncio
import ctypes
import json
import asyncio
from pathlib import Path
from typing import Dict, Union, Optional, Any
from typing import Any, Dict, Optional, Union

from .buffer import ImageListBuffer, RectBuffer, StringBuffer
from .callback_agent import Callback, CallbackAgent
from .controller import Controller
from .custom_action import CustomAction
from .custom_recognizer import CustomRecognizer
from .define import *
from .future import Future, MaaStatusEnum
from .library import Library
from .callback_agent import CallbackAgent, Callback
from .controller import Controller
from .resource import Resource
from .custom_recognizer import CustomRecognizer
from .custom_action import CustomAction
from .buffer import RectBuffer, ImageListBuffer, StringBuffer


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions source/binding/Python/maa/library.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ctypes
import ctypes.util
import pathlib
import os
import pathlib
import platform
from typing import Union, Optional
from typing import Optional, Union

from .define import *

Expand Down
2 changes: 1 addition & 1 deletion source/binding/Python/maa/library.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ctypes import c_int32
import pathlib
from ctypes import c_int32
from typing import Optional, Union

from .define import *
Expand Down
6 changes: 3 additions & 3 deletions source/binding/Python/maa/resource.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import asyncio
import ctypes
import pathlib
import asyncio
from typing import Union, Optional, Any
from typing import Any, Optional, Union

from .callback_agent import Callback, CallbackAgent
from .define import *
from .future import Future
from .library import Library
from .callback_agent import CallbackAgent, Callback


class Resource:
Expand Down
6 changes: 3 additions & 3 deletions source/binding/Python/maa/toolkit.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import asyncio
import ctypes
import json
import asyncio
from dataclasses import dataclass
from typing import List, Union, Dict
from pathlib import Path
from typing import Dict, List, Union

from .library import Library
from .define import *
from .instance import Instance
from .library import Library


@dataclass
Expand Down
Loading

0 comments on commit ac248d1

Please sign in to comment.