Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify logging #368

Open
yajo opened this issue Mar 11, 2021 · 2 comments
Open

Unify logging #368

yajo opened this issue Mar 11, 2021 · 2 comments
Assignees

Comments

@yajo
Copy link
Member

yajo commented Mar 11, 2021

There are many logging system around the codebase. Makes it confusing:

  • Old one

    copier/copier/tools.py

    Lines 60 to 88 in 76d6c2f

    def printf(
    action: str,
    msg: Any = "",
    style: Optional[IntSeq] = None,
    indent: int = 10,
    quiet: Union[bool, StrictBool] = False,
    file_: TextIO = sys.stdout,
    ) -> Optional[str]:
    if quiet:
    return None # HACK: Satisfy MyPy
    _msg = str(msg)
    action = action.rjust(indent, " ")
    if not style:
    return action + _msg
    out = style + [action] + Style.RESET + [INDENT, _msg] # type: ignore
    print(*out, sep="", file=file_)
    return None # HACK: Satisfy MyPy
    def printf_exception(
    e: Exception, action: str, msg: str = "", indent: int = 0, quiet: bool = False
    ) -> None:
    if not quiet:
    print("", file=sys.stderr)
    printf(action, msg=msg, style=Style.DANGER, indent=indent, file_=sys.stderr)
    print(HLINE, file=sys.stderr)
    print(e, file=sys.stderr)
    print(HLINE, file=sys.stderr)
  • plumbum one

    copier/copier/main.py

    Lines 605 to 609 in b3190c2

    print(
    colors.warn
    | f"Either {self.subproject.template.ref} or {self.template.commit} is not a PEP 440 valid version.",
    file=sys.stderr,
    )
  • Native warnings

    copier/copier/template.py

    Lines 114 to 117 in d86c88d

    warn(
    "Cannot check Copier version constraint.",
    UnknownCopierVersionWarning,
    )
  • Plumbum's ask, as opposed to Questionary's
    return bool(ask(f" Overwrite {dst_relpath}?", default=True))

Gotta pick one and use only it. Possibly Questionary for interactive output, and https://docs.python.org/3/library/logging.html with captureWarnings for informational output.

@yajo yajo added this to the v6.0.0 milestone Mar 11, 2021
@yajo yajo self-assigned this Mar 11, 2021
@karolzlot
Copy link

karolzlot commented Jul 21, 2021

@yajo

It should be written which file is processed before processing it, not after.

If I have error then I have to guess which file is next. (because this next file is causing error)

example error which I am now debugging:

    create  .
    create  .dependabot
    create  .dependabot/config.yml
    create  .en v copy
    create  .env
    create  .gitignore
    create  LICENSE
    create  README.md
    create  Banana
    create  Banana/.prettierignore
    create  Banana/backend
    create  Banana/backend/alembic.ini
    create  Banana/backend/app
    create  Banana/backend/app/alembic
    create  Banana/backend/app/alembic/env.py
    create  Banana/backend/app/alembic/README
    create  Banana/backend/app/alembic/script.py.mako
    create  Banana/backend/app/alembic/versions
    create  Banana/backend/app/alembic/versions/91979b40eb38_create_users_table.py
    create  Banana/backend/app/alembic/__init__.py
    create  Banana/backend/app/alembic.ini
    create  Banana/backend/app/api
    create  Banana/backend/app/api/api_v1
    create  Banana/backend/app/api/api_v1/routers
    create  Banana/backend/app/api/api_v1/routers/auth.py
    create  Banana/backend/app/api/api_v1/routers/tests
    create  Banana/backend/app/api/api_v1/routers/tests/test_auth.py
    create  Banana/backend/app/api/api_v1/routers/tests/test_users.py
    create  Banana/backend/app/api/api_v1/routers/tests/__init__.py
    create  Banana/backend/app/api/api_v1/routers/users.py
    create  Banana/backend/app/api/api_v1/routers/__init__.py
    create  Banana/backend/app/api/api_v1/__init__.py
    create  Banana/backend/app/api/dependencies
    create  Banana/backend/app/api/dependencies/__init__.py
    create  Banana/backend/app/api/__init__.py
    create  Banana/backend/app/core
    create  Banana/backend/app/core/auth.py
    create  Banana/backend/app/core/celery_app.py
    create  Banana/backend/app/core/config.py
    create  Banana/backend/app/core/security.py
    create  Banana/backend/app/core/__init__.py
    create  Banana/backend/app/db
    create  Banana/backend/app/db/crud.py
    create  Banana/backend/app/db/models.py
    create  Banana/backend/app/db/schemas.py
    create  Banana/backend/app/db/session.py
    create  Banana/backend/app/db/__init__.py
    create  Banana/backend/app/initial_data.py
    create  Banana/backend/app/main.py
    create  Banana/backend/app/tasks.py
    create  Banana/backend/app/tests
    create  Banana/backend/app/tests/test_main.py
    create  Banana/backend/app/tests/test_tasks.py
    create  Banana/backend/app/tests/__init__.py
    create  Banana/backend/app/__init__.py
    create  Banana/backend/conftest.py
    create  Banana/backend/Dockerfile
    create  Banana/backend/pyproject.toml
    create  Banana/backend/requirements.txt
    create  Banana/docker-compose.yml
    create  Banana/frontend
    create  Banana/frontend/.dockerignore
    create  Banana/frontend/.eslintrc.js
    create  Banana/frontend/.prettierrc.js
    create  Banana/frontend/Dockerfile
    create  Banana/frontend/package.json
    create  Banana/frontend/public
Traceback (most recent call last):
  File "/home/orange/.local/bin/copier", line 8, in <module>
    sys.exit(CopierApp.run())
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/plumbum/cli/application.py", line 614, in run
    inst, retcode = subapp.run(argv, exit=False)
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/plumbum/cli/application.py", line 609, in run
    retcode = inst.main(*tailargs)
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/cli.py", line 70, in _wrapper
    return method(*args, **kwargs)
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/cli.py", line 293, in main
    self.parent._worker(
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/main.py", line 575, in run_copy
    self._render_folder(src_abspath)
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/main.py", line 467, in _render_folder
    self._render_folder(file)
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/main.py", line 467, in _render_folder
    self._render_folder(file)
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/main.py", line 467, in _render_folder
    self._render_folder(file)
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/main.py", line 469, in _render_folder
    self._render_file(file)
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/copier/main.py", line 429, in _render_file
    tpl = self.jinja_env.get_template(str(src_relpath))
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/jinja2/environment.py", line 883, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/jinja2/environment.py", line 857, in _load_template
    template = self.loader.load(self, name, globals)
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/jinja2/loaders.py", line 115, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/home/orange/.local/pipx/venvs/copier/lib/python3.8/site-packages/jinja2/loaders.py", line 184, in get_source
    contents = f.read().decode(self.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x93 in position 14: invalid start byte

@yajo
Copy link
Member Author

yajo commented Jul 22, 2021

Well, although that's true, it's not the most important aspect of this issue. That issue you say is #433 and the fix is... to fix it 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants