6
6
7
7
from __future__ import unicode_literals
8
8
9
+ import sys
10
+ if sys .version_info [:2 ] >= (3 , 2 ):
11
+ import biblib .bib
9
12
import fnmatch
10
13
import os
11
14
import re
22
25
__status__ = 'Production'
23
26
24
27
__all__ = [
25
- 'APPLICATION_NAME' , 'PYTHON_PACKAGE_NAME' , 'PYPI_PACKAGE_NAME' , 'clean' ,
26
- 'formatting' , 'tests' , 'quality' , 'examples' , 'docs' , 'todo' , 'preflight' ,
27
- 'build' , 'virtualise' , 'tag' , 'release' , 'sha256'
28
+ 'APPLICATION_NAME' , 'PYTHON_PACKAGE_NAME' , 'PYPI_PACKAGE_NAME' ,
29
+ 'BIBLIOGRAPHY_NAME' , 'clean' , 'formatting' , 'tests' , 'quality' , 'examples' ,
30
+ 'docs' , 'todo' , 'preflight' , 'build' , 'virtualise' , 'tag' , 'release' ,
31
+ 'sha256'
28
32
]
29
33
30
34
APPLICATION_NAME = colour_checker_detection .__application_name__
33
37
34
38
PYPI_PACKAGE_NAME = 'colour-checker-detection'
35
39
40
+ BIBLIOGRAPHY_NAME = 'BIBLIOGRAPHY.bib'
41
+
36
42
37
43
@task
38
44
def clean (ctx , docs = True , bytecode = False ):
@@ -69,7 +75,7 @@ def clean(ctx, docs=True, bytecode=False):
69
75
70
76
71
77
@task
72
- def formatting (ctx , yapf = False , asciify = True ):
78
+ def formatting (ctx , yapf = False , asciify = True , bibtex = True ):
73
79
"""
74
80
Formats the codebase with *Yapf* and converts unicode characters to ASCII.
75
81
@@ -81,6 +87,8 @@ def formatting(ctx, yapf=False, asciify=True):
81
87
Whether to format the codebase with *Yapf*.
82
88
asciify : bool, optional
83
89
Whether to convert unicode characters to ASCII.
90
+ bibtex : bool, optional
91
+ Whether to cleanup the *BibTeX* file.
84
92
85
93
Returns
86
94
-------
@@ -97,6 +105,26 @@ def formatting(ctx, yapf=False, asciify=True):
97
105
with ctx .cd ('utilities' ):
98
106
ctx .run ('./unicode_to_ascii.py' )
99
107
108
+ if bibtex and sys .version_info [:2 ] >= (3 , 2 ):
109
+ message_box ('Cleaning up "BibTeX" file...' )
110
+ bibtex_path = BIBLIOGRAPHY_NAME
111
+ with open (bibtex_path ) as bibtex_file :
112
+ bibtex = biblib .bib .Parser ().parse (
113
+ bibtex_file .read ()).get_entries ()
114
+
115
+ for entry in sorted (bibtex .values (), key = lambda x : x .key ):
116
+ try :
117
+ del entry ['file' ]
118
+ except KeyError :
119
+ pass
120
+ for key , value in entry .items ():
121
+ entry [key ] = re .sub ('(?<!\\ \\ )\\ &' , '\\ &' , value )
122
+
123
+ with open (bibtex_path , 'w' ) as bibtex_file :
124
+ for entry in bibtex .values ():
125
+ bibtex_file .write (entry .to_bib ())
126
+ bibtex_file .write ('\n ' )
127
+
100
128
101
129
@task
102
130
def tests (ctx , nose = True ):
0 commit comments