Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Replacement for distutils.filelist ? #4071

Open
1 task done
Avasam opened this issue Oct 1, 2023 · 3 comments
Open
1 task done

[Docs] Replacement for distutils.filelist ? #4071

Avasam opened this issue Oct 1, 2023 · 3 comments
Labels
documentation Needs Triage Issues that need to be evaluated for severity and status.

Comments

@Avasam
Copy link
Contributor

Avasam commented Oct 1, 2023

Summary

I'm looking into progressively migrating distutil usage in pywin32 (mhammond/pywin32#2119), where distutils.filelist.FileList is used.
https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html#prefer-setuptools and https://peps.python.org/pep-0632/#migration-advice don't mention distutils.filelist at all. I searched the documentation for filelist and could not find any deprecation or migration mention.

OS / Environment

Windows 10
Python 3.9
setuptools 68.2.2

Additional Information

Document a migration path for distutils.filelist

Code of Conduct

  • I agree to follow the PSF Code of Conduct
@Avasam Avasam added documentation Needs Triage Issues that need to be evaluated for severity and status. labels Oct 1, 2023
@abravalheri
Copy link
Contributor

abravalheri commented Oct 2, 2023

Hi @Avasam thank you very much for working on this migration.

Is there any chance you could replace the usages of FileList with something like stdlib's glob/pathlib.Path.{r}glob/os.walk?

I had a look on your setup.py and it seems that for the first usage in py_modules = expand_modules("win32\\lib"), that could be an option?

The other usage in convert_data_files maybe can also be done with {r}glob/os.walk, but alternatively, if you feel you need something more complex, you can also try to use something like pathspec or ignorelib1.

What do you think?

Personally, I would like to avoid the extra work associated with maintaining something like a public FileList API.

Footnotes

  1. You can add build-time dependencies using pyproject.toml's [build-system] requires = [...].

@Avasam
Copy link
Contributor Author

Avasam commented Oct 2, 2023

Thank you for your response.

Indeed pywin32 doesn't do anything too complicated with filelist and it can all be replaced with pathlib and other similar API.

Before l started on that path, I wanted to inquire on the recommended migration path. And make sure that filelist is part of the API that isn't going to be re-exposed by setuptools.

The logic probably won't end up being a perfect 1:1, but I think re-implementing with your suggestions, with proper testing, is the way to go. Better than just copying FileList's code directly.

@Avasam
Copy link
Contributor Author

Avasam commented Oct 22, 2023

The following doc was useful: https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module
Related PR if anyone wants to take a look for inspiration: mhammond/pywin32#2138

Path.rglob to replace FileList.findall + FileList.include_pattern.
FileList.exclude_pattern is a bit more complex, you'd have to use a comprehension that filters out on a regex (and convert any previously used glob patterns to regexes yourself), but in my case I was able to simplify it down to the following:

  • path.suffix in {".pyc", ".pyo"} instead of a *.py[co] glob
  • "\\directory_name\\" in file (where file = str(path) to have the normalized slashes) instead of a regex

You can close this issue if you don't think there is a need to document FileList migration paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Needs Triage Issues that need to be evaluated for severity and status.
Projects
None yet
Development

No branches or pull requests

2 participants