ultrabug / mkdocs-static-i18n

MkDocs i18n plugin using static translation markdown files
https://ultrabug.github.io/mkdocs-static-i18n/
MIT License
237 stars 38 forks source link

TypeError bug after upgrading plugin > 0.53 #210

Closed dmitry-tiger closed 1 year ago

dmitry-tiger commented 1 year ago

Hello, I'm using mkdocs-material:8.4.0 image as base and when mkdocs-static-i18n module upgraded to 0.54 (tried last version and got same error) I started getting error during mkdocs buid

Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py", line 247, in build_command
    cfg = config.load_config(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/config/base.py", line 358, in load_config
    cfg.load_file(fd)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/config/base.py", line 258, in load_file
    return self.load_dict(utils.yaml_load(config_file))
  File "/usr/local/lib/python3.9/site-packages/mkdocs/utils/__init__.py", line 82, in yaml_load
    result = yaml.load(source, Loader=Loader)
  File "/usr/local/lib/python3.9/site-packages/yaml/__init__.py", line 81, in load
    return loader.get_single_data()
  File "/usr/local/lib/python3.9/site-packages/yaml/constructor.py", line 51, in get_single_data
    return self.construct_document(node)
  File "/usr/local/lib/python3.9/site-packages/yaml/constructor.py", line 60, in construct_document
    for dummy in generator:
  File "/usr/local/lib/python3.9/site-packages/yaml/constructor.py", line 413, in construct_yaml_map
    value = self.construct_mapping(node)
  File "/usr/local/lib/python3.9/site-packages/yaml/constructor.py", line 218, in construct_mapping
    return super().construct_mapping(node, deep=deep)
  File "/usr/local/lib/python3.9/site-packages/yaml/constructor.py", line 143, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "/usr/local/lib/python3.9/site-packages/yaml/constructor.py", line 102, in construct_object
    data = constructor(self, tag_suffix, node)
  File "/usr/local/lib/python3.9/site-packages/yaml/constructor.py", line 570, in construct_python_name
    return self.find_python_name(suffix, node.start_mark)
  File "/usr/local/lib/python3.9/site-packages/yaml/constructor.py", line 719, in find_python_name
    return super(UnsafeConstructor, self).find_python_name(name, mark, unsafe=True)
  File "/usr/local/lib/python3.9/site-packages/yaml/constructor.py", line 551, in find_python_name
    __import__(module_name)
  File "/usr/local/lib/python3.9/site-packages/materialx/emoji.py", line 17, in <module>
    RESOURCES = os.path.dirname(inspect.getfile(material))
  File "/usr/local/lib/python3.9/inspect.py", line 660, in getfile
    raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module 'material' (namespace)> is a built-in module

with version 0.53 it works well could it be related to old mkdocs-material release which we use?

ultrabug commented 1 year ago

ping @kamilkrzyskow

ultrabug commented 1 year ago

I'll look at it ASAP unless Kamin beats me to it, thanks for reporting this and sorry for the issue @dmitry-tiger

kamilkrzyskow commented 1 year ago

The error originates in /usr/local/lib/python3.9/site-packages/materialx/emoji.py 🤔. I don't think I made any changes related to it...

kamilkrzyskow commented 1 year ago

@dmitry-tiger could you provide the result of pip freeze here ✌️ I tried to run it locally and everything sadly works:

$ python --version
Python 3.9.13

$ pip freeze
click==8.1.3
colorama==0.4.6          
ghp-import==2.1.0        
importlib-metadata==6.1.0
Jinja2==3.1.2            
Markdown==3.3.7          
MarkupSafe==2.1.2        
mergedeep==1.3.4         
mkdocs==1.4.2            
mkdocs-material==8.4.0   
mkdocs-material-extensions==1.1.1
-e git+https://github.com/kamilkrzyskow/i18n.git@67a324bd019d9a0f3b31afb652e06b8e0af64095#egg=mkdocs_static_i18n
packaging==23.0
Pygments==2.14.0
pymdown-extensions==9.10
python-dateutil==2.8.2
PyYAML==6.0
pyyaml_env_tag==0.1
six==1.16.0
watchdog==3.0.0
zipp==3.15.0

Also you said something about "mkdocs-material:8.4.0 image". You mean a docker image? Default one or modified?

kamilkrzyskow commented 1 year ago

Based on this https://stackoverflow.com/questions/65523340/why-does-inspect-say-that-my-module-is-built-in I would assume there is some kind of material directory somewhere that is imported instead of the actual material theme 🤔 That "somewhere" is inside one of the loaded site-packages paths, but I'm not sure how to guide you to finding them 🤔

dmitry-tiger commented 1 year ago

I'm using image https://hub.docker.com/layers/squidfunk/mkdocs-material/8.4.0/ for base in my docker container only one thing i'm doing on top of base image is only RUN pip install --no-cache-dir mkdocs-static-i18n i made basic setup to reproduce errror just run build -t test1 . inside directory 231312.tar.gz I'm not sure that it is issue inside this plugin but setting version to 0.53 doesn't produce that error

kamilkrzyskow commented 1 year ago

In 0.5.4 the version for MkDocs increased to 1.4.2, it was a jump from version 1.2. The scripts also introduced the event priorities, but we lack a fallback function in case the plugins decorator isn't available on older versions, but the error doesn't display this...

ultrabug commented 1 year ago

I did not check this issue yet but do you mean that pip does not do its job to honor the mkdocs >= 1.4.2 dependency? I'm confused.

kamilkrzyskow commented 1 year ago

I got lucky that I still didn't bother to uninstall docker, after it broke my other VMs (good that I don't use them...) I was able to reproduce it. I modified the test file and added a script to see what is going on. It seems that somehow some parts of the mkdocs-material get deleted when mkdocs 1.3.1 is deleted and 1.4.2 is installed. I don't see the removal in the pip log, but I see the removed __init__.py file.

@ultrabug maybe you'll get something out of the log, for now I'm not sure how to fix it, other than to keep the version like it was before in the setup.py. But if we'll support MkDocs<1.4 then it's required to add a fallback to the event priorities. There is an example in the documentation.

docker.zip log.txt

kamilkrzyskow commented 1 year ago

@dmitry-tiger A quick fix for you until we figure it out:

RUN pip install --no-cache-dir mkdocs-static-i18n==0.54
RUN pip uninstall mkdocs-material -y
RUN pip install --no-cache-dir mkdocs-material==8.4.0
kamilkrzyskow commented 1 year ago

I run pip with -v and confirmed that the uninstall of MkDocs 1.3.1 is the cause of the issue.

#9 5.955   Attempting uninstall: mkdocs
#9 5.955     Found existing installation: mkdocs 1.3.1
#9 5.978     Uninstalling mkdocs-1.3.1:
#9 6.004       Created temporary directory: /tmp/pip-uninstall-cwu6mik2
#9 6.007       Removing file or directory /usr/local/bin/mkdocs
#9 6.008       Created temporary directory: /tmp/pip-uninstall-y47i4m2q
#9 6.010       Removing file or directory /usr/local/lib/python3.9/site-packages/material/404.html
#9 6.011       Removing file or directory /usr/local/lib/python3.9/site-packages/material/__init__.py
#9 6.013       Removing file or directory /usr/local/lib/python3.9/site-packages/material/base.html
#9 6.015       Removing file or directory /usr/local/lib/python3.9/site-packages/material/main.html
#9 6.018       Removing file or directory /usr/local/lib/python3.9/site-packages/material/mkdocs_theme.yml
#9 6.018       Created temporary directory: /usr/local/lib/python3.9/site-packages/~kdocs-1.3.1.dist-info
#9 6.019       Removing file or directory /usr/local/lib/python3.9/site-packages/mkdocs-1.3.1.dist-info/
#9 6.019       Created temporary directory: /usr/local/lib/python3.9/site-packages/~kdocs
#9 6.037       Removing file or directory /usr/local/lib/python3.9/site-packages/mkdocs/
#9 6.037       Successfully uninstalled mkdocs-1.3.1

I guess that the material theme plugin somehow is linked with the mkdocs dependency and is removed together with it.

ultrabug commented 1 year ago

It seems to me that's it's a problem specific to the docker images of material.

One could use mkdocs-material 8.x with newer plugin since mkdocs-material 8.4.0 has mkdocs>=1.3.0 dependency so I believe that the problem can't affect regular virtualenv users.

I'm thus not sure I'd call this a "regression" from this plugin's perspective I'm afraid.

ultrabug commented 1 year ago

I'm happy to announce release v1.0.0 of the mkdocs-static-i18n plugin!

Please check it out and reopen if needed.