diff --git a/packageimporter_1_2_0/.github/workflows/ci.yml b/packageimporter_1_2_0/.github/workflows/ci.yml new file mode 100644 index 0000000..4c15aac --- /dev/null +++ b/packageimporter_1_2_0/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: Package Importer + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: [3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Test with pytest + run: | + pip install pytest + pytest \ No newline at end of file diff --git a/packageimporter_1_2_0/.gitignore b/packageimporter_1_2_0/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/packageimporter_1_2_0/LICENSE.txt b/packageimporter_1_2_0/LICENSE.txt new file mode 100644 index 0000000..36dc1c9 --- /dev/null +++ b/packageimporter_1_2_0/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Ziyan Zhou + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/packageimporter_1_2_0/README.md b/packageimporter_1_2_0/README.md new file mode 100644 index 0000000..834c31b Binary files /dev/null and b/packageimporter_1_2_0/README.md differ diff --git a/packageimporter_1_2_0/dist/packageimporter-1.2.0-py3-none-any.whl b/packageimporter_1_2_0/dist/packageimporter-1.2.0-py3-none-any.whl new file mode 100644 index 0000000..e999ee5 Binary files /dev/null and b/packageimporter_1_2_0/dist/packageimporter-1.2.0-py3-none-any.whl differ diff --git a/packageimporter_1_2_0/dist/packageimporter-1.2.0.tar.gz b/packageimporter_1_2_0/dist/packageimporter-1.2.0.tar.gz new file mode 100644 index 0000000..0df705f Binary files /dev/null and b/packageimporter_1_2_0/dist/packageimporter-1.2.0.tar.gz differ diff --git a/packageimporter_1_2_0/packageimporter.egg-info/PKG-INFO b/packageimporter_1_2_0/packageimporter.egg-info/PKG-INFO new file mode 100644 index 0000000..c5b183b --- /dev/null +++ b/packageimporter_1_2_0/packageimporter.egg-info/PKG-INFO @@ -0,0 +1,35 @@ +Metadata-Version: 2.1 +Name: packageimporter +Version: 1.2.0 +Summary: A really simple package that allows you to import packages to your code +Author: Ziyan Zhou +Author-email: unknownuserfrommars@protonmail.com +Classifier: Programming Language :: Python :: 3.12 +Classifier: License :: OSI Approved :: MIT License +Classifier: Operating System :: OS Independent +Requires-Python: >=3.6 +Description-Content-Type: text/markdown +License-File: LICENSE.txt +Requires-Dist: setuptools>=69 + +# About +## PackageImporter is a simple project for importing projects according to different types (DataScience, Plotting, etc.) +# Installation +## To install PackageImporter, run this command into your terminal (Use Windows Powershell because I love it): +### pip install packageimporter +## For a specific version, run: +### pip install packageimporter=={version} +## To upgrade the exsisting PackageImporter module (which you probably don't): +### pip install --upgrade packageimporter +## note: you can either use python -m pip or py -m pip if it's different. (It may) PackageImporter has only one limitation: Python>=3.6 (Because there are f-strings) + +# Usage Example +## from packageimporter import Importer +## Importer.stable.Plotter.plotly.express(alias="i_love_plotly_express") +## # This will import plotly.express as i_love_plotly_express (weird alias) and raise an ModuleNotFoundError if plotly.express is not globally installed. + +# Update Notes: +## Added "ScienceAndMaths" Class that supports scipy and sympy +## Added "MyOwnModules" Class to import my own simple modules from PyPI +## Added "PackageImporterVersionCheck" Class to check the version. +## Fixed some minor grammartical issues with the README.md file diff --git a/packageimporter_1_2_0/packageimporter.egg-info/SOURCES.txt b/packageimporter_1_2_0/packageimporter.egg-info/SOURCES.txt new file mode 100644 index 0000000..12470ad --- /dev/null +++ b/packageimporter_1_2_0/packageimporter.egg-info/SOURCES.txt @@ -0,0 +1,8 @@ +LICENSE.txt +README.md +setup.py +packageimporter.egg-info/PKG-INFO +packageimporter.egg-info/SOURCES.txt +packageimporter.egg-info/dependency_links.txt +packageimporter.egg-info/requires.txt +packageimporter.egg-info/top_level.txt \ No newline at end of file diff --git a/packageimporter_1_2_0/packageimporter.egg-info/dependency_links.txt b/packageimporter_1_2_0/packageimporter.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/packageimporter_1_2_0/packageimporter.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/packageimporter_1_2_0/packageimporter.egg-info/requires.txt b/packageimporter_1_2_0/packageimporter.egg-info/requires.txt new file mode 100644 index 0000000..7997883 --- /dev/null +++ b/packageimporter_1_2_0/packageimporter.egg-info/requires.txt @@ -0,0 +1 @@ +setuptools>=69 diff --git a/packageimporter_1_2_0/packageimporter.egg-info/top_level.txt b/packageimporter_1_2_0/packageimporter.egg-info/top_level.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/packageimporter_1_2_0/packageimporter.egg-info/top_level.txt @@ -0,0 +1 @@ + diff --git a/packageimporter_1_2_0/packageimporter.py b/packageimporter_1_2_0/packageimporter.py new file mode 100644 index 0000000..707fbbf --- /dev/null +++ b/packageimporter_1_2_0/packageimporter.py @@ -0,0 +1,215 @@ +# Welcome to Version 1.2.0 of PackageImporter, released March 17, 2024 (Timezone unreliable) + +import importlib as impl + +cv = '1.2.0' + +class PackageImporterVersionCheck: + def Print(): + print(f'Current Version: {cv}') + def Return(): + f = f'Current Version: {cv}' + return f + +class Importer: + class MyOwnModules: + modules = { + 'pyprogramsimp': 'pprogs', + 'graphgame': 'gg', + 'packageimporter': 'pimport', + } + + @staticmethod + def import_module(module_name, alias=None): + """Import a single module with optional alias, error is raised if package is not globally installed""" + try: + if alias: + globals()[alias] = impl.import_module(module_name) + else: + globals()[module_name.split('.')[-1]] = impl.import_module(module_name) + except ModuleNotFoundError: + raise ModuleNotFoundError( + f"The module '{module_name}'is not globally installed, please install it first using pip" + ) + + @classmethod + def all(cls): + for module_name, pip_name in cls.modules.items(): + cls.import_module(module_name, pip_name if pip_name else module_name) + + @classmethod + def pyprogramsimp(cls, alias): + cls.import_module('pyprogramsimp', alias) + + @classmethod + def graphgame(cls, alias): + cls.import_module('graphgame', alias) + + @classmethod + def packageimporter(cls, alias): + cls.import_module('packageimporter', alias) + class ScienceAndMaths: + modules = { + 'scipy': None, + 'sympy': None, + } + + @staticmethod + def import_module(module_name, alias=None): + """Import a single module with optional alias, error is raised if package is not globally installed""" + try: + if alias: + globals()[alias] = impl.import_module(module_name) + else: + globals()[module_name.split('.')[-1]] = impl.import_module(module_name) + except ModuleNotFoundError: + raise ModuleNotFoundError( + f"The module '{module_name}'is not globally installed, please install it first using pip" + ) + + @classmethod + def scipy(cls, alias=None): + cls.import_module('scipy', alias) + + @classmethod + def sympy(cls, alias=None): + cls.import_module('sympy', alias) + + @classmethod + def all(cls): + for module_name, pip_name in cls.modules.items(): + cls.import_module(module_name, pip_name if pip_name else module_name) + class DataScience: + modules = { + 'pandas': None, + 'numpy': None, + 'sklearn': 'scikit-learn', + } + + @staticmethod + def import_module(module_name, alias=None): + """Import a single module with optional alias, error is raised if package is not globally installed""" + try: + if alias: + globals()[alias] = impl.import_module(module_name) + else: + globals()[module_name.split('.')[-1]] = impl.import_module(module_name) + except ModuleNotFoundError: + raise ModuleNotFoundError( + f"The module '{module_name}'is not globally installed, please install it first using pip" + ) + + @classmethod + def pandas(cls, alias=None): + cls.import_module('pandas', alias) + + @classmethod + def numpy(cls, alias=None): + cls.import_module('numpy', alias) + + @classmethod + def sklearn(cls, alias): # default alias is sklearn + cls.import_module('sklearn', alias) + + @classmethod + def all(cls): + for module_name, pip_name in cls.modules.items(): + cls.import_module(module_name, pip_name if pip_name else module_name) + + class Plotter: + class matplotlib: + modules = { + 'matplotlib.pyplot': 'plt', + 'matplotlib.style': 'style', + } + + @staticmethod + def import_module(module_name, alias): + """Import a single module with an alias""" + try: + module = impl.import_module(module_name) + if alias: + globals()[alias] = module + else: + default_alias = Importer.stable.Plotter.modules.get(module_name, module_name.split('.')[-1]) + globals()[default_alias] = module + except ModuleNotFoundError: + raise ModuleNotFoundError( + f"The module '{module_name}' is not installed." + ) + + @classmethod + def all(cls): + for alias, module_name in cls.modules.items(): + cls.import_module(module_name, alias) + + @classmethod + def pyplot(cls, alias=None): # default alias is plt + cls.import_module('matplotlib.pyplot', alias) + + @classmethod + def style(cls, alias=None): + cls.import_module('matplotlib.style', alias) + + class plotly: + modules = { + 'plotly.express': 'px', + 'plotly.graph_objects': 'go', + 'plotly.subplots': 'make_subplots', + } + + @staticmethod + def import_module(module_name, alias=None): + """Import a single module with an optional alias.""" + try: + module = impl.import_module(module_name) + if alias: + globals()[alias] = module + else: + # Use the default alias or module name if no alias is provided + default_alias = Importer.stable.Plotter.modules.get(module_name, module_name.split('.')[-1]) + globals()[default_alias] = module + except ModuleNotFoundError: + raise ModuleNotFoundError( + f"The module '{module_name}' is not installed. Please install it using pip (e.g., `pip install {module_name}`) before proceeding." + ) + + @classmethod + def express(cls, alias=None): + cls.import_module('plotly.express', alias) + + @classmethod + def graph_objects(cls, alias=None): + cls.import_module('plotly.graph_objects', alias) + + @classmethod + def subplots(cls, alias=None): + cls.import_module('plotly.subplots', alias) + + @classmethod + def all(cls): + for alias, module_name in cls.modules.items(): + cls.import_module(module_name, alias) + class Builtins: + modules = { + 'random': None, + 'time': None, + 'sys': None, + 'os': None, + } + def import_module(module_name, alias=None): + try: + module = impl.import_module(module_name) + if alias: + globals()[alias] = module + else: + default_alias = Importer.stable.Builtins.modules.get(module_name, module_name.split('.')[-1]) + globals()[default_alias] = module + except ModuleNotFoundError as e: + raise e(f"The module '{module_name}' is not installed, please install it using pip before proceeding.") + + # Notes: I've only done the 'all' for the Importer.stable.Builtins class because it seems to me that these are the basic imports for each program + @classmethod + def all(cls): + for alias, module_name in cls.modules.items(): + cls.import_module(module_name, alias) diff --git a/packageimporter_1_2_0/setup.py b/packageimporter_1_2_0/setup.py new file mode 100644 index 0000000..44d4f3b --- /dev/null +++ b/packageimporter_1_2_0/setup.py @@ -0,0 +1,21 @@ +from setuptools import setup, find_packages + +setup( + name='packageimporter', + version='1.2.0', + packages=find_packages(), + description='A really simple package that allows you to import packages to your code', + long_description=open('README.md').read(), + long_description_content_type='text/markdown', + author='Ziyan Zhou', + author_email='unknownuserfrommars@protonmail.com', + classifiers=[ + 'Programming Language :: Python :: 3.12', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + ], + install_requires=[ + 'setuptools >= 69', + ], + python_requires='>=3.6', +)