-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
Detect if package is installed editable #404
Comments
Since |
@jaraco yes that you work. But this means that I must rely that this file is created,whuch means that the packaging tool must follow the PEP.
|
Yes, that's right. The good news is that many/most tools now support the PEP.
Possibly, though I suspect not a robust one. Probably it would require coming up with some inference heuristic.
Yes, perhaps. If this behavior would prove generally useful, it could be exposed here. Can you describe more about why this behavior is useful and why it would be useful for others? My instinct is it probably could belong here, but I'd not wish to adopt the behavior if it only has narrow usefulness. Presuming we do wish to move forward, it would be worthwhile to have a draft/demo routine that implements the logic. Would you be willing to research the details and devise an implementation? |
Thanks a lot for your comment. I read now the full PEP 660 and PEP 610 and I think importlib-metadata could include a parser for direct_url.json which parses the file into an object which can be received over the distribution object. Since this is more general than my initial requirement all use cases listed in PEP 610 could benefit from this feature. In short, its then possible to get e.g. the file link and even git information over a well known API. As a way forward I would propose a new field part of the distribution called direct_url_origin. Behind the scenes a (possible lazy) parses reads the JSON file and publishes all fields of PEP 610. What do you think? |
That all sounds reasonable. I'd want to think carefully about the new field. Those are my thoughts. I'm encouraged and look forward to your implementation. |
Thanks for the ideas. Sounds like a great idea. I'll give a PR a try in the next 1/2 weeks |
@jaraco I have some issues getting the # install importlib_metadata itself with 'pip install -e .'
import importlib_metadata
x = importlib_metadata.distribution("importlib_metadata")
x._path
# PosixPath('importlib_metadata.egg-info') However, by using the following, I can see that also the dist-info path was found import importlib_metadata
x = list(importlib_metadata.Distribution.discover(name="importlib_metadata"))
# x[0]._path -> PosixPath('importlib_metadata.egg-info')
# x[1]._path -> PosixPath('importlib_metadata/.venv/lib64/python3.7/site-packages/importlib_metadata-0.1.dev1283+g5573f98.dist-info') If a user would use the default way with |
You don't want to use I can see that it doesn't work for egg-info. Only dist-info seems to be supplying the "direct_url.json" file. That means you won't be able to supply a meaningful You've observed above that your environment has two distributions for So the fact that you get |
Moved to pypa/packaging#701 |
I still think importlib_metadata should probably provide a convenience method to load the metadata file. I can see I pushed 5898112. Would that be helpful for the |
Hey,
Not sure if this is the right place and/or right package to ask, but you need to start somewhere 😄 .
I have the following case: A script in a distributable should behave differently if it's started by the distributable or by anther project just importing the distributable.
For instance, the distributable has the name
foo
.If I developing
foo
currently and I executefoo.py
it should return 1. If another project depends onfoo
and executesfoo.py
after installingfoo
over pip it should return 2.Since there seems to be no reliable way, for now I use the assumption that current project means editable install. With that I can use
So if
foo
is installed editable, the egg_info has no dist-info. But that's very hacky.Therefore, how can I improve this?
direct_url.json
of PEP 660 somehow? It would help to detect if it's an editable install w/o finding/parsing the file on my ownThe text was updated successfully, but these errors were encountered: