Indigo
Indigo

Reputation: 962

python setup tools creates unwanted implicit namespace package?

I am using setup tools to install a custom package. When I install it, it works fine but if I go to python I am able to import things I didn't intend to make available and I'd like to prevent this.

My setup.py looks like this:

from setuptools import setup, find_packages
import os

setup(
        name = "MyApp",

        version = "0.1.0",

        author = "Me",
        author_email = "[email protected]",

        packages = ["theapp"],

        package_data = {'theapp': ['../static/*.js', '../static/*.html', '../apps/*', '../resources/*', '../static/*.css', '../static/smore/*']},

        url = "https://github.com/Me/MyApp/",

        description = "does some stuff",

        python_requires = ">3.5",

        install_requires = [
            "qrcode>=5.3",
            "aiohttp>=2.3",
            "pyusb>=1.0",
            ],


        entry_points = {
            "console_scripts": [
                'myapp = myapp:main',
                ]
            },
)

and my directory is setup like this:

MyApp/
├── __init__.py
├── apps
│   ├── main.py
│   └── stuff.py
├── myapp
│   ├── __init__.py
│   ├── lib
│   │   ├── base.py
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   └── ui.py
│   ├── __main__.py
│   └── __pycache__
├── resources
│   ├── tex.cls
│   ├── moretex.sty
│   ├── moretexx.sty
│   ├── outfile.pdf
│   └── outfile.tex
├── setup.py
└── static
    ├── fontawesome-all.js
    ├── index.html
    ├── jquery-3.3.1.js
    ├── smore
    │   ├── myapp.css
    │   └── myapp.min.js
    └── style.css

In python, I can now import myapp without issue but I can also import static and import resources and import apps None of these three contain __init__ files or any .py files so it doesn't make sense for them to be importable. Is there something I'm doing wrong in my setup file to cause this?

EDIT: Based on hoefling's comment I tried adding a blank init.py to the top level directory but the unwanted directories still become importable packages. Is there a way to explicitly prevent this?

Upvotes: 1

Views: 147

Answers (0)

Related Questions