Skip to content

Commit

Permalink
Fix the path_object NPE when empty/none path_name is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Apr 25, 2024
1 parent 02e6e51 commit 538ee06
Show file tree
Hide file tree
Showing 40 changed files with 91 additions and 89 deletions.
2 changes: 1 addition & 1 deletion modules/hspylib/bumpver.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpver]
current_version = "1.12.37"
current_version = "1.12.38"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "++version {old_version} -> {new_version}"
commit = false
Expand Down
2 changes: 1 addition & 1 deletion modules/hspylib/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
app_version = '1.12.37'
app_version = '1.12.38'
app_name = 'hspylib'
4 changes: 2 additions & 2 deletions modules/hspylib/src/demo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: demo
"""Package initialization."""
Expand All @@ -9,4 +9,4 @@
'cli',
'other'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/demo/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: demo.cli
"""Package initialization."""

__all__ = [
'vt100'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/demo/cli/vt100/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: demo.cli.vt100
"""Package initialization."""

__all__ = [
'vt100_demo'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/demo/other/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: demo.other
"""Package initialization."""
Expand All @@ -9,4 +9,4 @@
'event_bus_demo',
'filter_demo'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main
"""Package initialization."""

__all__ = [
'hspylib'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
2 changes: 1 addition & 1 deletion modules/hspylib/src/main/hspylib/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.37
1.12.38
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib
"""Package initialization."""
Expand All @@ -9,4 +9,4 @@
'core',
'modules'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.core
"""Package initialization."""
Expand All @@ -18,4 +18,4 @@
'tools',
'zoned_datetime'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/core/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.core.config
"""Package initialization."""
Expand All @@ -12,4 +12,4 @@
'properties',
'settings'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
30 changes: 16 additions & 14 deletions modules/hspylib/src/main/hspylib/core/config/path_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from dataclasses import dataclass
from os.path import expandvars, relpath, join
from pathlib import Path
from typing import Literal
from typing import Literal, Optional

from hspylib.core.metaclass.classpath import AnyPath

Expand All @@ -34,20 +34,22 @@ class PathObject:
kind: Literal["file", "folder"]

@staticmethod
def of(path_name: AnyPath) -> 'PathObject':
def of(path_name: AnyPath) -> Optional['PathObject']:
"""Create a path object from a any path."""
path_dir: Path = Path(path_name) if isinstance(path_name, str) else path_name
posix_path = Path(expandvars(path_dir.expanduser())).absolute()
dir_name, filename = os.path.split(posix_path)
if posix_path.exists() and posix_path.is_dir():
dir_name = f"{dir_name}/{filename}"
filename = ''
if dir_name in ['.', '..', '']:
dir_name = (dir_name or '.') + os.path.sep
return PathObject(
dir_name.strip(), relpath(dir_name, os.curdir), filename.strip(),
posix_path.exists(), "folder" if posix_path.is_dir() else "file"
)
if path_name:
path_dir: Path = Path(path_name) if isinstance(path_name, str) else path_name
posix_path = Path(expandvars(path_dir.expanduser())).absolute()
dir_name, filename = os.path.split(posix_path)
if posix_path.exists() and posix_path.is_dir():
dir_name = f"{dir_name}/{filename}"
filename = ''
if dir_name in ['.', '..', '']:
dir_name = (dir_name or '.') + os.path.sep
return PathObject(
dir_name.strip(), relpath(dir_name, os.curdir), filename.strip(),
posix_path.exists(), "folder" if posix_path.is_dir() else "file"
)
return None

@staticmethod
def split(path_name: AnyPath) -> tuple[str, str]:
Expand Down
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/core/decorator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.core.decorator
"""Package initialization."""

__all__ = [
'decorators'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/core/enums/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.core.enums
"""Package initialization."""
Expand All @@ -12,4 +12,4 @@
'http_code',
'http_method'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/core/exception/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.core.exception
"""Package initialization."""

__all__ = [
'exceptions'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/core/metaclass/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.core.metaclass
"""Package initialization."""
Expand All @@ -9,4 +9,4 @@
'classpath',
'singleton'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/core/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.core.tools
"""Package initialization."""
Expand All @@ -12,4 +12,4 @@
'text_tools',
'validator'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.modules
"""Package initialization."""
Expand All @@ -13,4 +13,4 @@
'fetch',
'security'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.modules.application
"""Package initialization."""
Expand All @@ -12,4 +12,4 @@
'exit_status',
'version'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.modules.application.argparse
"""Package initialization."""
Expand All @@ -12,4 +12,4 @@
'options_builder',
'parser_action'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/modules/cache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.modules.cache
"""Package initialization."""
Expand All @@ -9,4 +9,4 @@
'ttl_cache',
'ttl_keyring_be'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/modules/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.modules.cli
"""Package initialization."""
Expand All @@ -9,4 +9,4 @@
'keyboard',
'vt100'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.modules.cli.vt100
"""Package initialization."""
Expand All @@ -10,4 +10,4 @@
'vt_code',
'vt_color'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/modules/eventbus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.modules.eventbus
"""Package initialization."""
Expand All @@ -9,4 +9,4 @@
'event',
'eventbus'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/modules/fetch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.modules.fetch
"""Package initialization."""
Expand All @@ -11,4 +11,4 @@
'uri_builder',
'uri_scheme'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/main/hspylib/modules/security/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: main.hspylib.modules.security
"""Package initialization."""

__all__ = [
'security'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: test
"""Package initialization."""
Expand All @@ -11,4 +11,4 @@
'modules',
'shared'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
4 changes: 2 additions & 2 deletions modules/hspylib/src/test/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _*_ coding: utf-8 _*_
#
# hspylib v1.12.37
# hspylib v1.12.38
#
# Package: test.core
"""Package initialization."""
Expand All @@ -14,4 +14,4 @@
'test_preconditions',
'tools'
]
__version__ = '1.12.37'
__version__ = '1.12.38'
Loading

0 comments on commit 538ee06

Please sign in to comment.