CadQuery / sphinxcadquery

An extension to visualize CadQuery 3D files in your Sphinx documentation
BSD 3-Clause "New" or "Revised" License
13 stars 4 forks source link

Using deprecated export method #30

Open shimwell opened 3 years ago

shimwell commented 3 years ago

The method currently used to export the TJS file is the toString method https://github.com/Peque/sphinxcadquery/blob/0b7050c0204b8b2c6f7e6912eaee97ca02b9e776/sphinxcadquery/sphinxcadquery.py#L111

toString appears to be deprecated https://github.com/CadQuery/cadquery/blob/05e42a75e157ed911aeef84cd7a4a864c59a5750/cadquery/occ_impl/exporters/__init__.py#L114-L118

However CadQuery offers a new method https://github.com/CadQuery/cadquery/blob/05e42a75e157ed911aeef84cd7a4a864c59a5750/cadquery/occ_impl/exporters/__init__.py#L34-L82

That works like this...

from cadquery import exporters
exporters.export(result, 'result.tjs', exportType='TJS')

This is not a problem quite yet but might become a problem if toString is removed in the future.

While I'm here I was wondering why the file is saved with a sha256 of the string as the file name, is this to make sure it has a unique filename?

Peque commented 3 years ago

@Shimwell Yeah, one of the reasons was to have unique filenames. That can be achieved with uuid too, but then it is not repeatable/stable.

In example, if you generate the docs locally, you would have a different file name for the same part than me, even if we were at the same commit. Also, if you wanted to share a link to the specific part that you found on a documentation online, you could do that, but the link would break the next time the documentation is generated, even if the part was not altered (imagine a pipeline trigger after a simple typo fix in some paragraph).

I think that was the reasoning behind that decision. But I did this some time ago, so I may have forgotten something... :joy:

Maybe stuff about Sphinx cache? :shrug:

Peque commented 3 years ago

PS: if you want to update the export procedure, you can still use the hashing on the generated file (instead of on the string on memory). :blush:

shimwell commented 3 years ago

Thanks for the info, I can put this on my todo list, perhaps not straight away as I have a few other things to thinker with first.

Good to know there is a solution that updates the export method and keeps the unique filenames. This will be handy when that deprecate happens