API reference

class phystool.tags.Tags(tags: dict[str, list[str]])

This class allows to tag PDBFiles with user defined tags sorted by custom categories.

Warning:

Directly creating an instance without using Tags.validate could lead to unwanted tags.

Parameters:

tags – tags sorted by category

classmethod load() None

Load the static variable Tags.TAGS from the file config.TAGS_PATH that contains all valid tags. If the file does not exist, it will be recreated by calling Tags.reset_all_tags()

classmethod reset_all_tags() None

Read all “.json” metadata files to extract all tags and save the result in config.TAGS_PATH so that it can be easily reloaded by calling Tags.load()

classmethod validate(list_of_tags: str) Self

Converts a string of comma separated words into a valid Tags instance.

The string is split after each comma. If the words in the resulting list are valid tags, they will be sorted by category.

Parameters:

list_of_tags – string of comma separated words

Returns:

a Tags instance with only valid tags

with_overlap(other: Self) bool

Returns False for the first category where there isn’t any shared tag between this instance and the other instance, otherwise, returns True

Warning:

Returns False if, for a given category, either set or the two sets are empty (this should not happen)

without_overlap(other: Self) bool

Returns False for the first category where there is at least one shared tag between this instance and the other instance, otherwise, returns True

Warning:

Doesn’t necessarily return True if, for a given category, either set or the two sets are empty (this should not happen).

class phystool.pdbfile.Exercise(pdb_file: Path, pdb_data: dict)
tex_export() None

Print a string that can be inserted in LexTeX file

to_dict() dict[str, str | dict | list[str]]

Return a dict that is JSON compatible

class phystool.pdbfile.Figure(pdb_file: Path, pdb_data: dict)
tex_export() None

Print a string that can be inserted in LexTeX file

to_dict() dict[str, str | dict | list[str]]

Return a dict that is JSON compatible

class phystool.pdbfile.PDBFile(tex_file: Path)
parse_texfile() bool

Parse a texfile to analyse its content and create metadata

abstract tex_export() None

Print a string that can be inserted in LexTeX file

abstract to_dict() dict[str, str | dict | list[str]]

Return a dict that is JSON compatible

class phystool.pdbfile.QCM(pdb_file: Path, pdb_data: dict)
tex_export() None

Print a string that can be inserted in LexTeX file

to_dict() dict[str, str | dict | list[str]]

Return a dict that is JSON compatible

class phystool.pdbfile.TP(pdb_file: Path, pdb_data: dict)
tex_export() None

Print a string that can be inserted in LexTeX file

to_dict() dict[str, str | dict | list[str]]

Return a dict that is JSON compatible

class phystool.pdbfile.Theory(pdb_file: Path, pdb_data: dict)
tex_export() None

Print a string that can be inserted in LexTeX file

to_dict() dict[str, str | dict | list[str]]

Return a dict that is JSON compatible

class phystool.metadata.Metadata(load=True)

Gathers the metadata of all PDBFiles in a single class.

filter(query: str, uuid_bit: str, file_types: set[str], selected_tags: Tags, excluded_tags: Tags) list[phystool.pdbfile.PDBFile]

Returns a list of PDBFile that match search criteria

Parameters:
  • query – string that should appear in the tex file

  • uuid_bit – string that should match part of a uuid

  • file_type – restrain search only to those file types

  • selected_tags – restrain search to the PDBFiles tagged with any of the selected_tags

  • excluded_tags – exclude PDBFiles tagged with any of the excluded_tags

class phystool.helper.ContextIterator(iterable: Iterable, before: int, after: int)

Wrapper around an iterable that allows peeking ahead to get next elements without consuming the iterator.

phystool.helper.greptex(query: str, path: Path, silent: bool) set[str]

Find query in tex files stored in the single directory path.

Format query to match a newline followed by spaces and returns a set of uuids of tex files containing query.

Parameters:
  • query – string that should be matched

  • path – directory where the search occurs

  • silent – if True, logs a warning when no match was found

Returns:

a set of uuids corresponding to tex files that contains the query

phystool.helper.progress_bar(max_step: int, step: int, length: int, msg: str) None

Display a progress bar in the terminal

Parameters:
  • max_step – process’ maximum number of steps

  • step – current process’ step

  • length – number of characters of the progress bar

  • msg – message displayed after the progress bar

phystool.helper.terminal_yes_no(prompt: str) bool

Ask for a confirmation in the terminal.

Parameters:

prompt – text displayed before the ‘[y/n]:’ question