Skip to content

Commit

Permalink
Handle __path__
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Apr 14, 2024
1 parent d3391b7 commit f7963f3
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 21 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12-dev']
architecture: ['x64', 'x86']
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
architecture: ["x64", "x86"]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11', '3.12-dev']
python-version: ["3.10", "3.11", "3.12-dev"]

steps:
- uses: actions/checkout@v3
Expand All @@ -73,7 +73,7 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
architecture: "x64"

- name: Setup Environment
run: |
Expand Down Expand Up @@ -103,12 +103,12 @@ jobs:
- uses: actions/setup-python@v4
with:
# This job only needs to target the oldest supported version (black@stable supports Python >=3.8)
python-version: '3.8'
python-version: "3.8"
- run: pip install pycln
- run: pycln . --config=pycln.toml --check
- uses: chartboost/ruff-action@v1
with:
version: '0.3.4'
version: "0.3.4"
- uses: psf/black@stable
with:
options: "--fast --check --diff --verbose"
Expand All @@ -119,7 +119,7 @@ jobs:
fail-fast: false
matrix:
# mypy 1.5 dropped support for Python 3.7
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand All @@ -133,7 +133,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand All @@ -144,5 +144,5 @@ jobs:
- uses: jakebailey/pyright-action@v2
with:
python-version: ${{ matrix.python-version }}
version: '1.1.354'
version: "1.1.358"
annotate: errors
4 changes: 4 additions & 0 deletions Pythonwin/pywin/framework/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
import pywin
import pywin.framework

# Ensure we're working on __path__ as list, not Iterable
pywin.__path__ = list(pywin.__path__)
pywin.framework.__path__ = list(pywin.framework.__path__)

pywin.__path__[0] = win32ui.FullPath(pywin.__path__[0])
pywin.framework.__path__[0] = win32ui.FullPath(pywin.framework.__path__[0])

Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/scintilla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def get_section_header(line):


def find_config_file(f):
return os.path.join(pywin.__path__[0], f + ".cfg")
return os.path.join(next(iter(pywin.__path__)), f + ".cfg")


def find_config_files():
return [
os.path.split(x)[1]
for x in [
os.path.splitext(x)[0]
for x in glob.glob(os.path.join(pywin.__path__[0], "*.cfg"))
for x in glob.glob(os.path.join(next(iter(pywin.__path__)), "*.cfg"))
]
]

Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/test/test_pywin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
user_interaction = getattr(__main__, "user_interaction", False) # from all.py maybe
file_abs = os.path.abspath(__file__)
src_dir = os.path.dirname(file_abs)
pywin_path = pywin.__path__[0]
pywin_path = next(iter(pywin.__path__))
pythonwinpy_path = os.path.dirname(pywin_path) + "\\start_pythonwin.py"
Object = argparse.Namespace
_indebugger = "pywin.debugger" in sys.modules
Expand Down
7 changes: 4 additions & 3 deletions com/win32com/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Initialization for the win32com package
#
from __future__ import annotations

import os
import sys
Expand All @@ -26,6 +27,8 @@
### TODO - Load _all_ \\Extensions subkeys - for now, we only read the default
### Modules will work if loaded into "win32comext" path.

# Ensure we're working on __path__ as list, not Iterable
__path__: list[str] = list(__path__)

def SetupEnvironment():
HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
Expand Down Expand Up @@ -96,9 +99,7 @@ def __PackageSupportBuildPath__(package_path):
try:
import win32com.gen_py

# hrmph - 3.3 throws: TypeError: '_NamespacePath' object does not support indexing
# attempting to get __path__[0] - but I can't quickly repro this stand-alone.
# Work around it by using an iterator.
# __path__ is only ensured to be an Iterable, not a list.
__gen_path__ = next(iter(sys.modules["win32com.gen_py"].__path__))
except ImportError:
# If a win32com\gen_py directory already exists, then we use it
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/server/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def _find_localserver_exe(mustfind):
def _find_localserver_module():
import win32com.server

path = win32com.server.__path__[0]
path = next(iter(win32com.server.__path__))
baseName = "localserver"
pyfile = os.path.join(path, baseName + ".py")
try:
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/test/GenTestScripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def GetGenPath():
import win32api

return os.path.join(win32api.GetFullPathName(win32com.test.__path__[0]), genDir)
return os.path.join(win32api.GetFullPathName(next(iter(win32com.test.__path__))), genDir)


def GenerateFromRegistered(fname, *loadArgs):
Expand Down
6 changes: 3 additions & 3 deletions com/win32com/test/testAXScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class AXScript(win32com.test.util.TestCase):
def setUp(self):
file = win32api.GetFullPathName(
os.path.join(win32com.axscript.client.__path__[0], "pyscript.py")
os.path.join(next(iter(win32com.axscript.client.__path__)), "pyscript.py")
)
from win32com.test.util import RegisterPythonServer

Expand All @@ -22,7 +22,7 @@ def setUp(self):

def testHost(self):
file = win32api.GetFullPathName(
os.path.join(win32com.axscript.__path__[0], "test\\testHost.py")
os.path.join(next(iter(win32com.axscript.__path__)), "test\\testHost.py")
)
cmd = f'{win32api.GetModuleFileName(0)} "{file}"'
if verbose:
Expand All @@ -31,7 +31,7 @@ def testHost(self):

def testCScript(self):
file = win32api.GetFullPathName(
os.path.join(win32com.axscript.__path__[0], "Demos\\Client\\wsh\\test.pys")
os.path.join(next(iter(win32com.axscript.__path__)), "Demos\\Client\\wsh\\test.pys")
)
cmd = 'cscript.exe "%s"' % (file)
if verbose:
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exclude = (?x)(
| ^Pythonwin/Scintilla/
; Forked IDLE extensions predating Python 2.3. They now live in idlelib in https://github.com/python/cpython/tree/main/Lib/idlelib
| ^Pythonwin/pywin/idle/
; TODO: adodbapi should be updated and fixed separatly
; TODO: adodbapi should be updated and fixed separately
| ^adodbapi/
; TODO: Ignoring non-public APIs until all public API is typed
| ([Tt]est|[Dd]emos?)/
Expand Down

0 comments on commit f7963f3

Please sign in to comment.