Skip to content

Commit

Permalink
Merge branch 'matlab2numpy' into mh_python
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoqing committed Feb 7, 2022
2 parents 344f031 + 714a56d commit c57b5d8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ This package provides a utility `mh_python` to translate MATLAB into Python form
The generated Python code hope to be directly runnable with the [mat2py](https://mat2py.org) framework.

This `mh_python` utility was initially developed under fork of [MISS_HIT](https://github.com/florianschanda/miss_hit) and
then exported to a seperated [branch](https://github.com/mat2py/miss_hit/tree/mh_python) for uploading to [PyPi](https://pypi.org/project/mh_python/).
then exported to a seperated [branch](https://github.com/mat2py/miss_hit/tree/mh_python) for uploading to [PyPi](https://pypi.org/project/mh-python/).

We hope to merge this utility back to `miss_hit` after it is stable.

## Usage

```python
# must install
python3 -m pip install mh_python
python3 -m pip install mh-python

# recommend install for prettify generated code
python3 -m pip install black isort --upgrade
Expand Down
41 changes: 38 additions & 3 deletions mh_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
## ##
##############################################################################

import sys
from collections import OrderedDict
from io import StringIO
from pathlib import Path

from miss_hit_core import command_line, pathutil, work_package
from miss_hit_core import command_line, pathutil, work_package, cfg_tree
from miss_hit_core.errors import Error, Message_Handler
from miss_hit_core.m_ast import *
from miss_hit_core.m_lexer import MATLAB_Lexer
Expand Down Expand Up @@ -512,7 +513,7 @@ def post_process(self):
pass


def main_handler():
def parse_args(argv=None):
clp = command_line.create_basic_clp()

# Extra language options
Expand All @@ -537,7 +538,41 @@ def main_handler():

# Extra debug options

options = command_line.parse_args(clp)
if argv is not None:
_argv = sys.argv
try:
sys.argv = argv
return command_line.parse_args(clp)
finally:
sys.argv = _argv
else:
return command_line.parse_args(clp)


def process_one_file(path: Path, options=None, mh=None):
if options is None:
options = parse_args()

if mh is None:
mh = Message_Handler("debug")

mh.show_context = not options.brief
mh.show_style = False
mh.show_checks = True
mh.autofix = False

cfg_tree.register_item(mh, path, options)
wp = work_package.create(False,
path,
options.input_encoding,
mh,
options, {})
backend = MH_Python(options)
wp.register_file()
return backend.process_result(backend.process_wp(wp))

def main_handler():
options = parse_args()

mh = Message_Handler("debug")

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name="mh_python",
version="0.0.1",
version="0.0.2",
author="Chaoqing Wang",
author_email="[email protected]",
description="Matlab to Python/Numpy translator",
Expand All @@ -17,7 +17,7 @@
url="https://translate.mat2py.org",
license="GNU Affero General Public License v3",
packages=["mh_python"],
install_requires=["miss_hit_core>=0.9.30"],
install_requires=["miss-hit-core>=0.9.30"],
python_requires=">=3.6, <4",
classifiers=[
"Development Status :: 2 - Pre-Alpha",
Expand Down

0 comments on commit c57b5d8

Please sign in to comment.