Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
543ad82b
Commit
543ad82b
authored
Jul 21, 2021
by
di68kap
Browse files
some refactoring
parent
550161f5
Changes
3
Hide whitespace changes
Inline
Side-by-side
DHParser/scripts/dhparser_
build_
cython.py
→
DHParser/scripts/dhparser_cython
ize
.py
100755 → 100644
View file @
543ad82b
File moved
DHParser/scripts/dhparser_cythonize_stringview.py
0 → 100644
View file @
543ad82b
#!/usr/bin/env python3
# build.py - support for building cython extensions with poetry
import
os
import
sys
from
setuptools
import
setup
try
:
from
Cython.Build
import
cythonize
has_cython
=
True
except
ImportError
:
has_cython
=
False
def
cythonize
(
filename
,
**
options
):
return
[]
cythonize_modules
=
[
'DHParser/stringview.py'
,
# 'DHParser/toolkit.py',
# 'DHParser/preprocess.py',
# 'DHParser/error.py',
# 'DHParser/syntaxtree.py',
# 'DHParser/log.py',
# 'DHParser/parse.py',
# 'DHParser/trace.py',
# 'DHParser/transform.py',
# 'DHParser/compile.py',
# 'DHParser/ebnf.py',
]
def
build
(
setup_kwargs
=
{}):
if
has_cython
:
# find path of DHParser-module
scriptdir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
i
=
scriptdir
.
find
(
'DHParser'
)
k
=
len
(
'DHParser-submodule'
)
if
scriptdir
[
i
:].
startswith
(
'DHParser-submodule'
)
\
else
len
(
'DHParser'
)
if
i
>=
0
:
dhparserdir
=
scriptdir
[:
i
+
k
]
if
dhparserdir
not
in
sys
.
path
:
sys
.
path
.
append
(
dhparserdir
)
else
:
dhparserdir
=
''
save_cwd
=
os
.
getcwd
()
os
.
chdir
(
dhparserdir
)
# delete stale c and object-files
for
name
in
os
.
listdir
(
dhparserdir
):
if
name
.
endswith
(
'.c'
)
or
name
.
endswith
(
'.pyd'
)
or
name
.
endswith
(
'.so'
):
os
.
remove
(
name
)
# build cyhton modules inplace
sys
.
argv
.
extend
([
'build_ext'
,
'--inplace'
])
setup
(
name
=
'DHParser'
,
ext_modules
=
cythonize
(
cythonize_modules
,
nthreads
=
0
,
annotate
=
False
),
zip_safe
=
False
,
)
os
.
chdir
(
save_cwd
)
else
:
print
(
'DHParser.scripts.build_cython: Cannot build Cython modules, '
'because Cython has not installed!
\n
Try running: pip install cython'
)
if
__name__
==
"__main__"
:
build
()
DHParser/stringview.py
View file @
543ad82b
...
...
@@ -98,8 +98,8 @@ def fast_real_indices(begin: Optional[int],
"""Returns the tuple of real (i.e. positive) indices from the slice
indices `begin`, `end`, assuming a string of size `length`.
"""
#
cbegin = 0 if begin is None else begin
cbegin
=
begin
if
begin
else
0
cbegin
=
0
if
begin
is
None
else
begin
#
cbegin = begin if begin else 0
cend
=
length
if
end
is
None
else
end
return
pack_index
(
cbegin
,
length
),
pack_index
(
cend
,
length
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment