Exemple #1
0
def modify_path():
    """Add the DLL directory to the module search path.

    This will only modify path if
    * on Windows
    * the ``extra-dll`` directory is in package file metadata
    """
    if os.name != "nt":
        return

    # pylint: disable=import-outside-toplevel
    try:
        import importlib.metadata as importlib_metadata
    except ImportError:  # pragma: NO COVER
        import importlib_metadata
    # pylint: enable=import-outside-toplevel

    try:
        bezier_files = importlib_metadata.files("bezier")
    except importlib_metadata.PackageNotFoundError:
        return

    extra_dll_dir = _get_extra_dll_dir(bezier_files)
    if extra_dll_dir is None:
        return
    add_dll_directory(extra_dll_dir)
Exemple #2
0
def qt_register_fonts():
    for i in files('render-pipeline'):
        if len(i.parts) == 4 and '/'.join(i.parts[:3]) == 'rpcore/data/font':
            f = i.parts[3]
            if f.endswith('.ttf'):
                modpath = '.'.join(i.parts[:3])
                data = pkgutil.get_data(modpath, f)
                QFontDatabase.addApplicationFontFromData(data)
Exemple #3
0
    def get_maestral_command_path():
        # try to get location of console script from package metadata
        console_script = next(p for p in files('maestral')
                              if '/bin/maestral' in str(p))
        path = console_script.locate().resolve()
        if not osp.isfile(path):
            # if not found, check our PATH for maestral command
            path = shutil.which('maestral')

        return path
Exemple #4
0
def importPkg(package):
    """Import phase for analyzing the package."""
    for path in files(package.name):
        # TODO: pyc, C extensions?
        if path.suffix != PY_EXTENSION:
            continue

        import_path = path_to_import(path)
        print('Importing', import_path)
        try:
            importlib.import_module(import_path)
        except:
            print('Failed to import', import_path)
            traceback.print_exc()
Exemple #5
0
    def get_maestral_command_path():
        # try to get location of console script from package metadata
        # fall back to 'which' otherwise
        try:
            pkg_path = next(p for p in files('maestral')
                            if str(p).endswith('/bin/maestral'))
            path = pkg_path.locate().resolve()
        except StopIteration:
            path = ''

        if not osp.isfile(path):
            path = shutil.which('maestral')

        return path
Exemple #6
0
def get_pybind_include_new():
        """Correct way to get pybinds include path.
        Lifted from https://github.com/matplotlib/mplcairo
        """
        try:
            import importlib.metadata as importlib_metadata
        except ImportError:
            import importlib_metadata
        # pybind11.get_include() is brittle (pybind #1425).
        pybind11_include_path = next(
            path for path in importlib_metadata.files("pybind11")
            if path.name == "pybind11.h").locate().parents[1]
        if not (pybind11_include_path / "pybind11/pybind11.h").exists():
            # egg-install from setup_requires:
            # importlib-metadata thinks the headers are at
            #   .eggs/pybind11-VER-TAG.egg/pybind11-VER.data/headers/pybind11.h
            # but they're actually at
            #   .eggs/pybind11-VER-TAG.egg/pybind11.h
            # pybind11_include_path is
            #   /<...>/.eggs/pybind11-VER-TAG.egg/pybind11-VER.data
            # so just create the proper structure there.
            try:
                is_egg = (pybind11_include_path.relative_to(
                    Path(__file__).resolve().parent).parts[0] == ".eggs")
            except ValueError:
                # Arch Linux ships completely wrong metadata, but the headers
                # are in the default include paths, so just leave things as is.
                is_egg = False
            if is_egg:
                shutil.rmtree(pybind11_include_path / "pybind11",
                              ignore_errors=True)
                for file in [*pybind11_include_path.parent.glob("**/*")]:
                    if file.is_dir():
                        continue
                    dest = (pybind11_include_path / "pybind11" /
                            file.relative_to(pybind11_include_path.parent))
                    dest.parent.mkdir(parents=True, exist_ok=True)
                    shutil.copy2(file, dest)

        return pybind11_include_path
Exemple #7
0
"""
pythonnet requires both clr.pyd and Python.Runtime.dll, 
but the latter isn't found by PyInstaller.
"""

import ctypes.util
from PyInstaller.log import logger

try:
    from importlib.metadata import files
except ImportError:
    from importlib_metadata import files

datas = []

filepaths = [f for f in files('pythonnet') if 'Python.Runtime.dll' in str(f)]
if len(filepaths) == 1:
    pyruntime_path = filepaths[0]
    datas = [(pyruntime_path.locate(), pyruntime_path.parent.as_posix())]
elif len(filepaths) > 1:
    logger.warning(
        'More than one Python.Runtime.dll found in site packages! Cannot resolve.'
    )

if len(datas) == 0:
    # Fallback to legacy way of finding Python.Runtime dependency
    library = ctypes.util.find_library('Python.Runtime')
    if library:
        datas = [(library, '.')]
        logger.warning('Legacy method of finding Python.Runtime.dll was used!')
Exemple #8
0

"""
Objetivo:
    ...
"""

from importlib import metadata

def fonte():
    """

    """

# print([1], metadata.metadata("pip"))  # mostrar versão do metadata e um relatório
print([2], metadados := list(metadata.metadata("pip")))
print([3], len(metadata.files("pip")))              # 753
print([4], metadata.requires('pip'))                # pip install pip
print([5], metadata.requires('django'))             # pip install django
print([6], metadata.requires('django-bootstrap4'))  # pip install django-bootstrap4

# for x in metadados:
#     print('\033[1:32m' + 'metadata.metadata("pip")["' + f'{x}' + '"]' + '\033[m', metadata.metadata("pip")[f"{x}"])
#
# print(f'{tuple(enumerate([metadata.metadata("pip")[f"{x}"] for x in metadados]))}')
Exemple #9
0
metadata.version("pip")
# '21.0.1'
pip_metadata = metadata.metadata("pip")
list(pip_metadata)
# ['Metadata-Version', 'Name', 'Version', 'Summary', 'Home-page', 'Author', 'Author-email', 'License', 'Project-URL',
#  'Project-URL', 'Project-URL', 'Keywords', 'Platform', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier',
# 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Requires-Python']

pip_metadata["Home-page"]
# 'https://pip.pypa.io/'

pip_metadata['Requires-Python']
# '>=3.6'

len(metadata.files("pip"))
# 762

# Математические и статистические функции
# Новая функция math.isqrt(). Вы можете использовать, isqrt()чтобы найти целую часть квадратных корней :

math.isqrt(9)
# 3
math.sqrt(9)
# 3.0
math.isqrt(15)
# 3
math.sqrt(15)
# 3.872983346207417

# Наконец, теперь вы можете более легко работать с n -мерными точками и векторами в стандартной библиотеке.
Exemple #10
0
def test_files():
    files = im.files("foo-bar")
    assert len(files) == 1
    assert files[0].name == "foo_bar.py"
    assert files[0].size == 20