22from typing import Optional
33from pathlib import Path
44import logging
5- from subprocess import check_call , check_output , CalledProcessError
5+ from subprocess import check_call , CalledProcessError , getoutput
6+ from .generate_utils import return_origin_path
67
78from .change_log import main as change_log_main
89
@@ -21,22 +22,20 @@ def create_package(prefolder, name, dest_folder=DEFAULT_DEST_FOLDER):
2122 )
2223
2324
25+ @return_origin_path
2426def change_log_new (package_folder : str , lastest_pypi_version : bool ) -> str :
27+ os .chdir (package_folder )
2528 cmd = "tox run -c ../../../eng/tox/tox.ini --root . -e breaking -- --changelog "
2629 if lastest_pypi_version :
2730 cmd += "--latest-pypi-version"
2831 try :
29- output = check_output (cmd , cwd = package_folder , shell = True )
32+ output = getoutput (cmd )
3033 except CalledProcessError as e :
3134 _LOGGER .warning (f"Error ocurred when call breaking change detector: { e .output .decode ('utf-8' )} " )
3235 raise e
33- result = [l for l in output .decode ( "utf-8" ). split ( os . linesep )]
36+ result = [l for l in output .split ( " \n " )]
3437 begin = result .index ("===== changelog start =====" )
3538 end = result .index ("===== changelog end =====" )
36- if begin == - 1 or end == - 1 :
37- warn_info = "Failed to get changelog from breaking change detector"
38- _LOGGER .warning (warn_info )
39- raise Exception (warn_info )
4039 return "\n " .join (result [begin + 1 : end ]).strip ()
4140
4241
0 commit comments