Closed GeoffreyPlitt closed 6 years ago
Nothing that fancy at this point. You can just download the script, put it anywhere in your $PATH and execute it.
Gotcha, thanks!
FYI, this is now in pypi as chess-annotator
.
sweet!
For me there seems to be a problem. If I use pip3 install chess-annotator
it installs a non-working binary in /usr/bin/annotator
.
I use archlinux. I don't know much about how pip works on other distributions (or how it works at all, really). But I have had luck with pip3 install --user
sometimes. Try it?
Btw, when you say "non-working" what does that mean exactly?
I'm using Solus 3
sudo pip3 install chess-annotator
results in the following:
A binary in /usr/bin/annotator
which when called (with or without sudo
) gives the following output:
Traceback (most recent call last):
File "/usr/bin/annotator", line 11, in <module>
load_entry_point('chess-annotator==1.1.0', 'console_scripts', 'annotator')()
File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 565, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
return ep.load()
File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2291, in load
return self.resolve()
File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2297, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named 'annotator'
python3 -m annotator -h
(with or without sudo
):
/usr/bin/python3: No module named annotator
python3 -m chess-annotator
or python-chess-annotator
give similar results.
Using the --user
flag when installing results in the same binary but now in the $HOME/.local/bin
directory where this error log is shown when called
Traceback (most recent call last):
File ".local/bin/annotator", line 11, in <module>
load_entry_point('chess-annotator==1.1.0', 'console_scripts', 'annotator')()
File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 565, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
return ep.load()
File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2291, in load
return self.resolve()
File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2297, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named 'annotator'
python3 -m ...
still does not work in all variations
Cloning the repo works as expected though so I assume something does not work with the packaging.
I've now tested this on OSX as well and it seems to be working fine. I'm not sure what to suggest since I can't reproduce the issue. You may want to raise this with your community support channels for Solus.
Stop! The .tar.gz is incomplete. __main__.py
and eco.json
are both missing from source distribution you created and uploaded to pypi. The reason is some incorrect setup.py
lines.
1.packages=find_packages(exclude=['contrib', 'docs', 'tests']),
this will never find annotator ez a package bacause it's not a package (missing __init__.py
)
package_data={'eco': ['eco/eco.json'],},
same problem. There is no eco package at all to find any data file inside it.Btw. if someone creates a clone from your project it contains an empty eco dir and inside annotator/eco an invalid link pointing to ../../eco/eco.json
Maybe you should remove eco @ 8ef60f8
from your git repo(?)
A few things off the cuff before I look into this more deeply:
eco.json comes from a submodule. If you clone the repo, you have to sync the submodule separately using (I think) git submodule update
since a clone does not do that automatically (for reasons I don't really understand).
Since I have that submodule updated in my local copy, it should be included in the pypi package. The file is there in the filesystem.
I'm no expert on how to make python packages, as this is the first time I've done it. But my understanding is that __init__.py
is not a hard requirement in a package that will never be imported in another app.
I don't understand how what you're saying about the broken-ness of the pypi package can be true at all, since I have installed it via pip3 on a separate system and it seems to work fine. But I'll take a closer look when I get the time.
Solved. Thx!
Correct. But if you don't have __init__.py
you should use py_modules=[]
instead of packages=[]
in setup.py
You can download .tar.gz (what you uploaded to pypi) from https://pypi.python.org/pypi/chess-annotator/1.1.0 Look into it to see what files are missing.
All in all to create a correct source distribution on pypi you have to make a decision.
If you want eco.json to be a package data file (meaning it can be installed OS independent way, just right under your annotator package dir) you have to make annotator a package (adding __init__.py
).
If you don't want annotator to be a Python package (just a pure module) you have to install eco.py in data_files=[]
(instead of package_data=[]
), but then you have to add some code later to find it.
Anyway, you have to do something with your project layout unless your symlinked eco.json data file will be hard to handle with setup.py Maybe removing annotator/eco/eco.json symlink and moving eco git submodule under annotator/ can help.
But if you don't have init.py you should use py_modules=[] instead of packages=[] in setup.py
Alright, I'll look this up. If you are aware of any resources that explain the difference between py_modules
vs packages
in more detail, I encourage you to share them.
You can download .tar.gz (what you uploaded to pypi) from https://pypi.python.org/pypi/chess-annotator/1.1.0 Look into it to see what files are missing.
I did this, but I'm not sure how to understand what I'm seeing or what I should be looking for in this archive.
For what it's worth, I verified this again with pip3 uninstall chess-annotator && pip3 install --user chess-annotator
just now (on OSX) and confirmed that it's working fine.
If you want eco.json to be a package data file (meaning it can be installed OS independent way, just right under your annotator package dir) you have to make annotator a package (adding init.py).
If you don't want annotator to be a Python package (just a pure module) you have to install eco.py in data_files=[] (instead of package_data=[]), but then you have to add some code later to find it.
It's going to take me a bit of time to learn more about this and make a decision. Since the pypi package seems to be working, I don't consider this urgent.
Maybe removing annotator/eco/eco.json symlink and moving eco git submodule under annotator/ can help.
Yeah, I noticed in another issue that it's weird how I set this up, with the submodule in the root dir and a symlink pointing to it. I don't really remember why I did it that way. Looking at it again, the only reason I can guess might have motivated this structure is that the eco submodule contains files that chess-annotator doesn't need, so maybe I didn't want them included in the pypi package. But this isn't really a big deal, and almost assuredly is not worth complicating the packaging/installation process at all. Simplifying that in the way you suggested is probably my first order of business here.
The packaging tutorial is here https://packaging.python.org/tutorials/distributing-packages/
Telling the truth chess-annotator pypi package is not working at all. And it can't work because the __main__.py
(and eco.json also, but that is another issue) is missing from the .tar.gz you uploaded to pypi. If you find it's working on your OSX box this is because Python can find a __main__.py
somewhere else. It can be your git checkout, an old install from source or anything else. The thing is Python can find it somewhere, just you don't know where. I never had any Mac so i can't help where you should look for.
Telling the truth chess-annotator pypi package is not working at all.
In general, you need to be more specific than this when reporting problems. For example, a console log of how you installed it, how you tried to run it, and what errors/stack trace you got in response is a good idea in this situation.
If you find it's working on your OSX box this is because Python can find a
__main__.py
somewhere else.
Maybe you're right but I don't know how to prove that. The point is that unless I find a way to reproduce the issue then I can't troubleshoot or address it at all.
I'v just tried it on my Windows 10 box which never seen nor chess-annotator nor python-chess before. (I use it for PyChess testing only.)
C:\>pip3 install chess-annotator
Collecting chess-annotator
Downloading chess-annotator-1.1.0.tar.gz
Collecting python-chess (from chess-annotator)
Downloading python-chess-0.22.1.tar.gz (135kB)
100% |################################| 143kB 595kB/s
Installing collected packages: python-chess, chess-annotator
Running setup.py install for python-chess ... done
Running setup.py install for chess-annotator ... done
Successfully installed chess-annotator-1.1.0 python-chess-0.22.1
C:\>annotator
Traceback (most recent call last):
File "c:\python34\scripts\annotator-script.py", line 9, in <module>
load_entry_point('chess-annotator==1.1.0', 'console_scripts', 'annotator')()
File "c:\python34\lib\site-packages\pkg_resources\__init__.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "c:\python34\lib\site-packages\pkg_resources\__init__.py", line 2682, in load_entry_point
return ep.load()
File "c:\python34\lib\site-packages\pkg_resources\__init__.py", line 2355, in load
return self.resolve()
File "c:\python34\lib\site-packages\pkg_resources\__init__.py", line 2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named 'annotator'
But this is not a big surprise, because __main__.py
is missing from chess-annotator-1.1.0.tar.gz
Just to be clear this issue is not OS related at all. The only reason is that incorrect setup.py created a source package for pypi which is not containing your source module file.
Per the readme you should invoke it with e.g. python3 -m annotator -h
. But...
Okay, this is useful:
$ cd /tmp
$ python3 -m annotator -h
/usr/local/opt/python3/bin/python3.6: No module named annotator
$ cd /Users/rydelane/src/python-chess-annotator/
$ python3 -m annotator -h
usage: annotator [-h] --file FILE.pgn [--engine ENGINE] [--gametime MINUTES]
[--threads THREADS] [--verbose]
takes chess games in a PGN file and prints annotations to standard output
optional arguments:
-h, --help show this help message and exit
--file FILE.pgn, -f FILE.pgn
input PGN file
--engine ENGINE, -e ENGINE
analysis engine (default: stockfish)
--gametime MINUTES, -g MINUTES
how long to spend on each game (default: 1)
--threads THREADS, -t THREADS
threads for use by the engine (default: 1)
--verbose, -v increase verbosity
$
I just repeat myself, but again, look into the .tar.gz anyone can download from pypi please! Can you find your __main__.py
, the one and only source file inside that .tar.gz? Not. Then how on earth you think it will be installed by pip?
Then how on earth you think it will be installed by pip?
Because I know next to nothing about how pip or pypi work at all. For all I know/knew, that package is something akin to a PKGBUILD that contains information about where the required resources can be obtained elsewhere. And since (until now) I couldn't reproduce the problem, I had no way to even begin to approach it.
Luckily, I understand now that it appeared to be working only because my cwd was in the cloned repository and so python3 -m annotator
was able to find what it needed in the 'annotator' directory present in my cwd. If I attempt to invoke it from anywhere else in the filesystem, I get an error.
Therefore I agree with you now that the pypi package is broken and I need to fix it, and I can possibly fix it now that I know how to reproduce the problem. Thanks for reporting this and working with me on it. I'll try to make time ASAP to get a working package uploaded.
No problem.
The basic working of pip and pypi is simple. In simplest case you use python setup.py sdist
to create a so called source distribution (.tar.gz). Than you can give this archive to anyone else end he will be able to install your stuff by unpackaging it and running python setup.py install
on hes box. Now if you upload it to pypi instead, anyone can use pip to do the hard work (download, unpackage and run python setup.py install
) for him. Easy :)
Alright. I got rid of the eco.json
symlink by moving the submodule into the module dir. I then created an empty __init__.py
, and it looks like both the __init__.py
and __main__.py
are now included in the dist archive. I then confirmed that I can call the app with either $ annotator
or $ python3 -m annotator
from any path in the filesystem. However, eco.json
is still not included. Once I have that figured out I'll be able to upload a new, fixed package to pypi.
@gbtami After efcb0dd , installing the package locally is now working for me with eco.json
and all. Please verify on your end and I will update pypi.
@rpdelaney python3 setup.py sdist
creates correct source distribution package now. Thx!
Just one note. You can include eco.json
without using MANIFEST.in
and include_package_data=True
in setup.py
but:
package_data = {"annotator": ["eco/eco.json"], }
I tried that but it did not work. I don't know why. At this point I'm just happy to have a working solution. I'll be updating pypi shortly and then closing this issue.
Maybe you just mistyped something. I tried it also, and it worked :) But I agree with you, if the MANIFEST.in with include_package_data=True is working OK (and it is), no need to change it.
Confirmed pypi distribution is working in version 1.1.1. Thanks again
I'm interested in running this as a user, not hacking around on it, so I figured it would be available in python repos.
I tried:
and got "No matching distribution found for chess-annotator".
Is there a way to install this with pip?