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]) –

Return type:

Singleton

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

  • kw (dict[str, Any]) –

Return type:

Singleton

__dict__
__module__
__weakref__

list of weak references to the object

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
__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

src.exceptions module

Exceptions that might be raised by core or check code.

exception src.exceptions.CoreGoesBoomError[source]

Bases: Exception

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

__module__
__weakref__

list of weak references to the object

exception src.exceptions.CheckGoesBoomError[source]

Bases: Exception

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

__module__
__weakref__

list of weak references to the object

exception src.exceptions.CheckConstructionError[source]

Bases: Exception

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

__module__
__weakref__

list of weak references to the object

exception src.exceptions.CheckNotApplicableError[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

src.interfaces module

Collection of all interfaces

class src.interfaces.Named[source]

Bases: object

classmethod name() str[source]
Return type:

str

__dict__
__module__
__weakref__

list of weak references to the object

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[Project]

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]

Get the local repository for a remote project from the local OpenCoDE dump.

Parameters:

proj (Project) –

Return type:

Repo

clone_repo_for_proj(proj: Project) Repo[source]

Get the local repository for a remote project via cloning to temporary directory

Parameters:

proj (Project) –

Return type:

Repo

iter_projects(filter_func: ~collections.abc.Callable[[~gitlab.v4.objects.projects.Project, ~git.repo.base.Repo], bool] = <function OpenCode.<lambda>>, _id: int | None = None, directory: ~pathlib.Path | None = None) Generator[tuple[Project, Repo], None, None][source]
Parameters:
  • filter_func (Callable[[Project, 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[Project, Repo], None, None]

dashboard(cli_args: Namespace, /, *_: Any, **__: Any) None[source]

Visualize the state of the platform as a table.

Parameters:
  • cli_args (Namespace) –

  • _ (Any) –

  • __ (Any) –

Return type:

None

graph() None[source]

Visualize the state of the platform as a graph.

Return type:

None

_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(cli_args: Namespace, /, *_: Any, **__: Any) None[source]

Performs a set of checks on a set of repositories.

Parameters:
  • cli_args (Namespace) –

  • _ (Any) –

  • __ (Any) –

Return type:

None

update(*_: Any, **__: Any) None[source]

Updates the local OpenCoDE mirror.

Parameters:
  • _ (Any) –

  • __ (Any) –

Return type:

None

__annotations__
__dict__
__module__
__weakref__

list of weak references to the object

src.opencode_git module

Module to interact with OpenCoDE platform via git command line tool

src.opencode_git.clone_project(http_url: str, local_path: Path) None[source]
Parameters:
  • http_url (str) –

  • local_path (Path) –

Return type:

None

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: ~collections.abc.Callable[[str], bool] = <function <lambda>>, path_component_filter: ~collections.abc.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