Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-dev-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-dev-tools
Commits
1287a348
Commit
1287a348
authored
5 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
check_spelling: add support for checking strings
parent
6d77e2f0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
check_source/check_spelling.py
+57
-11
57 additions, 11 deletions
check_source/check_spelling.py
utils/blender_merge_format_changes.py
+1
-1
1 addition, 1 deletion
utils/blender_merge_format_changes.py
with
58 additions
and
12 deletions
check_source/check_spelling.py
+
57
−
11
View file @
1287a348
...
...
@@ -21,8 +21,10 @@
"""
Script for checking source code spelling.
python3 source/tools/check_source/check_spelling
_c
.py some_soure_file.py
python3 source/tools/check_source/check_spelling.py some_soure_file.py
- Pass in a path for it to be checked recursively.
- Pass in
'
--strings
'
to check strings instead of comments.
Currently only python source is checked.
"""
...
...
@@ -144,6 +146,38 @@ class Comment:
return
words_from_text
(
self
.
text
)
def
extract_code_strings
(
filepath
):
import
pygments
from
pygments
import
lexers
from
pygments.token
import
Token
comments
=
[]
code_words
=
set
()
# lex = lexers.find_lexer_class_for_filename(filepath)
# if lex is None:
# return comments, code_words
if
filepath
.
endswith
(
"
.py
"
):
lex
=
lexers
.
get_lexer_by_name
(
"
python
"
)
else
:
lex
=
lexers
.
get_lexer_by_name
(
"
c
"
)
slineno
=
1
with
open
(
filepath
,
encoding
=
'
utf-8
'
)
as
fh
:
source
=
fh
.
read
()
for
ty
,
ttext
in
lex
.
get_tokens
(
source
):
if
ty
in
{
Token
.
Literal
.
String
,
Token
.
Literal
.
String
.
Double
,
Token
.
Literal
.
String
.
Single
}:
comments
.
append
(
Comment
(
filepath
,
ttext
,
slineno
,
'
STRING
'
))
else
:
for
match
in
re_vars
.
finditer
(
ttext
):
code_words
.
add
(
match
.
group
(
0
))
# Ugh - not nice or fast.
slineno
+=
ttext
.
count
(
"
\n
"
)
return
comments
,
code_words
def
extract_py_comments
(
filepath
):
import
token
...
...
@@ -326,12 +360,15 @@ def extract_c_comments(filepath):
return
comments
,
code_words
def
spell_check_
comments
(
filepath
):
def
spell_check_
file
(
filepath
,
check_type
=
'
COMMENTS
'
):
if
filepath
.
endswith
(
"
.py
"
):
comment_list
,
code_words
=
extract_py_comments
(
filepath
)
else
:
comment_list
,
code_words
=
extract_c_comments
(
filepath
)
if
check_type
==
'
COMMENTS
'
:
if
filepath
.
endswith
(
"
.py
"
):
comment_list
,
code_words
=
extract_py_comments
(
filepath
)
else
:
comment_list
,
code_words
=
extract_c_comments
(
filepath
)
elif
check_type
==
'
STRINGS
'
:
comment_list
,
code_words
=
extract_code_strings
(
filepath
)
for
comment
in
comment_list
:
for
w
in
comment
.
parse
():
...
...
@@ -375,7 +412,7 @@ def spell_check_comments(filepath):
))
def
spell_check_
comments
_recursive
(
dirpath
):
def
spell_check_
file
_recursive
(
dirpath
,
check_type
=
'
COMMENTS
'
):
from
os.path
import
join
,
splitext
def
source_list
(
path
,
filename_check
=
None
):
...
...
@@ -408,17 +445,26 @@ def spell_check_comments_recursive(dirpath):
})
for
filepath
in
source_list
(
dirpath
,
is_source
):
spell_check_
comments
(
filepath
)
spell_check_
file
(
filepath
,
check_type
=
check_type
)
import
sys
import
os
if
__name__
==
"
__main__
"
:
for
filepath
in
sys
.
argv
[
1
:]:
# TODO, use argparse to expose more options.
args
=
sys
.
argv
[
1
:]
try
:
args
.
remove
(
"
--strings
"
)
check_type
=
'
STRINGS
'
except
ValueError
:
check_type
=
'
COMMENTS
'
print
(
check_type
)
for
filepath
in
args
:
if
os
.
path
.
isdir
(
filepath
):
# recursive search
spell_check_
comments
_recursive
(
filepath
)
spell_check_
file
_recursive
(
filepath
,
check_type
=
check_type
)
else
:
# single file
spell_check_
comments
(
filepath
)
spell_check_
file
(
filepath
,
check_type
=
check_type
)
This diff is collapsed.
Click to expand it.
utils/blender_merge_format_changes.py
+
1
−
1
View file @
1287a348
...
...
@@ -88,7 +88,7 @@ if code != 0:
os
.
system
(
'
git
'
+
mode_cmd
+
'
'
+
recursive_format_commit_merge_options
+
'
'
+
format_commits
[
-
1
])
paths
=
get_string
((
'
git
'
,
'
--no-pager
'
,
'
diff
'
,
'
--name-only
'
,
format_commits
[
-
1
])).
replace
(
'
\n
'
,
'
'
)
if
sys
.
platform
==
'
win32
'
and
len
(
paths
)
>
8000
:
# Windows commandline does not accept more than 8191 chars.
..
# Windows command
-
line does not accept more than 8191 chars.
os
.
system
(
'
make format
'
)
else
:
os
.
system
(
'
make format PATHS=
"'
+
paths
+
'"'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment