Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add converter entry point #1474

Merged
merged 18 commits into from
Sep 15, 2022
Merged

Add converter entry point #1474

merged 18 commits into from
Sep 15, 2022

Conversation

germa89
Copy link
Collaborator

@germa89 germa89 commented Sep 8, 2022

Add a command line interface for mapdl.convert_script.

Close #1469

Note

I couldn't make it work for [project.entry-points.(...)], not sure if because I was in editable mode (pip install -e .) or because I was doing something wrong.
I end up using [project.scripts] as ansys-templates library.

Result

$ convertscript.exe --helpconvertscript.exe --help
Usage: convertscript [OPTIONS] FILENAME_IN

  PyMAPDL CLI tool for converting MAPDL scripts to PyMAPDL scripts.

  USAGE:

  The main usage is:

      $ convertscript mapdl.dat -o python.py

      File mapdl.dat successfully converted to python.py.

  The output argument is completely optional, in that case, it will just
  change the extension to "py".

      $ convertscript mapdl.dat

      File mapdl.dat successfully converted to mapdl.py.

  You can use any option from ``ansys.mapdl.core.convert.convert_script``
  function:

      $ convertscript mapdl.dat --auto-exit False

      File mapdl.dat successfully converted to mapdl.py.

      $ convertscript.exe mapdl.dat --filename_out mapdl.out --add_imports
      False

      File mapdl.dat successfully converted to mapdl.out.

Options:
  -o TEXT                        Name of the output Python script.
  --filename_out TEXT            Name of the output Python script.
  --loglevel TEXT                Logging level of the ansys object within the
                                 script.
  --auto_exit BOOLEAN            Adds a line to the end of the script to exit
                                 MAPDL. Default ``True``
  --line_ending TEXT             When None, automatically is `` .``
  --exec_file TEXT               Specify the location of the ANSYS executable
                                 and include it in the converter output
                                 ``launch_mapdl`` call.
  --macros_as_functions BOOLEAN  Attempt to convert MAPDL macros to python
                                 functions.
  --use_function_names BOOLEAN   Convert MAPDL functions to
                                 ansys.mapdl.core.Mapdl class methods.  When
                                 ``True``, the MAPDL command ``K`` will be
                                 converted to ``mapdl.k``.  When ``False``, it
                                 will be converted to ``mapdl.run('k')``.
  --show_log BOOLEAN             Print the converted commands using a logger
                                 (from ``logging`` Python module).
  --add_imports BOOLEAN          If ``True``, add the lines ``from
                                 ansys.mapdl.core import launch_mapdl`` and
                                 ``mapdl = launch_mapdl(loglevel="WARNING")``
                                 to the beginning of the output file. This
                                 option is useful if you are planning to use
                                 the output script from another mapdl session.
                                 See examples section. This option overrides
                                 ``auto_exit``.
  --comment_solve BOOLEAN        If ``True``, it will pythonically comment the
                                 lines that contain ``"SOLVE"`` or ``"/EOF"``.
  --cleanup_output BOOLEAN       If ``True`` the output is formatted using
                                 ``autopep8`` before writing the file or
                                 returning the string. This requires
                                 ``autopep8`` to be installed.
  --header BOOLEAN               If ``True``, the default header is written in
                                 the first line of the output. If a string is
                                 provided, this string will be used as header.
  --print_com BOOLEAN            Print command ``/COM`` arguments to python
                                 console. Defaults to ``True``.
  --help                         Show this message and exit.

Adding filename_out kwarg.

Replacing ending line with "\n".

Adding spacing between code parts.
Adding doc about exec_file argument in converter.
Only raise an error if using default file name.
@germa89 germa89 added the Enhancement Improve any current implemented feature label Sep 8, 2022
@germa89 germa89 added this to the v0.64.0 milestone Sep 8, 2022
@germa89 germa89 requested a review from koubaa September 8, 2022 12:21
@germa89 germa89 self-assigned this Sep 8, 2022
@github-actions github-actions bot added Dependencies Maintenance General maintenance of the repo (libraries, cicd, etc) New Feature Request or proposal for a new feature labels Sep 8, 2022
@codecov
Copy link

codecov bot commented Sep 8, 2022

Codecov Report

Merging #1474 (de49cc5) into main (3d21ac6) will increase coverage by 0.25%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1474      +/-   ##
==========================================
+ Coverage   80.32%   80.58%   +0.25%     
==========================================
  Files          43       43              
  Lines        6779     6813      +34     
==========================================
+ Hits         5445     5490      +45     
+ Misses       1334     1323      -11     

@germa89
Copy link
Collaborator Author

germa89 commented Sep 8, 2022

I couldn't make it work for [project.entry-points.(...)], not sure if because I was in editable mode (pip install -e .) or because I was doing something wrong.
I end up using [project.scripts] as ansys-templates library.

Pinging @RobPasMue @jorgepiloto for the note.

@github-actions github-actions bot added the CI/CD Related with CICD, Github Actions, etc label Sep 8, 2022
@koubaa
Copy link
Contributor

koubaa commented Sep 9, 2022

convertscript is quite a generic name, the user should know that it's from pymapdl, right?

@germa89
Copy link
Collaborator Author

germa89 commented Sep 9, 2022

convertscript is quite a generic name, the user should know that it's from pymapdl, right?

Very good point. ConvertMAPD2Python?? convertmapdlscript??

@koubaa
Copy link
Contributor

koubaa commented Sep 9, 2022

@akaszynski a preference? If we do this more in the future across pyansys libraries, should there be a convention?

@akaszynski
Copy link
Collaborator

@akaszynski a preference? If we do this more in the future across pyansys libraries, should there be a convention?

We should follow bash conventions. Google has a guide for this. I'd go underscores, not CAPS, avoid numbers.

@koubaa
Copy link
Contributor

koubaa commented Sep 9, 2022

@akaszynski I was thinking more about the name and discovery of the command line program. SHould it be:

convertmapdlscript -h
ansys_mapdl_convert_script -h
python -m ansys.mapdl.core convert_script -h

@akaszynski
Copy link
Collaborator

pymapdl_convert_script -h

@germa89
Copy link
Collaborator Author

germa89 commented Sep 12, 2022

pymapdl_convert_script

Changed to this.

@germa89
Copy link
Collaborator Author

germa89 commented Sep 15, 2022

@koubaa could you review this PR?

@germa89 germa89 merged commit 284fca2 into main Sep 15, 2022
@germa89 germa89 deleted the feat/add-converter-entry-point branch September 15, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/CD Related with CICD, Github Actions, etc Dependencies Enhancement Improve any current implemented feature Maintenance General maintenance of the repo (libraries, cicd, etc) New Feature Request or proposal for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert script as a console entry point
3 participants