diff --git a/.github/images/demo.gif b/.github/images/demo.gif new file mode 100644 index 0000000..d220075 Binary files /dev/null and b/.github/images/demo.gif differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0a04128 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..64dd78d --- /dev/null +++ b/README.rst @@ -0,0 +1,45 @@ +=============================== +skeleton-python-binary +=============================== + +.. image:: https://img.shields.io/github/v/tag/pole-surfaces-planetaires/skeleton-python-ws +.. image:: https://img.shields.io/github/v/release/pole-surfaces-planetaires/skeleton-python-ws?include_prereleases + +.. image https://img.shields.io/github/downloads/pole-surfaces-planetaires/skeleton-python-ws/total +.. image https://img.shields.io/github/issues-raw/pole-surfaces-planetaires/skeleton-python-ws +.. image https://img.shields.io/github/issues-pr-raw/pole-surfaces-planetaires/skeleton-python-ws +.. image:: https://img.shields.io/badge/Maintained%3F-yes-green.svg + :target: https://github.com/pole-surfaces-planetaires/skeleton-python-ws/graphs/commit-activity +.. image https://img.shields.io/github/license/pole-surfaces-planetaires/skeleton-python-ws +.. image https://img.shields.io/github/forks/pole-surfaces-planetaires/skeleton-python-ws?style=social + + +Create a functional skeleton of a python package for a web service + +✨ Demo preview +--------------- + +.. image:: https://raw.githubusercontent.com/pole-surfaces-planetaires/skeleton-python-ws/main/.github/images/demo.gif + +Usage +----- + +To create a skeleton of a python project: + +* initialization of the README +* initialization of the loggers +* initialization of tests +* quality control of the code (black, flake8, ...) +* setting up of legal aspects (header, LICENSE) +* implementation of tasks by a Makefile + + pip install cookiecutter + + cookiecutter https://github.com/pole-surfaces-planetaires/skeleton-python-ws + + + + +Author +------ +👤 **Jean-Christophe Malapert** diff --git a/cookiecutter.json b/cookiecutter.json new file mode 100644 index 0000000..6c90fa0 --- /dev/null +++ b/cookiecutter.json @@ -0,0 +1,28 @@ +{ + "full_name": "Jean-Christophe Malapert", + "institute": "CNES", + "email": "jean-christophe.malapert@cnes.fr", + "github_username": "", + "project_name": "My Great Project", + "project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}", + "project_class_lib": "{{ cookiecutter.project_slug.title().replace('_', '') + 'Lib' }}", + "project_short_description": "My Great Project description.", + "year": "{% now 'utc', '%Y' %}", + "_extensions": [ + "jinja2_time.TimeExtension" + ], + "consortium_name": [ + "Pôle Surfaces Planétaires" + ], + "pypi_username": "{{ cookiecutter.github_username }}", + "version": "0.0.1", + "use_pytest": "n", + "use_pypi_deployment_with_travis": "y", + "add_pyup_badge": "n", + "create_author_file": "y", + "open_source_license": [ + "GNU General Public License v3", + "GNU Lesser General Public License v3", + "GNU Affero General Public License v3" + ] +} \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/.flake8 b/{{cookiecutter.project_slug}}/.flake8 new file mode 100644 index 0000000..3d21184 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.flake8 @@ -0,0 +1,6 @@ +[flake8] +ignore = E203, E266, E501, W503, F403, F401 +max-line-length = 79 +max-complexity = 18 +select = B,C,E,F,W,T4,B9 +exclude = docs/source/conf.py diff --git a/{{cookiecutter.project_slug}}/.gitignore b/{{cookiecutter.project_slug}}/.gitignore new file mode 100644 index 0000000..8387623 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.gitignore @@ -0,0 +1,133 @@ +# 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/ +pip-wheel-metadata/ +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/ + +# 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 +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.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 + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__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/ + +{{ cookiecutter.project_slug }}-env/ + +docs/build/ \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml new file mode 100644 index 0000000..fd8f084 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml @@ -0,0 +1,32 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-xml + - id: check-json + - id: check-added-large-files + - id: fix-byte-order-marker + - id: end-of-file-fixer + - id: detect-private-key + - id: name-tests-test + - id: requirements-txt-fixer + - id: pretty-format-json + - id: fix-encoding-pragma + - repo: https://github.com/asottile/reorder_python_imports + rev: v2.4.0 + hooks: + - id: reorder-python-imports + - repo: https://github.com/ambv/black + rev: stable + hooks: + - id: black + language_version: python3.8 + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.7.9 + hooks: + - id: flake8 diff --git a/{{cookiecutter.project_slug}}/.pypirc b/{{cookiecutter.project_slug}}/.pypirc new file mode 100644 index 0000000..5e94458 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.pypirc @@ -0,0 +1,11 @@ +[distutils] +index-servers = + pypi + pypitest + +[pypi] +username: {{cookiecutter.pypi_username}} + +[pypitest] +repository: https://test.pypi.org/legacy/ +username: {{cookiecutter.pypi_username}} diff --git a/{{cookiecutter.project_slug}}/.travis.yml b/{{cookiecutter.project_slug}}/.travis.yml new file mode 100644 index 0000000..02700a8 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.travis.yml @@ -0,0 +1,28 @@ +# Config file for automatic testing at travis-ci.com + +language: python +python: + - 3.8 + +# Command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors +install: pip install -U tox-travis + +# Command to run tests, e.g. python setup.py test +script: tox + +{% if cookiecutter.use_pypi_deployment_with_travis == 'y' -%} +# Assuming you have installed the travis-ci CLI tool, after you +# create the Github repo and add it to Travis, run the +# following command to finish PyPI deployment setup: +# $ travis encrypt --add deploy.password +deploy: + provider: pypi + distributions: sdist bdist_wheel + user: {{ cookiecutter.pypi_username }} + password: + secure: PLEASE_REPLACE_ME + on: + tags: true + repo: pole-surfaces-planetaires/{{ cookiecutter.project_slug }} + python: 3.8 +{%- endif %} \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/AUTHORS.rst b/{{cookiecutter.project_slug}}/AUTHORS.rst new file mode 100644 index 0000000..9052be7 --- /dev/null +++ b/{{cookiecutter.project_slug}}/AUTHORS.rst @@ -0,0 +1,13 @@ +======= +Credits +======= + +Development Lead +---------------- + +* {{ cookiecutter.full_name }} <{{ cookiecutter.email }}> + +Contributors +------------ + +None yet. \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/CHANGELOG b/{{cookiecutter.project_slug}}/CHANGELOG new file mode 100644 index 0000000..a06d89a --- /dev/null +++ b/{{cookiecutter.project_slug}}/CHANGELOG @@ -0,0 +1,3 @@ +========= +Changelog +========= \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/CONTRIBUTING.rst b/{{cookiecutter.project_slug}}/CONTRIBUTING.rst new file mode 100644 index 0000000..00fcbf9 --- /dev/null +++ b/{{cookiecutter.project_slug}}/CONTRIBUTING.rst @@ -0,0 +1,124 @@ +.. highlight:: shell + +============ +Contributing +============ + +Contributions are welcome, and they are greatly appreciated! Every little bit +helps, and credit will always be given. + +You can contribute in many ways: + +Types of Contributions +---------------------- + +Report Bugs +~~~~~~~~~~~ + +Report bugs at https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}/issues. + +If you are reporting a bug, please include: + +* Your operating system name and version. +* Any details about your local setup that might be helpful in troubleshooting. +* Detailed steps to reproduce the bug. + +Fix Bugs +~~~~~~~~ + +Look through the GitHub issues for bugs. Anything tagged with "bug" and "help +wanted" is open to whoever wants to implement it. + +Implement Features +~~~~~~~~~~~~~~~~~~ + +Look through the GitHub issues for features. Anything tagged with "enhancement" +and "help wanted" is open to whoever wants to implement it. + +Write Documentation +~~~~~~~~~~~~~~~~~~~ + +{{ cookiecutter.project_name }} could always use more documentation, whether as part of the +official {{ cookiecutter.project_name }} docs, in docstrings, or even on the web in blog posts, +articles, and such. + +Submit Feedback +~~~~~~~~~~~~~~~ + +The best way to send feedback is to file an issue at https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}/issues. + +If you are proposing a feature: + +* Explain in detail how it would work. +* Keep the scope as narrow as possible, to make it easier to implement. +* Remember that this is a volunteer-driven project, and that contributions + are welcome :) + +Get Started! +------------ + +Ready to contribute? Here's how to set up `{{ cookiecutter.project_slug }}` for local development. + +1. Fork the `{{ cookiecutter.project_slug }}` repo on GitHub. +2. Clone your fork locally:: + + $ git clone git@github.com:your_name_here/{{ cookiecutter.project_slug }}.git + +3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: + + $ mkvirtualenv {{ cookiecutter.project_slug }} + $ cd {{ cookiecutter.project_slug }}/ + $ python setup.py develop + +4. Create a branch for local development:: + + $ git checkout -b name-of-your-bugfix-or-feature + + Now you can make your changes locally. + +5. When you're done making changes, check that your changes pass flake8 and the + tests, including testing other Python versions with tox:: + + $ flake8 {{ cookiecutter.project_slug }} tests + $ python setup.py test or pytest + $ tox + + To get flake8 and tox, just pip install them into your virtualenv. + +6. Commit your changes and push your branch to GitHub:: + + $ git add . + $ git commit -m "Your detailed description of your changes." + $ git push origin name-of-your-bugfix-or-feature + +7. Submit a pull request through the GitHub website. + +Pull Request Guidelines +----------------------- + +Before you submit a pull request, check that it meets these guidelines: + +1. The pull request should include tests. +2. If the pull request adds functionality, the docs should be updated. Put + your new functionality in your commit message. + + +Tips +---- + +To run a subset of tests:: + +{% if cookiecutter.use_pytest == 'y' -%} + $ pytest tests.test_{{ cookiecutter.project_slug }} +{% else %} + $ python -m unittest tests.test_{{ cookiecutter.project_slug }} +{%- endif %} + +Deploying +--------- + +A reminder for the maintainers on how to deploy. +Make sure all your changes are committed. +Then run:: + + git tag -a v1.4.0 -m "my version 1.4.0" \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/LICENSE b/{{cookiecutter.project_slug}}/LICENSE new file mode 100644 index 0000000..0304b61 --- /dev/null +++ b/{{cookiecutter.project_slug}}/LICENSE @@ -0,0 +1,1451 @@ +{% if cookiecutter.open_source_license == 'GNU General Public License v3' -%} + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS +{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%} + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. +{% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%} + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. +{% endif %} \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/MANIFEST.in b/{{cookiecutter.project_slug}}/MANIFEST.in new file mode 100644 index 0000000..983a270 --- /dev/null +++ b/{{cookiecutter.project_slug}}/MANIFEST.in @@ -0,0 +1,5 @@ +include LICENSE +include README.rst +include pyproject.toml +include requirements.txt +include conf diff --git a/{{cookiecutter.project_slug}}/Makefile b/{{cookiecutter.project_slug}}/Makefile new file mode 100644 index 0000000..0e1455e --- /dev/null +++ b/{{cookiecutter.project_slug}}/Makefile @@ -0,0 +1,134 @@ +.DEFAULT_GOAL := init +.PHONY: prepare-dev install-dev data help lint tests coverage upload-prod-pypi upload-test-pypi update_req update_req_dev pyclean doc doc-pdf visu-doc-pdf visu-doc tox licences +VENV = ".{{cookiecutter.project_slug}}" + +define PROJECT_HELP_MSG + +Usage:\n + \n + make help\t\t\t show this message\n + \n + -------------------------------------------------------------------------\n + \t\tInstallation\n + -------------------------------------------------------------------------\n + make\t\t\t\t Install {{ cookiecutter.project_slug }} in the system (root)\n + make user\t\t\t Install {{ cookiecutter.project_slug }} for non-root usage\n + \n + -------------------------------------------------------------------------\n + \t\tDevelopment\n + -------------------------------------------------------------------------\n + make prepare-dev\t\t Prepare Development environment\n + make install-dev\t\t Install COTS and {{ cookiecutter.project_slug }} for development purpose\n + make data\t\t\t Download data\n + make test\t\t\t Run units and integration tests\n + \n + make doc\t\t\t Generate the documentation\n + make doc-pdf\t\t\t Generate the documentation as PDF\n + make visu-doc-pdf\t\t View the generated PDF\n + make visu-doc\t\t\t View the generated documentation\n + \n + make release\t\t\t Release the package as tar.gz\n + make upload-test-pypi\t\t Upload the pypi package on the test platform\n + make upload-prod-pypi\t\t Upload the pypi package on the prod platform\n + \n + make update_req\t\t Update the version of the packages in requirements.txt\n + make update_req_dev\t\t Update the version of the packages in requirements_dev.txt\n + \n + make pyclean\t\t\t Clean .pyc files and __pycache__ directories\n + \n + -------------------------------------------------------------------------\n + \t\tOthers\n + -------------------------------------------------------------------------\n + make licences\t\t\t Display the list of licences\n + make version\t\t\t Display the version\n + make coverage\t\t\t Coverage\n + make lint\t\t\t Lint\n + make tox\t\t\t Run all tests\n + +endef +export PROJECT_HELP_MSG + + +#Show help +#--------- +help: + echo $$PROJECT_HELP_MSG + + +# +# Sotware Installation in the system (need root access) +# ----------------------------------------------------- +# +init: + python3 setup.py install + +# +# Sotware Installation for user +# ----------------------------- +# This scheme is designed to be the most convenient solution for users +# that don’t have write permission to the global site-packages directory or +# don’t want to install into it. +# +user: + python3 setup.py install --user + +prepare-dev: + cp .pypirc ~${USER} && git init && echo "python3 -m venv {{cookiecutter.project_slug}}-env && export PYTHONPATH=. && export PATH=`pwd`/{{cookiecutter.project_slug}}-env/bin:${PATH}" > ${VENV} && echo "source \"`pwd`/{{cookiecutter.project_slug}}-env/bin/activate\"" >> ${VENV} && scripts/install-hooks.bash && echo "\nnow source this file: \033[31msource ${VENV}\033[0m" + +install-dev: + pip install -r requirements.txt && pip install -r requirements_dev.txt && pre-commit install && pre-commit autoupdate && python3 setup.py develop + +coverage: ## Run tests with coverage + coverage erase + coverage run --include={{cookiecutter.project_slug}}/* -m pytest -ra + coverage report -m + +lint: ## Lint and static-check + flake8 --ignore=E203,E266,E501,W503,F403,F401,W292 --max-line-length=79 --max-complexity=18 --select=B,C,E,F,W,T4,B9 {{cookiecutter.project_slug}} + pylint {{cookiecutter.project_slug}} + mypy {{cookiecutter.project_slug}} + +tests: ## Run tests + pytest -ra + +tox: + tox -e py38 + +doc: + make html -C docs + +doc-pdf: + make doc && make latexpdf -C docs + +visu-doc-pdf: + make doc-pdf && acroread docs/build/latex/{{cookiecutter.project_slug}}.pdf + +visu-doc: + make doc && firefox docs/build/html/index.html + +release: + python3 setup.py sdist + +version: + python3 setup.py --version + +data: + pip install -r requirements_data.txt && python scripts/data_download.py + +upload-test-pypi: + flit publish --repository pypitest + +upload-prod-pypi: + flit publish + +licences: + pip-licenses + +update_req: + pur -r requirements.txt + +update_req_dev: + pur -r requirements_dev.txt + +pyclean: + find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete diff --git a/{{cookiecutter.project_slug}}/README.rst b/{{cookiecutter.project_slug}}/README.rst new file mode 100644 index 0000000..558b1fe --- /dev/null +++ b/{{cookiecutter.project_slug}}/README.rst @@ -0,0 +1,121 @@ +.. highlight:: shell + +=============================== +{{ cookiecutter.project_name }} +=============================== + +.. image:: https://img.shields.io/github/v/tag/pole-surfaces-planetaires/{{ cookiecutter.project_slug }} +.. image:: https://img.shields.io/github/v/release/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}?include_prereleases +{% if cookiecutter.add_pyup_badge == 'y' %} +.. image:: https://img.shields.io/pypi/v/{{ cookiecutter.project_slug }} +{% endif %} +.. image https://img.shields.io/github/downloads/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}/total +.. image https://img.shields.io/github/issues-raw/pole-surfaces-planetaires/{{ cookiecutter.project_slug }} +.. image https://img.shields.io/github/issues-pr-raw/pole-surfaces-planetaires/{{ cookiecutter.project_slug }} +.. image:: https://img.shields.io/badge/Maintained%3F-yes-green.svg + :target: https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}/graphs/commit-activity +.. image https://img.shields.io/github/license/pole-surfaces-planetaires/{{ cookiecutter.project_slug }} +.. image https://img.shields.io/github/forks/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}?style=social + + +{{ cookiecutter.project_short_description }} + + +Stable release +-------------- + +To install {{ cookiecutter.project_name }}, run this command in your terminal: + +.. code-block:: console + + $ pip install {{ cookiecutter.project_slug }} + +This is the preferred method to install {{ cookiecutter.project_name }}, as it will always install the most recent stable release. + +If you don't have `pip`_ installed, this `Python installation guide`_ can guide +you through the process. + +.. _pip: https://pip.pypa.io +.. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/ + + +From sources +------------ + +The sources for {{ cookiecutter.project_name }} can be downloaded from the `Github repo`_. + +You can either clone the public repository: + +.. code-block:: console + + $ git clone git://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }} + +Or download the `tarball`_: + +.. code-block:: console + + $ curl -OJL https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}/tarball/master + +Once you have a copy of the source, you can install it with: + +.. code-block:: console + + $ make # install in the system root + $ make user # or Install for non-root usage + + +.. _Github repo: https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }} +.. _tarball: https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}/tarball/master + + + +Development +----------- + +.. code-block:: console + + $ git clone https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }} + $ cd {{ cookiecutter.project_slug }} + $ make prepare-dev + $ source .{{ cookiecutter.project_slug }} + $ make install-dev + + +To get more information about the preconfigured tasks: + +.. code-block:: console + + $ make help + +Usage +----- + +To use {{ cookiecutter.project_name }} in a project:: + + import {{ cookiecutter.project_slug }} + + + +Run tests +--------- + +.. code-block:: console + + $make tests + + + +Author +------ +👤 **{{ cookiecutter.full_name }}** + + + +🤝 Contributing +--------------- +Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}/issues). You can also take a look at the [contributing guide](https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}/blob/master/CONTRIBUTING.rst) + + +📝 License +---------- +This project is [{{ cookiecutter.open_source_license }}](https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}/blob/master/LICENSE) licensed. diff --git a/{{cookiecutter.project_slug}}/docker/Dockerfile b/{{cookiecutter.project_slug}}/docker/Dockerfile new file mode 100644 index 0000000..c7333f7 --- /dev/null +++ b/{{cookiecutter.project_slug}}/docker/Dockerfile @@ -0,0 +1,51 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +FROM ubuntu:latest + +LABEL maintainer="{{ cookiecutter.full_name }} <{{ cookiecutter.email }}>" + +ARG BUILD_DATE +ARG VERSION +ARG DEBIAN_FRONTEND=noninteractive + +# Labels (based on http://label-schema.org/rc1/) +LABEL \ + org.label-schema.schema-version="1.0" \ + org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name="cdm" \ + org.label-schema.description="{{ cookiecutter.project_short_description }}" \ + org.label-schema.url="https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}" \ + org.label-schema.vcs-url="https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vendor="{{ cookiecutter.consortium_name }}" \ + org.label-schema.version=$VERSION + +RUN apt-get update && \ + apt-get install -y \ + software-properties-common apt-transport-https wget git\ + make python3-pip && \ + update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 && \ + pip install setuptools && \ + git clone "https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}.git" && \ + cd {{ cookiecutter.project_slug }} && \ + make + +# Custom prompt +RUN echo 'export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@platoscope-dev\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$"' >> /etc/bash.bashrc + +CMD ["{{cookiecutter.project_slug}}"] \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/docker/build.sh b/{{cookiecutter.project_slug}}/docker/build.sh new file mode 100755 index 0000000..2131a36 --- /dev/null +++ b/{{cookiecutter.project_slug}}/docker/build.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +docker build --no-cache=true --build-arg SSH_PRIVATE_KEY="`more ~/.ssh/id_rsa`" -t dev/{{cookiecutter.project_slug}} . diff --git a/{{cookiecutter.project_slug}}/docker/commit-dev.sh b/{{cookiecutter.project_slug}}/docker/commit-dev.sh new file mode 100755 index 0000000..36ccdc8 --- /dev/null +++ b/{{cookiecutter.project_slug}}/docker/commit-dev.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +docker commit develop-{{cookiecutter.project_slug}} dev/{{cookiecutter.project_slug}} diff --git a/{{cookiecutter.project_slug}}/docker/remove-dev.sh b/{{cookiecutter.project_slug}}/docker/remove-dev.sh new file mode 100755 index 0000000..25d0df4 --- /dev/null +++ b/{{cookiecutter.project_slug}}/docker/remove-dev.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +docker stop develop-{{cookiecutter.project_slug}} && docker rm develop-{{cookiecutter.project_slug}} + diff --git a/{{cookiecutter.project_slug}}/docker/run-dev.sh b/{{cookiecutter.project_slug}}/docker/run-dev.sh new file mode 100755 index 0000000..26a8d6b --- /dev/null +++ b/{{cookiecutter.project_slug}}/docker/run-dev.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +set search +set ps + +search=`docker images | grep dev/{{cookiecutter.project_slug}} | wc -l` +if [ $search = 0 ]; +then + # only the heaader - no image found + echo "Please build the image by running 'make docker-container-dev'" + exit 1 +fi + +ps=`docker ps -a | grep develop-{{cookiecutter.project_slug}} | wc -l` +if [ $ps = 0 ]; +then + echo "no container available, start one" + docker run --name=develop-{{cookiecutter.project_slug}} #\ + #-v /dev:/dev \ + #-v `echo ~`:/home/${USER} \ + #-v `pwd`/data:/srv/{{cookiecutter.project_slug}}/data \ + #-p 8082:8082 \ + -it dev/{{cookiecutter.project_slug}} /bin/bash + exit $? +fi + +ps=`docker ps | grep develop-{{cookiecutter.project_slug}} | wc -l` +if [ $ps = 0 ]; +then + echo "container available but not started, start and go inside" + docker start develop-{{cookiecutter.project_slug}} + docker exec -it develop-{{cookiecutter.project_slug}} /bin/bash +else + echo "container started, go inside" + docker exec -it develop-{{cookiecutter.project_slug}} /bin/bash +fi diff --git a/{{cookiecutter.project_slug}}/docs/Makefile b/{{cookiecutter.project_slug}}/docs/Makefile new file mode 100644 index 0000000..d0c3cbf --- /dev/null +++ b/{{cookiecutter.project_slug}}/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/{{cookiecutter.project_slug}}/docs/make.bat b/{{cookiecutter.project_slug}}/docs/make.bat new file mode 100644 index 0000000..6247f7e --- /dev/null +++ b/{{cookiecutter.project_slug}}/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/{{cookiecutter.project_slug}}/docs/source/authors.rst b/{{cookiecutter.project_slug}}/docs/source/authors.rst new file mode 100644 index 0000000..45e128a --- /dev/null +++ b/{{cookiecutter.project_slug}}/docs/source/authors.rst @@ -0,0 +1 @@ +.. include:: ../../AUTHORS.rst \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/docs/source/conf.py b/{{cookiecutter.project_slug}}/docs/source/conf.py new file mode 100644 index 0000000..2806d3f --- /dev/null +++ b/{{cookiecutter.project_slug}}/docs/source/conf.py @@ -0,0 +1,127 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# 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. +# +import os +import sys + +sys.path.insert(0, os.path.abspath("../..")) +import {{ cookiecutter.project_slug }} + +# -- Project information ----------------------------------------------------- + +project = "{{cookiecutter.project_name}}" +copyright = "{{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}})" +author = "{{cookiecutter.full_name}}" +version = {{ cookiecutter.project_slug }}.__version__ +release = {{ cookiecutter.project_slug }}.__version__ + +# -- General configuration --------------------------------------------------- + +# 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.viewcode', + 'sphinx.ext.autosummary', + 'sphinx.ext.autosummary' +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build'] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = 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 = "sphinx_rtd_theme" + +html_logo = "logo.png" + +# 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"] + +# Output file base name for HTML help builder. +htmlhelp_basename = '{{ cookiecutter.project_slug }}doc' + +# -- 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': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# 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 = [ + (master_doc, '{{ cookiecutter.project_slug }}.tex', + '{{ cookiecutter.project_name }} Documentation', + '{{ cookiecutter.full_name }}', 'manual'), +] + +# -- Options for manual page output ------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, '{{ cookiecutter.project_slug }}', + '{{ cookiecutter.project_name }} Documentation', + [author], 1) +] + +# -- 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 = [ + (master_doc, '{{ cookiecutter.project_slug }}', + '{{ cookiecutter.project_name }} Documentation', + author, + '{{ cookiecutter.project_slug }}', + 'One line description of project.', + 'Miscellaneous'), +] diff --git a/{{cookiecutter.project_slug}}/docs/source/contributing.rst b/{{cookiecutter.project_slug}}/docs/source/contributing.rst new file mode 100644 index 0000000..8cb3146 --- /dev/null +++ b/{{cookiecutter.project_slug}}/docs/source/contributing.rst @@ -0,0 +1 @@ +.. include:: ../../CONTRIBUTING.rst \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/docs/source/history.rst b/{{cookiecutter.project_slug}}/docs/source/history.rst new file mode 100644 index 0000000..ac253be --- /dev/null +++ b/{{cookiecutter.project_slug}}/docs/source/history.rst @@ -0,0 +1 @@ +.. include:: ../../CHANGELOG \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/docs/source/index.rst b/{{cookiecutter.project_slug}}/docs/source/index.rst new file mode 100644 index 0000000..bae70b0 --- /dev/null +++ b/{{cookiecutter.project_slug}}/docs/source/index.rst @@ -0,0 +1,18 @@ +Welcome to {{ cookiecutter.project_name }}'s documentation! +====================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + readme + modules + contributing + {% if cookiecutter.create_author_file == 'y' -%}authors + {% endif -%}history + +Indices and tables +================== +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/{{cookiecutter.project_slug}}/docs/source/logo.png b/{{cookiecutter.project_slug}}/docs/source/logo.png new file mode 100644 index 0000000..1d14f0f Binary files /dev/null and b/{{cookiecutter.project_slug}}/docs/source/logo.png differ diff --git a/{{cookiecutter.project_slug}}/docs/source/modules.rst b/{{cookiecutter.project_slug}}/docs/source/modules.rst new file mode 100644 index 0000000..ad37537 --- /dev/null +++ b/{{cookiecutter.project_slug}}/docs/source/modules.rst @@ -0,0 +1,36 @@ +******** +Modules +******** + +1 - Introduction +################ + +.. automodule:: {{ cookiecutter.project_slug }} + +2 - Monitoring +############## + +.. automodule:: {{ cookiecutter.project_slug }}.monitoring +.. autoclass:: UtilsMonitoring + :members: + :private-members: + +3 - Custom Logging +################### + +.. automodule:: {{ cookiecutter.project_slug }}.custom_logging +.. autoclass:: UtilsLogs + :members: + :private-members: + +.. autoclass:: LogRecord + :members: + :private-members: + +.. autoclass:: CustomColorFormatter + :members: + :private-members: + +.. autoclass:: ShellColorFormatter + :members: + :private-members: diff --git a/{{cookiecutter.project_slug}}/docs/source/readme.rst b/{{cookiecutter.project_slug}}/docs/source/readme.rst new file mode 100644 index 0000000..38ba804 --- /dev/null +++ b/{{cookiecutter.project_slug}}/docs/source/readme.rst @@ -0,0 +1 @@ +.. include:: ../../README.rst \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml new file mode 100644 index 0000000..c57772b --- /dev/null +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -0,0 +1,28 @@ +[build-system] +requires = ["setuptools", "wheel", "setuptools_scm"] +build-backend = 'setuptools.build_meta' + +[tool.black] +line-length = 79 +include = '\.pyi?$' +exclude = ''' +/( + \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist +)/ +''' + +[tool.flit.metadata] +module = "{{cookiecutter.project_slug}}" +author = "{{cookiecutter.full_name}}" +author-email = "{{cookiecutter.email}}" +home-page = "https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}" +classifiers = [ "License :: OSI Approved :: {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License v3 (GPLv3){% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 (LGPLv3){% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3 (AGPLv3){% endif %}",] +description-file = "README.rst" \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/requirements.txt b/{{cookiecutter.project_slug}}/requirements.txt new file mode 100644 index 0000000..a3c7c47 --- /dev/null +++ b/{{cookiecutter.project_slug}}/requirements.txt @@ -0,0 +1,8 @@ +setuptools-scm==6.0.1 +types-setuptools==57.0.0 +fastapi==0.65.2 +uvicorn==0.14.0 +tortoise-orm==0.17.4 +pydantic==1.8.2 +asyncpg==0.23.0 +python-dotenv==0.18.0 \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/requirements_data.txt b/{{cookiecutter.project_slug}}/requirements_data.txt new file mode 100644 index 0000000..e69de29 diff --git a/{{cookiecutter.project_slug}}/requirements_dev.txt b/{{cookiecutter.project_slug}}/requirements_dev.txt new file mode 100644 index 0000000..a0b672c --- /dev/null +++ b/{{cookiecutter.project_slug}}/requirements_dev.txt @@ -0,0 +1,17 @@ +pre-commit==2.13.0 +pre-commit-hooks==4.0.1 +flit==3.2.0 +flit-core==3.2.0 +black==20.8b1 +coverage==5.5 +flake8==3.9.2 +mccabe==0.6.1 +mypy==0.910 +mypy-extensions==0.4.3 +pylint==3.0.0a1 +pytest==6.2.4 +tox==3.23.1 +Sphinx==4.0.2 +pip-licenses==3.4.0 +sphinx_rtd_theme +pur==5.4.1 diff --git a/{{cookiecutter.project_slug}}/scripts/data_download.py b/{{cookiecutter.project_slug}}/scripts/data_download.py new file mode 100644 index 0000000..a3d4b02 --- /dev/null +++ b/{{cookiecutter.project_slug}}/scripts/data_download.py @@ -0,0 +1,4 @@ +import os +import os.path + +# download script TODO diff --git a/{{cookiecutter.project_slug}}/scripts/generate-changelog.bash b/{{cookiecutter.project_slug}}/scripts/generate-changelog.bash new file mode 100755 index 0000000..d3f7f06 --- /dev/null +++ b/{{cookiecutter.project_slug}}/scripts/generate-changelog.bash @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# if any command inside script returns error, exit and return that error +set -e + +# magic line to ensure that we're always inside the root of our application, +# no matter from which directory we'll run script +# thanks to it we can just enter `./scripts/run-tests.bash` +cd "${0%/*}/.." + +# generate the changelog +echo "Generate changelog" +git --no-pager log --no-merges --format="### %s%d%n>%aD%n%n>Author: %aN (%aE)%n%n>Commiter: %cN (%cE)%n%n%b%n%N%n" > CHANGELOG + +# prevent recursion! +# since a 'commit --amend' will trigger the post-commit script again +# we have to check if the changelog file has changed or not +res=$(git status --porcelain | grep -c CHANGELOG) +if [ "$res" -gt 0 ]; then + git add CHANGELOG + git commit --amend --no-edit --no-verify + echo "Populated Changelog in CHANGELOG" +fi diff --git a/{{cookiecutter.project_slug}}/scripts/init_remote_repo.bash b/{{cookiecutter.project_slug}}/scripts/init_remote_repo.bash new file mode 100644 index 0000000..e61fa83 --- /dev/null +++ b/{{cookiecutter.project_slug}}/scripts/init_remote_repo.bash @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +git branch -M main +git remote add origin https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}.git +git push -u origin main diff --git a/{{cookiecutter.project_slug}}/scripts/install-hooks.bash b/{{cookiecutter.project_slug}}/scripts/install-hooks.bash new file mode 100755 index 0000000..4230764 --- /dev/null +++ b/{{cookiecutter.project_slug}}/scripts/install-hooks.bash @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +GIT_DIR=$(git rev-parse --git-dir) + +echo "Installing hooks..." +# this command creates symlink to our pre-commit script +ln -s ../../scripts/post-commit.bash $GIT_DIR/hooks/post-commit +echo "Done!" diff --git a/{{cookiecutter.project_slug}}/scripts/post-commit.bash b/{{cookiecutter.project_slug}}/scripts/post-commit.bash new file mode 100755 index 0000000..44cfccb --- /dev/null +++ b/{{cookiecutter.project_slug}}/scripts/post-commit.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +./scripts/generate-changelog.bash diff --git a/{{cookiecutter.project_slug}}/setup.py b/{{cookiecutter.project_slug}}/setup.py new file mode 100644 index 0000000..258b823 --- /dev/null +++ b/{{cookiecutter.project_slug}}/setup.py @@ -0,0 +1,54 @@ +import setuptools +from os import path, sep + +here = path.abspath(path.dirname(__file__)) + +# Get the long description from the README file +with open(path.join(here, "README.rst"), encoding="utf-8") as f: + readme = f.read() + +with open("requirements.txt") as f: + required = f.read().splitlines() + +setup_requirements = ['setuptools_scm',{%- if cookiecutter.use_pytest == 'y' %}'pytest-runner',{%- endif %} ] + +test_requirements = [{%- if cookiecutter.use_pytest == 'y' %}'pytest>=3',{%- endif %} ] + +about = {} +with open( + path.join(here, "{{cookiecutter.project_slug}}", "_version.py"), + encoding="utf-8", +) as f: + exec(f.read(), about) + +setuptools.setup( + use_scm_version=True, + name=about["__name_soft__"], + description=about["__description__"], + long_description=readme, + author=about["__author__"], + author_email=about["__author_email__"], + url=about["__url__"], + license=about["__license__"], + long_description_content_type="text/markdown", + packages=setuptools.find_packages(), + setup_requires=setup_requirements, + test_suite='tests', + tests_require=test_requirements, + package_data={about["__name_soft__"]: ["README.md", "logging.conf"]}, + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3){% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License v3 (GPLv3){% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 (LGPLv3){% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3 (AGPLv3){% endif %}", + "Operating System :: OS Independent", + ], + python_requires=">=3.6", + install_requires=required, + entry_points={ + "console_scripts": [ + about["__name_soft__"] + + "=" + + about["__name_soft__"] + + ".__main__:run", + ], + }, # Optional +) diff --git a/{{cookiecutter.project_slug}}/tests/{{cookiecutter.project_slug}}_test.py b/{{cookiecutter.project_slug}}/tests/{{cookiecutter.project_slug}}_test.py new file mode 100644 index 0000000..28f4eb9 --- /dev/null +++ b/{{cookiecutter.project_slug}}/tests/{{cookiecutter.project_slug}}_test.py @@ -0,0 +1,14 @@ +import pytest + +import {{cookiecutter.project_slug}} +import logging + +def test_name(): + name = {{cookiecutter.project_slug}}.__name_soft__ + assert name == "{{cookiecutter.project_slug}}" + +def test_logger(): + loggers = [logging.getLogger()] + loggers = loggers + [logging.getLogger(name) for name in logging.root.manager.loggerDict] + assert loggers[0].name == "root" + assert loggers[1].name == "{{cookiecutter.project_slug}}" \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/tox.ini b/{{cookiecutter.project_slug}}/tox.ini new file mode 100644 index 0000000..2fe8f5d --- /dev/null +++ b/{{cookiecutter.project_slug}}/tox.ini @@ -0,0 +1,21 @@ +[tox] +isolated_build = True +envlist = py38 + +[testenv] +deps = + black + coverage + flake8 + mccabe + mypy + pylint + pytest +commands = + black --line-length=79 --include='\.pyi?$' --exclude='(\.git | \.docker| \.mypy_cache | \.tox | {{cookiecutter.project_slug}}-env | scripts | tests | _build | build | dist)' {{cookiecutter.project_slug}} + flake8 --ignore=E203,E266,E501,W503,F403,F401 --max-line-length=79 --max-complexity=18 --select=B,C,E,F,W,T4,B9 --exclude=docs/source/conf.py {{cookiecutter.project_slug}} + pylint {{cookiecutter.project_slug}} + mypy {{cookiecutter.project_slug}} + coverage erase + coverage run --include={{cookiecutter.project_slug}}/* -m pytest -ra + coverage report -m \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/__init__.py new file mode 100644 index 0000000..954bdc1 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/__init__.py @@ -0,0 +1,49 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""{{cookiecutter.project_short_description}}""" +import logging.config +import os +from logging import NullHandler + +from ._version import __author__ +from ._version import __author_email__ +from ._version import __copyright__ +from ._version import __description__ +from ._version import __license__ +from ._version import __name_soft__ +from ._version import __title__ +from ._version import __url__ +from ._version import __version__ +from .custom_logging import LogRecord +from .custom_logging import UtilsLogs + +logging.getLogger(__name__).addHandler(NullHandler()) + +UtilsLogs.add_logging_level("TRACE", 15) +try: + PATH_TO_CONF = os.path.dirname(os.path.realpath(__file__)) + logging.config.fileConfig( + os.path.join(PATH_TO_CONF, "logging.conf"), + disable_existing_loggers=False, + ) + logging.debug( + "file %s loaded" % os.path.join(PATH_TO_CONF, "logging.conf") + ) +except Exception as exception: # pylint: disable=broad-except + logging.warning("cannot load logging.conf : %s" % exception) +logging.setLogRecordFactory(LogRecord) # pylint: disable=no-member diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/__main__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/__main__.py new file mode 100644 index 0000000..a4e8016 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/__main__.py @@ -0,0 +1,138 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Main program.""" +import logging +import argparse +import signal +import sys +from {{cookiecutter.project_slug}} import __author__ +from {{cookiecutter.project_slug}} import __copyright__ +from {{cookiecutter.project_slug}} import __description__ +from {{cookiecutter.project_slug}} import __version__ +from .{{cookiecutter.project_slug}} import {{cookiecutter.project_class_lib}} + + +class SmartFormatter(argparse.HelpFormatter): + """Smart formatter for argparse - The lines are split for long text""" + + def _split_lines(self, text, width): + if text.startswith("R|"): + return text[2:].splitlines() + # this is the RawTextHelpFormatter._split_lines + return argparse.HelpFormatter._split_lines(self, text, width) + + +class SigintHandler: # pylint: disable=too-few-public-methods + """Handles the signal""" + + def __init__(self): + self.SIGINT = False # pylint: disable=invalid-name + + def signal_handler(self, sig: int, frame): + """Trap the signal + + Args: + sig (int): the signal number + frame: the current stack frame + """ + # pylint: disable=unused-argument + logging.error("You pressed Ctrl+C") + self.SIGINT = True + sys.exit(2) + + +def str2bool(string_to_test: str) -> bool: + """Checks if a given string is a boolean + + Args: + string_to_test (str): string to test + + Returns: + bool: True when the string is a boolean otherwise False + """ + return string_to_test.lower() in ("yes", "true", "True", "t", "1") + + +def parse_cli() -> argparse.Namespace: + """Parse command line inputs. + + Returns + ------- + argparse.Namespace + Command line options + """ + parser = argparse.ArgumentParser( + description=__description__, + formatter_class=SmartFormatter, + epilog=__author__ + " - " + __copyright__, + ) + parser.add_argument( + "-v", "--version", action="version", version="%(prog)s " + __version__ + ) + + parser.add_argument( + "--conf_file", + default="conf/{{cookiecutter.project_slug}}.conf", + help="The location of the configuration file (default: %(default)s)", + ) + + parser.add_argument( + "--output_directory", + default="{{cookiecutter.project_slug}}-data", + help="The output directory where the data products are created (default: %(default)s)", + ) + + parser.add_argument( + "--level", + choices=[ + "INFO", + "DEBUG", + "WARNING", + "ERROR", + "CRITICAL", + "TRACE", + ], + default="INFO", + help="set Level log (default: %(default)s)", + ) + + return parser.parse_args() + + +def run(): + """Main function that instanciates the library.""" +# logger = logging.getLogger(__name__) + handler = SigintHandler() + signal.signal(signal.SIGINT, handler.signal_handler) + try: + options_cli = parse_cli() + + {{cookiecutter.project_slug}} = {{cookiecutter.project_class_lib}}( + options_cli.conf_file, + options_cli.output_directory, + level=options_cli.level, + ) + {{cookiecutter.project_slug}}.start() + except Exception as error: # pylint: disable=broad-except + logging.exception(error) + sys.exit(1) + + +if __name__ == "__main__": + # execute only if run as a script + run() diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/_version.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/_version.py new file mode 100644 index 0000000..37d6d59 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/_version.py @@ -0,0 +1,33 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License{% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Project metadata.""" +from pkg_resources import DistributionNotFound +from pkg_resources import get_distribution + +__name_soft__ = "{{cookiecutter.project_slug}}" +try: + __version__ = get_distribution(__name_soft__).version +except DistributionNotFound: + __version__ = "0.0.0" +__title__ = "{{cookiecutter.project_name}}" +__description__ = "{{cookiecutter.project_short_description}}" +__url__ = "https://github.com/pole-surfaces-planetaires/{{ cookiecutter.project_slug }}" +__author__ = "{{cookiecutter.full_name}}" +__author_email__ = "{{cookiecutter.email}}" +__license__ = "{{cookiecutter.open_source_license}}" +__copyright__ = "{{cookiecutter.year}}, {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}})" diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/conf/{{cookiecutter.project_slug}}.conf b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/conf/{{cookiecutter.project_slug}}.conf new file mode 100644 index 0000000..e69de29 diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/__init__.py new file mode 100644 index 0000000..e1952eb --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/__init__.py @@ -0,0 +1,23 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Config of application""" +from .db import TortoiseSettings +from .openapi import OpenAPISettings + +tortoise_config = TortoiseSettings.generate() +openapi_config = OpenAPISettings.generate() diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/base.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/base.py new file mode 100644 index 0000000..e441347 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/base.py @@ -0,0 +1,25 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Base Settings""" +from pydantic import BaseSettings as BS + + +class BaseSettings(BS): # pylint: disable=too-few-public-methods + """Base settings.""" + + # include some if needed diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/cfg.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/cfg.py new file mode 100644 index 0000000..63dca42 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/cfg.py @@ -0,0 +1,21 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Some vars""" +from os import environ + +IS_TEST = bool(environ.get("API_TEST")) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/db.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/db.py new file mode 100644 index 0000000..4d2efe1 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/db.py @@ -0,0 +1,67 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Config of DB""" +from pydantic import Field + +from .base import BaseSettings +from .cfg import IS_TEST + +DB_MODELS = ["{{cookiecutter.project_slug}}.core.models.tortoise"] +POSTGRES_DB_URL = "postgres://{postgres_user}:{postgres_password}@{postgres_host}:{postgres_port}/{postgres_db}" # pylint: disable=line-too-long +SQLITE_DB_URL = "sqlite://{sqlite_db}" # sqlite://:memory:" + + +class SqlLiteSettings(BaseSettings): # pylint: disable=too-few-public-methods + """SQL liste env values""" + + sqlite_db: str = Field("db.sqlite3", env="SQLITE_DB") + + +class PostgresSettings(BaseSettings): # pylint: disable=too-few-public-methods + """Postgres env values""" + + postgres_user: str = Field("postgres", env="POSTGRES_USER") + postgres_password: str = Field("postgres", env="POSTGRES_PASSWORD") + postgres_db: str = Field("mydb", env="POSTGRES_DB") + postgres_port: str = Field("5432", env="POSTGRES_PORT") + postgres_host: str = Field("postgres", env="POSTGRES_HOST") + + +class TortoiseSettings(BaseSettings): # pylint: disable=too-few-public-methods + """Tortoise-ORM settings""" + + db_url: str + modules: dict + generate_schemas: bool + + @classmethod + def generate(cls): + """Generate Tortoise-ORM settings (with sqlite if tests)""" + + if IS_TEST: + sqlite = SqlLiteSettings() + db_url = SQLITE_DB_URL.format(**sqlite.dict()) + del sqlite + else: + postgres = PostgresSettings() + db_url = POSTGRES_DB_URL.format(**postgres.dict()) + del postgres + modules = {"models": DB_MODELS} + return TortoiseSettings( + db_url=db_url, modules=modules, generate_schemas=True + ) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/openapi.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/openapi.py new file mode 100644 index 0000000..bc43d45 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/config/openapi.py @@ -0,0 +1,45 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""OpenAPI-schema""" +from .base import BaseSettings +from .._version import __title__, __version__, __description__ + +OPENAPI_API_NAME = __title__ +OPENAPI_API_VERSION = __version__ +OPENAPI_API_DESCRIPTION = __description__ + + +class OpenAPISettings(BaseSettings): # pylint: disable=too-few-public-methods + """Open API settings.""" + + name: str + version: str + description: str + + @classmethod + def generate(cls): + """Generate the settings of the OpenAPI + + Returns: + OpenAPISettings: the settings of the OpenAPI + """ + return OpenAPISettings( + name=OPENAPI_API_NAME, + version=OPENAPI_API_VERSION, + description=OPENAPI_API_DESCRIPTION, + ) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/__init__.py new file mode 100644 index 0000000..0cdc07e --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/__init__.py @@ -0,0 +1,26 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +""" +Core of API. +""" +from . import business +from . import exceptions +from . import models +from . import routers + +__all__ = ["business", "exceptions", "models", "routers"] diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/business/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/business/__init__.py new file mode 100644 index 0000000..cbb66df --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/business/__init__.py @@ -0,0 +1,19 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Business - Business classes""" +# import your business classes diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/exceptions/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/exceptions/__init__.py new file mode 100644 index 0000000..2ab180d --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/exceptions/__init__.py @@ -0,0 +1,18 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +# Some exception, handlers diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/exceptions/exceptions.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/exceptions/exceptions.py new file mode 100644 index 0000000..aea25d4 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/exceptions/exceptions.py @@ -0,0 +1,19 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""API Exceptions""" +# some exceptions diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/exceptions/handlers.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/exceptions/handlers.py new file mode 100644 index 0000000..a3d09df --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/exceptions/handlers.py @@ -0,0 +1,18 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Handler for those exceptions.""" diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/__init__.py new file mode 100644 index 0000000..2f19f8e --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/__init__.py @@ -0,0 +1,22 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +""" +Models - database and pydantic models of API entities. +""" +from .pydantic import User_Pydantic +from .tortoise import Users diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/pydantic/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/pydantic/__init__.py new file mode 100644 index 0000000..a55a0a2 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/pydantic/__init__.py @@ -0,0 +1,21 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +""" +Pydantic models. +""" +from .users import User_Pydantic diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/pydantic/users.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/pydantic/users.py new file mode 100644 index 0000000..355dd7b --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/pydantic/users.py @@ -0,0 +1,22 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Pydantic model""" +from tortoise.contrib.pydantic import pydantic_model_creator +from ..tortoise import Users + +User_Pydantic = pydantic_model_creator(Users, name="User") diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/tortoise/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/tortoise/__init__.py new file mode 100644 index 0000000..79a04fa --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/tortoise/__init__.py @@ -0,0 +1,21 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +""" +Tortoise models. +""" +from .users import Users diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/tortoise/users.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/tortoise/users.py new file mode 100644 index 0000000..b3ecd3a --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/models/tortoise/users.py @@ -0,0 +1,49 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""ORM Models""" +from tortoise import fields, models + + +class Users(models.Model): + """ + The User model + """ + + id = fields.IntField(pk=True) + #: This is a username + username = fields.CharField(max_length=20, unique=True) + name = fields.CharField(max_length=50, null=True) + family_name = fields.CharField(max_length=50, null=True) + category = fields.CharField(max_length=30, default="misc") + password_hash = fields.CharField(max_length=128, null=True) + created_at = fields.DatetimeField(auto_now_add=True) + modified_at = fields.DatetimeField(auto_now=True) + + def full_name(self) -> str: + """ + Returns the best name + """ + if self.name or self.family_name: + return f"{self.name or ''} {self.family_name or ''}".strip() + return self.username + + class PydanticMeta: # pylint: disable=too-few-public-methods + """Metadata""" + + computed = ["full_name"] + exclude = ["password_hash"] diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/routers/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/routers/__init__.py new file mode 100644 index 0000000..f3a91a1 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/routers/__init__.py @@ -0,0 +1,5 @@ +"""Routers""" +from .website_router import router as router_web_site +from .ws_router import router as router_ws + +__all__ = ["router_web_site", "router_ws"] diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/routers/website_router.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/routers/website_router.py new file mode 100644 index 0000000..646edfb --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/routers/website_router.py @@ -0,0 +1,29 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Web site router""" + +from fastapi import APIRouter +from starlette.responses import HTMLResponse + +router = APIRouter() + + +@router.get("/") +async def root(): + """Root path if the web server""" + return HTMLResponse("Hello!") diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/routers/ws_router.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/routers/ws_router.py new file mode 100644 index 0000000..eeda326 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/core/routers/ws_router.py @@ -0,0 +1,53 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Services router""" + +import logging +from fastapi import APIRouter + +logger = logging.getLogger(__name__) + +router = APIRouter() + + +@router.get( + "/ping", + summary="Method to be used to test if the server is alive", + response_model=str, + description="The service answers 'I am alive'", + tags=["Alive"], +) +async def get_alive(): + """Returns 'I am alive" when the server is alive. + + Returns: + str: I am alive + """ + return "I am alive" + + +@router.on_event("startup") +async def startup_event(): + """Startup the server.""" + logger.info("Startup") + + +@router.on_event("shutdown") +async def close_orm(): + """Shutdown the server.""" + logger.info("shutdown") diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/custom_logging.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/custom_logging.py new file mode 100644 index 0000000..f0afccb --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/custom_logging.py @@ -0,0 +1,165 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Module for customizing ths logs.""" +import logging +from typing import Optional + + +class UtilsLogs: # pylint: disable=R0903 + """Utility class for logs.""" + + @staticmethod + def add_logging_level( + level_name: str, level_num: int, method_name: Optional[str] = None + ) -> None: + """Add a new logging level to the `logging` module. + + Parameters + ---------- + level_name: str + level name of the logging + level_num: int + level number related to the level name + method_name: Optional[str] + method for both `logging` itself and the class returned by + `logging.Logger` + + Returns + ------- + None + + Raises + ------ + AttributeError + If this levelName or methodName is already defined in the + logger. + + """ + if not method_name: + method_name = level_name.lower() + + def log_for_level(self, message, *args, **kwargs): + if self.isEnabledFor(level_num): + self._log( # pylint: disable=W0212 + level_num, message, args, **kwargs + ) + + def log_to_root(message, *args, **kwargs): + logging.log(level_num, message, *args, **kwargs) + + logging.addLevelName(level_num, level_name) + setattr(logging, level_name, level_num) + setattr(logging.getLoggerClass(), method_name, log_for_level) + setattr(logging, method_name, log_to_root) + + +class LogRecord(logging.LogRecord): # pylint: disable=R0903 + """Specific class to handle output in logs.""" + + def getMessage(self) -> str: + """Returns the message. + + Format the message according to the type of the message. + + Returns: + str: Returns the message + """ + msg = str(self.msg) + if isinstance(self.args, dict): + return msg.format(self.args) + return msg.format(*self.args) if self.args else msg + + +class CustomColorFormatter(logging.Formatter): + """Color formatter.""" + + UtilsLogs.add_logging_level("TRACE", 15) + # Reset + color_Off = "\033[0m" # Text Reset + + log_colors = { + logging.TRACE: "\033[0;36m", # type: ignore # pylint: disable=no-member # cyan + logging.DEBUG: "\033[1;34m", # blue + logging.INFO: "\033[0;32m", # green + logging.WARNING: "\033[1;33m", # yellow + logging.ERROR: "\033[1;31m", # red + logging.CRITICAL: "\033[1;41m", # red reverted + } + + def format(self, record) -> str: + """Format the log. + + Args: + record: the log record + + Returns: + str: the formatted log record + """ + record.levelname = "{}{}{}".format( + CustomColorFormatter.log_colors[record.levelno], + record.levelname, + CustomColorFormatter.color_Off, + ) + record.msg = "{}{}{}".format( + CustomColorFormatter.log_colors[record.levelno], + record.msg, + CustomColorFormatter.color_Off, + ) + + # Select the formatter according to the log if several handlers are + # attached to the logger + my_formatter = logging.Formatter + my_handler = None + handlers = logging.getLogger(__name__).handlers + for handler in handlers: + handler_level = handler.level + if ( + handler_level + == logging.getLogger(__name__).getEffectiveLevel() + ): + if handler.formatter: + my_formatter._fmt = ( # pylint: disable=W0212 + handler.formatter._fmt # pylint: disable=W0212 + ) + my_handler = handler + break + if my_handler is not None: + for handler in handlers: + if handler != my_handler: + logging.getLogger(__name__).removeHandler(handler) + return my_formatter.format(self, record) # type: ignore + + +class ShellColorFormatter(CustomColorFormatter): + """Shell Color formatter.""" + + def format(self, record) -> str: + """Format the log. + + Args: + record: the log record + + Returns: + str: the formatted log record + """ + record.msg = "{}{}{}".format( + CustomColorFormatter.log_colors[logging.INFO], + record.msg, + CustomColorFormatter.color_Off, + ) + return record.msg diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/initializer.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/initializer.py new file mode 100644 index 0000000..bec77bc --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/initializer.py @@ -0,0 +1,64 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""Initialization of the server""" +from fastapi import FastAPI +from tortoise.contrib.starlette import register_tortoise + +from .config import tortoise_config +from .core.routers import router_web_site, router_ws + + +def init(app: FastAPI): + """ + Init routers and etc. + :return: + """ + init_routers(app) + init_db(app) + + +def init_db(app: FastAPI): + """ + Init database models. + :param app: + :return: + """ + register_tortoise( + app, + db_url=tortoise_config.db_url, + generate_schemas=tortoise_config.generate_schemas, + modules=tortoise_config.modules, + ) + + +def init_routers(app: FastAPI): + """ + Initialize routers defined in `app.api` + :param app: + :return: + """ + app.include_router( + router_ws, + prefix="/ws", + responses={404: {"description": "Not found"}}, + ) + app.include_router( + router_web_site, + tags=["Web site"], + responses={404: {"description": "Not found"}}, + ) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/logging.conf b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/logging.conf new file mode 100644 index 0000000..3f3c625 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/logging.conf @@ -0,0 +1,89 @@ +[loggers] +keys=root, {{cookiecutter.project_slug}} + +[handlers] +keys=devel,normal_colored, minimal_colored, devel_colored, screen + +[formatters] +keys=minimal,normal,debug,minimal_colored,normal_colored,debug_colored + + +########### +# Loggers # +########### +[logger_root] +handlers=minimal_colored +level=INFO + +[logger_{{cookiecutter.project_slug}}] +qualname={{cookiecutter.project_slug}} +level=INFO +handlers=minimal_colored +propagate=0 + +################ +# Log Handlers # +################ + +[handler_starting] +class=StreamHandler +level=NOTSET +formatter=minimal +args=(sys.stdout,) + +[handler_devel] +class=StreamHandler +level=NOTSET +formatter=debug +args=(sys.stdout,) + +[handler_minimal_colored] +class=StreamHandler +name=minimal_colored +level=INFO +formatter=minimal_colored +args=(sys.stdout,) + +[handler_normal_colored] +class=StreamHandler +level=INFO +formatter=normal_colored +args=(sys.stdout,) + +[handler_devel_colored] +class=StreamHandler +level=DEBUG +formatter=debug_colored +args=(sys.stdout,) + +[handler_screen] +class=StreamHandler +formatter=minimal +level=INFO +args=(sys.stdout,) + + +################## +# Log Formatters # +################## + +[formatter_minimal] +format=%(message)s + +[formatter_normal] +format=(%(name)s): %(asctime)s %(levelname)s %(message)s + +[formatter_debug] +format=(%(name)s:%(lineno)s) %(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s + +[formatter_minimal_colored] +class={{cookiecutter.project_slug}}.custom_logging.CustomColorFormatter +format=%(message)s + +[formatter_normal_colored] +class={{cookiecutter.project_slug}}.custom_logging.CustomColorFormatter +format=(%(name)s): %(asctime)s %(levelname)s %(message)s + +[formatter_debug_colored] +class={{cookiecutter.project_slug}}.custom_logging.CustomColorFormatter +format=(%(name)s:%(lineno)s) %(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/monitoring.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/monitoring.py new file mode 100644 index 0000000..6417693 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/monitoring.py @@ -0,0 +1,203 @@ +# Copyright (C) 2020-2021 - Centre National d'Etudes Spatiales +# jean-christophe.malapert@cnes.fr +# +# This file is part of {{cookiecutter.project_slug}}. +# +# {{cookiecutter.project_slug}} is a free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3.0 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA +"""Some Utilities.""" +import logging +import os +import time +import tracemalloc +from functools import partial +from functools import wraps + + +class UtilsMonitoring: # noqa: R0205 + """Some Utilities.""" + + # pylint: disable:invalid_name + @staticmethod + def io_display( + func=None, input=True, output=True, level=15 + ): # pylint: disable=W0622 + """Monitor the input/output of a function. + + NB : Do not use this monitoring method on an __init__ if the class + implements __repr__ with attributes + + Parameters + ---------- + func: func + function to monitor (default: {None}) + input: bool + True when the function must monitor the input (default: {True}) + output: bool + True when the function must monitor the output (default: {True}) + level: int + Level from which the function must log + Returns + ------- + object : the result of the function + """ + if func is None: + return partial( + UtilsMonitoring.io_display, + input=input, + output=output, + level=level, + ) + + @wraps(func) + def wrapped(*args, **kwargs): + name = func.__qualname__ + logger = logging.getLogger(__name__ + "." + name) + + if input and logger.getEffectiveLevel() >= level: + msg = f"Entering '{name}' (args={args}, kwargs={kwargs})" + logger.log(level, msg) + + result = func(*args, **kwargs) + + if output and logger.getEffectiveLevel() >= level: + msg = f"Exiting '{name}' (result={result})" + logger.log(level, msg) + + return result + + return wrapped + + @staticmethod + def time_spend(func=None, level=logging.DEBUG, threshold_in_ms=1000): + """Monitor the performances of a function. + + Parameters + ---------- + func: func + Function to monitor (default: {None}) + level: int + Level from which the monitoring starts (default: {logging.DEBUG}) + threshold_in_ms: int + an alert is sent at any level when the function duration > + threshold_in_ms (default: {1000}) + + Returns + ------- + object : the result of the function + """ + if func is None: + return partial(UtilsMonitoring.time_spend, level=level) + + @wraps(func) + def newfunc(*args, **kwargs): + name = func.__qualname__ + logger = logging.getLogger(__name__ + "." + name) + start_time = time.time() + result = func(*args, **kwargs) + elapsed_time = time.time() - start_time + logger.log( + level, + "function [{}] finished in {:.2f} ms".format( + func.__qualname__, elapsed_time * 1000 + ), + ) + if float(elapsed_time) * 1000 > threshold_in_ms: + logger.warning( + "function [{}] is too long to compute : {:.2f} ms".format( + func.__qualname__, elapsed_time * 1000 + ) + ) + return result + + return newfunc + + @staticmethod + def size(func=None, level=logging.INFO): + """Monitor the number of records in a file. + + Parameters + ---------- + func: func + Function to monitor (default: {None}) + level: int + Level from which the monitoring starts (default: {logging.INFO}) + + Returns + ------- + object : the result of the function + """ + if func is None: + return partial(UtilsMonitoring.size, level=level) + + @wraps(func) + def newfunc(*args, **kwargs): + name = func.__qualname__ + logger = logging.getLogger(__name__ + "." + name) + filename = os.path.basename(args[1]) + logger.log(level, "Loading file '%s'", filename) + result = func(*args, **kwargs) + type_result = type(result) + if type_result in [type({}), type([])]: + nb_records = len(result) + else: + try: + nb_records = result.shape + except AttributeError: # noqa: W0703 + nb_records = None + + if nb_records is not None: + msg = ( + f"File '{filename}' loaded with {str(nb_records)} records" + ) + logger.info(msg) + else: + msg = f"Unable to load the number of records in file '{args[1]}' - type: {type_result}" # pylint: disable=line-too-long + logger.warning(msg) + return result + + return newfunc + + @staticmethod + def measure_memory(func=None, level=logging.DEBUG): + """Measure the memory of the function + + Args: + func (func, optional): Function to measure. Defaults to None. + level (int, optional): Level of the log. Defaults to logging.INFO. + + Returns: + object : the result of the function + """ + if func is None: + return partial(UtilsMonitoring.measure_memory, level=level) + + @wraps(func) + def newfunc(*args, **kwargs): + name = func.__qualname__ + logger = logging.getLogger(__name__ + "." + name) + tracemalloc.start() + result = func(*args, **kwargs) + current, peak = tracemalloc.get_traced_memory() + msg = f""" + \033[37mFunction Name :\033[35;1m {func.__name__}\033[0m + \033[37mCurrent memory usage:\033[36m {current / 10 ** 6}MB\033[0m + \033[37mPeak :\033[36m {peak / 10 ** 6}MB\033[0m + """ + logger.log(level, msg) + tracemalloc.stop() + return result + + return newfunc diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}.py new file mode 100644 index 0000000..014be10 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}.py @@ -0,0 +1,108 @@ +# {{cookiecutter.project_name}} - {{cookiecutter.project_short_description}} +# Copyright (C) {{cookiecutter.year}} - {{cookiecutter.institute}} ({{cookiecutter.full_name}} for {{cookiecutter.consortium_name}}) +# +# This file is part of {{cookiecutter.project_name}}. +# +# {{cookiecutter.project_name}} is free software: you can redistribute it and/or modify +# it under the terms of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# {{cookiecutter.project_name}} is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} for more details. +# +# You should have received a copy of the {% if cookiecutter.open_source_license == 'GNU General Public License v3' -%}GNU General Public License{% elif cookiecutter.open_source_license == 'GNU Lesser General Public License v3' -%}GNU Lesser General Public License v3 {% elif cookiecutter.open_source_license == 'GNU Affero General Public License v3' -%}GNU Affero General Public License v3{% endif %} +# along with {{cookiecutter.project_name}}. If not, see . +"""This module contains the library.""" +import logging +import configparser +import uvicorn # type: ignore +from fastapi import FastAPI + +from ._version import __name_soft__ +from .config import openapi_config +from .initializer import init + +logger = logging.getLogger(__name__) + + +class {{cookiecutter.project_class_lib}}: + """The library""" + + def __init__(self, path_to_conf: str, directory: str, *args, **kwargs): + # pylint: disable=unused-argument + if "level" in kwargs: + {{cookiecutter.project_class_lib}}._parse_level(kwargs["level"]) + + self.__directory = directory + self.__config = configparser.ConfigParser() + self.__config.optionxform = str # type: ignore + self.__config.read(path_to_conf) + self.__app = FastAPI( + itle=openapi_config.name, + version=openapi_config.version, + description=openapi_config.description, + ) + + @staticmethod + def _parse_level(level: str): + """Parse level name and set the rigt level for the logger. + If the level is not known, the INFO level is set + + Args: + level (str): level name + """ + logger_main = logging.getLogger(__name_soft__) + if level == "INFO": + logger_main.setLevel(logging.INFO) + elif level == "DEBUG": + logger_main.setLevel(logging.DEBUG) + elif level == "WARNING": + logger_main.setLevel(logging.WARNING) + elif level == "ERROR": + logger_main.setLevel(logging.ERROR) + elif level == "CRITICAL": + logger_main.setLevel(logging.CRITICAL) + elif level == "TRACE": + logger_main.setLevel(logging.TRACE) # type: ignore # pylint: disable=no-member + else: + logger_main.warning( + "Unknown level name : %s - setting level to INFO", level + ) + logger_main.setLevel(logging.INFO) + + @property + def config(self) -> configparser.ConfigParser: + """The configuration file. + + :getter: Returns the configuration file + :type: configparser.ConfigParser + """ + return self.__config + + @property + def directory(self) -> str: + """The output directory. + + :getter: Returns the output directory + :type: str + """ + return self.__directory + + @property + def app(self) -> FastAPI: + """The fast API app. + + :getter: Returns the Fast API app + :type: FastAPI + """ + return self.__app + + def start(self): + """Starts the server.""" + logger.info("Starting application initialization...") + init(self.app) + logger.info("Successfully initialized!") + uvicorn.run(self.app, host="0.0.0.0", port=8080)