Skip to content

Commit

Permalink
merge upstream changes to fork, use flat layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre committed May 6, 2024
1 parent 16c0220 commit 5ad91df
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 64 deletions.
2 changes: 1 addition & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def replace_contents(filepath):
remove_file("environment-dev.yml")

if "no" in "{{ cookiecutter.command_line_interface|lower }}":
cli_file = Path("{{ cookiecutter.project_slug }}").joinpath("cli.py")
cli_file = Path("src/{{ cookiecutter.project_slug }}").joinpath("cli.py")
remove_file(cli_file)

if "Not open source" == "{{ cookiecutter.open_source_license }}":
Expand Down
16 changes: 10 additions & 6 deletions tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def test_year_compute_in_license_file(cookies):
def project_info(result):
"""Get toplevel dir, project_slug, and project dir from baked cookies"""
assert result.exception is None
assert result.project.isdir()
assert result.project_path.is_dir()

project_path = str(result.project)
project_slug = os.path.split(project_path)[-1]
project_dir = os.path.join(project_path, project_slug)
project_path = result.project_path
project_slug = project_path.name
project_dir = project_path.joinpath("src").joinpath(project_slug)
return project_path, project_slug, project_dir


Expand All @@ -82,9 +82,13 @@ def test_bake_with_defaults(cookies):
assert result.exception is None

found_toplevel_files = [f.name for f in result.project_path.iterdir()]
assert "LICENSE" in found_toplevel_files
assert "Makefile" in found_toplevel_files
assert "README.rst" in found_toplevel_files
assert "environment-dev.yml" in found_toplevel_files
assert "pyproject.toml" in found_toplevel_files
assert "python_boilerplate" in found_toplevel_files
assert "src" in found_toplevel_files
assert "python_boilerplate" in next(result.project_path.joinpath("src").iterdir()).name
assert "tests" in found_toplevel_files
assert "tox.ini" in found_toplevel_files

Expand Down Expand Up @@ -295,7 +299,7 @@ def test_bake_with_no_console_script(cookies):
assert "[project.scripts]" not in setup_file.read()


@pytest.mark.parametrize("option", ["Click", "Argparse"])
@pytest.mark.parametrize("option", ["Click", "Argparse", "Typer"])
def test_bake_with_console_options_script_files(cookies, option):
context = {"command_line_interface": option}
result = cookies.bake(
Expand Down
1 change: 0 additions & 1 deletion {{cookiecutter.project_slug}}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,3 @@ ENV/
# IDE settings
.vscode/
.idea/

15 changes: 5 additions & 10 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ authors = [
maintainers = [
{name = "{{ cookiecutter.full_name.replace('\"', '\\\"') }}", email = "{{ cookiecutter.email }}"}
]
maintainers = []
readme = {file = "README.rst", content-type = "text/x-rst"}
requires-python = ">=3.8.0"
keywords = ["{{ cookiecutter.project_slug }}"]
Expand Down Expand Up @@ -60,7 +59,7 @@ dev = [
"tox >=4.5.1",
"coverage >=7.0.0",
"coveralls >=3.3.1",
"mypy"
"mypy",
{%- if cookiecutter.use_pytest == 'y' %}
"pytest >=7.3.1",
"pytest-cov >=4.0.0",
Expand Down Expand Up @@ -93,10 +92,10 @@ docs = [
"jupyter_client"
]
{%- endif %}
{%- if cookiecutter.command_line_interface != "No command-line interface" %}

{%- if cookiecutter.command_line_interface != 'No command-line interface' %}
[project.scripts]
{{ cookiecutter.project_slug }} = "{{ cookiecutter.project_slug }}.cli:cli"
{{cookiecutter.project_slug}} = "{{cookiecutter.project_slug}}.cli:app"
{%- endif %}

[project.urls]
Expand All @@ -107,11 +106,6 @@ docs = [
"changelog" = "https://github.com/{{ cookiecutter.__gh_slug }}/blob/main/changelog.rst"
"homepage" = "https://github.com/{{ cookiecutter.__gh_slug }}"

{% if cookiecutter.command_line_interface == 'Yes' %}
[project.scripts]
{{cookiecutter.slug}} = "{{cookiecutter.slug}}.cli:app"
{% endif %}

[tool]
{%- if cookiecutter.use_black == 'y' %}

Expand Down Expand Up @@ -306,7 +300,8 @@ no-lines-before = ["future", "standard-library"]
max-complexity = 15

[tool.ruff.lint.per-file-ignores]
"{{ cookiecutter.project_slug }}/**/__init__.py" = ["F401", "F403"]
"docs/**" = ["E402"]
"src/{{ cookiecutter.project_slug }}/**/__init__.py" = ["F401", "F403"]

[tool.ruff.lint.pycodestyle]
max-doc-length = 180
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
"""Console script for {{cookiecutter.project_slug}}."""
import {{cookiecutter.project_slug}}
{% if cookiecutter.command_line_interface|lower == 'argparse' -%}
import argparse
import sys

def main():
"""Console script for {{cookiecutter.project_slug}}."""
parser = argparse.ArgumentParser()
parser.add_argument('_', nargs='*')
args = parser.parse_args()

print("Arguments: " + str(args._))
print("Replace this message by putting your code into "
"{{cookiecutter.project_slug}}.cli.main")
return 0


if __name__ == "__main__":
sys.exit(main()) # pragma: no cover

{%- elif cookiecutter.command_line_interface|lower == 'click' -%}
import sys

import click


@click.command()
def main(args=None):
"""Console script for {{cookiecutter.project_slug}}."""
click.echo(
"Replace this message by putting your code into {{cookiecutter.project_slug}}.cli.main"
)
click.echo("See click documentation at https://click.palletsprojects.com/")
return 0

if __name__ == "__main__":
sys.exit(main()) # pragma: no cover
{%- elif cookiecutter.command_line_interface|lower == 'typer' %}
import typer
from rich.console import Console

Expand All @@ -11,11 +46,12 @@
@app.command()
def main():
"""Console script for {{cookiecutter.project_slug}}."""
console.print("Replace this message by putting your code into "
"{{cookiecutter.project_slug}}.cli.main")
console.print(
"Replace this message by putting your code into {{cookiecutter.project_slug}}.cli.main"
)
console.print("See Typer documentation at https://typer.tiangolo.com/")



if __name__ == "__main__":
app()
{%- endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""Tests for `{{ cookiecutter.project_slug }}` package."""

import pathlib
import pkgutil
from importlib.util import find_spec
{% if cookiecutter.use_pytest == 'n' -%}
import unittest
{% else %}
Expand All @@ -12,7 +12,6 @@
{%- if cookiecutter.command_line_interface|lower == 'click' %}
from click.testing import CliRunner
{%- endif %}

{% if cookiecutter.command_line_interface|lower == 'click' %}import {{ cookiecutter.project_slug }}.cli as cli{%- endif %}
from {{ cookiecutter.project_slug }} import {{ cookiecutter.project_slug }} # noqa: F401
{%- if cookiecutter.use_pytest == 'y' %}
Expand Down Expand Up @@ -76,9 +75,15 @@ def test_command_line_interface(self):

def test_package_metadata():
"""Test the package metadata."""
project = pkgutil.get_loader("{{ cookiecutter.project_slug }}").get_filename()

metadata = pathlib.Path(project).resolve().parent.joinpath("__init__.py")
project = find_spec("{{ cookiecutter.project_slug }}").submodule_search_locations[0]

metadata = (
pathlib.Path(project)
.resolve()
.joinpath("src")
.joinpath("{{ cookiecutter.project_slug }}")
.joinpath("__init__.py")
)

with open(metadata) as f:
contents = f.read()
Expand Down
37 changes: 0 additions & 37 deletions {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/cli.py

This file was deleted.

0 comments on commit 5ad91df

Please sign in to comment.