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

Adding directory to PymodeRope #1159

Open
claudio-ebel opened this issue Sep 6, 2022 · 0 comments
Open

Adding directory to PymodeRope #1159

claudio-ebel opened this issue Sep 6, 2022 · 0 comments

Comments

@claudio-ebel
Copy link

claudio-ebel commented Sep 6, 2022

Using the python project scheme suggested by the pytest documentation, pymode does not include the tests/ directory into its ropeproject when the “include method” of the src/ directory is done via an editable install (pip install -e .).

How do I add an additional source directory to PymodeRope, namely the tests/ directory?

Minimal working example

First create a venv virtual environment as well as a temporary directory. The abbreviation pmt stands for “pymode test”.

$ mkdir -p /tmp/pmt/{.venv,src/pmt,tests}
$ cd /tmp/pmt
$ python -m venv /tmp/pmt/.venv/pmt
$ source /tmp/pmt/.venv/pmt/bin/activate
(pmt) $ python -m pip install -U pip
(pmt) $ python -m pip install build pytest
(pmt) $ touch pyproject.toml src/pmt/__init__.py

Create the three source files with an editor of your choice, namely

  • # ––– file /tmp/pmt/src/pmt/spam.py
    def spamfunc() -> int:
        return 1
  • # ––– file /tmp/pmt/src/pmt/bacon.py
    from .spam import spamfunc
    
    
    def baconfunc() -> None:
        return 1 + spamfunc()
  • # ––– file /tmp/pmt/tests/test_pmt.py
    from pmt.bacon import baconfunc
    from pmt.spam import spamfunc
    
    
    def test_baconfunc() -> None:
        assert 2 == baconfunc()
    
    
    def test_spamfunc() -> None:
        assert 1 == spamfunc()

The project directory will look like this:

.
├── pyproject.toml
├── src
│   └── pmt
│       ├── bacon.py
│       ├── __init__.py
│       └── spam.py
└── tests
    └── test_pmt.py

As suggested by pytest, install the editable version of the package and invoke pytest:

(pmt) $ python -m pip install -e .
(pmt) $ python -m pytest
================================ test session starts =================================
platform linux -- Python 3.10.6, pytest-7.1.3, pluggy-1.0.0
rootdir: /tmp/pmt
collected 2 items                                                                    

tests/test_pmt.py ..                                                           [100%]

================================= 2 passed in 0.01s ==================================

To finally reproduce the behaviour:

  • open the source file with vim /tmp/pmt/src/pmt/spam.py
  • move the cursor to spamfunc
  • start function renaming by hitting <C-c>rr
  • insert a different name, for instance hamfunc and press <Enter>
  • perform the renaming by inserting 1<Enter>

After that, the renaming was successfully done in /tmp/pmt/src/pmt/spam.py and /tmp/pmt/src/pmt/bacon.py but not in tmp/pmt/tests/test_pmt.py (as I expect).

What I have tried

I tried to add manually the tests directory to the .ropeproject/config.py file

def set_prefs(prefs):
    # … more code of the default config.py file …

    # Custom source folders:  By default rope searches the project
    # for finding source folders (folders that should be searched
    # for finding modules).  You can add paths to that list.  Note
    # that rope guesses project source folders correctly most of the
    # time; use this if you have any problems.
    # The folders should be relative to project root and use '/' for
    # separating folders regardless of the platform rope is running on.
    # 'src/my_source_folder' for instance.
    prefs.add('source_folders', 'tests')

    # … more code of the default config.py file …

with no success.

When I change the import policy by

  • uninstalling the module again with (pmt) $ python -m pip uninstall pmt
  • change the imports of tmp/pmt/tests/test_pmt.py to
    from src.pmt.bacon import baconfunc
    from src.pmt.spam import spamfunc

then the renaming as suggested above does work, but that project structure is not as I or the pytest guys, respectively, want it to be.

Used versions

(pmt) $ python --version
Python 3.10.6
(pmt) $ python -m pip freeze | grep 'build\|pytest'
build==0.8.0
pytest==7.1.3

Pymode version: commit 85d2cd1a196ac1def79d4599b5be69395ed5b603 (HEAD → develop)

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

1 participant