pax_global_header00006660000000000000000000000064147507221670014525gustar00rootroot0000000000000052 comment=382ecdf1dbf9bc6b802f64e8bcebbd9b10d0db30 presets-1.0.0/000077500000000000000000000000001475072216700132105ustar00rootroot00000000000000presets-1.0.0/.github/000077500000000000000000000000001475072216700145505ustar00rootroot00000000000000presets-1.0.0/.github/environment-ci.yml000066400000000000000000000002531475072216700202300ustar00rootroot00000000000000name: presets-dev channels: - conda-forge - defaults dependencies: # required - pip # optional, but required for testing - pytest - pytest-cov - coverage presets-1.0.0/.github/environment-lint.yml000066400000000000000000000004021475072216700205770ustar00rootroot00000000000000name: lint channels: - conda-forge - defaults dependencies: # required - pip - bandit - codespell - flake8 - pytest - pydocstyle # Dependencies for velin - numpydoc>=1.1.0 - sphinx>=5.1.0 - pygments - black - pip: - velin presets-1.0.0/.github/environment-minimal.yml000066400000000000000000000002531475072216700212630ustar00rootroot00000000000000name: presets-dev channels: - conda-forge - defaults dependencies: # required - pip # optional, but required for testing - pytest - pytest-cov - coverage presets-1.0.0/.github/workflows/000077500000000000000000000000001475072216700166055ustar00rootroot00000000000000presets-1.0.0/.github/workflows/ci.yml000066400000000000000000000072071475072216700177310ustar00rootroot00000000000000name: CI on: push: branches: - main pull_request: branches: - main concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: True jobs: test: name: "Python ${{ matrix.python-version }} on ${{ matrix.os }}" runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: include: - os: ubuntu-latest python-version: "3.8" envfile: ".github/environment-minimal.yml" channel-priority: "flexible" name: "Minimal dependencies" - os: ubuntu-latest python-version: "3.9" channel-priority: "strict" envfile: ".github/environment-ci.yml" - os: ubuntu-latest python-version: "3.10" channel-priority: "strict" envfile: ".github/environment-ci.yml" - os: ubuntu-latest python-version: "3.11" channel-priority: "strict" envfile: ".github/environment-ci.yml" - os: ubuntu-latest python-version: "3.12" channel-priority: "strict" envfile: ".github/environment-ci.yml" - os: ubuntu-latest python-version: "3.13" channel-priority: "strict" envfile: ".github/environment-ci.yml" - os: macos-latest python-version: "3.13" channel-priority: "strict" envfile: ".github/environment-ci.yml" - os: windows-latest python-version: "3.13" channel-priority: "strict" envfile: ".github/environment-ci.yml" steps: - uses: actions/checkout@v4 with: submodules: true - name: Cache conda uses: actions/cache@v4 env: # Increase this value to reset cache if etc/example-environment.yml has not changed CACHE_NUMBER: 0 with: path: ~/conda_pkgs_dir key: ${{ runner.os }}-${{ matrix.python-version }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles( matrix.envfile ) }} - name: Install Conda environment uses: conda-incubator/setup-miniconda@v3 with: auto-update-conda: true python-version: ${{ matrix.python-version }} add-pip-as-python-dependency: true auto-activate-base: false activate-environment: test channel-priority: ${{ matrix.channel-priority }} environment-file: ${{ matrix.envfile }} use-only-tar-bz2: false # IMPORTANT: This needs to be set for caching to work properly! - name: Conda info shell: bash -l {0} run: | conda info -a conda list - name: Install presets shell: bash -l {0} run: python -m pip install --upgrade-strategy only-if-needed -e .[tests] - name: Run pytest shell: bash -l {0} run: pytest - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.xml flags: unittests env_vars: OS,PYTHON name: codecov-umbrella fail_ci_if_error: true verbose: true presets-1.0.0/.github/workflows/lint_python.yml000066400000000000000000000033331475072216700217010ustar00rootroot00000000000000name: lint_python on: [pull_request, push] jobs: lint_python: name: "Lint and code analysis" runs-on: ubuntu-latest strategy: fail-fast: true matrix: include: - os: ubuntu-latest python-version: "3.8" channel-priority: "flexible" envfile: ".github/environment-lint.yml" steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Cache conda uses: actions/cache@v4 env: CACHE_NUMBER: 0 with: path: ~/conda_pkgs_dir key: ${{ runner.os }}-${{ matrix.python-version }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles( matrix.envfile ) }} - name: Install conda environmnent uses: conda-incubator/setup-miniconda@v3 with: auto-update-conda: false python-version: ${{ matrix.python-version }} add-pip-as-python-dependency: true auto-activate-base: false activate-environment: lint # mamba-version: "*" channel-priority: ${{ matrix.channel-priority }} environment-file: ${{ matrix.envfile }} use-only-tar-bz2: true - name: Conda info shell: bash -l {0} run: | conda info -a conda list - name: Spell check shell: bash -l {0} run: codespell --skip="./AUTHORS.md,./docs/changes.rst" - name: Security check shell: bash -l {0} run: bandit --recursive --skip B101,B110 . - name: Style check shell: bash -l {0} run: python -m flake8 presets - name: Docstring check shell: bash -l {0} run: python -m velin --check presets - name: Docstring style check shell: bash -l {0} run: python -m pydocstyle presets presets-1.0.0/.github/workflows/publish.yml000066400000000000000000000016461475072216700210050ustar00rootroot00000000000000name: Publish Python 🐍 distributions 📦 to PyPI on: release: types: [created] jobs: pypi-publish: name: Upload release to PyPI runs-on: ubuntu-latest environment: name: pypi url: https://pypi.org/p/presets permissions: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing steps: - uses: actions/checkout@v4 - name: Set up Python 3.12 uses: actions/setup-python@v5 with: python-version: 3.12 - name: Install pypa/build run: >- python -m pip install build --user - name: Build a binary wheel and a source tarball run: >- python -m build --sdist --wheel --outdir dist/ . - name: Publish package distributions to PyPI if: startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1 presets-1.0.0/.gitignore000066400000000000000000000012761475072216700152060ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # 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/ .coverage .coverage.* .cache nosetests.xml coverage.xml *,cover # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation docs/_build/ # PyBuilder target/ presets-1.0.0/.readthedocs.yaml000066400000000000000000000020431475072216700164360ustar00rootroot00000000000000# Read the Docs configuration file for Sphinx projects # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details # Required version: 2 # Set the OS, Python version and other tools you might need build: os: ubuntu-22.04 tools: python: "3.12" # You can also specify other tool versions: # nodejs: "20" # rust: "1.70" # golang: "1.20" # Build documentation in the "docs/" directory with Sphinx sphinx: configuration: docs/conf.py # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs # builder: "dirhtml" # Fail on all warnings to avoid broken references # fail_on_warning: true # Optionally build your docs in additional formats such as PDF and ePub # formats: # - pdf # - epub # Optional but recommended, declare the Python requirements required # to build your documentation # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html python: install: - method: pip path: . extra_requirements: - docs presets-1.0.0/LICENSE000066400000000000000000000013471475072216700142220ustar00rootroot00000000000000ISC License Copyright (c) 2015, Brian McFee Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. presets-1.0.0/README.md000066400000000000000000000013621475072216700144710ustar00rootroot00000000000000# presets [![PyPI](https://img.shields.io/pypi/v/presets.svg)](https://pypi.python.org/pypi/presets) [![CI](https://github.com/bmcfee/presets/actions/workflows/ci.yml/badge.svg)](https://github.com/bmcfee/presets/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/bmcfee/presets/graph/badge.svg?token=MOplTIz54j)](https://codecov.io/gh/bmcfee/presets) [![License](https://img.shields.io/github/license/bmcfee/presets.svg)]() [![Documentation Status](https://readthedocs.org/projects/presets/badge/?version=latest)](http://presets.readthedocs.org/en/latest/?badge=latest) A python module to manipulate default parameters of a module's functions. For instructions, please refer to the [documentation](http://presets.readthedocs.org/en/latest/). presets-1.0.0/docs/000077500000000000000000000000001475072216700141405ustar00rootroot00000000000000presets-1.0.0/docs/Makefile000066400000000000000000000151561475072216700156100ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) endif # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " xml to make Docutils-native XML files" @echo " pseudoxml to make pseudoxml-XML files for display purposes" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/presets.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/presets.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/presets" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/presets" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." latexpdfja: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through platex and dvipdfmx..." $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." xml: $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml @echo @echo "Build finished. The XML files are in $(BUILDDIR)/xml." pseudoxml: $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml @echo @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." presets-1.0.0/docs/api.rst000066400000000000000000000001611475072216700154410ustar00rootroot00000000000000.. _api: Object reference ================ .. module:: presets .. autoclass:: Preset :inherited-members: presets-1.0.0/docs/changes.rst000066400000000000000000000006741475072216700163110ustar00rootroot00000000000000Changes ======= v1.0.0 ------ - Removed support for python < 3.8 - Modernized to support python 3.13 v0.1.3 ------ - Fixed a bug in handling built-in modules - Added transparency of wrapped function docstrings and call signatures v0.1.2 ------ - Fixed a bug in overriding anonymous keyword arguments - Updated inspect usage for python 3.5 v0.1.1 ------ - Fixed an error in PyPI-based installation v0.1.0 ------ - Initial public release presets-1.0.0/docs/conf.py000066400000000000000000000203221475072216700154360ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # presets documentation build configuration file, created by # sphinx-quickstart on Fri Oct 16 13:55:12 2015. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys import os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath('../')) from presets import __version__ as release version = release # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'sphinx.ext.coverage', 'sphinx.ext.viewcode', 'numpydoc', ] from glob import glob autosummary_generate = glob('*.rst') # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'presets' copyright = u'2015--2025, Brian McFee' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. # The full version, including alpha/beta/rc tags. # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all # documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. #html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. #html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'presetsdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ ('index', 'presets.tex', u'presets Documentation', u'Brian McFee', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'presets', u'presets Documentation', [u'Brian McFee'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'presets', u'presets Documentation', u'Brian McFee', 'presets', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False presets-1.0.0/docs/index.rst000066400000000000000000000023551475072216700160060ustar00rootroot00000000000000.. presets documentation master file, created by sphinx-quickstart on Fri Oct 16 13:55:12 2015. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. presets ======= Presets provides an object interface that can override common default parameter settings for all functions within a target module or package. It's simple to use. Simply construct a ``Preset`` object with the target module as an argument, then set the default parameters via a dict-like interface. After that, your new object will act just as the target module, but it replaces the default arguments of any functions with values that you set. Example ------- .. code-block:: python >>> import librosa as _librosa >>> from presets import Preset >>> librosa = Preset(_librosa) >>> librosa['sr'] = 44100 >>> librosa['n_fft'] = 4096 >>> librosa['hop_length'] = 1024 >>> y, sr = librosa.load(librosa.util.example_audio_file()) >>> sr 44100 >>> stft = librosa.stft(y) API Reference ------------- .. toctree:: :maxdepth: 3 api changes Contribute ---------- - `Issue Tracker `_ - `Source Code `_ presets-1.0.0/docs/requirements.txt000066400000000000000000000000161475072216700174210ustar00rootroot00000000000000numpydoc>=0.5 presets-1.0.0/presets/000077500000000000000000000000001475072216700146755ustar00rootroot00000000000000presets-1.0.0/presets/__init__.py000066400000000000000000000136441475072216700170160ustar00rootroot00000000000000#!/usr/bin/env python # -*- encoding: utf-8 -*- """Presets provides an object interface to a module which can override \ the default parameter values. This is primarily useful for packages which contain many functions with overlapping parameter sets. Presets can be used to consistently override all defaults at once, while maintaining the same externally-facing API. Example ------- This example shows how to override common default parameters in the librosa package. >>> import librosa as _librosa >>> from presets import Preset >>> librosa = Preset(_librosa) >>> librosa['sr'] = 44100 >>> librosa['n_fft'] = 4096 >>> librosa['hop_length'] = 1024 >>> y, sr = librosa.load(librosa.util.example_audio_file()) >>> stft = librosa.stft(y) >>> tempo, beats = librosa.beat.beat_track(y) """ import inspect import os import types import functools short_version = '1.0' version = '1.0.0' __version__ = version class Preset(object): """The Preset class overrides the default parameters of functions \ within a module. If the given module contains submodules, these are also encapsulated by Preset objects that share the same default parameter dictionary. Submodules are detected by examining common prefixes of the module source paths. Attributes ---------- module : Python module The module to encapsulate dispatch : None or dictionary A dictionary mapping modules to existing Preset objects. This should be left as `None` for most situations. defaults : None or dictionary An existing dictionary object used to collect default parameters. Note: this will be passed by reference. """ def __wrap(self, func): """Override the default arguments of a function. For each keyword argument in the function, the decorator first checks if the argument has been overridden by the caller, and uses that value instead if so. If not, the decorator consults the Preset object for an override value. If both of the above cases fail, the decorator reverts to the function's native default parameter value. """ def deffunc(*args, **kwargs): """Decorate the given function.""" # Get the list of function arguments function_args = inspect.signature(func).parameters # Construct a dict of those kwargs which appear in the function filtered_kwargs = kwargs.copy() # look at all relevant keyword arguments for this function for param in function_args: if param in kwargs: # Did the user override the default? filtered_kwargs[param] = kwargs[param] elif param in self._defaults: # Do we have a clobbering value in the default dict? filtered_kwargs[param] = self._defaults[param] # Call with the supplied args and the filtered kwarg dict return func(*args, **filtered_kwargs) # pylint: disable=W0142 wrapped = functools.update_wrapper(deffunc, func) # force-mangle the docstring here wrapped.__doc__ = ( 'WARNING: this function has been modified by the Presets ' 'package.\nDefault parameter values described in the ' f'documentation below may be inaccurate.\n\n{wrapped.__doc__}') return wrapped def __init__(self, module, dispatch=None, defaults=None): """Initialize Preset object around a given module.""" # This defaults directory will get passed around by reference if defaults is None: defaults = dict() self._defaults = defaults self._module = module if dispatch is None: dispatch = dict() dispatch[module] = self self._dispatch = dispatch modpath = os.path.dirname(inspect.getfile(module)) # inspect the target module for attr, value in inspect.getmembers(module): # If it's a function, wrap it if callable(value): # Wrap the function in a decorator wrapped = self.__wrap(value) setattr(self, attr, wrapped) # If it's a module, construct a parameterizer to wrap it elif (isinstance(value, types.ModuleType) and hasattr(value, '__file__')): # test if this is a submodule of the current module submodpath = inspect.getfile(value) if os.path.commonprefix([modpath, submodpath]) == modpath: if value not in self._dispatch: # We need to pre-seed the dispatch entry to avoid # cyclic references self._dispatch[value] = None self._dispatch[value] = Preset(value, dispatch=self._dispatch, defaults=self._defaults) setattr(self, attr, self._dispatch[value]) else: setattr(self, attr, value) def __getitem__(self, param): """Implement dictionary interface (get) to presets object.""" return self._defaults[param] def __delitem__(self, param): """Implement dictionary interface (del) to presets object.""" del self._defaults[param] def __contains__(self, param): """Implement dictionary interface (in) to presets object.""" return param in self._defaults def __setitem__(self, param, value): """Implement dictionary interface (set) to presets object.""" self._defaults[param] = value def keys(self): """Return a list of currently set parameter defaults.""" return self._defaults.keys() def update(self, D): """Update the default parameter set with the provided dictionary D.""" self._defaults.update(D) presets-1.0.0/setup.cfg000066400000000000000000000021271475072216700150330ustar00rootroot00000000000000[tool:pytest] addopts = -v --cov --cov-branch --cov-report=xml tests [metadata] name = presets version = attr: presets.version description = A python module to manipulate default parameters of a module's functions long_description = file: README.md author = Brian McFee url = http://github.com/bmcfee/presets download_url = http://github.com/bmcfee/presets/releases license = ISC license_file = LICENSE license_file_content_type = text/markdown; charset=UTF-8 classifiers = License :: OSI Approved :: ISC License (ISCL) Programming Language :: Python Development Status :: 3 - Alpha Intended Audience :: Developers Topic :: Software Development Programming Language :: Python :: 3 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 Programming Language :: Python :: 3.13 [options] packages = find: python_requires >= 3.8 [options.extras_require] docs = numpydoc tests = coverage pytest pytest-cov presets-1.0.0/setup.py000066400000000000000000000001051475072216700147160ustar00rootroot00000000000000from setuptools import setup if __name__ == '__main__': setup() presets-1.0.0/tests/000077500000000000000000000000001475072216700143525ustar00rootroot00000000000000presets-1.0.0/tests/preset_test/000077500000000000000000000000001475072216700167135ustar00rootroot00000000000000presets-1.0.0/tests/preset_test/__init__.py000066400000000000000000000002741475072216700210270ustar00rootroot00000000000000#!/usr/bin/env python # Import an external module with a default kwarg import json # Import a submodule from . import submod from . import secondmod def mult(a, b=3): return a * b presets-1.0.0/tests/preset_test/secondmod.py000066400000000000000000000001201475072216700212310ustar00rootroot00000000000000#!/usr/bin/env python from . import submod def sub(a, b=3): return a - b presets-1.0.0/tests/preset_test/submod.py000066400000000000000000000001061475072216700205530ustar00rootroot00000000000000#!/usr/bin/env python import sys def add(a, b=5): return a + b presets-1.0.0/tests/test_presets.py000066400000000000000000000035051475072216700174530ustar00rootroot00000000000000#!/usr/bin/env python import presets import preset_test def test_main_default(): P = presets.Preset(preset_test) assert preset_test.mult(4) == P.mult(4) def test_submod_default(): P = presets.Preset(preset_test) assert preset_test.submod.add(4) == P.submod.add(4) def test_main_override(): b = -3 P = presets.Preset(preset_test) P['b'] = b assert preset_test.mult(4, b=b) == P.mult(4) def test_submod_override(): b = -3 P = presets.Preset(preset_test) P['b'] = b assert preset_test.submod.add(4, b=b) == P.submod.add(4) def test_main_update(): b = -3 P = presets.Preset(preset_test) P['b'] = b assert preset_test.mult(4, b=b) == P.mult(4) P['b'] = b + 10 assert preset_test.mult(4, b=b+10) == P.mult(4) def test_user_override(): b = -3 P = presets.Preset(preset_test) P['b'] = b assert preset_test.mult(4, b=10 + b) == P.mult(4, b=10 + b) def test_revert(): b = -3 P = presets.Preset(preset_test) P['b'] = b del P['b'] assert preset_test.mult(4) == P.mult(4) def test_contains(): P = presets.Preset(preset_test) P['b'] = 3 assert 'b' in P assert 'c' not in P def test_set_get(): b = 20 P = presets.Preset(preset_test) P['b'] = b assert P['b'] == b def test_update(): P = presets.Preset(preset_test) params = dict(b=30, c=20, d=50) P.update(params) for key in params.keys(): assert P[key] == params[key] def test_keys(): P = presets.Preset(preset_test) params = dict(b=30, c=20, d=50) P.update(params) assert set(P.keys()) == set(params.keys()) def test_external(): P = presets.Preset(preset_test) assert preset_test.json == P.json def test_docstring(): P = presets.Preset(preset_test) assert 'WARNING' in P.mult.__doc__