Skip to content

Commit

Permalink
Merge pull request #3 from tinnawong/develop
Browse files Browse the repository at this point in the history
Add minio and Refactor code
  • Loading branch information
tinnawong authored Sep 19, 2023
2 parents b0733bd + f6dfb71 commit 7823c4d
Show file tree
Hide file tree
Showing 22 changed files with 714 additions and 303 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [published]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
46 changes: 46 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python tests

on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]

jobs:
test:
runs-on: ubuntu-20.04

strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest setuptools wheel
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- name: Install
run: |
python setup.py sdist bdist_wheel
pip install dist/pylabtools-*.whl
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
main.py
*.log
test.py

__pycache__
build
dist
tin_utility.egg-info
text.txt
py_utility.egg-info
dist
26 changes: 0 additions & 26 deletions .gitlab-ci.yml

This file was deleted.

23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# pylabtools

`pylabtools` is a Python utility library that provides various helper functions for file and directory manipulation, text formatting, and logging.

## Installation

You can install pylabtools using pip:

```bash
pip install pylabtools
```

## Testing

You can run the unit tests using pytest:

```bash
python -m unittest discover tests
```

## Contributing

If you find a bug or have an idea for a new feature, please open an issue on the GitHub repository. Pull requests are welcome!
3 changes: 0 additions & 3 deletions py_utility/__init__.py

This file was deleted.

35 changes: 0 additions & 35 deletions py_utility/file.py

This file was deleted.

26 changes: 0 additions & 26 deletions py_utility/log.py

This file was deleted.

41 changes: 0 additions & 41 deletions py_utility/path.py

This file was deleted.

8 changes: 8 additions & 0 deletions pylabtools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

files = os.listdir(__path__[0])
modules = (
x.replace(".py", "") for x in files if x.endswith(".py") and not x.startswith("__")
)
for module in modules:
__import__("pylabtools." + module)
89 changes: 89 additions & 0 deletions pylabtools/file_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import json
from pathlib import Path
from typing import Generator

def read_file_all_text(path: str, encoding: str = "utf-8") -> str:
"""
Reads the entire content of a file and returns it as a single string.
Args:
path (str): The path to the file.
encoding (str, optional): The encoding of the file. Defaults to "utf-8".
Returns:
str: The entire content of the file.
"""
with open(path, "r", encoding=encoding) as f:
return f.read()

def stream_file_by_line(path: str, encoding: str = "utf-8") -> Generator[str, None, None]:
"""
Streams the content of a file line by line.
Args:
path (str): The path to the file.
encoding (str, optional): The encoding of the file. Defaults to "utf-8".
Yields:
Generator[str, None, None]: Each line from the file.
"""
with open(path, "r", encoding=encoding) as f:
for line in f:
yield line.rstrip('\r\n')


def write_text_to_file(path: str, content: str, encoding: str = "utf-8") -> None:
"""Write text to file
Args:
path (str): Path to the output file.
content (str): Content to write.
encoding (str, optional): Encoding of the file. Defaults to "utf-8".
"""
with open(path, "w", encoding=encoding) as f:
f.write(content)


def read_json_config(path: str) -> dict:
"""Read JSON config file
Args:
path (str): Path to the config file.
Returns:
dict: Configuration as a dictionary.
"""
with open(path, "r", encoding="utf-8") as f:
return json.load(f)


def get_file_name_without_extension(path: str) -> str:
"""Get file name without extension
Args:
path (str): Path to the file.
Returns:
str: File name without extension.
"""
return Path(path).stem


def get_file_name(path: str, tail: str = "", set_extension: str = None, without_extension: bool = False) -> str:
"""Get file name with optional modifications
Args:
path (str): Path to the file.
tail (str, optional): Additional tail for the file name. Defaults to "".
set_extension (str, optional): Desired file extension. If None, uses original extension. Defaults to None.
without_extension (bool, optional): If True, returns file name without extension. Defaults to False.
Returns:
str: Modified file name.
"""
file_name = Path(path).stem
if without_extension:
return file_name + tail
if not set_extension:
set_extension = Path(path).suffix
return file_name + tail + set_extension
Loading

0 comments on commit 7823c4d

Please sign in to comment.