Giter Club home page Giter Club logo

cookiecutter-python-app's Introduction

Python Application Project Template

Python 3.8 Python 3.9 Python 3.10 Python 3.11 MIT License CI Test

This is a Cookiecutter template for creating a Python application project based on the Python Packaging User Guide.

Project features:

Application features:

  • CLI with subcommands
  • Standard Python logging
  • Hierarchical TOML configuration

Usage

Install Python requirements for using the template:

$ python -m pip install -r requirements.txt

Create a new project directly from the template on GitHub:

$ cookiecutter gh:mdklatt/cookiecutter-python-app

Development

Create a local development environment and run template tests:

$ make dev test

cookiecutter-python-app's People

Contributors

ammsa avatar js-thivierge avatar luiscachog avatar mdklatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cookiecutter-python-app's Issues

deprecated call to pytest.main() in test scripts

After upgrading to pytest 3, arguments to pytest.main() should be a list, not a single string:

===== pytest-warning summary =====
WC1 None passing a string to pytest.main() is deprecated, pass a list of arguments instead.

This block has to be modified at the end of every test script:

if __name__ == "__main__":
    raise SystemExit(pytest.main(__file__))

Import not used

Hello,

at this line is getLogger imported but never used.

Thank you for your template, this is just a minor issue :)

app is not working out of the box

Hi,

Excellent idea, just it is not working out of the box.

I've installed the pyapp running:

cd pyapp
pip install .

Then the error comes when I run the app with no arguments:

pyapp
Traceback (most recent call last):
  File "/Users/luis/.virtualenvs/ca-env/bin/pyapp", line 8, in <module>
    sys.exit(main())
  File "/Users/luis/.virtualenvs/ca-env/lib/python3.7/site-packages/pyapp/cli.py", line 31, in main
    command = args.command
AttributeError: 'Namespace' object has no attribute 'command'

However, if I run the app with the correct command hello, I believe the app works:

pyapp hello
echo $?
0

Now, if I added command as an argument on the parent parser:

parser.add_argument("command", action="store",help="test command")

The app runs as expected with no arguments:

pyapp
usage: pyapp [-h] [-c CONFIG] [-v] [-w WARN] command {hello} ...
pyapp: error: the following arguments are required: command

But generates errors with the command argument hello:

 pyapp hello
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 1126, in getfullargspec
    sigcls=Signature)
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 2208, in _signature_from_callable
    raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: 'hello' is not a callable object

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/luis/.virtualenvs/ca-env/bin/pyapp", line 8, in <module>
    sys.exit(main())
  File "/Users/luis/.virtualenvs/ca-env/lib/python3.7/site-packages/pyapp/cli.py", line 33, in main
    spec = getfullargspec(command)
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 1132, in getfullargspec
    raise TypeError('unsupported callable') from ex
TypeError: unsupported callable

I'm new at programming and don't know how to fix it.

Could you take a look, please?

python setup.py install --user is failing (windows / Python 3.4)

Windows 10/ Python 3.4.4 64 bit (WinPython distibution)
Getting an error below. It seems that this function is not working

def version():
    """ Get the local package version.

    """
    path = join("lib", _CONFIG["name"], "__version__.py")
    with open(path) as stream:
        exec(stream.read())
    return __version__

python setup.py install --user

Traceback (most recent call last):
File "setup.py", line 172, in
raise SystemExit(main())
File "setup.py", line 160, in main
_CONFIG["version"] = version()
File "setup.py", line 48, in version
return version
NameError: name 'version' is not defined

Explicit `!param` tag resolution fails in config.load()

If a YAML scalar is an explicit string, implicit resolution is not performed. In that case, it's necessary to mark the scalar with a tag:

value: !param "${ENV}"

However, this fails:

self = <yaml.loader.SafeLoader object at 0x7fdde5569410>
node = ScalarNode(tag='!param', value='${env1}${env2}')

    def construct_undefined(self, node):
        raise ConstructorError(None, None,
                "could not determine a constructor for the tag %r" % node.tag,
>               node.start_mark)
E       yaml.constructor.ConstructorError: could not determine a constructor for the tag '!param'
E         in "test/data/conf1.yml", line 2, column 6

The ! needs to be explicit when registering the tag name on the loader.

Path to the config.yml file

When I install the app with pip install -e . and I call the cli from from any working directory other than the top directory oft the project, I get a file not found error:

$ name_of_the_app -w DEBUG hello

2023-06-14 14:29:37,123;DEBUG;name_of_the_app;starting execution
Traceback (most recent call last):
  File "C:\Users\MYUSER\anaconda3\envs\NAMEOFMYENV\Scripts\edupsy_admin-script.py", line 33, in <module>
    sys.exit(load_entry_point('name-of-the-app', 'console_scripts', 'name_of_the_app')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\PATHTOTHEAPP\name_of_the_app\src\name_of_the_app\cli.py", line 25, in main
    config.load(args.config)
  File "c:\PATHTOTHEAPP\name_of_the_app\src\name_of_the_app\core\config.py", line 99, in load
    with open(path, "r") as stream:
         ^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'etc/config.yml'

If I run the same command from the top level directory of the app, the config.yml file loads.

OS: Win10
Python 3.11.3

Is this expected behaviour? Should I replace the relative default path etc/config.yml with an absolute path, for example one generated with the package platformdirs?

Use safe_load() to load YAML config files

The yaml safe_load() function prevents the deserialization of complex objects which could be used for arbitrary code execution. While loading config data from untrusted sources is a bad idea in the first place, adding an extra layer of security here won't hurt.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.