Python - 1.5

Extension ID

com.castsoftware.python

What’s new?

Please see Python 1.5 - Release Notes  for more information

Description

This extension provides support for Python.

In what situation should you install this extension?

If your application contains Python source code (both .py and .jy extensions are supported) and you want to view these object types and their links with other objects, then you should install this extension.

Files analyzed

Icons File Extension Note

Python .py,  Python files - standard extension.

Jython .jy By convention, Python files to be run in a Java implementation of the Python interpreter.
- YAML (YAML Ain't Markup Language) *.yml, *.yaml,  Files related to the YAML language, commonly used for configuration purposes. Necessary to interpret Amazon Web Services deployment code.

Supported Python versions

The following table displays the supported versions matrix:

Version Support
3.x (tick)
2.x (tick)
1.x (error)

Framework support

Web Service Frameworks

Client-side
requests

Server-side operations Link to the Framework details
Aiohttp (https://docs.aiohttp.org/en/stable/) (tick) (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#aiohttpAiohttp

Bottle: https://bottlepy.org/docs/dev/

N/A (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#Bottle
CherryPy (https://docs.cherrypy.dev/en/latest/) N/A (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#CherryPy

Django: https://www.djangoproject.com/

N/A (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#Django
Falcon (https://falconframework.org/) N/A (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#Falcon
FastAPI (https://fastapi.tiangolo.com/) N/A (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#FastAPI
Flask (https://flask.palletsprojects.com/) N/A (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#Flask
http.client (https://docs.python.org/3/library/http.client.html) (tick) N/A Python 1.5 - Analysis Results - Web Service calls and operations support#Http.client
httplib (https://docs.python.org/2/library/httplib.html) (tick) N/A Python 1.5 - Analysis Results - Web Service calls and operations support#Httplib
httplib2 (https://pypi.org/project/httplib2/) (tick) N/A Python 1.5 - Analysis Results - Web Service calls and operations support#Httplib2
Nameko: https://github.com/nameko/nameko N/A (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#Nameko
Pyramid (https://docs.pylonsproject.org/projects/pyramid/en/latest/index.html) N/A (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#Pyramid
Requests (https://docs.python-requests.org/) (tick) N/A Python 1.5 - Analysis Results - Web Service calls and operations support#Requests
Sanic: https://sanic.readthedocs.io/en/stable/ N/A (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#Sanic
Tornado: https://www.tornadoweb.org/en/stable/ (error) (tick) Python 1.5 - Analysis Results - Web Service calls and operations support#Tornado
urllib (https://docs.python.org/3/library/urllib.html) (tick) N/A Python 1.5 - Analysis Results - Web Service calls and operations support#Urllib
urllib2 (https://docs.python.org/2/library/urllib2.html) (tick) N/A Python 1.5 - Analysis Results - Web Service calls and operations support#Urllib2
urllib3 (https://pypi.org/project/urllib3/) (tick) N/A Python 1.5 - Analysis Results - Web Service calls and operations support#Urllib3
web2py (http://www.web2py.com/) (tick) (error) Python 1.5 - Analysis Results - Web Service calls and operations support#Web2py

Function Point, Quality and Sizing support

This extension provides the following support:

  • Function Points (transactions): a green tick indicates that OMG Function Point counting and Transaction Risk Index are supported
  • Quality and Sizing: a green tick indicates that CAST can measure size and that a minimum set of Quality Rules exist
Function Points
(transactions)
Quality and Sizing Security
(tick) (tick) (tick)

AIP Core compatibility

This extension is compatible with:

CAST AIP release
Supported
8.3.x (tick)

Dependencies with other extensions

Some CAST extensions require the presence of other CAST extensions in order to function correctly. The Python extension requires that the following other CAST extensions are also installed:

  • Web Services Linker  (internal technical extension)
  • CAST AIP Internal extension (internal technical extension)

Note that when using the CAST Extension Downloader to download the extension and the Manage Extensions interface in CAST Server Manager to install the extension, any dependent extensions are automatically downloaded and installed for you. You do not need to do anything.

Download and installation instructions

The extension will be automatically downloaded and installed in CAST Console.

Source code discovery

A discoverer is provided with the extension to automatically detect Python code: a Python project will be discovered for the package’s root folder when at least one .py or .jy (jython) file is detected in the root folder or any sub-folders. For every Python project located, one Universal Technology Analysis Unit will be created:

Analysis - Automatic skipping of unit-test code and external libraries

The analyzer skips files that are recognized as forming part of testing code, i.e., in principle, code not pertaining to production code. The reason to avoid inclusion of testing code is that many Quality Rule violations are overrepresented in test code, either because code tends to be of poorer quality (certainly not critical) or prevalence of particular testing patterns. Accounting for test code would negatively impact the total score of the project.

Similarly we skip folders that contain external python libraries. Currently we only skip the canonical folders site-packages and dist-packages (the latter being used in certain Linux distributions). Not only analyzing external libraries is discouraged, but it can interfere with correct interpretation of supported libraries and frameworks, and have a serious impact in memory consumption and overall analysis performance.

The heuristics used by the analyzer are based on detecting (unit-test) library imports, and file and path naming conventions as summarized in the table below: 

Type

Value

HeaderLines

MinimumCount

FilePath /test_*.py

FilePath /*_test.py

FilePath /*_test_*.py

FilePath /test/*.py

FilePath /tests/*.py

FileContent import unittest 12
FileContent from unittest import 12
FileContent from nose.tools import 12
FileContent self.assert
2
FilePath /site-packages/

FilePath /dist-packages/

FilePath /Python*/Lib/

FilePath /Python*/Scripts/

FilePath /Python*/Include/

FilePath /Python*/Bin/

  • The ** symbol represents any arbitrary path string, whereas * represents any string without directory slashes.
  • The heuristics above should also similarly valid for .jy (jython) files.
  • FilePath match is case-insensitive

What results can you expect?

Once the analysis/snapshot generation has completed, you can view the results in the normal manner:

Python Class and method example

iOS Front-end connected to a Python Flask Back-end.

Objects

Icon Description

Python Project, Python External Library

Python Module

Python Class
Python Method
Python Script

Python GET (urllib, urllib2, httplib, httplib2, aiohttp) servicePython GET service requestPython (Flask, aiohttp) Web Service GET operation Python Web Service Get Operation

Python POST (urllib, urllib2, httplib, httplib2, aiohttp) service
Python POST service request
Python (Flask, aiohttp) Web Service POST operation Python Web Service Post Operation

Python PUT (urllib, urllib2, httplib, httplib2, aiohttp) service
Python PUT service requestPython (Flask, aiohttp) Web Service PUT operation Python Web Service Post Operation

Python DELETE (urllib, urllib2, httplib, httplib2, aiohttp) service
Python DELETE service request
Python Flask, aiohttp Web Service DELETE operation Python Web Service Delete Operation

Python Web Service Any Operation

Python Query, Python ORM Mapping, Python File Query

RabbitMQ Python QueueCall
ActiveMQ Python QueueCall
IBM MQ Python QueueCall

RabbitMQ Python QueueReceive
ActiveMQ Python QueueReceive
IBM MQ Python QueueReceive

Python Call To Java Program

Python Call To Generic Program
Amazon Web Services

Python Call to AWS Lambda Function

Python Call to Unknown AWS Lambda Function

Python AWS Lambda GET Operation

Python AWS Lambda POST Operation
Python AWS Lambda PUT Operation
Python AWS Lambda DELETE Operation

Python AWS Lambda ANY Operation

Python AWS SQS Publisher, Python AWS SNS Publisher

Python AWS SQS Receiver, Python AWS SNS Receiver

Python AWS SQS Unknown Publisher, Python AWS SNS Unknown Publisher

Python AWS SQS Unknown Receiver, Python AWS SNS Unknown Receiver

Python S3 Bucket

Python Unknown S3 Bucket

Python DynamoDB Database

Python DynamoDB Table

Python Unknown DynamoDB Table

Python Email, Python SMS

Python callable artifact

Python Script, Python Module and Python Method objects form part of Python (callable) artifacts.

The following links are created:

  • call links between methods
  • inherit link between hierarchically related classes
  • refer link from methods to class (constructor call)
  • use link between modules through import
  • call links between Python callable artifacts and Python Call objects
  • call links between Python Call objects and external programs or lambda functions

The following links are created between Python ORM Mapping objects and database table objects:

  • useSelectLink in case of SELECT operation
  • useDeleteLink in case of DELETE operation
  • useInsertLink in case of INSERT operation
  • useUpdateLink in case of UPDATE operation
  • call links in case of generic operation on S3 buckets

Structural Rules

The following structural rules are provided: 

Release Link
1.5.3-funcrel https://technologies.castsoftware.com/rules?sec=srs_python&ref=||1.5.3-funcrel
1.5.2-funcrel https://technologies.castsoftware.com/rules?sec=srs_python&ref=||1.5.2-funcrel
1.5.1-funcrel https://technologies.castsoftware.com/rules?sec=srs_python&ref=||1.5.1-funcrel
1.5.0-funcrel https://technologies.castsoftware.com/rules?sec=srs_python&ref=||1.5.0-funcrel
1.5.0-alpha3 https://technologies.castsoftware.com/rules?sec=srs_python&ref=||1.5.0-alpha3
1.5.0-alpha2 https://technologies.castsoftware.com/rules?sec=srs_python&ref=||1.5.0-alpha2
1.5.0-alpha1 https://technologies.castsoftware.com/rules?sec=srs_python&ref=||1.5.0-alpha1

You can also find a global list here: https://technologies.castsoftware.com/rules?sec=t_1021000&ref=||

Expected results for supported frameworks

Refer Results for more information about the results that you can expect for each supported framework.

Limitations

  • Not fully supported Python Decorator function.

  • Quality rules do not apply to code inside the class definition (class or “static” variables)

  • The “Avoid disabling certificate check when requesting secured urls” for ‘urllib3’ is only partially supported by detecting the call to ‘urllib3.disable_warnings’.

  • Limited Python resolution that leads to missing links:

    • No support for __all__
    • No support for variable of type class, function
  • Flask:

    • Objects for other web service operations such as PATCH are not generated.
    • The endpoint abstraction layer between functions and annotations is not considered. When using  add_url_rule the endpoint argument is taken as the calling function name.
  • Cherrypy:

    • Only support default request.dispatcher “cherrypy.dispatch.MethodDispatcher()”.
  • Java-Python interoperability via Jython is not supported. However the files with the specific extension .jy for Jython is analyzed as a regular Python file.

  • Message queues

    •  To generate queue message objects the queue name has to be initialized explicitly in the code (dynamic naming not supported).