Extract SOMIX model from Python code
Project description
Python2SOMIX
Extract SOMIX model from Python code
What is it for?
It allows to visualize Python code and the relations due to calls, accesses and grouping.
See the following example with two Python files:
test1.py
# test1.py remains unchanged
class ClassOne:
class_variable = 100
def __init__(self):
self.instance_variable = 0
ClassOne.class_variable += 1 # Fixed class variable increment
def method_one(self):
self.instance_variable += 1
print("ClassOne method_one called")
def function_one():
print("function_one called")
test2.py
# Updated test2.py with type annotations
from test1 import ClassOne, function_one
class ClassTwo:
def method_two(self):
obj = ClassOne()
obj.method_one()
function_one()
print("ClassTwo method_two called")
def method_three(self, my_obj: ClassOne):
# To check that usage is also found when ClassOne is passed as an argument
my_obj.method_one()
def function_two():
obj = ClassOne()
obj.method_one()
function_one()
print("function_two called")
Use Python2SOMIX to extract an mse file to display diagrams in Moose2Model. Go to www.moose2model.org to do this. This website uses only simple JavaScript coding and can also be run locally.
You may display all parts in a diagram like this:
Or construct diagrams which may contain only parts of the application together with coding. These are easy to keep correct when the code changes. You can also easily jump to an editor from the diagram.
How to run
start the script in the terminal with
python .\python2somix.py
See parameter -h or --help for available options.
The script will ask for the path to the folder where the python code is saved.
You may place a configuration file in the same folder as python2somix.py to specify which folder is to be read and where the output file is to be placed:
Exact name of the file: config_python2somix.txt
# Configuration file
base_path=/path/to/your/base/folder
output_path=/path/to/output/directory
To find usages of methods when the instance is passed to a parameter, you have to annotate the import parameter (Here that is belongs to ClassOne):
def method_three(self, my_obj: ClassOne):
# To check that usage is also found when ClassOne is passed as an argument
my_obj.method_one()
Automatic test
Do an automatic test with
...\Python2SOMIX\src\tests> python .\test_extraction.py
This test generates the subfolder test with test coding and compares the expected mse file expected_output.mse with the extracted file test(date_time).mse. Adapt this coding when the logic is changed. The test ignores the exact order of entries and the exact value of the id.
Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python2somix-0.1.1.tar.gz.
File metadata
- Download URL: python2somix-0.1.1.tar.gz
- Upload date:
- Size: 436.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
128004aa55f68c1a7bb2c2a264021877da59c5a6308e34d7a614799dc80586a7
|
|
| MD5 |
632e1b96d6a76d30f15ad0f9ed3622df
|
|
| BLAKE2b-256 |
4a3b764af50e12554238d4e79ed0ee71e3de77bbd43876178330050e91924c84
|
File details
Details for the file python2somix-0.1.1-py3-none-any.whl.
File metadata
- Download URL: python2somix-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ac28cb820b6ba790456d18512ddb283dee4ae12bf41a322dcd275e1a6d52e61
|
|
| MD5 |
bf8c8178a23427a26fe1e7ee44695924
|
|
| BLAKE2b-256 |
a29b00e0f9ac96be221036c07074a59222b9deaac74971b4bec5d4e1ce30e94b
|