What distutils is equivalent to setuptools `find_packages`? (Python)

I have a file setup.pythat checks if the user has one setuptools, and if not, then I have to use distutils. The thing is, to make sure that the submodules are installed, I use the setuptools'find package:

from setuptools import setup, find_packages
packages = find_packages()

and then from there.

However, I am not sure how to do this using distutils. Is there an equivalent function, or do I have to manually look for subdirs with __init__.pyinside them? If so, is it acceptable for me to require me to setuptoolsinstall my package and just forget about distutils?

Greetings.

+4
source share
1

setuptools; PyPI .

find_packages(), , __init__.py . , setuptools.PackageFinder . :

import os
from distutils.util import convert_path


def find_packages(base_path):
    base_path = convert_path(base_path)
    found = []
    for root, dirs, files in os.walk(base_path, followlinks=True):
        dirs[:] = [d for d in dirs if d[0] != '.' and d not in ('ez_setup', '__pycache__')]
        relpath = os.path.relpath(root, base_path)
        parent = relpath.replace(os.sep, '.').lstrip('.')
        if relpath != '.' and parent not in found:
            # foo.bar package but no foo package, skip
            continue
        for dir in dirs:
            if os.path.isfile(os.path.join(root, dir, '__init__.py')):
                package = '.'.join((parent, dir)) if parent else dir
                found.append(package)
    return found

include exclude setuptools.find_packages().

+5

All Articles