Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
54bb1e6a
Kaydet (Commit)
54bb1e6a
authored
Haz 19, 2011
tarafından
Éric Araujo
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Improve documentation of packaging hooks
üst
3e425ac6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
22 deletions
+36
-22
commandhooks.rst
Doc/packaging/commandhooks.rst
+30
-19
setupcfg.rst
Doc/packaging/setupcfg.rst
+6
-3
No files found.
Doc/packaging/commandhooks.rst
Dosyayı görüntüle @
54bb1e6a
.. TODO integrate this in commandref and configfile
.. _packaging-command-hooks:
=============
Command hooks
=============
Packaging provides a way of extending its commands by the use of pre- and
post- command hooks. The hooks are simple Python functions (or any callable
objects) and are specified in the config file using their full qualified names.
The pre-hooks are run after the command is finalized (its options are
processed), but before it is run. The post-hooks are run after the command
itself. Both types of hooks receive an instance of the command object.
post-command hooks. Hooks are Python functions (or any callable object) that
take a command object as argument. They're specified in :ref:`config files
<packaging-config-filenames>` using their fully qualified names. After a
command is finalized (its options are processed), the pre-command hooks are
executed, then the command itself is run, and finally the post-command hooks are
executed.
See also global setup hooks in :ref:`setupcfg-spec`.
Sample usage of hooks
=====================
.. _packaging-finding-hooks:
Finding hooks
=============
Firstly, you need to make sure your hook is present in the path. This is usually
done by dropping them to the same folder where `setup.py` file lives ::
As a hook is configured with a Python dotted name, it must either be defined in
a module installed on the system, or in a module present in the project
directory, where the :file:`setup.cfg` file lives::
# file: myhooks.py
def my_install_hook(install_cmd):
print "Oh la la! Someone is installing my project!"
# file: _setuphooks.py
Then, you need to point to it in your `setup.cfg` file, under the appropriate
command section ::
def hook(install_cmd):
metadata = install_cmd.dist.metadata
print('Hooked while installing %r %s!' % (metadata['Name'],
metadata['Version']))
Then you need to configure it in :file:`setup.cfg`::
[install_dist]
pre-hook.project = myhooks.my_install_hook
pre-hook.a = _setuphooks.hook
Packaging will add the project directory to :data:`sys.path` and find the
``_setuphooks`` module.
The h
ooks defined in different config files (system-wide, user-wide and
p
ackage
-wide) do not override each other as long as they are specified with
different aliases (additional names after the dot). The alias in the example
above is ``
project
``.
H
ooks defined in different config files (system-wide, user-wide and
p
roject
-wide) do not override each other as long as they are specified with
different aliases (additional names after the dot).
The alias in the example
above is ``
a
``.
Doc/packaging/setupcfg.rst
Dosyayı görüntüle @
54bb1e6a
...
...
@@ -178,17 +178,20 @@ compilers
setup_hooks
Defines a list of callables to be called right after the :file:`setup.cfg`
file is read, before any other processing. The callables are executed in the
file is read, before any other processing. Each value is a Python dotted
name to an object, which has to be defined in a module present in the project
directory alonside :file:`setup.cfg` or on Python's :data:`sys.path` (see
:ref:`packaging-finding-hooks`). The callables are executed in the
order they're found in the file; if one of them cannot be found, tools should
not stop, but for example produce a warning and continue with the next line.
Each callable receives the configuration as a dictionary (keys are
:file:`setup.cfg` sections, values are dictionaries of fields) and can make
any change
s
to it. *optional*, *multi*
any change to it. *optional*, *multi*
Example::
[global]
setup_hooks =
package.setup.customize_dist
setup_hooks =
_setuphooks.customize_config
Metadata
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment