-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace FileLanguage class with a Language enum
- Avoids referencing languages by name (as strings). - Enables multiple constructors (from_path and from_ext). - Enables a dedicated sentinel value (UNKNOWN) instead of None. Signed-off-by: John Pennycook <[email protected]>
- Loading branch information
Showing
6 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright (C) 2019-2024 Intel Corporation | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import os | ||
from enum import Enum, auto | ||
|
||
|
||
class Language(Enum): | ||
ASM = auto() | ||
C = auto() | ||
CPLUSPLUS = auto() | ||
FORTRAN_FREE = auto() | ||
FORTRAN_MIXED = auto() | ||
UNKNOWN = auto() | ||
|
||
@classmethod | ||
def from_extension(cls, ext: str) -> "Language": | ||
if ext in [".s", ".S", ".asm"]: | ||
return cls.ASM | ||
|
||
if ext in [".c", ".h"]: | ||
return cls.C | ||
|
||
if ext in [ | ||
".c++", | ||
".cxx", | ||
".cpp", | ||
".cc", | ||
".hpp", | ||
".hxx", | ||
".h++", | ||
".hh", | ||
".inc", | ||
".inl", | ||
".tcc", | ||
".icc", | ||
".ipp", | ||
".cu", | ||
".cuh", | ||
".cl", | ||
]: | ||
return cls.CPLUSPLUS | ||
|
||
if ext in [".f90", ".F90"]: | ||
return cls.FORTRAN_FREE | ||
|
||
if ext in [".f", ".ftn", ".fpp", ".F", ".FOR", ".FTN", ".FPP"]: | ||
return cls.FORTRAN_FIXED | ||
|
||
return cls.UNKNOWN | ||
|
||
@classmethod | ||
def from_path(cls, path: str) -> "Language": | ||
ext = os.path.splitext(path)[1] | ||
return cls.from_extension(ext) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,12 @@ | |
author="John Pennycook", | ||
author_email="[email protected]", | ||
url="https://www.github.com/intel/code-base-investigator", | ||
packages=["codebasin", "codebasin.schema", "codebasin.walkers"], | ||
packages=[ | ||
"codebasin", | ||
"codebasin.source", | ||
"codebasin.schema", | ||
"codebasin.walkers", | ||
], | ||
include_package_data=True, | ||
scripts=["codebasin.py"], | ||
classifiers=[ | ||
|