in uberpoet/loccalc.py [0:0]
def calculate_loc(self, text, language):
# actual code = lines of code, minus whitespace
# calculated using cloc
if language == Language.SWIFT:
extension = '.swift'
elif language == Language.OBJC:
extension = '.m'
else:
raise ValueError("Unknown language: {}".format(language))
tmp_file_path = join(tempfile.gettempdir(), 'ub_mock_gen_example_file{}'.format(extension))
with open(tmp_file_path, 'w') as f:
f.write(text)
loc = count_loc(tmp_file_path, language)
if loc == -1:
logging.warning("Using fallback loc calc method due to cloc not being installed.")
if language == Language.SWIFT:
# fallback if cloc is not installed
# this fallback is based on running cloc on the file made by `self.swift_gen.gen_file(3, 3)`
# and saving the result of cloc(file_result.text) / file_result.text_line_count to here:
fallback_code_multiplier = 0.811537333
elif language == Language.OBJC:
# fallback if cloc is not installed
# this fallback is based on running cloc on the file made by `self.objc_source_gen.gen_file(3, 3)`
# and saving the result of cloc(file_result.text) / file_result.text_line_count to here:
fallback_code_multiplier = 0.772727272
else:
raise ValueError('No fallback multiplier calculated for language: {}'.format(language))
loc = int(ceil(len(text.split('\n')) * fallback_code_multiplier))
return loc