poetry version

This commit is contained in:
Histausse 2023-05-15 13:23:02 +02:00
commit 2b7362c2f4
12 changed files with 319 additions and 0 deletions

21
README.md Normal file
View file

@ -0,0 +1,21 @@
# Python template
A template for python project using [cookicutter](https://github.com/cookiecutter/cookiecutter).
## Cookicutter config
A good config to have for cookicutter at `~/.cookiecutterrc`:
```
abbreviations:
pp: https://git.pains-perdus.fr/templates/{}.git
default_context:
full_name: "Jane Doe"
email: "jane.doe@example.com"
git_user: "jdoe"
gitea_url: "https://git.pains-perdus.fr"
```
To create the project on gitea, cookie cutter needs the `giteapy` module and a gitea token. The token can be retrieved with the `secretstorage` by looking up the secret `"Title": "Gitea Token"`, or by prompting the user.

8
TODO.md Normal file
View file

@ -0,0 +1,8 @@
# TODO:
- edit readme to use poetry
- tests
- add AGPL
- add CI
- add flake
- use bool value for `generate_gitea_project` when the feature is available

15
cookiecutter.json Normal file
View file

@ -0,0 +1,15 @@
{
"project_name": "",
"project_short_description": "",
"full_name": "",
"email": "",
"git_user": "",
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
"gitea_url": "",
"project_url": "{{ cookiecutter.gitea_url }}/{{ cookiecutter.git_user }}/{{ cookiecutter.project_slug }}",
"generate_gitea_project": [ true, false ],
"git_origin": "{{ cookiecutter.gitea_url.replace('https://', 'gitea@').replace('http://', 'gitea') }}:{{ cookiecutter.git_user }}/{{ cookiecutter.project_slug }}.git",
"version": "0.1.0",
"open_source_license": ["GNU General Public License v3", "MIT license", "BSD license", "ISC license", "Apache Software License 2.0", "Proprietary"],
"python_min_version": "3.10"
}

50
hooks/post_gen_project.py Normal file
View file

@ -0,0 +1,50 @@
import subprocess
subprocess.call(["git", "init"])
subprocess.call(["git", "checkout", "-b", "main"])
subprocess.call(["git", "add", "*"])
subprocess.call(["git", "commit", "-m", "Initial commit"])
subprocess.call(["git", "config", "user.name", "{{ cookiecutter.git_user }}"])
subprocess.call(["git", "config", "user.email", "{{ cookiecutter.email }}"])
#subprocess.call(["python", "-m", "venv", "venv"])
if {{cookiecutter.generate_gitea_project}}:
try:
import giteapy
except ModuleNotFoundError:
print("giteapy is not availabled, repository not created")
exit()
try:
import secretstorage
connection = secretstorage.dbus_init()
collection = secretstorage.get_default_collection(connection)
collection.unlock()
secret = collection.search_items({"Title": "Gitea Token"}).__next__()
secret.unlock()
API_KEY = secret.get_secret().decode("utf-8")
except (ModuleNotFoundError, StopIteration):
try:
import getpass
my_input = getpass.getpass
except ModuleNotFoundError:
my_input = input
API_KEY = my_input(
"Secret service or secret {'Title': 'Gitea Token'} not available,"
"please enter you gitea api token:"
)
configuration = giteapy.Configuration()
configuration.api_key["access_token"] = API_KEY
client = giteapy.ApiClient(configuration)
client.configuration.host = "{{ cookiecutter.gitea_url }}/api/v1"
api_instance = giteapy.AdminApi(client)
username = "{{ cookiecutter.git_user }}"
repo = giteapy.CreateRepoOption(
name="{{ cookiecutter.project_slug }}", private=True
)
api_instance.admin_create_repo(username, repo)
subprocess.call(["git", "remote", "add", "origin", "{{ cookiecutter.git_origin }}"])
subprocess.call(["git", "push", "-u", "origin", "master"])

View file

@ -0,0 +1,32 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# virtualenv
venv/
# mypy
.mypy_cache/

View file

@ -0,0 +1,111 @@
{% if cookiecutter.open_source_license == 'MIT license' -%}
MIT License
Copyright (c) {% now 'local', '%Y' %}, {{ cookiecutter.full_name }}
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
{% elif cookiecutter.open_source_license == 'BSD license' %}
BSD License
Copyright (c) {% now 'local', '%Y' %}, {{ cookiecutter.full_name }}
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
{% elif cookiecutter.open_source_license == 'ISC license' -%}
ISC License
Copyright (c) {% now 'local', '%Y' %}, {{ cookiecutter.full_name }}
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
{% elif cookiecutter.open_source_license == 'Apache Software License 2.0' -%}
Apache Software License 2.0
Copyright (c) {% now 'local', '%Y' %}, {{ cookiecutter.full_name }}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{% elif cookiecutter.open_source_license == 'GNU General Public License v3' -%}
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
{{ cookiecutter.project_short_description }}
Copyright (C) {% now 'local', '%Y' %} {{ cookiecutter.full_name }}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
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 GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
{% endif %}

View file

@ -0,0 +1,46 @@
{% set is_open_source = cookiecutter.open_source_license != 'Proprietary' -%}
# {{ cookiecutter.project_name }}
{{ cookiecutter.project_short_description }}
## Install
This project can be installed using pip:
```
pip install git+{{ cookiecutter.project_url }}.git
```
{% if is_open_source %}
## License
This project if a free software released under the {{ cookiecutter.open_source_license }}.
## Dev
If you want to tinker with this project, you can clone it and install it in editable mode:
```
git clone {{ cookiecutter.project_url }}.git
cd {{ cookiecutter.project_slug }}
python -m venv venv && source venv/bin/activate
pip install -e .[dev]
```
### Test
Tests are run using `pytest`:
```
pytest
```
{% endif %}
## Author
- {{ cookiecutter.full_name }}
## Security
If you discover a potential security issue in this project, please contact {{ cookiecutter.email }}.

View file

@ -0,0 +1,3 @@
# Reporting a Vulnerability
If you discover a potential security issue in this project, please contact {{ cookiecutter.email }}.

View file

@ -0,0 +1,22 @@
[tool.poetry]
name = "{{ cookiecutter.project_slug }}"
version = "{{ cookiecutter.version }}"
description = "{{ cookiecutter.project_short_description }}"
authors = ["{{ cookiecutter.full_name }} <{{ cookiecutter.email }}>"]
readme = "README.md"
homepage = "{{ cookiecutter.project_url }}"
repository = "{{ cookiecutter.project_url }}"
license = "{{ cookiecutter.open_source_license }}"
[tool.poetry.urls]
"Bug Tracker" = "{{ cookiecutter.project_url }}/issues"
[tool.poetry.dependencies]
python = "^3.10"
[tool.poetry.scripts]
{{ cookiecutter.project_slug }} = "{{ cookiecutter.project_slug }}.cli:main"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

View file

@ -0,0 +1,3 @@
__author__ = """{{ cookiecutter.full_name }}"""
__email__ = '{{ cookiecutter.email }}'
__version__ = '{{ cookiecutter.version }}'

View file

@ -0,0 +1,8 @@
import argparse
def main():
""" Console entrypoint for {{cookiecutter.project_slug}}."""
parser = argparse.ArgumentParser()
parser.add_argument('_', nargs='*')
args = parser.parse_args()
print("Hello word!")