Skip to content

Commit

Permalink
Add py.typed marker (#6)
Browse files Browse the repository at this point in the history
* Add py.typed marker, improve typing, make release process automatically set package version

* Remove unneeded bound.
  • Loading branch information
flipbit03 authored Dec 1, 2024
1 parent 554273f commit 028dad8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand All @@ -14,6 +14,10 @@ classifiers=[
'Natural Language :: English',
]

packages = [
{ include = "python_main"},
]

[tool.poetry.dependencies]
python = "^3.9"

Expand Down
10 changes: 8 additions & 2 deletions python_main/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
Empty file added python_main/py.typed
Empty file.

0 comments on commit 028dad8

Please sign in to comment.