Skip to content

Commit

Permalink
Bringing project up to speed with changes (#28)
Browse files Browse the repository at this point in the history
* Using Black in project and rendered project but docs said YAPF.
* Updating docs and requirement specs to point to black
  for formatting Python code
* Fixing lint errors in hooks scripts
* Setting line length limits for flake8 to be 88
* Removing .yapfignore as yapf is no longer used
* Updating .gitignore file
* Fixing tests to use project_path
* pytest cookie plugin is deprecating project from result context
* adjusting code to the new context as needed
* [pre-commit.ci] auto fixes from pre-commit.com hooks
* Fixing issues found by deepsource
* Moving test workflow to Python setup
* Using GitHub action Python setup
* Invoking tox after each Python version is setup
* Adding pip install tox and upgrade pip

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
komailo and pre-commit-ci[bot] committed Feb 8, 2022
1 parent 42fe503 commit 5d5d018
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 87 deletions.
68 changes: 38 additions & 30 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
---
name: tests

on: # yamllint disable-line rule:truthy
push:
branches: [master]
pull_request:
branches: [master]
on: # yamllint disable-line rule:truthy
push:
branches: [master]
pull_request:
branches: [master]

jobs:
cookie:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
if: ${{ always() }}
- name: Run tox based tests
uses: fedora-python/tox-github-action@v0.4
with:
tox_env: ${{ matrix.tox_env }}
if: ${{ always() }}
strategy:
matrix:
tox_env: [py36, py37, py38, py39]
cookie:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Run tox based tests on py${{ matrix.python-version }}
run: |
pip install tox
pip install --upgrade pip
tox -e $(echo "py${{ matrix.python-version }}" | tr -d ".")
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]

doc:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
if: ${{ always() }}
- name: Run tox based tests
uses: fedora-python/tox-github-action@v0.4
with:
tox_env: docs
if: ${{ always() }}
doc:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
architecture: x64
- name: Run tox based tests
run: |
pip install tox
pip install --upgrade pip
tox -e docs
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ __pycache__/
*$py.class

# Pytest files and directories
/.pytest_tmp/
/.pytest_cache/

# IDE files and directories
/.vscode/
/.vs/

# Cookiecutter baking directory
/.baked/

# Docs build directory
/docs/_build/

# Build Directory
/build/
4 changes: 0 additions & 4 deletions .yapfignore

This file was deleted.

4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The following features apply to the template project of this Cookiecutter:
* Tox testing: Test against multiple Python versions (3.6+)
* Development: Easily setup a development environment using Tox
* Makefile: Predefined make rules to build, test, lint and deploy
* YAPF_ Formatting: Have your Python code formatted in a consistent manner
* Black_ Formatting: Have your Python code formatted in a consistent manner

Quickstart
==========
Expand Down Expand Up @@ -147,5 +147,5 @@ the Git repository in your templated project later by doing:
git push
.. _Cookiecutter: https://github.com/cookiecutter/cookiecutter
.. _YAPF: https://github.com/google/yapf
.. _Black: https://github.com/psf/black
.. _setup.py: ../../{{cookiecutter.project_slug}}/setup.py
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"install_requires": "",
"project_extra_dev_requires": "pre-commit",
"project_extra_test_requires": "coverage, pytest, pytest-cov, safety",
"project_extra_lint_requires": "flake8, pylint, yamllint, yapf",
"project_extra_lint_requires": "flake8, pylint, yamllint, black",
"project_license": [
"BSD-3-Clause",
"Proprietary"
Expand Down
2 changes: 1 addition & 1 deletion docs/global.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.. _Cookiecutter: https://github.com/cookiecutter/cookiecutter
.. _YPAF: https://github.com/google/yapf
.. _Black: https://github.com/psf/black
2 changes: 1 addition & 1 deletion docs/users_guide/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ the Git repository in your templated project later by doing:
git push
.. _Cookiecutter: https://github.com/cookiecutter/cookiecutter
.. _YPAF: https://github.com/google/yapf
.. _black: https://github.com/psf/black
10 changes: 7 additions & 3 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import shutil
import subprocess
import sys
from collections import OrderedDict # noqa pylint: disable=unused-import
from collections import OrderedDict

PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)

Expand All @@ -36,7 +36,9 @@ def git_commit():
"""
Commit the staged changes in the generated project.
"""

cookiecutter_config = (
OrderedDict()
) # We init the variable to the same type that will be set in the next line.
cookiecutter_config = {{cookiecutter}} # noqa pylint: disable=undefined-variable

cookiecutter_config_str = ""
Expand Down Expand Up @@ -121,7 +123,9 @@ def set_license():
shutil.rmtree(os.path.join(project_directory, "LICENSES"))

# Add the title to the LICENSE.rst file
with open(os.path.join(project_directory, "LICENSE.rst"), "r+") as license_fp:
with open(
os.path.join(project_directory, "LICENSE.rst"), "r+", encoding="utf8"
) as license_fp:
content = license_fp.read()
license_fp.seek(0, 0)
license_fp.write("LICENSE\n#######" + "\n" + content)
Expand Down
12 changes: 4 additions & 8 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def check_python_min_max_versions():
elif str(project_python_max_version) not in project_valid_python_versions:
print(
(
"** ERROR: Invalid value provided for"
' "project_python_max_version"'
'** ERROR: Invalid value provided for "project_python_max_version"'
f" {project_python_max_version}."
f" Expecting on of: {project_valid_python_versions}"
)
Expand All @@ -49,12 +48,9 @@ def check_python_min_max_versions():

if project_python_min_version > project_python_max_version:
print(
(
'** ERROR: "project_python_min_version" (%s) has to be greater'
' than or equal to "project_python_max_version" (%s)'
)
% project_python_min_version,
project_python_max_version,
f'** ERROR: "project_python_min_version" {project_python_min_version} has'
' to be greater than or equal to "project_python_max_version"'
f" {project_python_max_version}"
)
sys.exit(1)

Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.black]
extend-exclude = '{{cookiecutter.project_slug}}'
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length=88
2 changes: 1 addition & 1 deletion tests/cookiecutter_test_user_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ default_context:
project_source_url: https://google.com/
project_doc_url: https://google.com/
install_requires: ''
project_extra_dev_requires: yapf
project_extra_dev_requires: black
project_extra_test_requires: coverage, flake8, pylint, pytest, pytest-cov
project_license: BSD-3-Clause
project_python_max_version: '3.9'
Expand Down
8 changes: 4 additions & 4 deletions tests/test_code_of_conduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
def test_code_of_conduct_file(cookies):
"Test that the CODE_OF_CONDUCT.md file exists and the content is valid"
with bake_cookie(cookies) as result:
code_of_conduct_path = result.project.join("CODE_OF_CONDUCT.rst")

code_of_conduct_path = result.project_path.joinpath("CODE_OF_CONDUCT.rst")
cookiecutter_json = load_cookiecutter_json()
assert os.path.exists(code_of_conduct_path)

code_of_conduct = result.project.join("CODE_OF_CONDUCT.rst").read()
cookiecutter_json = load_cookiecutter_json()
with open(code_of_conduct_path, "r") as fp:
code_of_conduct = fp.read()

assert str(cookiecutter_json["project_author_email"]) in code_of_conduct
9 changes: 5 additions & 4 deletions tests/test_git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
def test_git_repo_is_clean(cookies):
"Check that Git repo does not have any files not committed"
with bake_cookie(cookies) as result:
assert result.project.isdir()
repo = git.Repo(result.project)
assert result.project_path.is_dir()
repo = git.Repo(result.project_path)
assert not repo.bare
assert not repo.is_dirty(untracked_files=True)


def test_no_git_repo(cookies):
"Check that Git repo is not created when the option is False"
with bake_cookie(cookies, extra_context={"initialize_git_repo": "no"}) as result:
assert result.project.isdir()
print(dir(result.project_path))
assert result.project_path.is_dir()
with pytest.raises(git.exc.InvalidGitRepositoryError):
git.Repo(result.project)
git.Repo(result.project_path)
23 changes: 14 additions & 9 deletions tests/test_license_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
def test_license_file_exists(cookies):
"Check that the LICENSE file exists"
with bake_cookie(cookies) as result:
license_file_path = result.project.join("LICENSE.rst")
license_file_path = result.project_path.joinpath("LICENSE.rst")
assert os.path.exists(license_file_path)


def test_licenses_dir_not_present(cookies):
"Check that the LICENSES dir is removed"
with bake_cookie(cookies) as result:
licenses_dir_path = result.project.join("LICENSES")
licenses_dir_path = result.project_path.joinpath("LICENSES")
assert not os.path.exists(licenses_dir_path)


Expand All @@ -30,17 +30,22 @@ def test_bake_selecting_license(cookies):

for license in supported_licenses:
with bake_cookie(cookies, extra_context={"project_license": license}) as result:
license_file_path = result.project_path.joinpath("LICENSE.rst")

with open(license_file_path, "r") as fp:
license_file = fp.read()
license_file_lines = license_file.splitlines()

if license == "Proprietary":
assert (
"All rights reserved."
in result.project.join("LICENSE.rst").readlines()[3]
)
assert "All rights reserved." in license_file_lines[3]
else:
assert license in result.project.join("LICENSE.rst").readlines()[2]
assert license in license_file_lines[2]

assert f"license = {license}" in result.project.join("setup.cfg").read()
assert (
f"license = {license}"
in result.project_path.joinpath("setup.cfg").read_text()
)

license_file = result.project.join("LICENSE.rst").read()
assert str("Cookie Baker") in license_file
assert str("baker@cookier.com") in license_file
assert str(now.year) in license_file
9 changes: 4 additions & 5 deletions tests/test_manifest_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
def test_manifest_file(cookies):
"Test that the MANIFEST.in file exists and the content is valid"
with bake_cookie(cookies) as result:
manifest_file_path = result.project.join("MANIFEST.in")
manifest_file_path = result.project_path.joinpath("MANIFEST.in")
cookiecutter_json = load_cookiecutter_json()

assert os.path.exists(manifest_file_path)

manifest_file = result.project.join("MANIFEST.in").read()
cookiecutter_json = load_cookiecutter_json()

assert str(cookiecutter_json["project_slug"]) in manifest_file
with open(manifest_file_path, "r") as fp:
assert str(cookiecutter_json["project_slug"]) in fp.read()
2 changes: 1 addition & 1 deletion tests/test_readme_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
def test_readme_file_exists(cookies):
"Test that the README.md file exists"
with bake_cookie(cookies) as result:
readme_file_path = result.project.join("README.md")
readme_file_path = result.project_path.joinpath("README.md")
assert os.path.exists(readme_file_path)
6 changes: 3 additions & 3 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

def test_bake_and_run_tests(cookies):
with bake_cookie(cookies) as result:
assert result.project.isdir()
subprocess_in_dir("python setup.py test", str(result.project)) == 0
print("python setup.py test", str(result.project))
assert result.project_path.is_dir()
print("python setup.py test", str(result.project_path))
subprocess_in_dir("python setup.py test", str(result.project_path))
6 changes: 3 additions & 3 deletions tests/test_sphinx_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

def test_doc_tox_env(cookies):
with bake_cookie(cookies) as result:
assert result.project.isdir()
assert result.project_path.is_dir()
subprocess_in_dir(
"tox -e docs --workdir .tox",
str(result.project),
) == 0
str(result.project_path),
)
9 changes: 4 additions & 5 deletions {{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ it by invoking `pip install tox`.

### Style Guidelines

* This project follows
[Google Python Style Guide](http://google.github.io/styleguide/pyguide.html).
* Using [yapf](https://github.com/google/yapf/) the code should be formatted to
ensure consistent code structure between developers. The `yapf` make rule can
be used to format the code by running `make yapf`.
* This project uses [Black](https://github.com/psf/black) to format Python code.
* Using `black` the code should be formatted to ensure consistent code structure between
developers. The `black` make rule can be used to format the code by running
`make black`.

### Testing

Expand Down

0 comments on commit 5d5d018

Please sign in to comment.