-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from tinnawong/develop
Add minio and Refactor code
- Loading branch information
Showing
22 changed files
with
714 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.