Hello Christian, > if there are more than one packages with the same label?
Two apps cannot have the same label. One of them must be relabeled as described in https://docs.djangoproject.com/en/2.2/ref/applications/#django.apps.AppConfig.label <https://docs.djangoproject.com/en/2.2/ref/applications/#django.apps.AppConfig.label>. If a pluggable app wants to access its own app config even if it was relabeled, there's no direct API to do so, but it's a one-liner: from django.apps import apps app_name = "gdaps.frontend" app_config = [ac for ac in apps.get_app_configs() if ac.name == app_name][0] This is pretty much how apps.is_installed(app_name) is implemented. There isn't a more efficient way to do this with the current implementation of django.apps.Apps. Perhaps the API of django.apps.Apps could be improved to facilitate such use cases. At first sight, there are several options to consider: - provide an apps.get_app_label(app_name) function that would do the translation from app_name to app_label - accept either an app_label (e.g. "admin") or an app_name (e.g. "django.contrib.admin") in APIs that currently only accept an app_label - etc. It's been five years since Django 1.7 was released with new app registry. During this time, I haven't seen app_label conflicts or relabeling causing big problems in practice. (The only vaguely related case I've ever seen was someone who copy-pasted an app under a different name. This changed both the app_label and the app_name, so even relying on the app_name would fail in that case.) I'd rather keep things simple here. Best regards, -- Aymeric. > On 10 Nov 2019, at 22:12, Christian González <christian.gonza...@nerdocs.at> > wrote: > > Hi all, > > I recently found a problem - maybe I didn't get everything, but the docs > say that, if you want to get an app's path, you should use > get_app_config(app_label).path. > > Now, passing the app_label is handy if you have few packages installed, > but it comes to name clashes if there are multiple packages with the > same label (but different names). > > I happen to start a bigger project, and there are some packages > installed like "gdaps.frontend". Maybe one of my plugins later will be > named "medux.frontend". These two have a different name, but the same label. > > Ok, I can simply do a > > from medux import frontend > do_something_with(os.path.dirname(frontend.__file__)) > > But AppConfig.get_app_config() exactly should exist because I should NOT > do that. > > How do I get the path of an app in a deterministic way, if there are > more than one packages with the same label? Is this a bug? > > Thanks, > > Christian > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/c8e6e354-7d02-835e-cd62-5d38102bd374%40nerdocs.at. > <pEpkey.asc> -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/BE8FAA8F-BE28-4DDB-B36C-3CD9C5DC6164%40polytechnique.org.