Skip to content

Make dev_tools/nbfmt more careful about tensorflow-docs#219

Merged
mhucka merged 10 commits intoquantumlib:mainfrom
mhucka:mh-fix-nbfmt
Mar 10, 2025
Merged

Make dev_tools/nbfmt more careful about tensorflow-docs#219
mhucka merged 10 commits intoquantumlib:mainfrom
mhucka:mh-fix-nbfmt

Conversation

@mhucka
Copy link
Copy Markdown
Contributor

@mhucka mhucka commented Feb 28, 2025

If the user previously installed unitary in one virtual environment, did the pip install -r requirements.txt, ran check/nbfmt (which in turn installs dev_tools/nbformat and tensorflow-docs), then at a later time created a different virtual environment, did the same installation steps, and ran check/nbfmt, it would fail because the presence of dev_tools/nbformat fooled nbfmt into thinking tensorflow-docs was already installed. A solution is to decouple of check for the nbformat script and the tensorflow-docs package.

I also tweaked the error-message rewriting code at the very end, because it wasn't doing the substitution in my environment. (That might be because the stock version of Bash on MacOS is an old 3.2.)

If the user previously installed unitary in one virtual environment,
did the `pip install -r requirements.txt`, ran `check/nbfmt` (which in
turn installs `dev_tools/nbformat` and tensorflow-docs), then at a
later time created a different virtual environment, did the same
installation steps, and ran `check/nbfmt`, it would fail because the
presence of `dev_tools/nbformat` fooled `nbfmt` into thinking
tensorflow-docs was already installed. A solution is to decouple of
check for the nbformat script and the tensorflow-docs package.

I also tweaked the error-message rewriting code at the very end,
because it wasn't doing the substitution in my environment. (That
might be because the stock version of Bash on MacOS is an old 3.2.)
@mhucka
Copy link
Copy Markdown
Contributor Author

mhucka commented Feb 28, 2025

Note: the current CI check failures should disappear after PR #220 is applied.

@mhucka mhucka marked this pull request as ready for review February 28, 2025 18:31
@mhucka mhucka requested a review from dstrain115 February 28, 2025 18:31

# Check if cirq/check/nbformat exists, if not grab it.
# Base URL for downloading tools from Cirq.
declare -r cirq=https://raw.githubusercontent.com/quantumlib/Cirq/main
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we planning to download from cirq from other repos too?

Copy link
Copy Markdown
Contributor Author

@mhucka mhucka Mar 7, 2025

Choose a reason for hiding this comment

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

Are we planning to download from cirq from other repos too?

Ah, no; the reason I assigned a variable is that the same URL is used in two places (as it was in the previous version of this script too). It seems better to keep things DRY and write it once.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is still downloading from https://raw.githubusercontent.com/quantumlib/Cirq/main I am not sure I understand your comment.

Copy link
Copy Markdown
Contributor Author

@mhucka mhucka Mar 9, 2025

Choose a reason for hiding this comment

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

Ok, maybe I don't understand your question :-).

You had asked "Are we planning to download from cirq from other repos too?", which I interpreted as asking whether we'd download cirq from repos other than the cirq repo. The answer to that is no – I can't think of a reason to download it from a repo other than cirq's repo. I was puzzled by why you were asking, so I thought maybe the reason you were asking is that it's unclear why the download location is being assigned to a variable when that value will never change. The reason for that is that the location is used in more than one place in the script.

Could you clarify what "download from cirq from other repos" means?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This PR is for the unitary repo but the url is downloading tools from the cirq repo:

declare -r cirq=https://raw.githubusercontent.com/quantumlib/Cirq/main```

I think we should keep the repos self-contained and not download tools from the cirq repo unless there is a good reason.

Copy link
Copy Markdown
Contributor Author

@mhucka mhucka Mar 10, 2025

Choose a reason for hiding this comment

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

Oh, I understand now.

The reason for this is simply that the original nbfmt in unitary does this. (This can be seen in the version in main currently.) I didn't want to question the original choice so left that part the same, and only cleaned up the code in other ways.

I could rewrite that, if that would be preferable?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh, I see. I didn't realize that this was preexisting. Yeah, maybe we could make this more independent, but it's lower priority and can be done in a later PR.

@mhucka mhucka changed the title Make check/nbfmt more careful about tensorflow-docs Make dev_tools/nbfmt more careful about tensorflow-docs Mar 7, 2025
@mhucka mhucka merged commit 417975a into quantumlib:main Mar 10, 2025
6 checks passed
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.

2 participants