Skip to content

Commit d171a74

Browse files
authored
Cython seq (#4500)
* Modify CyDifflib the same way we modified difflib Signed-off-by: Jono Yang <[email protected]> * Update assignment code Signed-off-by: Jono Yang <[email protected]> * Use unordered_map instead of vector Signed-off-by: Jono Yang <[email protected]> * Build seq.pyx on install and use as default * Ignore .so files in src/ Signed-off-by: Jono Yang <[email protected]> * Install cython in venv Signed-off-by: Jono Yang <[email protected]> * State argument types in function declarations Signed-off-by: Jono Yang <[email protected]> * Do not perform list comprehension when returning matching blocks Signed-off-by: Jono Yang <[email protected]> * Install cython in create_virtualenv function Signed-off-by: Jono Yang <[email protected]> * Update import in test_seq.py Signed-off-by: Jono Yang <[email protected]> * Add ABOUT and LICENSE file for seq.pyx Signed-off-by: Jono Yang <[email protected]> * Modify extend_match for use in Python Signed-off-by: Jono Yang <[email protected]> * Remove seq.pyx and import it as cyseq Signed-off-by: Jono Yang <[email protected]> * Do not install cython into the venv Signed-off-by: Jono Yang <[email protected]> * Remove unneeded gitignore rule Signed-off-by: Jono Yang <[email protected]> --------- Signed-off-by: Jono Yang <[email protected]>
1 parent e411b8b commit d171a74

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

configure

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ CFG_ROOT_DIR="$( cd "$( dirname "${CFG_BIN}" )" && pwd )"
118118

119119
CFG_BIN_DIR=$CFG_ROOT_DIR/$VIRTUALENV_DIR/bin
120120

121-
# force relaunching under X86-64 architecture on macOS M1/ARM
121+
# force relaunching under X86-64 architecture on macOS M1/ARM
122122
if [[ $OSTYPE == 'darwin'* && $(uname -m) == 'arm64' && $(sysctl -in sysctl.proc_translated) == 0 ]]; then
123123
arch -x86_64 /bin/bash -c "$CFG_ROOT_DIR/configure $*"
124124
exit $?
@@ -253,7 +253,6 @@ install_packages() {
253253
# be reinstalled a second time and reused from the virtualenv and this
254254
# speeds up the installation.
255255
# We always have the PEP517 build dependencies installed already.
256-
257256
"$CFG_BIN_DIR/pip" install \
258257
--upgrade \
259258
--no-build-isolation \

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ include = [
6969
"."
7070

7171
]
72-
# ignore test data and testfiles: they should never be linted nor formatted
72+
# ignore test data and testfiles: they should never be linted nor formatted
7373
exclude = [
7474
# main style
7575
"**/tests/data/**/*",

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ install_requires =
117117
typecode >= 30.0.1
118118
typecode[full] >= 30.0.1
119119
extractcode[full] >= 31.0.0
120+
cyseq; platform_system == 'Linux'
120121

121122

122123
[options.packages.find]

src/licensedcode/index.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@
2828
from licensedcode import match_spdx_lid
2929
from licensedcode import match_unknown
3030
from licensedcode.dmp import match_blocks as match_blocks_dmp
31-
from licensedcode.seq import match_blocks as match_blocks_seq
3231
from licensedcode import query
3332
from licensedcode import tokenize
3433
from licensedcode.spans import Span
3534
from typing import NamedTuple
3635
from typing import Callable
3736

37+
try:
38+
# Use Cython seq.py implementation
39+
from cyseq import match_blocks as match_blocks_seq
40+
except ImportError:
41+
# Use Python seq.py if it is not available
42+
from licensedcode.seq import match_blocks as match_blocks_seq
43+
3844
"""
3945
Main license index construction, query processing and matching entry points for
4046
license detection.

src/licensedcode/match_seq.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ def match_sequence(
6363
return []
6464

6565
if not match_blocks:
66-
from licensedcode.seq import match_blocks
66+
try:
67+
# Use Cython seq.py implementation
68+
from cyseq import match_blocks
69+
except ImportError:
70+
# Use Python seq.py if it is not available
71+
from licensedcode.seq import match_blocks
6772

6873
rid = rule.rid
6974
itokens = idx.tids_by_rid[rid]

0 commit comments

Comments
 (0)