Git Product home page Git Product logo

esapy's People

Contributors

kosukemizuno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

esapy's Issues

List up input arguments

動作全体に関するもの

  • [--destructive] | --no-output | --output=<filename>
    • 入力ファイルを書き換えるフラグ
    • default = destructive
    • no-outputの場合はアップロードの記録(metadata)も残らないのでリトライ不可
    • outputが指定されていれば、そこにipynbを保存
  • --force-upload フラグ
    • 画像のアップロードに失敗したものがあっても、構わずbodyのアップロードを行う
  • --force-new-post フラグ
    • ipynb限定
    • 過去にアップロードしたことがあるipynbだとしても新しいポストとして投稿する
  • --edit-in-browser | --no-browser
    • bodyのアップロードに成功したら、ブラウザでeditページを開くかどうか

misc

--name
--category
--message
--tag
[--wip | --no-wip]

[--token <esa.io_token>]
[--team <esa.io_team_name>]
[--proxy :]

[--verbose]

filename check

アップロード時にpost_numberが存在したら既存の記事を上書きするが、ipynbファイルをexplorer上でコピーして新しいnotebookにした場合を検出して、新しい記事として投稿するようにしたい。

ただし、アップ後にファイル名を変える場合もあるので、強制で新しい記事にするのではなく尋ねる(or 実行時引数で指定)という形にしたい

実装案

post_number だけじゃなく、ファイル名(親ディレクトリを含まない)でsha256 hashを記録しておく

改修すべきポイント

  • 新しい投稿か上書きかの判断
    • コマンドライン上で尋ねるようにする
  • 投稿成功して保存するときにファイル名hashを記録
  • esa reset でpost_numberを指定した場合に、ファイル名hashも整合するように書き換え
  • esa ls で整合しているかどうか表示する

Attached image

Uploading images attached to a cell.

Command Ctrl+V on jupyter embed a clipboard image on a cell. The conversion process to markdown via nbconvert doesn't extract these attached images.

png以外の画像があるとコケる

png前提のコードになってるので要修正

# attachment があったら抽出
at_images = {} # key=attachment:(xxx.png), value=file path
for at_name, v in cell_md.get('attachments', {}).items():
path_at = self._save_encodedimage(v['image/png'])
at_images[at_name] = path_at
# attachment image を参照するimgタグがあったら抽出後のファイルパスで置き換え
for i, l in enumerate(md):
_l = l
matches = list(re.finditer(r'!\[(.*?)\]\(attachment:(.+\.png)\)', l))
for m in matches[::-1]:
path_img = at_images.get(m.group(2), m.group(2))
_l = _l[:m.start()] \
+ '![%s](%s)' % (m.group(1), str(path_img)) \
+ _l[m.end():]
md[i] = _l
# imgタグがあったらsha256からurlをゲットして、置き換え
for i, l in enumerate(md):
_l = l
matches = list(re.finditer(r'!\[(.*?)\]\((.+\.png)\)', l))
for m in matches[::-1]:
fn = m.group(2)
if len(fn) >= 4 and fn[:4] == 'http':
continue
alttxt = m.group(1)
path_img = self.path_root / Path(unquote(fn))
try:
url = self._upload_image_and_get_url(path_img)
except RuntimeError:
url = unquote(fn)
alttxt = alttxt + ' (upload failed)'
_l = _l[:m.start()] \
+ '![%s](%s)' % (alttxt, url) \
+ _l[m.end():]
md[i] = _l

upload file via context menu

windows10限定(その他のOSはどうする?)

エクスプローラの右クリックからファイルをesa.ioのアップローダに送れるようにする

コマンドは esa register-sendto <type> とか

  1. ファイルをアップロードするエントリポイントを作る(単独の実行可能な.pyファイル)
  2. typeによって、アップロード後にURLをクリップボードに返すexe, markdownリンクとして返すexeを作り分ける
  3. pyinstallerでexeファイルに変換
  4. windowsのsendtoフォルダに配置

esa unregister-sendto [<type> | --all] とかも欲しい

Escape inline math

markdown内のinline math がmathjaxと競合しないようにする
アンダースコアをエスケープする
バックスラッシュ+記号のコマンドをエスケープする(\,, \ , \!

Gather current post_info by HTTP request

patch時のpost_infoとして、過去の記録ではなくて、GETして現在の情報を集めるようにしたい
GETして記事が存在しなかったら、newpostとして作成する

md support

mdファイルをアップするときに、記事作成に成功したのにエラーが出る

[2020-06-13 15:41:07,664] esapy.processor INFO: Intermediate markdown file has been saved.
[2020-06-13 15:41:07,665] esapy.entrypoint INFO: publish mode=force, result of preprocess=True, ... pu
blish: True
[2020-06-13 15:41:07,665] esapy.processor INFO: Uploading markdown body ...
[2020-06-13 15:41:07,669] esapy.processor INFO: Gathering information for create post
[2020-06-13 15:41:07,670] esapy.processor INFO: This file has not been uploaded before. ==> create new
 post
[2020-06-13 15:41:07,670] esapy.api INFO: Creating new post
[2020-06-13 15:41:08,308] esapy.api INFO: New post was successfully created.
[2020-06-13 15:41:08,309] esapy.api INFO: URL of the created post: https://dia-pe-titech.esa.io/posts/
590
[2020-06-13 15:41:08,311] esapy.processor INFO: Removing temporal working directory
Traceback (most recent call last):
  File "/home/mizuno/.pyenv/versions/3.7.7/bin/esa", line 8, in <module>
    sys.exit(main())
  File "/home/mizuno/.pyenv/versions/3.7.7/lib/python3.7/site-packages/esapy/entrypoint.py", line 183,
 in main
    args.handler(args)
  File "/home/mizuno/.pyenv/versions/3.7.7/lib/python3.7/site-packages/esapy/entrypoint.py", line 57,
in command_up
    post_url = proc.upload_body()
  File "/home/mizuno/.pyenv/versions/3.7.7/lib/python3.7/site-packages/esapy/processor.py", line 296,
in upload_body
    self.nbjson
AttributeError: 'MarkdownProcessor' object has no attribute 'nbjson'

Check JSON structure inside notebook

attached image

  • 一つのセルに複数ついている場合の動作は?そもそもつけれる?

cell

  • アウトプットの種類は?
  • 畳んだときの動作は?
  • セルごと or セル内のmetadata は書き換えられる可能性ある?

metadata

  • ファイル全体のメタデータは書き換えられる可能性ある?

Improve upload function

Current

  • one function, "upload".

Preferable

  • small functions
  • retry acceptable

Concrete logic

  • list up all image refs using a relative path
  • upload all images
  • check the number of relative-path images

This way can separate

  • calling nbconvert
  • uploading an image each.

and they make able to

  • upload images which are not generated by jupyter kernel
  • retry.

無駄な空白行を削除するようにする

</summary>の後と、</details>の前の無駄な空白行が追加されてしまうのが気になる。

例↓

<details open>
<summary>[32]: code source</summary>


` ` `python
import numpy as np

def calc_theta(MFD, f):
    return MFD/f * 180/np.pi

# For test
print(f"test: {calc_theta(3.5e-6, 4.0e-3)} deg")
` ` `


</details>

markdown with details tag

The esa.io provides us <details> ... </details> tag.

Sometimes python code and result are too long to look roughly.

If code-block or result-block is longer than --fold-line-num, they should be enclosed with <details> ... </details> tag in the final markdown.

Make flowcharts

  • Convert process
    • ipynb file
    • md file
    • tex file
  • Upload process

support latex input

if figure caption includes reference (e.g. cross-ref), image tag in markdown is ignored in replace stage.

reduce post_info in metadata

post_info に記事の本体をいれとくとjupyterlabの拡張機能でmetadataを調べるとき邪魔
使ってないし除去してもよいだろう

Uploaded tag in metadata

Currently, even if once upload was succeeded, there is no record. Notebook files can store optional data as metadata. If an upload-experienced ipynb file is assigned for esa-up, it should update the post rather than create a new post.

titleなどをマジックコマンドで登録する

現在はUntitledでアップロード → 手動でタイトル・記事変更としていて手間である
例えばマジックコマンドで指定できるようにする。

@esapy_title sugoi_taitoru

もしくは、1セル目1行目の1st class headerをタイトル扱いにする

どちらの場合も生成される記事には残らないようにしたい

実行時にサブコマンドがない場合に発生するエラーのbugfix

esa -vや単にesaなどと実行時にサブコマンドを指定しない場合、次のようなエラーが発生した。

Traceback (most recent call last):
  File "c:\users\__username__\.conda\envs\qudi\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\__username__\.conda\envs\qudi\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\__username__\.conda\envs\qudi\Scripts\esa.exe\__main__.py", line 7, in <module>
  File "c:\users\__username__\.conda\envs\qudi\lib\site-packages\esapy\entrypoint.py", line 189, in main
    args.handler(args)
AttributeError: 'Namespace' object has no attribute 'handler'

bug at loading token

Preference:

  • If .esapyrc file doesn't exist,
  • the configuration should be loaded from environment variables.

Current:

  • When environs exist, but .esapyrc file doesn't exist,
  • FileNotFoundError occurred.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.