implementing --version with importlib.metadata (intermediate) anthony explains

Поделиться
HTML-код
  • Опубликовано: 8 фев 2025

Комментарии • 7

  • @ali.hamdan
    @ali.hamdan 3 года назад +2

    Great videos, thank you. One question though, is there a reason why you don't store the version in the source file and use the attr directive of setuptools? This way you avoid adding a runtime dependency on importlib-metadata in py37 and below.
    I usually define a `__version__` variable in `mymodule.py` (or `mypackage/__init__.py`) and have `version = attr: mymodule.__version__` (or `mypackage.__version__`) in setup.cfg metadata.

    • @anthonywritescode
      @anthonywritescode  3 года назад +3

      attr requires your module to be importable at *setup* time. it's all-too-easy to write a completely broken package because of this (requiring your *runtime* dependencies at *setup* time)

    • @ali.hamdan
      @ali.hamdan 3 года назад

      @@anthonywritescode Good point.
      The documentation of setuptools however says: "attr: first tries to read the value from the module by examining the module’s AST. If that fails, attr: falls back to importing the module."
      I didn't have a case where it actually imported the module yet.

    • @anthonywritescode
      @anthonywritescode  3 года назад +1

      guess you're getting lucky then!

  • @avallbona
    @avallbona 4 года назад

    this is dope!!! Kudos

  • @patskanteam
    @patskanteam 4 года назад +2

    Explain tox please

    • @anthonywritescode
      @anthonywritescode  4 года назад

      already on my list -- I'll be recording a quick intro to tox in a few days!