diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4b300ca..3b575e1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -29,6 +29,15 @@ jobs: python -m pip install --upgrade pip pip install poetry + - name: Set version from GITHUB_REF + run: >- + # GITHUB_REF will be `refs/tags/v1.2.3` for a tag named "v1.2.3" + # we strip the `refs/tags/` part to get the version number + # we also strip "v" from the version number, if it exists, getting "1.2.3" + export VERSION=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,' -e 's/^v//') + echo Setting version to $VERSION + poetry version $VERSION + - name: Build wheels and source tarball run: >- poetry build diff --git a/pyproject.toml b/pyproject.toml index 703bd05..d927ea3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "python-main" -version = "1.0.2" +version = "0.0.0" homepage = "https://github.com/flipbit03/main" description = "Decorator which runs the tagged function if the current module is being run as a script. No more `if __name__ == \"__main__\"` madness." authors = ["Cadu "] @@ -14,6 +14,10 @@ classifiers=[ 'Natural Language :: English', ] +packages = [ + { include = "python_main"}, +] + [tool.poetry.dependencies] python = "^3.9" diff --git a/python_main/__init__.py b/python_main/__init__.py index 9b4c3be..2b00fe9 100644 --- a/python_main/__init__.py +++ b/python_main/__init__.py @@ -1,10 +1,16 @@ -from typing import Callable, Optional +from typing import Callable, TypeVar __RAN_AS_SCRIPT_MODULE = "__main__" __CALLABLE_MODULE_PROP = "__module__" +__MAIN_RETURN_TYPE = TypeVar("__MAIN_RETURN_TYPE") -def main(f: Callable[[], Optional[int]]) -> Callable: + +def main(f: Callable[[], __MAIN_RETURN_TYPE]) -> Callable[[], __MAIN_RETURN_TYPE]: if getattr(f, __CALLABLE_MODULE_PROP) == __RAN_AS_SCRIPT_MODULE: f() return f + + +# Only export the main function +__all__ = ["main"] diff --git a/python_main/py.typed b/python_main/py.typed new file mode 100644 index 0000000..e69de29