You are not logged in.

#1 2021-01-05 22:47:41

lchip
Member
Registered: 2021-01-03
Posts: 2

PKGBUILD Review Request

Hello. I have recently made an installable package that I would like to upload to the AUR as my first package. However, my PKGBUILD has some glaring issues that I would greatly appreciate some feedback on.

To give some more context about my program: I've written a Python program and it's using setuptools (or, what I understand to be handling certain automation during 'makepkg'). These are the main issues I'm experiencing, specifically in the package() function:  I've had to manually install a configuration file, manually edit a line of text from the repository, and manually assign execute permissions to the main module. All other files were automatically placed in the correct system directories as expected. As to whether my decisions are the right way to go about things, I'm definitely unclear on- largely because the program is running just fine from the command line after installing.

Here's my PKGBUILD:

# Maintainer: Lawrence <lawrencechip@protonmail.com>
pkgname='screendimmer'
pkgver=0.1.0
pkgrel=1
pkgdesc="A tray application designed to dim the brightness of your monitors."
arch=(x86_64)
url="https://github.com/Lawrence-Chiappelli/screendimmer.git"
license=('MIT')
depends=('python')
makedepends=('git' 'python-setuptools')
source=("$pkgname::git://github.com/Lawrence-Chiappelli/screendimmer.git")
md5sums=('SKIP')

build() {
        cd "$pkgname"           
        python setup.py build
}

package() {     

        cd "$pkgname"
        python setup.py install --root="$pkgdir" --optimize=1 --skip-build      

        # Need perms on following file  
        install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
        install -Dm644 brightness.ini "$pkgdir/etc/$pkgname/brightness.ini"
        install -Dm644 "$pkgname.desktop" "$pkgdir/usr/share/applications/$pkgname.desktop"
        install -Dm644 "$pkgname.png" "$pkgdir/usr/share/pixmaps/$pkgname.png"

        # Make sure the shell scripts points to the correct Python version:
        # (setuptools seems to automatically creates this directory depending on the Python version I've used)
        _python_version="$printf$(ls $pkgdir/usr/lib/)"                 
        _line1="#!/bin/sh"
        _line2="exec /usr/lib/$_python_version/site-packages/$pkgname/tray.py"               
        printf "$_line1\n$_line2" > "$pkgdir/usr/bin/$pkgname"

        # Lastly, assign execute permission to main module
        chmod +x "$pkgdir/usr/lib/$_python_version/site-packages/$pkgname/tray.py"
}

That said, I'm open to feedback, and feel free to let me know if I can provide any more information.

Offline

#2 2021-01-05 23:35:05

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,463

Re: PKGBUILD Review Request

The upstream setup is bad. If tray.py is the main script that the user should be running, why isn't that being installed to /usr/bin/? Or make that a library and just import that and create_tray from a separate script?

Offline

#3 2021-01-06 01:29:27

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: PKGBUILD Review Request

You're currently using the old distutils "scripts" method of installing a program in /usr/bin -- but you're doing it wrong. Don't create a bash script that execs tray.py, create a python script with:

#!/usr/bin/python3

from screendimmer.tray import create_tray
create_tray()

setuptools will auto-rewrite the shebang to target the version of python you used to run setup.py install, so this works for any version of python, inside or outside of virtualenvs, etc.

You'll need to remove the final line from tray.py, or guard it in the common python pattern for a file that can be imported *or* executed as a module: https://docs.python.org/3/library/__main__.html

Another method of doing this is to forego the "scripts" and instead use

    entry_points={
        'gui_scripts': [
            'screendimmer=screendimmer.tray:create_tray',
        ],
    },

setuptools will then generate its own script for you; this script might be a python script importing the same function and running it, but on Windows it could instead be a special .exe file handling the Windows... shortcomings... when it comes to scripts. This is very useful for cross-platform code.

More info: https://setuptools.readthedocs.io/en/la … point.html

...

P.S. The software needs to use git tags: https://github.com/Lawrence-Chiappelli/ … immer/tags

You can then use the source line:

# git is not needed
makedepends=('python-setuptools')
source=("$pkgname-$pkgver.tar.gz::https://github.com/Lawrence-Chiappelli/screendimmer/archive/$pkgver.tar.gz")

If your package uses the latest git master then you need to follow the instructions at https://wiki.archlinux.org/index.php/VC … guidelines including use pkgname=screendimmer-git and including a pkgver() function.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#4 2021-01-06 01:57:51

lchip
Member
Registered: 2021-01-03
Posts: 2

Re: PKGBUILD Review Request

Thanks for taking the time to write your feedback eschwartz. You've cleared up several misconceptions I've held for a while that I struggled to articulate as a question. I'll be taking another shot with this information soon.

Scimmia wrote:

If tray.py is the main script that the user should be running, why isn't that being installed to /usr/bin/? Or make that a library and just import that and create_tray from a separate script?

It's an educated guess based on googling, looking at other PKGBUILDs, and trying to fit the pieces together from the Wiki. Now I understand your latter suggestion is the right way to go about it. Thanks for the feedback.

Offline

Board footer

Powered by FluxBB