20
20
#-------------------------------------------------------------------------------
21
21
# Imports
22
22
#-------------------------------------------------------------------------------
23
+ import io
23
24
import os
24
25
import sys
25
26
@@ -330,41 +331,12 @@ def check_for_dependencies():
330
331
331
332
def record_commit_info (pkg_dir , build_cmd = build_py ):
332
333
""" Return extended build command class for recording commit
333
-
334
- The extended command tries to run git to find the current commit, getting
335
- the empty string if it fails. It then writes the commit hash into a file
336
- in the `pkg_dir` path, named ``.git_commit_info.ini``.
337
-
338
- In due course this information can be used by the package after it is
339
- installed, to tell you what commit it was installed from if known.
340
-
341
- To make use of this system, you need a package with a .git_commit_info.ini
342
- file - e.g. ``myproject/.git_commit_info.ini`` - that might well look like
343
- this::
344
-
345
- # This is an ini file that may contain information about the code state
346
- [commit hash]
347
- # The line below may contain a valid hash if it has been substituted
348
- # during 'git archive'
349
- archive_subst_hash=$Format:%h$
350
- # This line may be modified by the install process
351
- install_hash=
352
-
353
- The .git_commit_info file above is also designed to be used with git
354
- substitution - so you probably also want a ``.gitattributes`` file in the
355
- root directory of your working tree that contains something like this::
356
-
357
- myproject/.git_commit_info.ini export-subst
358
-
359
- That will cause the ``.git_commit_info.ini`` file to get filled in by ``git
360
- archive`` - useful in case someone makes such an archive - for example with
361
- via the github 'download source' button.
362
-
363
- Although all the above will work as is, you might consider having something
364
- like a ``get_info()`` function in your package to display the commit
365
- information at the terminal. See the ``pkg_info.py`` module in the nipy
366
- package for an example.
334
+
335
+ records git commit in IPython.utils._sysinfo.commit
336
+
337
+ for use in IPython.utils.sysinfo.sys_info() calls after installation.
367
338
"""
339
+
368
340
class MyBuildPy (build_cmd ):
369
341
''' Subclass to write commit data into installation tree '''
370
342
def run (self ):
@@ -375,16 +347,13 @@ def run(self):
375
347
stderr = subprocess .PIPE ,
376
348
shell = True )
377
349
repo_commit , _ = proc .communicate ()
350
+ repo_commit = repo_commit .strip ()
378
351
# We write the installation commit even if it's empty
379
- cfg_parser = ConfigParser ()
380
- cfg_parser .read (pjoin (pkg_dir , '.git_commit_info.ini' ))
381
- if not cfg_parser .has_section ('commit hash' ):
382
- # just in case the ini file is empty or doesn't exist, somehow
383
- # we don't want the next line to raise
384
- cfg_parser .add_section ('commit hash' )
385
- cfg_parser .set ('commit hash' , 'install_hash' , repo_commit .decode ('ascii' ))
386
- out_pth = pjoin (self .build_lib , pkg_dir , '.git_commit_info.ini' )
387
- out_file = open (out_pth , 'wt' )
388
- cfg_parser .write (out_file )
389
- out_file .close ()
352
+ out_pth = pjoin (self .build_lib , pkg_dir , 'utils' , '_sysinfo.py' )
353
+ with io .open (out_pth , 'w' ) as out_file :
354
+ for line in [
355
+ u"# GENERATED BY setup.py" ,
356
+ u"commit = '%s'" % repo_commit ,
357
+ ]:
358
+ out_file .write (line + u'\n ' )
390
359
return MyBuildPy
0 commit comments