ckan / ckanapi

A command line interface and Python module for accessing the CKAN Action API
Other
176 stars 74 forks source link

Fix error class import fail due to local directory named 'ckan'. #155

Closed tomeksabala closed 3 years ago

tomeksabala commented 3 years ago

Overview

I have encountered this bug while developing a helper script next to my docker-compose configuration for CKAN stack. Next to the script I have a ckan directory with a Dockerfile and image related stuff. I'm not sure if it's a proper fix for this, but earlier behaviour depending on fallback on import ckan looked weak to me. I think we should generate error classes stubs only after actual classes we need fail to import.

Minimal steps to reproduce the issue:

  1. create a script main.py with the following content:
    
    # main.py
    import ckanapi

if name == 'main': print("Works.")

2. Running the script with `python3 main.py` works fine.
3. Create an empty directory ckan

mkdir ckan

project directory tree:

. ├── ckan # empty directory └── main.py

4. Running the script errors with:

$ python3 main.py Traceback (most recent call last): File "main.py", line 1, in import ckanapi File "/home/tomek/tmp/venv/local/lib/python3.6/site-packages/ckanapi/init.py", line 8, in from ckanapi.errors import ( File "/home/tomek/tmp/venv/local/lib/python3.6/site-packages/ckanapi/errors.py", line 63, in from ckan.logic import (NotAuthorized, NotFound, ValidationError) ModuleNotFoundError: No module named 'ckan.logic'


because python import the local directory ckan as a package and it causes the error stubs generation in `ckanapi.errors` to fail.