├── LICENSE ├── MANIFEST.in ├── README.md ├── example.py ├── setup.py └── tariff ├── __init__.py └── __main__.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Tariff Package Contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md 2 | include LICENSE -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 👊 TARIFF 🔥 2 | 3 | 4 | The GREATEST, most TREMENDOUS Python package that makes importing great again! 5 | 6 | ![MIGA](https://i.imgur.com/2OoRBu6.png) 7 | 8 | ## About 9 | 10 | TARIFF is a fantastic tool that lets you impose import tariffs on Python packages. We're going to bring manufacturing BACK to your codebase by making foreign imports more EXPENSIVE! 11 | 12 | ![meme](https://github.com/user-attachments/assets/c0b37be1-28ca-40d3-9234-cbdb3074c8eb) 13 | 14 | ## Installation 15 | 16 | ```bash 17 | pip install tariff 18 | ``` 19 | 20 | ## Usage 21 | 22 | ```python 23 | import tariff 24 | 25 | # Set your tariff rates (package_name: percentage) 26 | tariff.set({ 27 | "numpy": 50, # 50% tariff on numpy 28 | "pandas": 200, # 200% tariff on pandas 29 | "requests": 150 # 150% tariff on requests 30 | }) 31 | 32 | # Now when you import these packages, they'll be TARIFFED! 33 | import numpy # This will be 50% slower 34 | import pandas # This will be 200% slower 35 | ``` 36 | 37 | ## How It Works 38 | 39 | When you import a package that has a tariff: 40 | 1. TARIFF measures how long the original import takes 41 | 2. TARIFF makes the import take longer based on your tariff percentage 42 | 3. TARIFF announces the tariff with a TREMENDOUS message 43 | 44 | ## Example Output 45 | 46 | ``` 47 | JUST IMPOSED a 50% TARIFF on numpy! Original import took 45000 us, now takes 67500 us. American packages are WINNING AGAIN! #MIGA 48 | ``` 49 | 50 | ## Why TARIFF? 51 | 52 | Because foreign packages have been STEALING our CPU cycles for TOO LONG! It's time to put AMERICA FIRST and make importing FAIR and BALANCED again! 53 | 54 | ## License 55 | 56 | This is a parody package. Use at your own risk. MAKE IMPORTING GREAT AGAIN! 57 | -------------------------------------------------------------------------------- /example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Example usage of the tariff package. 4 | """ 5 | 6 | import tariff 7 | 8 | print("Setting tariffs on packages...") 9 | tariff.set({ 10 | "time": 50, # 50% tariff 11 | "os": 100, # 100% tariff 12 | "sys": 200 # 200% tariff 13 | }) 14 | 15 | print("\nImporting packages with tariffs:") 16 | import time 17 | import os 18 | import sys 19 | 20 | print("\nImporting a package without tariffs:") 21 | import json 22 | 23 | print("\nDemo completed! Make importing great again! 🇺🇸") -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | with open("README.md", "r", encoding="utf-8") as fh: 4 | long_description = fh.read() 5 | 6 | setup( 7 | name="tariff", 8 | version="1.0.0", 9 | author="Python Economist", 10 | author_email="huan.xu71@gmail.com", 11 | description="Make importing great again! A parody package that imposes tariffs on Python imports.", 12 | long_description=long_description, 13 | long_description_content_type="text/markdown", 14 | url="https://github.com/hxu296/tariff", 15 | packages=find_packages(), 16 | classifiers=[ 17 | "Programming Language :: Python :: 3", 18 | "License :: OSI Approved :: MIT License", 19 | "Operating System :: OS Independent", 20 | "Development Status :: 3 - Alpha", 21 | "Intended Audience :: Developers", 22 | "Topic :: Software Development :: Libraries :: Python Modules", 23 | "Topic :: Utilities", 24 | ], 25 | python_requires=">=3.6", 26 | keywords="import, tariff, parody, monkey-patch", 27 | ) -------------------------------------------------------------------------------- /tariff/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 🇺🇸 TARIFF 🇺🇸 - Make importing great again! 3 | """ 4 | 5 | import sys 6 | import time 7 | import builtins 8 | import importlib 9 | import random 10 | 11 | # Store the original import function 12 | original_import = builtins.__import__ 13 | 14 | # Global tariff sheet 15 | _tariff_sheet = {} 16 | 17 | # List of Trump-like phrases 18 | _trump_phrases = [ 19 | "American packages are WINNING AGAIN!", 20 | "We're bringing back JOBS to our codebase!", 21 | "This is how we get FAIR TRADE in Python!", 22 | "Big win for AMERICAN programmers!", 23 | "No more BAD DEALS with foreign packages!", 24 | "Making Programming Great Again!", 25 | "Believe me, this is the BEST tariff!", 26 | "We're going to win SO MUCH, you'll get tired of winning!", 27 | "This is how we Keep America Coding Again!", 28 | "HUGE success!" 29 | ] 30 | 31 | def _get_trump_phrase(): 32 | """Get a random Trump-like phrase.""" 33 | return random.choice(_trump_phrases) 34 | 35 | def set(tariff_sheet): 36 | """ 37 | Set tariff rates for packages. 38 | 39 | Args: 40 | tariff_sheet (dict): Dictionary mapping package names to tariff percentages. 41 | e.g., {"numpy": 50, "pandas": 200} 42 | """ 43 | global _tariff_sheet 44 | _tariff_sheet = tariff_sheet 45 | 46 | # Only patch the import once 47 | if builtins.__import__ is not original_import: 48 | return 49 | 50 | # Replace the built-in import with our custom version 51 | builtins.__import__ = _tariffed_import 52 | 53 | def _tariffed_import(name, globals=None, locals=None, fromlist=(), level=0): 54 | """Custom import function that applies tariffs.""" 55 | # Check if the package is in our tariff sheet 56 | base_package = name.split('.')[0] 57 | tariff_rate = _tariff_sheet.get(base_package) 58 | 59 | # Measure import time 60 | start_time = time.time() 61 | module = original_import(name, globals, locals, fromlist, level) 62 | original_import_time = (time.time() - start_time) * 1000000 # convert to microseconds 63 | 64 | # Apply tariff if applicable 65 | if tariff_rate is not None: 66 | # Calculate sleep time based on tariff rate 67 | sleep_time = original_import_time * (tariff_rate / 100) 68 | time.sleep(sleep_time / 1000000) # convert back to seconds 69 | 70 | # Calculate new total time 71 | new_total_time = original_import_time + sleep_time 72 | 73 | # Print tariff announcement in Trump style 74 | print(f"JUST IMPOSED a {tariff_rate}% TARIFF on {base_package}! Original import took {int(original_import_time)} us, " 75 | f"now takes {int(new_total_time)} us. {_get_trump_phrase()}") 76 | 77 | return module -------------------------------------------------------------------------------- /tariff/__main__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Main entry point for the tariff package. 3 | """ 4 | 5 | if __name__ == "__main__": 6 | print("🇺🇸 TARIFF 🇺🇸 - Make importing great again!") 7 | print("Import this package and use tariff.set() to impose tariffs on imports.") 8 | print("Example: tariff.set({'numpy': 50, 'pandas': 200})") --------------------------------------------------------------------------------