Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e5a944

Browse files
committed
Add a script to validate refactored imports
This script can be removed after imports are refactored and checkedto see that module contents are the same as before or otherwisenon-broken.This script assumes that module contents are the same as thecontents of their dictionaries, and that all modules in the projectget imported as a consequence of importing the top-level module.These are both the case currently for GitPython, but they do nothold for all projects, and may not hold for GitPython at some pointin the future.
1 parent0a609b9 commit1e5a944

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

‎.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ output.txt
4747

4848
# Finder metadata
4949
.DS_Store
50+
51+
# Output files for modattrs.py (these entries will be removed soon)
52+
a
53+
b

‎modattrs.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python
2+
3+
"""Script to get the names and "stabilized" reprs of module attributes in GitPython.
4+
5+
Run with :envvar:`PYTHONHASHSEED` set to ``0`` for fully comparable results. These are
6+
only still meaningful for comparing if the same platform and Python version are used.
7+
8+
The output of this script should probably not be committed, because within the reprs of
9+
objects found in modules, it may contain sensitive information, such as API keys stored
10+
in environment variables. The "sanitization" performed here is only for common forms of
11+
whitespace that clash with the output format.
12+
"""
13+
14+
# fmt: off
15+
16+
__all__= ["git","main"]
17+
18+
importitertools
19+
importre
20+
importsys
21+
22+
importgit
23+
24+
25+
defmain():
26+
# This assumes `import git` causes all of them to be loaded.
27+
gitpython_modules=sorted(
28+
(module_name,module)
29+
formodule_name,moduleinsys.modules.items()
30+
ifre.match(r"git(?:\.|$)",module_name)
31+
)
32+
33+
# We will print two blank lines between successive module reports.
34+
separators=itertools.chain(("",),itertools.repeat("\n\n"))
35+
36+
# Report each module's contents.
37+
for (module_name,module),separatorinzip(gitpython_modules,separators):
38+
print(f"{separator}{module_name}:")
39+
40+
attributes=sorted(
41+
(name,value)
42+
forname,valueinmodule.__dict__.items()
43+
ifname!="__all__"# Because we are deliberately adding these.
44+
)
45+
46+
forname,valueinattributes:
47+
sanitized_repr=re.sub(r"[\r\n\v\f]","?",repr(value))
48+
normalized_repr=re.sub(r" at 0x[0-9a-fA-F]+"," at 0x...",sanitized_repr)
49+
print(f"{name}:{normalized_repr}")
50+
51+
52+
if__name__=="__main__":
53+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp