Skip to content

chore: extract glob for pyupgrade to separate script for cross-platform compatibility#950

Open
peschuster wants to merge 1 commit intoCycloneDX:mainfrom
peschuster:pyupgrade-crossplatform
Open

chore: extract glob for pyupgrade to separate script for cross-platform compatibility#950
peschuster wants to merge 1 commit intoCycloneDX:mainfrom
peschuster:pyupgrade-crossplatform

Conversation

@peschuster
Copy link
Contributor

Currently pyupgrade cannot be run on Windows due to 'sh' in tox.ini not working in PowerShell.

Adding a separate script for this might be controversial.
I could not find another solution that is platform independent, except from inline python in tox.ini which got "complicated" due to {posargs}. However, if anyone has a better idea, this could be reworked.

AI Tool Disclosure

  • My contribution includes AI-generated content, as disclosed below:
    • The contents of the new script is based on suggestions from Claude Sonnet 4.6

Affirmation

@peschuster peschuster requested a review from a team as a code owner March 17, 2026 14:52
import sys
from pathlib import Path

from pyupgrade._main import main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pyupgrade._main is internal of a 3rd party package.
we dont want to call it like that.

call the CLI programmatically, like so - but maek sure that the args are properly escaped if needed ....

subprocess.run(
    [sys.executable, "-m", "pyupgrade", ...],
)

or use runpy.run_module or something.

str(p)
for d in ['cyclonedx', 'typings', 'tests', 'tools', 'examples']
for ext in ['*.py', '*.pyi']
for p in Path(d).rglob(ext)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these d shall be paths relative to the repository root.
current behavior searches them relative to the current working dir, right?
could this be changed so that Path(d) is looked up relative to repo root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave this some thought and would change it a little bit different: keep the list of paths in tox.ini and use the python script just as a wrapper to perform the glob. The responsibility for passing the correct paths (relative to the current working directory or absolute) would stay at the caller and the script would not have to need any knowledge about the repository. Would you agree with that approach?

@peschuster peschuster force-pushed the pyupgrade-crossplatform branch from 0730b36 to f91065d Compare March 21, 2026 13:38
…rm compatibility

'sh' in tox.ini does not work on Windows in PowerShell.

Signed-off-by: Peter Schuster <p.schuster@pilz.de>
@peschuster peschuster force-pushed the pyupgrade-crossplatform branch from f91065d to 53bb407 Compare March 21, 2026 13:39
@peschuster peschuster requested a review from jkowalleck March 21, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants