0

I have the following folder structure:

- etl
    - raw
        - raw.py
        - etl (symlink)
            - raw
                - raw.py
                - etl (symlink)
                    ... (infinite paths)
- config.py

I've created a symlink from the etl folder. I'm using symlink so that I can have absolute imports from raw.py into config.py. For example, in raw.py I have the following import: from etl.config import MY_CONSTANT. This absolute import is made possible due to the symlink.

However, when I try to run Black, as in poetry run black ${INCLUDE_FILES} and INCLUDE_FILES = ./etl I run into a infinite loop, as Black tryies to enter in the symlinks and keep going forever. This infinite loop doesn't happen with, for example, Pylint and Flake8.

I could try running Black on every single specific .py file. However, as I have many files, that'd be time consuming.

Is there a way to make Black ignore the symlinks? Or is there another workaround for my situation?

Matheus Schaly
  • 163
  • 4
  • 21
  • 2
    How about using one of the options to make absolute imports possible *without* creating infinite loops? Much easier, much more Pythonic, much more portable, etc. etc. – MattDMo Dec 18 '22 at 21:38
  • That'd great. I'm using symlinks just because I can't figure out how to do these absolute imports without them. My current path is `/home/hsmatheus/git/cryptocurrency-monitoring/etl/raw` and my current relative path is `cryptocurrency-monitoring/etl/raw`. These paths have a `-` in them, which is an invalid syntax for Python imports. – Matheus Schaly Dec 18 '22 at 21:50
  • 1
    Put empty `__init__.py` files in `etl` and `raw`. This should allow you to use `etl` as a package from the `cryptocurrency-monitoring` directory. Alternatively, you can always use relative imports. – MattDMo Dec 18 '22 at 22:06
  • I ended up renaming my GitHub repo to cryptocurrency_monitor. I removed the symlinks. I also added `__init__.py` files, as it seems to be good practice overall. Then I started using absolute paths as, for example, in `cryptocurrency_monitoring/etl/raw/run.py`: `from cryptocurrency_monitoring.etl.raw.coingecko import run_raw_btc`. Then I run `poetry shell` in `~/git/cryptocurrency_monitoring$`. Then finally I run my code like this: `~/git$ python3 -m cryptocurrency_monitoring.etl.raw.run`. That'll do for now, thanks for the insights @MattDMo – Matheus Schaly Dec 18 '22 at 22:58
  • Glad you got things sorted out. Cheers! – MattDMo Dec 19 '22 at 16:36

0 Answers0