Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/licensedcode/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from intbitset import intbitset

import typecode

from commoncode.text import toascii
from licensedcode.spans import Span
Expand Down Expand Up @@ -120,6 +119,7 @@ def build_query(
Return a Query built from location or query string given an index.
"""
if location:
import typecode
T = typecode.get_type(location)
# TODO: implement additional type-driven heuristics for query chunking.
if not T.contains_text:
Expand Down Expand Up @@ -584,6 +584,7 @@ def _tokenize_and_build_runs(self, tokens_by_line, line_threshold=4):
query_runs_append = self.query_runs.append

if self.location:
import typecode
ft = typecode.get_type(self.location)
if ft.is_text_with_long_lines:
self.has_long_lines = True
Expand Down
4 changes: 2 additions & 2 deletions src/scancode/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import os
import sys

from license_expression import combine_expressions
from commoncode.filetype import get_last_modified_date
from commoncode.hash import multi_checksums
from scancode import ScancodeError
from typecode.contenttype import get_type

TRACE = os.environ.get('SCANCODE_DEBUG_API', False)

Expand Down Expand Up @@ -179,7 +179,6 @@ def get_licenses(
from licensedcode.cache import build_spdx_license_expression
from licensedcode.cache import get_cache
from licensedcode.detection import detect_licenses
from packagedcode.utils import combine_expressions

license_clues = []
license_detections = []
Expand Down Expand Up @@ -340,6 +339,7 @@ def get_file_info(location, **kwargs):
"""
Return a mapping of file information collected for the file at `location`.
"""
from typecode.contenttype import get_type
result = {}

# TODO: move date and size these to the inventory collection step???
Expand Down
3 changes: 2 additions & 1 deletion src/textcode/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import unicodedata

import chardet
import typecode

from textcode import pdf
from textcode import markup
Expand Down Expand Up @@ -86,6 +85,7 @@ def numbered_text_lines(
logger_debug('numbered_text_lines:', 'plain_text')
return enumerate(unicode_text_lines(location), start_line)

import typecode
T = typecode.get_type(location)

if TRACE:
Expand Down Expand Up @@ -184,6 +184,7 @@ def unicode_text_lines_from_binary(location):
Return an iterable over unicode text lines extracted from a binary file at
location.
"""
import typecode
T = typecode.get_type(location)
if T.contains_text:
for line in strings.strings_from_file(location):
Expand Down
12 changes: 12 additions & 0 deletions tests/scancode/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#

import os
import subprocess
import sys

from commoncode.testcase import FileBasedTesting
from scancode import api
Expand Down Expand Up @@ -144,3 +146,13 @@ def test_get_license_returns_correct_lines(self):
assert results['detected_license_expression'] == 'mit'
assert results['license_detections'][0]['matches'][0]['start_line'] == 2
assert results['license_detections'][0]['matches'][0]['end_line'] == 4

def test_get_licenses_imports_without_heavy_dependencies(self):
script = (
'import sys; '
'from scancode.api import get_licenses; '
'assert "typecode" not in sys.modules; '
'assert "extractcode" not in sys.modules; '
'assert "packagedcode" not in sys.modules'
)
subprocess.check_call([sys.executable, '-c', script])
Loading