File: package.py

package info (click to toggle)
python-xsdata 24.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,936 kB
  • sloc: python: 29,257; xml: 404; makefile: 27; sh: 6
file content (22 lines) | stat: -rw-r--r-- 694 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import functools
import os
from pathlib import Path


@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


@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(".", "/"))


@functools.lru_cache(maxsize=50)
def module_name(source: str) -> str:
    module = source.split("/")[-1]
    name, extension = os.path.splitext(module)
    return name if extension in (".xsd", ".dtd", ".wsdl", ".xml", ".json") else module