# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           python 1.0

name                maestral
categories          sysutils python
license             MIT
maintainers         nomaintainer
description         Light-weight and open-source Dropbox client for macOS and Linux
long_description    Maestral is an open-source Dropbox client written in Python. \
                    The project’s main goal is to provide a client for platforms \
                    and file systems that are no longer directly supported by Dropbox.
supported_archs     noarch
platforms           {darwin any}

# We want to have GUI, but pyqt4 is broken with python 3.11:
# https://bugzilla.redhat.com/show_bug.cgi?id=2062145
# Set the custom Python first, otherwise we get wrong dependencies.
# Below the default is changed to Python 3.14,
# unless we are on macOS < 11.
python.default_version 310

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    # Version for old systems; keep pegged until/unless a newer it fixed.
    # Notice, it should be compatible with py-watchdog version. Related issues:
    # https://github.com/samschott/maestral/issues/997
    # https://github.com/samschott/maestral-qt/issues/28
    # https://github.com/gorakhargosh/watchdog/issues/1021
    github.setup    samschott maestral 1.3.1 v
    revision        0
    checksums       rmd160  a63f51eae443f929bc99f2023ac58667dde644ca \
                    sha256  6427f13256bf970eeaea5d6d37489cf8d185da614997a46324d9d36f0f8f830e \
                    size    6709092
    github.tarball_from archive

    depends_lib-append \
                    port:py${python.version}-sdnotify \
                    port:py${python.version}-sqlalchemy
} else {
    github.setup    samschott maestral 1.9.6 v
    revision        0
    checksums       rmd160  ccd31de0dba3671c67ca0b04e4ba0a424f62f992 \
                    sha256  eed85515b7b3f85b0ea1c9f026bf9f50aa410ff80dbfedf0b315cc55f59aa3e6 \
                    size    8129919
    github.tarball_from archive

    python.default_version 314

    depends_lib-append \
                    port:py${python.version}-desktop-notifier \
                    port:py${python.version}-rich \
                    port:py${python.version}-typing_extensions \
                    port:py${python.version}-xattr
}

depends_lib-append  port:py${python.version}-alembic \
                    port:py${python.version}-bugsnag \
                    port:py${python.version}-click \
                    port:py${python.version}-dropbox \
                    port:py${python.version}-fasteners \
                    port:py${python.version}-keyring \
                    port:py${python.version}-keyrings.alt \
                    port:py${python.version}-packaging \
                    port:py${python.version}-pathspec \
                    port:py${python.version}-Pyro5 \
                    port:py${python.version}-requests \
                    port:py${python.version}-survey \
                    port:py${python.version}-watchdog

if {${os.platform} eq "darwin"} {
    depends_lib-append \
                    port:py${python.version}-rubicon-objc
}

depends_test-append  port:py${python.version}-pytest \
                    port:py${python.version}-pytest-benchmark \
                    port:py${python.version}-pytest-rerunfailures

# Some tests may fail: https://github.com/samschott/maestral/issues/1001
test.run            yes

variant bash_completion {
    post-destroot {
        xinstall -d "${destroot}${prefix}/share/bash-completion/completions"
        system "PYTHONPATH=${destroot}${python.pkgd} ${destroot}${python.prefix}/bin/maestral completion bash > ${destroot}${prefix}/share/bash-completion/completions/maestral"
    }
}

variant zsh_completion {
    post-destroot {
        xinstall -d "${destroot}${prefix}/share/zsh/site-functions"
        system "PYTHONPATH=${destroot}${python.pkgd} ${destroot}${python.prefix}/bin/maestral completion zsh > ${destroot}${prefix}/share/zsh/site-functions/_maestral"
    }
}

variant fish_completion {
    post-destroot {
        xinstall -d "${destroot}${prefix}/share/fish/completions"
        system "PYTHONPATH=${destroot}${python.pkgd} ${destroot}${python.prefix}/bin/maestral completion fish > ${destroot}${prefix}/share/fish/completions/maestral.fish"
    }
}

# Ignore dev releases
github.livecheck.regex  "(\\d+(?:\\.\\d+)+)"
