jmbuilder package#

JMatrix Builder written in Python

JMBuilder, provides some utilities and configurations to build the JMatrix library, the module are written in Python. Created by Ryuu Mitsuki. For more information about JMatrix you can refer to link below.

Copyright (c) 2023-2024 Ryuu Mitsuki

Available Classes#

JMProperties

A custom properties parser class, implemented in jmbuilder.utils package. Python does not provide an easy way to parsing files with extension of .properties, this class is designed to parse properties file and access their contents with ease without any third-party modules.

JMSetupConfRetriever

A class that provides all configurations for setting up the JMBuilder module.

JMException

This class is a base exception for JMBuilder module.

JMParserError

This exception is raised when an error has occurred during parsing the configuration (e.g., properties file).

JMUnknownTypeError

This exception is raised when an unknown type error occurs during the execution in this module.

JMRepairer

A class for repairing manifest and properties files using information from a POM file.

PomParser

A class that provides an easy way to parse and retrieve useful information from the provided POM file.

Available Functions#

json_parser

Provide a simple way to parse the specified JSON file.

remove_comments

Remove lines within the given list of strings that starting with the specified delimiter, and returning a new list of strings with the lines starting with the specified delimiter removed.

remove_blanks

Remove blank or empty lines (including line with trailing whitespace) and None within the given list of strings, and returning a new list of strings with empty lines and None removed.

Available Constants#

BASEDIR

Provides a string that represents the path to base directory of JMBuilder module.

LOGSDIR

Provides a string that represents the path to logs directory that being used by this package to log some information and errors.

STDOUT

References the console standard output (sys.stdout).

STDERR

References the console standard error (sys.stderr).

TMPDIR

Provides a string that represents the path to temporary directory that being used by this package to store some temporary file(s) or cache(s).

class jmbuilder.JMSetupConfRetriever[source]#

Bases: object

A class that retrieves and provides all setup configuration.

Notes

This class only retrieves the setup configuration without any modification methods to their values.

Attributes:
author

Get the author name from setup configuration.

license

Get the license name from setup configuration.

progname

Get the program name from setup configuration.

version

Get the module version from setup configuration.

property author: str#

Get the author name from setup configuration.

Returns:
str

A string representing the author name.

property license: str#

Get the license name from setup configuration.

Returns:
str

A string representing the license name.

property progname: str#

Get the program name from setup configuration.

Returns:
str

A string representing the program name.

property version: FrozenJMVersion#

Get the module version from setup configuration.

Returns:
FrozenJMVersion

A frozen named tuple representing the module version.

Subpackages#

Submodules#

jmbuilder.__main__ module#

Main Module for JMBuilder

Copyright (c) 2023-2024 Ryuu Mitsuki.

jmbuilder.__main__.__argchck(targets: Union[str, Iterable], args: Union[List[str], Tuple[str]]) bool[source]#

Check whether specified argument are presented in args.

Returns:
bool

Returns True if the specified argument are presented in args, otherwise returns False.

jmbuilder.__main__.__find_arg(val: Union[str, Pattern]) int[source]#

Find the index of specified argument from the command-line arguments.

Parameters:
valstr or re.Pattern

A regular expression pattern used to search for the argument within the command-line arguments. Accepts a string literal representing the regular expression or a compiled regular expression.

Returns:
int

The index of the specified argument in the command-line arguments. Returns -1 if the argument cannot be found or if the command-line arguments are empty.

Notes

This function utilizes the global constant CLEAN_ARGS, ensuring that it searches for the desired argument within the command-line arguments with all duplicate arguments omitted.

jmbuilder.__main__.__print_help() None[source]#

Print the help message to the standard output.

jmbuilder.__main__.__print_version(_exit: bool = False, *, only_ver: bool = False, file: ~typing.TextIO = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>) None[source]#

Print the version info to specific opened file.

Parameters:
exitbool, optional

Whether to exit and terminate the Python after printed the version. Defaults to False (disabled).

only_ver: bool, optional

Whether to print the version only. By activating this option, other information like program name, license, and copyright will not be printed. Defaults to False.

fileTextIO, optional

The file to print the version info. Defaults to console standard output (sys.stdout).

jmbuilder._globals module#

Global Module for JMBuilder

This module contains all global variables, constants, and classes used by the JMBuilder module. It provides access to various path variables and other configurations used throughout the module.

Copyright (c) 2023-2024 Ryuu Mitsuki.

Available Classes#

JMSetupConfRetriever

This class provide an easy way to retrieve and access the setup configurations for JMBuilder module.

Available Constants#

AUTHORstr

The author name (as well as the creator) of the JMBuilder module.

BASEDIRstr

Provides the path to the base directory of the JMBuilder package.

This is an alias for _JMCustomPath().basedir.

CONFDIRstr

Provides the path to the directory that contains configuration files for configuring the JMBuilder module. The path itself is relative to BASEDIR.

This is an alias for _JMCustomPath().confdir.

LOGSDIRstr

Provides the path to the directory used for logging by the JMBuilder module. The path itself is relative to BASEDIR.

This is an alias for _JMCustomPath().logsdir.

STDOUTTextIO

An alias for sys.stdout, representing the standard output console.

STDERRTextIO

An alias for sys.stderr, representing the standard error console.

TMPDIRstr or pathlib.Path

Provides the path to the temporary directory used by the JMBuilder module. The path itself is relative to BASEDIR.

This is an alias for _JMCustomPath().tmpdir.

VERSIONstr

A string representing the JMBuilder’s version information.

class jmbuilder._globals.JMSetupConfRetriever[source]#

Bases: object

A class that retrieves and provides all setup configuration.

Notes

This class only retrieves the setup configuration without any modification methods to their values.

Attributes:
author

Get the author name from setup configuration.

license

Get the license name from setup configuration.

progname

Get the program name from setup configuration.

version

Get the module version from setup configuration.

property author: str#

Get the author name from setup configuration.

Returns:
str

A string representing the author name.

property license: str#

Get the license name from setup configuration.

Returns:
str

A string representing the license name.

property progname: str#

Get the program name from setup configuration.

Returns:
str

A string representing the program name.

property version: FrozenJMVersion#

Get the module version from setup configuration.

Returns:
FrozenJMVersion

A frozen named tuple representing the module version.

jmbuilder.core module#

JMBuilder’s core module.

Copyright (c) 2023-2024 Ryuu Mitsuki.

class jmbuilder.core.JMRepairer(pom: Union[str, PomParser, BeautifulSoup])[source]#

Bases: object

A class for repairing manifest and properties files using information from a POM file.

Parameters:
pomstr, PomParser, or _bs4.BeautifulSoup

The POM file, either as a path (str), a PomParser instance, or a BeautifulSoup object.

Raises:
ValueError

If the ‘pom’ argument is empty.

TypeError

If the type of ‘pom’ argument is unknown, neither of str, a PomParser instance, nor a BeautifulSoup object.

Attributes:
_val_patternre.Pattern

Regular expression pattern for extracting values from curly braces in strings.

_soupPomParser

Instance of PomParser representing the parsed POM file.

_pom_itemsDict[str, str (could possibly None)]

Dictionary containing key-value pairs extracted from the POM file.

Methods

fix_manifest(infile[, outfile])

Fix the given manifest file by replacing placeholders with values from the POM file.

fix_properties(infile[, outfile])

Fix the given properties file by replacing placeholders with values from the POM file.

classmethod __write_out(contents: List[str], out: str) None#

Write the given contents to the specified output file.

Parameters:
contentsa list of str

List of strings to be written to the file.

outstr

Path to the output file.

Raises:
Exception

If an error occurs while writing to the output file.

fix_manifest(infile: str, outfile: Optional[str] = None) None[source]#

Fix the given manifest file by replacing placeholders with values from the POM file.

Parameters:
infilestr

Path to the input manifest file.

outfilestr, optional

Path to the output manifest file. If not specified, the input file will be overwritten.

Raises:
ValueError

If the ‘infile’ argument is empty.

FileNotFoundError

If the specified input file does not exist.

fix_properties(infile: str, outfile: Optional[str] = None) None[source]#

Fix the given properties file by replacing placeholders with values from the POM file.

Parameters:
infilestr

Path to the input properties file.

outfilestr, optional

Path to the output properties file. If not specified, the input file will be overwritten.

Raises:
ValueError

If the ‘infile’ argument is empty.

FileNotFoundError

If the specified input file does not exist.

class jmbuilder.core.PomParser(soup: BeautifulSoup)[source]#

Bases: object

A class that provides an easy way to parse and retrieve useful information from the provided POM file.

Parameters:
soupBeautifulSoup

A bs4.BeautifulSoup object representing the parsed POM file.

Methods

get(key)

Find the element tag based on the provided key, which can be a string (separated by dots) or a list of tag names.

get_author()

Return a dictionary with 'id', 'name', and 'url' of the project author.

get_id()

Return a dictionary with 'groupId' and 'artifactId'.

get_inception_year()

Return the project inception year.

get_license()

Return a dictionary with 'name', 'url', and 'distribution' of the project license.

get_name()

Return the project name.

get_property(key[, dot])

Return the value of the specified property key from the POM properties.

get_url()

Return the project URL.

get_version()

Return the project version.

parse(pom_file[, encoding])

Parse the POM file (pom.xml) and return an instance of this class.

printsoup(*[, pretty, file])

Print the BeautifulSoup object, optionally prettified, for debugging purposes.

get(key: Union[str, List[str]]) Optional[Tag][source]#

Find the element tag based on the provided key, which can be a string (separated by dots) or a list of tag names. The result could be a None, this means that element are undefined or the users has specified wrong element tree path.

Parameters:
keystr or a list of str

The key representing the element tree path.

Returns:
Tag or None

A bs4.element.Tag object representing the desired element tag, or None if the element tag is undefined or cannot be found.

get_author() Dict[str, Optional[str]][source]#

Return a dictionary with ‘id’, ‘name’, and ‘url’ of the project author.

get_id() Dict[str, Optional[str]][source]#

Return a dictionary with ‘groupId’ and ‘artifactId’.

get_inception_year() Optional[str][source]#

Return the project inception year.

get_license() Dict[str, str][source]#

Return a dictionary with ‘name’, ‘url’, and ‘distribution’ of the project license.

get_name() Optional[str][source]#

Return the project name.

get_property(key: str, dot: bool = True) Optional[str][source]#

Return the value of the specified property key from the POM properties.

Parameters:
keystr

The property key.

dotbool, optional

If True, split the key using dots. Defaults to True.

Returns:
str or None

The property value if found, otherwise, returns None.

Raises:
ValueError

If the provided key is an empty string or None.

get_url() Optional[str][source]#

Return the project URL.

get_version() Optional[str][source]#

Return the project version.

static parse(pom_file: str, encoding: str = 'UTF-8') PomParser[source]#

Parse the POM file (pom.xml) and return an instance of this class. Remove comments and blank lines to keep the POM clean.

Parameters:
pom_filestr

The path of the pom.xml file to be parsed.

encodingstr, optional

The encoding used while parsing the pom.xml file. Defaults to UTF-8.

Returns:
PomParser

An instance of this class.

printsoup(*, pretty: bool = True, file: ~typing.TextIO = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>) None[source]#

Print the BeautifulSoup object, optionally prettified, for debugging purposes.

Parameters:
prettybool, optional

If True, the BeautifulSoup object will be prettified for better readability. Defaults to True.

fileTextIO, optional

A file-like object to which the output will be printed. Defaults to sys.stdout.

Notes

This method is intended for debugging and allows you to print the current state of the BeautifulSoup object. The output can be customized with the pretty parameter to control prettification and the file parameter to redirect the output to a specific file-like object.