Skip to content

Commit

Permalink
Merge pull request #10 from raulgotor/chore/pipeline_linter
Browse files Browse the repository at this point in the history
  • Loading branch information
raulgotor authored Dec 17, 2023
2 parents 6557ec9 + b181de9 commit cfcd795
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 131 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --disable=C0114,R0902,C0116 --fail-under=9
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ At the folder examples, there are a series of configurations and map `.yaml` fil

## Roadmap

- [ ] Labels at specific memory addresses
- [ ] Area titles
- [x] Labels at specific memory addresses
- [x] Area titles
- [ ] Links across specific areas
- [ ] Choose side of the labels
- [ ] Memory direction
- [x] Memory direction
- [ ] Hide specific elements
- [ ] Memory size in bytes
- [ ] Sections links across breaks
- [ ] Section links across breaks
- [ ] Friendly name and identifier
- [ ] Legend
## References
Expand Down
42 changes: 34 additions & 8 deletions area_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@


class AreaView:
"""
AreaView provides the container for a given set of sections and the methods to process
and transform the information they contain into useful data for graphical representation
"""
pos_y: int
pos_x: int
zoom: int
Expand Down Expand Up @@ -37,18 +41,38 @@ def __init__(self,
if self.config is not None:
self._process()

def get_processed_section_views(self):
def get_split_area_views(self):
"""
Get current area view split in multiple area views around break sections
:return: List of AreaViews
"""
return self.processed_section_views

def to_pixels(self, value):
def to_pixels(self, value) -> float:
"""
Convert a given address to pixels in an absolute manner,
according to the address / pixel size ratio of current area
:param value: Address to be converted to pixels
:return: Conversion result
"""
return value / self.address_to_pxl

def to_pixels_relative(self, value):
a = self.size_y - ((value - self.start_address) / self.address_to_pxl)
return a
def to_pixels_relative(self, value) -> float:
"""
Convert a given address to pixels in a relative manner,
according to the address / pixel size ratio of current area
def _overwrite_sections_info(self):
Relative in this context means relative to the start address of the Area view. If Area View
starts at 0x20000 and ends at 0x30000, passing these values to this function for an area
with a height of 1000 pixels, will result in 0 and 1000 respectively
:param value: Address to be converted to pixels
:return: Conversion result
"""
return self.size_y - ((value - self.start_address) / self.address_to_pxl)

def _overwrite_sections_info(self):
for section in self.sections.get_sections():

section_style = copy.deepcopy(self.style)
Expand Down Expand Up @@ -80,7 +104,8 @@ def _process(self):
if area_has_breaks:

total_breaks_size_y_px = self._get_break_total_size_px()
total_non_breaks_size_y_px = self._get_non_breaks_total_size_px(self.sections.get_sections())
total_non_breaks_size_y_px = self._get_non_breaks_total_size_px(
self.sections.get_sections())
expandable_size_px = total_breaks_size_y_px - (breaks_section_size_y_px * breaks_count)

last_area_pos = self.pos_y + self.size_y
Expand All @@ -90,7 +115,8 @@ def _process(self):
if section_group.is_break_section_group():
corrected_size = breaks_section_size_y_px
else:
split_section_size_px = self._get_non_breaks_total_size_px(section_group.get_sections())
split_section_size_px = self._get_non_breaks_total_size_px(
section_group.get_sections())
corrected_size = (split_section_size_px / total_non_breaks_size_y_px) * (
total_non_breaks_size_y_px + expandable_size_px)

Expand Down
19 changes: 16 additions & 3 deletions labels.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import copy

from dataclasses import dataclass
from style import Style


@dataclass
class Labels:
"""
Container for labels, and methods to build them from a yaml label specification
"""
sections: []
addresses: []
style: Style
Expand All @@ -12,7 +16,12 @@ def __init__(self, labels, style):
self.style = style
self.labels = self.build_labels(labels)

def build_labels(self, labels_yaml):
def build_labels(self, labels_yaml) -> []:
"""
Build a list of labels (`[Label]`) from a list of labels in a yaml format
:param labels_yaml: List of labels in a yaml format
:return: list of labels (`[Label]`)
"""
labels = []

for element in labels_yaml:
Expand All @@ -28,8 +37,12 @@ def build_labels(self, labels_yaml):
return labels


@dataclass
class Label:

"""
Stores single label information for a given address.
Additionally, provides style information for drawing the link
"""
def __init__(self, style):
self.style = style
self.address = 0
Expand Down
25 changes: 14 additions & 11 deletions linkerscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import argparse
import copy
import sys

import yaml

from area_view import AreaView
from helpers import safe_element_get
from labels import Labels
from links import Links
from map_drawer import Map
from style import Style
from map_file_parser import MapFileParser
from map_file_loader import MapFileLoader
from sections import Sections

parser = argparse.ArgumentParser()
Expand All @@ -20,25 +21,25 @@
default='map.svg')
parser.add_argument('--input',
'-i',
help='Name of the map file, can be either linker .map files or .yaml descriptor',
help='Name of the map file,'
'can be either linker .map files or .yaml descriptor',
default='map.yaml')
parser.add_argument('--configuration',
'-c',
help='Configuration file (.yml). If not specified, will use config.yaml as default',
help='Configuration file (.yml). If not specified,'
'will use config.yaml as default',
default='config.yaml')

args = parser.parse_args()

areas = []

with open(args.configuration, 'r') as file:
with open(args.configuration, 'r', encoding='utf-8') as file:
config = yaml.safe_load(file)

if config['areas'] is None:
print('No information to show on current configuration file')
exit(-1)

# TODO: linked sections compatibility
sys.exit(-1)

base_style = Style().get_default()
base_style.override_properties_from(Style(style=config.get('style', None)))
Expand All @@ -50,7 +51,7 @@
section_size = area.get('section-size', {})
_range = area.get('range', {})
area_view = AreaView(
sections=(Sections(sections=MapFileParser(args.input).parse())
sections=(Sections(sections=MapFileLoader(args.input).parse())
.filter_address_min(safe_element_get(_range, 0))
.filter_address_max(safe_element_get(_range, 1))
.filter_size_min(safe_element_get(section_size, 0))
Expand All @@ -60,11 +61,13 @@
global_config=config,
style=area_style.override_properties_from(Style(style=area.get('style')))
)
areas.extend(area_view.get_processed_section_views())
areas.extend(area_view.get_split_area_views())
yaml_links = config.get('links', None)

links_style = copy.deepcopy(base_style)
links = Links(config.get('links', {}), style=links_style.override_properties_from(Style(style=yaml_links.get('style') if yaml_links is not None else None)))
links = Links(config.get('links', {}),
style=links_style.override_properties_from(
Style(style=yaml_links.get('style') if yaml_links is not None else None)))
Map(area_view=areas,
links=links,
style=base_style,
Expand Down
6 changes: 5 additions & 1 deletion links.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@


class Links:
"""
Stores the link information between given section or address
Additionally, provides style information for drawing the link
"""
sections: []
addresses: []
style: Style

def __init__(self, links={}, style=None):
def __init__(self, links, style=None):
self.addresses = links.get('addresses', [])
self.sections = links.get('sections', [])
self.style = style
Loading

0 comments on commit cfcd795

Please sign in to comment.