Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Pre-commit linter

on:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout the current repo
uses: actions/checkout@v3

- name: Cache pre-commit and Python virtual environment
id: pre-commit-cache-restore
uses: actions/cache@v3
with:
path: |
.git/hooks/pre-commit
py3_yagro_venv
key: ${{ runner.os }}-lint-${{ hashFiles('**/.pre-commit-config.yaml') }}

- name: Install pre-commit and all of the necessary hooks
run: |
python -m venv py3_yagro_venv
source py3_yagro_venv/bin/activate

pip install pre-commit
pre-commit install --install-hooks

- name: Run pre-commit hooks
run: |
source py3_yagro_venv/bin/activate
pre-commit run --show-diff-on-failure --all-files
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ cython_debug/
.vscode/
.ruff_cache/
changelog.json
.idea
.idea
103 changes: 103 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
default_language_version:
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Copy link
Owner

@pydanny pydanny Oct 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add hook to exclude cookiecutter.json from the linting process.

- id: check-merge-conflict
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- id: check-case-conflict
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- id: check-symlinks
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- id: end-of-file-fixer
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- id: trailing-whitespace
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- id: check-ast
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)
- id: debug-statements
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- id: check-json
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- id: pretty-format-json
args:
- --autofix
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- id: check-yaml
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- id: detect-private-key
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
types:
- file
- python
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
hooks:
- id: ruff
exclude: >
(?x)(
^{{cookiecutter.slug}}/
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ TODO finish this section
</a>
</td></tr>
</table>
<!-- readme: contributors -end -->
<!-- readme: contributors -end -->
22 changes: 16 additions & 6 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
{
"full_name": "Daniel Roy Greenfeld",
"__gh_slug": "{{ cookiecutter.github_username }}/{{ cookiecutter.slug }}",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug which will cause Cookiecutter to behave erratically or throw an error. This is because the __gh_slug element requires earlier items.

"command_line_interface": [
"No",
"Yes"
],
"email": "[email protected]",
"full_name": "Daniel Roy Greenfeld",
"github_username": "pydanny",
"license": [
"MIT",
"BSD",
"ISC",
"Apache Software License 2.0",
"GNU General Public License v3",
"Not open source"
],
"project_name": "Python Boilerplate",
"slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
"__gh_slug": "{{ cookiecutter.github_username }}/{{ cookiecutter.slug }}",
"project_short_description": "Python Boilerplate contains all the boilerplate you need to create a Python package.",
"pypi_username": "{{ cookiecutter.github_username }}",
"command_line_interface": ["No", "Yes"],
"version": "0.1.0",
"license": ["MIT", "BSD", "ISC", "Apache Software License 2.0", "GNU General Public License v3", "Not open source"]
"slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
"version": "0.1.0"
}
8 changes: 4 additions & 4 deletions docs/alternatives.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

What inspired **Simplicity**, how it compares to other alternatives and what it learned from them.

## Intro
## Intro

**Simplicity** wouldn't exist if not for the previous work of others.

Expand All @@ -16,12 +16,12 @@ This is the progenitor of Python package templates, designed to work for everyon

### cookiecutter-django

I started this project with the intention of building a tool that works for everyone. It taught me to not accept PRs or work from people bringing in new tech I don't understand without a history with me of maintaining their efforts.
I started this project with the intention of building a tool that works for everyone. It taught me to not accept PRs or work from people bringing in new tech I don't understand without a history with me of maintaining their efforts.

### Pipenv

The lesson of pipenv (and some other tools) is that pip, venv, and other "standard" tools are good foundations to build on.
The lesson of pipenv (and some other tools) is that pip, venv, and other "standard" tools are good foundations to build on.

### Poetry

Sometimes it's good to go off in your own direction, to reinvent the wheel. Poetry taught me to be okay with reinventing the wheel of package templating one more time.
Sometimes it's good to go off in your own direction, to reinvent the wheel. Poetry taught me to be okay with reinventing the wheel of package templating one more time.
2 changes: 1 addition & 1 deletion docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
6. Run `make changelog`
7. Use `git commit --amend` to add the just pulled release notes to the release commit
8. `git push --force`
9. Merge to main
9. Merge to main
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ allow_untyped_defs = true
disable_error_code = "attr-defined"

[tool.pytest.ini_options]
python_files = ["test_*.py"]
python_files = ["test_*.py"]

[tool.ruff]
exclude = ["build", "dist", "docs", "venv", ".tox", ".nox", ".venv", ".mypy_cache", ".pytest_cache", ".git", "__pycache__"]
line-length = 99
3 changes: 2 additions & 1 deletion src/simplicity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ruff: noqa: F401
__author__ = "Daniel Greenfeld"


from .legacy import rst_to_json, file_opener
from .legacy import file_opener, rst_to_json
3 changes: 2 additions & 1 deletion src/simplicity/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pathlib

import typer
from cookiecutter import main
from rich import print
import typer

from .legacy import rst_to_json as legacy_rst_to_json


app = typer.Typer()


Expand Down
4 changes: 2 additions & 2 deletions src/simplicity/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import warnings


# Python 3 compatibility
STRING_TYPE = str
DIVIDERS = ["~", "=", "-", "+", "_"]
Expand Down Expand Up @@ -40,7 +41,6 @@ def rst_to_json(text):

lines = text.splitlines()
for index, line in enumerate(lines):

# check for directives
if len(line) and line.strip().startswith(".."):
directive = True
Expand Down Expand Up @@ -70,7 +70,7 @@ def rst_to_json(text):
continue

# Work on multi-line strings
if len(line) and line[0].startswith(" ") and directive == False:
if len(line) and line[0].startswith(" ") and directive is False:
if not isinstance(data[key], str):
# Not a string so continue on
continue
Expand Down
16 changes: 8 additions & 8 deletions tests/legacy/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
simplicity
==========

Converts ReStructuredText into JSON.
Converts ReStructuredText into JSON.

* **Sections** are JSON list dictionary elements
* **Sections** are JSON list dictionary elements
* **Section Headers** become list titles.
* **Field** definitions become key/value representations.
* **Directives** are ignored.
Expand All @@ -20,12 +20,12 @@ Input
------
:age: 22
:typing: dynamic, strong
Java

Java
----
:age: 18
:typing: static, strong

Output

.. code-block:: JavaScript
Expand All @@ -34,7 +34,7 @@ Output
{"title": "Python", "age": 22, "typing": "dynamic, strong"}
{"title": "Java", "age": 18, "typing": "static, strong"}
]

Usage
------

Expand All @@ -45,7 +45,7 @@ Usage
$ python simplicity.py sample.rst
[
{
"description": "A fun programming language.\n\nUsed to build simplicity!",
"description": "A fun programming language.\n\nUsed to build simplicity!",
"title": "Python",
"price": 0.0,
"typing": "dynamic, strong",
Expand Down Expand Up @@ -83,4 +83,4 @@ Know of any other good uses for Simplicity? Let me know and I'll add it to the l
Examples
---------

* https://github.com/pydanny/simplicity-complexity-example
* https://github.com/pydanny/simplicity-complexity-example
4 changes: 2 additions & 2 deletions tests/legacy/sample.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Python

My favorite programming language. This line is ignored by simplicity.

Java
Java
----
:age: 18
:typing: static, strong
Expand All @@ -26,4 +26,4 @@ These are three code examples.
.. image:: https://nowhere.org/xxx.png
:target: https://nowhere.org/xxx-target/

More text
More text
2 changes: 1 addition & 1 deletion tests/legacy/sample2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ My Title (Sample ReST document)
.. image:: https://nowhere.org/xxx.png
:target: https://nowhere.org/xxx-target/

More text ...
More text ...
4 changes: 2 additions & 2 deletions tests/legacy/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# -*- coding: utf-8 -*-

import json
import warnings
import unittest
import warnings

import simplicity


# Python 3 compatibility
STRING_TYPE = str

Expand Down Expand Up @@ -83,6 +84,5 @@ def test_open(self):
self.assertEqual(text, simplicity.file_opener("tests/legacy/sample.rst"))



if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion utils/update_changelog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pathlib
import json
import pathlib


def main():
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pip install -e '.[test]'

### Code quality

```bash
```bash
make lint
```

Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.slug}}/docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
6. Run `make changelog`
7. Use `git commit --amend` to add the just pulled release notes to the release commit
8. `git push --force`
9. Merge to main
9. Merge to main
3 changes: 2 additions & 1 deletion {{cookiecutter.slug}}/src/{{cookiecutter.slug}}/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rich import print
import typer
from rich import print


app = typer.Typer()

Expand Down
Loading