GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Drop deprecated sre_compile usage by jspricke · Pull Request #214 · cpplint/cpplint

Conversation

@jspricke

@jspricke jspricke commented Dec 24, 2022

Copy link
Copy Markdown
Contributor

No description provided.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ptrcnull reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Jochen Sprickerhof @jspricke
Drop deprecated sre_compile usage
e84e84f
@tkruse
tkruse force-pushed the develop branch 5 times, most recently from b683f2b to 2cb090b Compare January 29, 2023 12:33
tkruse
tkruse reviewed Feb 13, 2023
View reviewed changes
Comment thread cpplint.py Outdated
# to be noticeably expensive.
if pattern not in _regexp_compile_cache:
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
_regexp_compile_cache[pattern] = re.compile(pattern)

@tkruse tkruse Feb 13, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Is there any meaningful difference between re.compile and re._compiler.compile? I must admit I don't know, and I don't know why the original developers chose sre_compile.

On python 3.11

import re
import sre_compile

sre_compile.compile == re._compiler.compile
Out[11]: True
sre_compile.compile == re.compile
Out[12]: False

The deprecation thread does not help me either https://bugs.python.org/issue47152

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jspricke jspricke Feb 13, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I don't think so, see https://stackoverflow.com/questions/32576273/why-do-both-the-sre-and-re-modules-exist-in-python

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tkruse tkruse Feb 13, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

So re.compile() is here: https://github.com/python/cpython/blob/main/Lib/re/__init__.py#L280
It wraps re._compiler.compile() here: https://github.com/python/cpython/blob/main/Lib/re/__init__.py#L307
It uses caching for compiled expressions.

So... they are basically the same, except re.compile() has caching and is the official (future-safe) api.
But cpplint has it's own implementation of caching already (without eviction), so it's a little silly to use re.compile which has caching and then also do caching in cpplint.

I believe re caches 256 compiled expressions, and cpplint has < 100 so far, with little reason to believe it will be more.

So if we do the migration in this PR, we can also remove the caching from cpplint (maybe check caching in python3.7 re)

@jspricke : Is that also your understanding, do you have a strong preference?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jspricke jspricke Feb 14, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That makes a lot of sense to me, I've added a commit to do that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tkruse tkruse Feb 14, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

ahhh, sorry. Actually I worry a lot about this change. The number of used patterns is larger than the number of occurrences of Search that I counted yesterday. Some of those occurrences use variables when building the pattern, like Search(r'new\(\S+\)\s*' + matched_type, line, but then there is also Match(). Now even if we did exceed the re.compile cache sizes, it might not cause significant additional slowdown if the LRU cache hit rate is high. Bug I don't know if I want to risk this. My concern is that for very large codebases, running cpplint could become much slower with this change.

So either we find some loadtest with a representative very large codebase and check there is no slowdown, or we keep the duplicate caching logic as documented technical debt (by adding a small comment where cpplint does caching). Or we make very damn certain that we stay below a certain number of patterns.

Thoughts?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jspricke jspricke Feb 15, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I don't really mind, could you simply cherry-pick from this what you see fit or do you prefer if I rework this again?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tkruse tkruse Feb 21, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

ok, don't worry I'll cherry-pick Sorry for being indecisive about this, only have limited time for cpplint.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jspricke
Drop extra regex cache in favour of the one in re
58e6090
@richardlau richardlau mentioned this pull request Mar 8, 2023
tools: replace sre_compile with re.compile nodejs/node#47005
Closed
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Apr 10, 2023
dgarcia @bmwiedemann
Update python-cpplint to version 1.6.1 / rev 6 via SR 1078255
281b5e5
https://build.opensuse.org/request/show/1078255
by user dgarcia + dimstar_suse
- Add drop-sre-compile.patch upstream patch to fix issues with
  deprecated usage of sre_compile gh#cpplint/cpplint#214
- Update to 1.6.1
  * Fix #195 Fix post increment/decrement operator causing a false positive.
  * Fix #202 .hh files should not be considered sytem headers
  * Fix #207 Python2 incompatibility for loading CPPLINT.cfg file
  * Fix #184 NOLINT(clang-analyzer) comments should not cause warnings
- 1.6.0 (2022-02-19)
  * Fix #188: "Include the directory when naming header files" also
    for header files with other names like "*.hpp"
- 1.5.5 (2021-05-20)
  * Fix #172: Added 'size_t' to typecasts detected by CheckCStyleCast
  * Fixed wrong CLI help text: Each filter needs + or -
  * Fix #164: add elif as an exception for CheckSpacingForFunctionCall()
  * Fix google#346: --root
@dvzrv

dvzrv commented Apr 13, 2023

Copy link
Copy Markdown

Hi! I'm currently looking into applying this for our Python 3.11 rebuild on Arch Linux. Unfortunately this does not apply on top of 1.6.1.
Can this please be rebased, merged and released? That would be very awesome. Thank you! :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

archlinux-github pushed a commit to archlinux/svntogit-community that referenced this pull request Apr 13, 2023
@dvzrv
upgpkg: python-cpplint 1.6.1-3: Rebuild against Python 3.11.
ab0bcfb
Remove unneeded dependencies.
Remove use of legacy sre_compile: cpplint/cpplint#214
Remove use of pytest-runner (not needed for build).
Simplify installation of files using install's -t switch.
Remove the use of srcdir.

git-svn-id: file:///srv/repos/svn-community/svn@1445958 9fca08f4-af9d-4005-b8df-a31f2cc04f65
archlinux-github pushed a commit to archlinux/svntogit-community that referenced this pull request Apr 13, 2023
@dvzrv svntogit
upgpkg: python-cpplint 1.6.1-3: Rebuild against Python 3.11.
25e9993
Remove unneeded dependencies.
Remove use of legacy sre_compile: cpplint/cpplint#214
Remove use of pytest-runner (not needed for build).
Simplify installation of files using install's -t switch.
Remove the use of srcdir.

git-svn-id: file:///srv/repos/svn-community/svn@1445958 9fca08f4-af9d-4005-b8df-a31f2cc04f65
@tjni tjni mentioned this pull request Aug 30, 2023
cpplint: patch so that tests pass on python 3.11 NixOS/nixpkgs#252271
Closed
3 of 12 tasks
@captainurist captainurist mentioned this pull request Nov 12, 2023
Use the latest version of cpplint OpenEnroth/OpenEnroth#1379
Merged
@aaronliu0130
aaronliu0130 merged commit 4557b16 into cpplint:develop Jan 27, 2024
@jspricke
jspricke deleted the python3_11 branch January 28, 2024 13:07
@acreyes acreyes mentioned this pull request Sep 13, 2024
[Trivial] Move a bunch of code from header files to implementation files parthenon-hpc-lab/parthenon#1176
Merged
7 of 12 tasks
@scpeters scpeters mentioned this pull request Sep 21, 2026
Replace deprecated sre_compile with re gazebosim/gz-cmake#589
Merged
6 of 19 tasks
@cottsay cottsay mentioned this pull request Nov 10, 2026
Drop deprecated sre_compile usage ament/ament_lint#610
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@tkruse tkruse tkruse left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@jspricke @dvzrv @tkruse @aaronliu0130
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.