Skip to content

Commit

Permalink
Add pre-commit and bunch of autofixes support (#2034)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Mar 14, 2024
1 parent 1df78cf commit 1ba696d
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 118 deletions.
1 change: 0 additions & 1 deletion .clang-format
@@ -1,7 +1,6 @@
# A clang-format style that approximates Python's PEP 7
# Useful for IDE integration
BasedOnStyle: Google
AlwaysBreakAfterReturnType: All
AllowShortIfStatementsOnASingleLine: false
AlignAfterOpenBracket: Align
BreakBeforeBraces: Stroustrup
Expand Down
19 changes: 19 additions & 0 deletions .editorconfig
@@ -0,0 +1,19 @@
root = true

[*]
# TODO: Activate and run in a different PR. Lots of files affected
# trim_trailing_whitespace = true
# insert_final_newline = true
# end_of_line = crlf
indent_style = space
indent_size = 4
max_line_length = 120 # Same as .clang-format

[*.py]
max_line_length = 88 # Same as Black

[*.md]
trim_trailing_whitespace = false

[*.{yaml,yml}]
indent_size = 2
70 changes: 35 additions & 35 deletions .github/workflows/docs.yml
Expand Up @@ -4,68 +4,68 @@ on:
create:
tags:
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
- b[0-9][0-9][0-9]
- publish-docs*
- b[0-9][0-9][0-9]
- publish-docs*
push:
branches:
- main
- main

jobs:
decompile:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install latest release
run: pip install --user --upgrade pywin32
- name: Install latest release
run: pip install --user --upgrade pywin32

- name: Set Python user site directory
run: python -c "import os,site;open(os.environ['GITHUB_ENV'], 'a').write(f'USER_DIR={site.USER_SITE}\n')"
- name: Set Python user site directory
run: python -c "import os,site;open(os.environ['GITHUB_ENV'], 'a').write(f'USER_DIR={site.USER_SITE}\n')"

- name: Decompile shipped help file
run: hh -decompile site ${env:USER_DIR}\PyWin32.chm
- name: Decompile shipped help file
run: hh -decompile site ${env:USER_DIR}\PyWin32.chm

- name: Rename root HTML file
run: mv site\PyWin32.HTML site\index.html
- name: Rename root HTML file
run: mv site\PyWin32.HTML site\index.html

# Compress first to avoid slowly uploading thousands of individual files
- name: Create archive
run: python -m zipfile -c site.zip site
- name: Create archive
run: python -m zipfile -c site.zip site

- uses: actions/upload-artifact@v3
with:
name: documentation
path: site.zip
- uses: actions/upload-artifact@v3
with:
name: documentation
path: site.zip

publish:
runs-on: ubuntu-latest
needs:
- decompile
- decompile

# Only publish tags
if: github.event_name == 'create' && github.event.ref_type == 'tag'

steps:
- uses: actions/download-artifact@v3
with:
name: documentation
- uses: actions/download-artifact@v3
with:
name: documentation

- name: Unpack archive
run: python -m zipfile -e site.zip .
- name: Unpack archive
run: python -m zipfile -e site.zip .

- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: site
commit_message: ${{ github.event.head_commit.message }}
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: site
commit_message: ${{ github.event.head_commit.message }}
# Write .nojekyll at the root, see:
# https://help.github.com/en/github/working-with-github-pages/about-github-pages#static-site-generators
enable_jekyll: false
enable_jekyll: false
# Only deploy if there were changes
allow_empty_commit: false
allow_empty_commit: false
129 changes: 64 additions & 65 deletions .github/workflows/main.yml
Expand Up @@ -4,7 +4,7 @@ on:
push:
pull_request:
branches:
- main
- main

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand All @@ -21,40 +21,40 @@ jobs:
architecture: ['x64', 'x86']

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}

- name: Setup environment
run: |
python --version
pip --version
pip install --upgrade setuptools wheel
- name: Build and install
run: |
python setup.py --skip-verstamp install --user
- name: Run tests
# Run the tests directly from the source dir so support files (eg, .wav files etc)
# can be found - they aren't installed into the Python tree.
run: python pywin32_testall.py -v -skip-adodbapi

- name: Build wheels
run: |
python setup.py bdist_wheel --skip-build
- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: artifacts
path: |
dist/*.whl
dist/*.exe
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}

- name: Setup environment
run: |
python --version
pip --version
pip install --upgrade setuptools wheel
- name: Build and install
run: |
python setup.py --skip-verstamp install --user
- name: Run tests
# Run the tests directly from the source dir so support files (eg, .wav files etc)
# can be found - they aren't installed into the Python tree.
run: python pywin32_testall.py -v -skip-adodbapi

- name: Build wheels
run: |
python setup.py bdist_wheel --skip-build
- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: artifacts
path: |
dist/*.whl
dist/*.exe
# We cannot build and test on ARM64, so we cross-compile.
# Later, when available, we can add tests using this wheel on ARM64 VMs
Expand All @@ -67,35 +67,35 @@ jobs:
python-version: ['3.10', '3.11', '3.12-dev']

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'

- name: Setup Environment
run: |
python --version
pip --version
pip install --upgrade setuptools wheel
- name: Obtain ARM64 library files
run: |
python .github\workflows\download-arm64-libs.py .\arm64libs
- name: Build wheels
run: python setup.py --skip-verstamp build_ext -L .\arm64libs --plat-name win-arm64 build --plat-name win-arm64 bdist_wheel --plat-name win-arm64

- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: artifacts
path: |
dist/*.whl
# This job can be run locally with the `format_all.bat` script
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'

- name: Setup Environment
run: |
python --version
pip --version
pip install --upgrade setuptools wheel
- name: Obtain ARM64 library files
run: |
python .github\workflows\download-arm64-libs.py .\arm64libs
- name: Build wheels
run: python setup.py --skip-verstamp build_ext -L .\arm64libs --plat-name win-arm64 build --plat-name win-arm64 bdist_wheel --plat-name win-arm64

- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: artifacts
path: |-
dist/*.whl
# This job can be run locally by running `pre-commit run`
checkers:
runs-on: windows-2019
steps:
Expand Down Expand Up @@ -143,4 +143,3 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
annotate: errors

2 changes: 1 addition & 1 deletion .isort.cfg
@@ -1,5 +1,5 @@
[isort]
py_version=37
py_version = 37
profile = black
combine_as_imports = true
skip = setup.py
Expand Down
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,43 @@
# You can run this locally with `pre-commit run [--all]`
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
# TODO: Activate and run in a different PR. Lots of files affected
# - id: trailing-whitespace
# args: [--markdown-linebreak-ext=md]
# - id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=crlf]
# Vendored
exclude: ^com/win32comext/mapi/src/mapi_headers/.*$
- id: check-case-conflict
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.12.0
hooks:
- id: pretty-format-toml
args: [--autofix, --trailing-commas]
- id: pretty-format-yaml
args: [--autofix, --indent, "2", --offset, "2", --preserve-quotes]
- id: pretty-format-ini
args: [--autofix]
- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
hooks:
- id: pycln
args: [--config=pycln.toml]
verbose: true
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
verbose: true
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
hooks:
- id: black
verbose: true

ci:
autoupdate_schedule: quarterly
3 changes: 0 additions & 3 deletions format_all.bat

This file was deleted.

26 changes: 13 additions & 13 deletions win32/Demos/service/install/perf_install.ini
@@ -1,18 +1,18 @@
[info]
drivername=PipeServicePerf
symbolfile=perf_install.h
drivername = PipeServicePerf
symbolfile = perf_install.h

[languages]
009=English
009 = English

[text]
SERVICE_009_NAME=Python Demo Service
SERVICE_009_HELP=Shows performance statistics for the sample Python service
HEARTBEAT_009_NAME=Heartbeat pulse
HEARTBEAT_009_HELP=Regular counter to indicate the service is alive. Useful so system monitors can detect health even under low loads.
READ_009_NAME=Bytes read/sec
READ_009_HELP=Number of bytes read in total
WRITE_009_NAME=Bytes written/sec
WRITE_009_HELP=Number of bytes written in total
THREADS_009_NAME=Number of threads
THREADS_009_HELP=Number of threads currently servicing client connections
SERVICE_009_NAME = Python Demo Service
SERVICE_009_HELP = Shows performance statistics for the sample Python service
HEARTBEAT_009_NAME = Heartbeat pulse
HEARTBEAT_009_HELP = Regular counter to indicate the service is alive. Useful so system monitors can detect health even under low loads.
READ_009_NAME = Bytes read/sec
READ_009_HELP = Number of bytes read in total
WRITE_009_NAME = Bytes written/sec
WRITE_009_HELP = Number of bytes written in total
THREADS_009_NAME = Number of threads
THREADS_009_HELP = Number of threads currently servicing client connections

0 comments on commit 1ba696d

Please sign in to comment.