Skip to content

Commit e5b02cd

Browse files
committedJun 3, 2018
use dedicated files for auto additions
1 parent 7cb18cd commit e5b02cd

23 files changed

+118
-41
lines changed
 

‎python/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,19 @@ ENDFOREACH(pyfile)
327327
FOREACH(module ${PY_MODULES})
328328
ADD_CUSTOM_TARGET(py${module} ALL)
329329
ADD_DEPENDENCIES(py${module} python_module_qgis__${module})
330+
331+
332+
# concat auto_additions/*.py in _module_/__init__.py
333+
FILE(GLOB PY_FILES_AUTO_ADDITIONS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${module}/auto_additions/*.py)
334+
FOREACH(pyfile ${PY_FILES_AUTO_ADDITIONS})
335+
file(READ ${IN_FILE} CONTENTS)
336+
file(APPEND ${OUT_FILE} "${CONTENTS}")
337+
ENDFOREACH(pyfile)
338+
configure_file(somefile.sql.in somefile.sql COPYONLY)
339+
330340
FILE(GLOB PY_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${module}/*.py)
331-
FILE(GLOB PY_FILES_ADDITIONS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${module}/additions/*.py)
332341
INSTALL(FILES ${PY_FILES} DESTINATION "${QGIS_PYTHON_DIR}/${module}")
342+
FILE(GLOB PY_FILES_ADDITIONS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${module}/additions/*.py)
333343
INSTALL(FILES ${PY_FILES_ADDITIONS} DESTINATION "${QGIS_PYTHON_DIR}/${module}/additions")
334344
SET(PY_FILES ${PY_FILES} ${PY_FILES_ADDITIONS})
335345
FOREACH(pyfile ${PY_FILES})
File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
This folder is completed using sipify.pl script
3+
It is not aimed to be manually edited
4+
"""
File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
This folder is completed using sipify.pl script
3+
It is not aimed to be manually edited
4+
"""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# The following has been generated automatically from src/core/qgsdataitem.h
2+
QgsDataItem.Type.baseClass = QgsDataItem
3+
QgsDataItem.State.baseClass = QgsDataItem
4+
QgsLayerItem.LayerType.baseClass = QgsLayerItem
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The following has been generated automatically from src/core/qgsfieldproxymodel.h
2+
QgsFieldProxyModel.Filters.baseClass = QgsFieldProxyModel
3+
Filters = QgsFieldProxyModel # dirty hack since SIP seems to introduce the flags in module
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# The following has been generated automatically from src/core/geometry/qgsgeometry.h
2+
QgsGeometry.BufferSide.baseClass = QgsGeometry
3+
QgsGeometry.EndCapStyle.baseClass = QgsGeometry
4+
QgsGeometry.JoinStyle.baseClass = QgsGeometry
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The following has been generated automatically from src/core/qgsmaplayerproxymodel.h
2+
QgsMapLayerProxyModel.Filters.baseClass = QgsMapLayerProxyModel
3+
Filters = QgsMapLayerProxyModel # dirty hack since SIP seems to introduce the flags in module
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The following has been generated automatically from src/core/qgssnappingconfig.h
2+
QgsSnappingConfig.SnappingMode.baseClass = QgsSnappingConfig
3+
QgsSnappingConfig.SnappingType.baseClass = QgsSnappingConfig
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The following has been generated automatically from src/core/qgsunittypes.h
2+
QgsUnitTypes.DistanceUnit.baseClass = QgsUnitTypes
3+
QgsUnitTypes.AreaUnit.baseClass = QgsUnitTypes
4+
QgsUnitTypes.AngleUnit.baseClass = QgsUnitTypes
5+
QgsUnitTypes.RenderUnit.baseClass = QgsUnitTypes
6+
QgsUnitTypes.LayoutUnit.baseClass = QgsUnitTypes
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# The following has been generated automatically from src/core/qgsvectorsimplifymethod.h
2+
QgsVectorSimplifyMethod.SimplifyHint.baseClass = QgsVectorSimplifyMethod
3+
QgsVectorSimplifyMethod.SimplifyHints.baseClass = QgsVectorSimplifyMethod
4+
SimplifyHints = QgsVectorSimplifyMethod # dirty hack since SIP seems to introduce the flags in module
5+
QgsVectorSimplifyMethod.SimplifyAlgorithm.baseClass = QgsVectorSimplifyMethod
File renamed without changes.

‎python/gui/auto_additions/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
This folder is completed using sipify.pl script
3+
It is not aimed to be manually edited
4+
"""
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The following has been generated automatically from src/gui/qgsadvanceddigitizingdockwidget.h
2+
QgsAdvancedDigitizingDockWidget.CadCapacities.baseClass = QgsAdvancedDigitizingDockWidget
3+
CadCapacities = QgsAdvancedDigitizingDockWidget # dirty hack since SIP seems to introduce the flags in module
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The following has been generated automatically from src/gui/attributetable/qgsattributetablefiltermodel.h
2+
QgsAttributeTableFilterModel.FilterMode.baseClass = QgsAttributeTableFilterModel
3+
QgsAttributeTableFilterModel.ColumnType.baseClass = QgsAttributeTableFilterModel
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# The following has been generated automatically from src/gui/qgsmaplayeractionregistry.h
2+
QgsMapLayerAction.Targets.baseClass = QgsMapLayerAction
3+
Targets = QgsMapLayerAction # dirty hack since SIP seems to introduce the flags in module
4+
QgsMapLayerAction.Flags.baseClass = QgsMapLayerAction
5+
Flags = QgsMapLayerAction # dirty hack since SIP seems to introduce the flags in module
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# The following has been generated automatically from src/gui/qgsmaptoolidentify.h
2+
QgsMapToolIdentify.IdentifyMode.baseClass = QgsMapToolIdentify
3+
QgsMapToolIdentify.LayerType.baseClass = QgsMapToolIdentify
4+
LayerType = QgsMapToolIdentify # dirty hack since SIP seems to introduce the flags in module
File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
This folder is completed using sipify.pl script
3+
It is not aimed to be manually edited
4+
"""

‎scripts/sipify.pl

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
my $LINE_IDX = 0;
7272
my $LINE;
7373
my @OUTPUT = ();
74+
my @OUTPUT_PYTHON = ();
7475

7576

7677
sub read_line {
@@ -115,20 +116,31 @@ sub exit_with_error {
115116
die "! Sipify error in $headerfile at line :: $LINE_IDX\n! $_[0]\n";
116117
}
117118

118-
sub write_header_footer {
119+
sub sip_header_footer {
120+
my @header_footer = ();
119121
# small hack to turn files src/core/3d/X.h to src/core/./3d/X.h
120122
# otherwise "sip up to date" test fails. This is because the test uses %Include entries
121123
# and over there we have to use ./3d/X.h entries because SIP parser does not allow a number
122124
# as the first letter of a relative path
123125
my $headerfile_x = $headerfile;
124126
$headerfile_x =~ s/src\/core\/3d/src\/core\/.\/3d/;
125-
push @OUTPUT, "/************************************************************************\n";
126-
push @OUTPUT, " * This file has been generated automatically from *\n";
127-
push @OUTPUT, " * *\n";
128-
push @OUTPUT, sprintf " * %-*s *\n", 68, $headerfile_x;
129-
push @OUTPUT, " * *\n";
130-
push @OUTPUT, " * Do not edit manually ! Edit header and run scripts/sipify.pl again *\n";
131-
push @OUTPUT, " ************************************************************************/\n";
127+
push @header_footer, "/************************************************************************\n";
128+
push @header_footer, " * This file has been generated automatically from *\n";
129+
push @header_footer, " * *\n";
130+
push @header_footer, sprintf " * %-*s *\n", 68, $headerfile_x;
131+
push @header_footer, " * *\n";
132+
push @header_footer, " * Do not edit manually ! Edit header and run scripts/sipify.pl again *\n";
133+
push @header_footer, " ************************************************************************/\n";
134+
return @header_footer;
135+
}
136+
137+
sub python_header {
138+
my @header = ();
139+
my $headerfile_x = $headerfile;
140+
$headerfile_x =~ s/src\/core\/3d/src\/core\/.\/3d/;
141+
push @header, "# The following has been generated automatically from ";
142+
push @header, sprintf "%s\n", $headerfile_x;
143+
return @header;
132144
}
133145

134146
sub processDoxygenLine {
@@ -455,9 +467,6 @@ sub detect_non_method_member{
455467
return 0;
456468
}
457469

458-
459-
write_header_footer();
460-
461470
# write some code in front of line to know where the output comes from
462471
$debug == 0 or push @OUTPUT, "CODE SIP_RUN MultiLine\n";
463472

@@ -656,23 +665,14 @@ sub detect_non_method_member{
656665
my $enum_helper = "$ACTUAL_CLASS.$2.baseClass = $ACTUAL_CLASS";
657666
dbg_info("Q_ENUM/Q_FLAG $enum_helper");
658667
if ($python_output ne ''){
659-
my $pl;
660-
open(FH, '+<', $python_output) or die $!;
661-
foreach $pl (<FH>) {
662-
if ($pl =~ m/$enum_helper/){
663-
$enum_helper = '';
664-
last;
665-
}
666-
}
667668
if ($enum_helper ne ''){
669+
push @OUTPUT_PYTHON, "$enum_helper\n";
668670
if ($is_flag == 1){
669671
# SIP seems to introduce the flags in the module rather than in the class itself
670672
# as a dirty hack, inject directly in module, hopefully we don't have flags with the same name....
671-
$enum_helper .= "\n$2 = $ACTUAL_CLASS # dirty hack since SIP seems to introduce the flags in module";
673+
push @OUTPUT_PYTHON, "$2 = $ACTUAL_CLASS # dirty hack since SIP seems to introduce the flags in module\n";
672674
}
673-
print FH "$enum_helper\n";
674675
}
675-
close(FH);
676676
}
677677
}
678678
next;
@@ -705,21 +705,10 @@ sub detect_non_method_member{
705705
my $pyop = "${ACTUAL_CLASS}.__" . lc($1) . "__ = lambda self: self.$2()";
706706
dbg_info("PYTHON OPERATOR $pyop");
707707
if ($python_output ne ''){
708-
my $pl;
709-
open(FH, '+<', $python_output) or die $!;
710-
foreach $pl (<FH>) {
711-
if ($pl =~ m/$pyop/){
712-
$pyop = '';
713-
last;
714-
}
715-
}
716-
if ($pyop ne ''){
717-
print FH "$pyop\n";
718-
}
719-
close(FH);
720-
}
708+
push @OUTPUT_PYTHON, "$pyop\n";
709+
}
721710
}
722-
711+
723712
$COMMENT = '';
724713
next;
725714
}
@@ -1190,12 +1179,25 @@ sub detect_non_method_member{
11901179
$IS_OVERRIDE = 0;
11911180
}
11921181
}
1193-
write_header_footer();
11941182

11951183
if ( $sip_output ne ''){
11961184
open(FH, '>', $sip_output) or die $!;
1185+
print FH join('', sip_header_footer());
11971186
print FH join('',@OUTPUT);
1187+
print FH join('', sip_header_footer());
11981188
close(FH);
11991189
} else {
1190+
print join('', sip_header_footer());
12001191
print join('',@OUTPUT);
1192+
print join('', sip_header_footer());
1193+
}
1194+
1195+
if ( $python_output ne '' ){
1196+
unlink $python_output or 1;
1197+
if ( $#OUTPUT_PYTHON > 0 ){
1198+
open(FH2, '>', $python_output) or die $!;
1199+
print FH2 join('', python_header());
1200+
print FH2 join('', @OUTPUT_PYTHON);
1201+
close(FH2);
1202+
}
12011203
}

‎scripts/sipify_all.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ for module in "${modules[@]}"; do
4242
while read -r sipfile; do
4343
echo "$sipfile.in"
4444
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)
45+
pyfile=$(${GP}sed -E 's@([^\/]+\/)*([^\/]+)\.sip@\2.py@;' <<< $sipfile)
4546
if [ ! -f $header ]; then
4647
echo "*** Missing header: $header for sipfile $sipfile"
4748
else
4849
path=$(${GP}sed -r 's@/[^/]+$@@' <<< $sipfile)
4950
mkdir -p python/$path
50-
./scripts/sipify.pl -s python/$sipfile.in -p python/${module}/__init__.py $header &
51+
./scripts/sipify.pl -s python/$sipfile.in -p python/${module}/auto_additions/${pyfile} $header &
5152
fi
5253
count=$((count+1))
5354
done < <( ${GP}sed -n -r "s@^%Include auto_generated/(.*\.sip)@${module}/auto_generated/\1@p" python/${module}/${module}_auto.sip )

‎tests/code_layout/test_sipfiles_uptodate.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ for module in "${modules[@]}"; do
2020
cp ${module_init} ${DIR}/${module}.temp
2121
while read -r sipfile; do
2222
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)
23+
pyfile=$(${GP}sed -E 's@([^\/]+\/)*([^\/]+)\.sip@\2.py@;' <<< $sipfile)
2324
if [ ! -f $header ]; then
2425
echo "*** Missing header: $header for sipfile $sipfile"
2526
else
26-
outdiff=$(./scripts/sipify.pl -p ${DIR}/${module}.temp $header | diff python/$sipfile.in -)
27+
outdiff=$(./scripts/sipify.pl -p python/${module}/auto_additions/${pyfile}.temp $header | diff python/$sipfile.in -)
28+
outdiff2=$(diff python/${module}/auto_additions/${pyfile} python/${module}/auto_additions/${pyfile}.temp)
2729
if [[ -n "$outdiff" ]]; then
2830
echo " *** SIP file not up to date: $sipfile"
2931
code=1
3032
fi
33+
if [[ -n "$outdiff2" ]]; then
34+
echo " *** Python addition file not up to date: $sipfile"
35+
code=1
36+
fi
3137
fi
3238
done < <(
3339
${GP}sed -n -r "s@^%Include auto_generated/(.*\.sip)@${module}/auto_generated/\1@p" python/${module}/${module}_auto.sip
@@ -37,7 +43,6 @@ for module in "${modules[@]}"; do
3743
echo " *** Python ${module} (${module_init}) init not up to date: run sipify with -p argument"
3844
code=1
3945
fi
40-
rm ${DIR}/${module}.temp
4146
done
4247

4348

0 commit comments

Comments
 (0)
Please sign in to comment.