Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Sep 17, 2023
1 parent d45bf56 commit ab19b71
Show file tree
Hide file tree
Showing 20 changed files with 1,017 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI

on: [push, pull_request]

jobs:
build-package:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref_name }}-build
cancel-in-progress: true
timeout-minutes: 20
container:
image: ghcr.io/thombashi/python-ci:3.11

steps:
- uses: actions/checkout@v4

- run: make build

lint:
runs-on: ubuntu-latest
permissions:
contents: read
concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref_name }}-lint
cancel-in-progress: true
timeout-minutes: 20
container:
image: ghcr.io/thombashi/python-ci:3.11

steps:
- uses: actions/checkout@v4

- run: make check

unit-test:
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref_name }}-ut-${{ matrix.os }}-${{ matrix.python-version }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]
timeout-minutes: 20

steps:
- uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
**/*requirements.txt
setup.py
tox.ini
- run: make setup-ci

- name: Run tests
run: tox -e py
121 changes: 121 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# User settings
_sandbox/
*_profile
Untitled.ipynb
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include LICENSE
include README.rst
include tox.ini

recursive-include requirements *
recursive-include test *

global-exclude __pycache__/*
global-exclude *.pyc
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
PYTHON := python3

AUTHOR := thombashi
PACKAGE := pathvalidate-cli

BUILD_WORK_DIR := _work
PKG_BUILD_DIR := $(BUILD_WORK_DIR)/$(PACKAGE)


.PHONY: build-remote
build-remote: clean
@mkdir -p $(BUILD_WORK_DIR)
@cd $(BUILD_WORK_DIR) && \
git clone https://github.com/$(AUTHOR)/$(PACKAGE).git --depth 1 && \
cd $(PACKAGE) && \
$(PYTHON) -m tox -e build
ls -lh $(PKG_BUILD_DIR)/dist/*

.PHONY: build
build: clean
$(PYTHON) -m tox -e build
ls -lh dist/*

.PHONY: check
check:
$(PYTHON) -m tox -e lint

.PHONY: clean
clean:
rm -rf $(BUILD_WORK_DIR)
$(PYTHON) -m tox -e clean

.PHONY: fmt
fmt:
$(PYTHON) -m tox -e fmt

.PHONY: release
release:
$(PYTHON) setup.py release --sign --verbose
$(MAKE) clean

.PHONY: setup-ci
setup-ci:
$(PYTHON) -m pip install -q --disable-pip-version-check --upgrade tox

.PHONY: setup
setup: setup-ci
$(PYTHON) -m pip install -q --disable-pip-version-check --upgrade -e .[test] releasecmd
$(PYTHON) -m pip check
64 changes: 64 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.. contents:: **pathvalidate-cli**
:backlinks: top
:depth: 2


Summary
============================================

pathvalidate-cli is a command line interface for `pathvalidate <https://github.com/thombashi/pathvalidate>`__ library.


Installation
============================================
::

pip install pathvalidate-cli


Usage
============================================

::

$ pathvalidate sanitize 'fi:l*e/p"a?t>h|.t<xt'
file/path.txt
$ pathvalidate --filename sanitize 'fi:l*e/p"a?t>h|.t<xt'
filepath.txt

$ pathvalidate validate 'fi:l*e/p"a?t>h|.t<xt'
[PV1100] invalid characters found: invalids=(':', '*', '"', '?', '>', '|', '<'), value='fi:l*e/p"a?t>h|.t<xt', platform=Windows

Command Help
--------------------------------------------

::

Usage: pathvalidate [OPTIONS] COMMAND [ARGS]...

Options:
--version Show the version and exit.
--debug For debug print.
-q, --quiet Suppress execution log messages.
--filename Consider inputs as filenames.
--max-len, --max-bytes BYTES Maximum byte counts of file paths. -1: same
value with the platform limitation. [default:
-1]
--platform PLATFORM Execution platform name (case-insensitive).
Valid platform specifiers are
Linux/Windows/macOS. Valid special values are:
POSIX, universal (a) auto: automatically
detects the execution platform. (b) universal:
platform independent. [default: universal]
-v, --verbose Verbosity level [default: 0]
-h, --help Show this message and exit.

Commands:
error Print error reasons.
sanitize Sanitize file paths.
validate Validate file paths.


Dependencies
============================================
Python 3.8+
1 change: 1 addition & 0 deletions pathvalidate_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .__version__ import __author__, __copyright__, __email__, __license__, __version__
6 changes: 6 additions & 0 deletions pathvalidate_cli/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__author__ = "Tsuyoshi Hombashi"
__copyright__ = f"Copyright 2023, {__author__}"
__license__ = "MIT License"
__version__ = "0.0.1"
__maintainer__ = __author__
__email__ = "tsuyoshi.hombashi@gmail.com"
4 changes: 4 additions & 0 deletions pathvalidate_cli/_const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import Final


MODULE_NAME: Final[str] = "pathvalidate-cli"
43 changes: 43 additions & 0 deletions pathvalidate_cli/_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sys
from typing import Final

from loguru import logger

from ._const import MODULE_NAME


class LogLevel:
DEBUG: Final[str] = "DEBUG"
INFO: Final[str] = "INFO"
QUIET: Final[str] = "QUIET"


logger.disable(MODULE_NAME)


def set_logger(is_enable: bool, propagation_depth: int = 1) -> None:
if is_enable:
logger.enable(MODULE_NAME)
else:
logger.disable(MODULE_NAME)


def initialize_logger(name: str, log_level: str) -> None:
logger.remove()

if log_level == LogLevel.QUIET:
logger.disable(name)
return

if log_level == LogLevel.DEBUG:
log_format = (
"<level>{level: <8}</level> | "
"<cyan>{name}</cyan>:"
"<cyan>{function}</cyan>:"
"<cyan>{line}</cyan> - <level>{message}</level>"
)
else:
log_format = "<level>[{level}]</level> {message}"

logger.add(sys.stderr, colorize=True, format=log_format, level=log_level)
logger.enable(name)
Loading

0 comments on commit ab19b71

Please sign in to comment.