Return a Resource matching the ``referenced_filename`` path or filename given a ``resource`` in ``codebase``. To find the `referenced_filename` the sibling files of the `resource` and files at the `codebase` root are searched. Return None if the ``referenced_filename`` cannot
(referenced_filename, resource, codebase, **kwargs)
| 1949 | |
| 1950 | |
| 1951 | def find_referenced_resource(referenced_filename, resource, codebase, **kwargs): |
| 1952 | """ |
| 1953 | Return a Resource matching the ``referenced_filename`` path or filename |
| 1954 | given a ``resource`` in ``codebase``. |
| 1955 | |
| 1956 | To find the `referenced_filename` the sibling files of the `resource` |
| 1957 | and files at the `codebase` root are searched. |
| 1958 | |
| 1959 | Return None if the ``referenced_filename`` cannot be found in the same |
| 1960 | directory as the base ``resource``, or at the codebase ``root``. |
| 1961 | |
| 1962 | ``referenced_filename`` is the path or filename referenced in a |
| 1963 | LicenseMatch detected at ``resource``, |
| 1964 | """ |
| 1965 | if not resource: |
| 1966 | return |
| 1967 | |
| 1968 | parent_path = resource.parent_path() |
| 1969 | if not parent_path: |
| 1970 | return |
| 1971 | |
| 1972 | # this can be a path or a plain name |
| 1973 | referenced_filename = clean_path(referenced_filename) |
| 1974 | path = posixpath.join(parent_path, referenced_filename) |
| 1975 | resource = codebase.get_resource(path=path) |
| 1976 | if resource: |
| 1977 | return resource |
| 1978 | |
| 1979 | # Also look at codebase root for referenced file |
| 1980 | root_path = codebase.root.path |
| 1981 | path = posixpath.join(root_path, referenced_filename) |
| 1982 | resource = codebase.get_resource(path=path) |
| 1983 | if resource: |
| 1984 | return resource |
| 1985 | |
| 1986 | |
| 1987 | def update_expressions_from_license_detections(resource, codebase): |