metanorma / metanorma-iso

Metanorma processor for ISO standards
BSD 2-Clause "Simplified" License
14 stars 5 forks source link

Error: Image not found: images/... #797

Closed Intelligent2013 closed 2 years ago

Intelligent2013 commented 2 years ago

Source ticket: https://github.com/metanorma/metanorma-iso/issues/796 I'm trying to generate presentation XML for the document https://github.com/metanorma/iso-19135 bundle exec metanorma -t iso -x presentation document.adoc ended with created document.xml.abort and error:

(XML Line 004956): Image not found: images/D:/Work/Metanorma/repositories/iso-19135/sources/iso-19135-2021/images/lutaml/lutaml20220913-7144-s5djb6.png
    <figure id="_210e4bd5-d2a0-1dd1-37f5-68af543522fc">
    <name>Elements of the Register model</name>
    <image src="images/D:/Work/Metanorma/repositories/iso-19135/sources/iso-19135-2021/images/lutaml/lutaml20220913-7144-s5djb6.png" id="_54ab6cec-6beb-a71b-7050-6567f8f26a9d" mimetype="image/png" height="auto" width="auto"/></figure>
(XML Line 005271): Image not found: images/D:/Work/Metanorma/repositories/iso-19135/sources/iso-19135-2021/images/lutaml/lutaml20220913-7144-9w030j.png
    <figure id="_6be57c4b-b507-3057-bbda-aca3955bc211">
    <name>Identifiers in the Register</name>
    <image src="images/D:/Work/Metanorma/repositories/iso-19135/sources/iso-19135-2021/images/lutaml/lutaml20220913-7144-9w030j.png" id="_99edfe0f-11da-d423-9c2c-50d01a8850e3" mimetype="image/png" height="auto" width="auto"/></figure>
(XML Line 005392): Image not found: images/D:/Work/Metanorma/repositories/iso-19135/sources/iso-19135-2021/images/lutaml/lutaml20220913-7144-48e0d4.png
    <figure id="_57dd9bdb-d761-9510-c24a-d8ecefec2f10">
    <name>Register item statuses and relationships</name>
    <image src="images/D:/Work/Metanorma/repositories/iso-19135/sources/iso-19135-2021/images/lutaml/lutaml20220913-7144-48e0d4.png" id="_6a528a0e-8487-7109-c1b7-cfe0074c8310" mimetype="image/png" height="auto" width="auto"/></figure>
(XML Line 005570): Image not found: images/D:/Work/Metanorma/repositories/iso-19135/sources/iso-19135-2021/images/lutaml/lutaml20220913-7144-cd4c0k.png
    <figure id="_25001995-6d02-043c-cfbc-819535f2b006">
    <name>Proposal and Appeal</name>
    <image src="images/D:/Work/Metanorma/repositories/iso-19135/sources/iso-19135-2021/images/lutaml/lutaml20220913-7144-cd4c0k.png" id="_19688494-dc26-50b0-4100-ff3e066c5143" mimetype="image/png" height="auto" width="auto"/></figure>

The file D:/Work/Metanorma/repositories/iso-19135/sources/iso-19135-2021/images/lutaml/lutaml20220913-7144-9w030j.png physically is present on the disk, but there is a strange prefix images/ before D:/Work.

It seems this issue occurs on Win platform only: https://github.com/metanorma/iso-19135/actions/runs/3040514350/jobs/4896647319

ronaldtse commented 2 years ago

I think this may be an image processing problem after the incorporation of pngcheck. Ping @opoudjis .

Intelligent2013 commented 2 years ago

Some investigation - see https://github.com/metanorma/metanorma-iso/issues/796#issuecomment-1245306704.

Intelligent2013 commented 2 years ago

The paths in the src should be relative, not absolute. (https://github.com/metanorma/metanorma-cli/issues/255)

For instance, in the presentation XML generated on Ubuntu (found in /home/testuser/iso-19135/sources/iso-19135-2021/), instead of

<image src="/home/testuser/iso-19135/sources/iso-19135-2021/images/lutaml/lutaml20220913-4327-zyjutc.png" 

expected:

<image src="./images/lutaml/lutaml20220913-4327-zyjutc.png" 
opoudjis commented 2 years ago

I think I know what happened with images prefix: D:/ not being recognised as an absolute path in metanorma-utils.

It used to, and I have no idea what changed.

opoudjis commented 2 years ago

What changed is @ronaldtse taking it upon himself to refactor metanorma-utils in https://github.com/metanorma/metanorma-utils/commit/aee97aca2b89e749d5dcc48c421fdb79be7b70ed , and introducing several bugs in the process, including this.

@ronaldtse I have enough to do already without you disrupting functioning code. You also committed that code without giving me the opportunity to review it. This is not acceptable, and I will revert any future commits you make to Metanorma code if you have not first discussed them with me. Only PRs are acceptable.

Intelligent2013 commented 2 years ago

@opoudjis with latest metanorma-utils commit '3803557a36d3...' I get the error:

Fatal Error: undefined local variable or method `uri' for Metanorma::Utils:Module

          warn "Image specified at `#{uri}` does not exist."
                                       ^^^                  

Did you mean?  URI
C:/tools/ruby31/lib/ruby/gems/3.1.0/bundler/gems/metanorma-utils-3803557a36d3/lib/utils/image.rb:140:in `datauri1': undefined local variable or method `uri' for Metanorma::Utils:Module (NameError)

          warn "Image specified at `#{uri}` does not exist."\r

Did you mean?  URI

        from C:/tools/ruby31/lib/ruby/gems/3.1.0/bundler/gems/metanorma-utils-3803557a36d3/lib/utils/image.rb:135:in `datauri'
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/bundler/gems/metanorma-standoc-35e26a016582/lib/metanorma/standoc/cleanup_image.rb:67:in `block in img_cleanup'
ronaldtse commented 2 years ago

The problem with the latest crash is @opoudjis artificially split a method that is not supposed to be split: https://github.com/metanorma/metanorma-utils/commit/7f20637a2be8853e449aa3703646285584f6b2a5#diff-365195b15b8cb4ad83fe5e25c64e72b0206de119661460ea4a5ad8752e345a5aR138-R142

That these "method splits" should not happen and is representative of poor practice.

opoudjis commented 2 years ago

That these "method splits" should not happen and is representative of poor practice.

I'm not the one who decided 10 lines per method is good practice.

opoudjis commented 2 years ago

Hotfix metanorma-utils released, @Intelligent2013

ronaldtse commented 2 years ago

@opoudjis the current behavior you committed does not generate datauri for an absolute file path. See the correct fix at https://github.com/metanorma/metanorma-utils/pull/24 with specs.