Skip to content

Pylint: import-outside-toplevel #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
evaherrada opened this issue Mar 10, 2020 · 2 comments
Closed

Pylint: import-outside-toplevel #25

evaherrada opened this issue Mar 10, 2020 · 2 comments

Comments

@evaherrada
Copy link
Collaborator

Here's what I get when I run pylint 2.4 locally.

************* Module adafruit_imageload.bmp
adafruit_imageload/bmp/__init__.py:68:4: C0415: Import outside toplevel (%s) (import-outside-toplevel)
************* Module adafruit_imageload
adafruit_imageload/__init__.py:49:12: C0415: Import outside toplevel (%s) (import-outside-toplevel)
adafruit_imageload/__init__.py:53:12: C0415: Import outside toplevel (%s) (import-outside-toplevel)
adafruit_imageload/__init__.py:57:12: C0415: Import outside toplevel (%s) (import-outside-toplevel)
************* Module adafruit_imageload.pnm
adafruit_imageload/pnm/__init__.py:53:16: C0415: Import outside toplevel (%s) (import-outside-toplevel)
adafruit_imageload/pnm/__init__.py:60:16: C0415: Import outside toplevel (%s) (import-outside-toplevel)
adafruit_imageload/pnm/__init__.py:67:16: C0415: Import outside toplevel (%s) (import-outside-toplevel)
adafruit_imageload/pnm/__init__.py:79:16: C0415: Import outside toplevel (%s) (import-outside-toplevel)
adafruit_imageload/pnm/__init__.py:85:12: C0415: Import outside toplevel (%s) (import-outside-toplevel)
************* Module adafruit_imageload.pnm.pgm
adafruit_imageload/pnm/pgm/__init__.py:43:8: C0415: Import outside toplevel (%s) (import-outside-toplevel)
adafruit_imageload/pnm/pgm/__init__.py:48:8: C0415: Import outside toplevel (%s) (import-outside-toplevel)

bmp/__init__.py
The lines in question:

    from . import indexed

    return indexed.load(
        file,
        width,
        height,
        data_start,
        colors,
        color_depth,
        compression,
        bitmap=bitmap,
        palette=palette,
    )

__init__.py
The lines in question:

        if header.startswith(b"BM"):
            from . import bmp

            return bmp.load(file, bitmap=bitmap, palette=palette)
        if header.startswith(b"P"):
            from . import pnm

            return pnm.load(file, header, bitmap=bitmap, palette=palette)
        if header.startswith(b"GIF"):
            from . import gif

pnm/__init__.py
The lines in question:

            if magic_number in [b"P2", b"P5"]:
                from . import pgm

                return pgm.load(
                    file, magic_number, pnm_header, bitmap=bitmap, palette=palette
                )

            if magic_number == b"P3":
                from . import ppm_ascii

                return ppm_ascii.load(
                    file, pnm_header[0], pnm_header[1], bitmap=bitmap, palette=palette
                )

            if magic_number == b"P6":
                from . import ppm_binary

                return ppm_binary.load(
                    file, pnm_header[0], pnm_header[1], bitmap=bitmap, palette=palette
                )

and

            if magic_number.startswith(b"P1"):
                from . import pbm_ascii

                return pbm_ascii.load(
                    file, pnm_header[0], pnm_header[1], bitmap=bitmap, palette=palette
                )

            from . import pbm_binary

            return pbm_binary.load(
                file, pnm_header[0], pnm_header[1], bitmap=bitmap, palette=palette
            )

pnm/pgm/__init__.py
And finally:

    if magic_number == b"P2":  # To handle ascii PGM files.
        from . import ascii as pgm_ascii

        return pgm_ascii.load(file, width, height, bitmap=bitmap, palette=palette)

    if magic_number == b"P5":  # To handle binary PGM files.
        from . import binary

        return binary.load(file, width, height, bitmap=bitmap, palette=palette)

I'm not sure how resource-intensive the imported libraries are, but I'd assume for something that loads images, they might take up quite a bit of memory. It'd be useful to have someone test this on a board with a smallish amount of memory to see if it still works when everything is imported at once at the top of the file.

Referencing main issue: adafruit/Adafruit_CircuitPython_Bundle#232

@tannewt
Copy link
Member

tannewt commented Mar 11, 2020

Please just disable that check at the top of the files. The imports are nested to reduce the memory footprint.

@kattni
Copy link
Contributor

kattni commented Mar 30, 2020

This is completed.

@kattni kattni closed this as completed Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants