-
Notifications
You must be signed in to change notification settings - Fork 23
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 entrypoints #274
add entrypoints #274
Conversation
Looks ok codewise. I'll test personally later. Can you confirm that the following is true?:
@JS3xton do you have any comments? |
|
@castillohair All confirmed, except windows / osx part. |
@JS3xton "main" is a pretty standard name for a function that parses command-line arguments and runs the actual main function in the program. In both Python and C. I don't feel uncomfortable about having an argument parsing function and naming it main. Compared to
I prefer
but I also think we can always get away with just main(), because whether we use |
No, I don't. I'd rather keep the function and the
Not that I know, although someone might be calling this function from python in their own scripts. Backwards compatibility is another reason to not combine
Edit: Apparently @JS3xton was complaining about the function name choice. I have no strong feelings one way or another. Both seem like logical choices to me.
Edit: apparently a function is necessary for the entrypoint.
Agree. Assuming that we keep the function, we will need a docstring before accepting the request. @renxida , please check https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt for the docstring format that we use, although for this particular case it might be enough to just look at the other docstrings in our code. I am ok with the current docstring of
Although def main (args = None)
if args is None:
args=copy.deepcopy(sys.argv)
.... |
Thanks for the helpful comments. I'm on it with the docstring. Importing Ultimately though, it's your call. |
Docstring added. argv moved to function body. |
I don't think the Please rename
|
On it.
…On Thu, Oct 5, 2017 at 7:22 PM John T. Sexton ***@***.***> wrote:
I don't think the deepcopy of sys.argv is necessary, but I also don't
think it hurts. I at least want a sentinel value used in the function
definition, though, so that the function binds sys.argv when the function
is called, not when the function is defined.
Please rename main to run_command_line.
- I'm familiar with main()'s use in other programming languages; much
of my initial training was in C. I haven't seen main() used in Python
much, and, more relevantly, Python and the console_scripts Entry Point
mechanism afford us the opportunity to have a more descriptive function
name, which I think is important. main is painfully vague (outside of
its historical use in other languages, as discussed), whereas
run_command_line appropriately alludes to the existing run function
and concisely communicates the relevant information that it's
differentiated from run for reasons related to the command line.
- @castillohair <https://github.com/castillohair> and I discussed this
in person, and he established something that I agreed with upon reflection:
the behavior of python -m FlowCal and calling flowcal from the
terminal should be the same, and that behavior should be to run FlowCal
from the command line. Given that their behavior should be the same (even
though their implementation mechanisms are different), it makes sense to
call the same function to implement both behaviors. In my opinion, that
behavior is much more clearly described via run_command_line, though,
than main.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#274 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AJ4gSABWjIvIANqqPBEkeKvlMMFf9cD6ks5spWTKgaJpZM4PuGmw>
.
|
…cripts to avoid "pip uninstall" problems
Done. |
Currently fails on Windows 10.
In
Same if I try to run |
|
||
Notes | ||
---------- | ||
Use main(argv = ['arguments', 'you', 'want', 'to', 'test']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not called "main" anymore.
@@ -1521,11 +1545,14 @@ def run(input_path=None, | |||
"--histogram-sheet", | |||
action="store_true", | |||
help="generate sheet in output Excel file specifying histogram bins") | |||
args = parser.parse_args() | |||
args = parser.parse_args(args=argv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fails on Windows 10, both when using flowcal
and python -m FlowCal.excel_ui
. Replacing this line with the previous version, args = parser.parse_args()
, makes everything work.
I think the reason is that the list of arguments, as given by sys.argv
, includes the path of the script as the first element on Windows. However, parser.parse_args
doesn't expect this. Therefore, it fails.
An immediate solution is to replace this line with the old version, and eliminate the option to specify argument argv
to the function run_command_line
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, it appears that argparse
version 1.1 (the default argparse
module included in Python 2.7 [source] and Python 3.6 [source]) strips out the first argument here [source]:
def parse_known_args(self, args=None, namespace=None):
if args is None:
# args default to the system args
args = _sys.argv[1:]
else:
# make sure that args are mutable
args = list(args)
Thus, I think we're justified in doing the same thing. Might be nice to explicitly state all of this in a brief comment in the code, though.
@@ -34,6 +34,12 @@ def find_version(file_path): | |||
setup( | |||
name='FlowCal', | |||
|
|||
entry_points = { | |||
'console_scripts': [ | |||
'flowcal=FlowCal.excel_ui:run_command_line' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was the entrypoint FlowCal
eliminated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@renxida raised this issue here: pypa/pip#4771
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In light of @renxida's post and possible uninstall problems, I think we should just go with lowercase flowcal
.
Separately, I think it's a good idea to incorporate verification of a clean uninstall in the build process (I hate it when a package sloppily fails to uninstall correctly and pollutes my system).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #281 for a discussion on installation.
Assuming that I install the package with pip install .
, uninstallation proceeds cleanly, so I'm unable to reproduce this issue.
On FlowCal's folder:
$ sudo pip install .
Processing /home/[redacted]/FlowCal
Requirement already satisfied: packaging>=16.8 in /usr/local/lib/python2.7/dist-packages (from FlowCal==1.1.4)
Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python2.7/dist-packages/six-1.11.0-py2.7.egg (from FlowCal==1.1.4)
Requirement already satisfied: numpy>=1.8.2 in /usr/local/lib/python2.7/dist-packages (from FlowCal==1.1.4)
Requirement already satisfied: scipy>=0.14.0 in /usr/local/lib/python2.7/dist-packages (from FlowCal==1.1.4)
Requirement already satisfied: matplotlib>=1.3.1 in /usr/local/lib/python2.7/dist-packages (from FlowCal==1.1.4)
Requirement already satisfied: palettable>=2.1.1 in /usr/local/lib/python2.7/dist-packages/palettable-3.0.0-py2.7.egg (from FlowCal==1.1.4)
Requirement already satisfied: scikit-learn>=0.16.0 in /usr/local/lib/python2.7/dist-packages (from FlowCal==1.1.4)
Requirement already satisfied: pandas>=0.16.1 in /usr/local/lib/python2.7/dist-packages (from FlowCal==1.1.4)
Requirement already satisfied: xlrd>=0.9.2 in /usr/local/lib/python2.7/dist-packages/xlrd-1.0.0-py2.7.egg (from FlowCal==1.1.4)
Requirement already satisfied: XlsxWriter>=0.5.2 in /usr/local/lib/python2.7/dist-packages/XlsxWriter-0.9.6-py2.7.egg (from FlowCal==1.1.4)
Requirement already satisfied: pyparsing in /usr/local/lib/python2.7/dist-packages (from packaging>=16.8->FlowCal==1.1.4)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python2.7/dist-packages (from matplotlib>=1.3.1->FlowCal==1.1.4)
Requirement already satisfied: python-dateutil in /usr/local/lib/python2.7/dist-packages (from matplotlib>=1.3.1->FlowCal==1.1.4)
Requirement already satisfied: functools32 in /usr/local/lib/python2.7/dist-packages (from matplotlib>=1.3.1->FlowCal==1.1.4)
Requirement already satisfied: pytz in /usr/local/lib/python2.7/dist-packages (from matplotlib>=1.3.1->FlowCal==1.1.4)
Requirement already satisfied: subprocess32 in /usr/local/lib/python2.7/dist-packages (from matplotlib>=1.3.1->FlowCal==1.1.4)
Installing collected packages: FlowCal
Running setup.py install for FlowCal ... done
Successfully installed FlowCal-1.1.4
Somewhere else (not in the FlowCal folder):
$ flowcal
$ FlowCal
(Both commands work and open the "open file" dialog.
Same location:
$ sudo pip uninstall FlowCal
Uninstalling FlowCal-1.1.4:
/usr/local/bin/FlowCal
/usr/local/bin/flowcal
/usr/local/lib/python2.7/dist-packages/FlowCal-1.1.4-py2.7.egg-info
/usr/local/lib/python2.7/dist-packages/FlowCal/__init__.py
/usr/local/lib/python2.7/dist-packages/FlowCal/__init__.pyc
/usr/local/lib/python2.7/dist-packages/FlowCal/excel_ui.py
/usr/local/lib/python2.7/dist-packages/FlowCal/excel_ui.pyc
/usr/local/lib/python2.7/dist-packages/FlowCal/gate.py
/usr/local/lib/python2.7/dist-packages/FlowCal/gate.pyc
/usr/local/lib/python2.7/dist-packages/FlowCal/io.py
/usr/local/lib/python2.7/dist-packages/FlowCal/io.pyc
/usr/local/lib/python2.7/dist-packages/FlowCal/mef.py
/usr/local/lib/python2.7/dist-packages/FlowCal/mef.pyc
/usr/local/lib/python2.7/dist-packages/FlowCal/plot.py
/usr/local/lib/python2.7/dist-packages/FlowCal/plot.pyc
/usr/local/lib/python2.7/dist-packages/FlowCal/stats.py
/usr/local/lib/python2.7/dist-packages/FlowCal/stats.pyc
/usr/local/lib/python2.7/dist-packages/FlowCal/transform.py
/usr/local/lib/python2.7/dist-packages/FlowCal/transform.pyc
Proceed (y/n)? y
Successfully uninstalled FlowCal-1.1.4
$ flowcal
bash: /usr/local/bin/flowcal: No such file or directory
$ FlowCal
bash: /usr/local/bin/FlowCal: No such file or directory
After starting another bash session:
$ flowcal
flowcal: command not found
$ FlowCal
FlowCal: command not found
So it seems that uninstalling proceeds as expected.
(All of this was performed with pip 9.0.1 in Linux Mint 18).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I successfully reproduced the problem in python 3.6. Again, after installing with sudo pip3.6 install .
and confirming that everything works, I get the following:
$ sudo pip3.6 uninstall FlowCal
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/local/lib/python3.6/dist-packages/pip/commands/uninstall.py", line 76, in run
requirement_set.uninstall(auto_confirm=options.yes)
File "/usr/local/lib/python3.6/dist-packages/pip/req/req_set.py", line 346, in uninstall
req.uninstall(auto_confirm=auto_confirm)
File "/usr/local/lib/python3.6/dist-packages/pip/req/req_install.py", line 734, in uninstall
FakeFile(dist.get_metadata_lines('entry_points.txt'))
File "/usr/lib/python3.6/configparser.py", line 763, in readfp
self.read_file(fp, source=filename)
File "/usr/lib/python3.6/configparser.py", line 718, in read_file
self._read(f, source)
File "/usr/lib/python3.6/configparser.py", line 1092, in _read
fpname, lineno)
configparser.DuplicateOptionError: While reading from '<???>' [line 3]: option 'flowcal' in section 'console_scripts' already exists
This doesn't happen if I only have the entrypoint flowcal
.
It is interesting that this error only happens in python 3.6 (and possibly other versions of python 3). I will remove the entrypoint FlowCal
as discussed.
http://amir.rachum.com/blog/2017/07/28/python-entry-points/ | ||
|
||
""" | ||
if argv == None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be is None
. Check https://stackoverflow.com/questions/3257919/what-is-the-difference-between-is-none-and-none
I made a local branch from the changes in this PR and submitted a new PR to accelerate code iteration. Please continue discussion in #280. |
flowcal
andFlowCal
to launchexcel_ui
insetup.py
FlowCal/excel_ui.py
to accomodate those changesTested in fresh anaconda python3 and python2 environments on Ubuntu Linux 16.10.