Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcddb8aa

Browse files
committed
add dev docs and format code
1 parent4938503 commitcddb8aa

File tree

8 files changed

+92
-35
lines changed

8 files changed

+92
-35
lines changed

‎.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
.doit.db*
12
src/midgy/_version.py
3+
settings.json
24

35
# Byte-compiled / optimized / DLL files
46
__pycache__/

‎dev.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
a collection of doit tasks for project specific actions
2+
3+
def task_format():
4+
run formatters on the code
5+
6+
return dict(actions=["hatch run format:code"])
7+
8+
def task_docs():
9+
build the docs
10+
11+
return dict(actions=["hatch run docs:build"], clean=["rm -rf site"])
12+
13+
def task_test():
14+
test midgy
15+
16+
return dict(actions=["hatch run test:cov"])
17+
18+
19+
def task_build():
20+
build the wheel and binaries
21+
22+
return dict(
23+
actions=["hatch build"],
24+
clean=["rm -rf dist"]
25+
)
26+
27+
def task_test_release():
28+
a test release to pypi
29+
30+
return dict(actions=[
31+
"rm -rf dist",
32+
"hatch build",
33+
"hatch publish -r repo"
34+
])
35+
36+
def task_release():
37+
a release to pypi
38+
39+
return dict(actions=[
40+
"rm -rf dist",
41+
"hatch build",
42+
"hatch publish"
43+
])
44+
45+
if __name__ == "__main__":
46+
import doit, sys
47+
doit.doit_cmd.DoitMain(doit.cmd_base.ModuleTaskLoader(globals())).run(sys.argv[1:])

‎docs/language/test_language.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
frompathlibimportPath
2+
23
frompytestimportmark
4+
35
importmidgy
46

57
HERE=Path(__file__).parent
68

7-
importmidgy.render,midgy.python
9+
importmidgy.python
10+
importmidgy.render
811

912

1013
defgen_tests():
@@ -35,6 +38,7 @@ def gen_tests():
3538
ifname:
3639
yield (file.stem,name), (i,o,parser)
3740

41+
3842
defget_description(tokens):
3943
fortokenintokens:
4044
iftoken.type=="paragraph_open":
@@ -47,7 +51,6 @@ def get_description(tokens):
4751
break
4852

4953

50-
5154
cases=dict(gen_tests())
5255

5356

‎pyproject.toml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
requires = ["hatchling","hatch-vcs"]
33
build-backend ="hatchling.build"
44

5-
65
[tool.hatch.build.targets.sdist]
76
[tool.hatch.build.targets.wheel]
87

@@ -49,18 +48,18 @@ Source = "https://github.com/deathbeds/midgy"
4948
[tool.hatch.version]
5049
source ="vcs"
5150

52-
[tool.hatch.metadata]
53-
allow-direct-references =true
54-
5551
[tool.hatch.build.hooks.vcs]
5652
version-file ="src/midgy/_version.py"
5753

5854
[tool.coverage.html]
5955
directory ="docs/coverage"
6056

6157
[tool.hatch.envs.test]
58+
description ="the testing environment"
6259
dependencies = ["pytest","pytest-cov","ruamel.yaml"]
63-
scripts = {run ="pytest" }
60+
61+
[tool.hatch.envs.test.scripts]
62+
cov ="pytest"
6463

6564
[tool.pytest.ini_options]
6665
addopts ="-pno:warnings -vv --cov=midgy --cov-report html:docs/coverage --ignore site"
@@ -69,8 +68,31 @@ addopts = "-pno:warnings -vv --cov=midgy --cov-report html:docs/coverage --ignor
6968
omit = ["*/__*__.py","*/_version.py","site/*"]
7069

7170
[tool.hatch.envs.docs]
71+
description ="the docs environment"
7272
dependencies = ["mkdocs","mkdocs-material","ruamel.yaml"]
7373

7474
[tool.hatch.envs.docs.scripts]
7575
build ="mkdocs build"
7676
serve ="mkdocs serve"
77+
78+
# formatting cause linting sucks
79+
[tool.isort]
80+
profile ="black"
81+
82+
[tool.black]
83+
line_length =100
84+
85+
[tool.hatch.envs.format]
86+
description ="the formatting environment"
87+
skip-install =true
88+
dependencies = ["black","isort"]
89+
90+
[tool.hatch.envs.format.scripts]
91+
code ="""
92+
isort .
93+
black .
94+
"""
95+
96+
[tool.doit]
97+
verbosity =2
98+
backend ="json"

‎src/midgy/__main__.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
frompathlibimportPath
21
fromargparseimportArgumentParser
2+
frompathlibimportPath
3+
34
from .runimportMarkdown
45

56
parser=ArgumentParser("midgy",description="run markdown files")
@@ -29,19 +30,7 @@
2930
defmain(parser=parser):
3031
fromsysimportargv
3132

32-
argv=argv[1:]
33-
ifargv[0]notinsubs:
34-
argv.insert(0,"run")
35-
36-
ns,_=parser.parse_known_args(argv)
37-
ns=vars(ns)
38-
39-
subparser=ns.pop("subparser")
40-
ifsubparserin {None,"run"}:
41-
from .runimportMarkdown
42-
43-
Markdown.load_argv(argv[1:])
44-
return
33+
Markdown.load_argv(argv[1:])
4534

4635

4736
if__name__=="__main__":

‎src/midgy/python.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def fence_pycon(self, token, env):
7575

7676
defformat(self,body):
7777
"""blacken the python"""
78-
fromblackimportformat_str,FileMode
78+
fromblackimportFileMode,format_str
7979

8080
returnformat_str(body,mode=FileMode())
8181

@@ -106,10 +106,7 @@ def non_code_block_string(self, env, next=None):
106106
map(escape,body),
107107
lead=lead,
108108
trail=trail,
109-
continuation=self.extend_continuations
110-
andenv.get("continued")
111-
and"\\"
112-
or"",
109+
continuation=self.extend_continuationsandenv.get("continued")and"\\"or"",
113110
)
114111

115112
defnon_code_comment(self,env,next=None):

‎src/midgy/render.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ class Renderer:
3939
config_key:str="py"
4040

4141
def__post_init__(self):
42-
frommdit_py_pluginsimportfootnote,deflist
43-
from .front_matterimport (
44-
_front_matter_lexer,
45-
_shebang_lexer,
46-
)
42+
frommdit_py_pluginsimportdeflist,footnote
43+
44+
from .front_matterimport_front_matter_lexer,_shebang_lexer
4745

4846
# our tangling system adds extra conventions to commonmark:
4947
## extend indented code to recognize doctest syntax in-line
@@ -95,8 +93,7 @@ def parse(self, src):
9593

9694
defparse_cells(self,body,*,include_cell_hr=True):
9795
yieldfrom (
98-
x[0]
99-
forxinself.walk_cells(self.parse(body),include_cell_hr=include_cell_hr)
96+
x[0]forxinself.walk_cells(self.parse(body),include_cell_hr=include_cell_hr)
10097
)
10198

10299
defprint(self,iter,io):
@@ -115,7 +112,7 @@ def render(self, src, format=False):
115112

116113
defrender_cells(self,src,*,include_cell_hr=True):
117114
tokens=self.parse(src)
118-
self=self.renderer_from_tokens(tokens)
115+
self=self.renderer_from_tokens(tokens)
119116
prior=self._init_env(src,tokens)
120117
prior_token=None
121118
source=prior.pop("source")

‎src/midgy/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""run and import markdown files as python"""
22
fromdataclassesimportdataclass
3+
34
fromimportnbimportNotebook
45

56
from .pythonimportPython
67

7-
88
__all__= ("Markdown","run")
99

1010

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp