pytivo ported to python3

Discussion in 'Developers Corner' started by itsayellow, Jan 15, 2020.

  1. itsayellow

    itsayellow New Member

    7
    4
    Jan 14, 2020
    Over thanksgiving break I decided to port pytivo (wmcbrine's version) completely to python3. In the process I also tried to clean up some of the code.

    If you're interested, here it is:
    itsayellow/pytivo

    It is installable as a python package via pip or pipx, which makes installation a little nicer and a little more portable.

    For some help text, execute:
    pytivo --help

    I may not be super available for supporting end users, but the code is pretty solid and I've been using it for some months now without problem.

    The main difference from the original pytivo is probably where it searches for pyTivo.conf. Here are the new locations:
    • /etc/pyTivo.conf
    • In your home directory: .config/pytivo/pyTivo.conf
    • In the directory you started pytivo from: pyTivo.conf
    • You can also specify the full path to your desired pyTivo.conf using the -c option.
    For developers, it may be of note that the entire code is also statically typed with python type hints and can be verified using mypy.

    Since python 2 is EOL this year, hopefully this is also useful going forward for other developers.
     
    mlippert, Allanon and davidblackledge like this.
  2. Allanon

    Allanon Active Member

    864
    130
    Nov 2, 2005
    I can finally remove python 2 from my computer, this was the only thing holding me back!
     
  3. Allanon

    Allanon Active Member

    864
    130
    Nov 2, 2005
    Am I missing something, where is the pyTivo.py file?
     
  4. itsayellow

    itsayellow New Member

    7
    4
    Jan 14, 2020
    That's another change from the old pytivo I guess.

    The best way of running this is to install this using pipx. Once you do that, you should have a command on your path called 'pytivo' executable from anywhere.

    Installation example if you downloaded pytivo to directory <Some_Directory>/pytivo (replace <Some_Directory> with whatever directory is the parent of your pytivo directory.)
    1. python -m pip install --user pipx
    2. pipx install <Some_Directory>/pytivo
    pipx will install pytivo (or pytivo.exe on Windows) in your home directory to: .local/bin/ . If this is in your PATH, then pytivo will be executable anywhere. You can also run it explicitly from that path.


    The more technical answer is, there are a number of python packages that need to be installed to make this new pytivo work. The installation method above handles this automatically. If you know what you're doing and install all the python packages needed yourself, then to run pytivo you can also execute:
    python src/pytivo/main.py​
     
  5. itsayellow

    itsayellow New Member

    7
    4
    Jan 14, 2020
    I just updated the install directions on the main page for my fork of pytivo:
    itsayellow/pytivo

    I tried to find the right balance of enough information but not too much! But that balance is a little tricky. Hopefully those instructions are complete enough without being overwhelming.
     
  6. Allanon

    Allanon Active Member

    864
    130
    Nov 2, 2005
    Got it working, thanks.
     
    itsayellow likes this.
  7. eherberg

    eherberg Active Member

    360
    201
    Feb 16, 2011
    Forum user @mlippert also did this a couple of years ago, I think (ported to python 3). Just an FYI in case the 2 of you want to compare notes. :)
     
    mlippert and itsayellow like this.
  8. itsayellow

    itsayellow New Member

    7
    4
    Jan 14, 2020
    Thanks for the note, that's good to know! I looked, but I couldn't find any python3 pytivo ports on my own...might have saved me some work :D
     
  9. mlippert

    mlippert Active Member

    289
    58
    Apr 2, 2010
    Massachusetts
    It sounds like we focused on different things for our ports, and there are things you've done that I'd definitely want, but I don't have the bandwidth now to look at merging. I've never even heard of pipx.
    You can find my port at mlippert/pytivo

    [edit] for instance I added some config functionality to allow defining how you want shows and movie files named, and I added a .syncerr.yaml file to show where the errors occurred when doing ts downloads, based on @Dan203's changes to wmcbrine's base code.
     
    itsayellow likes this.
  10. itsayellow

    itsayellow New Member

    7
    4
    Jan 14, 2020
    @mlippert , I also don't have a ton of bandwidth, but was happy to see another python3 port.

    I will say I was pleasantly surprised how much benefit using type hints gave me. Not only did it make porting much faster in the end, but I believe I may have found some bugs that had been hiding in pytivo for a while. It certainly eased tracking down all the str/bytes bugs that popped up in the transition from python2 to python3.
     
    mlippert likes this.
  11. mlippert

    mlippert Active Member

    289
    58
    Apr 2, 2010
    Massachusetts
    @itsayellow Adding type hints is something I definitely wanted to do, but I didn't know nearly enough when I started about how to format them and actually lint them, so I left that for later. I did restructure many parts of the code, and I've been using it ever since I did this. I run it on linux though, and I didn't go the extra step to make it easier for others to install that it sounds like you did.
    I know it runs on linux (if you get the required pre-reqs installed, and that's not hard, I use a virtual env and the requirements.txt), and I think I got it running on Windows a long time ago. I have no idea how/if it runs on a Mac.

    If I get some time in the future I'll check out your port and if that happens I'm sure I'll have questions so you may hear from me!
     
    itsayellow likes this.
  12. Dan203

    Dan203 Super Moderator Staff Member TCF Club

    49,044
    5,116
    Apr 17, 2000
    Nevada
    So is there any real advantage to using 3 vs 2? I'm not really a python developer. I faked my way through the additions I made to my fork by a lot of goggling and trial and error. Would there be any advantages to using 3 in my pyTivo Desktop app?
     
  13. itsayellow

    itsayellow New Member

    7
    4
    Jan 14, 2020
    Well, I think the main thing is that Python 2 will not be supported anymore (EOL). "...January 1, 2020, will be the day that we sunset Python 2. That means that we will not improve it anymore after that day, even if someone finds a security problem in it."
    Sunsetting Python 2

    Going forward, there won't be many libraries that still support python 2.

    Other than that, I find python 3 much more pleasant to program in, it has a lot of nice features and syntax than python 2. Python 2.7 was released in 2010, a lot of nice stuff has happened since then in Python 3.
     
  14. mlippert

    mlippert Active Member

    289
    58
    Apr 2, 2010
    Massachusetts
    So basically what @itsayellow said.

    If you really were going to continue supporting/developing your pytivo desktop, then yes you probably should use python 3 and I would suggest you at least look at my fork because I've got your changes through 1.6.7 incorporated. But the effort involved isn't small, and what you have is working just fine.
     

Share This Page