Page 1 of 1

About Python code

Published: September 4, 2019 - 9:30 PM
by frferrer
Good evening,

Upon reviewing some code examples, I am wondering about an instruction that appears in the documentation and in some packages.

Specifically in the following document https://www.wapt.fr/fr/doc/wapt-create- ... g-software

Here is the code in question:

Code: Select all

for soft in installed_softwares('winscp3'):
    if Version(soft['version']) < Version('5.0.2'):
        run(WAPT.uninstall_cmd(soft['key']))
The instruction uninstall_cmd is a function of the module setuphelpers.
This module is loaded into all files setup.py at the top of the file with the instruction

Code: Select all

from setuphelpers import *
So I don't really understand the point of using WAPT.uninstall_cmd compared to a simple uninstall_cmd.
This results in the following code:

Code: Select all

for soft in installed_softwares('winscp3'):
    if Version(soft['version']) < Version('5.0.2'):
        run(uninstall_cmd(soft['key']))
From what I understand, WAPT is an object containing methods from the setuphelpers module.

Hence the following questions:
  • Where is this WAPT object instantiated? What is its purpose?
  • Why use the uninstall_cmd of the WAPT object rather than the uninstall_cmd of the setuphelpers module?
  • What is the advantage of using this method?
THANKS.

Re: About Python code

Published: September 6, 2019 - 5:23 PM
by htouvet
common.Wapt.uninstall_cmd is an alias for setuphelpers.uninstall_cmd, likely for backward compatibility reasons.

The WAPT instance (of the common.Wapt class) that can be used in the hook functions install(), uninstall(), session_setup(), and audit() in setup.py is an object variable instantiated by the WAPT client and automatically injected into the namespace of the setup module before the function call, much like a built-in implicit variable... see, for example: https://github.com/tranquilit/WAPT/blob ... n.py#L3701.

Initially, this was done to avoid an explicit list of parameters in the install function definitions, etc., so as not to clutter the setup.py file for novice packagers, as this variable is rarely used.

The WAPT object (class common.Wapt) allows access to the current state of the wapt client and the associated API and to launch explicit commands WAPT.install('package') WAPT.remove('package'), WAPT.forget('package'), etc... a bit like we do in the command line with wapt-get install, wapt-get remove but in the python code.

Re: About Python code

Published: September 9, 2019 - 10:02 PM
by frferrer
Good evening,

Thank you for this explanation of the text, it's much clearer.

It's not easy for beginners to find their way around when both writing systems are used.

May I suggest that the code example in the documentation be cleaned up to keep only the syntax?

Code: Select all

run(uninstall_cmd())
; and retain the use of WAPT.<méthode> than for what it is, that is to say the WAPT client instance?
https://www.wapt.fr/fr/doc/wapt-create- ... g-software

THANKS.

Re: About Python code

Published: September 16, 2019 - 6:25 PM
by sfonteneau
We definitely need to clean things up...

We haven't really talked about it much, but you can edit the documentation yourself using pull requests:

The documentation is here:

https://github.com/tranquilit/WAPT-Documentation.

We have less and less time to create documentation.

Community help would be greatly appreciated!

You can submit pull requests directly!