Skip to content

Commit

Permalink
fix: Remove Singleton pattern in Config class (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
echo724 committed Mar 1, 2022
1 parent 9d5e9ec commit 2de75e3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 74 deletions.
17 changes: 0 additions & 17 deletions notion2md/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,7 @@

from notion_client.helpers import get_id

from notion2md.exceptions import UnInitializedConfigException


def singleton(cls):
instance = {}

def get_instance(**kargs):
if cls not in instance:
if kargs:
instance[cls] = cls(**kargs)
else:
raise UnInitializedConfigException
return instance[cls]

return get_instance


@singleton
class Config(object):
__slots__ = (
"file_name",
Expand Down
2 changes: 1 addition & 1 deletion notion2md/console/commands/export_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def handle(self):
self.error(e)
if not config.target_id:
self.error("Notion2Md requires either id or url.")
exporter = BlockConvertor(self.io)
exporter = BlockConvertor(config, self.io)
# Directory Checking and Creating
if not os.path.exists(config.tmp_path):
os.makedirs(config.tmp_path)
Expand Down
54 changes: 0 additions & 54 deletions notion2md/convertor/file.py

This file was deleted.

4 changes: 2 additions & 2 deletions notion2md/exporter/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def markdown_exporter(
"w",
encoding="utf-8",
) as output:
output.write(BlockConvertor().convert(blocks))
output.write(BlockConvertor(config).convert(blocks))
# Make Zip file and Delete tmp
if not config.unzipped:
zip_dir(
Expand All @@ -55,7 +55,7 @@ def string_exporter(
if not config.unzipped and not os.path.exists(config.tmp_path):
os.makedirs(config.tmp_path)
blocks = get_children(config.target_id)
md = BlockConvertor().to_string(blocks)
md = BlockConvertor(config).to_string(blocks)
# Make Zip file and Delete tmp
if not config.unzipped:
zip_dir(
Expand Down

0 comments on commit 2de75e3

Please sign in to comment.