def main(): conf = config.read_cfg() parser = cli(data) # Show help if no arg provided if len(sys.argv) == 1: parser.print_help(sys.stderr) raise ExpectedExit() # This is for the command required constraint in 2.0 try: args = parser.parse_args() except TypeError: raise NoCommandFoundError() if args.name: conf.update({"name": args.name}) elif not args.name and not conf.path: conf.update({"name": "cz_conventional_commits"}) if args.debug: logging.getLogger("commitizen").setLevel(logging.DEBUG) sys.excepthook = commitizen_debug_excepthook args.func(conf, vars(args))()
def main(): conf = config.read_cfg() parser = cli(data) # Show help if no arg provided if len(sys.argv) == 1: parser.print_help(sys.stderr) raise SystemExit() try: args = parser.parse_args() except TypeError: out.error("Command is required") raise SystemExit() if args.name: conf.update({"name": args.name}) if args.version: warnings.warn( "'cz --version' will be deprecated in next major version. " "Please use 'cz version' command from your scripts") logging.getLogger("commitizen").setLevel(logging.DEBUG) if args.debug: warnings.warn("Debug will be deprecated in next major version. " "Please remove it from your scripts") logging.getLogger("commitizen").setLevel(logging.DEBUG) # TODO: This try block can be removed after command is required in 2.0 try: args.func(conf, vars(args))() except AttributeError: out.error("Command is required")
def test_load_empty_pyproject_toml_and_cz_toml_with_config(_, tmpdir): with tmpdir.as_cwd(): p = tmpdir.join("pyproject.toml") p.write("") p = tmpdir.join(".cz.toml") p.write(PYPROJECT) cfg = config.read_cfg() assert cfg.settings == _settings
def main(): conf = config.read_cfg() parser = cli(data) # Show help if no arg provided if len(sys.argv) == 1: parser.print_help(sys.stderr) raise SystemExit() # This is for the command required constraint in 2.0 try: args = parser.parse_args() except TypeError: out.error("Command is required") raise SystemExit() if args.name: conf.update({"name": args.name}) elif not args.name and not conf.path: conf.update({"name": "cz_conventional_commits"}) if args.version: warnings.warn( ("'cz --version' will be deprecated in next major version. " "Please use 'cz version' command from your scripts"), category=DeprecationWarning, ) args.func = commands.Version if args.debug: warnings.warn( ("Debug will be deprecated in next major version. " "Please remove it from your scripts"), category=DeprecationWarning, ) logging.getLogger("commitizen").setLevel(logging.DEBUG) # TODO: This try block can be removed after command is required in 2.0 # Handle the case that argument is given, but no command is provided try: args.func(conf, vars(args))() except AttributeError: out.error("Command is required") raise SystemExit()
def main(): conf = config.read_cfg() parser = cli(data) argcomplete.autocomplete(parser) # Show help if no arg provided if len(sys.argv) == 1: parser.print_help(sys.stderr) raise ExpectedExit() # This is for the command required constraint in 2.0 try: args = parser.parse_args() except (TypeError, SystemExit) as e: # https://github.com/commitizen-tools/commitizen/issues/429 # argparse raises TypeError when non exist command is provided on Python < 3.9 # but raise SystemExit with exit code == 2 on Python 3.9 if isinstance(e, TypeError) or (isinstance(e, SystemExit) and e.code == 2): raise NoCommandFoundError() raise e if args.name: conf.update({"name": args.name}) elif not args.name and not conf.path: conf.update({"name": "cz_conventional_commits"}) if args.debug: logging.getLogger("commitizen").setLevel(logging.DEBUG) sys.excepthook = commitizen_debug_excepthook elif args.no_raise: no_raise_exit_codes = parse_no_raise(args.no_raise) no_raise_debug_excepthook = partial(commitizen_excepthook, no_raise=no_raise_exit_codes) sys.excepthook = no_raise_debug_excepthook args.func(conf, vars(args))()
def main(): conf = config.read_cfg() parser = cli(data) # Show help if no arg provided if len(sys.argv) == 1: parser.print_help(sys.stderr) raise SystemExit() args = parser.parse_args() if args.name: conf.update({"name": args.name}) if args.debug: warnings.warn("Debug will be deprecated in next major version. " "Please remove it from your scripts") logging.getLogger("commitizen").setLevel(logging.DEBUG) if args.version: out.line(__version__) raise SystemExit() args.func(conf, vars(args))()
def test_conf_returns_default_when_no_files(_, tmpdir): with tmpdir.as_cwd(): cfg = config.read_cfg() assert cfg.settings == defaults.DEFAULT_SETTINGS
def test_load_conf(_, config_files_manager): cfg = config.read_cfg() assert cfg.settings == _settings
def test_set_key(config_files_manager): _conf = config.read_cfg() _conf.set_key("version", "2.0.0") cfg = config.read_cfg() assert cfg.settings == _new_settings
def test_set_key(configure_supported_files, config_files_manager): config.read_cfg() config.set_key("version", "2.0.0") cfg = config.read_cfg() assert cfg == _new_config
def test_conf_returns_default_when_no_files(configure_supported_files): cfg = config.read_cfg() assert cfg == defaults.settings
def test_conf_is_loaded_with_empty_pyproject_but_ok_cz( empty_pyproject_ok_cz, configure_supported_files): cfg = config.read_cfg() assert cfg == _config
def test_load_conf(config_files_manager, configure_supported_files): cfg = config.read_cfg() assert cfg == _config
def test_read_cfg_when_not_in_a_git_project(tmpdir): with tmpdir.as_cwd() as _: with pytest.raises(NotAGitProjectError) as excinfo: config.read_cfg() assert NotAGitProjectError.message in str(excinfo.value)
def test_read_cfg_when_not_in_a_git_project(tmpdir): with tmpdir.as_cwd() as _: with pytest.raises(SystemExit): config.read_cfg()