Skip to content

Commit

Permalink
Merge branch 'main' into gmodeler_panel
Browse files Browse the repository at this point in the history
  • Loading branch information
landam authored Apr 8, 2024
2 parents c1c010f + 2c93249 commit aa03ca0
Show file tree
Hide file tree
Showing 22 changed files with 322 additions and 106 deletions.
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:
sudo apt-get install -y --no-install-recommends --no-install-suggests
- name: Initialize CodeQL
uses: github/codeql-action/init@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
uses: github/codeql-action/init@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml
Expand All @@ -82,6 +82,6 @@ jobs:
run: .github/workflows/build_ubuntu-22.04.sh "${HOME}/install"

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
uses: github/codeql-action/analyze@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
with:
category: "/language:${{matrix.language}}"
1 change: 1 addition & 0 deletions .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ jobs:
coverity_url: ${{ secrets.COVERITY_URL }} # The URL to Coverity
coverity_user: ${{ secrets.COVERITY_USER }} # The user for the Coverity project
coverity_passphrase: ${{ secrets.COVERITY_PASSPHRASE }} # The password for the Coverity user
coverity_version: '2023.6.2' # The version for Coverity Scan
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Login to DockerHub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
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 @@ -108,7 +108,7 @@ jobs:
path: bandit.sarif

- name: Upload SARIF File into Security Tab
uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
uses: github/codeql-action/upload-sarif@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
with:
sarif_file: bandit.sarif

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# list of files that changed across commits
fetch-depth: 0
- name: Lint code base
uses: super-linter/super-linter/slim@e0fc164bba85f4b58c6cd17ba1dfd435d01e8a06 # v6.3.0
uses: super-linter/super-linter/slim@92e2606383320f72e6129f8a50d8537cf9c84ed6 # v6.3.1
env:
DEFAULT_BRANCH: main
# To report GitHub Actions status checks
Expand Down
41 changes: 26 additions & 15 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -10473,42 +10473,53 @@ pdal::PointTable table;
_ACEOF
if ac_fn_cxx_try_link "$LINENO"
then :

PDAL_LIBS="$PDAL_LIBS"
else $as_nop

as_fn_error $? "*** Unable to locate suitable (>=1.7.1) PDAL library." "$LINENO" 5

fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext


printf "%s\n" "#define HAVE_PDAL 1" >>confdefs.h


{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to use PDAL NoFilenameWriter" >&5
printf %s "checking whether to use PDAL NoFilenameWriter... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <pdal/PointTable.hpp>
#include <pdal/Streamable.hpp>
class St:public pdal::Streamable {};
#include <pdal/Writer.hpp>
class St:public pdal::NoFilenameWriter {};
int
main (void)
{
pdal::PointTable table;
class NFWTest : public pdal::NoFilenameWriter {};
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"
then :
PDAL_LIBS="$PDAL_LIBS"
else $as_nop

as_fn_error $? "*** Unable to locate suitable (>=1.7.1) PDAL library." "$LINENO" 5

fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext
printf "%s\n" "#define HAVE_PDAL_NOFILENAMEWRITER 1" >>confdefs.h

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }

else $as_nop
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext

LIBS=${ac_save_libs}
CFLAGS=${ac_save_cflags}


printf "%s\n" "#define HAVE_PDAL 1" >>confdefs.h

fi


Expand Down
22 changes: 15 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1076,17 +1076,25 @@ else
CFLAGS="$CFLAGS $PDAL_CFLAGS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pdal/PointTable.hpp>
#include <pdal/Streamable.hpp>
class St:public pdal::Streamable {};]], [[pdal::PointTable table;]])],[],[
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pdal/PointTable.hpp>
#include <pdal/Streamable.hpp>
class St:public pdal::Streamable {};]], [[pdal::PointTable table;]])],[PDAL_LIBS="$PDAL_LIBS"],[
class St:public pdal::Streamable {};]], [[pdal::PointTable table;]])],
[PDAL_LIBS="$PDAL_LIBS"],[
AC_MSG_ERROR([*** Unable to locate suitable (>=1.7.1) PDAL library.])
])
])
LIBS=${ac_save_libs}
CFLAGS=${ac_save_cflags}

AC_DEFINE(HAVE_PDAL, 1, [Define to 1 if PDAL exists.])

AC_MSG_CHECKING(whether to use PDAL NoFilenameWriter)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pdal/Writer.hpp>
class St:public pdal::NoFilenameWriter {};]], [[
class NFWTest : public pdal::NoFilenameWriter {};
]])],
[
AC_DEFINE(HAVE_PDAL_NOFILENAMEWRITER, 1, [Define to 1 if PDAL NoFilenameWriter is present.])
AC_MSG_RESULT(yes)
],[AC_MSG_RESULT(no)])

LIBS=${ac_save_libs}
CFLAGS=${ac_save_cflags}
fi

AC_SUBST(PDAL_LIBS)
Expand Down
3 changes: 3 additions & 0 deletions include/grass/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@
/* Define to 1 if PDAL exists. */
#undef HAVE_PDAL

/* Define to 1 if PDAL NoFilenameWriter is present. */
#undef HAVE_PDAL_NOFILENAMEWRITER

/* Define to 1 if glXCreateGLXPixmap exists. */
#undef HAVE_PIXMAPS

Expand Down
2 changes: 1 addition & 1 deletion lib/gis/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void G_init_logging(void)
if (!logfile) {
char buf[GPATH_MAX];

sprintf(buf, "%s/GIS_ERROR_LOG", G__home());
snprintf(buf, GPATH_MAX, "%s/GIS_ERROR_LOG", G__home());
logfile = G_store(buf);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/gis/mapset_msc.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,15 @@ int G_make_mapset_object_group_basedir(const char *type, const char *basedir)
int make_mapset_element_impl(const char *p_path, const char *p_element,
bool race_ok)
{
char path[GPATH_MAX], *p;
char path[GPATH_MAX] = {'\0'};
char *p;
const char *element;

element = p_element;
if (*element == 0)
return 0;

strncpy(path, p_path, GPATH_MAX);
strncpy(path, p_path, GPATH_MAX - 1);
p = path;
while (*p)
p++;
Expand Down
2 changes: 2 additions & 0 deletions python/grass/jupyter/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import os
import weakref
from pathlib import Path

import grass.script as gs

Expand Down Expand Up @@ -87,6 +88,7 @@ def switch_mapset(self, path, location=None, mapset=None):
if (
not location
and not mapset
and len(Path(path).parts) == 1
and mapset_exists(
path=gisenv["GISDBASE"], location=gisenv["LOCATION_NAME"], mapset=path
)
Expand Down
106 changes: 66 additions & 40 deletions python/grass/script/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import random
import shlex
from tempfile import NamedTemporaryFile
from pathlib import Path

from .utils import KeyValue, parse_key_val, basename, encode, decode, try_remove
from grass.exceptions import ScriptError, CalledModuleError
from grass.grassdb.manage import resolve_mapset_path


# subprocess wrapper that uses shell on Windows
Expand Down Expand Up @@ -1697,9 +1699,16 @@ def mapsets(search_path=False, env=None):
# interface to `g.proj -c`


def create_location(
dbase,
location,
def create_location(*args, **kwargs):
if "location" in kwargs:
kwargs["name"] = kwargs["location"]
del kwargs["location"]
return create_project(*args, **kwargs)


def create_project(
path,
name=None,
epsg=None,
proj4=None,
filename=None,
Expand All @@ -1709,44 +1718,34 @@ def create_location(
desc=None,
overwrite=False,
):
"""Create new location
"""Create new project
Raise ScriptError on error.
:param str dbase: path to GRASS database
:param str location: location name to create
:param epsg: if given create new location based on EPSG code
:param proj4: if given create new location based on Proj4 definition
:param str filename: if given create new location based on georeferenced file
:param str wkt: if given create new location based on WKT definition
:param str path: path to GRASS database or project; if path to database, project
name must be specified with name parameter
:param str name: project name to create
:param epsg: if given create new project based on EPSG code
:param proj4: if given create new project based on Proj4 definition
:param str filename: if given create new project based on georeferenced file
:param str wkt: if given create new project based on WKT definition
(can be path to PRJ file or WKT string)
:param datum: GRASS format datum code
:param datum_trans: datum transformation parameters (used for epsg and proj4)
:param desc: description of the location (creates MYNAME file)
:param bool overwrite: True to overwrite location if exists(WARNING:
ALL DATA from existing location ARE DELETED!)
:param desc: description of the project (creates MYNAME file)
:param bool overwrite: True to overwrite project if exists (WARNING:
ALL DATA from existing project ARE DELETED!)
"""
# create dbase if not exists
if not os.path.exists(dbase):
os.mkdir(dbase)
# Add default mapset to project path if needed
if not name:
path = os.path.join(path, "PERMANENT")

# check if location already exists
if os.path.exists(os.path.join(dbase, location)):
if not overwrite:
warning(_("Location <%s> already exists. Operation canceled.") % location)
return
else:
warning(
_("Location <%s> already exists and will be overwritten") % location
)
shutil.rmtree(os.path.join(dbase, location))
# resolve dbase, location and mapset
mapset_path = resolve_mapset_path(path=path, location=name)

stdin = None
kwargs = dict()
if datum:
kwargs["datum"] = datum
if datum_trans:
kwargs["datum_trans"] = datum_trans
# create dbase if not exists
if not os.path.exists(mapset_path.directory):
os.mkdir(mapset_path.directory)

# Lazy-importing to avoid circular dependencies.
# pylint: disable=import-outside-toplevel
Expand All @@ -1761,16 +1760,38 @@ def create_location(
if epsg or proj4 or filename or wkt:
# The names don't really matter here.
tmp_gisrc, env = create_environment(
dbase, "<placeholder>", "<placeholder>", env=env
mapset_path.directory, mapset_path.location, mapset_path.mapset, env=env
)

# check if location already exists
if Path(mapset_path.directory, mapset_path.location).exists():
if not overwrite:
fatal(
_("Location <%s> already exists. Operation canceled.")
% mapset_path.location,
env=env,
)
warning(
_("Location <%s> already exists and will be overwritten")
% mapset_path.location,
env=env,
)
shutil.rmtree(os.path.join(mapset_path.directory, mapset_path.location))

stdin = None
kwargs = dict()
if datum:
kwargs["datum"] = datum
if datum_trans:
kwargs["datum_trans"] = datum_trans

if epsg:
ps = pipe_command(
"g.proj",
quiet=True,
flags="t",
epsg=epsg,
location=location,
location=mapset_path.location,
stderr=PIPE,
env=env,
**kwargs,
Expand All @@ -1781,7 +1802,7 @@ def create_location(
quiet=True,
flags="t",
proj4=proj4,
location=location,
location=mapset_path.location,
stderr=PIPE,
env=env,
**kwargs,
Expand All @@ -1791,28 +1812,33 @@ def create_location(
"g.proj",
quiet=True,
georef=filename,
location=location,
location=mapset_path.location,
stderr=PIPE,
env=env,
)
elif wkt:
if os.path.isfile(wkt):
ps = pipe_command(
"g.proj", quiet=True, wkt=wkt, location=location, stderr=PIPE, env=env
"g.proj",
quiet=True,
wkt=wkt,
location=mapset_path.location,
stderr=PIPE,
env=env,
)
else:
ps = pipe_command(
"g.proj",
quiet=True,
wkt="-",
location=location,
location=mapset_path.location,
stderr=PIPE,
stdin=PIPE,
env=env,
)
stdin = encode(wkt)
else:
_create_location_xy(dbase, location)
_create_location_xy(mapset_path.directory, mapset_path.location)

if epsg or proj4 or filename or wkt:
error = ps.communicate(stdin)[1]
Expand All @@ -1821,7 +1847,7 @@ def create_location(
if ps.returncode != 0 and error:
raise ScriptError(repr(error))

_set_location_description(dbase, location, desc)
_set_location_description(mapset_path.directory, mapset_path.location, desc)


def _set_location_description(path, location, text):
Expand Down
Loading

0 comments on commit aa03ca0

Please sign in to comment.