Skip to content

Commit

Permalink
Use src for Python source directory
Browse files Browse the repository at this point in the history
`src` is a blessed project layout directory for source files, and most
tools support it.

This layout also decreases complexity in the Makefile.

Module and namespace directories will go inside it.
  • Loading branch information
ekilmer committed Nov 3, 2023
1 parent 47716ad commit b41ba1c
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: |
cookiecutter --no-input -o /tmp .
[[ -d /tmp/python-project/python_project ]] || { >&2 echo "not generated?"; exit 1; }
[[ -d /tmp/python-project/src/python_project ]] || { >&2 echo "not generated?"; exit 1; }
cd /tmp/python-project
make dev
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
run: |
cookiecutter --no-input -o /tmp . project_namespace_import=tob.r_and_e
[[ -d /tmp/tob-r-and-e-python-project/tob/r_and_e/python_project ]] || { >&2 echo "not generated?"; exit 1; }
[[ -d /tmp/tob-r-and-e-python-project/src/tob/r_and_e/python_project ]] || { >&2 echo "not generated?"; exit 1; }
cd /tmp/tob-r-and-e-python-project
make dev
Expand All @@ -68,7 +68,7 @@ jobs:
run: |
cookiecutter --no-input -o /tmp . project_namespace_import=tob.r_and_e "project_name=Bit Trails" project_slug=bit-trails
[[ -d /tmp/bit-trails/tob/r_and_e/bit_trails ]] || { >&2 echo "not generated?"; exit 1; }
[[ -d /tmp/bit-trails/src/tob/r_and_e/bit_trails ]] || { >&2 echo "not generated?"; exit 1; }
cd /tmp/bit-trails
make dev
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"__project_namespace_slug": "{{ cookiecutter.project_namespace_import.replace('_', '-').replace('.', '-') }}",
"project_slug": "{{ (cookiecutter.__project_namespace_slug + '-' if cookiecutter.project_namespace_import else '') + cookiecutter.__module_slug }}",
"__project_import": "{{ (cookiecutter.project_namespace_import + '.' if cookiecutter.project_namespace_import else '') + cookiecutter.__module_import }}",
"__project_src_path": "{{ cookiecutter.__project_import.replace('.', '/') }}",
"__project_src_path": "src/{{ cookiecutter.__project_import.replace('.', '/') }}",
"project_description": "",
"repo_type": [
"CLI",
Expand Down
2 changes: 1 addition & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
os.getcwd(), "{{ cookiecutter.__project_src_path }}"
)
if not os.path.exists(namespace_project_dir):
module_dir = os.path.join(os.getcwd(), "{{ cookiecutter.__module_import }}")
module_dir = os.path.join(os.getcwd(), "src", "{{ cookiecutter.__module_import }}")
os.makedirs(namespace_project_dir)
os.rename(module_dir, os.path.join(namespace_project_dir))
3 changes: 1 addition & 2 deletions {{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
SHELL := /bin/bash

PY_SRC_DIR = {{ cookiecutter.__project_src_path }}
PY_IMPORT = {{ cookiecutter.__project_import }}

ALL_PY_SRCS := $(shell find $(PY_SRC_DIR) -name '*.py') \
ALL_PY_SRCS := $(shell find src -name '*.py') \
$(shell find test -name '*.py')

# Optionally overriden by the user, if they're using a virtual environment manager.
Expand Down
1 change: 1 addition & 0 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ line-length = 100
omit = ["{{ cookiecutter.__project_src_path }}/_cli.py"]

[tool.mypy]
mypy_path = "src"
packages = "{{ cookiecutter.__project_import }}"
allow_redefinition = true
check_untyped_defs = true
Expand Down

0 comments on commit b41ba1c

Please sign in to comment.