piel.file_system#

Module Contents#

Functions#

check_path_exists(→ bool)

Checks if a directory exists.

check_example_design(→ bool)

We copy the example simple_design from docs to the /foss/designs in the iic-osic-tools environment.

copy_source_folder(→ None)

Copies the files from a source_directory to a target_directory

copy_example_design(→ None)

We copy the example simple_design from docs to the /foss/designs in the iic-osic-tools environment.

create_new_directory(→ bool)

Creates a new directory.

create_piel_home_directory(→ None)

Creates the piel home directory.

delete_path(→ None)

Deletes a path.

delete_path_list_in_directory(→ None)

Deletes a list of files in a directory.

get_files_recursively_in_directory(path[, extension])

Returns a list of files in a directory.

get_id_map_directory_dictionary(path_list, target_prefix)

Returns a dictionary of ids to directories.

get_top_level_script_directory(→ pathlib.Path)

Attempts to return the top-level script directory when this file is run,

list_prefix_match_directories(output_directory, ...)

Returns a list of directories that match a prefix.

permit_script_execution(→ None)

Permits the execution of a script.

permit_directory_all(→ None)

Permits a directory to be read, written and executed. Use with care as it can be a source for security issues.

read_json(→ dict)

Reads a JSON file.

rename_file(→ None)

Renames a file.

rename_files_in_directory(→ None)

Renames all files in a directory.

replace_string_in_file(file_path, match_string, ...)

Replaces a string in a file.

replace_string_in_directory_files(target_directory, ...)

Replaces a string in all files in a directory.

return_path(→ pathlib.Path)

Returns a pathlib.Path to be able to perform operations accordingly internally.

run_script(→ None)

Runs a script on the filesystem script_path.

write_file(→ None)

Records a script_name in the scripts project directory.

check_path_exists(path: piel.types.piel_path_types, raise_errors: bool = False) bool[source]#

Checks if a directory exists.

Parameters:

path (piel_path_types) – Input path.

Returns:

True if directory exists.

Return type:

directory_exists(bool)

check_example_design(design_name: str = 'simple_design', designs_directory: piel.types.piel_path_types | None = None) bool[source]#

We copy the example simple_design from docs to the /foss/designs in the iic-osic-tools environment.

Parameters:
  • design_name (str) – Name of the design to check.

  • designs_directory (piel_path_types) – Directory that contains the DESIGNS environment flag.

  • TODO (#) –

Returns:

None

copy_source_folder(source_directory: piel.types.piel_path_types, target_directory: piel.types.piel_path_types) None[source]#

Copies the files from a source_directory to a target_directory

Parameters:
  • source_directory (piel_path_types) – Source directory.

  • target_directory (piel_path_types) – Target directory.

Returns:

None

copy_example_design(project_source: Literal[piel, openlane] = 'piel', example_name: str = 'simple_design', target_directory: piel.types.piel_path_types = None, target_project_name: str | None = None) None[source]#

We copy the example simple_design from docs to the /foss/designs in the iic-osic-tools environment.

Parameters:
  • project_source (str) – Source of the project.

  • example_name (str) – Name of the example design.

  • target_directory (piel_path_types) – Target directory.

  • target_project_name (str) – Name of the target project.

Returns:

None

create_new_directory(directory_path: str | pathlib.Path, overwrite: bool = False) bool[source]#

Creates a new directory.

If the parents of the target_directory do not exist, they will be created too.

Parameters:
  • overwrite – Overwrite directory if it already exists.

  • directory_path (str | pathlib.Path) – Input path.

Returns:

None

create_piel_home_directory() None[source]#

Creates the piel home directory.

Returns:

None

delete_path(path: str | pathlib.Path) None[source]#

Deletes a path.

Parameters:

path (str | pathlib.Path) – Input path.

Returns:

None

delete_path_list_in_directory(directory_path: piel.types.piel_path_types, path_list: list, ignore_confirmation: bool = False, validate_individual: bool = False) None[source]#

Deletes a list of files in a directory.

Usage:

```python delete_path_list_in_directory(

directory_path=directory_path, path_list=path_list, ignore_confirmation=True

)#

param directory_path:

Input path.

type directory_path:

piel_path_types

param path_list:

List of files.

type path_list:

list

param ignore_confirmation:

Ignore confirmation. Default: False.

type ignore_confirmation:

bool

param validate_individual:

Validate individual files. Default: False.

type validate_individual:

bool

returns:

None

get_files_recursively_in_directory(path: piel.types.piel_path_types, extension: str = '*')[source]#

Returns a list of files in a directory.

Usage:

get_files_recursively_in_directory(‘path/to/directory’, ‘extension’)

Parameters:
  • path (piel_path_types) – Input path.

  • extension (str) – File extension.

Returns:

List of files.

Return type:

file_list(list)

get_id_map_directory_dictionary(path_list: list[piel.types.piel_path_types], target_prefix: str)[source]#

Returns a dictionary of ids to directories.

Usage:

get_id_to_directory_dictionary(path_list, target_prefix)

Parameters:
  • path_list (list[piel_path_types]) – List of paths.

  • target_prefix (str) – Target prefix.

Returns:

Dictionary of ids to directories.

Return type:

id_dict(dict)

get_top_level_script_directory() pathlib.Path[source]#

Attempts to return the top-level script directory when this file is run, compatible with various execution environments like Jupyter Lab, pytest, PDM, etc. TODO run full verification.

Returns:

Top level script directory.

Return type:

top_level_script_directory(pathlib.Path)

list_prefix_match_directories(output_directory: piel.types.piel_path_types, target_prefix: str)[source]#

Returns a list of directories that match a prefix.

Usage:

list_prefix_match_directories(‘path/to/directory’, ‘prefix’)

Parameters:
  • output_directory (piel_path_types) – Output directory.

  • target_prefix (str) – Target prefix.

Returns:

List of directories.

Return type:

matching_dirs(list)

permit_script_execution(script_path: piel.types.piel_path_types) None[source]#

Permits the execution of a script.

Usage:

permit_script_execution(‘path/to/script’)

Parameters:

script_path (piel_path_types) – Script path.

Returns:

None

permit_directory_all(directory_path: piel.types.piel_path_types) None[source]#

Permits a directory to be read, written and executed. Use with care as it can be a source for security issues.

Usage:

permit_directory_all(‘path/to/directory’)

Parameters:

directory_path (piel_path_types) – Input path.

Returns:

None

read_json(path: piel.types.piel_path_types) dict[source]#

Reads a JSON file.

Usage:

read_json(‘path/to/file.json’)

Parameters:

path (piel_path_types) – Input path.

Returns:

JSON data.

Return type:

json_data(dict)

rename_file(match_file_path: piel.types.piel_path_types, renamed_file_path: piel.types.piel_path_types) None[source]#

Renames a file.

Usage:

rename_file(‘path/to/match_file’, ‘path/to/renamed_file’)

Parameters:
  • match_file_path (piel_path_types) – Input path.

  • renamed_file_path (piel_path_types) – Input path.

Returns:

None

rename_files_in_directory(target_directory: piel.types.piel_path_types, match_string: str, renamed_string: str) None[source]#

Renames all files in a directory.

Usage:

rename_files_in_directory(‘path/to/directory’, ‘match_string’, ‘renamed_string’)

Parameters:
  • target_directory (piel_path_types) – Input path.

  • match_string (str) – String to match.

  • renamed_string (str) – String to replace.

Returns:

None

replace_string_in_file(file_path: piel.types.piel_path_types, match_string: str, replace_string: str)[source]#

Replaces a string in a file.

Usage:

replace_string_in_file(‘path/to/file’, ‘match_string’, ‘replace_string’)

Parameters:
  • file_path (piel_path_types) – Input path.

  • match_string (str) – String to match.

  • replace_string (str) – String to replace.

Returns:

None

replace_string_in_directory_files(target_directory: piel.types.piel_path_types, match_string: str, replace_string: str)[source]#

Replaces a string in all files in a directory.

Usage:

replace_string_in_directory_files(‘path/to/directory’, ‘match_string’, ‘replace_string’)

Parameters:
  • target_directory (piel_path_types) – Input path.

  • match_string (str) – String to match.

  • replace_string (str) – String to replace.

Returns:

None

return_path(input_path: piel.types.piel_path_types, as_piel_module: bool = False) pathlib.Path[source]#

Returns a pathlib.Path to be able to perform operations accordingly internally.

This allows us to maintain compatibility between POSIX and Windows systems. When the as_piel_module flag is enabled, it will analyse whether the input path can be treated as a piel module, and treat the returned path as a module would be treated. This comes useful when analysing data generated in this particular structure accordingly.

Usage:

return_path(‘path/to/file’)

Parameters:

input_path (str) – Input path.

Returns:

Pathlib path.

Return type:

pathlib.Path

run_script(script_path: piel.types.piel_path_types) None[source]#

Runs a script on the filesystem script_path.

Parameters:

script_path (piel_path_types) – Script path.

Returns:

None

write_file(directory_path: piel.types.piel_path_types, file_text: str, file_name: str) None[source]#

Records a script_name in the scripts project directory.

Parameters:
  • directory_path (piel_path_types) – Design directory.

  • file_text (str) – Script to write.

  • file_name (str) – Name of the script.

Returns:

None