Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

style: Fix PTH208 use of pathlib#5238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
arohanajit wants to merge10 commits intoOSGeo:mainfromarohanajit:ruff-pth208
Closed
Show file tree
Hide file tree
Changes fromall 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
4 changes: 2 additions & 2 deletionsgui/wxpython/icons/grass_icons.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,14 +7,14 @@
__author__ = "Robert Szczepanek"

import os

from pathlib import Path
from core import globalvar

iconPath = os.path.join(globalvar.ICONDIR, "grass")

iconSet = {}

for icon inos.listdir(iconPath):
for icon inPath(iconPath).iterdir():
name, ext = os.path.splitext(icon)
if ext != ".png":
continue
Expand Down
30 changes: 21 additions & 9 deletionsgui/wxpython/image2target/ii2t_manager.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,7 @@
import shutil
import sys
from copy import copy
from pathlib import Path
from typing import TYPE_CHECKING

import wx
Expand DownExpand Up@@ -490,7 +491,10 @@ def OnLocation(self, event):
self.xylocation = event.GetString()

# create a list of valid mapsets
tmplist = os.listdir(os.path.join(self.grassdatabase, self.xylocation))
tmplist = [
p.name
for p in Path(os.path.join(self.grassdatabase, self.xylocation)).iterdir()
]
self.mapsetList = []
for item in tmplist:
if os.path.isdir(
Expand DownExpand Up@@ -711,11 +715,14 @@ def OnEnterPage(self, event: WizardEvent | None = None) -> None:
if os.path.isdir(
os.path.join(self.grassdatabase, self.xylocation, self.xymapset, "group")
):
tmplist = os.listdir(
os.path.join(
self.grassdatabase, self.xylocation, self.xymapset, "group"
)
)
tmplist = [
p.name
for p in Path(
os.path.join(
self.grassdatabase, self.xylocation, self.xymapset, "group"
)
).iterdir()
]
for item in tmplist:
if os.path.isdir(
os.path.join(
Expand DownExpand Up@@ -2579,9 +2586,14 @@ def __init__(
#
# get list of valid vector directories
#
vectlist = os.listdir(
os.path.join(self.grassdatabase, self.xylocation, self.xymapset, "vector")
)
vectlist = [
p.name
for p in Path(
os.path.join(
self.grassdatabase, self.xylocation, self.xymapset, "vector"
)
).iterdir()
]
for dir in vectlist:
if not os.path.isfile(
os.path.join(
Expand Down
8 changes: 4 additions & 4 deletionsgui/wxpython/psmap/dialogs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2206,9 +2206,9 @@ def __init__(self, parent, id, vectors, tmpSettings):
gisbase = os.getenv("GISBASE")
self.symbolPath = os.path.join(gisbase, "etc", "symbol")
self.symbols = []
fordir inos.listdir(self.symbolPath):
for symbol inos.listdir(os.path.join(self.symbolPath, dir)):
self.symbols.append(os.path.join(dir, symbol))
fordir_path inPath(self.symbolPath).iterdir():
for symbol inPath(dir_path).iterdir():
self.symbols.append(os.path.join(dir_path.name, symbol.name))
self.patternPath = os.path.join(gisbase, "etc", "paint", "patterns")

# notebook
Expand DownExpand Up@@ -5929,7 +5929,7 @@ def OnDirChanged(self, event):
"""Image directory changed"""
path = self.imagePanel.image["dir"].GetValue()
try:
files =os.listdir(path)
files =[p.name for p in Path(path).iterdir()]
except OSError: # no such directory
files = []
imageList = []
Expand Down
12 changes: 4 additions & 8 deletionsgui/wxpython/rlisetup/frame.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@

import wx
import os
from pathlib import Path

from core import globalvar, gcmd
from grass.script.utils import try_remove
Expand DownExpand Up@@ -209,15 +210,10 @@ def _layout(self):
self.Layout()

def ListFiles(self):
"""Check the configuration files inside the path"""
# list of configuration file
# return all the configuration files in self.rlipath, check if there are
"""Return a sorted list of configuration files"""
# check in each configuration file if it is a real file, not a symbolic
# link or directory and doesn't add them
listfiles = [
rli_conf
for rli_conf in os.listdir(self.rlipath)
if os.path.isfile(os.path.join(self.rlipath, rli_conf))
]
listfiles = [p.name for p in Path(self.rlipath).iterdir() if p.is_file()]
return sorted(listfiles)

def OnClose(self, event):
Expand Down
9 changes: 4 additions & 5 deletionslib/init/testsuite/test_grass_tmp_mapset.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,10 @@
"""

import unittest
import os
import shutil
import subprocess
from grass.gunittest.utils import xfail_windows

from pathlib import Path

# Note that unlike rest of GRASS GIS, here we are using unittest package
# directly. The grass.gunittest machinery for mapsets is not needed here.
Expand All@@ -38,7 +37,7 @@ class TestTmpMapset(unittest.TestCase):
def setUp(self):
"""Creates a location used in the tests"""
subprocess.check_call([self.executable, "-c", "XY", self.location, "-e"])
self.subdirs =os.listdir(self.location)
self.subdirs =[p.name for p in Path(self.location).iterdir()]

def tearDown(self):
"""Deletes the location"""
Expand DownExpand Up@@ -101,9 +100,9 @@ def test_mapset_deleted(self):
subprocess.check_call(
[self.executable, "--tmp-mapset", self.location, "--exec", "g.proj", "-p"]
)
for directory inos.listdir(self.location):
for directory inPath(self.location).iterdir():
self.assertTrue(
directory in self.subdirs,
directory.name in self.subdirs,
msg="Directory {directory} should have been deleted".format(**locals()),
)

Expand Down
2 changes: 1 addition & 1 deletionman/build.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,7 +83,7 @@ def copy_file(src, dst):


def get_files(man_dir, cls=None, ignore_gui=True, extension="html"):
for cmd in sorted(os.listdir(man_dir)):
for cmd in sorted([p.name for p in Path(man_dir).iterdir()]):
if (
cmd.endswith(f".{extension}")
and (cls in (None, "*") or cmd.startswith(cls + "."))
Expand Down
3 changes: 2 additions & 1 deletionman/build_class_graphical.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,7 @@
)

import build_md
from pathlib import Path


graphical_index_style = """\
Expand DownExpand Up@@ -275,7 +276,7 @@ def main():
img_extensions = ["png", "jpg", "gif"]
img_patterns = ["*." + extension for extension in img_extensions]
imgs = []
for filename in sorted(os.listdir(html_dir)):
for filename in sorted([p.name for p in Path(html_dir).iterdir()]):
if file_matches(filename, img_patterns):
imgs.append(filename)

Expand Down
8 changes: 4 additions & 4 deletionsman/build_manual_gallery.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ def file_matches(filename: str, patterns: Iterable[str]):

def get_files(directory, patterns, exclude_patterns):
files = []
for filename in sorted(os.listdir(directory)):
for filename in sorted([p.name for p in Path(directory).iterdir()]):
if file_matches(filename, patterns):
if not file_matches(filename, exclude_patterns):
files.append(filename)
Expand DownExpand Up@@ -177,10 +177,10 @@ def main(ext):
)
img_files = {}

for filename inos.listdir(man_dir):
if filename in img_blacklist:
for filename inPath(man_dir).iterdir():
if filename.name in img_blacklist:
continue
if file_matches(filename, img_patterns):
if file_matches(filename.name, img_patterns):
width = image_width(Path(man_dir, filename))
if width is not None and width < MIN_IMAGE_WIDTH:
# Skip small images.
Expand Down
2 changes: 1 addition & 1 deletionman/build_rest.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -308,7 +308,7 @@ def copy_file(src, dst):


def rest_files(cls=None):
for cmd in sorted(os.listdir(rest_dir)):
for cmd in sorted([p.name for p in Path(rest_dir).iterdir()]):
if (
cmd.endswith(".txt")
and (cls in {None, "*"} or cmd.startswith(cls + "."))
Expand Down
25 changes: 6 additions & 19 deletionspyproject.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -284,51 +284,40 @@ ignore = [
"**.py" = ["PYI066"]
"*/testsuite/**.py" = ["PT009", "PT027"]
"gui/wxpython/iclass/statistics.py" = ["A005"]
"gui/wxpython/icons/grass_icons.py" = ["PTH208"]
"gui/wxpython/image2target/ii2t_manager.py" = ["PTH208","SIM115"]
"gui/wxpython/image2target/ii2t_manager.py" = ["SIM115"]
"gui/wxpython/mapdisp/main.py" = ["SIM115"]
"gui/wxpython/modules/colorrules.py" = ["SIM115"]
"gui/wxpython/modules/mcalc_builder.py" = ["SIM115"]
"gui/wxpython/photo2image/ip2i_manager.py" = ["SIM115"]
"gui/wxpython/psmap/dialogs.py" = ["PTH208"]
"gui/wxpython/psmap/instructions.py" = ["SIM115"]
"gui/wxpython/rlisetup/frame.py" = ["PTH208"]
"gui/wxpython/tools/update_menudata.py" = ["SIM115"]
"gui/wxpython/vnet/vnet_data.py" = ["SIM115"]
"gui/wxpython/web_services/dialogs.py" = ["SIM115"]
"gui/wxpython/wxplot/profile.py" = ["A005", "SIM115"]
"lib/imagery/testsuite/test_imagery_signature_management.py" = ["SIM115"]
"lib/imagery/testsuite/test_imagery_sigsetfile.py" = ["FURB152"]
"lib/init/grass.py" = ["SIM115"]
"lib/init/testsuite/test_grass_tmp_mapset.py" = ["PTH208"]
"locale/grass_po_stats.py" = ["SIM115"]
"man/build.py" = ["PTH208"]
"man/build_class_graphical.py" = ["PTH208"]
"man/build_manual_gallery.py" = ["PTH208"]
"man/build_rest.py" = ["PTH208"]
"python/grass/__init__.py" = ["PYI056"]
"python/grass/exp*/tests/grass_script_mapset_session_test.py" = ["SIM117"]
"python/grass/exp*/tests/grass_script_tmp_mapset_session_test.py" = ["SIM117"]
"python/grass/gunittest/case.py" = ["PT009"]
"python/grass/gunittest/loader.py" = ["PTH208", "PYI024"]
"python/grass/gunittest/loader.py" = ["PYI024"]
"python/grass/gunittest/multireport.py" = ["PYI024"]
"python/grass/gunittest/testsu*/d*/s*/s*/subsub*/t*/test_segfaut.py" = ["B018"]
"python/grass/imaging/images2ims.py" = ["PTH208"]
"python/grass/jupyter/testsuite/interactivemap_test.py" = ["PGH004"]
"python/grass/jupyter/testsuite/map_test.py" = ["PGH004"]
"python/grass/pydispatch/signal.py" = ["A005"]
"python/grass/pygrass/gis/__init__.py" = ["PTH208"]
"python/grass/pygrass/modules/grid/grid.py" = ["PTH208", "SIM115"]
"python/grass/pygrass/modules/grid/grid.py" = ["SIM115"]
"python/grass/pygrass/modules/grid/testsuite/test_*_modules_grid_doctests.py" = ["F401"]
"python/grass/pygrass/modules/interface/env.py" = ["SIM115"]
"python/grass/pygrass/modules/testsuite/test_pygrass_modules_doctests.py" = ["F401"]
"python/grass/pygrass/raster/category.py" = ["FURB189"]
"python/grass/pygrass/raster/segment.py" = ["SIM115"]
"python/grass/pygrass/tests/*.py" = ["SIM115"]
"python/grass/pygrass/utils.py" = ["PTH208"]
"python/grass/pygrass/vector/geometry.py" = ["PYI024"]
"python/grass/pygrass/vector/testsuite/test_table.py" = ["PLW0108"]
"python/grass/script/array.py" = ["A005"]
"python/grass/script/core.py" = ["PTH208"]
"python/grass/script/utils.py" = ["FURB189"]
"python/grass/temporal/aggregation.py" = ["SIM115"]
"python/grass/temporal/register.py" = ["SIM115"]
Expand All@@ -337,7 +326,7 @@ ignore = [
"python/grass/temporal/temporal_algebra.py" = ["D300"]
"python/grass/temporal/temporal_operator.py" = ["D300"]
"python/grass/temporal/univar_statistics.py" = ["SIM115"]
"python/grass/utils/download.py" = ["PTH208", "SIM115"]
"python/grass/utils/download.py" = ["SIM115"]
"raster/r.*/testsuite/*.py" = ["SIM115"]
"raster/r.topidx/*.py" = ["SIM115"]
"scripts/d.correlate/d.correlate.py" = ["SIM115"]
Expand All@@ -346,10 +335,8 @@ ignore = [
"scripts/db.in.ogr/db.in.ogr.py" = ["SIM115"]
"scripts/db.test/db.test.py" = ["SIM115"]
"scripts/db.univar/db.univar.py" = ["SIM115"]
"scripts/g.download.project/g.download.project.py" = ["PTH208"]
"scripts/g.extension.all/g.extension.all.py" = ["SIM115"]
"scripts/g.extension/g.extension.py" = ["PTH208", "SIM115"]
"scripts/g.extension/testsuite/test_addons_modules.py" = ["PTH208"]
"scripts/g.extension/g.extension.py" = ["SIM115"]
"scripts/g.search.modules/g.search.modules.py" = ["SIM115"]
"scripts/i.oif/i.oif*.py" = ["SIM115"]
"scripts/m.proj/m.proj.py" = ["SIM115"]
Expand Down
11 changes: 8 additions & 3 deletionspython/grass/gunittest/loader.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@
import os
import re
import unittest
from pathlib import PurePath
from pathlib import PurePath, Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand DownExpand Up@@ -118,11 +118,16 @@ def discover_modules(
dirs.remove(testsuite_dir) # do not recurse to testsuite
full = os.path.join(root, testsuite_dir)

files =os.listdir(full)
files =[p.name for p in Path(full).iterdir()]
if file_pattern:
files = fnmatch.filter(files, file_pattern)
if file_regexp:
files = [f for f in files if re.match(file_regexp, f)]
pattern = (
file_regexp
if isinstance(file_regexp, str) and file_regexp.startswith('r"')
else r"{}".format(file_regexp)
)
files = [f for f in files if re.search(pattern, f)]
if exclude:
files = fnmatch_exclude_with_base(files, full, exclude)
files = sorted(files)
Expand Down
7 changes: 4 additions & 3 deletionspython/grass/imaging/images2ims.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@
import os
from operator import itemgetter
from string import digits
from pathlib import Path

try:
import numpy as np
Expand DownExpand Up@@ -208,10 +209,10 @@ def readIms(filename, asNumpy=True):
images = []

# Get all files in directory
for fname inos.listdir(dirname):
if fname.startswith(part1) and fname.endswith(part2):
for fname inPath(dirname).iterdir():
if fname.name.startswith(part1) and fname.name.endswith(part2):
# Get sequence number
nr = _getSequenceNumber(fname, part1, part2)
nr = _getSequenceNumber(fname.name, part1, part2)
# Get Pil image and store copy (to prevent keeping the file)
im = PIL.Image.open(os.path.join(dirname, fname))
images.append((im.copy(), nr))
Expand Down
14 changes: 7 additions & 7 deletionspython/grass/pygrass/gis/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
#!/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
Expand All@@ -11,6 +10,7 @@
from grass.pygrass.errors import GrassError
from grass.script.utils import encode, decode
from grass.pygrass.utils import getenv
from pathlib import Path

test_vector_name = "Gis_test_vector"
test_raster_name = "Gis_test_raster"
Expand DownExpand Up@@ -187,8 +187,8 @@ def locations(self):
"""
return sorted(
[
loc
for loc inlistdir(self.name)
loc.name
for loc inPath(self.name).iterdir()
if libgis.G_is_location(encode(join(self.name, loc)))
]
)
Expand DownExpand Up@@ -241,9 +241,9 @@ def __getitem__(self, mapset):
def __iter__(self):
lpath = self.path()
return (
m
for m inlistdir(lpath)
if (isdir(join(lpath, m)) and is_valid(m, lpath, "MAPSET"))
m.name
for m inPath(lpath).iterdir()
if (m.is_dir() and is_valid(m.name, lpath, "MAPSET"))
)

def __len__(self):
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp