#6653 Prepare all scripts for pkg_resources entry points
Opened 7 years ago by cheimes. Modified 7 years ago

In the long run we want to move away from manual script generation. The state of the art are setuptools' entry points for console script [1]. Setuptools or wheels auto-generates CLI scripts with correct shebang to the current Python interpreter. This will also fix an outstanding issue with virtual envs and tox testing. Console scripts take virtual envs correctly into account.

To prepare FreeIPA's code base for console script entry points, the body of all scripts must be moved into importable modules. About half of the scripts in install/tools are already in the correct form. Some scripts like ipa-ca-install have to be changed. The ipa script also needs a minor overhaul. Entry points can only import one object and call one function. It's possible to call a method on a sub-object but it is neither possible to instantiate a class and call a method on the instance, or to call a function with an additional argument.

The approach has another big benefit. It's going to be much easier to grep for code, imports and function calls. There will be no extra Python code in directories outside the package directories.

Example

# ipa-backup
from ipaserver.install.ipa_backup import Backup
Backup.run_cli()

becomes

ipa-backup = ipaserver.install.ipa_backup:Backup.run_cli

code:

>>> import pkg_resources
>>> e = pkg_resources.EntryPoint.parse('ipa-backup = ipaserver.install.ipa_backup:Backup.run_cli')
>>> e
EntryPoint.parse('ipa-backup = ipaserver.install.ipa_backup:Backup.run_cli')
>>> e.resolve()
<bound method type.run_cli of <class 'ipaserver.install.ipa_backup.Backup'>>

[1] https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html#the-console-scripts-entry-point


  • client/ipa-client-automount

  • daemons/dnssec/ipa-dnskeysyncd

  • daemons/dnssec/ipa-dnskeysync-replica
  • daemons/dnssec/ipa-ods-exporter

  • install/tools/ipa-adtrust-install

  • install/tools/ipa-ca-install
  • install/tools/ipa-compat-manage
  • install/tools/ipa-csreplica-manage
  • install/tools/ipactl
  • install/tools/ipa-dns-install
  • install/tools/ipa-httpd-kdcproxy
  • install/tools/ipa-managed-entries
  • install/tools/ipa-nis-manage
  • install/tools/ipa-pki-retrieve-key
  • install/tools/ipa-replica-conncheck
  • install/tools/ipa-replica-manage

  • install/certmonger/ipa-server-guard

  • install/certmonger/dogtag-ipa-ca-renew-agent-submit
  • install/certmonger/ipa-server-guard

  • install/oddjob/com.redhat.idm.trust-fetch-domains

  • install/restart_scripts/renew_ca_cert

  • install/restart_scripts/renew_ra_cert
  • install/restart_scripts/renew_ra_cert_pre
  • install/restart_scripts/restart_dirsrv
  • install/restart_scripts/restart_httpd
  • install/restart_scripts/stop_pkicad

  • ipatests/ipa-run-tests

  • ipatests/ipa-test-config
  • ipatests/ipa-test-task

  • makeapi

  • makeaci
  • ipa

Metadata Update from @cheimes:
- Issue assigned to someone
- Issue set to the milestone: Future Releases

7 years ago

master:

  • bf67974 Use entry_points for ipa CLI

ipa-4-5:

  • 1e1e4e8 Use entry_points for ipa CLI

Log in to comment on this ticket.

Metadata