Skip to content

Commit

Permalink
Merge branch 'mr/ramonat/remove-e3-config' into 'master'
Browse files Browse the repository at this point in the history
Remove e3.config and typeguard dependency

See merge request it/e3-core!15
  • Loading branch information
enzbang committed Jul 24, 2024
2 parents 69b819f + 85176bc commit c9d9e3e
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 225 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* Add DLL closure check to Anod class
* Add git_shallow_fetch_since to checkout.py

* Backward incompatible change:
* Remove e3.config and typeguard dependency. This removes the possibility
to configure the default e3.log formatting using `e3.toml`

# Version 22.6.0 (2024-06-19)

* Fix encoding/vex action statement for affected products
Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ dependencies = [
Repository = "https://github.com/AdaCore/e3-core"

[project.optional-dependencies]
config = [
"tomlkit",
# There are some backward incompatible checks in typeguard 3.x
"typeguard<3.0.0"
]
test = [
"coverage",
"mock",
Expand Down
142 changes: 0 additions & 142 deletions src/e3/config.py

This file was deleted.

26 changes: 4 additions & 22 deletions src/e3/log.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
"""Extensions to the standard Python logging system."""

from __future__ import annotations
from dataclasses import dataclass

import logging
import os
import re
import sys
import time
import json
from typing import TYPE_CHECKING, ClassVar
from typing import TYPE_CHECKING

from colorama import Fore, Style
from tqdm import tqdm

from e3.config import ConfigSection

if TYPE_CHECKING:
from typing import (
Any,
Expand Down Expand Up @@ -47,28 +44,13 @@
NO_DEBUG_LOGGING_MODULES = ["boto3", "botocore", "requests", "urllib3"]


@dataclass
class LogConfig(ConfigSection):
title: ClassVar[str] = "log"

pretty: bool = True
stream_fmt: str = "%(levelname)-8s %(message)s"
file_fmt: str = "%(asctime)s: %(name)-24s: %(levelname)-8s %(message)s"


log_config = LogConfig.load()


# Default output stream (sys.stdout by default, or a file descriptor if
# activate() is called with a filename.
default_output_stream: TextIO | IO[str] = sys.stdout

# If sys.stdout is a terminal then enable "pretty" output for user
# This includes progress bars and colors
if sys.stdout.isatty(): # all: no cover (not used in production!)
pretty_cli = log_config.pretty
else:
pretty_cli = False
pretty_cli = sys.stdout.isatty()

console_logs: str | None = None

Expand Down Expand Up @@ -419,8 +401,8 @@ def activate_with_args(args: Namespace, default_level: int = logging.WARNING) ->


def activate(
stream_format: str = log_config.stream_fmt,
file_format: str = log_config.file_fmt,
stream_format: str = "%(levelname)-8s %(message)s",
file_format: str = "%(asctime)s: %(name)-24s: %(levelname)-8s %(message)s",
datefmt: str | None = None,
level: int = logging.INFO,
filename: str | None = None,
Expand Down
2 changes: 0 additions & 2 deletions src/e3/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import os

from e3.config import Config
from e3.env import Env
from e3.fs import rm
from e3.os.fs import cd, mv, which
Expand Down Expand Up @@ -88,7 +87,6 @@ def env_protect(request: pytest.FixtureRequest) -> None:
Env().store()
tempd = mkdtemp()
cd(tempd)
Config.data = {}

os.environ["TZ"] = "UTC"
os.environ["E3_ENABLE_FEATURE"] = ""
Expand Down
10 changes: 0 additions & 10 deletions src/e3/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import sys
from typing import TYPE_CHECKING
from enum import Enum
from dataclasses import asdict
from pprint import pformat

import e3.log

Expand Down Expand Up @@ -178,9 +176,6 @@ def main() -> None:
m.argument_parser.add_argument(
"--check", help="Run e3 sanity checking", action="store_true"
)
m.argument_parser.add_argument(
"--show-config", action="store_true", help="Show e3 config"
)
m.parse_args()

if TYPE_CHECKING:
Expand All @@ -200,11 +195,6 @@ def main() -> None:
elif m.args.platform_info:
print(getattr(Env(), m.args.platform_info))

if m.args.show_config:
print("[log]")
for k, v in asdict(e3.log.log_config).items():
print("{}: {}".format(k, pformat(v)))


def set_python_env(prefix: str) -> None:
"""Set environment for a Python distribution.
Expand Down
21 changes: 0 additions & 21 deletions tests/tests_e3/config/main_test.py

This file was deleted.

23 changes: 0 additions & 23 deletions tests/tests_e3/main/main_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import re
import sys

Expand All @@ -15,28 +14,6 @@ def test_main():
)


def test_main_config():
os.environ["E3_CONFIG"] = "e3.toml"
assert "pretty: True" in e3.os.process.Run(["e3", "--show-config"]).out

with open("e3.toml", "w") as f:
f.write("[log]\npretty = false\n")
assert "pretty: False" in e3.os.process.Run(["e3", "--show-config"]).out

# Verify that invalid config field is ignored
with open("e3.toml", "w") as f:
f.write('[log]\npretty = "false"\nstream_fmt = "%(message)s"')
out = e3.os.process.Run(["e3", "--show-config"]).out
assert "pretty: True" in out
assert "stream_fmt: '%(message)s'" in out
assert "type of log.pretty must be bool" in out

# And finally check that invalid toml are discarded
with open("e3.toml", "w") as f:
f.write("this is an invalid toml content")
assert "pretty: True" in e3.os.process.Run(["e3", "--show-config"]).out


def test_mainprog():
with open("mymain.py", "w") as f:
f.write(
Expand Down

0 comments on commit c9d9e3e

Please sign in to comment.