Skip to content

Commit

Permalink
New Api First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofix committed Dec 21, 2024
1 parent 4d10984 commit 9dd0527
Show file tree
Hide file tree
Showing 35 changed files with 2,741 additions and 1,065 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ pip-selfcheck.json

# VSCode
.vscode

uv.lock
115 changes: 115 additions & 0 deletions ejemplo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# import khipu_tools

# khipu_tools.api_key = "your-secret-api-key"
# khipu_tools.log = "debug"
# banks = khipu_tools.Banks.getBanks()
# print(f"{banks = }")

# prediction = khipu_tools.Predict.get()
# print(f"{prediction = }")

import json
import os
import sys
import traceback
from collections import defaultdict

files = []
function_calls = defaultdict(lambda: defaultdict(int))


def trace_calls(frame, event, arg):
if event == "call":
# Get information about the function being called
code = frame.f_code
func_name = code.co_name
file_name = code.co_filename

allowed_directory = "/home/mariofix/proyectos/khipu-tools"

# Only include files from the allowed directory
if not file_name.startswith(allowed_directory):
return

if "site-packages" in file_name or "/usr/lib/python" in file_name:

return

# Print function name, file, and line number
# print(f"Function: {func_name}, File: {file_name}, Line: {line_no}")
function_calls[file_name][func_name] += 1

return trace_calls


def main():
import khipu_tools

khipu_tools.api_key = "your-secret-api-key"
khipu_tools.log = "debug"

prediction = khipu_tools.Predict.get(
payer_email="yo@mariofix.com",
amount="500000",
currency="CLP",
)
print(prediction)


def list_unused_files(tracked_files, project_directory):
"""
Lists files in the project directory that were not used in the script.
Args:
tracked_files (list): List of file paths that were traced during execution.
project_directory (str): Path to the root directory of the project.
Returns:
list: List of file paths that are in the project directory but were not used.
"""
# Get all Python files in the project directory
all_files = []
for root, _, files in os.walk(project_directory):
for file in files:
if file.endswith(".py"): # Only consider Python files
all_files.append(os.path.join(root, file))

# Normalize paths for comparison
tracked_files_set = {os.path.normpath(file) for file in tracked_files}
all_files_set = {os.path.normpath(file) for file in all_files}

# Find unused files
unused_files = all_files_set - tracked_files_set
return sorted(unused_files)


if __name__ == "__main__":
sys.settrace(trace_calls) # Set the trace function
try:
main() # Run your script
except Exception:
traceback.print_exc()
finally:
sys.settrace(None) # Disable the trace function

# Format the output as the required JSON structure
output = []
for file_name, functions in function_calls.items():
modules = [
{"function": func_name, "count": count}
for func_name, count in functions.items()
]
output.append({"file": file_name, "modules": modules})

# Print the JSON string
# print(json.dumps(output))

project_directory = "/home/mariofix/proyectos/khipu-tools/khipu_tools"
tracked_files = tracked_files = list(function_calls.keys())

# Get unused files
unused_files = list_unused_files(tracked_files, project_directory)

print("Unused files:")
for file in unused_files:
print(file)
59 changes: 59 additions & 0 deletions khipu_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from typing import Optional

from typing_extensions import Literal

from khipu_tools._api_requestor import _APIRequestor
from khipu_tools._api_version import _ApiVersion
from khipu_tools._app_info import AppInfo as AppInfo
from khipu_tools._version import VERSION as VERSION

# Constants
DEFAULT_API_BASE: str = "http://tardis.local:5000"

api_key: Optional[str] = None
api_base: str = DEFAULT_API_BASE
api_version: str = _ApiVersion.CURRENT
default_http_client: Optional["HTTPClient"] = None
app_info: Optional[AppInfo] = None
enable_telemetry: bool = False
max_network_retries: int = 0
default_http_client = None


def ensure_default_http_client():
_init_default_http_client()


def _init_default_http_client():
global default_http_client

default_http_client = new_default_http_client()


log: Optional[Literal["debug", "info"]] = None


def set_app_info(
name: str,
url: Optional[str] = None,
version: Optional[str] = None,
):
global app_info
app_info = {
"name": name,
"url": url,
"version": version,
}


# Infrastructure types
from khipu_tools._api_resource import APIResource as APIResource
from khipu_tools._khipu_client import KhipuClient as KhipuClient

from khipu_tools._http_client import (
new_default_http_client as new_default_http_client,
)

from khipu_tools._banks import Banks as Banks

from khipu_tools._predict import Predict as Predict
3 changes: 3 additions & 0 deletions khipu_tools/_api_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing_extensions import Literal

ApiMode = Literal["V3"]
Loading

0 comments on commit 9dd0527

Please sign in to comment.