Skip to content

Implement preview command#139

Merged
mishig25 merged 35 commits into
mainfrom
dev_mode
Mar 23, 2022
Merged

Implement preview command#139
mishig25 merged 35 commits into
mainfrom
dev_mode

Conversation

@mishig25

@mishig25 mishig25 commented Mar 14, 2022

Copy link
Copy Markdown
Contributor

Dev command with hot reloading

doc-builder preview datasets ~/Desktop/datasets/docs/source

I think this will make the experience writing docs better 🙂

letsgo_U79b9L1x.mov

@mishig25 mishig25 requested review from LysandreJik, coyotte508 and sgugger and removed request for sgugger March 14, 2022 17:28
Comment thread src/doc_builder/build_doc.py Outdated
)

return anchor_mapping
return anchor_mapping, src_py_path_mapping

@mishig25 mishig25 Mar 14, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src_py_path_mapping is used to know wich mdx file to update/build when a docstring is updated inside python file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want a different name for it, but completely okay with this addition :-)

@sgugger sgugger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a great addition, thanks for working on this! I have a few comments on the variable names and we need to handle watchdog as a soft dependency (that the user should install only if they want to use doc-builder dev).

The name dev is not super intuitive to me, is it something that comes from node? I'd prefer something like doc-builder preview (or if you have another idea I'm all ears!).

Comment thread src/doc_builder/commands/dev.py Outdated
Comment thread src/doc_builder/autodoc.py
Comment thread src/doc_builder/build_doc.py Outdated
Comment thread src/doc_builder/build_doc.py Outdated
Comment thread src/doc_builder/build_doc.py Outdated
Comment thread src/doc_builder/build_doc.py Outdated
)

return anchor_mapping
return anchor_mapping, src_py_path_mapping

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want a different name for it, but completely okay with this addition :-)

Comment thread src/doc_builder/build_doc.py Outdated
Comment thread src/doc_builder/build_doc.py Outdated
Comment thread src/doc_builder/commands/dev.py Outdated
env["DOCS_LIBRARY"] = args.library_name
env["DOCS_VERSION"] = args.version
env["DOCS_LANGUAGE"] = args.language
Thread(target=start_sveltekit_dev, args=(tmp_dir, env, args)).start()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never be closed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this thread should be running as long as the program is running

@coyotte508 coyotte508 removed their request for review March 14, 2022 19:28
mishig25 and others added 8 commits March 14, 2022 21:53
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
@mishig25

Copy link
Copy Markdown
Contributor Author

@sgugger thanks a lot for the suggestions!

  1. Renamed command dev -> preview
  2. Added soft dependency watchdog
  3. Renamed variables as suggested

@mishig25 mishig25 requested a review from sgugger March 14, 2022 22:12
@mishig25 mishig25 changed the title Implement dev command Implement preview command Mar 14, 2022

@sgugger sgugger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding all of that! I just left one last styling suggestion.

For the Thread, are we sure that exiting will close it (it's not the case with Process if I remember correctly, so just want to be 100% sure)

Comment thread src/doc_builder/commands/preview.py Outdated


def preview_command(args):
if is_watchdog_available():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid everything being indented here, I'd test the negation and raise the ImportError, then just unindent the whole function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/doc_builder/commands/preview.py Outdated
# files/folders cannot have a name that starts with `__` since it is a reserved Sveltekit keyword
for dir in output_path.glob("**/__*/*"):
dir.rmdir()
subprocess.run(["rm", "-rf", str(dir)])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
subprocess.run(["rm", "-rf", str(dir)])
shutil.rmtree(dir)

This is cleaner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this glob can catch a file "**/__*/*"
in that case, would shutil.rmtree(dir) work?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only works for dir, so you should make a test. It's still better than using subprocess for this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handled in 635938b

Comment thread src/doc_builder/commands/preview.py Outdated
@mishig25

Copy link
Copy Markdown
Contributor Author

@LysandreJik please feel free to retry the preview command.
You may need to reinstall the CLI if you face some error starting it up.

doc-builder preview datasets ~/Desktop/datasets/docs/source/

Fixed the relative path issue (should be working whether you provide absolute or relative path to docs folder)

@LysandreJik

Copy link
Copy Markdown
Member

Thanks for the ping, will try it again.

@mishig25 mishig25 merged commit fff9359 into main Mar 23, 2022
@mishig25 mishig25 deleted the dev_mode branch March 23, 2022 15:41
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 this pull request may close these issues.

3 participants