diff --git a/.github/workflows/publish-to-test-pypi.yml b/.github/workflows/publish-to-test-pypi.yml index 437a690..82b9787 100644 --- a/.github/workflows/publish-to-test-pypi.yml +++ b/.github/workflows/publish-to-test-pypi.yml @@ -9,9 +9,15 @@ jobs: steps: - uses: actions/checkout@master - name: Set up Python 3.9 - uses: actions/setup-python@v1 + uses: actions/setup-python@v3 with: python-version: "3.9" + - name: Update pip + run: python -m pip install --upgrade pip + - name: Install dependencies + run: | + pip install -r requirements.txt + pip install . - name: Install pypa/build run: >- python -m diff --git a/.github/workflows/run_black_and_isort.yml b/.github/workflows/run_black_and_isort.yml index f6f6c6a..8470aa9 100644 --- a/.github/workflows/run_black_and_isort.yml +++ b/.github/workflows/run_black_and_isort.yml @@ -20,10 +20,12 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | + pip install --upgrade pip + pip install -r requirements.txt pip install . pip install black isort - name: Run black and isort run: | python -m black easyPythonpi/* python -m isort easyPythonpi/* - + diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index ecc004d..2791202 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v3 @@ -21,6 +21,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | + pip install --upgrade pip + pip install -r requirements.txt pip install . pip install regex - name: Run tests diff --git a/.gitignore b/.gitignore index 18c90f8..4da9a66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,168 @@ -# prevents all pycaches from being added +# prevents all pycaches from being added __pycache__ easyPythonpi/__pycache__ build dist -easyPythonpi.egg.info \ No newline at end of file +easyPythonpi.egg.info + +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +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 +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# 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/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ \ No newline at end of file diff --git a/easyPythonpi/methods/array.py b/easyPythonpi/methods/array.py index 5722421..c5aee41 100644 --- a/easyPythonpi/methods/array.py +++ b/easyPythonpi/methods/array.py @@ -34,3 +34,27 @@ def arrayrev(array:'list')->'list': return reversed_array + +def fast_arrayrev(array: 'list') -> 'list': + """ + Reverses the elements of the input list. + + Parameters: + array (list): The list to be reversed. + + Returns: + list: A new list containing the elements of the input list in reverse order. + + Steps: + 1. The function takes a single argument, `array`, which is expected to be a list. + 2. It uses Python's slicing feature to reverse the list: + - The slice notation `array[::-1]` means: + - Start[start::] from the end [:end:] of the list (indicated by the negative step)[start : end : -1]. + - Move backwards through the list. + - The result is a new list that contains the elements of `array` in reverse order. + 3. The reversed list is stored in the variable `reversed_array`. + 4. Finally, the function returns `reversed_array`, which is the reversed version of the input list. + source: https://www.geeksforgeeks.org/python-reversed-vs-1-which-one-is-faster/ + """ + reversed_array = array[::-1] + return reversed_array \ No newline at end of file diff --git a/easyPythonpi/methods/linkedlist.py b/easyPythonpi/methods/linkedlist.py index fd49a7c..e0d851c 100644 --- a/easyPythonpi/methods/linkedlist.py +++ b/easyPythonpi/methods/linkedlist.py @@ -2,41 +2,56 @@ #-*- coding: utf-8 -*- -#Linked list - -def create_node(data:'int')->'list': - class node: - def __init__(self,data): - self.data=data - self.next=None - - a=node(data) +#Linked list + +class Node: + def __init__(self,data): + self.data=data + self.next=None + +def create_node(data:'int')->'Node': + a=Node(data) return a + # to link a node with another node -def node_link(a:'int',b:'int'): +def node_link(a:'Node', b:'Node'): a.next=b b.next=None #a=node(data1) - - -# to count number of nodes -def count_node(head:'node')->'int': + + +# to count number of nodes +def count_node(head:'Node')->'int': + count=0 if head is None: - return 0 + return count else: temp=head - count=0 while(temp!=None): - count=count+1 - temp=temp.next - return count + count=count+1 + temp=temp.next + return count # to diplay a linked list whose header node is passed as an argument. -def display_nodes(head:'node')->'int': +def display_nodes(head:'Node')->None: t=head while t is not None: print(t.data,"->",end="") t=t.next print("NULL") +# re revrese a lined list +def revrese_lined_list(head: 'Node')->'Node': + prev = None + # a -> b -> c -> d -> e -> f -> g -> h -> None + current = head + while current is not None: + next = current.next # b -> c -> d -> so one... + + current.next = prev # a -> None + prev = current # b -> a -> None + current = next # c -> d -> e -> f -> g -> h -> None + head=prev # h -> g -> f -> e -> d -> c -> b -> a -> None + + return head \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c2f6d95 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy >= 1.19.5 +requests >= 2.25.1 \ No newline at end of file diff --git a/setup.py b/setup.py index 33d6fda..f37a295 100644 --- a/setup.py +++ b/setup.py @@ -3,14 +3,65 @@ import codecs import os +try: + import requests + requests_installed = True +except ImportError: + requests_installed = False + #VERSION = '0.0.1' -VERSION = ( - subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE) - .stdout.decode("utf-8") - .strip() -) +# VERSION = ( +# subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE) +# .stdout.decode("utf-8") +# .strip() +# ) + +def get_pypi_version(): + if not requests_installed: + print("Warning: 'requests' module is not installed. Using default version.") + return "0.0.1" + try: + response = requests.get("https://pypi.org/pypi/easyPythonpi/json") + data = response.json() + return str(data["info"]["version"]) + except Exception as e: + print(f"Error fetching version from PyPI: {e}") + return "0.0.1" + +def increment_version(version): + major, minor, patch = map(int, version.split('.')) + patch += 1 + if patch > 9: + patch = 0 + minor += 1 + if minor > 9: + minor = 0 + major += 1 + return f"{major}.{minor}.{patch}" + +def get_version(): + pypi_version = get_pypi_version() + new_version = increment_version(pypi_version) + + try: + git_describe = subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True) + git_version = git_describe.stdout.decode("utf-8").strip() + + if "-" in git_version: + v, i, s = git_version.split("-") + git_version = f"{new_version}+{i}.git.{s}" + else: + git_version = new_version + except subprocess.CalledProcessError: + git_version = new_version + + return git_version + +VERSION = get_version() + +print("Version: ", VERSION) -if "-" in VERSION: +if VERSION and "-" in VERSION: # when not on tag, git describe outputs: "1.3.3-22-gdf81228" # pip has gotten strict with version numbers # so change it to: "1.3.3+22.git.gdf81228" @@ -39,7 +90,8 @@ description=DESCRIPTION, long_description_content_type="text/markdown", packages=find_packages(), - install_requires=["numpy >= 1.19.5"], + install_requires=["numpy >= 1.19.5"] + (["requests >= 2.25.1"] if not requests_installed else []), + setup_requires=["requests >= 2.25.1"], keywords=['python', 'sorting', 'beginners', 'sockets'], classifiers=[ "Development Status :: 1 - Planning",