Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gui/wxpython/datacatalog/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import re
import copy
from multiprocessing import Process, Queue, cpu_count
from pathlib import Path

import wx

Expand Down Expand Up @@ -354,7 +355,7 @@ def _getValidSavedGrassDBs(self):
dbs = UserSettings.Get(
group="datacatalog", key="grassdbs", subkey="listAsString"
)
return [db for db in dbs.split(",") if os.path.isdir(db)]
return [db for db in dbs.split(",") if Path(db).is_dir()]

def _saveGrassDBs(self):
"""Save current grass dbs in tree to settings"""
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/image2target/ii2t_gis_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def _set_properties(self, version, revision):
# set database
if not self.gisdbase:
# sets an initial path for gisdbase if nothing in GISRC
if os.path.isdir(os.getenv("HOME")):
if Path(os.getenv("HOME")).is_dir():
self.gisdbase = os.getenv("HOME")
else:
self.gisdbase = str(Path.cwd())
Expand All @@ -331,7 +331,7 @@ def _set_properties(self, version, revision):
location = self.GetRCValue("LOCATION_NAME")
if location == "<UNKNOWN>":
return
if not os.path.isdir(os.path.join(self.gisdbase, location)):
if not Path(os.path.join(self.gisdbase, location)).is_dir():
location = None

# list of locations
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/image2target/ii2t_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def OnLocation(self, event):
self.mapsetList = []
for item in tmplist:
if (
os.path.isdir(os.path.join(self.grassdatabase, self.xylocation, item))
Path(self.grassdatabase, self.xylocation, item).is_dir()
and Path(self.grassdatabase, self.xylocation, item, "WIND").exists()
):
if item != "PERMANENT":
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/lmgr/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def Load(self, filename):
self.lmgr.SetSize(gxwXml.layerManager["size"])
if gxwXml.layerManager["cwd"]:
self.lmgr.cwdPath = gxwXml.layerManager["cwd"]
if os.path.isdir(self.lmgr.cwdPath):
if Path(self.lmgr.cwdPath).is_dir():
os.chdir(self.lmgr.cwdPath)

#
Expand Down
10 changes: 5 additions & 5 deletions lib/init/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,12 @@ def create_grass_config_dir() -> str:
except (RuntimeError, NotADirectoryError) as e:
fatal(f"{e}")

if not os.path.isdir(directory):
if not Path(directory).is_dir():
try:
Path(directory).mkdir(parents=True)
except OSError as e:
# Can happen as a race condition
if e.errno != errno.EEXIST or not os.path.isdir(directory):
if e.errno != errno.EEXIST or not Path(directory).is_dir():
fatal(
_(
"Failed to create configuration directory '{}' with error: {}"
Expand Down Expand Up @@ -700,7 +700,7 @@ def cannot_create_location_reason(gisdbase: StrPath, location: str) -> str:
return _(
"Unable to create new project <{location}> because <{path}> is a file."
).format(**locals())
if os.path.isdir(path):
if Path(path).is_dir():
return _(
"Unable to create new project <{location}> because"
" the directory <{path}>"
Expand Down Expand Up @@ -851,7 +851,7 @@ def set_mapset(
" because <{path}> is a file."
).format(mapset=mapset, path=path)
)
elif os.path.isdir(path):
elif Path(path).is_dir():
# not a valid mapset, but dir exists, assuming
# broken/incomplete mapset
warning(
Expand Down Expand Up @@ -2181,7 +2181,7 @@ def main() -> None:
GRASS_VERSION_MAJOR = runtime_paths.version_major
GRASS_VERSION_GIT = runtime_paths.grass_version_git
gisbase = runtime_paths.gisbase
if not os.path.isdir(gisbase):
if not Path(gisbase).is_dir():
gisbase = get_install_path(gisbase)
# Set the main prefix again.
# See also grass.script.setup.setup_runtime_env.
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ ignore = [
"PTH107", # os-remove
"PTH108", # os-unlink
"PTH111", # os-path-expanduser
"PTH112", # os-path-isdir
"PTH117", # os-path-isabs
"PTH118", # os-path-join
"PTH119", # os-path-basename
Expand Down
2 changes: 1 addition & 1 deletion python/grass/app/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_grass_config_dir_for_version(major_version, minor_version, *, env):
)
raise RuntimeError(msg)

if not os.path.isdir(config_dir):
if not Path(config_dir).is_dir():
msg = (
f"The {env_dirname} variable points to directory which does"
" not exist, ask your operating system support"
Expand Down
3 changes: 1 addition & 2 deletions python/grass/app/tests/grass_app_resource_paths_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from pathlib import Path

import pytest
Expand Down Expand Up @@ -39,4 +38,4 @@ def test_value_not_empty(name):
def test_value_is_directory(name):
value = getattr(resource_paths, name)
assert Path(value).exists()
assert os.path.isdir(value)
assert Path(value).is_dir()
5 changes: 3 additions & 2 deletions python/grass/pygrass/gis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3

from os import listdir
from os.path import join, isdir
from os.path import join
import shutil
import ctypes as ct
import fnmatch
from pathlib import Path


import grass.lib.gis as libgis
Expand Down Expand Up @@ -243,7 +244,7 @@ def __iter__(self):
return (
m
for m in listdir(lpath)
if (isdir(join(lpath, m)) and is_valid(m, lpath, "MAPSET"))
if (Path(lpath, m).is_dir() and is_valid(m, lpath, "MAPSET"))
)

def __len__(self):
Expand Down
12 changes: 6 additions & 6 deletions python/grass/pygrass/modules/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def get_mapset(gisrc_src, gisrc_dst):
mdst, ldst, gdst = read_gisrc(gisrc_dst)
path_src = os.path.join(gsrc, lsrc, msrc)
path_dst = os.path.join(gdst, ldst, mdst)
if not os.path.isdir(path_dst):
if not Path(path_dst).is_dir():
Path(path_dst).mkdir(parents=True)
copy_special_mapset_files(path_src, path_dst)
src = Mapset(msrc, lsrc, gsrc)
Expand Down Expand Up @@ -273,7 +273,7 @@ def copy_rasters(rasters, gisrc_src, gisrc_dst, processes, region=None):
# change gisdbase to dst
env["GISRC"] = gisrc_dst
rupck(input=file_dst, output=rast_clean, overwrite=True, env_=env)
os.remove(file_dst)
Path(file_dst).unlink()


def copy_vectors(vectors, gisrc_src, gisrc_dst):
Expand Down Expand Up @@ -307,7 +307,7 @@ def copy_vectors(vectors, gisrc_src, gisrc_dst):
# change gisdbase to dst
env["GISRC"] = gisrc_dst
vupck(input=file_dst, output=vect, overwrite=True, env_=env)
os.remove(file_dst)
Path(file_dst).unlink()


def get_cmd(cmdd):
Expand Down Expand Up @@ -395,7 +395,7 @@ def cmd_exe(args):
# run the grass command
sub.Popen(get_cmd(cmd), shell=shell, env=env).wait()
# remove temp GISRC
os.remove(gisrc_dst)
Path(gisrc_dst).unlink()


class GridModule:
Expand Down Expand Up @@ -539,7 +539,7 @@ def __init__(
def __del__(self):
if self.gisrc_dst:
# remove GISRC file
os.remove(self.gisrc_dst)
Path(self.gisrc_dst).unlink()

def clean_location(self, location=None):
"""Remove all created mapsets.
Expand Down Expand Up @@ -730,7 +730,7 @@ def _clean(self):
gisdbase, location = os.path.split(self.move)
self.clean_location(Location(location, gisdbase))
# rm temporary gis_rc
os.remove(self.gisrc_dst)
Path(self.gisrc_dst).unlink()
self.gisrc_dst = None
sht.rmtree(os.path.join(self.move, "PERMANENT"))
sht.rmtree(os.path.join(self.move, self.mset.name))
Expand Down
3 changes: 2 additions & 1 deletion python/grass/pygrass/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fnmatch
import itertools
import os
from pathlib import Path
from sqlite3 import OperationalError

import grass.lib.gis as libgis
Expand Down Expand Up @@ -39,7 +40,7 @@ def findfiles(dirpath, match=None):
res = []
for f in sorted(os.listdir(dirpath)):
abspath = os.path.join(dirpath, f)
if os.path.isdir(abspath):
if Path(abspath).is_dir():
res.extend(findfiles(abspath, match))

if match:
Expand Down
12 changes: 6 additions & 6 deletions python/grass/script/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,20 @@ def ask_executable(arg):
).stdout.strip()

# Directory was provided as a parameter.
if path and os.path.isdir(path):
if path and Path(path).is_dir():
return os.fspath(path)

# Executable was provided as parameter.
if path and shutil.which(path):
# The path was provided by the user and it is an executable
# (on path or provided with full path), so raise exception on failure.
path_from_executable = ask_executable(path)
if os.path.isdir(path_from_executable):
if Path(path_from_executable).is_dir():
return path_from_executable

# GISBASE is set from the outside or already set.
env_gisbase = os.environ.get("GISBASE")
if env_gisbase and os.path.isdir(env_gisbase):
if env_gisbase and Path(env_gisbase).is_dir():
return env_gisbase

# Executable provided in environment (name is from grass-session).
Expand All @@ -170,7 +170,7 @@ def ask_executable(arg):
grass_bin = os.environ.get("GRASSBIN")
if grass_bin and shutil.which(grass_bin):
path_from_executable = ask_executable(grass_bin)
if os.path.isdir(path_from_executable):
if Path(path_from_executable).is_dir():
return path_from_executable

# Derive the path from path to this file (Python module).
Expand All @@ -191,7 +191,7 @@ def ask_executable(arg):
grass_bin = "grass"
if grass_bin and shutil.which(grass_bin):
path_from_executable = ask_executable(grass_bin)
if os.path.isdir(path_from_executable):
if Path(path_from_executable).is_dir():
return path_from_executable

# We fallback to whatever was provided. This may help trace the issue
Expand Down Expand Up @@ -227,7 +227,7 @@ def setup_runtime_env(gisbase=None, *, env=None):

runtime_paths = RuntimePaths(env=env, prefix=gisbase)
gisbase = runtime_paths.gisbase
if not os.path.isdir(gisbase):
if not Path(gisbase).is_dir():
gisbase = get_install_path(gisbase)
# Set the main prefix again.
# See also the main grass executable code.
Expand Down
13 changes: 7 additions & 6 deletions python/grass/script/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,21 +433,22 @@ def alphanum_key(actual_key):
def get_lib_path(modname, libname=None):
"""Return the path of the libname contained in the module."""
from os import getenv
from os.path import isdir, join, sep
from os.path import join, sep

if isdir(join(getenv("GISBASE"), "etc", modname)):
if Path(getenv("GISBASE"), "etc", modname).is_dir():
path = join(os.getenv("GISBASE"), "etc", modname)
elif (
getenv("GRASS_ADDON_BASE")
and libname
and isdir(join(getenv("GRASS_ADDON_BASE"), "etc", modname, libname))
and Path(getenv("GRASS_ADDON_BASE"), "etc", modname, libname).is_dir()
) or (
getenv("GRASS_ADDON_BASE")
and isdir(join(getenv("GRASS_ADDON_BASE"), "etc", modname))
and Path(getenv("GRASS_ADDON_BASE"), "etc", modname).is_dir()
):
path = join(getenv("GRASS_ADDON_BASE"), "etc", modname)
elif getenv("GRASS_ADDON_BASE") and isdir(
join(getenv("GRASS_ADDON_BASE"), modname, modname)
elif (
getenv("GRASS_ADDON_BASE")
and Path(getenv("GRASS_ADDON_BASE"), modname, modname).is_dir()
):
path = join(os.getenv("GRASS_ADDON_BASE"), modname, modname)
else:
Expand Down
4 changes: 2 additions & 2 deletions python/grass/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ def _move_extracted_files(extract_dir, target_dir, files):
debug("_move_extracted_files({})".format(locals()))
if len(files) == 1:
actual_path = os.path.join(extract_dir, files[0])
if os.path.isdir(actual_path):
if Path(actual_path).is_dir():
shutil.copytree(actual_path, target_dir)
else:
shutil.copy(actual_path, target_dir)
else:
Path(target_dir).mkdir(exist_ok=True)
for file_name in files:
actual_file = os.path.join(extract_dir, file_name)
if os.path.isdir(actual_file):
if Path(actual_file).is_dir():
# Choice of copy tree function:
# shutil.copytree() fails when subdirectory exists.
# However, distutils.copy_tree() may fail to create directories before
Expand Down
2 changes: 1 addition & 1 deletion scripts/g.download.project/g.download.project.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def find_location_in_directory(path, recurse=0):
"""
assert recurse >= 0
full_paths = [os.path.join(path, i) for i in os.listdir(path)]
candidates = sorted([i for i in full_paths if os.path.isdir(i)])
candidates = sorted([i for i in full_paths if Path(i).is_dir()])
for candidate in candidates:
if is_location_valid(candidate):
return candidate
Expand Down
10 changes: 5 additions & 5 deletions scripts/g.extension/g.extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ def move_extracted_files(extract_dir, target_dir, files):
Path(target_dir).mkdir(exist_ok=True)
for file_name in files:
actual_file = os.path.join(extract_dir, file_name)
if os.path.isdir(actual_file):
if Path(actual_file).is_dir():
# shutil.copytree() replaced by copy_tree() because
# shutil's copytree() fails when subdirectory exists
copy_tree(actual_file, os.path.join(target_dir, file_name))
Expand Down Expand Up @@ -1947,7 +1947,7 @@ def download_source_code(
" Please report this to the grass-user mailing list."
).format(source)
)
assert os.path.isdir(directory)
assert Path(directory).is_dir()
return directory, url


Expand Down Expand Up @@ -2286,7 +2286,7 @@ def remove_extension_std(name, force=False):

# remove module libraries under GRASS_ADDONS/etc/{name}/*
libpath = os.path.join(options["prefix"], "etc", name)
if os.path.isdir(libpath):
if Path(libpath).is_dir():
gs.verbose(libpath)
if force:
shutil.rmtree(libpath)
Expand Down Expand Up @@ -2372,7 +2372,7 @@ def create_dir(path):

NOOP for existing directory.
"""
if os.path.isdir(path):
if Path(path).is_dir():
return

try:
Expand Down Expand Up @@ -2722,7 +2722,7 @@ def resolve_source_code(url=None, name=None, branch=None, fork=False):
return "official_fork", url

# Handle local URLs
if os.path.isdir(url):
if Path(url).is_dir():
return "dir", os.path.abspath(url)
if Path(url).exists():
if url.endswith(".zip"):
Expand Down
Loading
Loading