Package: pycompile
pycompile"""                                        _ __ __  _   _  ___ ___  _ __ ___  _ __ (_) | ___| '_ \| | | |/ __/ _ \| '_ ` _ \| '_ \| | |/ _ \| |_) | |_| | (_| (_) | | | | | | |_) | | |  __/| .__/ \__, |\___\___/|_| |_| |_| .__/|_|_|\___||_|    |___/                    |_|"""A CLI tool for compiling python source code usingCythonorNuitka.Latest docs 📝hereTable of contentsinstallation 🔨compilebenchmarkdry runLocal-development 💻🏭InstallationpipinstallpycompileCompileSyntaxDescription--input-path PATHby default it excludes anytestand__init__.pyfiles--clean-sourceDeletes the sources files.--keep-buildsKeeps the temp build files.--clean-executablesDeletes the shared objects (.so) files.--engineCan becythonornuitka.--exclude-glob-pathsGlob file patterns for excluding specific files.--verboseIncrease log messages.pycompile-iyour_python_files--clean-source--enginenuitkaBy default, theCythonis being used as the default
compiler.[!TIP]
For compiling theexamplesuse the following commandpycompile-iinput_path--enginecythonwhich by default, deletes any temp build files and keeps the source files.orpycompile-iinput_path--enginenuitkaAfter the compilation theinputdir  will have the following structure.examples
    ├── fib.py.py                           
    ├── fib.cpython-310-darwin.so                      
    ├── test_fib.pyBenchmarkSyntaxDescription--input-path PATHby default it excludes anytestand__init__.pyfiles--engineCan becython,nuitka,allornone.--typeCan bememory,cpy, orboth--verboseIncrease log messages.--profile_func_pattern TEXTfunction name pattern for profiling defaults tobenchmarkFor running a benchmark on theinput-pathuse the following command:pycompilebenchmark-isrc/examples-vvvwhich by default will start amemoryand acpubenchmark, starting withpythonand then withcythonandnuitka[!IMPORTANT]
The python package must have atest_module.pybecause both benchmark types are invoked
withpytestruns[!NOTE]
Formemory profilingthe script will decorate all the functions inbenchmark.pywith theprofiledecorator frommemory-profiler. This is not optimal memory profiling,
because we don't actuallyprofilethe function itself, instead we profile thecallerbut it's necessary
if we want toprofilealso the compiled code.
Use theprofile_func_patternto specify the function to be profiled in different module for example
ifmainis the entrypoint undermain.pyuse--profile_func_pattern main.Hence, the following structure are required for thebenchmarksubcommand.module
    ├── sample_funcs.py                        # implementation
    ├── main.py                                # entrypoint with a `main` function, during compilation will be excluded
    ├── test_sample_funcs.py                   # test casesMemory benchmarkusing:3.10.9 (main, Feb  2 2023, 12:59:36) [Clang 14.0.0 (clang-1400.0.29.202)Line #    Mem usage    Increment  Occurrences   Line Contents
=============================================================
     7     49.4 MiB     49.4 MiB           1   @profile
     8                                         def samples_benchmark():
     9    127.7 MiB     78.4 MiB           1       sum_of_squares()
    10    166.0 MiB     38.3 MiB           1       harmonic_mean()
    11    166.0 MiB      0.0 MiB           1       fibonacci(30)
    12    204.2 MiB     38.2 MiB           1       sum_numbers()
    13     57.7 MiB   -146.5 MiB           1       sum_strings()46.03s call     test_examples.py::test_examples[!NOTE]
Forcpu profilingthe same approached is being used, but instead of decorating thecalling functionsitdecoratesthe test cases with thebenchmarkfrompytest-benchmark.CPU benchmarkusing:3.10.9 (main, Feb  2 2023, 12:59:36) [Clang 14.0.0 (clang-1400.0.29.202)]------------------------------------------- benchmark: 1 tests ------------------------------------------
Name (time in s)        Min     Max    Mean  StdDev  Median     IQR  Outliers     OPS  Rounds  Iterations
---------------------------------------------------------------------------------------------------------
test_examples        3.9257  4.0640  3.9731  0.0605  3.9387  0.0917       1;0  0.2517       5           1
---------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean
=================================================================================================================
29.40s call     test_examples.py::test_examplesDry runSyntaxDescription--input-path PATHby default it excludes anytestand__init__.pyfiles--exclude-glob-pathsGlob file patterns for excluding specific files.--verboseIncrease log messages.pycompiledry_run-i./srcLocal-developmentFor local development run the following commandmakesetup-local-devAll availablemakecommandsmakehelp