"tools/git@developer.sourcefind.cn:OpenDAS/dlib.git" did not exist on "0175116fce521944b88e5eaca6fb54680453a6ed"
Commit ce776f7d authored by Miquel Jubert Hermoso's avatar Miquel Jubert Hermoso Committed by Facebook GitHub Bot
Browse files

Hardcode top-level directory, remove import for resource access

Summary:
Pull Request resolved: https://github.com/facebookresearch/d2go/pull/229

*This diff is part of a stack which has the goal of "buckifying" D2 (https://github.com/facebookresearch/d2go/commit/87374efb134e539090e0b5c476809dc35bf6aedb)Go core and enabling autodeps and other tooling. The last diff in the stack introduces the TARGETS. The diffs earlier in the stack are resolving circular dependencies and other issues which prevent the buckification from occurring.*

This diff changes the import paths being rerouted in the d2go package. Instead of local-importing the package, which creates a buck circular dependency, we can hardcode the top-level path. We know it is fixed because we are defining it with base_module.

For the other packages it can remain as-is.

Also add some dependencies annotations in preparation for the buckification, with manual.

Reviewed By: wat3rBro

Differential Revision: D35928513

fbshipit-source-id: 756c95740bab519e8093d254bcee64692e1a1b98
parent 3b64e76a
...@@ -7,19 +7,16 @@ from enum import Enum ...@@ -7,19 +7,16 @@ from enum import Enum
from typing import Any, Dict, List from typing import Any, Dict, List
import pkg_resources import pkg_resources
from mobile_cv.common.misc.oss_utils import fb_overwritable from mobile_cv.common.misc.oss_utils import fb_overwritable
@fb_overwritable()
def reroute_config_path(path: str) -> str: def reroute_config_path(path: str) -> str:
""" """
Supporting rerouting the config files for convenience: Supporting rerouting the config files for convenience:
d2go:// -> mobile-vision/d2go/... d2go:// -> mobile-vision/d2go/...
detectron2go:// -> mobile-vision/d2go/configs/... detectron2go:// -> mobile-vision/d2go/configs/...
detectron2:// -> vision/fair/detectron2/configs/... detectron2:// -> vision/fair/detectron2/configs/...
flow:// -> fblearner/flow/projects/mobile_vision/detectron2go/...
mv_experimental:// -> mobile-vision/experimental/...
(see //mobile-vision/experimental:mv_experimental_d2go_yaml_files)
Those config are considered as code, so they'll reflect your current checkout, Those config are considered as code, so they'll reflect your current checkout,
try using canary if you have local changes. try using canary if you have local changes.
""" """
...@@ -27,34 +24,25 @@ def reroute_config_path(path: str) -> str: ...@@ -27,34 +24,25 @@ def reroute_config_path(path: str) -> str:
if path.startswith("d2go://"): if path.startswith("d2go://"):
rel_path = path[len("d2go://") :] rel_path = path[len("d2go://") :]
config_in_resource = pkg_resources.resource_filename("d2go", rel_path) return pkg_resources.resource_filename("d2go", rel_path)
return config_in_resource
elif path.startswith("detectron2go://"): elif path.startswith("detectron2go://"):
rel_path = path[len("detectron2go://") :] rel_path = path[len("detectron2go://") :]
config_in_resource = pkg_resources.resource_filename( return pkg_resources.resource_filename(
"d2go", os.path.join("configs", rel_path) "d2go", os.path.join("configs", rel_path)
) )
return config_in_resource
elif path.startswith("detectron2://"): elif path.startswith("detectron2://"):
rel_path = path[len("detectron2://") :] rel_path = path[len("detectron2://") :]
config_in_resource = pkg_resources.resource_filename( return pkg_resources.resource_filename(
"detectron2.model_zoo", os.path.join("configs", rel_path) "detectron2.model_zoo", os.path.join("configs", rel_path)
) )
return config_in_resource else:
return reroute_fb_config_path(path)
return path
def _flatten_config_dict(x, reorder, prefix): @fb_overwritable()
if not isinstance(x, dict): def reroute_fb_config_path(path: str) -> str:
return {prefix: x} return path
d = {}
for k in sorted(x.keys()) if reorder else x.keys():
v = x[k]
new_key = f"{prefix}.{k}" if prefix else k
d.update(_flatten_config_dict(v, reorder, new_key))
return d
def flatten_config_dict(dic, reorder=True): def flatten_config_dict(dic, reorder=True):
...@@ -81,6 +69,18 @@ def flatten_config_dict(dic, reorder=True): ...@@ -81,6 +69,18 @@ def flatten_config_dict(dic, reorder=True):
return _flatten_config_dict(dic, reorder=reorder, prefix="") return _flatten_config_dict(dic, reorder=reorder, prefix="")
def _flatten_config_dict(x, reorder, prefix):
if not isinstance(x, dict):
return {prefix: x}
d = {}
for k in sorted(x.keys()) if reorder else x.keys():
v = x[k]
new_key = f"{prefix}.{k}" if prefix else k
d.update(_flatten_config_dict(v, reorder, new_key))
return d
def config_dict_to_list_str(config_dict: Dict) -> List[str]: def config_dict_to_list_str(config_dict: Dict) -> List[str]:
"""Creates a list of str given configuration dict """Creates a list of str given configuration dict
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment