• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CityOfZion / neo3-boa / e084b44c-1a5f-4649-92cd-d3ed06099181

05 Mar 2024 05:58PM UTC coverage: 92.023% (-0.08%) from 92.107%
e084b44c-1a5f-4649-92cd-d3ed06099181

push

circleci

Mirella de Medeiros
CU-86drpnc9z - Drop support to Python 3.10

20547 of 22328 relevant lines covered (92.02%)

1.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.04
/boa3/internal/cli_commands/compile_command.py
1
import logging
2✔
2
import os
2✔
3
import sys
2✔
4
from argparse import _SubParsersAction
2✔
5

6
from boa3.boa3 import Boa3
2✔
7
from boa3.internal.cli_commands.icommand import ICommand
2✔
8
from boa3.internal.exception.NotLoadedException import NotLoadedException
2✔
9

10

11
class CompileCommand(ICommand):
2✔
12

13
    def __init__(self, main_parser: _SubParsersAction):
2✔
14
        super().__init__(main_parser, 'compile', 'Compiles your smart contract')
2✔
15

16
    def add_arguments_and_callback(self):
2✔
17
        self.parser.add_argument("input",
2✔
18
                                 type=str,
19
                                 help=".py smart contract to compile")
20
        self.parser.add_argument("-db", "--debug",
2✔
21
                                 action='store_true',
22
                                 help="generates a .nefdbgnfo file")
23
        self.parser.add_argument("--project-path",
2✔
24
                                 type=str,
25
                                 help="Project root path. Path of the contract by default.")
26
        self.parser.add_argument("-e", "--env",
2✔
27
                                 type=str,
28
                                 help="Set the contract environment for compiling.")
29
        self.parser.add_argument("-o", "--output-path",
2✔
30
                                 metavar='NEF_OUTPUT',
31
                                 type=str,
32
                                 default=None,
33
                                 help="Chooses the name and where the compiled files will be generated, "
34
                                      "if not specified it will be generated on the same directory with the same name "
35
                                      "as the python file.")
36
        self.parser.add_argument("--no-failfast",
2✔
37
                                 action='store_true',
38
                                 help="Do not stop on first compile error")
39
        self.parser.add_argument("--log-level",
2✔
40
                                 type=str,
41
                                 help="Log output level")
42

43
        self.parser.set_defaults(func=self.execute_command)
2✔
44

45
    @staticmethod
2✔
46
    def execute_command(args: dict):
2✔
47
        sc_path: str = args['input']
2✔
48
        project_path: str = args['project_path']
2✔
49
        debug: bool = args['debug']
2✔
50
        env: str = args['env']
2✔
51
        output_path: str | None = args['output_path']
2✔
52
        fail_fast: bool = not args['no_failfast']
2✔
53
        log_level = args['log_level']
2✔
54

55
        if not sc_path.endswith(".py") or not os.path.isfile(sc_path):
2✔
56
            logging.error("Input file is not .py")
2✔
57
            sys.exit(1)
2✔
58

59
        fullpath = os.path.realpath(sc_path)
2✔
60
        path, filename = os.path.split(fullpath)
2✔
61

62
        if isinstance(output_path, str):
2✔
63
            if not output_path.endswith('.nef'):
2✔
64
                logging.error("Output path file extension is not .nef")
2✔
65
                sys.exit(1)
2✔
66

67
            path, filename = os.path.split(os.path.realpath(output_path))
2✔
68

69
        try:
2✔
70
            Boa3.compile_and_save(sc_path,
2✔
71
                                  output_path=output_path,
72
                                  debug=debug,
73
                                  root_folder=project_path,
74
                                  env=env,
75
                                  fail_fast=fail_fast,
76
                                  show_errors=True,
77
                                  log_level=log_level
78
                                  )
79
            logging.info(f"Wrote {filename.replace('.py', '.nef')} to {path}")
2✔
80
        except NotLoadedException as e:
2✔
81
            error_message = e.message
2✔
82
            log_error = 'Could not compile'
2✔
83
            if len(error_message) > 0:
2✔
84
                log_error += f': {error_message}'
×
85

86
            logging.error(log_error)
2✔
87
            sys.exit(1)
2✔
88
        except Exception as e:
2✔
89
            logging.exception(e)
2✔
90
            sys.exit(1)
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc