-
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
7babfb8
commit 85a6244
Showing
13 changed files
with
334 additions
and
0 deletions.
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,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 |
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,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. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,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: [email protected] | ||
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 |
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,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 |
1 change: 1 addition & 0 deletions
1
packageimporter_1_2_0/packageimporter.egg-info/dependency_links.txt
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 @@ | ||
|
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 @@ | ||
setuptools>=69 |
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 @@ | ||
|
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,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) |
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,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='[email protected]', | ||
classifiers=[ | ||
'Programming Language :: Python :: 3.12', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
], | ||
install_requires=[ | ||
'setuptools >= 69', | ||
], | ||
python_requires='>=3.6', | ||
) |