Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created February 7, 2023 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save podhmo/33ac3fed4e575075755d9c5b9f0f9215 to your computer and use it in GitHub Desktop.
Save podhmo/33ac3fed4e575075755d9c5b9f0f9215 to your computer and use it in GitHub Desktop.
def run():
from flake8.options.parse_args import parse_args
plugins, namespace = parse_args([])
print("plugins")
for p in plugins:
print("\t", p)
print("")
print("namespace")
print("\t", namespace)
def run2():
from flake8.utils import normalize_pypi_name
from flake8.plugins.finder import _find_importlib_plugins
plugins = list(_find_importlib_plugins())
for p in plugins:
L = [normalize_pypi_name(p.package), p.entry_point.name, p.entry_point.value]
print("\t".join(L))
def run3():
from importlib import metadata
m = metadata.distribution("flake8-soft-keywords")
filename = "entry_points.txt"
print(m.locate_file(filename))
print(m._path.joinpath(filename))
print(m.read_text(filename))
print(m.entry_points)
run()
@podhmo
Copy link
Author

podhmo commented Feb 7, 2023

entry pointsを見つけるやつ poetnry install を忘れててハマった

@podhmo
Copy link
Author

podhmo commented Feb 9, 2023

locate_fileが壊れてたように見えたけど、filesを呼んだときも壊れてる?

@podhmo
Copy link
Author

podhmo commented Feb 9, 2023

https://github.com/python/cpython/blob/ecfd2d37c529c1952dc11fabe1758156924de67a/Lib/importlib/metadata/__init__.py#L743-L756

locate_fileの使い方が違うのか。Distribution#files の結果とかを見ながらこれをfilepathに変換するときに使うのか。PackagePathをPosixPathなどに変換する。 d.locate_file(d.files[0]) ここで PackagePath("pip/__init__.py") みたいな感じになるので。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment