diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..46538de --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,53 @@ +name: Publish a new package + +on: + workflow_dispatch: + inputs: + version: + description: "The package version to create (ex: 1.0.0)" + required: true + +permissions: + id-token: write + contents: read + +jobs: + test-package: + timeout-minutes: 20 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.8 + + build-and-publish: + timeout-minutes: 20 + runs-on: ubuntu-latest + environment: publish + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.12" + + - name: test python + run: | + sudo apt install -y software-properties-common + sudo add-apt-repository ppa:deadsnakes/ppa + sudo apt install python3.8 -y + sudo apt install python3.9 -y + sudo apt install python3.10 -y + sudo apt install python3.11 -y + sudo apt install python3.12 -y + sudo apt install -y python3.8-distutils python3.9-distutils python3.10-distutils python3.11-distutils python3.12-distutils + + - name: Publish + run: | + bash tools/publish.sh + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: libtest_build + path: dist \ No newline at end of file diff --git a/.gitignore b/.gitignore index 82f9275..c6b9e3f 100644 --- a/.gitignore +++ b/.gitignore @@ -159,4 +159,5 @@ cython_debug/ # 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/ +.idea/ +*.pyi \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..1eb29c2 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,7 @@ +recursive-include src *.pyc *.pyi +include testlib-3.8.zip +include testlib-3.9.zip +include testlib-3.10.zip +include testlib-3.11.zip +include testlib-3.12.zip +include testlib/core/*.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5e4e1a7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,28 @@ +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "testlib" +version = "0.1.0" +description = "A basic Python library with LinkedList and BinaryTree data structures" +authors = [ + { name="Joao Andre", email="joao.dasilva@taipy.io" } +] +readme = "README.md" +license = { text = "MIT" } +requires-python = ">=3.8" +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] + +[project.urls] +homepage = "https://github.com/Avaiga/test_lib_compile" +repository = "https://github.com/Avaiga/test_lib_compile" +documentation = "https://github.com/Avaiga/test_lib_compile" + +[tool.setuptools.package-data] +testlib = ["*"] diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..20c1b8e --- /dev/null +++ b/setup.py @@ -0,0 +1,56 @@ +"""The setup script.""" +import json +import os +import sys +import zipfile + +from setuptools import find_namespace_packages, find_packages, setup + +with open("README.md") as readme_file: + readme = readme_file.read() + +_python_version = (sys.version_info[0], sys.version_info[1]) + + +def extract_zip_package(python_version: str): + file_path = f"{os.getcwd()}{os.path.sep}testlib-{python_version}.zip" + if zipfile.is_zipfile(file_path): + with zipfile.ZipFile(file_path, "r") as zip_ref: + zip_ref.extractall(f"{os.getcwd()}") + + +if _python_version < (3, 8): + sys.exit("Python >=3.8 is required to install testlib") + +if _python_version == (3, 8): + extract_zip_package("3.8") +elif _python_version == (3, 9): + extract_zip_package("3.9") +elif _python_version == (3, 10): + extract_zip_package("3.10") +elif _python_version == (3, 11): + extract_zip_package("3.11") +elif _python_version == (3, 12): + extract_zip_package("3.12") + +setup( + name="testlib", + version="0.1.0", + author="Your Name", + author_email="youremail@example.com", + description="A basic Python library with LinkedList and BinaryTree data structures", + long_description=open("README.md").read(), + long_description_content_type="text/markdown", + url="https://github.com/Avaiga/test_lib_compile", + include_package_data=True, + packages=find_namespace_packages(where=".") + find_packages( + include=["testlib", "testlib.core", "testlib.core.*"] + ), + classifiers=[ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], + python_requires='>=3.8', +) diff --git a/testlib/__init__.py b/testlib/__init__.py new file mode 100644 index 0000000..d91da9f --- /dev/null +++ b/testlib/__init__.py @@ -0,0 +1 @@ +from .main import Main \ No newline at end of file diff --git a/testlib/core/binarytree.py b/testlib/core/binarytree.py new file mode 100644 index 0000000..ac392a9 --- /dev/null +++ b/testlib/core/binarytree.py @@ -0,0 +1,37 @@ +class TreeNode: + def __init__(self, value): + self.value = value + self.left = None + self.right = None + +class BinaryTree: + def __init__(self): + self.root = None + + def insert(self, value): + if self.root is None: + self.root = TreeNode(value) + else: + self._insert_recursive(self.root, value) + + def _insert_recursive(self, node, value): + if value < node.value: + if node.left is None: + node.left = TreeNode(value) + else: + self._insert_recursive(node.left, value) + else: + if node.right is None: + node.right = TreeNode(value) + else: + self._insert_recursive(node.right, value) + + def inorder_traversal(self): + return self._inorder_recursive(self.root, []) + + def _inorder_recursive(self, node, result): + if node is not None: + self._inorder_recursive(node.left, result) + result.append(node.value) + self._inorder_recursive(node.right, result) + return result diff --git a/testlib/core/linkedlist.py b/testlib/core/linkedlist.py new file mode 100644 index 0000000..805baa6 --- /dev/null +++ b/testlib/core/linkedlist.py @@ -0,0 +1,26 @@ +class Node: + def __init__(self, value): + self.value = value + self.next = None + +class LinkedList: + def __init__(self): + self.head = None + + def insert(self, value): + new_node = Node(value) + if self.head is None: + self.head = new_node + else: + current = self.head + while current.next: + current = current.next + current.next = new_node + + def display(self): + nodes = [] + current = self.head + while current: + nodes.append(current.value) + current = current.next + return " -> ".join(map(str, nodes)) diff --git a/testlib/core/version.json b/testlib/core/version.json new file mode 100644 index 0000000..5bbc6a9 --- /dev/null +++ b/testlib/core/version.json @@ -0,0 +1 @@ +{"major": 0, "minor": 0, "patch": 0} diff --git a/testlib/core/version.py b/testlib/core/version.py new file mode 100644 index 0000000..e69de29 diff --git a/testlib/main.py b/testlib/main.py new file mode 100644 index 0000000..2f99b23 --- /dev/null +++ b/testlib/main.py @@ -0,0 +1,20 @@ +from .core.linkedlist import LinkedList +from .core.binarytree import BinaryTree + + +class Main: + def __init__(self): + self.linked_list = LinkedList() + self.binary_tree = BinaryTree() + + def insert_to_linked_list(self, value): + self.linked_list.insert(value) + + def display_linked_list(self): + return self.linked_list.display() + + def insert_to_binary_tree(self, value): + self.binary_tree.insert(value) + + def display_binary_tree_inorder(self): + return self.binary_tree.inorder_traversal() diff --git a/tools/publish.sh b/tools/publish.sh new file mode 100755 index 0000000..d92d081 --- /dev/null +++ b/tools/publish.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +python3.10 -m pip install build + +cp -fR testlib/. tmp + +compile() { + PYTHON_PATH=$1 + ZIP_FILE=$2 + + # create new working dir + cp -R tmp testlib + # generate pyi + $PYTHON_PATH -O -m compileall testlib -b -f + # Generate pyi + $PYTHON_PATH -m pip install mypy + stubgen testlib -o ./ + # Remove unnecessary files + find testlib -name '*.py' -delete + find testlib -type d -name "__pycache__" -exec rm -r {} + + # zip folder + zip -r $ZIP_FILE testlib + # remove current working dir + rm -rf testlib +} + +compile python3.8 ./testlib-3.8.zip +compile python3.9 ./testlib-3.9.zip +compile python3.10 ./testlib-3.10.zip +compile python3.11 ./testlib-3.11.zip +compile python3.12 ./testlib-3.12.zip + +rm -rf tmp + +find src -name '*.py' -delete + +python3.10 -m build