Skip to content
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

Could not find package in your path #10

Closed
Kraymer opened this issue Jul 24, 2018 · 10 comments
Closed

Could not find package in your path #10

Kraymer opened this issue Jul 24, 2018 · 10 comments
Assignees

Comments

@Kraymer
Copy link

Kraymer commented Jul 24, 2018

  • Layer Linter version: 0.4.0 (but layer-lint --version does not work)
  • Python version: 2.7.12
  • Operating System: Ubuntu 16.04

Description

Running the program

What I Did

$ layer-lint test
Could not find package 'test' in your path.
$ echo $PYTHONPATH 
/home/flap/Dev/jlmcc/apps
$ pwd
/home/flap/Dev/jlmcc/apps
$ ls test
__init__.py  [...]
$ more layers.html 
rental:
    packages:
        - test
        - test/rental
    layers:
        - core
        - domain

I expect to have more infos in the doc to make this first __import__ works

@seddonym
Copy link
Owner

Thanks for the bug report @Kraymer. I'm afraid Layer Linter doesn't support Python 2; it's possibly a consequence of that.

Are you able to reproduce the issue with Python 3?

@seddonym
Copy link
Owner

P.S. Good suggestion about --version flag, I've added it as an issue: #11

@Kraymer
Copy link
Author

Kraymer commented Jul 24, 2018

~/Dev/jlmcc/apps$ python3 ~/.local/bin/layer-lint myproject
Could not find package 'myproject' in your path.
$ ls myproject
__init__.py  [...]
$ python3 ~/.local/bin/layer-lint test 
============
Layer Linter
============

---------
Contracts
---------

rental KEPT

Contracts: 1 kept, 0 broken.

but I have no idea where is lcoated this test package on my disk, but it is not in ~/Dev/jlmcc/apps

@Kraymer
Copy link
Author

Kraymer commented Jul 24, 2018

PS: trying to make it work on a django project

@seddonym
Copy link
Owner

Layer Linter looks at packages in the Python path, rather than in the filesystem. So you could in theory run it on any package that is installed and importable from your Python prompt. In this case it's linting the built in test module.

Could you try running the Python prompt and then typing import myproject?

One other thing: your layers file should be called layers.yml (not html) and the packages should be listed as Python packages, not files. For example, if you wanted core and domain layers within two subpackages in your project, it would look something like this:

rental:
    packages:
        - myproject.subpackage1
        - myproject.subpackage2
    layers:
        - core
        - domain

Does that make sense?

@Kraymer
Copy link
Author

Kraymer commented Jul 24, 2018

╰─ python3 
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import apps
>>> 
 
╰─ more layers.yml 
rental:
    packages:
        - apps.test
        - apps.test.rental
    layers:
        - core
        - domain

╰─ python3 ~/.local/bin/layer-lint apps
Could not find package 'apps' in your path.

The import works ok in the interpreter.

@Kraymer
Copy link
Author

Kraymer commented Jul 24, 2018

I can somehow make it work if I add a breakpoint in the code (sigh)

╰─ layer-lint apps
Could not find package 'apps' in your path.

// add breakpoint

╰─ layer-lint apps
> /home/flap/Dev/jlmcc/lib/python2.7/site-packages/layer_linter/cmdline.py(50)_main()
     49         import ipdb;ipdb.set_trace()
---> 50         package = __import__(package_name)
     51     except ImportError:

ipdb> n
> /home/flap/Dev/jlmcc/lib/python2.7/site-packages/layer_linter/cmdline.py(54)_main()
     53 
---> 54     if config_directory is None:
     55         config_directory = os.getcwd()

ipdb> c
============
Layer Linter
============

---------
Contracts
---------

rental KEPT

Contracts: 1 kept, 0 broken.

@seddonym
Copy link
Owner

Hmm, I'm not sure what's going on here and it's difficult to troubleshoot without your package / setup.

Try doing this:

  1. Create a Python3 virtualenv, and install your project's requirements in it, plus layer-linter.
  2. Change directory to your project's root, and create your layers.yml in that same directory.
  3. Run layer-lint yourproject.

If it still doesn't work, you could try removing the exception handling for the ImportError in layer_linter/cmdline.py and see if there's a more helpful exception raised.

Alternatively if you're able to share with me with an example project that triggers the error, I could see if I can reproduce it.

Thanks so much for your patience!

@seddonym seddonym self-assigned this Jul 24, 2018
@seddonym
Copy link
Owner

seddonym commented Aug 1, 2018

Hi @Kraymer, I've just released an update (0.5.0) which fixes some problems with importing certain packages. It may fix your problem, if you would like to try it.

If you still have issues, could you run the program including the --debug flag, and paste the output here?

@seddonym
Copy link
Owner

I'm going to close this issue, as I believe it will have been addressed, if not in earlier updates, by the rewrite of the static analysis in the latest version. Feel free to open a new bug report if you still find you have issues.

Thanks again for the bug report.

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

2 participants