14-12-2024
- Added setup system.
- Implemented program flow.
- Added PhotonApplication class
- Added Basic Run loop.
- Added entry point for program.
Interesting Things I learned
1. pip install for development
If you have a setup.py file in your project, you can use pip install -e . to install the package while you still work on it and also import it in other packages to use it, while it will automaticlly update as you work on it.
2. Relative paths in packages
If you are Package a project as pip package, put
include_package_data=True,
package_data={"path": ["data/*", "config/*.json"]},
in your setup function and use importlib.resources.open(pkg, filename) function to open the file without worring about the path. You can also use pkg_resources.resource_filename("path.config", filename) to get exact filepaths.
3. To find subclasses of a class
Use the following snippit of code to get all subclasses of a class:
import inspect
from typing import TypeVar
_T = TypeVar("_T")
def FindSubclass(cls: _T) -> _T:
"""Find a subclass of Application dynamically."""
for name, obj in inspect.getmembers(sys.modules["__main__"]):
if inspect.isclass(obj) and issubclass(obj, cls) and obj is not cls:
return obj
raise RuntimeError("No subclass of cls found in the main module.")