Skip to content

Commit eb28308

Browse files
authored
func: convert ipynb to markdown (#1)
Signed-off-by: xiexianbin <me@xiexianbin.cn>
1 parent 74bd88a commit eb28308

13 files changed

Lines changed: 208 additions & 99 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,4 @@ cython_debug/
162162
# self define
163163
.DS_Store
164164
.history
165+
.vscode

ChangeLog

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
CHANGES
22
=======
33

4-
v0.1.0
5-
------
6-
7-
* feautre: base func, convert ipynb to hugo markdown files
8-
* init commit
4+
* init
5+
* Initial commit

Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ FROM ubuntu:22.04
33
# Dockerfile build cache
44
ENV REFRESHED_AT 2023-05-07
55

6-
LABEL "com.github.actions.name"="nbcli"
7-
LABEL "com.github.actions.description"="nbcli"
6+
LABEL "com.github.actions.name"="nbctl"
7+
LABEL "com.github.actions.description"="nbctl"
88
LABEL "com.github.actions.icon"="chevrons-right"
99
LABEL "com.github.actions.color"="blue"
10-
LABEL "repository"="http://github.com/x-actions/python3-nbcli"
11-
LABEL "homepage"="http://github.com/x-actions/python3-nbcli"
10+
LABEL "repository"="http://github.com/x-actions/python3-nbctl"
11+
LABEL "homepage"="http://github.com/x-actions/python3-nbctl"
1212
LABEL "maintainer"="xiexianbin<me@xiexianbin.cn>"
1313

14-
LABEL "Name"="nbcli"
14+
LABEL "Name"="nbctl"
1515
LABEL "Version"="1.0.0"
1616

1717
ENV LC_ALL C.UTF-8
@@ -20,10 +20,10 @@ ENV LANGUAGE en_US.UTF-8
2020

2121
# apt install -y docker-ce docker-ce-cli containerd.io; systemctl start docker
2222
RUN apt update && \
23-
apt install -y git python3 python3-pip skopeo jq && \
23+
apt install -y git python3 python3-pip && \
2424
cd ~ && \
25-
git clone https://github.com/x-actions/python3-nbcli.git && \
26-
cd python3-nbcli && \
25+
git clone https://github.com/x-actions/python3-nbctl.git && \
26+
cd python3-nbctl && \
2727
git checkout v1 && \
2828
pip3 install -r requirements.txt && \
2929
python3 setup.py --version && \

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
# python3-nbcli
1+
# python3-nbctl
22

3-
将ipynb文件转化为hugo markdown文件/Convert ipynb to hugo markdown files
3+
将ipynb文件转化为markdown文件/convert jupyter *.ipynb file to markdown files
44

5-
[![PyPI-python3-nbcli](https://img.shields.io/pypi/v/python3-nbcli.svg?maxAge=3600)](https://pypi.org/project/python3-nbcli/)
5+
[![PyPI-python3-nbctl](https://img.shields.io/pypi/v/python3-nbctl.svg?maxAge=3600)](https://pypi.org/project/python3-nbctl/)
66

7-
Github Actions for [Container Images Sync](https://github.com/marketplace/actions/nbcli)
7+
Github Actions for [Container ipynb to markdown](https://github.com/marketplace/actions/nbctl)
88

99
## How to Use by Github Actions
1010

1111
```
12-
- name: convert ipynb to hugo markdown
13-
uses: x-actions/python3-nbcli@v1
12+
- name: convert jupyter *.ipynb file to markdown
13+
uses: x-actions/python3-nbctl@v1
14+
with:
15+
script: >
16+
find <path> -type f -name "*.ipynb" | grep -v ".ipynb_checkpoints" | xargs -I{} nbctl --input {} --force --debug
1417
```
1518

1619
## Dev and Test
@@ -23,8 +26,11 @@ pip3 install -r requirements.txt
2326
python3 setup.py install
2427
2528
# or
26-
pip3 install python3-nbcli
29+
pip3 install python3-nbctl
30+
```
31+
32+
- help
2733

28-
# run
29-
cisctl
34+
```
35+
nbctl --help
3036
```

action.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
name: 'convert ipynb to hugo markdown'
2-
description: 'nbcli'
1+
name: 'nbctl'
2+
description: 'convert jupyter *.ipynb file to markdown'
33
author: 'xiexianbin <me@xiexianbin>'
44
inputs:
5-
LOG_LEVEL:
5+
log:
66
description: 'logger level, value [DEBUG|INFO|WARN|ERROR|FATAL]'
77
default: 'DEBUG'
8+
script:
9+
description: 'script to run'
10+
default: 'find . -type f -name "*.ipynb" | xargs -I{} nbctl --input {} -f'
11+
812
runs:
913
using: 'docker'
1014
image: 'Dockerfile'

entrypoint.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
#!/bin/bash
22
set -e
33

4-
export LOG_LEVEL=${LOG_LEVEL:-"DEBUG"}
4+
export LOG_LEVEL=${INPUT_LOG:-"DEBUG"}
5+
export INPUT_SCRIPT=${INPUT_SCRIPT:-"echo `date`"}
56

7+
echo $(pwd)
68
echo "## Check Package Version ##################"
79
bash --version
810
git version
911

10-
nbcli
12+
echo "env is:"
13+
env
14+
15+
echo "## Run nbctl ##################"
16+
17+
eval ${INPUT_SCRIPT}

nbcli/shell.py

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
__all__ = ['__version__']
1818

1919

20-
version_info = pbr.version.VersionInfo('python3-nbcli')
20+
version_info = pbr.version.VersionInfo('python3-nbctl')
2121
# We have a circular import problem when we first run python setup.py sdist
2222
# It's harmless, so deflect it.
2323
try:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616

1717
CURRENT_PATH = os.getcwd()
1818
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'DEBUG')
19+
DEFAULT_LOG_LEVEL = "INFO"

nbcli/logger.py renamed to nbctl/logger.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@
1919
from nbctl import constants
2020

2121

22-
def gen_logger():
22+
def gen_logger(level=constants.LOG_LEVEL):
2323
# create logger
24-
if constants.LOG_LEVEL == 'DEBUG':
24+
if level == 'DEBUG':
2525
log_level = logging.DEBUG
26-
elif constants.LOG_LEVEL == 'INFO':
26+
elif level == 'INFO':
2727
log_level = logging.INFO
28-
elif constants.LOG_LEVEL == 'WARN':
28+
elif level == 'WARN':
2929
log_level = logging.WARN
30-
elif constants.LOG_LEVEL == 'ERROR':
30+
elif level == 'ERROR':
3131
log_level = logging.ERROR
32-
elif constants.LOG_LEVEL == 'FATAL':
32+
elif level == 'FATAL':
3333
log_level = logging.FATAL
3434
else:
3535
log_level = logging.DEBUG
3636
formatter = logging.Formatter(
37-
fmt="%(asctime)-15s %(process)d %(levelname)s %(message)s - %(filename)s %(lineno)d",
37+
fmt="%(asctime)-15s %(process)d - %(filename)s:%(lineno)d %(levelname)s %(message)s",
3838
datefmt="%a %d %b %Y %H:%M:%S")
3939

40-
_logger = logging.getLogger(name="cis")
40+
_logger = logging.getLogger(name="nbctl")
4141
_logger.setLevel(log_level)
4242

43-
fh = logging.FileHandler(filename="cis.log")
44-
fh.setLevel(log_level)
45-
fh.setFormatter(formatter)
46-
_logger.addHandler(fh)
43+
# fh = logging.FileHandler(filename="nbctl.log")
44+
# fh.setLevel(log_level)
45+
# fh.setFormatter(formatter)
46+
# _logger.addHandler(fh)
4747

4848
oh = logging.StreamHandler(sys.stdout)
4949
oh.setLevel(log_level)
@@ -52,4 +52,4 @@ def gen_logger():
5252
return _logger
5353

5454

55-
logger = gen_logger()
55+
logger = gen_logger(constants.DEFAULT_LOG_LEVEL)

0 commit comments

Comments
 (0)