Skip to content

Commit

Permalink
use dedicated files for auto additions
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jun 3, 2018
1 parent 7cb18cd commit e5b02cd
Show file tree
Hide file tree
Showing 23 changed files with 118 additions and 41 deletions.
12 changes: 11 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,19 @@ ENDFOREACH(pyfile)
FOREACH(module ${PY_MODULES})
ADD_CUSTOM_TARGET(py${module} ALL)
ADD_DEPENDENCIES(py${module} python_module_qgis__${module})


# concat auto_additions/*.py in _module_/__init__.py
FILE(GLOB PY_FILES_AUTO_ADDITIONS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${module}/auto_additions/*.py)
FOREACH(pyfile ${PY_FILES_AUTO_ADDITIONS})
file(READ ${IN_FILE} CONTENTS)
file(APPEND ${OUT_FILE} "${CONTENTS}")
ENDFOREACH(pyfile)
configure_file(somefile.sql.in somefile.sql COPYONLY)

FILE(GLOB PY_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${module}/*.py)
FILE(GLOB PY_FILES_ADDITIONS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${module}/additions/*.py)
INSTALL(FILES ${PY_FILES} DESTINATION "${QGIS_PYTHON_DIR}/${module}")
FILE(GLOB PY_FILES_ADDITIONS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${module}/additions/*.py)
INSTALL(FILES ${PY_FILES_ADDITIONS} DESTINATION "${QGIS_PYTHON_DIR}/${module}/additions")
SET(PY_FILES ${PY_FILES} ${PY_FILES_ADDITIONS})
FOREACH(pyfile ${PY_FILES})
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions python/analysis/auto_additions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
This folder is completed using sipify.pl script
It is not aimed to be manually edited
"""
File renamed without changes.
4 changes: 4 additions & 0 deletions python/core/auto_additions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
This folder is completed using sipify.pl script
It is not aimed to be manually edited
"""
4 changes: 4 additions & 0 deletions python/core/auto_additions/qgsdataitem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The following has been generated automatically from src/core/qgsdataitem.h
QgsDataItem.Type.baseClass = QgsDataItem
QgsDataItem.State.baseClass = QgsDataItem
QgsLayerItem.LayerType.baseClass = QgsLayerItem
3 changes: 3 additions & 0 deletions python/core/auto_additions/qgsfieldproxymodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The following has been generated automatically from src/core/qgsfieldproxymodel.h
QgsFieldProxyModel.Filters.baseClass = QgsFieldProxyModel
Filters = QgsFieldProxyModel # dirty hack since SIP seems to introduce the flags in module
4 changes: 4 additions & 0 deletions python/core/auto_additions/qgsgeometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The following has been generated automatically from src/core/geometry/qgsgeometry.h
QgsGeometry.BufferSide.baseClass = QgsGeometry
QgsGeometry.EndCapStyle.baseClass = QgsGeometry
QgsGeometry.JoinStyle.baseClass = QgsGeometry
3 changes: 3 additions & 0 deletions python/core/auto_additions/qgsmaplayerproxymodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The following has been generated automatically from src/core/qgsmaplayerproxymodel.h
QgsMapLayerProxyModel.Filters.baseClass = QgsMapLayerProxyModel
Filters = QgsMapLayerProxyModel # dirty hack since SIP seems to introduce the flags in module
3 changes: 3 additions & 0 deletions python/core/auto_additions/qgssnappingconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The following has been generated automatically from src/core/qgssnappingconfig.h
QgsSnappingConfig.SnappingMode.baseClass = QgsSnappingConfig
QgsSnappingConfig.SnappingType.baseClass = QgsSnappingConfig
6 changes: 6 additions & 0 deletions python/core/auto_additions/qgsunittypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# The following has been generated automatically from src/core/qgsunittypes.h
QgsUnitTypes.DistanceUnit.baseClass = QgsUnitTypes
QgsUnitTypes.AreaUnit.baseClass = QgsUnitTypes
QgsUnitTypes.AngleUnit.baseClass = QgsUnitTypes
QgsUnitTypes.RenderUnit.baseClass = QgsUnitTypes
QgsUnitTypes.LayoutUnit.baseClass = QgsUnitTypes
5 changes: 5 additions & 0 deletions python/core/auto_additions/qgsvectorsimplifymethod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The following has been generated automatically from src/core/qgsvectorsimplifymethod.h
QgsVectorSimplifyMethod.SimplifyHint.baseClass = QgsVectorSimplifyMethod
QgsVectorSimplifyMethod.SimplifyHints.baseClass = QgsVectorSimplifyMethod
SimplifyHints = QgsVectorSimplifyMethod # dirty hack since SIP seems to introduce the flags in module
QgsVectorSimplifyMethod.SimplifyAlgorithm.baseClass = QgsVectorSimplifyMethod
File renamed without changes.
4 changes: 4 additions & 0 deletions python/gui/auto_additions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
This folder is completed using sipify.pl script
It is not aimed to be manually edited
"""
3 changes: 3 additions & 0 deletions python/gui/auto_additions/qgsadvanceddigitizingdockwidget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The following has been generated automatically from src/gui/qgsadvanceddigitizingdockwidget.h
QgsAdvancedDigitizingDockWidget.CadCapacities.baseClass = QgsAdvancedDigitizingDockWidget
CadCapacities = QgsAdvancedDigitizingDockWidget # dirty hack since SIP seems to introduce the flags in module
3 changes: 3 additions & 0 deletions python/gui/auto_additions/qgsattributetablefiltermodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The following has been generated automatically from src/gui/attributetable/qgsattributetablefiltermodel.h
QgsAttributeTableFilterModel.FilterMode.baseClass = QgsAttributeTableFilterModel
QgsAttributeTableFilterModel.ColumnType.baseClass = QgsAttributeTableFilterModel
5 changes: 5 additions & 0 deletions python/gui/auto_additions/qgsmaplayeractionregistry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The following has been generated automatically from src/gui/qgsmaplayeractionregistry.h
QgsMapLayerAction.Targets.baseClass = QgsMapLayerAction
Targets = QgsMapLayerAction # dirty hack since SIP seems to introduce the flags in module
QgsMapLayerAction.Flags.baseClass = QgsMapLayerAction
Flags = QgsMapLayerAction # dirty hack since SIP seems to introduce the flags in module
4 changes: 4 additions & 0 deletions python/gui/auto_additions/qgsmaptoolidentify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The following has been generated automatically from src/gui/qgsmaptoolidentify.h
QgsMapToolIdentify.IdentifyMode.baseClass = QgsMapToolIdentify
QgsMapToolIdentify.LayerType.baseClass = QgsMapToolIdentify
LayerType = QgsMapToolIdentify # dirty hack since SIP seems to introduce the flags in module
File renamed without changes.
4 changes: 4 additions & 0 deletions python/server/auto_additions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
This folder is completed using sipify.pl script
It is not aimed to be manually edited
"""
76 changes: 39 additions & 37 deletions scripts/sipify.pl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
my $LINE_IDX = 0;
my $LINE;
my @OUTPUT = ();
my @OUTPUT_PYTHON = ();


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

sub write_header_footer {
sub sip_header_footer {
my @header_footer = ();
# small hack to turn files src/core/3d/X.h to src/core/./3d/X.h
# otherwise "sip up to date" test fails. This is because the test uses %Include entries
# and over there we have to use ./3d/X.h entries because SIP parser does not allow a number
# as the first letter of a relative path
my $headerfile_x = $headerfile;
$headerfile_x =~ s/src\/core\/3d/src\/core\/.\/3d/;
push @OUTPUT, "/************************************************************************\n";
push @OUTPUT, " * This file has been generated automatically from *\n";
push @OUTPUT, " * *\n";
push @OUTPUT, sprintf " * %-*s *\n", 68, $headerfile_x;
push @OUTPUT, " * *\n";
push @OUTPUT, " * Do not edit manually ! Edit header and run scripts/sipify.pl again *\n";
push @OUTPUT, " ************************************************************************/\n";
push @header_footer, "/************************************************************************\n";
push @header_footer, " * This file has been generated automatically from *\n";
push @header_footer, " * *\n";
push @header_footer, sprintf " * %-*s *\n", 68, $headerfile_x;
push @header_footer, " * *\n";
push @header_footer, " * Do not edit manually ! Edit header and run scripts/sipify.pl again *\n";
push @header_footer, " ************************************************************************/\n";
return @header_footer;
}

sub python_header {
my @header = ();
my $headerfile_x = $headerfile;
$headerfile_x =~ s/src\/core\/3d/src\/core\/.\/3d/;
push @header, "# The following has been generated automatically from ";
push @header, sprintf "%s\n", $headerfile_x;
return @header;
}

sub processDoxygenLine {
Expand Down Expand Up @@ -455,9 +467,6 @@ sub detect_non_method_member{
return 0;
}


write_header_footer();

# write some code in front of line to know where the output comes from
$debug == 0 or push @OUTPUT, "CODE SIP_RUN MultiLine\n";

Expand Down Expand Up @@ -656,23 +665,14 @@ sub detect_non_method_member{
my $enum_helper = "$ACTUAL_CLASS.$2.baseClass = $ACTUAL_CLASS";
dbg_info("Q_ENUM/Q_FLAG $enum_helper");
if ($python_output ne ''){
my $pl;
open(FH, '+<', $python_output) or die $!;
foreach $pl (<FH>) {
if ($pl =~ m/$enum_helper/){
$enum_helper = '';
last;
}
}
if ($enum_helper ne ''){
push @OUTPUT_PYTHON, "$enum_helper\n";
if ($is_flag == 1){
# SIP seems to introduce the flags in the module rather than in the class itself
# as a dirty hack, inject directly in module, hopefully we don't have flags with the same name....
$enum_helper .= "\n$2 = $ACTUAL_CLASS # dirty hack since SIP seems to introduce the flags in module";
push @OUTPUT_PYTHON, "$2 = $ACTUAL_CLASS # dirty hack since SIP seems to introduce the flags in module\n";
}
print FH "$enum_helper\n";
}
close(FH);
}
}
next;
Expand Down Expand Up @@ -705,21 +705,10 @@ sub detect_non_method_member{
my $pyop = "${ACTUAL_CLASS}.__" . lc($1) . "__ = lambda self: self.$2()";
dbg_info("PYTHON OPERATOR $pyop");
if ($python_output ne ''){
my $pl;
open(FH, '+<', $python_output) or die $!;
foreach $pl (<FH>) {
if ($pl =~ m/$pyop/){
$pyop = '';
last;
}
}
if ($pyop ne ''){
print FH "$pyop\n";
}
close(FH);
}
push @OUTPUT_PYTHON, "$pyop\n";
}
}

$COMMENT = '';
next;
}
Expand Down Expand Up @@ -1190,12 +1179,25 @@ sub detect_non_method_member{
$IS_OVERRIDE = 0;
}
}
write_header_footer();

if ( $sip_output ne ''){
open(FH, '>', $sip_output) or die $!;
print FH join('', sip_header_footer());
print FH join('',@OUTPUT);
print FH join('', sip_header_footer());
close(FH);
} else {
print join('', sip_header_footer());
print join('',@OUTPUT);
print join('', sip_header_footer());
}

if ( $python_output ne '' ){
unlink $python_output or 1;
if ( $#OUTPUT_PYTHON > 0 ){
open(FH2, '>', $python_output) or die $!;
print FH2 join('', python_header());
print FH2 join('', @OUTPUT_PYTHON);
close(FH2);
}
}
3 changes: 2 additions & 1 deletion scripts/sipify_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ for module in "${modules[@]}"; do
while read -r sipfile; do
echo "$sipfile.in"
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)
pyfile=$(${GP}sed -E 's@([^\/]+\/)*([^\/]+)\.sip@\2.py@;' <<< $sipfile)
if [ ! -f $header ]; then
echo "*** Missing header: $header for sipfile $sipfile"
else
path=$(${GP}sed -r 's@/[^/]+$@@' <<< $sipfile)
mkdir -p python/$path
./scripts/sipify.pl -s python/$sipfile.in -p python/${module}/__init__.py $header &
./scripts/sipify.pl -s python/$sipfile.in -p python/${module}/auto_additions/${pyfile} $header &
fi
count=$((count+1))
done < <( ${GP}sed -n -r "s@^%Include auto_generated/(.*\.sip)@${module}/auto_generated/\1@p" python/${module}/${module}_auto.sip )
Expand Down
9 changes: 7 additions & 2 deletions tests/code_layout/test_sipfiles_uptodate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ for module in "${modules[@]}"; do
cp ${module_init} ${DIR}/${module}.temp
while read -r sipfile; do
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)
pyfile=$(${GP}sed -E 's@([^\/]+\/)*([^\/]+)\.sip@\2.py@;' <<< $sipfile)
if [ ! -f $header ]; then
echo "*** Missing header: $header for sipfile $sipfile"
else
outdiff=$(./scripts/sipify.pl -p ${DIR}/${module}.temp $header | diff python/$sipfile.in -)
outdiff=$(./scripts/sipify.pl -p python/${module}/auto_additions/${pyfile}.temp $header | diff python/$sipfile.in -)
outdiff2=$(diff python/${module}/auto_additions/${pyfile} python/${module}/auto_additions/${pyfile}.temp)
if [[ -n "$outdiff" ]]; then
echo " *** SIP file not up to date: $sipfile"
code=1
fi
if [[ -n "$outdiff2" ]]; then
echo " *** Python addition file not up to date: $sipfile"
code=1
fi
fi
done < <(
${GP}sed -n -r "s@^%Include auto_generated/(.*\.sip)@${module}/auto_generated/\1@p" python/${module}/${module}_auto.sip
Expand All @@ -37,7 +43,6 @@ for module in "${modules[@]}"; do
echo " *** Python ${module} (${module_init}) init not up to date: run sipify with -p argument"
code=1
fi
rm ${DIR}/${module}.temp
done


Expand Down

0 comments on commit e5b02cd

Please sign in to comment.