-
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.
- Loading branch information
1 parent
faa0d39
commit d8b8eda
Showing
13 changed files
with
268 additions
and
1 deletion.
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,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 |
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
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,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 |
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,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="[email protected]" } | ||
] | ||
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 = ["*"] |
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,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="[email protected]", | ||
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', | ||
) |
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 @@ | ||
from .main import Main |
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,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 |
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,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)) |
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,20 @@ | ||
from testlib.linkedlist import LinkedList | ||
from testlib.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() |
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 @@ | ||
{"major": 0, "minor": 0, "patch": 0} |
Empty file.
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,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 |