You are not logged in.

#1 2018-11-14 07:54:08

huzo11
Member
Registered: 2018-10-31
Posts: 60

Calling makepkg from an outer directory

Hello all

When trying to write a python script, I realized that when I try to call makepkg command on a PKGBUILD in an inner file, for instance

makepkg package_name/PKGBUILD

, I get an error saying

    ==> ERROR: PKGBUILD does not exist.

But when I change my current directory to the directory of PKGBUILD file,

cd package_name

, and run

makepkg PKGBUILD

I face no problems. So, is it true that I have to strictly be in the PKGBUILD file's directory to be able to call makepkg on it? If that is the case, how can I run

makepkg PKGBUILD

after downloading the package directory using python subprocess? Because using

subprocess.call("cd " + package_file_name, shell=True)

does not do anything at all.

Thanks!

Last edited by huzo11 (2018-11-14 07:55:58)


Be nice and live for others.
https://prismatically.blog

Offline

#2 2018-11-14 08:47:14

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,673
Website

Re: Calling makepkg from an outer directory

       -p <buildscript>
           Read the package script buildscript instead of the PKGBUILD
           default; see PKGBUILD(5). The buildscript must be located in the
           directory makepkg is called from.

Offline

#3 2018-11-14 09:26:22

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Calling makepkg from an outer directory

Similarly, for the Python part of the question, "RTFM" would also help, as would a better understanding of processes. Every process has a current working directory. This is abbreviated as "cwd". For example, you can find the working directory of process $pid in /proc/$pid/cwd. The various Python subprocess methods also have an optional parameter with this name.

huzo11 wrote:

Because using

subprocess.call("cd " + package_file_name, shell=True)

does not do anything at all.

That starts a shell as a subprocess, which inherits the cwd of the parent (the Python interpreter). The shell executes the cd command, changing the cwd of its own process, and then exits (no other shell commands left to execute). Then the Python script continues, but its cwd was not affected by any changes in the child process, so if you make a separate subprocess.call for makepkg, that would still be in the "outer directory".

You could also change the cwd of the Python process with os.chdir() (and query it with os.getcwd()), but check out the cwd parameter for subprocess methods first.

Offline

#4 2018-11-14 09:34:08

huzo11
Member
Registered: 2018-10-31
Posts: 60

Re: Calling makepkg from an outer directory

Allan wrote:
       -p <buildscript>
           Read the package script buildscript instead of the PKGBUILD
           default; see PKGBUILD(5). The buildscript must be located in the
           directory makepkg is called from.

If this means that -p allows me to do what I want, I do get an error "option requires an argument -- 'p'". Else, too bad I can't do it. Thanks!


Be nice and live for others.
https://prismatically.blog

Offline

#5 2018-11-14 09:42:26

progandy
Member
Registered: 2012-05-17
Posts: 5,322

Re: Calling makepkg from an outer directory

The description for -p means that makepkg requires you to change the working directory to the location of your PKGBUILD. Raynman already gave you the correct hint:

subprocess.call(..., cwd="package_dir")

https://docs.python.org/3/library/subprocess.html

Last edited by progandy (2018-11-14 09:47:44)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

#6 2018-11-14 12:51:52

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

Re: Calling makepkg from an outer directory

huzo11 wrote:
Allan wrote:
       -p <buildscript>
           Read the package script buildscript instead of the PKGBUILD
           default; see PKGBUILD(5). The buildscript must be located in the
           directory makepkg is called from.

If this means that -p allows me to do what I want, I do get an error "option requires an argument -- 'p'". Else, too bad I can't do it. Thanks!

Your comment is completely unrelated to the description of the "-p" option. Please read the description rather than simply throwing command-line switches at the metaphorical wall like spaghetti in an attempt to see what sticks.

Particularly, since descriptions exist because they're meant to be read. It does no one any good at all to say things if you just ignore them.


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

Offline

#7 2018-11-14 14:28:15

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,534
Website

Re: Calling makepkg from an outer directory

Also using the comman `makepkg PKGBUILD` makes little sense.  It will work under the proper conditions, but only because "PKGBUILD" in that command is essentially ignored.  This would be clear from a reading of even the first line of the man page.

The -p flag allows you to specify a file named something other that PKGBUILD, but as the very short description clearly and concisely notes, it must still be in the current working directory that makepkg is called from.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2018-11-14 14:30:46

AlienofOne
Member
Registered: 2018-10-22
Posts: 11

Re: Calling makepkg from an outer directory

Are you sure that you're pointing to the pkgbuild file properly? Can you try editing your script to read "~/package_name/PKGBUILD" and run to see if that works?

Offline

#9 2018-11-14 14:39:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,534
Website

Re: Calling makepkg from an outer directory

*Headdesk*

AlienofOne, read the thread, or the man page, before posting.  That is nonsensical advice.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#10 2018-11-14 14:55:01

sincomil
Member
Registered: 2018-02-13
Posts: 118

Re: Calling makepkg from an outer directory

manpage wrote:

-p <buildscript>
           Read the package script buildscript instead of the PKGBUILD default; see PKGBUILD(5). The buildscript must be located in the directory makepkg is called from.

If you want to run your shell command from specific directory there is way you have to call your command from Python:

subprocess.Popen("ls", cwd="/working/directory")

But running cd shell command will not work because it is shell internal command

Last edited by sincomil (2018-11-14 14:57:57)

Offline

#11 2018-11-14 15:06:40

huzo11
Member
Registered: 2018-10-31
Posts: 60

Re: Calling makepkg from an outer directory

Thank you guys.

subprocess.call(... , cwd="dir")

was exactly what I was looking for! smile


Be nice and live for others.
https://prismatically.blog

Offline

#12 2018-11-14 17:31:42

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

Re: Calling makepkg from an outer directory

sincomil wrote:
manpage wrote:

-p <buildscript>
           Read the package script buildscript instead of the PKGBUILD default; see PKGBUILD(5). The buildscript must be located in the directory makepkg is called from.

If you want to run your shell command from specific directory there is way you have to call your command from Python:

subprocess.Popen("ls", cwd="/working/directory")

But running cd shell command will not work because it is shell internal command

Not only did someone already explain above, how to use subprocess with cwd properly, you're also wrong that cd won't work. In fact, someone explained above, why it *does* work.

subprocess.Popen supports a shell=True parameter which will make the string run inside the /bin/sh shell and thus cd works fine. It's the wrong way to do it, but it does work...

However, as (again) explained above, if you launch a subprocess, then use it to cd inside the subprocess, then immediately end the subprocess, it quite obviously doesn't do anything meaningful. It's not because it's an internal command. if it was because it's an internal command, then the OP would not have gotten "does not do anything at all", the OP would have gotten:

>>> import subprocess
>>> subprocess.Popen(['cd'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/subprocess.py", line 769, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.7/subprocess.py", line 1516, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'cd': 'cd'

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

Offline

Board footer

Powered by FluxBB