complexity icon indicating copy to clipboard operation
complexity copied to clipboard

Unable to obtain complexity result from a script

Open Heziode opened this issue 1 year ago • 0 comments

I try to write a script that clone GH repository, and compute some metrics (like LoC with Tokei, and complexity with your tool).

Unfortunaltly, I was unable to get result of complexity when I call the complexity from a script.

Example:

# Import the subprocess module to execute shell commands
import subprocess

# Define a function to call the complexity command with specific parameters
def call_complexity_command():
    # Define the command and arguments as a list of strings
    command = ['complexity', '--format', 'json', '--only', '**/*.ads', '**/*.adb']

    # Execute the command using subprocess.run, capturing the output and error
    result = subprocess.run(command, capture_output=True, text=True)

    # Check if the command was executed successfully
    if result.returncode == 0:
        # Print the standard output from the command
        print("Command output:", result.stdout)
    else:
        # Print the standard error if the command failed
        print("Error:", result.stderr)

# Call the function to execute the command
call_complexity_command()

For example, executing this script from the https://github.com/Heziode/lsystem-editor repo give the following result from the Python script (or Deno, because initialy I write the script in Deno):

python ../../callCommand.py
Command output: {}

But the expected output should be:

{"./src/model/l_system/error/lse-model-l_system-error-not_a_angle.ads":0.2319336,"./src/model/grammar/lse-model-grammar-symbol-logoforwardtrace.adb":1.2820122,"./src/model/l_system/lse-model-l_system.ads":0.121212125,"./src/view/lse-view-view_ptr.ads":0.114285715,"./src/model/l_system/error/lse-model-l_system-error.adb":0.41360295,"./src/model/io/lse-model-io-text_file.adb":15.325445,"./src/model/l_system/lse-model-l_system-l_system_ptr.ads":0.114285715,"./src/model/grammar/lse-model-grammar-symbol-othersymbol.adb":1.8101223,"./src/model/l_system/error/lse-model-l_system-error-not_a_angle.adb":1.05625,"./src/model/io/lse-model-io-drawing_area-postscript.ads":2.00691,"./src/model/io/lse-model-io-drawing_area_factory.adb":2.5208333,"./src/utils/lse-utils-colors.adb":14.512196,"./src/model/grammar/lse-model-grammar-symbol-logouturn.ads":0.36914062,"./src/io/lse-io-drawing_area.adb":10.3359375,"./src/model/grammar/lse-model-grammar-symbol-logoforwardtrace.ads":0.36914062,"./src/model/l_system/error/lse-model-l_system-error-missing_angle.ads":0.2319336,"./src/model/l_system/lse-model-l_system-growth_rule_utils.ads":0.625,"./src/io/lse-io-export_factory.ads":0.8056844,"./src/model/l_system/error/lse-model-l_system-error-missing_axiom.adb":1.05625,"./src/presenter/lse-presenter.ads":0.121212125,"./src/model/grammar/lse-model-grammar-symbol-logouturn.adb":1.2820122,"./src/utils/lse-utils-coordinate_2d.adb":2.2203948,"./src/model/io/lse-model-io-drawing_area-drawing_area_ptr.ads":0.25714287,"./src/model/l_system/error/lse-model-l_system-error-missing_save.ads":0.5878209,"./src/model/l_system/lse-model-l_system-concrete_builder.ads":4.1263094,"./src/model/l_system/error/lse-model-l_system-error-invalid_rule.adb":1.418064,"./src/model/l_system/lse-model-l_system-factory.adb":20.45884,"./src/model/l_system/error/lse-model-l_system-error-unexpected_character.adb":3.3128004,"./src/view/lse-view-callbacks.ads":1.109375,"./src/model/io/lse-model-io-turtle.adb":53.230602,"./src/utils/lse-utils-angle.ads":0.18749237,"./src/model/io/lse-model-io.ads":0.121212125,"./src/model/l_system/error/lse-model-l_system-error-missing_rule.adb":1.05625,"./src/utils/lse-utils-coordinate_2d_list.ads":0.114285715,"./src/io/lse-io.ads":0.121212125,"./src/model/l_system/error/lse-model-l_system-error-missing_rule.ads":0.2319336,"./src/model/l_system/lse-model-l_system-growth_rule.ads":2.3698072,"./src/lse.ads":0.121212125,"./src/model/grammar/lse-model-grammar-symbol-logoangleplus.ads":0.36914062,"./src/model/l_system/error/lse-model-l_system-error-missing_restore.ads":0.5878209,"./src/io/lse-io-drawing_area.ads":1.8852985,"./src/model/io/lse-model-io-drawing_area_factory.ads":0.784446,"./src/model/grammar/lse-model-grammar-symbol-logoangleminus.ads":0.36914062,"./src/model/l_system/lse-model-l_system-factory.ads":1.857855,"./src/view/lse-view-view.adb":57.50195,"./src/model/grammar/lse-model-grammar-symbol-logopositionrestore.adb":1.2820122,"./src/utils/lse-utils.ads":0.121212125,"./src/io/lse-io-export_factory.adb":3.7571023,"./src/utils/lse-utils-colors.ads":5.293683,"./src/model/grammar/lse-model-grammar-symbol-logoangleminus.adb":1.2820122,"./src/main.adb":17.746359,"./src/model/l_system/error/lse-model-l_system-error-unexpected_character.ads":1.0801197,"./src/view/lse-view.ads":0.121212125,"./src/model/grammar/lse-model-grammar-symbol-logopositionrestore.ads":0.36914062,"./src/model/l_system/lse-model-l_system-l_system.ads":2.4479773,"./src/model/io/lse-model-io-turtle_utils.ads":0.114285715,"./src/model/l_system/error/lse-model-l_system-error-missing_save.adb":2.188802,"./src/model/grammar/lse-model-grammar-symbol-othersymbol.ads":0.5486328,"./src/view/lse-view-view.ads":2.9137397,"./src/utils/lse-utils-utils.ads":0.2987805,"./src/model/l_system/error/lse-model-l_system-error-missing_axiom.ads":0.2319336,"./src/utils/lse-utils-angle.adb":3.5672169,"./src/presenter/lse-presenter-presenter.adb":27.83169,"./src/model/grammar/lse-model-grammar-symbol-logoforward.adb":1.2820122,"./src/view/lse-view-callbacks.adb":16.231558,"./src/model/grammar/lse-model-grammar.ads":0.121212125,"./src/model/grammar/lse-model-grammar-symbol-logopositionsave.ads":0.38759765,"./src/model/grammar/lse-model-grammar-symbol-logoforward.ads":0.36914062,"./src/model/io/lse-model-io-text_file.ads":2.6168149,"./src/model/io/lse-model-io-drawing_area-postscript.adb":14.992036,"./src/model/l_system/lse-model-l_system-l_system.adb":25.753843,"./src/model/grammar/lse-model-grammar-symbol.ads":0.5703494,"./src/model/grammar/lse-model-grammar-symbol-logoangleplus.adb":1.2820122,"./src/utils/lse-utils-coordinate_2d_ptr.ads":0.114285715,"./src/presenter/lse-presenter-presenter.ads":1.314892,"./src/model/grammar/lse-model-grammar-symbol.adb":1.0304878,"./src/model/grammar/lse-model-grammar-symbol_utils.ads":0.96022725,"./src/utils/lse-utils-coordinate_2d.ads":0.6766645,"./src/model/lse-model.ads":0.121212125,"./src/model/l_system/lse-model-l_system-growth_rule.adb":3.9556818,"./src/model/io/lse-model-io-drawing_area.ads":0.9329382,"./src/model/l_system/error/lse-model-l_system-error-invalid_rule.ads":0.55208874,"./src/model/l_system/error/lse-model-l_system-error.ads":1.146825,"./src/model/io/lse-model-io-turtle.ads":1.6385912,"./src/model/l_system/lse-model-l_system-concrete_builder.adb":57.907936,"./src/model/l_system/error/lse-model-l_system-error-missing_restore.adb":2.188802,"./src/model/lse-model-interpreter.ads":0.36055595,"./src/model/l_system/error/lse-model-l_system-error-missing_angle.adb":1.05625,"./src/model/grammar/lse-model-grammar-symbol-logopositionsave.adb":1.2820122}

Setup:

  • Complexity version: 0.4.2
  • OS: macOS (14.5 (23F79))

Heziode avatar Jul 28 '24 19:07 Heziode