The Utils module

The utils module is the summary of all functionality needed by Nester.

We are planning to modularize and clean it up in the future.

This module provides all functions necessary for Nester’s three main utilities:

  • create

  • validate

  • clean

nester.utils.clean(project_name: str) None

Cleanup the given project.

Parameters:

project_name – The name of the project

nester.utils.create_structure(structure: dict, base_path: Path, project_name: str) None

Iterate through the items in the structure and create directories and files based on that structure

Parameters:
  • structure (dict) – the directory structure from the template

  • base_path (Path) – The current directory

  • project_name (str) – the name of the project

Returns:

None

nester.utils.detect_languages() list

Look through the templates folder to find which languages we have templates for

Returns:

List of languages that have template folders

Return type:

list

nester.utils.get_project_dir(project_name: str, should_create: bool) Path

Get the project root directory. If the name of the current working directory does not match the project_name, a new directory will be created with the given project_name inside which the project is created.

Parameters:
  • project_name (str) – the name of the project

  • should_create (bool) – if directory should be created or not

Returns:

the path of the project root

nester.utils.initialize_git_repository(project_dir: Path) None

Initialize `git` repository in project dir.

Parameters:

project_dir – Directory of the project to initialize git repository in.

nester.utils.load_json(language: str, project_name: str) dict

Load the template for the project.

Parameters:
  • language (str) – the programming language of the project

  • project_name (str) – the name of the project

Return structure:

Returns the structure of the given language as a dict

Return type:

dict

nester.utils.validate_structure(structure: dict, project_name: str, base_path: Path) bool

Iterates through the subdirectories of the current directory and validates if it is a subset of the schema for the given language.

Parameters:
  • structure (dict) – The directory structure from the template

  • base_path (Path) – The current directory

  • project_name (str) – The name of the project

Returns:

True or False depending on if the structure corresponds to the schema or not

Return type:

bool