pygae/galgebra

View on GitHub
galgebra/gprinter.py

Summary

Maintainability
C
1 day
Test Coverage

subprocess call - check for execution of untrusted input.
Open

                subprocess.call([pdfprog, tex_filename])
Severity: Info
Found in galgebra/gprinter.py by bandit

subprocess call - check for execution of untrusted input.
Open

            subprocess.call(['pdfcrop', pdf_filename])
Severity: Info
Found in galgebra/gprinter.py by bandit

subprocess call - check for execution of untrusted input.
Open

            subprocess.call(['mv', rootfilename+'-crop.pdf', pdf_filename])
Severity: Info
Found in galgebra/gprinter.py by bandit

subprocess call - check for execution of untrusted input.
Open

                subprocess.call([sys_cmd['rm'], rootfilename+'.aux ', rootfilename+'.log ', rootfilename+'.tex'])
Severity: Info
Found in galgebra/gprinter.py by bandit

subprocess call - check for execution of untrusted input.
Open

            subprocess.call(['Pdf2Png', rootfilename])
Severity: Info
Found in galgebra/gprinter.py by bandit

subprocess call - check for execution of untrusted input.
Open

            subprocess.call(['rm', pdf_filename])
Severity: Info
Found in galgebra/gprinter.py by bandit

subprocess call - check for execution of untrusted input.
Open

                subprocess.call([pdfprog, tex_filename, sys_cmd['null']])
Severity: Info
Found in galgebra/gprinter.py by bandit

subprocess call - check for execution of untrusted input.
Open

            subprocess.call([sys_cmd['evince'], pdf_filename])
Severity: Info
Found in galgebra/gprinter.py by bandit

Consider possible security implications associated with subprocess module.
Open

import subprocess
Severity: Info
Found in galgebra/gprinter.py by bandit

subprocess call - check for execution of untrusted input.
Open

                subprocess.call([sys_cmd['rm'], rootfilename+'.aux ', rootfilename+'.log'])
Severity: Info
Found in galgebra/gprinter.py by bandit

Starting a process with a partial executable path
Open

            subprocess.call(['rm', pdf_filename])
Severity: Info
Found in galgebra/gprinter.py by bandit

Starting a process with a partial executable path
Open

            subprocess.call(['pdfcrop', pdf_filename])
Severity: Info
Found in galgebra/gprinter.py by bandit

Starting a process with a partial executable path
Open

            subprocess.call(['Pdf2Png', rootfilename])
Severity: Info
Found in galgebra/gprinter.py by bandit

Starting a process with a partial executable path
Open

            subprocess.call(['mv', rootfilename+'-crop.pdf', pdf_filename])
Severity: Info
Found in galgebra/gprinter.py by bandit

Function gprint has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

def gprint(*xargs):
    """
    Print latex or text from python script or latex from Jupyter Notebook/Lab

    """
Severity: Minor
Found in galgebra/gprinter.py - About 6 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function gxpdf has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

def gxpdf(filename=None, paper=(14, 11), crop=False, png=False, prog=False, debug=False, pt='10pt', pdfprog='pdflatex', evince=True, rm=True, null=True, documentclass='book'):

    """
    Post processes LaTeX output (see comments below), adds preamble and
    postscript, generates tex file, inputs file to latex, displays resulting
Severity: Minor
Found in galgebra/gprinter.py - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Cyclomatic complexity is too high in function gprint. (14)
Open

def gprint(*xargs):
    """
    Print latex or text from python script or latex from Jupyter Notebook/Lab

    """
Severity: Minor
Found in galgebra/gprinter.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Cyclomatic complexity is too high in function gxpdf. (12)
Open

def gxpdf(filename=None, paper=(14, 11), crop=False, png=False, prog=False, debug=False, pt='10pt', pdfprog='pdflatex', evince=True, rm=True, null=True, documentclass='book'):

    """
    Post processes LaTeX output (see comments below), adds preamble and
    postscript, generates tex file, inputs file to latex, displays resulting
Severity: Minor
Found in galgebra/gprinter.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Function gxpdf has 12 arguments (exceeds 4 allowed). Consider refactoring.
Open

def gxpdf(filename=None, paper=(14, 11), crop=False, png=False, prog=False, debug=False, pt='10pt', pdfprog='pdflatex', evince=True, rm=True, null=True, documentclass='book'):
Severity: Major
Found in galgebra/gprinter.py - About 1 hr to fix

    Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed.
    Open

    def gxpdf(filename=None, paper=(14, 11), crop=False, png=False, prog=False, debug=False, pt='10pt', pdfprog='pdflatex', evince=True, rm=True, null=True, documentclass='book'):
    Severity: Critical
    Found in galgebra/gprinter.py by sonar-python

    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

    See

    Refactor this function to reduce its Cognitive Complexity from 40 to the 15 allowed.
    Open

    def gprint(*xargs):
    Severity: Critical
    Found in galgebra/gprinter.py by sonar-python

    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

    See

    Function "gxpdf" has 12 parameters, which is greater than the 7 authorized.
    Open

    def gxpdf(filename=None, paper=(14, 11), crop=False, png=False, prog=False, debug=False, pt='10pt', pdfprog='pdflatex', evince=True, rm=True, null=True, documentclass='book'):
    Severity: Major
    Found in galgebra/gprinter.py by sonar-python

    A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

    Noncompliant Code Example

    With a maximum number of 4 parameters:

    def do_something(param1, param2, param3, param4, param5):
        ...
    

    Compliant Solution

    def do_something(param1, param2, param3, param4):
        ...
    

    Line too long (91 > 79 characters)
    Open

                r'$$\newcommand{\npdiff}[3]{\bfrac{\partial^{#3} {#1}}{\partial {#2}^{#3}}}$$',
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (175 > 79 characters)
    Open

    def gxpdf(filename=None, paper=(14, 11), crop=False, png=False, prog=False, debug=False, pt='10pt', pdfprog='pdflatex', evince=True, rm=True, null=True, documentclass='book'):
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (86 > 79 characters)
    Open

               'darwin': {'rm': 'rm', 'evince': 'open', 'null': ' > /dev/null', '&': '&'}}
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (141 > 79 characters)
    Open

        ``Format()`` is also required for printing from *ipython notebook* (note that ``xpdf()`` is not needed to print from *ipython notebook*).
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (101 > 79 characters)
    Open

        crop        True        Use "pdfcrop" to crop output file (pdfcrop must be installed, linux only)
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (91 > 79 characters)
    Open

                    subprocess.call([sys_cmd['rm'], rootfilename+'.aux ', rootfilename+'.log'])
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (87 > 79 characters)
    Open

               'linux': {'rm': 'rm', 'evince': 'evince', 'null': ' > /dev/null', '&': '&'},
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (103 > 79 characters)
    Open

        We assume that if gxpdf() is called then gFormat() has been called at the beginning of the program.
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (80 > 79 characters)
    Open

                r'$$\newcommand{\pdiff}[2]{\bfrac{\partial {#1}}{\partial {#2}}}$$',
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (100 > 79 characters)
    Open

        pdfprog    'pdflatex'   Use pdfprog to generate pdf output, only generate tex if pdfprog is None
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (107 > 79 characters)
    Open

        png         True        Use "convert" to produce png output (imagemagick must be installed, linux only)
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (83 > 79 characters)
    Open

                          'in,' + str(paper[1]) + 'in},total={' + str(paper[0] - 1) + \
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (85 > 79 characters)
    Open

    def paper_format(paper, pt, documentclass='book'):  # Set size of paper and font size
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (194 > 79 characters)
    Open

            LaTeX.latex_str += r'\begin{lstlisting}[language=Python,showspaces=false,showstringspaces=false,backgroundcolor=\color{gray},frame=single]%s\end{lstlisting}\text{Code Output:}' % tmp_str
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (113 > 79 characters)
    Open

                    subprocess.call([sys_cmd['rm'], rootfilename+'.aux ', rootfilename+'.log ', rootfilename+'.tex'])
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (80 > 79 characters)
    Open

               'win32': {'rm': 'del', 'evince': 'start', 'null': ' > NUL', '&': ''},
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (85 > 79 characters)
    Open

                        xi_rep = xi.replace(r'\\', r'\end{equation*}@\begin{equation*} ')
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (109 > 79 characters)
    Open

        latex_str = paper_format(paper, pt, documentclass)+LaTeX.latex_preamble+LaTeX.latex_str+r'\end{document}'
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (88 > 79 characters)
    Open

    SYS_CMD = {'linux2': {'rm': 'rm', 'evince': 'evince', 'null': ' > /dev/null', '&': '&'},
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (93 > 79 characters)
    Open

                        xi_rep = xi.replace(r'\\', r'\end{equation*}'+'\n'+r'\begin{equation*} ')
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (99 > 79 characters)
    Open

                LaTeX.latex_str += r'\begin{equation*} ' + (fstr % tuple(x)) + r'\end{equation*} '+'\n'
    Severity: Minor
    Found in galgebra/gprinter.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Rename function "gPrint_Function" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
    Open

    def gPrint_Function():
    Severity: Major
    Found in galgebra/gprinter.py by sonar-python

    Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

    Noncompliant Code Example

    With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

    def MyFunction(a,b):
        ...
    

    Compliant Solution

    def my_function(a,b):
        ...
    

    Rename function "gFormat" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
    Open

    def gFormat(Fmode: bool = True, Dmode: bool = True, inverse='full'):
    Severity: Major
    Found in galgebra/gprinter.py by sonar-python

    Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

    Noncompliant Code Example

    With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

    def MyFunction(a,b):
        ...
    

    Compliant Solution

    def my_function(a,b):
        ...
    

    There are no issues that match your filters.

    Category
    Status