Skip to content

Commit

Permalink
Lint and refactor bin/ci.py
Browse files Browse the repository at this point in the history
  • Loading branch information
stefmolin committed Nov 25, 2024
1 parent 5d2a1d5 commit eca5a32
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions bin/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
$ python bin/ci.py src/data_morph/shapes/bases/line_collection.py
high_lines h_lines slant_down slant_up v_lines wide_lines x diamond rectangle star
$ python bin/ci.py src/data_morph/shapes/points/heart.py
heart spade
$ python bin/ci.py src/data_morph/data/starter_shapes/superdatascience.csv
SDS
"""
from data_morph.shapes.factory import ShapeFactory
from data_morph.data.loader import DataLoader

import sys
from os.path import basename
from pathlib import Path

from data_morph.data.loader import DataLoader
from data_morph.shapes.factory import ShapeFactory

new_paths = sys.argv[1:]

Expand All @@ -31,16 +36,21 @@
args.append(dataset)

# Figure out argument of shapes based on .py filename
new_files = [basename(x).split('/')[-1] for x in new_paths]
for shape, c in ShapeFactory._SHAPE_MAPPING.items():
for new_file in new_files:
# Find the class and all parent classes and get their module name
# We get the module name because it ends in the python file without .py extension
# To make it easy to compare, we just add the extension onto the end
parents = [x.__module__ for x in c.__mro__]
all_modules = parents + [c.__module__]
all_modules = [f'{x}.py' for x in all_modules]
new_files = [Path(x).name for x in new_paths]
for shape, shape_cls in ShapeFactory._SHAPE_MAPPING.items():
# Find the class and all parent classes and get their module name
# We get the module name because it ends in the python file without .py extension
# To make it easy to compare, we just add the extension onto the end
mro = [
x.__module__ for x in shape_cls.__mro__ if x.__module__.startswith('data_morph')
]

if shape == 'spade':
mro.append('heart')

all_modules = [f'{x}.py' for x in mro]

for new_file in new_files:
for module in all_modules:
if module.endswith(new_file):
args.append(shape)
Expand Down

0 comments on commit eca5a32

Please sign in to comment.