Closed pawamoy closed 6 years ago
Another solution is to set up your files like the following:
__main__.py
# -*- coding: utf-8 -*-
"""
Entrypoint module, in case you use `python -mdependenpy`.
Why does this file exist, and why __main__? For more info, read:
- https://www.python.org/dev/peps/pep-0338/
- https://docs.python.org/2/using/cmdline.html#cmdoption-m
- https://docs.python.org/3/using/cmdline.html#cmdoption-m
"""
import sys
from dependenpy.cli import main
if __name__ == "__main__":
main(sys.argv[1:])
cli.py
# -*- coding: utf-8 -*-
"""
Module that contains the command line application.
Why does this file exist, and why not put this in __main__?
You might be tempted to import things from __main__ later,
but that will cause problems: the code will get executed twice:
- When you run `python -mretox` python will execute
``__main__.py`` as a script. That means there won't be any
``retox.__main__`` in ``sys.modules``.
- When you import __main__ it will get executed again (as a module) because
there's no ``retox.__main__`` in ``sys.modules``.
Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
"""
def main(args=None):
...
setup.py
...
entry_points={
'console_scripts': [
'retox = retox.cli:main',
],
}
...
Thanks, Args gets filled by argparse. It’s a little bit more complex in this application as I’ve developed it around tox’s Plugin system. You’ll notice there are 2 hooks for the watch parameter and also the concurrency setting. Will try and repro this on a clean environment. Are you installing 1.2? I made changes to the main methods in there
retox==1.2.0
$ retox
Traceback (most recent call last):
File "/usr/local/bin/retox", line 11, in
@Pawamoy and @kmmbvnr thanks. Fixing now.
Validated and fixed in 1.2.1.
@Pawamoy @kmmbvnr apologies for the mess-up. I really need to figure out a way to create integration tests for this now.
(testbin-2) anthonyshaw ~/repo/test $ pip install retox
Collecting retox
Downloading retox-1.2.1-py2-none-any.whl
Collecting eventlet==0.21.0 (from retox)
Using cached eventlet-0.21.0-py2.py3-none-any.whl
Collecting asciimatics==1.9.0 (from retox)
Using cached asciimatics-1.9.0-py2.py3-none-any.whl
Collecting tox==2.9.1 (from retox)
Using cached tox-2.9.1-py2.py3-none-any.whl
Collecting enum-compat (from eventlet==0.21.0->retox)
Collecting greenlet>=0.3 (from eventlet==0.21.0->retox)
Collecting pyfiglet>=0.7.2 (from asciimatics==1.9.0->retox)
Collecting Pillow>=2.7.0 (from asciimatics==1.9.0->retox)
Using cached Pillow-4.3.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting future (from asciimatics==1.9.0->retox)
Collecting wcwidth (from asciimatics==1.9.0->retox)
Using cached wcwidth-0.1.7-py2.py3-none-any.whl
Collecting virtualenv>=1.11.2; python_version != "3.2" (from tox==2.9.1->retox)
Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Collecting pluggy<1.0,>=0.3.0 (from tox==2.9.1->retox)
Collecting six (from tox==2.9.1->retox)
Using cached six-1.11.0-py2.py3-none-any.whl
Collecting py>=1.4.17 (from tox==2.9.1->retox)
Using cached py-1.5.2-py2.py3-none-any.whl
Collecting enum34 (from enum-compat->eventlet==0.21.0->retox)
Using cached enum34-1.1.6-py2-none-any.whl
Collecting olefile (from Pillow>=2.7.0->asciimatics==1.9.0->retox)
Installing collected packages: enum34, enum-compat, greenlet, eventlet, pyfiglet, olefile, Pillow, future, wcwidth, asciimatics, virtualenv, pluggy, six, py, tox, retox
Successfully installed Pillow-4.3.0 asciimatics-1.9.0 enum-compat-0.0.2 enum34-1.1.6 eventlet-0.21.0 future-0.16.0 greenlet-0.4.12 olefile-0.44 pluggy-0.6.0 py-1.5.2 pyfiglet-0.7.5 retox-1.2.1 six-1.11.0 tox-2.9.1 virtualenv-15.1.0 wcwidth-0.1.7
(testbin-2) anthonyshaw ~/repo/test $ retox --help
usage: retox [-w WATCH] [-n NUMPROC] [--version] [-h] [--help-ini] [-v]
[--showconfig] [-l] [-a] [-c CONFIGFILE] [-e envlist] [--notest]
[--sdistonly] [--installpkg PATH] [--develop] [-i URL] [--pre]
[-r] [--result-json PATH] [--hashseed SEED] [--force-dep REQ]
[--sitepackages] [--alwayscopy] [--skip-missing-interpreters]
[--workdir PATH]
[args [args ...]]
tox options
positional arguments:
args additional arguments available to command positional
substitution
optional arguments:
-w WATCH, --watch WATCH
Watch a folder for changes and rebuild when detected
file changes/new files
-n NUMPROC, --num NUMPROC
set the number of concurrent processes (default 4).
--version report version information to stdout.
-h, --help show help about options
--help-ini, --hi show help about ini-names
-v increase verbosity of reporting output. -vv mode turns
off output redirection for package installation
--showconfig show configuration information for all environments.
-l, --listenvs show list of test environments (with description if
verbose)
-a, --listenvs-all show list of all defined environments(with description
if verbose)
-c CONFIGFILE config file name or directory with 'tox.ini' file.
-e envlist work against specified environments (ALL selects all).
--notest skip invoking test commands.
--sdistonly only perform the sdist packaging activity.
--installpkg PATH use specified package for installation into venv,
instead of creating an sdist.
--develop install package in the venv using 'setup.py develop'
via 'pip -e .'
-i URL, --index-url URL
set indexserver url (if URL is of form name=url set
the url for the 'name' indexserver, specifically)
--pre install pre-releases and development versions of
dependencies. This will pass the --pre option to
install_command (pip by default).
-r, --recreate force recreation of virtual environments
--result-json PATH write a json file with detailed information about all
commands and results involved.
--hashseed SEED set PYTHONHASHSEED to SEED before running commands.
Defaults to a random integer in the range [1,
4294967295] ([1, 1024] on Windows). Passing 'noset'
suppresses this behavior.
--force-dep REQ Forces a certain version of one of the dependencies
when configuring the virtual environment. REQ Examples
'pytest<2.7' or 'django>=1.6'.
--sitepackages override sitepackages setting to True in all envs
--alwayscopy override alwayscopy setting to True in all envs
--skip-missing-interpreters
don't fail tests for missing interpreters
--workdir PATH tox working directory
Environment variables
TOXENV: comma separated list of environments (overridable by '-e')
TOX_TESTENV_PASSENV: space-separated list of extra environment variables to be passed into test command environments
When installing through pip, I get this executable file:
As you can see, it runs
main()
without parameters, which results in the following error;