From a528b432312f03b0cb610171e8c8ca954b340d2f Mon Sep 17 00:00:00 2001 From: zeeland Date: Tue, 5 Nov 2024 12:58:24 +0800 Subject: [PATCH] docs: add singleton usage examples - Update README.md with singleton usage examples - Add new file examples/singleton_usage.py - Remove setup.cfg This commit enhances the documentation by adding detailed examples of singleton usage in the README.md and includes a new file with additional singleton examples. The removal of setup.cfg is part of a configuration cleanup. --- README.md | 41 ++++++++++++++++++++++++++----------- examples/singleton_usage.py | 24 ++++++++++++++++++++++ setup.cfg | 4 ---- 3 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 examples/singleton_usage.py delete mode 100644 setup.cfg diff --git a/README.md b/README.md index cc5ff41..7500b6f 100644 --- a/README.md +++ b/README.md @@ -40,18 +40,6 @@ conda activate zeeland pip install poetry ``` -Then you can run the client using the following command: - -```bash -zeeland --help -``` - -or with `Poetry`: - -```bash -poetry run zeeland --help -``` - ### Basic Usage Create a metadata file in the default storage path. @@ -82,6 +70,35 @@ if __name__ == "__main__": main() ``` +Singleton usage + +```python +from zeeland import Singleton, singleton + + +@singleton() +class TestSingleton: + pass + + +instance1 = TestSingleton() +instance2 = TestSingleton() + +assert instance1 is instance2 + + +class TestSingletonWithArgs(metaclass=Singleton): + def __init__(self, value): + self.value = value + + +instance1 = TestSingletonWithArgs("test1") +instance2 = TestSingletonWithArgs("test2") + +assert instance1 is instance2 +assert instance1.value == "test1" +``` + ### Makefile usage [`Makefile`](https://github.com/Undertone0809/zeeland/blob/main/Makefile) contains a lot of functions for faster development. diff --git a/examples/singleton_usage.py b/examples/singleton_usage.py new file mode 100644 index 0000000..9f4e4cc --- /dev/null +++ b/examples/singleton_usage.py @@ -0,0 +1,24 @@ +from zeeland import Singleton, singleton + + +@singleton() +class TestSingleton: + pass + + +instance1 = TestSingleton() +instance2 = TestSingleton() + +assert instance1 is instance2 + + +class TestSingletonWithArgs(metaclass=Singleton): + def __init__(self, value): + self.value = value + + +instance1 = TestSingletonWithArgs("test1") +instance2 = TestSingletonWithArgs("test2") + +assert instance1 is instance2 +assert instance1.value == "test1" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 3c46a08..0000000 --- a/setup.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[darglint] -# https://github.com/terrencepreilly/darglint -strictness = long -docstring_style = google