c-3lab / dim-python

MIT License
0 stars 0 forks source link

Add parser of "dim.json" file #15

Open lisphilar opened 1 year ago

lisphilar commented 1 year ago

Summary

Add parser of "dim.json" file to confirm the JSON data structure of "dim.json" file.

Solutions

from dim import Locker
# When dim.json does NOT exists
Locker(directory="data_files") # -> raise FileNotFoundError
locker_empty = Locker(directory="data_files", create_if_missing=True) # -> create data_files/dim.json
locker_empty.defined # -> return the contents of dim.json
# When dim.json exists
locker = Locker(directory="data_files")
locker_empty.defined # -> return the contents of dim.json

APIs to be deprecated

NA

Additional Context

This parser may be removed (or changed to an internal class) if necessary because only develoers will use this. Documentation could be skipped at this time.

lisphilar commented 1 year ago

This is the first step of #14.

  1. confirm the JSON data structure of "dim.json" file, adding a parser of this file with a new issue
ryo-ma commented 1 year ago

I don't think it is necessary to have a parser in dim-python. This is because the parsing process is delegated to the dim command.

The process of generating data_files is also delegated as follows

dim-python

dim.init()

⇩ dim command

dim init
lisphilar commented 1 year ago

Yes, this is not for users. As I mentioned in #14 and additional context of this issue, this will be used to clarify the JSON data structure of "dim.json". This may be removed later before 1.0.0 release.

ryo-ma commented 1 year ago

Sorry, I don't understand because my English is not good enough. Do you mean that you wrote the code for testing?

lisphilar commented 1 year ago

伝わりづらくてすみません... Pythonぐらいしかプログラム言語を使ったことがなく、私が単純にdenoとdim本体のコードの知識がないので混乱しているだけですが、dim.json, dim-lock.jsonのデータ構造と各コマンドの役割と詳細、引数の役割をあまり把握できていないです。そのため#14の通り、順を追ってすり合わせをできればと思っています。 dim.jsonのデータ構造はhttps://github.com/c-3lab/dim/blob/main/libs/types.ts のままとは思いますが、dataclassで表現してみましたので認識に誤りがないか#17にてご確認いただけるとありがたいです。 解析器がないとコマンドラインなどで試しにくいのでLocker クラスも作っています。

もちろん最終的な目的は#14の5番目以降なのでLockerは現時点では仮の機能と認識していますが、将来入ってくれるかもしれないPythonユーザーの開発メンバーにとっても有用かもしれません。

(For the record) Classes created with this issue are just developer tools for me and expected dim(-python) developers to understand the JSON data structure of "dim.json" file. Because of short knowledge of Deno language, I was confused when reading deno codes of dim source codes to identify the roles of dim-deno commands (refer to #14) and their arguments. As the first step, I tried to translate DimJson object defined with types.ps to Python codes using dataclass. Locker class was created as an interface of the data parser (internal class _DimJson). Please review my pull request #17 to confirm the JSON data structure.

ryo-ma commented 1 year ago

I don't fully understand pull request #17 yet. If you have submitted the code for your own understanding as a pull request, that code is not needed. This is because understanding the structure is not necessary to develop dim-python. You only need to provide us with the actually required delegate code.

I'm sorry if I'm misinterpreting your consideration.