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

type error on macros #22

Closed
rachmadaniHaryono opened this issue Dec 13, 2021 · 1 comment · Fixed by #24
Closed

type error on macros #22

rachmadaniHaryono opened this issue Dec 13, 2021 · 1 comment · Fixed by #24

Comments

@rachmadaniHaryono
Copy link
Contributor

when i remove code of conduct i get error on macros.py

src/iqdb_tagger/main.pymkdocs build -sBuilding documentation (1)
  > mkdocs build -s
  INFO     -  [macros] - Macros arguments: {'module_name': 'docs/macros',
              'modules': [], 'include_dir': '', 'include_yaml': [],
              'j2_block_start_string': '', 'j2_block_end_string': '',
              'j2_variable_start_string': '', 'j2_variable_end_string': '',
              'verbose': False}
  INFO     -  [macros] - Found local Python module 'docs/macros' in:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
  INFO     -  [macros] - Found external Python module 'docs/macros' in:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
  INFO     -  [macros] - Extra filters (module): ['pretty']
  INFO     -  Cleaning site directory
  INFO     -  Building documentation to directory:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/site
  WARNING  -  A relative path to 'code_of_conduct.md' is included in the 'nav'
              configuration, which is not found in the documentation files
  Package(s) not found: astunparse, atomicwrites, cached-property, pywin32-ctypes
  INFO     -  [macros] - ERROR # _Macro Rendering Error_

              **TypeError**: tuple indices must be integers or slices, not str


              ```
              Traceback (most recent call last):
                File
              "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/mkdocs_macros/plugin.py",
              line 434, in render
                  return md_template.render(**page_variables)
                File
              "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/environment.py",
              line 1090, in render
                  self.environment.handle_exception()
                File
              "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/environment.py",
              line 832, in handle_exception
                  reraise(*rewrite_traceback_stack(source=source))
                File
              "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/_compat.py",
              line 28, in reraise
                  raise value.with_traceback(tb)
                File "<template>", line 1, in top-level template code
                File
              "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py",
              line 81, in credits
                  return get_credits()
                File
              "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py",
              line 63, in get_credits
                  template_data = get_credits_data()
                File
              "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py",
              line 35, in get_credits_data
                  pkg = {_: pkg[_] for _ in ("name", "home-page")}  # type: ignore
                File
              "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py",
              line 35, in <dictcomp>
                  pkg = {_: pkg[_] for _ in ("name", "home-page")}  # type: ignore
              TypeError: tuple indices must be integers or slices, not str

              ```

  Aborted with 1 warnings in strict mode!
WPS332 Found walrus operator> poetry run mkdocs build -s
INFO     -  [macros] - Macros arguments: {'module_name': 'docs/macros', 'modules': [], 'include_dir': '', 'include_yaml': [], 'j2_block_start_string': '', 'j2_block_end_string': '',
            'j2_variable_start_string': '', 'j2_variable_end_string': '', 'verbose': False}
INFO     -  [macros] - Found local Python module 'docs/macros' in: /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
INFO     -  [macros] - Found external Python module 'docs/macros' in: /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
INFO     -  [macros] - Extra filters (module): ['pretty']
INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/site
WARNING  -  A relative path to 'code_of_conduct.md' is included in the 'nav' configuration, which is not found in the documentation files
Package(s) not found: astunparse, atomicwrites, cached-property, pywin32-ctypes
WARNING:root:tuple indices must be integers or slices, not str
Traceback (most recent call last):
  File "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py", line 37, in get_credits_data
    pkg = {_: pkg[_] for _ in ("name", "home-page")}  # type: ignore
  File "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py", line 37, in <dictcomp>
    pkg = {_: pkg[_] for _ in ("name", "home-page")}  # type: ignore
TypeError: tuple indices must be integers or slices, not str
INFO     -  [macros] - ERROR # _Macro Rendering Error_

            **KeyError**: 'name'


            ```
            Traceback (most recent call last):
              File "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/mkdocs_macros/plugin.py", line 434, in render
                return md_template.render(**page_variables)
              File "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/environment.py", line 1090, in render
                self.environment.handle_exception()
              File "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/environment.py", line 832, in handle_exception
                reraise(*rewrite_traceback_stack(source=source))
              File "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/_compat.py", line 28, in reraise
                raise value.with_traceback(tb)
              File "<template>", line 1, in top-level template code
              File "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py", line 86, in credits
                return get_credits()
              File "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py", line 68, in get_credits
                template_data = get_credits_data()
              File "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py", line 41, in get_credits_data
                packages[pkg["name"].lower()] = pkg  # type: ignore
            KeyError: 'name'

            ```

Aborted with 1 warnings in strict mode!
  INFO     -  [macros] - Macros arguments: {'module_name': 'docs/macros',
              'modules': [], 'include_dir': '', 'include_yaml': [],
              'j2_block_start_string': '', 'j2_block_end_string': '',
              'j2_variable_start_string': '', 'j2_variable_end_string': '',
              'verbose': False}
  INFO     -  [macros] - Found local Python module 'docs/macros' in:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
  INFO     -  [macros] - Found external Python module 'docs/macros' in:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
  INFO     -  [macros] - Extra filters (module): ['pretty']
  INFO     -  Cleaning site directory
  INFO     -  Building documentation to directory:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/site
  WARNING  -  A relative path to 'code_of_conduct.md' is included in the 'nav'
              configuration, which is not found in the documentation files
  Package(s) not found: astunparse, atomicwrites, cached-property, pywin32-ctypes

  Aborted with 1 warnings in strict mode!

make: *** [Makefile:45: check] Error 1

i tried to by pass that but got another error

src/iqdb_tagger/main.pymkdocs build -sBuilding documentation (1)
  > mkdocs build -s
  INFO     -  [macros] - Macros arguments: {'module_name': 'docs/macros',
              'modules': [], 'include_dir': '', 'include_yaml': [],
              'j2_block_start_string': '', 'j2_block_end_string': '',
              'j2_variable_start_string': '', 'j2_variable_end_string': '',
              'verbose': False}
  INFO     -  [macros] - Found local Python module 'docs/macros' in:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
  INFO     -  [macros] - Found external Python module 'docs/macros' in:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
  INFO     -  [macros] - Extra filters (module): ['pretty']
  INFO     -  Cleaning site directory
  INFO     -  Building documentation to directory:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/site
  WARNING  -  A relative path to 'code_of_conduct.md' is included in the 'nav'
              configuration, which is not found in the documentation files
  Package(s) not found: astunparse, atomicwrites, cached-property, pywin32-ctypes
  INFO     -  [macros] - ERROR # _Macro Rendering Error_

              **TypeError**: tuple indices must be integers or slices, not str


              ```
              Traceback (most recent call last):
                File
              "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/mkdocs_macros/plugin.py",
              line 434, in render
                  return md_template.render(**page_variables)
                File
              "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/environment.py",
              line 1090, in render
                  self.environment.handle_exception()
                File
              "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/environment.py",
              line 832, in handle_exception
                  reraise(*rewrite_traceback_stack(source=source))
                File
              "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/_compat.py",
              line 28, in reraise
                  raise value.with_traceback(tb)
                File "<template>", line 1, in top-level template code
                File
              "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py",
              line 81, in credits
                  return get_credits()
                File
              "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py",
              line 63, in get_credits
                  template_data = get_credits_data()
                File
              "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py",
              line 35, in get_credits_data
                  pkg = {_: pkg[_] for _ in ("name", "home-page")}  # type: ignore
                File
              "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py",
              line 35, in <dictcomp>
                  pkg = {_: pkg[_] for _ in ("name", "home-page")}  # type: ignore
              TypeError: tuple indices must be integers or slices, not str

              ```

  Aborted with 1 warnings in strict mode!
WPS332 Found walrus operator> poetry run mkdocs build -s
INFO     -  [macros] - Macros arguments: {'module_name': 'docs/macros', 'modules': [], 'include_dir': '', 'include_yaml': [], 'j2_block_start_string': '', 'j2_block_end_string': '',
            'j2_variable_start_string': '', 'j2_variable_end_string': '', 'verbose': False}
INFO     -  [macros] - Found local Python module 'docs/macros' in: /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
INFO     -  [macros] - Found external Python module 'docs/macros' in: /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
INFO     -  [macros] - Extra filters (module): ['pretty']
INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/site
WARNING  -  A relative path to 'code_of_conduct.md' is included in the 'nav' configuration, which is not found in the documentation files
Package(s) not found: astunparse, atomicwrites, cached-property, pywin32-ctypes
WARNING:root:tuple indices must be integers or slices, not str
Traceback (most recent call last):
  File "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py", line 37, in get_credits_data
    pkg = {_: pkg[_] for _ in ("name", "home-page")}  # type: ignore
  File "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py", line 37, in <dictcomp>
    pkg = {_: pkg[_] for _ in ("name", "home-page")}  # type: ignore
TypeError: tuple indices must be integers or slices, not str
INFO     -  [macros] - ERROR # _Macro Rendering Error_

            **KeyError**: 'name'


            ```
            Traceback (most recent call last):
              File "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/mkdocs_macros/plugin.py", line 434, in render
                return md_template.render(**page_variables)
              File "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/environment.py", line 1090, in render
                self.environment.handle_exception()
              File "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/environment.py", line 832, in handle_exception
                reraise(*rewrite_traceback_stack(source=source))
              File "/home/r3r/.cache/pypoetry/virtualenvs/iqdb-tagger-C28AsU-2-py3.9/lib/python3.9/site-packages/jinja2/_compat.py", line 28, in reraise
                raise value.with_traceback(tb)
              File "<template>", line 1, in top-level template code
              File "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py", line 86, in credits
                return get_credits()
              File "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py", line 68, in get_credits
                template_data = get_credits_data()
              File "/mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/docs/macros.py", line 41, in get_credits_data
                packages[pkg["name"].lower()] = pkg  # type: ignore
            KeyError: 'name'

            ```

Aborted with 1 warnings in strict mode!
  INFO     -  [macros] - Macros arguments: {'module_name': 'docs/macros',
              'modules': [], 'include_dir': '', 'include_yaml': [],
              'j2_block_start_string': '', 'j2_block_end_string': '',
              'j2_variable_start_string': '', 'j2_variable_end_string': '',
              'verbose': False}
  INFO     -  [macros] - Found local Python module 'docs/macros' in:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
  INFO     -  [macros] - Found external Python module 'docs/macros' in:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger
  INFO     -  [macros] - Extra filters (module): ['pretty']
  INFO     -  Cleaning site directory
  INFO     -  Building documentation to directory:
              /mnt/ac54dceb-73a5-4f94-b52c-cb7a426c0f29/Documents/iqdb_tagger/site
  WARNING  -  A relative path to 'code_of_conduct.md' is included in the 'nav'
              configuration, which is not found in the documentation files
  Package(s) not found: astunparse, atomicwrites, cached-property, pywin32-ctypes

  Aborted with 1 warnings in strict mode!

make: *** [Makefile:45: check] Error 1

this is fix for python3.8

Author: Rachmadani Haryono <foreturiga@gmail.com>
Date:   Tue Dec 14 07:45:16 2021 +0800

    fix(macros): type error

diff --git a/project/docs/macros.py b/project/docs/macros.py
index 72262ad..2ccf826 100644
--- a/project/docs/macros.py
+++ b/project/docs/macros.py
@@ -4,6 +4,7 @@ import functools
 from itertools import chain
 from pathlib import Path

+import logging
 import httpx
 import toml
 from jinja2 import StrictUndefined
@@ -32,8 +33,13 @@ def get_credits_data() -> dict:

     packages = {}
     for pkg in search_packages_info(list(dependencies)):
-        pkg = {_: pkg[_] for _ in ("name", "home-page")}  # type: ignore
-        packages[pkg["name"].lower()] = pkg  # type: ignore
+        try:
+            pkg_data = {_: pkg[_] for _ in ("name", "home-page")}  # type: ignore
+        except TypeError as err:
+            logging.debug(err, exc_info=True)
+            pkg_data = {}
+        if pkg_name := pkg_data.get("name"):
+            packages[pkg_name.lower()] = pkg_data  # type: ignore

     # all packages might not be credited,
     # like the ones that are now part of the standard library
@pawamoy
Copy link
Owner

pawamoy commented Dec 14, 2021

Take a look at a more recent version in the PDM version of the template: https://github.com/pawamoy/copier-pdm/blob/master/project/docs/gen_credits.py.jinja

Feel free to send a PR 🙂

pawamoy pushed a commit that referenced this issue Dec 27, 2021
Co-authored-by: Timothée Mazzucotelli <pawamoy@pm.me>
Issue #22: #22
PR #24: #24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants