Skip to content

Commit

Permalink
Do not import builder in release script
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Oct 28, 2024
1 parent 541a113 commit 14b2bd7
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from typing import Sequence, Tuple
from unittest.mock import patch

from mypy_boto3_builder.logger import get_logger
from requests.exceptions import ConnectionError as RequestsConnectionError
from requests.exceptions import HTTPError
from twine.commands.upload import upload
Expand All @@ -37,9 +36,25 @@
]
LOGGER_NAME = "release"

logging.getLogger("twine").disabled = True
logging.getLogger("twine.commands.upload").disabled = True
logger = get_logger(logging.DEBUG, LOGGER_NAME)

def setup_logging(level: int) -> logging.Logger:
"""
Get Logger instance.
Returns:
Overriden Logger.
"""
logging.getLogger("twine").disabled = True
logging.getLogger("twine.commands.upload").disabled = True

logger = logging.getLogger(LOGGER_NAME)
stream_handler = logging.StreamHandler()
formatter = logging.Formatter("%(asctime)s %(levelname)-7s %(message)s", datefmt="%H:%M:%S")
stream_handler.setFormatter(formatter)
stream_handler.setLevel(level)
logger.addHandler(stream_handler)
logger.setLevel(level)
return logger


@dataclass
Expand Down Expand Up @@ -97,6 +112,7 @@ def check_call(cmd: Sequence[str], print_error: bool = True) -> str:
return subprocess.check_output(cmd, stderr=subprocess.STDOUT, encoding="utf-8")
except subprocess.CalledProcessError as e:
if print_error:
logger = logging.getLogger(LOGGER_NAME)
for line in e.output.splitlines():
logger.warning(line)
raise
Expand Down Expand Up @@ -137,6 +153,7 @@ def build(path: Path, max_retries: int = 10) -> Path:
"""
Build package.
"""
logger = logging.getLogger(LOGGER_NAME)
attempt = 1
last_error = Exception("Unknown error")
while attempt <= max_retries:
Expand Down Expand Up @@ -168,6 +185,7 @@ def publish(path: Path, max_retries: int = 10) -> Path:
attempt = 1
dist_path = path / "dist"
packages = [i.as_posix() for i in dist_path.glob("*")]
logger = logging.getLogger(LOGGER_NAME)
last_error = Exception("Unknown error")
while attempt <= max_retries:
try:
Expand Down Expand Up @@ -246,6 +264,8 @@ def main() -> None:
Run main logic.
"""
args = parse_args()
setup_logging(logging.DEBUG)
logger = logging.getLogger(LOGGER_NAME)
paths = [i for i in args.path.absolute().iterdir() if i.is_dir()]
paths.sort(key=lambda x: x.name)
if args.filter:
Expand Down

0 comments on commit 14b2bd7

Please sign in to comment.