Collection mix-up when cross importing invoke tasks

Open
#979 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
cli

Research direction

Reproduce the behavior using tasks/init.py, module_a.py, and module_b.py from the report, then run inv -l and inv module-a.my-task-b1. Trace how the imported task is registered in the two collections. Done means the imported task is not listed or invokable under module-a while remaining available under module-b, with regression coverage for this example.

Written by the indexing model from the issue text.

Description

Problem statement

Hey ! Just stumbled upon something working with Invoke and I don't know if that's a feature or a bug so I'm filing a small issue !

TL; DR: When having 2 collections module_a and module_b. If I import my_task_b1 from module_b to module_a, then the module_a.my_task_b1 will be a valid invoke task (i.e I can use it and inv -l lists it as well). I don't think it should be the case.

Steps to reproduce

Install invoke (pip install invoke)(I'm using 2.2.0). Here is the folder architecture:

.
└── tasks
    ├── __init__.py
    ├── module_a.py
    └── module_b.py

__init__.py

from invoke import Collection

from . import (
    module_a,
    module_b
)

ns = Collection()

ns.add_collection(module_a)
ns.add_collection(module_b)

module_a.py

from invoke import task
from .module_b import my_task_b1

@task
def my_task_a(_):
    my_task_b1(_)
    print("Hey there !")

module_b.py

from invoke import task

@task
def my_task_b1(_):
    print("Hola !")

@task
def my_task_b2(_):
    print("Hola !")

When I run inv -l I get the following invoke tasks:

Available tasks:

  module-a.my-task-a
  module-a.my-task-b1
  module-b.my-task-b1
  module-b.my-task-b2

Also running it worka:

> inv module-a.my-task-b1
Hola !

Is this on purpose ? I would expect not to have module-a.my-task-b1 !

Behaviour I would have expected

I would have expected inv -l to output

Available tasks:

  module-a.my-task-a
  module-b.my-task-b1
  module-b.my-task-b2
Dominant language
Python
Stars
4.8k
Forks
412
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pyinvoke/invoke

All issues in pyinvoke/invoke

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.