src package

Subpackages

Submodules

src.config module

Module that loads the tool’s runtime configuration from a file and makes it accessible to other modules.

class src.config.Singleton(*args: Any, **kw: Dict[str, Any])[source]

Bases: object

Parameters:
  • args (Any) –

  • kw (Dict[str, Any]) –

static __new__(cls, *args: Any, **kw: Dict[str, Any])[source]
Parameters:
  • args (Any) –

  • kw (Dict[str, Any]) –

__dict__
__module__
__weakref__

list of weak references to the object (if defined)

class src.config.Context(*args: Any, **kw: Dict[str, Any])[source]

Bases: Singleton

Attributes:
settings: mapping of detected runtime configuration options to their

values. key naming scheme is <section>_<name>

config_file_name: str
config_file_locations: List[Path]
__init__()[source]
_read_config_file() ConfigParser[source]
Return type:

ConfigParser

_set_config_attributes() None[source]
Return type:

None

_transform_settings() None[source]
Return type:

None

_transform_setting(setting_name: str, new_type: Type[Any]) None[source]
Parameters:
  • setting_name (str) –

  • new_type (Type[Any]) –

Return type:

None

__annotations__
__module__
_instance

src.dashboard module

class src.dashboard.DashboardColumns(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

ID
NAME
COMMITS
LAST_UPDATE
BRANCHES
ISSUES
CONTRIBUTORS
USERS
STARS
LANGUAGES
LOC
__module__
class src.dashboard.Dashboard(oc: OpenCode)[source]

Bases: object

Parameters:

oc (OpenCode) –

dashboard_file_path: Path
pl_whitelist_path: Path
pl_whitelist_wiki_path: Path
pl_whitelist_manual: Set[str]
pl_blacklist_manual: Set[str]
repo_blacklist_manual: Set[int]
dashboard_columns: List[Tuple[str, Type]]
class dashboardColumns(id, Name, Commits, LastUpdate, Branches, Issues, Contributors, Users, Stars, Languages, LOC)

Bases: tuple

Parameters:
  • id (int) –

  • Name (str) –

  • Commits (int) –

  • LastUpdate (str) –

  • Branches (int) –

  • Issues (int) –

  • Contributors (int) –

  • Users (int) –

  • Stars (int) –

  • Languages (str) –

  • LOC (str) –

Branches: int

Alias for field number 4

Commits: int

Alias for field number 2

Contributors: int

Alias for field number 6

Issues: int

Alias for field number 5

LOC: str

Alias for field number 10

Languages: str

Alias for field number 9

LastUpdate: str

Alias for field number 3

Name: str

Alias for field number 1

Stars: int

Alias for field number 8

Users: int

Alias for field number 7

__annotations__
__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__match_args__
__module__
static __new__(_cls, id: int, Name: str, Commits: int, LastUpdate: str, Branches: int, Issues: int, Contributors: int, Users: int, Stars: int, Languages: str, LOC: str)

Create new instance of dashboardColumns(id, Name, Commits, LastUpdate, Branches, Issues, Contributors, Users, Stars, Languages, LOC)

Parameters:
  • id (int) –

  • Name (str) –

  • Commits (int) –

  • LastUpdate (str) –

  • Branches (int) –

  • Issues (int) –

  • Contributors (int) –

  • Users (int) –

  • Stars (int) –

  • Languages (str) –

  • LOC (str) –

__repr__()

Return a nicely formatted representation string

__slots__
_asdict()

Return a new dict which maps field names to their values.

_field_defaults
_fields
classmethod _make(iterable)

Make a new dashboardColumns object from a sequence or iterable

_replace(**kwds)

Return a new dashboardColumns object replacing specified fields with new values

id: int

Alias for field number 0

__init__(oc: OpenCode) None[source]
Parameters:

oc (OpenCode) –

Return type:

None

_load_pl_whitelist() Set[str][source]
Return type:

Set[str]

_maybe_create_pl_whitelist() bool[source]

cloc also counts stuff that’s not a PL, use a whitelist to filter its output

Return type:

bool

create_dashboard() None[source]
Return type:

None

_iter_dashboard() Iterable[dashboardColumns][source]
Return type:

Iterable[dashboardColumns]

pl_repo() None[source]
Return type:

None

pl_loc() None[source]
Return type:

None

_pl_print_cvs(result: List[Tuple[str, float]]) None[source]
Parameters:

result (List[Tuple[str, float]]) –

Return type:

None

run(args_dict: Dict[str, Any]) None[source]
Parameters:

args_dict (Dict[str, Any]) –

Return type:

None

__annotations__
__dict__
__module__
__weakref__

list of weak references to the object (if defined)

src.exceptions module

Exceptions that might be raised by core or check code.

exception src.exceptions.CoreGoesBoomException[source]

Bases: Exception

Raised if core code encounters an unrecoverable error (uncaught).

__module__
__weakref__

list of weak references to the object (if defined)

exception src.exceptions.CheckGoesBoomException[source]

Bases: Exception

Raise this exception if your check exploded. (at runtime)

__module__
__weakref__

list of weak references to the object (if defined)

exception src.exceptions.CheckConstructionException[source]

Bases: Exception

Raise this exception if your check’s constructor encountered some fatal error.

__module__
__weakref__

list of weak references to the object (if defined)

exception src.exceptions.CheckNotApplicableException[source]

Bases: Exception

Raise this exception if your check comes to the conclusion that it cannot produce a reasonable result for the griven project. (at runtime)

__module__
__weakref__

list of weak references to the object (if defined)

src.interfaces module

Collection of all interfaces

class src.interfaces.Named[source]

Bases: object

class property name: str

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

__dict__
__module__
__weakref__

list of weak references to the object (if defined)

class src.interfaces.CheckInterface(proj: Project, repo: Repo, api: Gitlab)[source]

Bases: Named

Represents a check that can be applied to a repository @schema: JSON schema that results of this check must adhere to

Parameters:
  • proj (Project) –

  • repo (Repo) –

  • api (Gitlab) –

exclude: Pattern[str] | None
__init__(proj: Project, repo: Repo, api: Gitlab)[source]
Parameters:
  • proj (Project) –

  • repo (Repo) –

  • api (Gitlab) –

_get_resource_dir() Path[source]
Returns:

The root of this check’s personal resource directory.

Return type:

Path

_load_results_schema() Dict[str, Any][source]
Return type:

Dict[str, Any]

_gen_file_list() Generator[Path, None, None][source]

Helper to generate a list of all _relevant_ files in a project. Skips all files whose - name matches the self.exclude pattern - path relative to the project root matches self.exclude_path pattern

Returns:

Iterator over all files in the project

Return type:

Generator[Path, None, None]

run(args_dict: Dict[str, Any] | None = None) Dict[str, Any][source]
Parameters:

args_dict (Dict[str, Any] | None) –

Return type:

Dict[str, Any]

property description: Dict[str, Any]
results_valid(results: Dict[str, Any]) bool[source]

Validates the tool-specific results of a run against the corresponding JSON schema returns: true iff the results match the schema

Parameters:

results (Dict[str, Any]) –

Return type:

bool

__annotations__
__module__

src.opencode module

Module which provides the methods that correspond to the subcommands of occmd

class src.opencode.OpenCode[source]

Bases: object

Class which provides the methods that correspond to the subcommands of occmd

url_opencode: str
apikey: str | None
p_db_raw: Path
__init__()[source]
property users: List[RESTObject] | RESTObjectList

returns: All users registered on the OpenCoDE platform Note: might not work if they change the API config

property projects: List[RESTObject] | RESTObjectList

returns: All projects listed on the OpenCoDE platform

get_project_by_id(_id: int) Project[source]

Get meta information about a project from its id

Parameters:

_id (int) –

Return type:

Project

get_repo_for_proj(proj: Project) Repo[source]
Parameters:

proj (Project) –

Return type:

Repo

iter_projects(filter_func: ~typing.Callable[[~gitlab.base.RESTObject, ~git.repo.base.Repo], bool] = <function OpenCode.<lambda>>, _id: int | None = None, directory: ~pathlib.Path | None = None) Generator[Tuple[RESTObject, Repo], None, None][source]
Parameters:
  • filter_func (Callable[[RESTObject, Repo], bool]) – skip project if this functions maps it to True

  • _id (int | None) – optional, Gitlab id of the project specified via ‘directory’ parameter

  • directory (Path | None) – optional, local file system location of git root of project specified via ‘id’ parameter

Returns:

Api objects and local repo objects for all projects on OpenCoDE. Optionally: Only generates a single tuple for the project specified by ‘id’ and ‘directory’ parameters.

Return type:

Generator[Tuple[RESTObject, Repo], None, None]

dashboard(*args, **kwargs) None[source]

Visualize the state of the platform as a table.

Return type:

None

graph()[source]

Visualize the state of the platform as a graph.

_construct_check_filter(check: str | None = None) Callable[[Type[CheckInterface]], bool][source]
returns:

Function on checks that returns True IFF the check should be skipped. Default: skip no checks

Parameters:

check (str | None) –

Return type:

Callable[[Type[CheckInterface]], bool]

_construct_repo_filter(repo_id: int | None = None) Callable[[RESTObject, Repo], bool][source]
returns:

Function on repository API instance and local instance that returns True IFF the repository should be skipped. Default: skip no repositories

Parameters:

repo_id (int | None) –

Return type:

Callable[[RESTObject, Repo], bool]

check(*args, **kwargs) None[source]

Performs a set of checks on a set of repositories.

Return type:

None

update(*args, **kwargs)[source]

Updates the local OpenCoDE mirror.

__annotations__
__dict__
__module__
__weakref__

list of weak references to the object (if defined)

src.opencode_git module

Module to interact with OpenCoDE platform via git command line tool

class src.opencode_git.OpenCodeGit[source]

Bases: object

Class to interact with OpenCoDE platform via git command line tool

username: str
apikey: str | None
classmethod clone_project(http_url: str, local_path: Path) None[source]
Parameters:
  • http_url (str) –

  • local_path (Path) –

Return type:

None

__annotations__
__dict__
__module__
__weakref__

list of weak references to the object (if defined)

src.utils module

src.utils.camel_to_snake(s: str) str[source]

Converts a string from CamelCase to snake_case. Does not handle many of the special cases.

Parameters:

s (str) –

Return type:

str

src.utils.dir_list(repo: Repo, dir_predicate: Callable[[str], bool]) Iterable[Path][source]

Searches the project for directories that match the dir_predicate. If a directory matches its subtree is not explored for more matching directories.

Parameters:
  • repo (Repo) – The local checkout of the project.

  • dir_predicate (Callable[[str], bool]) – Function that receives the directory name and returns True iff the spanned subtree should be yielded.

Return type:

Iterable[Path]

src.utils.file_list(repo: ~git.repo.base.Repo, file_name_filter: ~typing.Callable[[str], bool] = <function <lambda>>, path_component_filter: ~typing.Callable[[str], bool] = <function <lambda>>, root: ~pathlib.Path | None = None, recursive: bool = True) Iterable[Path][source]

Generates a list of all files in a project. Optionally, the yielded files can be filtered based on path components or file name. The function can also be restricted to a subtree.

Parameters:
  • repo (Repo) – The local checkout of the project.

  • file_name_filter (Callable[[str], bool]) – Function that receives a file name and returns True iff the file should be skipped.

  • path_component_filter (Callable[[str], bool]) – Function that receives the name of a directory and returns True iff the whole directory should be skipped.

  • root (Path | None) – Optionally, search only the subtree rooted at root

  • recursive (bool) – Iterate through folders recursively

Returns:

Iterator over all files in the project

Return type:

Iterable[Path]

src.utils.get_publiccode_cfg(repo: Repo) Path | None[source]

Tries to find the OpenCoDE configuration file in the repository.

Parameters:

repo (Repo) – The local checkout of the project.

Returns:

path of the file or None if it does not exist.

Return type:

Path | None

Module contents