|
3 | 3 | You can adapt this file completely to your liking, but it should at least
|
4 | 4 | contain the root `toctree` directive.
|
5 | 5 |
|
6 |
| -Welcome to pycompile's documentation! |
| 6 | +Welcome to pycompile's docs! |
7 | 7 | =====================================
|
8 | 8 |
|
9 | 9 | .. toctree::
|
10 | 10 | :maxdepth: 2
|
11 | 11 | :caption: Contents:
|
12 | 12 |
|
| 13 | + CLI |
13 | 14 |
|
14 |
| - |
15 |
| -Indices and tables |
| 15 | +Contents |
16 | 16 | ==================
|
17 | 17 |
|
18 | 18 | * :ref:`genindex`
|
19 | 19 | * :ref:`modindex`
|
20 |
| -* :ref:`search` |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +CLI |
| 24 | +================== |
| 25 | +1. `compile <#compile>`__ |
| 26 | +2. `benchmark <#benchmark>`__ |
| 27 | +3. `dry run <#dry-run>`__ |
| 28 | + |
| 29 | + |
| 30 | +================= |
| 31 | +compile |
| 32 | +================= |
| 33 | + |
| 34 | ++-------------------+--------------------------------------------------+ |
| 35 | +| Syntax | Description | |
| 36 | ++===================+==================================================+ |
| 37 | +| ``-- | by default it excludes any ``test`` and | |
| 38 | +| input-path PATH`` | ``__init__.py`` files | |
| 39 | ++-------------------+--------------------------------------------------+ |
| 40 | +| ` | Deletes the sources files. | |
| 41 | +| `--clean-source`` | | |
| 42 | ++-------------------+--------------------------------------------------+ |
| 43 | +| ``--keep-builds`` | Keeps the temp build files. | |
| 44 | ++-------------------+--------------------------------------------------+ |
| 45 | +| ``--cl | Deletes the shared objects (``.so``) files. | |
| 46 | +| ean-executables`` | | |
| 47 | ++-------------------+--------------------------------------------------+ |
| 48 | +| ``--engine`` | Can be ``cython`` or ``nuitka``. | |
| 49 | ++-------------------+--------------------------------------------------+ |
| 50 | +| ``--exc | Glob file patterns for excluding specific files. | |
| 51 | +| lude-glob-paths`` | | |
| 52 | ++-------------------+--------------------------------------------------+ |
| 53 | +| ``--verbose`` | Increase log messages. | |
| 54 | ++-------------------+--------------------------------------------------+ |
| 55 | + |
| 56 | +.. code:: bash |
| 57 | +
|
| 58 | + pycompile -i your_python_files --clean-source --engine nuitka |
| 59 | +
|
| 60 | +By default, the `Cython <https://cython.org/>`__ is being used as the |
| 61 | +default compiler. |
| 62 | + |
| 63 | +For compiling the ``examples`` use the following command: |
| 64 | + |
| 65 | +.. code:: bash |
| 66 | +
|
| 67 | + pycompile -i input_path --engine cython |
| 68 | +
|
| 69 | +which by default, deletes any temp build files and keeps the source |
| 70 | +files. |
| 71 | + |
| 72 | +.. code:: bash |
| 73 | +
|
| 74 | + pycompile -i input_path --engine nuitka |
| 75 | +
|
| 76 | +
|
| 77 | +
|
| 78 | +
|
| 79 | +After the compilation the ``input`` dir will have the following |
| 80 | +structure. |
| 81 | + |
| 82 | +.. code:: text |
| 83 | +
|
| 84 | + examples |
| 85 | + ├── fib.py.py |
| 86 | + ├── fib.cpython-310-darwin.so |
| 87 | + ├── test_fib.py |
| 88 | +
|
| 89 | +
|
| 90 | +
|
| 91 | +Benchmark |
| 92 | +~~~~~~~~~ |
| 93 | + |
| 94 | ++-----------------------+----------------------------------------------+ |
| 95 | +| Syntax | Description | |
| 96 | ++=======================+==============================================+ |
| 97 | +| ``--input-path PATH`` | by default it excludes any ``test`` and | |
| 98 | +| | ``__init__.py`` files | |
| 99 | ++-----------------------+----------------------------------------------+ |
| 100 | +| ``--engine`` | Can be ``cython``, ``nuitka``, ``all`` or | |
| 101 | +| | ``none``. | |
| 102 | ++-----------------------+----------------------------------------------+ |
| 103 | +| ``--type`` | Can be ``memory`` , ``cpy``, or ``both`` | |
| 104 | ++-----------------------+----------------------------------------------+ |
| 105 | +| ``--verbose`` | Increase log messages. | |
| 106 | ++-----------------------+----------------------------------------------+ |
| 107 | +| ``--profil | function name pattern for profiling defaults | |
| 108 | +| e_func_pattern TEXT`` | to ``benchmark`` | |
| 109 | ++-----------------------+----------------------------------------------+ |
| 110 | + |
| 111 | +For running a benchmark on the ``input-path`` use the following command: |
| 112 | + |
| 113 | +.. code:: bash |
| 114 | +
|
| 115 | + pycompile benchmark -i src/examples -vvv |
| 116 | +
|
| 117 | +which by default will start a ``memory`` and a ``cpu`` benchmark, |
| 118 | +starting with ``python`` and then with ``cython`` and ``nuitka`` |
| 119 | +The python package must have a ``test_module.py`` because both benchmark |
| 120 | +types are invoked with ``pytest`` runs |
| 121 | + |
| 122 | +- For **memory profiling** the script will decorate all the functions |
| 123 | + in ``benchmark.py`` with the ``profile`` decorator from |
| 124 | + ``memory-profiler``. This is not optimal memory profiling, because we |
| 125 | + don’t actually ``profile`` the function itself, instead we profile |
| 126 | + the ``caller`` but it’s necessary if we want to ``profile`` also the |
| 127 | + compiled code. Use the ``profile_func_pattern`` to specify the |
| 128 | + function to be profiled in different module for example if ``main`` |
| 129 | + is the entrypoint under ``main.py`` use |
| 130 | + ``--profile_func_pattern main``. |
| 131 | + |
| 132 | +Hence, the following structure are required for the ``benchmark`` |
| 133 | +subcommand. |
| 134 | + |
| 135 | +- For **cpu profiling** the same approached is being used, but instead |
| 136 | + of decorating the ``calling functions`` it ``decorates`` the test |
| 137 | + cases with the ``benchmark`` from ``pytest-benchmark``. |
| 138 | + |
| 139 | +.. code:: text |
| 140 | +
|
| 141 | + module |
| 142 | + ├── sample_funcs.py # implementation |
| 143 | + ├── main.py # entrypoint with a `main` function |
| 144 | + ├── test_sample_funcs.py # test cases |
| 145 | +
|
| 146 | +
|
| 147 | +
|
| 148 | +
|
| 149 | +Dry run |
| 150 | +~~~~~~~ |
| 151 | + |
| 152 | ++-------------------+--------------------------------------------------+ |
| 153 | +| Syntax | Description | |
| 154 | ++===================+==================================================+ |
| 155 | +| ``-- | by default it excludes any ``test`` and | |
| 156 | +| input-path PATH`` | ``__init__.py`` files | |
| 157 | ++-------------------+--------------------------------------------------+ |
| 158 | +| ``--exc | Glob file patterns for excluding specific files. | |
| 159 | +| lude-glob-paths`` | | |
| 160 | ++-------------------+--------------------------------------------------+ |
| 161 | +| ``--verbose`` | Increase log messages. | |
| 162 | ++-------------------+--------------------------------------------------+ |
| 163 | + |
| 164 | +.. code:: bash |
| 165 | +
|
| 166 | + pycompile dry_run -i ./src |
| 167 | +
|
| 168 | +
|
| 169 | +
|
| 170 | +
|
| 171 | +
|
| 172 | +
|
0 commit comments