Skip to content

CLI Usage

The Py++ CLI can initialize Py++ projects, transpile your code to C++, and build and run the generated C++ CMake project (if you don't want to use the CMake commands directly).

Primary Workflow

You can initialize your Py++ project in your current directory with:

pypp init

This will create: - a .pypp directory with: - cpp and resources directories - a proj_info.json file with default configuration. - a 'hello world' example file named main.py.

Once you have some code written, or are using the hello world code generated by init, you can transpile your project to C++ with:

pypp do transpile

It is also useful to format your code at the same time as transpiling, otherwise the generated code will be just a few long lines and unreadable. So, instead of the above command, you can transpile and format at the same time with:

pypp do transpile format

At this point, you will have a CMake project in the .pypp/cpp directory that you can use. You can do the usual CMake commands to build your project. There is also a pypp command to help you build the CMake project if you are using the clang compiler:

pypp do build

This command just runs cmake -S . -B build -G "Ninja" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release and cmake --build build --config Release together.

There is also a pypp command to help you run your generated executable if your executable is exactly at .pypp/cpp/build/my_exe_name.exe:

pypp do run -e my_exe_name

Or, you can also do the transpile, format, build, and run all at the same time with

pypp do transpile format build run -e main

Other commands

delete_timestamps

This one deletes the file_timestamps.json file under the .pypp directory. The transpiler uses the data in this file to determine if a Python file has been modified since the last transpile. If a file has not been modified since the last transpile, the transpiler won't transpile it again. So, deleting this file will result in Py++ transpiling all your Python files over.

pypp delete_timestamps

delete_cpp

This one will delete the entire .pypp/cpp directory (or whatever directory you have configured the C++ generated code to be written to). This forces the transpiler to recopy the C++ template code (which is C++ code that all Py++ generated C++ projects depend on) to the .pypp/cpp directory. The command also runs delete_timestamps

You will want to run this command if you update your Py++ CLI to a new version, because the C++ template code could have changed.

There is no harm in running this command. Only your next C++ build will be slower because everything needs to be recompiled.

pypp delete_cpp

delete_cpp_libs

This one will delete the entire libs directory in .pypp/cpp (or whatever directory you have configured the C++ generated code to be written to). This forces the transpiler to recopy the C++ code from all Py++ libraries you have installed.

You will want to run this command if you upgrade one of your Py++ libraries, because the transpiler won't overwrite the C++ code for the library in the libs directory if the C++ code has changed.

Again, there is no harm in running this command. Only your next C++ build will be slower because everything needs to be recompiled.

pypp delete_cpp_libs

Summary list of commands

  • init
  • do
  • delete_timestamps
  • delete_cpp
  • delete_cpp_libs