Browse Source

Python skeleton from pyscaffold

Nikola Kotur 3 years ago
parent
commit
65848ebb51
5 changed files with 243 additions and 0 deletions
  1. 21 0
      LICENSE.txt
  2. 76 0
      setup.cfg
  3. 22 0
      setup.py
  4. 11 0
      ynrc/__init__.py
  5. 113 0
      ynrc/main.py

+ 21 - 0
LICENSE.txt

@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2021 Nikola Kotur
+
+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.

+ 76 - 0
setup.cfg

@@ -0,0 +1,76 @@
+# This file is used to configure your project.
+# Read more about the various options under:
+# http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files
+
+[metadata]
+name = ynrc
+description = Add a short description here!
+author = Nikola Kotur
+author-email = kotnick@gmail.com
+license = mit
+long-description = file: README.md
+platforms = any
+# Add here all kinds of additional classifiers as defined under
+# https://pypi.python.org/pypi?%3Aaction=list_classifiers
+classifiers =
+    Development Status :: 4 - Beta
+    Programming Language :: Python
+
+[options]
+zip_safe = False
+packages = find:
+include_package_data = True
+#package_dir =
+#    =ynrc
+# DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD!
+setup_requires = pyscaffold>=3.3a0,<4
+# Add here dependencies of your project (semicolon/line-separated), e.g.
+# install_requires = numpy; scipy
+# The usage of test_requires is discouraged, see `Dependency Management` docs
+# tests_require = pytest; pytest-cov
+# Require a specific Python version, e.g. Python 2.7 or >= 3.4
+# python_requires = >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*
+
+[options.packages.find]
+where = ynrc
+
+[options.extras_require]
+# Add here additional requirements for extra features, to install with:
+# `pip install ynrc[PDF]` like:
+# PDF = ReportLab; RXP
+# Add here test requirements (semicolon/line-separated)
+testing =
+    pytest
+    pytest-cov
+
+[options.entry_points]
+# Add here console scripts like:
+# console_scripts =
+#     script_name = ynrc.module:function
+# For example:
+# console_scripts =
+#     fibonacci = ynrc.skeleton:run
+# And any other entry points, for example:
+# pyscaffold.cli =
+#     awesome = pyscaffoldext.awesome.extension:AwesomeExtension
+console_scripts =
+     weekly_report = ynrc.main:run
+
+[aliases]
+dists = bdist_wheel
+
+[bdist_wheel]
+# Use this option if your package is pure-python
+universal = 1
+
+[devpi:upload]
+# Options for the devpi: PyPI server and packaging tool
+# VCS export must be deactivated since we are using setuptools-scm
+no-vcs = 1
+formats = bdist_wheel
+
+[pyscaffold]
+# PyScaffold's parameters when the project was created.
+# This will be used when updating. Do not change!
+version = 3.3
+package = ynrc

+ 22 - 0
setup.py

@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+"""
+    Setup file for ynrc.
+    Use setup.cfg to configure your project.
+
+    This file was generated with PyScaffold 3.3.
+    PyScaffold helps you to put up the scaffold of your new Python project.
+    Learn more under: https://pyscaffold.org/
+"""
+import sys
+from pkg_resources import VersionConflict, require
+from setuptools import setup
+
+try:
+    require("setuptools>=38.3")
+except VersionConflict:
+    print("Error: version of setuptools is too old (<38.3)!")
+    sys.exit(1)
+
+
+if __name__ == "__main__":
+    setup(use_pyscaffold=True)

+ 11 - 0
ynrc/__init__.py

@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+from pkg_resources import DistributionNotFound, get_distribution
+
+try:
+    # Change here if project is renamed and does not equal the package name
+    dist_name = __name__
+    __version__ = get_distribution(dist_name).version
+except DistributionNotFound:
+    __version__ = "unknown"
+finally:
+    del get_distribution, DistributionNotFound

+ 113 - 0
ynrc/main.py

@@ -0,0 +1,113 @@
+# -*- coding: utf-8 -*-
+"""
+This is a skeleton file that can serve as a starting point for a Python
+console script. To run this script uncomment the following lines in the
+[options.entry_points] section in setup.cfg:
+
+    console_scripts =
+         fibonacci = ynrc.skeleton:run
+
+Then run `python setup.py install` which will install the command `fibonacci`
+inside your current environment.
+Besides console scripts, the header (i.e. until _logger...) of this file can
+also be used as template for Python modules.
+
+Note: This skeleton file can be safely removed if not needed!
+"""
+
+import argparse
+import logging
+import sys
+
+from ynrc import __version__
+
+__author__ = "Nikola Kotur"
+__copyright__ = "Nikola Kotur"
+__license__ = "mit"
+
+_logger = logging.getLogger(__name__)
+
+
+def fib(n):
+    """Fibonacci example function
+
+    Args:
+      n (int): integer
+
+    Returns:
+      int: n-th Fibonacci number
+    """
+    assert n > 0
+    a, b = 1, 1
+    for i in range(n - 1):
+        a, b = b, a + b
+    return a
+
+
+def parse_args(args):
+    """Parse command line parameters
+
+    Args:
+      args ([str]): command line parameters as list of strings
+
+    Returns:
+      :obj:`argparse.Namespace`: command line parameters namespace
+    """
+    parser = argparse.ArgumentParser(description="Just a Fibonacci demonstration")
+    parser.add_argument(
+        "--version",
+        action="version",
+        version="ynrc {ver}".format(ver=__version__),
+    )
+    parser.add_argument(dest="n", help="n-th Fibonacci number", type=int, metavar="INT")
+    parser.add_argument(
+        "-v",
+        "--verbose",
+        dest="loglevel",
+        help="set loglevel to INFO",
+        action="store_const",
+        const=logging.INFO,
+    )
+    parser.add_argument(
+        "-vv",
+        "--very-verbose",
+        dest="loglevel",
+        help="set loglevel to DEBUG",
+        action="store_const",
+        const=logging.DEBUG,
+    )
+    return parser.parse_args(args)
+
+
+def setup_logging(loglevel):
+    """Setup basic logging
+
+    Args:
+      loglevel (int): minimum loglevel for emitting messages
+    """
+    logformat = "[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
+    logging.basicConfig(
+        level=loglevel, stream=sys.stdout, format=logformat, datefmt="%Y-%m-%d %H:%M:%S"
+    )
+
+
+def main(args):
+    """Main entry point allowing external calls
+
+    Args:
+      args ([str]): command line parameter list
+    """
+    args = parse_args(args)
+    setup_logging(args.loglevel)
+    _logger.debug("Starting crazy calculations...")
+    print("The {}-th Fibonacci number is {}".format(args.n, fib(args.n)))
+    _logger.info("Script ends here")
+
+
+def run():
+    """Entry point for console_scripts"""
+    main(sys.argv[1:])
+
+
+if __name__ == "__main__":
+    run()