Skip to content

Commit 1ef2543

Browse files
authored
refactor: convert camelCase to snake_case (#37)
Purposes: 1. To match typical modern Python coding styles (recommended by PEP 8) 2. To prepare for argparse usage, which uses snake_case for default dests Via https://ast-grep.github.io/, with rule: ``` id: _ language: python rule: pattern: $ID kind: identifier all: - regex: '^[^A-Z]' # not PascalCase - regex: '[a-z][A-Z]' # has camelCase transition not: any: # backcompat (part of cog module API) - regex: ^sOut$ - inside: kind: attribute has: field: object regex: \.cogmodule$ # unittest methods - regex: ^assert - regex: ^setUp$ - regex: ^tearDown$ - regex: ^addCleanup$ transform: ID_SNAKE: convert: source: $ID toCase: snakeCase UNDERSCORE: replace: source: $ID replace: '^(_)?.*' by: '$1' fix: $UNDERSCORE$ID_SNAKE ``` plus manual review of all changes
1 parent 5a6f8c1 commit 1ef2543

File tree

8 files changed

+736
-736
lines changed

8 files changed

+736
-736
lines changed

cogapp/cogapp.py

Lines changed: 230 additions & 230 deletions
Large diffs are not rendered by default.

cogapp/makefiles.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import os.path
44

5-
from .whiteutils import reindentBlock
5+
from .whiteutils import reindent_block
66

77

8-
def makeFiles(d, basedir="."):
8+
def make_files(d, basedir="."):
99
"""Create files from the dictionary `d` in the directory named by `basedir`."""
1010
for name, contents in d.items():
1111
child = os.path.join(basedir, name)
@@ -14,14 +14,14 @@ def makeFiles(d, basedir="."):
1414
if isinstance(contents, bytes):
1515
mode += "b"
1616
with open(child, mode) as f:
17-
f.write(reindentBlock(contents))
17+
f.write(reindent_block(contents))
1818
else:
1919
if not os.path.exists(child):
2020
os.mkdir(child)
21-
makeFiles(contents, child)
21+
make_files(contents, child)
2222

2323

24-
def removeFiles(d, basedir="."):
24+
def remove_files(d, basedir="."):
2525
"""Remove the files created by `makeFiles`.
2626
2727
Directories are removed if they are empty.
@@ -32,6 +32,6 @@ def removeFiles(d, basedir="."):
3232
if isinstance(contents, (bytes, str)):
3333
os.remove(child)
3434
else:
35-
removeFiles(contents, child)
35+
remove_files(contents, child)
3636
if not os.listdir(child):
3737
os.rmdir(child)

0 commit comments

Comments
 (0)