Skip to content

Commit

Permalink
docs: add singleton usage examples
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Undertone0809 committed Nov 5, 2024
1 parent 7217ffa commit c1ee574
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
43 changes: 31 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -82,6 +70,37 @@ if __name__ == "__main__":
main()
```

The metadata file will be saved in the default storage path, which is `~/.zeeland/test/metadata.json`.

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.
Expand Down
24 changes: 24 additions & 0 deletions examples/singleton_usage.py
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 0 additions & 4 deletions setup.cfg

This file was deleted.

0 comments on commit c1ee574

Please sign in to comment.