Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add minio #1

Merged
merged 8 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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]
push:
tags: [feature-*]

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/py_utility-*.whl
26 changes: 0 additions & 26 deletions .gitlab-ci.yml

This file was deleted.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ You can install py_utility using pip:
pip install py_utility
```

## 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!
11 changes: 8 additions & 3 deletions py_utility/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from .file import *
from .log import *
from .path import *
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__("py_utility." + module)
82 changes: 0 additions & 82 deletions py_utility/file.py

This file was deleted.

89 changes: 89 additions & 0 deletions py_utility/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
40 changes: 0 additions & 40 deletions py_utility/log.py

This file was deleted.

Loading
Loading