Forráskód Böngészése

Generate project using cookiecutter template

Casper van der Wel 1 éve
commit
e80e10d95b

+ 12 - 0
.coveragerc

@@ -0,0 +1,12 @@
+[run]
+source = clean_python
+omit = test_*.py
+
+[report]
+show_missing = true
+
+[html]
+directory = htmlcov
+
+[xml]
+output = coverage.xml

+ 14 - 0
.cruft.json

@@ -0,0 +1,14 @@
+{
+  "template": "https://github.com/nens/cookiecutter-python-template",
+  "commit": "f70892c4590d8573425d333818c0333b1837ba79",
+  "checkout": null,
+  "context": {
+    "cookiecutter": {
+      "project_name": "clean-python",
+      "package_name": "clean_python",
+      "project_short_description": "Clean architecture in Python",
+      "_template": "https://github.com/nens/cookiecutter-python-template"
+    }
+  },
+  "directory": null
+}

+ 23 - 0
.github/workflows/lint.yml

@@ -0,0 +1,23 @@
+name: Lint
+
+on:
+  push:
+    branches:
+      - main
+    tags:
+      - '*'
+  pull_request:
+
+jobs:
+  lint:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+
+      - name: Set up Python
+        uses: actions/setup-python@v4
+        with:
+          python-version: "3.10"
+
+      - name: Run black, flake8, isort
+        uses: pre-commit/action@v3.0.0

+ 46 - 0
.github/workflows/test.yml

@@ -0,0 +1,46 @@
+name: Linux
+
+# Run on PR requests. And on master itself.
+on:
+  push:
+    branches:
+      - master
+  pull_request:
+
+jobs:
+  TestLinux:
+    name: Linux, Python ${{ matrix.python }}
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        include:
+          # 2019
+          - python: 3.8
+            pins: ""
+          # 2021
+          - python: 3.9
+            pins: ""
+          # 2022
+          - python: "3.10"
+            pins: ""
+          # current
+          - python: "3.11"
+            pins: ""
+
+    steps:
+      - uses: actions/checkout@v3
+
+      - name: Set up Python ${{ matrix.python }}
+        uses: actions/setup-python@v4
+        with:
+          python-version: ${{ matrix.python }}
+
+      - name: Install python dependencies
+        run: |
+          pip install --disable-pip-version-check --upgrade pip setuptools
+          pip install -e .[test] ${{ matrix.pins }}
+          pip list
+
+      - name: Run tests
+        run: pytest --cov

+ 38 - 0
.gitignore

@@ -0,0 +1,38 @@
+# Pyc/pyo/backup files.
+*.py[co]
+*~
+*.swp
+*.pyc
+
+# Packages/buildout/pip/pipenv
+*.egg
+*.egg-info
+sdist
+pip-log.txt
+bower_components/
+node_modules/
+.DS_Store
+doc/build/
+ansible/*.retry
+.venv
+bin/
+lib/
+pyvenv.cfg
+dist/
+var/
+
+# Unit test / coverage reports
+.coverage
+.tox
+nosetests.xml
+htmlcov
+.codeintel
+coverage.xml
+.pytest_cache
+
+# Pycharm, visual studio
+.idea
+.vscode
+
+# Docker
+docker-compose.override.yml

+ 28 - 0
.pre-commit-config.yaml

@@ -0,0 +1,28 @@
+default_language_version:
+  python: python3
+
+repos:
+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v4.4.0
+    hooks:
+      - id: trailing-whitespace
+      - id: end-of-file-fixer
+      - id: check-yaml
+      - id: check-toml
+      - id: check-added-large-files
+  - repo: https://github.com/pycqa/isort
+    rev: '5.12.0'
+    hooks:
+      - id: isort
+        exclude: 'settings'
+  - repo: https://github.com/psf/black
+    rev: '23.1.0'
+    hooks:
+      - id: black
+        exclude: 'migrations*|urls*|settings*'
+  - repo: https://github.com/pycqa/flake8
+    rev: '6.0.0'
+    hooks:
+      - id: flake8
+        # NB The "exclude" setting in setup.cfg is ignored by pre-commit
+        exclude: 'migrations*|urls*|settings*'

+ 7 - 0
CHANGES.md

@@ -0,0 +1,7 @@
+# Changelog of clean-python
+
+
+## 0.1 (unreleased)
+
+- Initial project structure created with cookiecutter and
+  [cookiecutter-python-template](https://github.com/nens/cookiecutter-python-template).

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright 2023 Nelen & Schuurmans <info@nelen-schuurmans.nl>.
+
+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.

+ 6 - 0
MANIFEST.in

@@ -0,0 +1,6 @@
+# Include docs in the root.
+include *.md
+include LICENSE
+# Exclude byte-compiled code
+global-exclude __pycache__
+global-exclude *.py[co]

+ 77 - 0
README.md

@@ -0,0 +1,77 @@
+# clean-python
+
+Introduction
+
+Usage, etc.
+
+## Installation
+
+We can be installed with:
+
+    $ pip install clean-python
+
+(TODO: after the first release has been made)
+
+
+## Development installation of this project itself
+
+We use python's build-in "virtualenv" to get a nice isolated
+directory. You only need to run this once:
+
+    $ python3 -m venv .
+
+A virtualenv puts its commands in the `bin` directory. So `bin/pip`,
+`bin/pytest`, etc. Set up the dependencies like this:
+
+    $ bin/pip install -e .[test]
+
+There will be a script you can run like this:
+
+    $ bin/run-clean-python
+
+It runs the `main()` function in `[clean-python/scripts.py`,
+adjust that if necessary. The script is configured in
+`TODO, MISSING NOW` (see `entry_points`).
+
+In order to get nicely formatted python files without having to spend
+manual work on it, get [pre-commit](https://pre-commit.com/) and install
+it on this project:
+
+    $ pre-commit install
+
+Run the tests regularly with coverage:
+
+    $ bin/pytest --cov
+
+The tests are also run automatically [on "github
+actions"](https://github.com/nens/clean-python/actions) for
+"main" and for pull requests. So don't just make a branch, but turn it into a
+pull request right away. On your pull request page, you also automatically get
+the feedback from the automated tests.
+
+If you need a new dependency (like `requests`), add it in
+`pyproject.toml` in `dependencies`. And update your local install with:
+
+    $ bin/pip install -e .[test]
+
+
+## Steps to do after generating with cookiecutter
+
+- Add a new project on <https://github.com/nens/> with the same name.  Think
+  about the visibility to ("public" / "private") and do not generate a
+  license or readme.
+
+  Note: "public" means "don't put customer data or sample data with real
+  persons' addresses on github"!
+
+- Follow the steps you then see (from "git init" to "git push origin main")
+  and your code will be online.
+
+- Go to
+  https://github.com/nens/>clean-python/settings/collaboration
+  and add the teams with write access (you might have to ask someone with
+  admin rights (like Reinout) to do it).
+
+- Update this readme.
+
+- Remove this section as you've done it all :-)

+ 3 - 0
clean_python/__init__.py

@@ -0,0 +1,3 @@
+# fmt: off
+__version__ = "0.1.dev0"
+# fmt: on

+ 47 - 0
clean_python/scripts.py

@@ -0,0 +1,47 @@
+"""TODO Docstring, used in the command line help text."""
+import argparse
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+def get_parser():
+    """Return argument parser."""
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument(
+        "-v",
+        "--verbose",
+        action="store_true",
+        dest="verbose",
+        default=False,
+        help="Verbose output",
+    )
+    # add arguments here
+    # parser.add_argument(
+    #     'path',
+    #     metavar='FILE',
+    # )
+    return parser
+
+
+def main():  # pragma: no cover
+    """Call main command with args from parser.
+
+    This method is called when you run 'bin/run-clean-python',
+    this is configured in 'setup.py'. Adjust when needed. You can have multiple
+    main scripts.
+
+    """
+    options = get_parser().parse_args()
+    if options.verbose:
+        log_level = logging.DEBUG
+    else:
+        log_level = logging.INFO
+    logging.basicConfig(level=log_level, format="%(levelname)s: %(message)s")
+
+    try:
+        print("Call some function from another file here")
+        # ^^^ TODO: pass in options.xyz where needed.
+    except:  # noqa: E722
+        logger.exception("An exception has occurred.")
+        return 1

+ 0 - 0
clean_python/tests/__init__.py


+ 10 - 0
clean_python/tests/test_scripts.py

@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+"""Tests for script.py"""
+from clean_python import scripts
+
+
+def test_get_parser():
+    parser = scripts.get_parser()
+    # As a test, we just check one option. That's enough.
+    options = parser.parse_args()
+    assert options.verbose is False

+ 46 - 0
pyproject.toml

@@ -0,0 +1,46 @@
+[project]
+name = "clean-python"
+description = "Clean architecture in Python"
+authors = [
+    {name = "Nelen & Schuurmans", email = "info@nelen-schuurmans.nl"},
+]
+readme = "README.md"
+license = {text = "MIT"}
+# Get classifier strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+classifiers = ["Programming Language :: Python"]
+keywords = []
+requires-python = ">=3.7"
+dependencies = []
+dynamic = ["version"]
+
+[project.optional-dependencies]
+test = [
+    "pytest",
+    "pytest-cov"
+]
+
+[project.urls]
+homepage = "https://github.com/nens/clean-python"
+
+[project.scripts]
+run-clean-python = "clean_python.scripts:main"
+
+[tool.setuptools]
+zip-safe = false
+
+[tool.setuptools.packages.find]
+include = ["clean_python*"]
+# package names should match these glob patterns (["*"] by default)
+
+[tool.setuptools.dynamic]
+version = {attr = "clean_python.__version__"}
+
+[tool.isort]
+profile = "black"
+force_alphabetical_sort_within_sections = true
+force_single_line = true
+
+[tool.pytest.ini_options]
+norecursedirs=".venv data doc etc *.egg-info misc var build lib include"
+python_files = "test_*.py"
+testpaths = "clean_python"

+ 7 - 0
setup.cfg

@@ -0,0 +1,7 @@
+[zest.releaser]
+release = no
+python-file-with-version = clean_python/__init__.py
+
+[flake8]
+max-line-length = 88
+ignore = E203, E266, E501, W503