Skip to content

Commit

Permalink
Merge branch 'main' into manual_html2md
Browse files Browse the repository at this point in the history
  • Loading branch information
neteler authored Nov 23, 2024
2 parents 2076251 + ab67825 commit 7524c52
Show file tree
Hide file tree
Showing 30 changed files with 106 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# renovate: datasource=pypi depName=bandit
BANDIT_VERSION: "1.7.10"
# renovate: datasource=pypi depName=ruff
RUFF_VERSION: "0.7.4"
RUFF_VERSION: "0.8.0"

runs-on: ${{ matrix.os }}
permissions:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ repos:
)
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.4
rev: v0.8.0
hooks:
# Run the linter.
- id: ruff
args: [--fix, --preview]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.42.0
rev: v0.43.0
hooks:
- id: markdownlint-fix
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
Expand Down
4 changes: 2 additions & 2 deletions display/d.text/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def text(in_text):
print(
".L 0\n"
+ re.sub(
'(".*?")',
r'(".*?")',
"\n.C red\n,\\g<0>\n.C gray\n",
re.sub("\n", "\n.L 1\n.L 0\n", re.sub("(?m)^#.*\n?", "", src)),
re.sub(r"\n", "\n.L 1\n.L 0\n", re.sub(r"(?m)^#.*\n?", "", src)),
)
)
2 changes: 1 addition & 1 deletion gui/wxpython/gmodeler/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2672,7 +2672,7 @@ def _getParamName(self, parameter_name, item):
@staticmethod
def _getModuleNickname(item):
return "{module_name}{module_id}".format(
module_name=re.sub("[^a-zA-Z]+", "", item.GetLabel()),
module_name=re.sub(r"[^a-zA-Z]+", "", item.GetLabel()),
module_id=item.GetId(),
)

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/photo2image/ip2i_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def __init__(
fc_count = 0
for line in fc:
fc_count += 1
if re.search("NUM", line):
if re.search(r"NUM", line):
storeLine = fc_count
numberOfFiducial = int(line.split()[-1])
dataFiducialX = []
Expand Down
2 changes: 1 addition & 1 deletion include/Make/DB.make
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include $(MODULE_TOPDIR)/include/Make/Compile.make

dbmi: $(DBDRIVERDIR)/$(PGM)$(EXE) db_html

db_html: $(HTMLDIR)/grass-$(PGM).html $(MANDIR)/grass-$(PGM).$(MANSECT)
db_html: $(HTMLDIR)/grass-$(PGM).html $(MANDIR)/grass-$(PGM).$(MANSECT) # $(MDDIR)/source/grass-$(PGM).md

$(DBDRIVERDIR)/$(PGM)$(EXE): $(ARCH_OBJS) $(DEPENDENCIES)
$(call linker)
Expand Down
7 changes: 4 additions & 3 deletions lib/gis/parser_rest_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ void print_escaped_for_md_keywords(FILE *f, const char *str)
fputc(*s, f);
}
}
fprintf(f, ".html)");
fprintf(f, ".md)");
}
else { /* first and other than second keyword */
if (st->n_keys > 0 && strcmp(st->module_info.keywords[0], str) == 0) {
Expand All @@ -532,13 +532,14 @@ void print_escaped_for_md_keywords(FILE *f, const char *str)
fputc(*s, f);
}
}
fprintf(f, ".html)");
fprintf(f, ".md)");
}
else {
/* keyword index */
char *str_link;
str_link = G_str_replace(str_s, " ", "%20");
fprintf(f, "[%s](keywords.html#%s)", str_s, str_link);
G_str_to_lower(str_link);
fprintf(f, "[%s](keywords.md#%s)", str_s, str_link);
G_free(str_link);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/init/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ def load_env(grass_env_file):
# Regular expression for lines starting with "export var=val" (^export
# lines below). Environment variables should start with a-zA-Z or _.
# \1 and \2 are a variable name and its value, respectively.
export_re = re.compile("^export[ \t]+([a-zA-Z_]+[a-zA-Z0-9_]*)=(.*?)[ \t]*$")
export_re = re.compile(r"^export[ \t]+([a-zA-Z_]+[a-zA-Z0-9_]*)=(.*?)[ \t]*$")

for line in readfile(grass_env_file).splitlines():
# match ^export lines
Expand Down
15 changes: 10 additions & 5 deletions lib/vector/Vlib/dbcolumns.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const char *Vect_get_column_names_types(struct Map_info *Map, int field)
dbHandle handle;
dbString table_name;
dbTable *table;
const char **col_type_names;
char **col_type_names;
char *list;

num_dblinks = Vect_get_num_dblinks(Map);
Expand All @@ -180,16 +180,21 @@ const char *Vect_get_column_names_types(struct Map_info *Map, int field)
ncols = db_get_table_number_of_columns(table);
col_type_names = G_malloc(ncols * sizeof(char *));
for (col = 0; col < ncols; col++) {
char buf[256];
col_type_names[col] = (char *)G_calloc(256, sizeof(char));

sprintf(buf, "%s(%s)",
sprintf(col_type_names[col], "%s(%s)",
db_get_column_name(db_get_table_column(table, col)),
db_sqltype_name(
db_get_column_sqltype(db_get_table_column(table, col))));
col_type_names[col] = buf;
}
if ((list = G_str_concat(col_type_names, ncols, ",", BUFF_MAX)) == NULL)

if ((list = G_str_concat((const char **)col_type_names, ncols, ",",
BUFF_MAX)) == NULL)
list = G_store("");

for (col = 0; col < ncols; col++) {
G_free(col_type_names[col]);
}
G_free(col_type_names);
G_debug(3, "%s", list);

Expand Down
2 changes: 1 addition & 1 deletion man/build_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,6 @@ def get_desc(cmd):

############################################################################

man_dir = os.path.join(os.environ["MDDIR"], "source")
man_dir = os.path.join(os.environ["ARCH_DISTDIR"], "docs", "mkdocs", "source")

############################################################################
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extend-exclude = '''
'''

[tool.ruff]
required-version = ">=0.6.0"
required-version = ">=0.8.0"

builtins = ["_"]

Expand Down Expand Up @@ -183,7 +183,6 @@ 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
4 changes: 2 additions & 2 deletions python/grass/gunittest/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,10 +1320,10 @@ def runModule(cls, module, expecting_stdout=False, **kwargs):
# TODO: standardized error code would be handy here
import re

if re.search("Raster map.*not found", errors, flags=re.DOTALL):
if re.search(r"Raster map.*not found", errors, flags=re.DOTALL):
errors += "\nSee available raster maps:\n"
errors += call_module("g.list", type="raster")
if re.search("Vector map.*not found", errors, flags=re.DOTALL):
if re.search(r"Vector map.*not found", errors, flags=re.DOTALL):
errors += "\nSee available vector maps:\n"
errors += call_module("g.list", type="vector")
# TODO: message format, parameters
Expand Down
8 changes: 4 additions & 4 deletions python/grass/script/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def convert(text):

def alphanum_key(actual_key):
sort_key = key(actual_key) if key else actual_key
return [convert(c) for c in re.split("([0-9]+)", sort_key)]
return [convert(c) for c in re.split(r"([0-9]+)", sort_key)]

items.sort(key=alphanum_key)

Expand Down Expand Up @@ -501,15 +501,15 @@ def legalize_vector_name(name, fallback_prefix="x"):
# The implementation is based on Vect_legal_filename().
if not name:
raise ValueError("name cannot be empty")
if fallback_prefix and re.match("[^A-Za-z]", fallback_prefix[0]):
if fallback_prefix and re.match(r"[^A-Za-z]", fallback_prefix[0]):
raise ValueError("fallback_prefix must start with an ASCII letter")
if fallback_prefix and re.match("[^A-Za-z]", name[0], flags=re.ASCII):
if fallback_prefix and re.match(r"[^A-Za-z]", name[0], flags=re.ASCII):
# We prefix here rather than just replace, because in cases of unique
# identifiers, e.g., columns or node names, replacing the first
# character by the same replacement character increases chances of
# conflict (e.g. column names 10, 20, 30).
name = "{fallback_prefix}{name}".format(**locals())
name = re.sub("[^A-Za-z0-9_]", "_", name, flags=re.ASCII)
name = re.sub(r"[^A-Za-z0-9_]", "_", name, flags=re.ASCII)
keywords = ["and", "or", "not"]
if name in keywords:
name = "{name}_".format(**locals())
Expand Down
19 changes: 19 additions & 0 deletions raster/r.to.vect/areas_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ int write_area(

catNum = 1;

if (centroid_flag) {
Vect_build_partial(&Map, GV_BUILD_ATTACH_ISLES);
}

G_important_message(_("Writing areas..."));
for (i = 0, p = a_list; i < n_areas; i++, p++) {
G_percent(i, n_areas, 3);
Expand Down Expand Up @@ -327,6 +331,21 @@ int write_area(
break;
}

if (centroid_flag) {
int area, ret;

area = Vect_find_area(&Map, x, y);
if (area == 0) {
G_warning(_("No area for centroid %d"), i);
}
else {
ret = Vect_get_point_in_area(&Map, area, &x, &y);
if (ret < 0) {
G_warning(_("Unable to calculate area centroid"));
}
}
}

Vect_reset_line(points);
Vect_append_point(points, x, y, 0.0);

Expand Down
3 changes: 2 additions & 1 deletion raster/r.to.vect/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ extern int n_alloced_ptrs;

extern int
smooth_flag; /* this is 0 for no smoothing, 1 for smoothing of lines */
extern int value_flag; /* use raster values as categories */
extern int value_flag; /* use raster values as categories */
extern int centroid_flag; /* re-center centroids */

extern struct Categories RastCats;
extern int has_cats; /* Category labels available */
Expand Down
15 changes: 13 additions & 2 deletions raster/r.to.vect/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ int row_length, row_count, n_rows;
int total_areas;
int n_alloced_ptrs;

int smooth_flag; /* this is 0 for no smoothing, 1 for smoothing of lines */
int value_flag; /* use raster values as categories */
int smooth_flag; /* this is 0 for no smoothing, 1 for smoothing of lines */
int value_flag; /* use raster values as categories */
int centroid_flag; /* re-center centroids */

struct Categories RastCats;
int has_cats; /* Category labels available */
struct field_info *Fi;
Expand All @@ -66,6 +68,7 @@ int main(int argc, char *argv[])
struct GModule *module;
struct Option *in_opt, *out_opt, *feature_opt, *column_name;
struct Flag *smooth_flg, *value_flg, *z_flg, *no_topol, *notab_flg;
struct Flag *centroid_flg;
int feature, notab_flag;

G_gisinit(argv[0]);
Expand Down Expand Up @@ -115,6 +118,13 @@ int main(int argc, char *argv[])
no_topol->label = _("Do not build vector topology");
no_topol->description = _("Recommended for massive point conversion");

centroid_flg = G_define_flag();
centroid_flg->key = 'c';
centroid_flg->label =
_("Move centroids to more central locations within areas");
centroid_flg->description = _("Default: centroids are located anywhere in "
"areas, often close to boundaries");

notab_flg = G_define_standard_flag(G_FLG_V_TABLE);

if (G_parser(argc, argv))
Expand All @@ -123,6 +133,7 @@ int main(int argc, char *argv[])
feature = Vect_option_to_types(feature_opt);
smooth_flag = (smooth_flg->answer) ? SMOOTH : NO_SMOOTH;
value_flag = value_flg->answer;
centroid_flag = centroid_flg->answer;
notab_flag = notab_flg->answer;

if (z_flg->answer && (feature != GV_POINT))
Expand Down
5 changes: 5 additions & 0 deletions raster/r.to.vect/r.to.vect.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ <h3>Area conversion</h3>
input file. If the raster map contains other data (i.e., line edges,
or point data) the output may be wrong.

<p>
By default, area centroids are often located close to boundaries and not
in the middle of an area. Centroids can be more centrally located with
the <em>-c</em> flag.

<h2>EXAMPLES</h2>

The examples are based on the North Carolina sample dataset:
Expand Down
2 changes: 1 addition & 1 deletion raster/r.topidx/arc_to_gridatb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def match(pattern, string):
return False


if len(sys.argv) != 3 or re.match("^-*help", sys.argv[1]):
if len(sys.argv) != 3 or re.match(r"^-*help", sys.argv[1]):
print("Usage: arc.to.gridatb.py arc_file gridatb_file")
sys.exit()

Expand Down
4 changes: 2 additions & 2 deletions raster/r.topidx/gridatb_to_arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
len(sys.argv) == 1
or len(sys.argv) == 4
or len(sys.argv) > 5
or re.match("^-*help", sys.argv[1])
or re.match(r"^-*help", sys.argv[1])
):
print("Usage: gridatb.to.arc.py gridatb_file arc_file [xllcorner yllcorner]")
sys.exit()
Expand All @@ -33,7 +33,7 @@

title = inf.readline()
inline = inf.readline()
m = re.match("^[ \t]*([0-9.]+)[ \t]+([0-9.]+)[ \t]+([0-9.]+)[ \t]*$", inline)
m = re.match(r"^[ \t]*([0-9.]+)[ \t]+([0-9.]+)[ \t]+([0-9.]+)[ \t]*$", inline)
if not m:
print(f"{infname}: Invalid input file format")
inf.close()
Expand Down
3 changes: 3 additions & 0 deletions raster/r.watershed/ram/do_cum.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ int do_cum(void)
}
}
G_free(astar_pts);
G_free(contour);
G_free(dist_to_nbr);

return 0;
}
Expand Down Expand Up @@ -632,6 +634,7 @@ int do_cum_mfd(void)

G_free(dist_to_nbr);
G_free(weight);
G_free(contour);

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions raster/r.watershed/seg/do_cum.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ int do_cum(void)
G_percent(do_points, do_points, 1); /* finish it */

seg_close(&astar_pts);
G_free(dist_to_nbr);
G_free(contour);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion utils/g.html2man/g.html2man.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def main():
sf.close()

# strip excess whitespace
blank_re = re.compile("[ \t\n]*\n([ \t]*\n)*")
blank_re = re.compile(r"[ \t\n]*\n([ \t]*\n)*")
s = blank_re.sub("\n", s)
s = s.lstrip()

Expand Down
2 changes: 1 addition & 1 deletion utils/g.html2man/ggroff.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, filename, stream=sys.stdout):
"index": [],
}
self.stack = []
self.strip_re = re.compile("^[ \t]+")
self.strip_re = re.compile(r"^[ \t]+")
self.filename = filename
self.at_bol = True

Expand Down
6 changes: 3 additions & 3 deletions utils/gitlog2changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# Match the author line and extract the part we want
# (Don't use startswith to allow Author override inside commit message.)
elif "Author:" in line:
authorList = re.split(": ", line, 1)
authorList = re.split(r": ", line, 1)
try:
author = authorList[1]
author = author[0 : len(author) - 1]
Expand All @@ -71,7 +71,7 @@

# Match the date line
elif line.startswith("Date:"):
dateList = re.split(": ", line, 1)
dateList = re.split(r": ", line, 1)
try:
date = dateList[1]
date = date[0 : len(date) - 1]
Expand Down Expand Up @@ -100,7 +100,7 @@
else:
message = message + " " + line.strip()
# If this line is hit all of the files have been stored for this commit
elif re.search("files? changed", line):
elif re.search(r"files? changed", line):
filesFound = True
continue
# Collect the files for this commit. FIXME: Still need to add +/- to files
Expand Down
Loading

0 comments on commit 7524c52

Please sign in to comment.