Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mhammond/pywin32 into pyupg…
Browse files Browse the repository at this point in the history
…rade-checks-with-ruff
  • Loading branch information
Avasam committed Jun 4, 2024
2 parents 261075b + 60d7236 commit 8e3f995
Show file tree
Hide file tree
Showing 321 changed files with 3,540 additions and 3,767 deletions.
12 changes: 6 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# A clang-format style that approximates Python's PEP 7
# Useful for IDE integration
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html#configurable-format-style-options
Language: Cpp
BasedOnStyle: Google
AllowShortIfStatementsOnASingleLine: false

AlignAfterOpenBracket: Align
AllowShortIfStatementsOnASingleLine: false
AlwaysBreakAfterReturnType: None # Don't break after return type
BreakBeforeBraces: Stroustrup
ColumnLimit: 120
DerivePointerAlignment: false
IndentWidth: 4
Language: Cpp
PointerAlignment: Right
ReflowComments: true
SortIncludes: false # Sorting includes breaks build
SpaceBeforeParens: ControlStatements
SpacesInParentheses: false
TabWidth: 4
UseTab: Never
# sorting includes breaks build
SortIncludes: false
# don't break after return type
AlwaysBreakAfterReturnType: None
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

# 2024-05-28 formatted trailing-whitespaces and end-of-file with pre-commit
452e3dafc126faa978d67a946385bf2514477411

# 2024-05-28 formatted c++ source with clang-format
637448f8252ab142eedd539ddf9b08259b73eecc
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,18 @@ jobs:
python-version: "3.8"
cache: pip
cache-dependency-path: .github/workflows/main.yml
- run: pip install pycln
- run: pip install clang-format pycln
- run: pycln . --config=pycln.toml --check
- uses: chartboost/ruff-action@v1
with:
version: "0.4.5"
- uses: psf/black@stable
with:
options: "--fast --check --diff --verbose"
- run: | # Too many files to fit in a single command, exclude vendored Scintilla and mapi_headers
clang-format --Werror --dry-run $(git ls-files '*.cpp')
clang-format --Werror --dry-run $(git ls-files '*.h' ':!:Pythonwin/Scintilla/' ':!:com/win32comext/mapi/src/mapi_headers/')
shell: powershell
mypy:
runs-on: windows-2019
Expand Down
16 changes: 12 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# You can run this locally with `pre-commit run [--all]`
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
Expand All @@ -10,10 +10,10 @@ repos:
args: [--fix=crlf]
- id: check-case-conflict
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.12.0
rev: v2.13.0
hooks:
- id: pretty-format-toml
args: [--autofix, --trailing-commas]
args: [--autofix, --trailing-commas, --inline-comment-spaces, "1", --no-sort]
- id: pretty-format-yaml
args: [--autofix, --indent, "2", --offset, "2", --preserve-quotes]
- id: pretty-format-ini
Expand All @@ -30,10 +30,18 @@ repos:
- id: ruff # Run the linter.
args: [--fix]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
rev: 24.4.2
hooks:
- id: black
verbose: true
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.5
hooks:
- id: clang-format
# Supports a lot more filetypes, but only tagging those we use
# https://github.com/pre-commit/mirrors-clang-format/blob/main/.pre-commit-hooks.yaml#L6
types: [c++]


# Vendored
exclude: ^(com/win32comext/mapi/src/mapi_headers/|Pythonwin/Scintilla/).*$
Expand Down
14 changes: 7 additions & 7 deletions AutoDuck/BuildHHP.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def handle_globs(lGlobs):
new = glob.glob(g)
if len(new) == 0:
print(f"The pattern '{g}' yielded no files!")
lFiles = lFiles + new
lFiles.extend(new)
# lFiles is now the list of origin files.
# Normalize all of the paths:
cFiles = len(lFiles)
Expand All @@ -52,9 +52,9 @@ def handle_globs(lGlobs):
while i < cFiles:
if not os.path.isfile(lFiles[i]):
del lFiles[i]
cFiles = cFiles - 1
cFiles -= 1
continue
i = i + 1
i += 1
# Find the common prefix of all of the files
sCommonPrefix = os.path.commonprefix(lFiles)
# Damn - more commonprefix problems
Expand All @@ -67,7 +67,7 @@ def handle_globs(lGlobs):
# else we have a trailing slash - it means we _expect_ it to be a patch as-is.
assert (
os.path.isdir(sCommonPrefix) and sCommonPrefix[-1] == "\\"
), "commonprefix splitting aint gunna work!"
), "commonprefix splitting ain't gunna work!"
print("sCommonPrefix=", sCommonPrefix)
# Ok, now remove this common prefix from every file:
lRelativeFiles = []
Expand Down Expand Up @@ -111,12 +111,12 @@ def main():
shutil.copyfile(lSrcFiles[i], file)

for file in lDestFiles:
html_files = html_files + f"{html_dir}\\{file}\n"
html_files += f"{html_dir}\\{file}\n"

for cat in doc:
html_files = html_files + f"{output_dir}\\{cat.id}.html\n"
html_files += f"{output_dir}\\{cat.id}.html\n"
for suffix in "_overview _modules _objects _constants".split():
html_files = html_files + f"{output_dir}\\{cat.id}{suffix}.html\n"
html_files += f"{output_dir}\\{cat.id}{suffix}.html\n"

f.write(sHHPFormat % {"output": output, "target": target, "html_files": html_files})
f.close()
Expand Down
2 changes: 1 addition & 1 deletion AutoDuck/Dump2HHC.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def genTOC(cats, output, title, target):
**locals()
)
)
# Dont show 'children' for objects - params etc don't need their own child nodes!
# Don't show 'children' for objects - params etc don't need their own child nodes!
_genItemsFromDict(cat.objects, cat, output, target, do_children=0)
output.write(
"""
Expand Down
6 changes: 3 additions & 3 deletions AutoDuck/InsertExternalOverviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ def processFile(input, out, extLinksHTML, extTopicHTML, importantHTML):
def genHTML(doc):
s = ""
for cat in doc:
s = s + f"<H3>{cat.label}</H3>\n"
s += f"<H3>{cat.label}</H3>\n"
dict = {}
for item in cat.overviewItems.items:
dict[item.name] = item.href
keys = list(dict.keys())
keys.sort()
for k in keys:
s = s + f'<LI><A HREF="html/{dict[k]}">{k}</A>\n'
s += f'<LI><A HREF="html/{dict[k]}">{k}</A>\n'
return s


def genLinksHTML(links):
s = ""
for link in links:
s = s + f'<LI><A HREF="{link.href}">{link.name}</A>\n'
s += f'<LI><A HREF="{link.href}">{link.name}</A>\n'
return s


Expand Down
16 changes: 8 additions & 8 deletions AutoDuck/makedfromi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def GetComments(line, lineNo, lines):
doc = ""
if len(data) == 2:
doc = data[1].strip()
lineNo = lineNo + 1
lineNo += 1
while lineNo < len(lines):
line = lines[lineNo]
data = line.split("//", 2)
Expand All @@ -24,10 +24,10 @@ def GetComments(line, lineNo, lines):
if data[1].strip().startswith("@"):
# new command
break
doc = doc + "\n// " + data[1].strip()
lineNo = lineNo + 1
# This line doesnt match - step back
lineNo = lineNo - 1
doc += "\n// " + data[1].strip()
lineNo += 1
# This line doesn't match - step back
lineNo -= 1
return doc, lineNo


Expand Down Expand Up @@ -87,7 +87,7 @@ def make_doc_summary(inFile, outFile):
_, msg, _ = sys.exc_info()
print("Line %d is badly formed - %s" % (lineNo, msg))

lineNo = lineNo + 1
lineNo += 1

# autoduck seems to crash when > ~97 methods. Loop multiple times,
# creating a synthetic module name when this happens.
Expand All @@ -106,9 +106,9 @@ def make_doc_summary(inFile, outFile):
if chunk_number == 0:
pass
elif chunk_number == 1:
thisModName = thisModName + " (more)"
thisModName += " (more)"
else:
thisModName = thisModName + " (more %d)" % (chunk_number + 1,)
thisModName += " (more %d)" % (chunk_number + 1,)

outFile.write("\n")
for meth, extras in these_methods:
Expand Down
5 changes: 4 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ Coming in build 307, as yet unreleased
--------------------------------------

### pywin32
* Marked `exc_type` and `exc_traceback` in `win32comext.axscript.client.error.AXScriptException.__init__` as deprecated.
* Add EnumDesktopWindows (#2219, @CristiFati)
* Marked `exc_type` and `exc_traceback` in `win32comext.axscript.client.error.AXScriptException.__init__` as deprecated. (#2236 , @Avasam)
They are now unused and all information is taken from the `exc_value` parameter.
* Fixed non-overriden `pywin.scintilla.formatter.Formatter.ColorizeString` raising `TypeError` instead of `RuntimeError` due to too many parameters (#2216, @Avasam)
* Fixed broken since Python 3 tokenization in `win32comext.axdebug.codecontainer.pySourceCodeContainer.GetSyntaxColorAttributes` (#2216, @Avasam)
* Fixed a `TypeError` due to incorrect kwargs in `win32comext.axscript.client.pydumper.Register` (#2216, @Avasam)
* Fixed error reporting of file copy failure for for installing debug dlls (#2216, @Avasam)
* Fixed `py.exe -m win32verstamp` command and other quote typos caused by Implied String Concatenation (#2225, @Avasam)
* Fixed tons of quote-related typos in strings, docs and comments (#2271 , @Avasam)
* Fixed VT_SAFEARRAY(VT_RECORD) which were missing the last element (#2247)
* Fixed `MFC redist DLLs not found` by preferring corresponding version but accepting different version (#2248, @andreabravetti)
* Fixed `pywintypes.error: (5, 'RegOpenKeyEx', 'Access is denied.')` when running service with debug parameter and no elevation (#2238, @jmartens)
Expand Down Expand Up @@ -135,6 +137,7 @@ Coming in build 307, as yet unreleased
* Use byte-string (`b""`) for constant bytes values instead of superfluous `.encode` calls (#2046, @Avasam)
* Cleaned up unused imports (#1986, #2051, #1990, #2124, #2126, @Avasam)
* Removed duplicated declarations, constants and definitions (#2050 , #1950, #1990, @Avasam)
* Small generalized optimization by using augmented assignements (in-place operators) where possible (#2274, @Avasam)
* General speed and size improvements due to all the removed code. (#2046, #1986, #2050, #1950, #2085, #2087, #2051, #1990, #2106, #2127, #2124, #2126, #2177, #2218, #2202, #2205, #2217)

### adodbapi
Expand Down
31 changes: 18 additions & 13 deletions Pythonwin/Win32uiHostGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ inline HKEY Win32uiHostGlue::GetRegistryRootKey()

#ifndef LINK_WITH_WIN32UI

#define CHECK_PFN(p) if (!p) { \
wsprintf(err_buf, _T("Failed to load ##p - %d\n"), GetLastError()); \
goto fail_with_error_dlg; \
}
#define CHECK_PFN(p) \
if (!p) { \
wsprintf(err_buf, _T("Failed to load ##p - %d\n"), GetLastError()); \
goto fail_with_error_dlg; \
}

inline BOOL Win32uiHostGlue::DynamicApplicationInit(const TCHAR *cmd, const TCHAR *additionalPaths)
{
Expand Down Expand Up @@ -186,19 +187,23 @@ inline BOOL Win32uiHostGlue::DynamicApplicationInit(const TCHAR *cmd, const TCHA
(*pfnPyInit)();
}

PyObject* (*pPyImport_ImportModule)(const char *name) = (PyObject* (*)(const char *name))GetProcAddress(hModCore, "PyImport_ImportModule");
PyObject *(*pPyImport_ImportModule)(const char *name) =
(PyObject * (*)(const char *name)) GetProcAddress(hModCore, "PyImport_ImportModule");
CHECK_PFN(pPyImport_ImportModule);
PyObject* (*pPyObject_GetAttrString)(PyObject *o, const char *attr_name) = (PyObject* (*)(PyObject *o, const char *attr_name))GetProcAddress(hModCore, "PyObject_GetAttrString");
PyObject *(*pPyObject_GetAttrString)(PyObject *o, const char *attr_name) =
(PyObject * (*)(PyObject * o, const char *attr_name)) GetProcAddress(hModCore, "PyObject_GetAttrString");
CHECK_PFN(pPyObject_GetAttrString);
Py_ssize_t (*pPyUnicode_AsWideChar)(PyObject *unicode, wchar_t *w, Py_ssize_t size) = (Py_ssize_t (*)(PyObject *unicode, wchar_t *w, Py_ssize_t size))GetProcAddress(hModCore, "PyUnicode_AsWideChar");
Py_ssize_t (*pPyUnicode_AsWideChar)(PyObject *unicode, wchar_t *w, Py_ssize_t size) =
(Py_ssize_t(*)(PyObject * unicode, wchar_t * w, Py_ssize_t size))
GetProcAddress(hModCore, "PyUnicode_AsWideChar");
CHECK_PFN(pPyUnicode_AsWideChar);

PyObject* win32ui = pPyImport_ImportModule("win32ui");
PyObject *win32ui = pPyImport_ImportModule("win32ui");
if (!win32ui) {
wsprintf(err_buf, _T("Failed to import win32ui\n"));
goto fail_with_error_dlg;
}
PyObject* pyfn = pPyObject_GetAttrString(win32ui, "__file__");
PyObject *pyfn = pPyObject_GetAttrString(win32ui, "__file__");
if (!pyfn) {
wsprintf(err_buf, _T("Failed to get __file__ from win32ui\n"));
goto fail_with_error_dlg;
Expand Down Expand Up @@ -231,14 +236,14 @@ inline BOOL Win32uiHostGlue::DynamicApplicationInit(const TCHAR *cmd, const TCHA
Py_ssize_t len = _tcslen(err_buf);
Py_ssize_t bufLeft = sizeof(err_buf) / sizeof(TCHAR) - len;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
err_buf + len, PyWin_SAFE_DOWNCAST(bufLeft, Py_ssize_t, DWORD), NULL);
err_buf + len, PyWin_SAFE_DOWNCAST(bufLeft, Py_ssize_t, DWORD), NULL);
AfxMessageBox(err_buf);
return FALSE;
}
#else // LINK_WITH_WIN32UI defined

extern "C" __declspec(dllimport) BOOL
Win32uiApplicationInit(Win32uiHostGlue *pGlue, const TCHAR *cmd, const TCHAR *addnPaths);
extern "C" __declspec(dllimport) BOOL Win32uiApplicationInit(Win32uiHostGlue *pGlue, const TCHAR *cmd,
const TCHAR *addnPaths);
extern "C" void initwin32ui();

inline BOOL Win32uiHostGlue::ApplicationInit(const TCHAR *cmd, const TCHAR *additionalPaths)
Expand All @@ -248,7 +253,7 @@ inline BOOL Win32uiHostGlue::ApplicationInit(const TCHAR *cmd, const TCHAR *addi
Py_Initialize();
}
// Make sure the statically linked win32ui is the one Python sees
// (and doesnt go searching for a new one)
// (and doesn't go searching for a new one)

PyInit_win32ui();
return Win32uiApplicationInit(this, cmd, additionalPaths);
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/contents.d
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ was used for the first block is used for the entire file.
Another common scenario where things go wrong is when pasting code into a new file.
You create a new file (which sets the tabs to your defaults), then
paste in a huge chunk of code that is indented differently. The editor is still using
the defaults, which dont reflect the code that now exists in the buffer.
the defaults, which don't reflect the code that now exists in the buffer.
<nl>
The "tab-timmy" shows up these problems very quickly, and you can quickly toggle the
current tab settings by pressing Ctrl+T, or change the indent width by pressing Ctrl+U.
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/ddemodule.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//#define PY_SSIZE_T_CLEAN // defined in win32virt.cpp which runs the z# format here
// #define PY_SSIZE_T_CLEAN // defined in win32virt.cpp which runs the z# format here

extern PyObject *BASED_CODE dde_module_error;

Expand Down
11 changes: 5 additions & 6 deletions Pythonwin/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ CInProcApp::CInProcApp(LPCTSTR lpszAppName) : CWinApp(lpszAppName)
/////////////////////////////////////////////////////////////////////////////
// CInProcApp initialization

extern "C" PYW_EXPORT BOOL
Win32uiApplicationInit(Win32uiHostGlue *pGlue, const TCHAR *cmd, const TCHAR *addnPaths);
extern "C" PYW_EXPORT BOOL Win32uiApplicationInit(Win32uiHostGlue *pGlue, const TCHAR *cmd, const TCHAR *addnPaths);

BOOL CInProcApp::InitInstance()
{
// Avoid dynamic search for Win32uiApplicationInit from inside DLL
//if (!glue.DynamicApplicationInit())
// if (!glue.DynamicApplicationInit())
if (!Win32uiApplicationInit(&glue, NULL, NULL))
return FALSE;
return glue.InitInstance();
Expand All @@ -115,9 +114,9 @@ BOOL CInProcApp::InitInstance()
// Check that we have a valid CWinApp object to use.
bool CheckGoodWinApp()
{
// Shouldnt need special symbols now that we delay the creation.
// shouldn't need special symbols now that we delay the creation.
// If the host exports a special symbol, then
// dont create a host app.
// don't create a host app.
// HMODULE hModule = GetModuleHandle(NULL);
// BOOL hasSymbol = (GetProcAddress(hModule, "NoCreateWinApp") != NULL);
if (AfxGetApp() == NULL) { // && !hasSymbol) {
Expand Down Expand Up @@ -207,7 +206,7 @@ extern "C" __declspec(dllexport) int __stdcall DllMainwin32ui(HINSTANCE hInstanc

if (pCreatedApp) {
pCreatedApp->CleanupMainWindow();
// We dont call ExitInstance, as the InitInstance we called could
// We don't call ExitInstance, as the InitInstance we called could
// not have possibly called back to Python, as the Python app object
// could not have been created. Let the Python code manage if it wants!
Win32uiFinalize();
Expand Down
12 changes: 6 additions & 6 deletions Pythonwin/pythonview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ void CPythonListViewImpl::DrawItem(LPDRAWITEMSTRUCT lpDIS)
obDC = Py_None;
}

helper.call_args("iiiiiiO(iiii)O", lpDIS->CtlType, lpDIS->CtlID, lpDIS->itemID, lpDIS->itemAction,
lpDIS->itemState, lpDIS->hwndItem, obDC, lpDIS->rcItem.left, lpDIS->rcItem.top,
lpDIS->rcItem.right, lpDIS->rcItem.bottom, obData);
helper.call_args("iiiiiiO(iiii)O", lpDIS->CtlType, lpDIS->CtlID, lpDIS->itemID, lpDIS->itemAction, lpDIS->itemState,
lpDIS->hwndItem, obDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right,
lpDIS->rcItem.bottom, obData);
// The DC is no longer valid.
Python_delete_assoc(pDC);
}
Expand Down Expand Up @@ -132,9 +132,9 @@ void CPythonTreeViewImpl::DrawItem(LPDRAWITEMSTRUCT lpDIS)
obDC = Py_None;
}

helper.call_args("iiiiiiO(iiii)O", lpDIS->CtlType, lpDIS->CtlID, lpDIS->itemID, lpDIS->itemAction,
lpDIS->itemState, lpDIS->hwndItem, obDC, lpDIS->rcItem.left, lpDIS->rcItem.top,
lpDIS->rcItem.right, lpDIS->rcItem.bottom, obData);
helper.call_args("iiiiiiO(iiii)O", lpDIS->CtlType, lpDIS->CtlID, lpDIS->itemID, lpDIS->itemAction, lpDIS->itemState,
lpDIS->hwndItem, obDC, lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right,
lpDIS->rcItem.bottom, obData);
// The DC is no longer valid.
Python_delete_assoc(pDC);
}
Loading

0 comments on commit 8e3f995

Please sign in to comment.