Skip to content

Commit

Permalink
Pass mypy and link issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Sep 18, 2024
1 parent 4e062b0 commit 0118ff4
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 57 deletions.
27 changes: 9 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,17 @@ jobs:
strategy:
# https://blog.jaraco.com/efficient-use-of-ci-resources/
matrix:
# This library is Windows-only
# pywin32 does not yet support pypy: mhammond/pywin32#1289 & pypy/pypy#3836
# pywin32's Python 3.13 support is not released yet: mhammond/pywin32#2367
python:
- "3.8"
- "3.13"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
platform:
- ubuntu-latest
- macos-latest
- windows-latest
include:
- python: "3.9"
platform: ubuntu-latest
- python: "3.10"
platform: ubuntu-latest
- python: "3.11"
platform: ubuntu-latest
- python: "3.12"
platform: ubuntu-latest
- python: "3.14"
platform: ubuntu-latest
- python: pypy3.10
platform: ubuntu-latest
- windows-latest
runs-on: ${{ matrix.platform }}
continue-on-error: ${{ matrix.python == '3.14' }}
steps:
Expand Down
27 changes: 12 additions & 15 deletions build-exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
Build script to create a doc-to-pdf convert server as a Windows executable.
"""

import os
import textwrap


setup_params = dict(
console=['server.py'],
options=dict(
py2exe=dict(
packages=['pkg_resources'],
),
),
script_args=('py2exe',),
)

if __name__ == '__main__':
import os
import textwrap

from setuptools import setup

__import__('py2exe')
Expand All @@ -25,5 +14,13 @@
convert.ConvertServer.start_server()
"""
open('server.py', 'w').write(textwrap.dedent(code))
setup(**setup_params)
setup(
console=['server.py'],
options=dict(
py2exe=dict(
packages=['pkg_resources'],
),
),
script_args=('py2exe',), # type: ignore[arg-type] # python/typeshed#12595
)
os.remove('server.py')
2 changes: 1 addition & 1 deletion jaraco/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
22 changes: 9 additions & 13 deletions jaraco/office/convert.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import os
import argparse
import os
import threading
from contextlib import contextmanager

from jaraco.path import save_to_file, replace_extension
import cherrypy
import pythoncom
from win32com.client import Dispatch, constants

from jaraco.path import replace_extension, save_to_file


@contextmanager
Expand All @@ -23,10 +28,6 @@ class Converter:
"""

def __init__(self):
from win32com.client import Dispatch
import pythoncom
import threading

if threading.current_thread().getName() != 'MainThread':
pythoncom.CoInitialize()
self.word = Dispatch('Word.Application')
Expand All @@ -36,8 +37,6 @@ def convert(self, docfile_string, target_format=None):
Take a string (in memory) and return it as a string of the
target format (also as a string in memory).
"""
from win32com.client import constants

target_format = target_format or getattr(constants, 'wdFormatPDF', 17)

with save_to_file(docfile_string) as docfile:
Expand Down Expand Up @@ -80,19 +79,16 @@ class ConvertServer:
def index(self):
return form

index.exposed = True # type: ignore
index.exposed = True # type: ignore[attr-defined]

def convert(self, document):
cherrypy.response.headers['Content-Type'] = 'application/pdf'
return Converter().convert(document.file.read())

convert.exposed = True # type: ignore
convert.exposed = True # type: ignore[attr-defined]

@staticmethod
def start_server():
global cherrypy
import cherrypy

parser = argparse.ArgumentParser()
parser.add_argument('config')
args = parser.parse_args()
Expand Down
4 changes: 2 additions & 2 deletions jaraco/office/excel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import contextlib

from win32com.client import Dispatch

from jaraco.path import tempfile_context


Expand All @@ -22,8 +24,6 @@ def to_dict(values):


def open_workbook(filename):
from win32com.client import Dispatch

app = Dispatch('Excel.Application')
return app.Workbooks.Open(filename)

Expand Down
7 changes: 4 additions & 3 deletions jaraco/office/grep.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import re
from __future__ import annotations

from win32com.client import Dispatch
import re

from win32com.client import Dispatch, dynamic

try:
app = Dispatch('Excel.Application')
app: dynamic.CDispatch | None = Dispatch('Excel.Application')
except Exception:
app = None

Expand Down
8 changes: 8 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ explicit_package_bases = True
disable_error_code =
# Disable due to many false positives
overload-overlap,

# jaraco/jaraco.path#2
[mypy-jaraco.path.*]
ignore_missing_imports = True

# cherrypy/cherrypy#1510
[mypy-cherrypy.*]
ignore_missing_imports = True
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ keywords = ["excel office word"]
requires-python = ">=3.8"
dependencies = [
"jaraco.path",
'pywin32; platform_system == "Windows"',
]
dynamic = ["version"]

Expand All @@ -33,7 +34,7 @@ test = [
"pytest >= 6, != 8.1.*",

# local
'pypiwin32; platform_system == "Windows"',
"cherrypy", # Optional dependency for ConvertServer
]

doc = [
Expand Down Expand Up @@ -65,6 +66,8 @@ type = [
"pytest-mypy",

# local
"types-pywin32",
"types-setuptools",
]


Expand All @@ -74,7 +77,3 @@ doc-to-pdf-server = "jaraco.office.convert:ConvertServer.start_server"


[tool.setuptools_scm]


[tool.pytest-enabler.mypy]
# Disabled due to jaraco/skeleton#143

0 comments on commit 0118ff4

Please sign in to comment.