Skip to content

Commit

Permalink
Merge branch 'main' into revise-root-testsuite-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
nilason committed Oct 15, 2024
2 parents 662e888 + ca171b7 commit 44d70a2
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 45 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ omit =
${INITIAL_PWD-.}/.github/*
${INITIAL_PWD-.}/bin.*/*
${INITIAL_PWD-.}/dist.*/*
**/gui/wxpython/*/**
**/OBJ.*/*
source =
.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
if: ${{ matrix.language == 'c-cpp' }}

- name: Initialize CodeQL
uses: github/codeql-action/init@c36620d31ac7c881962c3d9dd939c40ec9434f2b # v3.26.12
uses: github/codeql-action/init@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml
Expand All @@ -81,6 +81,6 @@ jobs:
run: .github/workflows/build_ubuntu-22.04.sh "${HOME}/install"

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@c36620d31ac7c881962c3d9dd939c40ec9434f2b # v3.26.12
uses: github/codeql-action/analyze@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
with:
category: "/language:${{matrix.language}}"
11 changes: 9 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,25 @@ jobs:
run: |
export PYTHONPATH=`grass --config python_path`:$PYTHONPATH
export LD_LIBRARY_PATH=$(grass --config path)/lib:$LD_LIBRARY_PATH
export INITIAL_GISBASE="$(grass --config path)"
export INITIAL_PWD="${PWD}"
pytest --verbose --color=yes --durations=0 --durations-min=0.5 \
--numprocesses auto -ra . \
--numprocesses auto \
--cov \
--cov-context=test \
-ra . \
-m 'not needs_solo_run'
- name: Run pytest with a single worker (for tests marked with needs_solo_run)
run: |
export PYTHONPATH=`grass --config python_path`:$PYTHONPATH
export LD_LIBRARY_PATH=$(grass --config path)/lib:$LD_LIBRARY_PATH
export INITIAL_GISBASE="$(grass --config path)"
INITIAL_PWD="${PWD}" pytest --verbose --color=yes --durations=0 --durations-min=0.5 \
export INITIAL_PWD="${PWD}"
pytest --verbose --color=yes --durations=0 --durations-min=0.5 \
--cov \
--cov-context=test \
--cov-append \
-ra . \
-m 'needs_solo_run'
- name: Fix non-standard installed script paths in coverage data
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
path: bandit.sarif

- name: Upload SARIF File into Security Tab
uses: github/codeql-action/upload-sarif@c36620d31ac7c881962c3d9dd939c40ec9434f2b # v3.26.12
uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
with:
sarif_file: bandit.sarif

Expand Down
4 changes: 3 additions & 1 deletion gui/wxpython/lmgr/giface.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def __init__(self, tree):
self._tree = tree

def __len__(self):
return len(list(self))
# The list constructor calls __len__ as an optimization if available,
# causing a RecursionError
return len([layer for layer in self]) # noqa: C416

def __iter__(self):
"""Iterates over the contents of the list."""
Expand Down
2 changes: 1 addition & 1 deletion lib/raster/mask_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int Rast__mask_info(char *name, char *mapset)
char rname[GNAME_MAX], rmapset[GMAPSET_MAX];

strcpy(rname, "MASK");
strcpy(rmapset, G_mapset());
(void)G_strlcpy(rmapset, G_mapset(), GMAPSET_MAX);

if (!G_find_raster(rname, rmapset))
return -1;
Expand Down
22 changes: 13 additions & 9 deletions lib/vector/Vlib/geos.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ GEOSCoordSequence *V1_read_line_geos(struct Map_info *Map, long offset,
long size;
double *x, *y, *z;

GEOSCoordSequence *pseq;
GEOSCoordSequence *pseq = NULL;

G_debug(3, "V1_read_line_geos(): offset = %ld", offset);

Expand Down Expand Up @@ -353,26 +353,29 @@ GEOSCoordSequence *V1_read_line_geos(struct Map_info *Map, long offset,
G_debug(3, " n_points = %d dim = %d", n_points,
(Map->head.with_z) ? 3 : 2);

pseq = GEOSCoordSeq_create(n_points, (Map->head.with_z) ? 3 : 2);

x = (double *)G_malloc(n_points * sizeof(double));
y = (double *)G_malloc(n_points * sizeof(double));
if (Map->head.with_z)
z = (double *)G_malloc(n_points * sizeof(double));
else
z = NULL;

if (0 >= dig__fread_port_D(x, n_points, &(Map->dig_fp)))
return NULL; /* end of file */
if (0 >= dig__fread_port_D(x, n_points, &(Map->dig_fp))) {
goto free_return; /* end of file */
}

if (0 >= dig__fread_port_D(y, n_points, &(Map->dig_fp)))
return NULL; /* end of file */
if (0 >= dig__fread_port_D(y, n_points, &(Map->dig_fp))) {
goto free_return; /* end of file */
}

if (Map->head.with_z) {
if (0 >= dig__fread_port_D(z, n_points, &(Map->dig_fp)))
return NULL; /* end of file */
if (0 >= dig__fread_port_D(z, n_points, &(Map->dig_fp))) {
goto free_return; /* end of file */
}
}

pseq = GEOSCoordSeq_create(n_points, (Map->head.with_z) ? 3 : 2);

for (i = 0; i < n_points; i++) {
GEOSCoordSeq_setX(pseq, i, x[i]);
GEOSCoordSeq_setY(pseq, i, y[i]);
Expand All @@ -382,6 +385,7 @@ GEOSCoordSequence *V1_read_line_geos(struct Map_info *Map, long offset,

G_debug(3, " off = %ld", (long)dig_ftell(&(Map->dig_fp)));

free_return:
G_free((void *)x);
G_free((void *)y);
if (z)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ ignore = [
"PLW1641", # eq-without-hash
"PLW2901", # redefined-loop-name
"PLW3201", # bad-dunder-method-name
"PT004", # pytest-missing-fixture-name-underscore # deprecated, so doesn't appear with --preview
"PTH100", # os-path-abspath
"PTH101", # os-chmod
"PTH102", # os-mkdir
Expand Down
2 changes: 2 additions & 0 deletions raster/r.mask.status/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ int report_status(struct Parameters *params)
else
json_object_set_null(root_object, "is_reclass_of");
char *serialized_string = json_serialize_to_string_pretty(root_value);
if (!serialized_string)
G_fatal_error(_("Failed to initialize pretty JSON string."));
puts(serialized_string);
json_free_serialized_string(serialized_string);
json_value_free(root_value);
Expand Down
52 changes: 28 additions & 24 deletions testsuite/raster_md5test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ if [ -z "$GISBASE" ] ; then
fi

#### check if we have sed
if [ ! -x "`which sed`" ] ; then
if [ ! -x "$(which sed)" ] ; then
echo "$PROG: sed required, please install first" 1>&2
exit 1
fi

#### check if we have md5sum
if [ ! -x "`which md5sum`" ] ; then
echo "$PROG: md5sum required, please install first" 1>&2
exit 1
#### check if we have md5sum or md5
if [ -x "$(which md5sum)" ] ; then
MD5="md5sum | cut -d' ' -f1"
elif [ -x "$(which md5)" ] ; then
MD5="md5 -q"
else
echo "$PROG: md5sum or md5 required, please install first" 1>&2
exit 1
fi

#### check if we have cut
if [ ! -x "`which cut`" ] ; then
if [ ! -x "$(which cut)" ] ; then
echo "$PROG: cut required, please install first" 1>&2
exit 1
fi
Expand All @@ -38,47 +42,47 @@ export LC_NUMERIC=C
# enforce ZLIB
export GRASS_COMPRESSOR=ZLIB

eval `g.gisenv`
: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
eval "$(g.gisenv)"
: "${GISBASE?}" "${GISDBASE?}" "${LOCATION_NAME?}" "${MAPSET?}"
MAPSET_PATH=$GISDBASE/$LOCATION_NAME/$MAPSET

# some definitions
PIXEL=3
PID=$$
TMPNAME="`echo ${PID}_tmp_testmap | sed 's+\.+_+g'`"
TMPNAME=$(echo ${PID}_tmp_testmap | sed 's+\.+_+g')

# some functions - keep order here
cleanup()
{
echo "Removing temporary map"
g.remove -f type=raster name=$TMPNAME > /dev/null
g.remove -f type=raster name="$TMPNAME" > /dev/null
}

# check if a MASK is already present:
MASKTMP=mask.$TMPNAME
USERMASK=usermask_${MASKTMP}
if test -f $MAPSET_PATH/cell/MASK
MASKTMP="mask.${TMPNAME}"
USERMASK="usermask_${MASKTMP}"
if test -f "${MAPSET_PATH}/cell/MASK"
then
echo "A user raster mask (MASK) is present. Saving it..."
g.rename raster=MASK,$USERMASK > /dev/null
g.rename raster=MASK,"$USERMASK" > /dev/null
fi

finalcleanup()
{
echo "Restoring user region"
g.region region=$TMPNAME
g.remove -f type=region name=$TMPNAME > /dev/null
g.region region="$TMPNAME"
g.remove -f type=region name="$TMPNAME" > /dev/null
#restore user mask if present:
if test -f $MAPSET_PATH/cell/$USERMASK ; then
if test -f "${MAPSET_PATH}/cell/${USERMASK}" ; then
echo "Restoring user MASK"
g.remove -f type=raster name=MASK > /dev/null
g.rename raster=$USERMASK,MASK > /dev/null
g.rename raster="$USERMASK",MASK > /dev/null
fi
}

check_exit_status()
{
if [ $1 -ne 0 ] ; then
if [ "$1" -ne 0 ] ; then
echo "An error occurred."
cleanup ; finalcleanup
exit 1
Expand Down Expand Up @@ -106,7 +110,7 @@ check_md5sum()
}

echo "Saving current & setting test region."
g.region save=$TMPNAME
g.region save="$TMPNAME"
check_exit_status $?
g.region s=0 n=$PIXEL w=0 e=$PIXEL res=1 tbres=1
check_exit_status $?
Expand All @@ -118,8 +122,8 @@ r.mapcalc "$TMPNAME = 1"
check_exit_status $?

echo "MD5 checksum on output of INT/CELL test."
MD5="`r.out.ascii $TMPNAME precision=15 | md5sum | cut -d' ' -f1`"
check_md5sum "549e7dabe70df893803690571d2e1503" "$MD5"
SUM=$(r.out.ascii "$TMPNAME" precision=15 | eval "$MD5")
check_md5sum "549e7dabe70df893803690571d2e1503" "$SUM"

cleanup
echo "INT/CELL md5sum test successful"
Expand All @@ -132,8 +136,8 @@ r.mapcalc "$TMPNAME = $VALUE"
check_exit_status $?

echo "MD5 checksum on output of FLOAT/FCELL test."
MD5="`r.out.ascii $TMPNAME precision=15 | md5sum | cut -d' ' -f1`"
check_md5sum "379f3d880b6d509051af6b4ccf470762" "$MD5"
SUM=$(r.out.ascii "$TMPNAME" precision=15 | eval "$MD5")
check_md5sum "379f3d880b6d509051af6b4ccf470762" "$SUM"

cleanup
echo "FLOAT/FCELL md5sum test successful"
Expand Down
6 changes: 4 additions & 2 deletions utils/coverage_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ def map_scripts_paths(old_path):
if INITIAL_GISBASE is None or INITIAL_PWD is None:
return old_path
p = Path(old_path)
extension = ".py"
p_name = p.stem if p.suffix == extension else p.name
temporal_base = Path(INITIAL_GISBASE) / "scripts" / "t.*"
base = Path(INITIAL_GISBASE) / "scripts" / "*"
if p.match(str(temporal_base)):
return str(Path(INITIAL_PWD) / "temporal" / (p.name) / (p.name)) + ".py"
return str(Path(INITIAL_PWD) / "temporal" / (p_name) / (p_name)) + extension
if p.match(str(base)):
return str(Path(INITIAL_PWD) / "scripts" / (p.name) / (p.name)) + ".py"
return str(Path(INITIAL_PWD) / "scripts" / (p_name) / (p_name)) + extension

return old_path

Expand Down
4 changes: 3 additions & 1 deletion vector/v.kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,9 @@ double compute_all_net_distances(struct Map_info *In, struct Map_info *Net,
G_debug(3, " kk = %d", kk);
}
}

Vect_destroy_line_struct(APoints);
Vect_destroy_line_struct(BPoints);
Vect_destroy_boxlist(List);
return (kk);
}

Expand Down
5 changes: 3 additions & 2 deletions vector/v.net.timetable/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ void write_subroute(struct segment *seg, struct line_pnts *line, int line_id)
struct line_cats *Cats;
struct ilist *list;

Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
list = Vect_new_list();
r = seg->route;

Vect_cat_set(Cats, 2, line_id);
Expand All @@ -188,6 +186,9 @@ void write_subroute(struct segment *seg, struct line_pnts *line, int line_id)
return;
}

Points = Vect_new_line_struct();
list = Vect_new_list();

for (i = 0; i < nnodes; i++)
edges[i] = 0;
for (i = 0; i < lines[r]->n_values; i++)
Expand Down

0 comments on commit 44d70a2

Please sign in to comment.