Skip to content

# package

## `xsdata.utils.package`

### `package_path(package)` `cached`

Join the current working path with the package name.

Source code in `xsdata/utils/package.py`

    6
    7
    8
    9

    @functools.lru_cache(maxsize=50)
    def package_path(package: str) -> Path:
        """Join the current working path with the package name."""
        return Path.cwd().joinpath(package.replace(".", "/")).parent

### `module_path(module)` `cached`

Join the current working path with the given module name.

Source code in `xsdata/utils/package.py`

    12
    13
    14
    15

    @functools.lru_cache(maxsize=50)
    def module_path(module: str) -> Path:
        """Join the current working path with the given module name."""
        return Path.cwd().joinpath(module.replace(".", "/"))

### `module_name(uri)` `cached`

Convert a file uri to a module name.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`uri` | `str` | A file URI location | required

Returns:

Type | Description
--- | ---
`str` | The last part of the URI path stripped from known extensions.

Source code in `xsdata/utils/package.py`

    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30

    @functools.lru_cache(maxsize=50)
    def module_name(uri: str) -> str:
        """Convert a file uri to a module name.

        Args:
            uri: A file URI location

        Returns:
            The last part of the URI path stripped from known extensions.
        """
        module = uri.split("/")[-1]
        name, extension = os.path.splitext(module)
        return name if extension in (".xsd", ".dtd", ".wsdl", ".xml", ".json") else module