Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regex escaping #88

Merged
merged 5 commits into from
Jul 24, 2020
Merged

Conversation

s-weigand
Copy link
Contributor

As concluded in #86, this fixes the way that copybutton_prompt_text is injected into copybutton.js_t.
And updates the docs on how to use the regex feature.
I left the old tests in there, since I kind like those oddities if you know them. But if that is too much clutter for you I can remove them.

Not sure how much you value SemVer but this is a breaking change, since it will break functionality for people that already use the regex feature.

fixes #86

Note: I left #84 (besides) untouched, since IMHO this should configurable i.e. by a variable copy_blank_lines. I just can see someone complaining around the corner, even so 'copy as is' is the most natural thing and should be default 😒

@s-weigand s-weigand changed the title Regex escaping Fix regex escaping Jul 21, 2020
@choldgraf
Copy link
Member

Thanks for this patch! @chrisjsewell do you think you could double-check that this looks correct? My regex skills are very poor 😬

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

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

Yep mainly good thanks, I just think we can probably remove the "old style"

doc/index.rst Outdated

.. code-block:: restructuredtext

Old style:
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need this old and new style? Was old style actually ever a thing (i.e. was it used in old versions of ipython) or can we just remove it (the examples and in the regex) and keep only the "new" style

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also wasn't sure if the "old style" was ever like this, ipython console, jupyter console and qt-console use the "new style".
But I thought "there had to be a reason why [1] was used" (that's why I came up with the "old" and "new"). So If you can't think of an "old" use case, I will remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, whlie derping around with ipython, jupyter console and jupyter qtconsole I found differences with line continuation:

ipython and jupyter qtconsole:

In [1]: def test():
   ...:     return 1

jupyter console:

In [1]: def test():
       :     return 1

So the regexes should be r"\s \.\.\.: " and r"\s : "

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about replacing:

  • "Old style" with "ipython and qtconsole style"
  • "New style" with "jupyter console style"

Also using the regexes r" {2,5}\.\.\.: " and r" {5,8}: " would support continuations for In []: up to In [999], an be more robust against false positive matches than my proposed version with \s .

Copy link
Member

Choose a reason for hiding this comment

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

didn't even know there was a jupyter console lol, but yeh sounds good to me if you want to have the two examples, or just use ipython

sphinx_copybutton/_static/test.js Show resolved Hide resolved
@chrisjsewell
Copy link
Member

Not sure how much you value SemVer but this is a breaking change, since it will break functionality for people that already use the regex feature.

Yep we should release this as 0.3.0

@s-weigand
Copy link
Contributor Author

Not sure how much you value SemVer but this is a breaking change, since it will break functionality for people that already use the regex feature.

Yep we should release this as 0.3.0

Well, as for SemVer that would be a 1. 0. 0 as it might break things.IMHO SemVer only makes sense if it is consistent, which manually is hard to do and I didn't find the proper tool for it in the python universe / GH actions to automate it for me (maybe you can give me a pointer 😉).
I.e. in a project we had a dependency which changed from 0.9.9 to 1.0.0 and all was fine.
But when they went to 1.0.1 many tests went down, so IMHO inconsistent versioning is more harmfull.
I think the easiest versioning scheme to maintain, is the date one as pip uses if for about 1.5y.

@chrisjsewell
Copy link
Member

chrisjsewell commented Jul 23, 2020

Well, as for SemVer that would be a 1. 0. 0

Yeh it's a bit of a cheat, but for versioning < 1.0.0, I generally treat MINOR version changes as also being backwards-incompatible, and PATCH for anything else. I think that's reasonable, since below 1.0 you're generally in "beta" mode where users should not yet expect the code to be completely "stable" anyway

@choldgraf
Copy link
Member

Yep I'm in the same boat - IMO pre 1.0 you treat "minor" versions as "major" versions, and pre 0.1 you treat "patch" versions as "major" versions

@s-weigand
Copy link
Contributor Author

Well, as for SemVer that would be a 1. 0. 0

Yeh it's a bit of a cheat, but for versioning < 1.0.0, I generally treat MINOR version changes as also being backwards-incompatible, and PATCH for anything else. I think that's reasonable, since below 1.0 you're generally in "beta" mode where users should not yet expect the code to be completely "stable" anyway

Yeah, fair enough, versions below 1.0 are a gray area ^^

@chrisjsewell
Copy link
Member

maybe you can give me a pointer

Well I don't know it there can be a completely programmatic identifier of back-compatability breaking.
But I'm trying to push this commit convention now https://executablebooks.org/en/latest/dev-conventions.html#commit-messages, which hopefully will help to make it clearer where breaking changes occur,
i.e. the commit from this PR will start: ‼️ BREAKING:

@s-weigand
Copy link
Contributor Author

maybe you can give me a pointer

Well I don't know it there can be a completely programmatic identifier of back-compatability breaking.
But I'm trying to push this commit convention now https://executablebooks.org/en/latest/dev-conventions.html#commit-messages, which hopefully will help to make it clearer where breaking changes occur,
i.e. the commit from this PR will start: ‼️ BREAKING:

In my TypeScript projects with template typescript-library-starter I use git-cz, which basically wrappes git commits in a CLI dialog and adds keywords which get picked up further down the line. But 'completely programmatic identifier of back-compatability breaking' might be a dream.. enough off topic xD

@chrisjsewell
Copy link
Member

In my TypeScript projects with template typescript-library-starter I use git-cz

Yeh interesting cheers, there's a few different categories, but quite similar. I guess there's no convention that can cover all eventualities, but its better to have a convention than none at all.

which basically wrappes git commits in a CLI dialog

The only problem with any locally installed "commit tool" is that actually you're mainly writing the commit message directly here in the GitHub PR interface

@s-weigand s-weigand requested a review from chrisjsewell July 24, 2020 19:19
@chrisjsewell chrisjsewell merged commit 1cd8420 into executablebooks:master Jul 24, 2020
@chrisjsewell
Copy link
Member

thanks @s-weigand!

@choldgraf
Copy link
Member

thanks for the patch @s-weigand !!

@s-weigand s-weigand deleted the regex_escaping branch July 25, 2020 12:05
s-weigand added a commit to s-weigand/sphinx-copybutton that referenced this pull request Jul 25, 2020
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.

Prompt Regex Escaping Confusion
3 participants