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

gh-121445: C implementation for fnmatch.translate #123181

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
10a6094
add implementation
picnixz Jul 6, 2024
ca03388
add initial tests
picnixz Jul 6, 2024
adb6ed0
add generated objects
picnixz Jul 6, 2024
e95c255
update PC/config.c
picnixz Jul 6, 2024
9b1c20d
update Modules/Setup
picnixz Jul 6, 2024
85fa953
update VCX project files
picnixz Jul 6, 2024
363ec36
fix return value
picnixz Jul 6, 2024
42b019f
fix typo in pythoncore.vcxproj
picnixz Jul 6, 2024
4120a95
Update pythoncore.vcxproj.filters
picnixz Jul 6, 2024
36394bb
Amend un-necessary modifications in `test_fnmatch.py`
picnixz Jul 6, 2024
2c2f9f1
update configurations
picnixz Jul 8, 2024
ecf8146
add C implementation
picnixz Jul 8, 2024
cb16b6a
update Python implementation
picnixz Jul 8, 2024
751c069
update tests
picnixz Jul 8, 2024
9258068
add generated objects
picnixz Jul 8, 2024
5a7183c
re-expose private API
picnixz Jul 8, 2024
2a80200
fix implementation?
picnixz Jul 9, 2024
36432e8
update generated objects
picnixz Jul 9, 2024
4a36980
FIX BUILD
picnixz Jul 9, 2024
4881f1c
remove interned strings
picnixz Jul 9, 2024
ec5a922
revert addition
picnixz Jul 9, 2024
b29ccb4
make it fail on Windows for now
picnixz Jul 9, 2024
a91f689
Update configurations?
picnixz Jul 9, 2024
9e93b58
split implementation
picnixz Jul 9, 2024
5cfd580
regenerated objects
picnixz Jul 9, 2024
891a368
maybe it's like that?
picnixz Jul 9, 2024
adc18bd
maybe like this...?
picnixz Jul 9, 2024
658fb81
regenerate configure script
picnixz Jul 10, 2024
cb29bd3
update tests
picnixz Jul 10, 2024
c1fae24
update files
picnixz Jul 10, 2024
f9343f3
update generated objects
picnixz Jul 10, 2024
46d7744
update module names
picnixz Jul 10, 2024
5bc902e
fix smelly names
picnixz Jul 10, 2024
7814028
fix translation unit
picnixz Jul 11, 2024
3f075bb
remove fnmatch(3) detection
picnixz Jul 11, 2024
c78a813
remove fnmatch(3) layout
picnixz Jul 11, 2024
2e166cc
update configuration scripts
picnixz Jul 11, 2024
14cd1fd
update function names
picnixz Jul 11, 2024
2a718f4
make the C interface equivalent to the Python one
picnixz Jul 11, 2024
c7a0685
fixups
picnixz Jul 11, 2024
1340fd2
update generated objects
picnixz Jul 11, 2024
2b6fe4f
reflect `__all__` ordering
picnixz Jul 11, 2024
124f8f8
update comments
picnixz Jul 11, 2024
7621d6c
blurb
picnixz Jul 12, 2024
9b94fe6
(hopefully MSVC will be happy...)
picnixz Jul 12, 2024
3903987
fix MSVC warnings
picnixz Jul 12, 2024
21ccc7c
Merge branch 'main' into fnmatch-c-implementation
picnixz Jul 12, 2024
c7422a5
fixup typo!
picnixz Jul 12, 2024
7dbe55c
`get_fnmatchmodulestate_state` -> `get_fnmatchmodule_state`
picnixz Jul 12, 2024
4a87911
remove unused imports
picnixz Jul 12, 2024
aca2b1b
update state
picnixz Jul 12, 2024
2ef61ad
simplify implementation
picnixz Jul 12, 2024
13dc17e
harmonize docs
picnixz Jul 12, 2024
dba784b
improvements
picnixz Jul 12, 2024
5374ff4
revert some improvements that were not improvements
picnixz Jul 12, 2024
4ff4f37
remove incorrect usage of clinic
picnixz Jul 13, 2024
178f2d3
update TODO note
picnixz Jul 13, 2024
9d237b1
use a dynamic module instead
picnixz Jul 15, 2024
b1568d4
remove un-necessary definitions
picnixz Jul 15, 2024
84b0b82
update configuration
picnixz Jul 15, 2024
8696024
intern strings & functions
picnixz Jul 16, 2024
b27b6d8
various improvements
picnixz Jul 16, 2024
b564b22
PEP-7 fixes
picnixz Jul 16, 2024
6740b10
Merge branch 'main' into fnmatch-c-implementation
picnixz Jul 17, 2024
d73f66d
update comments and names
picnixz Jul 17, 2024
6258b71
refactorization:
picnixz Jul 17, 2024
d595cb4
improve coverage
picnixz Jul 18, 2024
e4296d8
update benchmarks
picnixz Jul 18, 2024
cc92c4b
fixup
picnixz Jul 18, 2024
527712a
Merge branch 'main' into fnmatch-c-implementation
picnixz Jul 18, 2024
ee27297
refactorization:
picnixz Jul 20, 2024
0622be6
update dependencies
picnixz Jul 20, 2024
481fae0
merge commit
picnixz Jul 20, 2024
ff60eeb
Revert "merge commit"
picnixz Jul 20, 2024
aff1f97
Merge branch 'main' into fnmatch-c-implementation
picnixz Jul 20, 2024
3727582
update dependencies
picnixz Jul 20, 2024
90e809a
Merge remote-tracking branch 'upstream/main' into fnmatch-c-implement…
picnixz Jul 25, 2024
c89cf47
Fix missing exception handler
picnixz Jul 25, 2024
4fbd06b
cosmetic changes
picnixz Jul 25, 2024
3b348f5
update comments
picnixz Jul 28, 2024
da42703
remove some macros
picnixz Jul 28, 2024
97ed24d
cleanup
picnixz Jul 28, 2024
d38a0cb
test empty range
picnixz Jul 28, 2024
db88ff5
update macros.h
picnixz Jul 28, 2024
2caa5b8
update algorithm
picnixz Jul 28, 2024
ef2de2a
PEP 7
picnixz Jul 28, 2024
c00c8f9
remove un-necessary code
picnixz Jul 28, 2024
e93cd87
use convenience macros for aborting flow
picnixz Jul 28, 2024
3a05676
refactor macros
picnixz Jul 28, 2024
db75626
rename `COMPILED_CACHE_SIZE` to `LRU_CACHE_SIZE`
picnixz Aug 18, 2024
df76ba3
add LRU cache for `re.escape`
picnixz Aug 18, 2024
ac46e2c
cache `re.compile(...).sub` for set operations tokens
picnixz Aug 19, 2024
fa04ea1
update implementation
picnixz Aug 18, 2024
0b4cced
use macros for abort-flow
picnixz Aug 19, 2024
5039bce
allow path-like objects in `fnmatch.filter`
picnixz Aug 19, 2024
afc22b2
macros bike-shedding
picnixz Aug 19, 2024
e66a602
type bike-shedding
picnixz Aug 19, 2024
2b59064
update outdated comment
picnixz Aug 19, 2024
8efbe9a
only keep `fnmatch.translate` in C
picnixz Aug 20, 2024
5c37da7
remove legacy tests
picnixz Aug 20, 2024
79fb2f2
update NEWS
picnixz Aug 20, 2024
6e9879f
cleanup
picnixz Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(col_offset)
STRUCT_FOR_ID(command)
STRUCT_FOR_ID(comment_factory)
STRUCT_FOR_ID(compile)
STRUCT_FOR_ID(compile_mode)
STRUCT_FOR_ID(consts)
STRUCT_FOR_ID(context)
Expand Down Expand Up @@ -404,6 +405,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(entrypoint)
STRUCT_FOR_ID(env)
STRUCT_FOR_ID(errors)
STRUCT_FOR_ID(escape)
STRUCT_FOR_ID(event)
STRUCT_FOR_ID(eventmask)
STRUCT_FOR_ID(exc_type)
Expand Down Expand Up @@ -432,6 +434,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(filter)
STRUCT_FOR_ID(filters)
STRUCT_FOR_ID(final)
STRUCT_FOR_ID(find)
STRUCT_FOR_ID(find_class)
STRUCT_FOR_ID(fix_imports)
STRUCT_FOR_ID(flags)
Expand Down Expand Up @@ -575,6 +578,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(n_unnamed_fields)
STRUCT_FOR_ID(name)
STRUCT_FOR_ID(name_from)
STRUCT_FOR_ID(names)
STRUCT_FOR_ID(namespace_separator)
STRUCT_FOR_ID(namespaces)
STRUCT_FOR_ID(narg)
Expand Down Expand Up @@ -617,6 +621,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(pages)
STRUCT_FOR_ID(parent)
STRUCT_FOR_ID(password)
STRUCT_FOR_ID(pat)
STRUCT_FOR_ID(path)
STRUCT_FOR_ID(pattern)
STRUCT_FOR_ID(peek)
Expand Down Expand Up @@ -714,6 +719,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(strict)
STRUCT_FOR_ID(strict_mode)
STRUCT_FOR_ID(string)
STRUCT_FOR_ID(sub)
STRUCT_FOR_ID(sub_key)
STRUCT_FOR_ID(symmetric_difference_update)
STRUCT_FOR_ID(tabsize)
Expand Down
6 changes: 6 additions & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions Lib/fnmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ def fnmatchcase(name, pat):
match = _compile_pattern(pat)
return match(name) is not None


def translate(pat):
"""Translate a shell PATTERN to a regular expression.

There is no way to quote meta-characters.
"""

STAR = object()
parts = _translate(pat, STAR, '.')
return _join_translated_parts(parts, STAR)
try:
from _fnmatch import translate
except ImportError:
def translate(pat):
"""Translate a shell PATTERN to a regular expression.

There is no way to quote meta-characters.
"""

STAR = object()
parts = _translate(pat, STAR, '.')
return _join_translated_parts(parts, STAR)


def _translate(pat, STAR, QUESTION_MARK):
Expand Down
Loading
Loading