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

Add feature locust launcher useful for run/debug on IDEs like PyCharm #1656

Closed
wants to merge 1 commit into from

Conversation

aek
Copy link
Contributor

@aek aek commented Dec 10, 2020

Add feature locust launcher useful for run/debug on IDEs like PyCharm
Borrowed from the virtualenv installed package used for execute locust in the command-line

This will help to setup locust in an IDE like the following image
image

Using this script to run locust in the IDE will fix import errors related to the usage of others scripts like main.py, __init__.py and __main__.py

It's only an utility file to easy the develop of locust. An entry in the documentation will be needed if this PR become merged. I could include it as part of this PR.
This PR is related to the issue #613

Borrowed from the virtualenv installed package used for execute locust in the commandline
@heyman
Copy link
Member

heyman commented Dec 11, 2020

How about the suggestion in this comment: #613 (comment) ?

Doesn't that work? If so, I think the fix should be to just write proper documentation for that. I'm not keen on adding a locust.py file to the root.

@aek
Copy link
Contributor Author

aek commented Dec 11, 2020

@heyman I have used that way until I needed to start to develop and debug locust itself. It will not use your locust project files, it will be using the installed locust package instead so any modification to locust itself wouldn't be effective to be run without an issue of the command python setup.py install needing to packaging and reinstall locust for every modification in order to be able to see your changes

@heyman
Copy link
Member

heyman commented Dec 11, 2020

What if you install locust using pip install -e . (https://pip.pypa.io/en/stable/reference/pip_install/#install-editable)?

@aek
Copy link
Contributor Author

aek commented Dec 11, 2020

I guess that could be an option but for some users but in my case I will prefer to have a way to directly run/debug locust without pip install it.
Not need to merge it then but I found myself asking why locust doesn't have this launcher script that it's generated after pip install or python setup.py install?

@heyman
Copy link
Member

heyman commented Dec 11, 2020

If you don't want to use pip you could use python setup.py develop

@aek
Copy link
Contributor Author

aek commented Dec 11, 2020

It's the same, and don't answer my previous question why locust doesn't have this launcher script that it's generated after pip install or python setup.py install/develop?. I'm curious about it. Maybe to have it generated as a command-line program to be executed? Just because of that or there is anything else?

@heyman
Copy link
Member

heyman commented Dec 11, 2020

Sorry, I'm not sure I understand your question. Do you know of other python libraries that expose console script entrypoints that does this?

I guess that could be an option but for some users but in my case I will prefer to have a way to directly run/debug locust without pip install it.

If you use python setup.py develop doesn't that provide you a way of directly running locust without pip installing it?

@aek
Copy link
Contributor Author

aek commented Dec 11, 2020

Yes, I'm aware that others do this. It's ok. I was asking about why locust doesn't provide the launcher script physically and have the console script entrypoint to call/use it.
Nevermind. I confirm that the use of pip install -e path/to/locust/source works. I contains an implicit call to python setup.py develop so both ways are valid.
I close the PR then

@aek aek closed this Dec 11, 2020
@heyman
Copy link
Member

heyman commented Dec 11, 2020

I think we could maybe add an entrypoint file called __main__.py in the locust/ package directory (not directly in the git root). That seems to be the way both Flask and Django does it, so it might at least be some informal standard. I'd be willing to merge that if you update the PR (ideally we would also add a test to test.test_main.LocustProcessIntegrationTest as well).

@aek
Copy link
Contributor Author

aek commented Dec 11, 2020

The __main__.py file already exist and cannot be used directly because there is no defined parent package.
The exact error is:

ImportError: attempted relative import with no known parent package

That's the main reason to have an script importing locust package at the root level having the locust package imported and available to all the scripts that issue imports like:

from .main import main
from . import log
from .argument_parser import parse_locustfile_option, parse_options
from .env import Environment
from .log import setup_logging, greenlet_exception_logger
from . import stats
from .stats import print_error_report, print_percentile_stats, print_stats, stats_printer, stats_history
from .stats import StatsCSV, StatsCSVFileWriter
from .user import User
from .user.inspectuser import get_task_ratio_dict, print_task_ratio
from .util.timespan import parse_timespan
from .exception import AuthCredentialsError
from .shape import LoadTestShape
from .input_events import input_listener
from .html import get_html_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

Successfully merging this pull request may close these issues.

2 participants