Skip to content

Commit

Permalink
Merge pull request #6 from snakypy/develop
Browse files Browse the repository at this point in the history
News features
  • Loading branch information
williamcanin committed Jan 1, 2022
2 parents f09faa0 + 9755154 commit c3cbbee
Show file tree
Hide file tree
Showing 20 changed files with 425 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.7
3.9.9
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
copyright = "2021, William C. Canin"
author = "William C. Canin"

version = "0.2.2"
version = "0.3.0"
# The full version, including alpha/beta/rc tags
release = "0.2.2"
release = "0.3.0"


# -- General configuration ---------------------------------------------------
Expand Down Expand Up @@ -67,7 +67,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
# html_static_path = ["_static"]

source_suffix = {
".rst": "restructuredtext",
Expand Down
25 changes: 25 additions & 0 deletions docs/helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ Module "math"
:undoc-members:
:show-inheritance:

Subpackage "helpers.checking"
------------------------------

.. automodule:: snakypy.helpers.checking
:members:
:undoc-members:
:show-inheritance:

Module "generic"
~~~~~~~~~~~~~~~~~~~

.. automodule:: snakypy.helpers.checking.generic
:members:
:undoc-members:
:show-inheritance:


Subpackage "helpers.catches"
----------------------------

Expand Down Expand Up @@ -125,6 +142,14 @@ Module "removals"
:undoc-members:
:show-inheritance:

Module "modifiers"
~~~~~~~~~~~~~~~~~~~

.. automodule:: snakypy.helpers.os.modifiers
:members:
:undoc-members:
:show-inheritance:


Subpackage "helpers.path"
---------------------------
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT license"
name = "snakypy-helpers"
readme = "README.rst"
repository = "https://github.com/snakypy/snakypy-helpers"
version = "0.2.2"
version = "0.3.0"

packages = [
{include = "snakypy"},
Expand Down
2 changes: 1 addition & 1 deletion snakypy/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"email": "contact.snakypy@gmail.com",
"website": "https://snakypy.github.io",
"github": "https://github.com/snakypy",
"version": "0.2.2",
"version": "0.3.0",
}

# Keep the versions the same on pyproject.toml and __init__.py
Expand Down
2 changes: 1 addition & 1 deletion snakypy/helpers/calcs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .bmi import bmi
from .math import compound_interest, fibonacci, percentage, simple_interest
from .math import compound_interest, fibonacci, percentage, simple_interest, trunc
29 changes: 28 additions & 1 deletion snakypy/helpers/calcs/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,31 @@ def compound_interest(
return format_dict


__all__ = ["percentage", "fibonacci", "compound_interest", "simple_interest"]
def trunc(number, n_digits=None, *, is_round=False):
"""
Function to truncate float numbers
>>> from snakypy import helpers
>>> helpers.calcs.trunc(1.9989, 2)
1.99
>>> helpers.calcs.trunc(1.9989, 2, is_round=True)
2.0
Args:
number (float): Must receive a float number
n_digits (int): An integer must be passed to define the number of places after the comma.
is_round (bool): If the value is TRue, round the number.
Returns:
Returns a float number
"""
if is_round:
return round(number, n_digits)
if n_digits and not is_round:
return int(number * 10 ** n_digits) / 10 ** n_digits
return number


__all__ = ["percentage", "fibonacci", "compound_interest", "simple_interest", "trunc"]
2 changes: 1 addition & 1 deletion snakypy/helpers/catches/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .finders import find_objects, is_tool, tools_requirements
from .generic import extension, shell, whoami
from .generic import extension
6 changes: 1 addition & 5 deletions snakypy/helpers/catches/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from os.path import exists, isdir, join
from shutil import which

from snakypy.helpers.decorators import only_linux


def find_objects(
directory: str, /, files: tuple = (), folders: tuple = (), by_extension: tuple = ()
Expand Down Expand Up @@ -60,10 +58,9 @@ def find_objects(
)


@only_linux
def is_tool(*args: str) -> bool:
"""
Searches if a tool is installed on the machine. (Linux systems only)
Searches if a tool is installed on the machine.
>>> from snakypy import helpers
>>> helpers.catches.is_tool("ls")
Expand All @@ -82,7 +79,6 @@ def is_tool(*args: str) -> bool:
return False


@only_linux
def tools_requirements(*args) -> bool:
"""
Search required tools if you can not burst an exception
Expand Down
45 changes: 2 additions & 43 deletions snakypy/helpers/catches/generic.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,6 @@
import re
from os import environ, popen
from os.path import splitext

from snakypy.helpers.decorators import only_linux


@only_linux
def whoami() -> str:
"""
Get the currently logged in user.
>>> from snakypy import helpers
>>> helpers.catches.whoami()
'william'
Returns:
[str] -- Returns the name of the current user.
"""
return str(popen("whoami").read()).replace("\n", "")


@only_linux
def shell() -> str:
"""
Function to get the currently activated shell.
>>> from snakypy import helpers
>>> helpers.catches.shell()
'sh'
Returns:
[str] -- Returns the name of the current shell.
"""
try:
get_shell = environ["SHELL"]
except KeyError:
return ""

if "/" in get_shell:
return get_shell.strip("\n").strip("").split("/")[-1]

return get_shell


def extension(filename: str, dots: bool = False) -> str:
"""Get a file extension
Expand All @@ -53,7 +12,7 @@ def extension(filename: str, dots: bool = False) -> str:
>>> helpers.catches.extension(file, dots=True)
'tar.gz'
or using from
or
>>> from snakypy.helpers.catches import extension
>>> file = '/tmp/file.tar.gz'
Expand Down Expand Up @@ -85,4 +44,4 @@ def extension(filename: str, dots: bool = False) -> str:
return ext


__all__ = ["whoami", "shell", "extension"]
__all__ = ["extension"]
8 changes: 8 additions & 0 deletions snakypy/helpers/checking/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .generic import (
is_blank_file,
is_hidden,
is_palindrome,
shell,
turned_palindrome,
whoami,
)

0 comments on commit c3cbbee

Please sign in to comment.