Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,28 @@ pipenv run plextraktsync

### Install code from Pull request

This requires prior installation with `pipx`.
This requires prior installation with `pipx` or `uv`.
Replace `838` with a pull request you intend to install.

```
plextraktsync self-update --pr 838
```

It will create new binary `plextraktsync@838` for that pull request. You need to run this binary instead of `plextraktsync`.
With `pipx`, it creates a new binary `plextraktsync@838` for that pull request. You need to run this binary instead of `plextraktsync`.
With `uv`, it updates your `plextraktsync` tool install to the pull request ref.

To pull new changes for the same pull request:

```
plextraktsync@838 self-update
```

or with `uv`:

```
plextraktsync self-update --pr 838
```

If you need to do the same in docker container, you should:

͏ ͏ ͏1. first prepare the container with:
Expand All @@ -134,6 +141,8 @@ If you need to do the same in docker container, you should:
$ docker-compose run --rm --entrypoint sh plextraktsync
/app # pip install pipx
/app # pipx install plextraktsync
/app # pip install uv
/app # uv tool install plextraktsync
/app # apk add git
/app # plextraktsync self-update --pr 969
/app # plextraktsync@969 info
Expand Down Expand Up @@ -167,6 +176,12 @@ uninstalled PlexTraktSync@984! ✨ 🌟 ✨
$
```

For `uv`, remove the tool with:

```
uv tool uninstall plextraktsync
```

## Building docker image

You can build docker image from default branch:
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ have a file containing those on your harddrive, you can not use this project.
- [Pre-requisites](#pre-requisites)
- [Installation](#installation)
- [pipx](#pipx)
- [uv](#uv)
- [Docker Compose](#docker-compose)
- [Install code from Pull request](#install-code-from-pull-request), development
- [Windows Setup (optional alternative)](#windows-setup-optional-alternative), unsupported
Expand Down Expand Up @@ -104,6 +105,28 @@ which just calls `pipx` with:
pipx upgrade PlexTraktSync
```

### uv

Installation with [uv][install-uv]:

```
uv tool install PlexTraktSync
```

and to upgrade:

```
plextraktsync self-update
```

which calls `uv` with:

```
uv tool upgrade plextraktsync
```

If both `pipx` and `uv` installs exist, `plextraktsync self-update` updates all detected installs.

to run:

```
Expand All @@ -115,6 +138,7 @@ NOTE: `pipx` install will use OS specific paths for Config, Logs, Cache, see

[platformdirs]: https://pypi.org/project/platformdirs
[install-pipx]: https://github.com/pypa/pipx#install-pipx
[install-uv]: https://docs.astral.sh/uv/getting-started/installation/

### Docker Compose

Expand Down Expand Up @@ -554,7 +578,7 @@ Commands:
inspect Inspect details of an object
login Log in to Plex and Trakt if needed
plex-login Log in to Plex Account to obtain Access Token.
self-update Update PlexTraktSync to the latest version using pipx
self-update Update PlexTraktSync to the latest version using pipx and/or uv
sync Perform sync between Plex and Trakt
trakt-login Log in to Trakt Account to obtain Access Token.
unmatched List media that has no match in Trakt or Plex
Expand Down
6 changes: 3 additions & 3 deletions plextraktsync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ def download():
)
def self_update():
"""
Update PlexTraktSync to the latest version using pipx
Update PlexTraktSync to the latest version using pipx and/or uv

\b
$ plextraktsync self-update
Updating PlexTraktSync to latest using pipx
upgraded package plextraktsync from 0.15.3 to 0.18.5 (location: /Users/glen/.local/pipx/venvs/plextraktsync)
Updating PlexTraktSync install 'plextraktsync' using pipx
Updating PlexTraktSync install 'plextraktsync' using uv
"""


Expand Down
45 changes: 24 additions & 21 deletions plextraktsync/commands/self_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@

from plextraktsync.factory import factory
from plextraktsync.util.execp import execp


def has_previous_pr(pr: int):
from plextraktsync.util.packaging import pipx_installed

package = pipx_installed(f"plextraktsync@{pr}")

return package is not None
from plextraktsync.util.packaging import backend_for_name, list_managed_installs, managed_installs_by_backend, program_name


def pr_number() -> int | None:
"""
Check if current executable is named plextraktsync@<pr>
"""

import sys

try:
pr = sys.argv[0].split("@")[1]
pr = program_name().split("@")[1]
except IndexError:
return None

Expand All @@ -37,16 +28,28 @@ def self_update(pr: int):
if pr:
print(f"Installed as pr #{pr}, enabling pr mode")

installs = list_managed_installs()
if not installs:
print("No managed PlexTraktSync installation found in pipx or uv")
return

if pr:
if has_previous_pr(pr):
# Uninstall because pipx doesn't update otherwise:
# - https://github.com/pypa/pipx/issues/902
print(f"Uninstalling previous plextraktsync@{pr}")
execp(f"pipx uninstall plextraktsync@{pr}")

print(f"Updating PlexTraktSync to the pull request #{pr} version using pipx")
execp(f"pipx install --suffix=@{pr} --force git+https://github.com/Taxel/PlexTraktSync@refs/pull/{pr}/head")
for backend_name, backend_installs in managed_installs_by_backend().items():
backend = backend_for_name(backend_name)
if backend is None:
continue

print(f"Updating PlexTraktSync using {backend_name} to pull request #{pr}")
commands = backend.pr_update_commands(pr, backend_installs)
for command in commands:
print(f"Running [{backend_name}] {command}")
execp(command)
return

print("Updating PlexTraktSync to the latest version using pipx")
execp("pipx upgrade PlexTraktSync")
for install in installs:
backend = backend_for_name(install.backend)
if backend is None:
continue

print(f"Updating PlexTraktSync install '{install.app_name}' using {install.backend}")
execp(backend.latest_update_command(install))
6 changes: 2 additions & 4 deletions plextraktsync/factory/Factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,9 @@ def walker(self):

@cached_property
def enable_self_update(self):
from plextraktsync.util.packaging import pipx_installed, program_name
from plextraktsync.util.packaging import self_update_available

package = pipx_installed(program_name())

return package is not None
return self_update_available()

@cached_property
def web_socket_listener(self):
Expand Down
13 changes: 7 additions & 6 deletions plextraktsync/util/Version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def full_version(self):
return __version__

# Print version from pip
if self.pipx_installed:
if self.managed_installed:
v = self.vcs_info
return f"{__version__[0:-4]}@pr/{v['pr']}#{v['short_commit_id']}"
if v:
return f"{__version__[0:-4]}@pr/{v['pr']}#{v['short_commit_id']}"

# If installed with Git
gv = self.git_version_info
Expand Down Expand Up @@ -73,15 +74,15 @@ def vcs_info(self):
return vcs_info("PlexTraktSync")

@property
def pipx_installed(self):
def managed_installed(self):
if not self.installed:
return False

from plextraktsync.util.packaging import pipx_installed, program_name
from plextraktsync.util.packaging import managed_install_for_program

package = pipx_installed(program_name())
install = managed_install_for_program()

return package is not None
return install is not None

@property
def installed(self):
Expand Down
Loading
Loading