From 939b947cd55f083819ca185ed2a0241d27286c07 Mon Sep 17 00:00:00 2001 From: echedey-luis-alvarez <80125792+echedey-ls@users.noreply.github.com> Date: Mon, 26 Sep 2022 00:59:42 +0200 Subject: [PATCH 1/6] Modify installation and exposing of .mplstyles * Change distribution scheme similar to https://github.com/dhaitz/mplcyberpunk - Clears copy of files to .matplolib/styles * Bump version to 1.1.0 --- .gitignore | 161 ++++++++++++++++++ SciencePlots/__init__.py | 19 +++ .../styles}/color/bright.mplstyle | 0 .../styles}/color/high-contrast.mplstyle | 0 .../styles}/color/high-vis.mplstyle | 0 .../styles}/color/light.mplstyle | 0 .../styles}/color/muted.mplstyle | 0 .../styles}/color/retro.mplstyle | 0 .../styles}/color/std-colors.mplstyle | 0 .../styles}/color/vibrant.mplstyle | 0 .../styles}/journals/ieee.mplstyle | 0 .../styles}/journals/nature.mplstyle | 0 .../styles}/misc/cjk-jp-font.mplstyle | 0 .../styles}/misc/cjk-kr-font.mplstyle | 0 .../styles}/misc/cjk-sc-font.mplstyle | 0 .../styles}/misc/cjk-tc-font.mplstyle | 0 .../styles}/misc/grid.mplstyle | 0 .../styles}/misc/latex-sans.mplstyle | 0 .../styles}/misc/no-latex.mplstyle | 0 .../styles}/misc/pgf.mplstyle | 0 .../styles}/misc/russian-font.mplstyle | 0 .../styles}/misc/sans.mplstyle | 0 .../styles}/notebook.mplstyle | 0 .../styles}/scatter.mplstyle | 0 .../styles}/science.mplstyle | 0 setup.py | 49 ++++-- 26 files changed, 211 insertions(+), 18 deletions(-) create mode 100644 SciencePlots/__init__.py rename {styles => SciencePlots/styles}/color/bright.mplstyle (100%) rename {styles => SciencePlots/styles}/color/high-contrast.mplstyle (100%) rename {styles => SciencePlots/styles}/color/high-vis.mplstyle (100%) rename {styles => SciencePlots/styles}/color/light.mplstyle (100%) rename {styles => SciencePlots/styles}/color/muted.mplstyle (100%) rename {styles => SciencePlots/styles}/color/retro.mplstyle (100%) rename {styles => SciencePlots/styles}/color/std-colors.mplstyle (100%) rename {styles => SciencePlots/styles}/color/vibrant.mplstyle (100%) rename {styles => SciencePlots/styles}/journals/ieee.mplstyle (100%) rename {styles => SciencePlots/styles}/journals/nature.mplstyle (100%) rename {styles => SciencePlots/styles}/misc/cjk-jp-font.mplstyle (100%) rename {styles => SciencePlots/styles}/misc/cjk-kr-font.mplstyle (100%) rename {styles => SciencePlots/styles}/misc/cjk-sc-font.mplstyle (100%) rename {styles => SciencePlots/styles}/misc/cjk-tc-font.mplstyle (100%) rename {styles => SciencePlots/styles}/misc/grid.mplstyle (100%) rename {styles => SciencePlots/styles}/misc/latex-sans.mplstyle (100%) rename {styles => SciencePlots/styles}/misc/no-latex.mplstyle (100%) rename {styles => SciencePlots/styles}/misc/pgf.mplstyle (100%) rename {styles => SciencePlots/styles}/misc/russian-font.mplstyle (100%) rename {styles => SciencePlots/styles}/misc/sans.mplstyle (100%) rename {styles => SciencePlots/styles}/notebook.mplstyle (100%) rename {styles => SciencePlots/styles}/scatter.mplstyle (100%) rename {styles => SciencePlots/styles}/science.mplstyle (100%) diff --git a/.gitignore b/.gitignore index ba52e69..6aa9f8b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,164 @@ dev/ TODO.md new-version.md + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/SciencePlots/__init__.py b/SciencePlots/__init__.py new file mode 100644 index 0000000..3865eb5 --- /dev/null +++ b/SciencePlots/__init__.py @@ -0,0 +1,19 @@ +from os import listdir +from os.path import isdir, join + +import matplotlib.pyplot as plt + +import pkg_resources + +# register the included stylesheet in the matplotlib style library +# TODO: migrate to importlib_resources when possible +data_path = pkg_resources.resource_filename('SciencePlots', 'styles/') +stylesheets = plt.style.core.read_style_directory(data_path) # Reads styles in /styles +# Reads styles in /styles subfolders +for inode in listdir(data_path): + new_data_path = join(data_path, inode) + if isdir(new_data_path): + new_stylesheets = plt.style.core.read_style_directory(new_data_path) + stylesheets.update(new_stylesheets) +# Update dictionary of styles +plt.style.core.update_nested_dict(plt.style.library, stylesheets) diff --git a/styles/color/bright.mplstyle b/SciencePlots/styles/color/bright.mplstyle similarity index 100% rename from styles/color/bright.mplstyle rename to SciencePlots/styles/color/bright.mplstyle diff --git a/styles/color/high-contrast.mplstyle b/SciencePlots/styles/color/high-contrast.mplstyle similarity index 100% rename from styles/color/high-contrast.mplstyle rename to SciencePlots/styles/color/high-contrast.mplstyle diff --git a/styles/color/high-vis.mplstyle b/SciencePlots/styles/color/high-vis.mplstyle similarity index 100% rename from styles/color/high-vis.mplstyle rename to SciencePlots/styles/color/high-vis.mplstyle diff --git a/styles/color/light.mplstyle b/SciencePlots/styles/color/light.mplstyle similarity index 100% rename from styles/color/light.mplstyle rename to SciencePlots/styles/color/light.mplstyle diff --git a/styles/color/muted.mplstyle b/SciencePlots/styles/color/muted.mplstyle similarity index 100% rename from styles/color/muted.mplstyle rename to SciencePlots/styles/color/muted.mplstyle diff --git a/styles/color/retro.mplstyle b/SciencePlots/styles/color/retro.mplstyle similarity index 100% rename from styles/color/retro.mplstyle rename to SciencePlots/styles/color/retro.mplstyle diff --git a/styles/color/std-colors.mplstyle b/SciencePlots/styles/color/std-colors.mplstyle similarity index 100% rename from styles/color/std-colors.mplstyle rename to SciencePlots/styles/color/std-colors.mplstyle diff --git a/styles/color/vibrant.mplstyle b/SciencePlots/styles/color/vibrant.mplstyle similarity index 100% rename from styles/color/vibrant.mplstyle rename to SciencePlots/styles/color/vibrant.mplstyle diff --git a/styles/journals/ieee.mplstyle b/SciencePlots/styles/journals/ieee.mplstyle similarity index 100% rename from styles/journals/ieee.mplstyle rename to SciencePlots/styles/journals/ieee.mplstyle diff --git a/styles/journals/nature.mplstyle b/SciencePlots/styles/journals/nature.mplstyle similarity index 100% rename from styles/journals/nature.mplstyle rename to SciencePlots/styles/journals/nature.mplstyle diff --git a/styles/misc/cjk-jp-font.mplstyle b/SciencePlots/styles/misc/cjk-jp-font.mplstyle similarity index 100% rename from styles/misc/cjk-jp-font.mplstyle rename to SciencePlots/styles/misc/cjk-jp-font.mplstyle diff --git a/styles/misc/cjk-kr-font.mplstyle b/SciencePlots/styles/misc/cjk-kr-font.mplstyle similarity index 100% rename from styles/misc/cjk-kr-font.mplstyle rename to SciencePlots/styles/misc/cjk-kr-font.mplstyle diff --git a/styles/misc/cjk-sc-font.mplstyle b/SciencePlots/styles/misc/cjk-sc-font.mplstyle similarity index 100% rename from styles/misc/cjk-sc-font.mplstyle rename to SciencePlots/styles/misc/cjk-sc-font.mplstyle diff --git a/styles/misc/cjk-tc-font.mplstyle b/SciencePlots/styles/misc/cjk-tc-font.mplstyle similarity index 100% rename from styles/misc/cjk-tc-font.mplstyle rename to SciencePlots/styles/misc/cjk-tc-font.mplstyle diff --git a/styles/misc/grid.mplstyle b/SciencePlots/styles/misc/grid.mplstyle similarity index 100% rename from styles/misc/grid.mplstyle rename to SciencePlots/styles/misc/grid.mplstyle diff --git a/styles/misc/latex-sans.mplstyle b/SciencePlots/styles/misc/latex-sans.mplstyle similarity index 100% rename from styles/misc/latex-sans.mplstyle rename to SciencePlots/styles/misc/latex-sans.mplstyle diff --git a/styles/misc/no-latex.mplstyle b/SciencePlots/styles/misc/no-latex.mplstyle similarity index 100% rename from styles/misc/no-latex.mplstyle rename to SciencePlots/styles/misc/no-latex.mplstyle diff --git a/styles/misc/pgf.mplstyle b/SciencePlots/styles/misc/pgf.mplstyle similarity index 100% rename from styles/misc/pgf.mplstyle rename to SciencePlots/styles/misc/pgf.mplstyle diff --git a/styles/misc/russian-font.mplstyle b/SciencePlots/styles/misc/russian-font.mplstyle similarity index 100% rename from styles/misc/russian-font.mplstyle rename to SciencePlots/styles/misc/russian-font.mplstyle diff --git a/styles/misc/sans.mplstyle b/SciencePlots/styles/misc/sans.mplstyle similarity index 100% rename from styles/misc/sans.mplstyle rename to SciencePlots/styles/misc/sans.mplstyle diff --git a/styles/notebook.mplstyle b/SciencePlots/styles/notebook.mplstyle similarity index 100% rename from styles/notebook.mplstyle rename to SciencePlots/styles/notebook.mplstyle diff --git a/styles/scatter.mplstyle b/SciencePlots/styles/scatter.mplstyle similarity index 100% rename from styles/scatter.mplstyle rename to SciencePlots/styles/scatter.mplstyle diff --git a/styles/science.mplstyle b/SciencePlots/styles/science.mplstyle similarity index 100% rename from styles/science.mplstyle rename to SciencePlots/styles/science.mplstyle diff --git a/setup.py b/setup.py index a5a6dca..598eef0 100644 --- a/setup.py +++ b/setup.py @@ -1,21 +1,26 @@ """Install SciencePlots. -This script (setup.py) will copy the matplotlib styles (*.mplstyle) into the -appropriate directory on your computer (OS dependent). - -This code is based on a StackOverflow answer: -https://stackoverflow.com/questions/31559225/how-to-ship-or-distribute-a-matplotlib-stylesheet - +This script (setup.py) will install the SciencePlots package. +In order to expose .mplstyle files to matplotlib, "import SciencePlots" +must be called before plt.style.use(...). """ -import atexit -import glob import os -import shutil -import matplotlib from setuptools import setup -from setuptools.command.install import install + + +# def install_styles(): +# # Find all style files +# stylefiles = glob.glob('styles/**/*.mplstyle', recursive=True) +# # Find stylelib directory (where the *.mplstyle files go) +# # Copy files over +# print("Installing styles into", mpl_stylelib_dir) +# for stylefile in stylefiles: +# print(os.path.basename(stylefile)) +# shutil.copy( +# stylefile, +# os.path.join(mpl_stylelib_dir, os.path.basename(stylefile))) def install_styles(): @@ -30,11 +35,9 @@ def install_styles(): for stylefile in stylefiles: print(os.path.basename(stylefile)) shutil.copy( - stylefile, - os.path.join(mpl_stylelib_dir, os.path.basename(stylefile))) +# ('notebook.mplstyle', 'scatter.mplstyle', 'science.mplstyle', 'bright.mplstyle', 'high-contrast.mplstyle', 'high-vis.mplstyle', 'light.mplstyle', 'muted.mplstyle', 'retro.mplstyle', 'std-colors.mplstyle', 'vibrant.mplstyle', 'ieee.mplstyle', 'nature.mplstyle', 'cjk-jp-font.mplstyle', 'cjk-kr-font.mplstyle', 'cjk-sc-font.mplstyle', 'cjk-tc-font.mplstyle', 'grid.mplstyle', 'latex-sans.mplstyle', 'no-latex.mplstyle', 'pgf.mplstyle', 'russian-font.mplstyle', 'sans.mplstyle') -class PostInstallMoveFile(install): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) atexit.register(install_styles) @@ -47,13 +50,25 @@ def __init__(self, *args, **kwargs): setup( name='SciencePlots', - version='1.0.9', + version='1.1.0', author="John Garrett", author_email="garrettj403@gmail.com", description="Format Matplotlib for scientific plotting", long_description=long_description, long_description_content_type='text/markdown', license="MIT", + url="https://github.com/garrettj403/SciencePlots/", + + install_requires=['matplotlib'], + packages=["SciencePlots"], + package_data={ + 'SciencePlots': ['styles/**/*.mplstyle'], + }, + + classifiers=[ + 'Framework :: Matplotlib', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3' keywords=[ "matplotlib-style-sheets", "matplotlib-figures", @@ -62,7 +77,5 @@ def __init__(self, *args, **kwargs): "matplotlib-styles", "python" ], - url="https://github.com/garrettj403/SciencePlots/", - install_requires=['matplotlib', ], - cmdclass={'install': PostInstallMoveFile, }, + # cmdclass={'install': PostInstallMoveFile, }, ) From 1a1b13ebc604cf12045f10b4dae297bb354b9bbf Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Tue, 27 Sep 2022 16:07:52 +0200 Subject: [PATCH 2/6] Update setup.py Dunno how I messed up the GH Desktop selections duh Now you got everything although commented --- setup.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index 598eef0..20e4ab3 100644 --- a/setup.py +++ b/setup.py @@ -5,15 +5,28 @@ must be called before plt.style.use(...). """ +# Commented out code is due to how installation was made. +# That code is based on a StackOverflow answer: +# https://stackoverflow.com/questions/31559225/how-to-ship-or-distribute-a-matplotlib-stylesheet +# It will remain here until a decision is made on if we should uninstall old versions or just ignore the issue. + +# import atexit +# import glob import os +# import shutil +# import matplotlib from setuptools import setup +# from setuptools.command.install import install # def install_styles(): # # Find all style files # stylefiles = glob.glob('styles/**/*.mplstyle', recursive=True) # # Find stylelib directory (where the *.mplstyle files go) +# mpl_stylelib_dir = os.path.join(matplotlib.get_configdir(), "stylelib") +# if not os.path.exists(mpl_stylelib_dir): +# os.makedirs(mpl_stylelib_dir) # # Copy files over # print("Installing styles into", mpl_stylelib_dir) # for stylefile in stylefiles: @@ -23,24 +36,13 @@ # os.path.join(mpl_stylelib_dir, os.path.basename(stylefile))) -def install_styles(): - # Find all style files - stylefiles = glob.glob('styles/**/*.mplstyle', recursive=True) - # Find stylelib directory (where the *.mplstyle files go) - mpl_stylelib_dir = os.path.join(matplotlib.get_configdir(), "stylelib") - if not os.path.exists(mpl_stylelib_dir): - os.makedirs(mpl_stylelib_dir) - # Copy files over - print("Installing styles into", mpl_stylelib_dir) - for stylefile in stylefiles: - print(os.path.basename(stylefile)) - shutil.copy( # ('notebook.mplstyle', 'scatter.mplstyle', 'science.mplstyle', 'bright.mplstyle', 'high-contrast.mplstyle', 'high-vis.mplstyle', 'light.mplstyle', 'muted.mplstyle', 'retro.mplstyle', 'std-colors.mplstyle', 'vibrant.mplstyle', 'ieee.mplstyle', 'nature.mplstyle', 'cjk-jp-font.mplstyle', 'cjk-kr-font.mplstyle', 'cjk-sc-font.mplstyle', 'cjk-tc-font.mplstyle', 'grid.mplstyle', 'latex-sans.mplstyle', 'no-latex.mplstyle', 'pgf.mplstyle', 'russian-font.mplstyle', 'sans.mplstyle') - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - atexit.register(install_styles) +# class PostInstallMoveFile(install): +# def __init__(self, *args, **kwargs): +# super().__init__(*args, **kwargs) +# atexit.register(install_styles) # Get description from README @@ -69,6 +71,7 @@ def __init__(self, *args, **kwargs): 'Framework :: Matplotlib', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 3' + ], keywords=[ "matplotlib-style-sheets", "matplotlib-figures", From ec39f71f4e4961b2520f0d8c01e1d4c33da26f22 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sun, 6 Nov 2022 23:49:04 +0100 Subject: [PATCH 3/6] Package name to lowercase --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 20e4ab3..01420ef 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ long_description = f.read() setup( - name='SciencePlots', + name='scienceplots', version='1.1.0', author="John Garrett", author_email="garrettj403@gmail.com", From a2ecf0ebefe56adf830c4232fc66e16f131d2319 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Mon, 7 Nov 2022 00:27:54 +0100 Subject: [PATCH 4/6] Name to uppercase and fall back to prev release So changelog can be made by author --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 01420ef..e2c9b57 100644 --- a/setup.py +++ b/setup.py @@ -51,8 +51,8 @@ long_description = f.read() setup( - name='scienceplots', - version='1.1.0', + name='SciencePlots', + version='1.0.9', author="John Garrett", author_email="garrettj403@gmail.com", description="Format Matplotlib for scientific plotting", From d152224df4db30a4d5337bbe2e4eeb53571779ae Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Mon, 7 Nov 2022 00:28:29 +0100 Subject: [PATCH 5/6] Rename package import directive as SciencePlots --- SciencePlots/__init__.py | 2 +- setup.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SciencePlots/__init__.py b/SciencePlots/__init__.py index 3865eb5..2275285 100644 --- a/SciencePlots/__init__.py +++ b/SciencePlots/__init__.py @@ -7,7 +7,7 @@ # register the included stylesheet in the matplotlib style library # TODO: migrate to importlib_resources when possible -data_path = pkg_resources.resource_filename('SciencePlots', 'styles/') +data_path = pkg_resources.resource_filename('scienceplots', 'styles/') stylesheets = plt.style.core.read_style_directory(data_path) # Reads styles in /styles # Reads styles in /styles subfolders for inode in listdir(data_path): diff --git a/setup.py b/setup.py index e2c9b57..b3b3cdf 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ """Install SciencePlots. This script (setup.py) will install the SciencePlots package. -In order to expose .mplstyle files to matplotlib, "import SciencePlots" +In order to expose .mplstyle files to matplotlib, "import scienceplots" must be called before plt.style.use(...). """ @@ -62,9 +62,9 @@ url="https://github.com/garrettj403/SciencePlots/", install_requires=['matplotlib'], - packages=["SciencePlots"], + packages=["scienceplots"], package_data={ - 'SciencePlots': ['styles/**/*.mplstyle'], + 'scienceplots': ['styles/**/*.mplstyle'], }, classifiers=[ From 7641a70c0134f9646a40b665a8a819befeb171b3 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Mon, 7 Nov 2022 00:28:41 +0100 Subject: [PATCH 6/6] Add import to examples --- examples/plot-examples.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot-examples.py b/examples/plot-examples.py index 408ab85..63ade38 100644 --- a/examples/plot-examples.py +++ b/examples/plot-examples.py @@ -2,7 +2,7 @@ import numpy as np import matplotlib.pyplot as plt - +import scienceplots def model(x, p): return x ** (2 * p + 1) / (1 + x ** (2 * p))