0

My rssita.py python code has the following lines:

from feeds import RSS_FEEDS
from termcolors import PC

and this is the corresponding directory tree:

(rssita-py3.10) (base) bob@Roberts-Mac-mini rssita % tree
.
├── README.md
├── poetry.lock
├── pyproject.toml
├── setup.cfg
├── src
│   └── rssita
│       ├── __init__.py
│       ├── feeds.py
│       ├── rssita.py
│       └── termcolors.py
└── tests
    ├── __init__.py
    └── test_feeds.py

With this setup I can run rssita.py fine from both the command line (from the activated poetry venv) and from Visual Studio Code (also using the right venv).

On the other end with this setup, pylint fails:

(rssita-py3.10) (base) bob@Roberts-Mac-mini rssita % pylint src
************* Module rssita.rssita
src/rssita/rssita.py:12:0: E0401: Unable to import 'feeds' (import-error)
src/rssita/rssita.py:13:0: E0401: Unable to import 'termcolors' (import-error)

Also in Visual Studio Code, those imports are flagged as:

Unable to import 'feeds' (pylint(import-error) 

As a last issue, pre-commit runs passing all, including pylint, peraphs because I set 8 as a threshold under which it fails and the score is 8.47 (but the errors are there). Here is the relevant .pre-commit-configuration snippet:

-   repo: local
    hooks:
      - id: pylint
        name: pylint
        entry: pylint
        language: python
        types: [python]
        args: [--fail-under=8, --enable="W", --recursive=y, -rn,]

What do I need to do to fix and reconcile running the script from command line and Studio, and pylint from command line and pre-commit?

Robert Alexander
  • 875
  • 9
  • 24
  • 1
    When you run the python code do you run it with `src` as CWD or `rssita`? Also I think calling the main project with the same name as the src/rssita might cause additional confusion in debugging this issue – Ftagliacarne Feb 02 '23 at 10:36
  • Grazie! :) I usually run this from the root of the project when launching this from the shell. Yes the rssita module, being the main source of the project is named like the project itself. Is this a problem/bad practice? – Robert Alexander Feb 02 '23 at 10:46
  • 1
    Not sure if bad practice, just a bit harder to figure out what the issues are, I usually follow this guide for structure (albeit a bit outdated) https://docs.python-guide.org/writing/structure/ – Ftagliacarne Feb 02 '23 at 11:02
  • 1
    In any case, see if this works https://stackoverflow.com/questions/16981921/relative-imports-in-python-3 – Ftagliacarne Feb 02 '23 at 11:14
  • 1
    My project structure is just like yours, only that it will have more than one package in it and I think grouping all packages under src is a recommended practice. I'm reading though your kind suggested link and trying to understand it. Thanks !!! – Robert Alexander Feb 02 '23 at 11:21

0 Answers0