aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2025-04-20 14:17:36 -0400
committerAnthony Wang2025-04-20 14:18:15 -0400
commitce91c0d4902785c26a9d5705caa22f60b3ebc18a (patch)
tree403e96bc809927d08233f02e77319940a0d32a38
Initial commitHEADmaster
-rw-r--r--.gitignore10
-rw-r--r--.python-version1
-rw-r--r--README.md1
-rw-r--r--main.py83
-rw-r--r--pyproject.toml9
-rw-r--r--uv.lock8
6 files changed, 112 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..505a3b1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+# Python-generated files
+__pycache__/
+*.py[oc]
+build/
+dist/
+wheels/
+*.egg-info
+
+# Virtual environments
+.venv
diff --git a/.python-version b/.python-version
new file mode 100644
index 0000000..24ee5b1
--- /dev/null
+++ b/.python-version
@@ -0,0 +1 @@
+3.13
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0bf8e96
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# self-tariff
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..f36e3c1
--- /dev/null
+++ b/main.py
@@ -0,0 +1,83 @@
+# Copied from https://raw.githubusercontent.com/hxu296/tariff/refs/heads/main/tariff/__init__.py
+# There's probably a better way to do this
+
+import sys
+import time
+import builtins
+import importlib
+import random
+
+# Store the original import function
+original_import = builtins.__import__
+
+# Global tariff sheet
+_tariff_sheet = {}
+
+# List of Trump-like phrases
+_trump_phrases = [
+ "American packages are WINNING AGAIN!",
+ "We're bringing back JOBS to our codebase!",
+ "This is how we get FAIR TRADE in Python!",
+ "Big win for AMERICAN programmers!",
+ "No more BAD DEALS with foreign packages!",
+ "Making Programming Great Again!",
+ "Believe me, this is the BEST tariff!",
+ "We're going to win SO MUCH, you'll get tired of winning!",
+ "This is how we Keep America Coding Again!",
+ "HUGE success!"
+]
+
+def _get_trump_phrase():
+ """Get a random Trump-like phrase."""
+ return random.choice(_trump_phrases)
+
+def set(tariff_sheet):
+ """
+ Set tariff rates for packages.
+
+ Args:
+ tariff_sheet (dict): Dictionary mapping package names to tariff percentages.
+ e.g., {"numpy": 50, "pandas": 200}
+ """
+ global _tariff_sheet
+ _tariff_sheet = tariff_sheet
+
+ # Only patch the import once
+ if builtins.__import__ is not original_import:
+ return
+
+ # Replace the built-in import with our custom version
+ builtins.__import__ = _tariffed_import
+
+def _tariffed_import(name, globals=None, locals=None, fromlist=(), level=0):
+ """Custom import function that applies tariffs."""
+ # Check if the package is in our tariff sheet
+ base_package = name.split('.')[0]
+ tariff_rate = _tariff_sheet.get(base_package)
+
+ # Measure import time
+ start_time = time.time()
+ module = original_import(name, globals, locals, fromlist, level)
+ original_import_time = (time.time() - start_time) * 1000000 # convert to microseconds
+
+ # Apply tariff if applicable
+ if tariff_rate is not None:
+ # Calculate sleep time based on tariff rate
+ sleep_time = original_import_time * (tariff_rate / 100)
+ time.sleep(sleep_time / 1000000) # convert back to seconds
+
+ # Calculate new total time
+ new_total_time = original_import_time + sleep_time
+
+ # Print tariff announcement in Trump style
+ print(f"JUST IMPOSED a {tariff_rate}% TARIFF on {base_package}! Original import took {int(original_import_time)} us, "
+ f"now takes {int(new_total_time)} us. {_get_trump_phrase()}")
+
+ return module
+
+# import tariff
+set({"tariff": 100000})
+import tariff
+# _tariffed_import("tariff")
+# tariff.set()
+
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..bf6db5d
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,9 @@
+[project]
+name = "self-tariff"
+version = "0.1.0"
+description = "Add your description here"
+readme = "README.md"
+requires-python = ">=3.13"
+dependencies = [
+
+]
diff --git a/uv.lock b/uv.lock
new file mode 100644
index 0000000..152ca0b
--- /dev/null
+++ b/uv.lock
@@ -0,0 +1,8 @@
+version = 1
+revision = 1
+requires-python = ">=3.13"
+
+[[package]]
+name = "self-tariff"
+version = "0.1.0"
+source = { virtual = "." }