About Python code

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
frferrer
Messages: 8
Registration: Oct 20, 2017 - 7:05 p.m.

September 4, 2019 - 9:30 PM

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.
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

September 6, 2019 - 5:23 PM

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.
Tranquil IT
frferrer
Messages: 8
Registration: Oct 20, 2017 - 7:05 p.m.

September 9, 2019 - 10:02 PM

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.
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

September 16, 2019 - 6:25 PM

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!
Locked