Skip to content

Commit

Permalink
feat(template): Added hatchling as an option for build-system (#144)
Browse files Browse the repository at this point in the history
1. Activate option in TUI to hatchling
2. Adding documentation about hatchling
3. Adding hatchling as a build-system:
4. Creating a hatch-pyproject.toml
5. Editing post_gen_project.py
6. Creating a smoke test (build-system.sh)
7. Editing cookicutter.json
  • Loading branch information
ayeankit authored Jul 21, 2023
1 parent 76ee498 commit 32704a5
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ for a Python package.
systems like [Poetry](https://python-poetry.org/),
[Flit](https://flit.pypa.io),
[meson-python](https://meson-python.readthedocs.io/en/latest/index.html),
[Setuptools](https://setuptools.pypa.io/en/latest/) or
[PDM](https://pdm.fming.dev/)
[Setuptools](https://setuptools.pypa.io/en/latest/),
[PDM](https://pdm.fming.dev/) or
[Hatch](https://hatch.pypa.io)
based on your preference.
- The structure of the project can use the *src layout* or *flat
layout*. The “src layout” moving the code that is intended to be
Expand Down
12 changes: 11 additions & 1 deletion docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ packages. SciCookie support the following:
PEP 517 compilation backend, PEP 621 project metadata, a flexible and
powerful plugin system. It also offers, among other things, versatile
user scripting, PyPI integration and version management.


- [**Hatch**](https://hatch.pypa.io): It's a PEP 517/PEP 660 compatible
build backend used by Hatch, a modern, extensible Python project manager.
It provides a standardized build system with reproducible builds by default,
robust environment management with support for custom scripts, easy publishing
to PyPI or other indexes, version management, and configurable project generation
with sane defaults. Hatchling ensures that your builds are reproducible, so you
can be confident that they will always produce the same results. It also helps
you manage your Python environments, so you can be sure that your projects have
the correct dependencies.

The idea behind the options in SciCookie is that you can choose from some of the
most popular system compilers to suit your needs and preferences for developing
Python packages. If you think we should add more options, you can submit your
Expand Down
3 changes: 2 additions & 1 deletion src/scicookie/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"flit",
"mesonpy",
"setuptools",
"pdm"
"pdm",
"hatch"
],
"use_bandit": "yes",
"use_black": "no",
Expand Down
7 changes: 7 additions & 0 deletions src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
BUILD_SYSTEM = "setuptools"
{% elif cookiecutter.build_system == "pdm" -%}
BUILD_SYSTEM = "pdm"
{% elif cookiecutter.build_system == "hatch" -%}
BUILD_SYSTEM = "hatch"
{%- else %}
BUILD_SYSTEM = None
{%- endif %}
Expand Down Expand Up @@ -180,6 +182,11 @@ def clean_up_build_system():
build_system_dir / "pdm-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
elif BUILD_SYSTEM == "hatch":
shutil.move(
build_system_dir / "hatch-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
else:
shutil.move(
build_system_dir / "base-pyproject.toml",
Expand Down
1 change: 1 addition & 0 deletions src/scicookie/profiles/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ build_system:
- mesonpy
- setuptools
- pdm
- hatch
enabled: false

command_line_interface:
Expand Down
2 changes: 2 additions & 0 deletions src/scicookie/{{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ build:
python -m build
{%- elif cookiecutter.build_system == "pdm" %}
pdm build
{%- elif cookiecutter.build_system == "hatch" %}
hatch build
{%- endif %}

.PHONY:release-ci
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
[build-system]
requires = ["hatchling>=1.17.1"]
build-backend = "hatchling.build"

[project]
name = "{{ cookiecutter.project_slug }}"
authors = [
{ name = "{{ cookiecutter.author_full_name }}", email = "{{ cookiecutter.author_email }}" },
]
description = "{{ cookiecutter.project_short_description }}"
readme = "README.md"
classifiers = [
"Development Status :: 1 - Planning",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
{%- if cookiecutter.project_license == "MIT" %}
"License :: OSI Approved :: MIT License",
{%- elif cookiecutter.project_license == "BSD 3 Clause" %}
"License :: OSI Approved :: BSD License",
{%- elif cookiecutter.project_license == "Apache Software License 2.0" %}
"License :: OSI Approved :: Apache Software License",
{%- elif cookiecutter.project_license == "GNU General Public License v3" %}
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
{%- endif %}
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
"Typing :: Typed",
]
version = "{{ cookiecutter.project_version }}"
requires-python = ">=3.8.1"
dependencies = [
{# keep this line here #}
{%- if cookiecutter.use_pytest == "yes" -%}
"pytest >= 7.3.2",
{% if cookiecutter.use_coverage == "yes" -%}
"pytest-cov >= 4.1.0",
{% endif %}
{%- endif -%}{#- end of use_pytest -#}
{%- if cookiecutter.use_hypothesis == "yes" -%}
"hypothesis >= 6.0",
{% endif %}
{%- if cookiecutter.use_coverage == "yes" -%}
"coverage >= 7.2.7",
{% endif %}
{%- if cookiecutter.use_blue == "yes" -%}
"blue >= 0.9.1",
{% endif %}
{%- if cookiecutter.use_black == "yes" -%}
"black >= 23.3.0",
{% endif %}
{%- if cookiecutter.use_isort == "yes" -%}
"isort >= 5.12.0",
{% endif %}
{%- if cookiecutter.use_pre_commit -%}
"pre-commit >= 3.3.2",
{% endif %}
{%- if cookiecutter.use_flake8 == "yes" -%}
"flake8 >= 4.0.1, < 7",
{% endif %}
{%- if cookiecutter.use_ruff == "yes" -%}
"ruff >= 0.0.272",
{% endif %}
{%- if cookiecutter.use_mypy == "yes" -%}
"mypy >= 1.3.0",
{% endif %}
{%- if cookiecutter.use_bandit == "yes" -%}
"bandit >= 1.7.5",
{% endif %}
{%- if cookiecutter.use_pydocstyle == "yes" -%}
"pydocstyle >= 6.3.0",
{% endif %}
{%- if cookiecutter.use_vulture == "yes" -%}
"vulture >= 2.7",
{% endif %}
{%- if cookiecutter.use_mccabe == "yes" -%}
"mccabe >= 0.6.1",
{% endif %}
{%- if cookiecutter.use_containers in ['Docker', 'Podman'] -%}
# if you want to use docker-compose from your system, remove compose-go here
"compose-go >= 2.18.1",
{% endif %}
{%- if cookiecutter.documentation_engine == 'mkdocs' -%}
"Jinja2 >= 3.1.2",
"mkdocs >= 1.4.3",
"mkdocs-exclude >= 1.0.2",
"mkdocs-jupyter >= 0.24.1",
"mkdocs-literate-nav >= 0.6.0",
"mkdocs-macros-plugin >= 0.7.0, < 1",
"mkdocs-material >= 9.1.15",
"mkdocstrings >= 0.21.2",
"mkdocstrings-python >= 1.1.2",
{% elif cookiecutter.documentation_engine == 'sphinx' -%}
"Sphinx >= 6.2.1",
"sphinx-rtd-theme >= 1.2.2",
"importlib-metadata >= 6.5.1",
"myst-parser >= 0.19.2",
"nbsphinx >= 0.9.2",
"pandoc >= 2.3",
{% elif cookiecutter.documentation_engine == 'jupyter-book' -%}
"jupyter-book >= 0.15.1",
"myst-parser >= 0.18.1",
{% endif %}
]

[project.urls]
Homepage = "{{ cookiecutter.project_url }}"
"Bug Tracker" = "{{ cookiecutter.project_url }}/issues"
Discussions = "{{ cookiecutter.project_url }}/discussions"
Changelog = "{{ cookiecutter.project_url }}/releases"

[tool.hatch.version]
{# keep this line here #}
{%- if cookiecutter.project_layout == 'flat' -%}
path = "{{ cookiecutter.package_slug }}/__init__.py"
{% elif cookiecutter.project_layout == 'src' -%}
path = "src/{{ cookiecutter.package_slug }}/__init__.py"
{% endif %}

{% include "build-system/base-pyproject.toml" %}
{#- keep this line at the end of the file -#}
2 changes: 2 additions & 0 deletions src/scicookie/{{cookiecutter.project_slug}}/conda/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dependencies:
- build
{%- elif cookiecutter.build_system == "pdm" %}
- pdm
{%- elif cookiecutter.build_system == "hatch" %}
- hatch
{%- endif %}
- nodejs # used by semantic-release
- shellcheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ It provides an efficient and fast way to manage project dependencies, as
well as build and distribute code. It is fast to install, has built-in
virtualenv, offers support for different package sources, and provides
an easy way to distribute code.
[Hatch](https://hatch.pypa.io): It's a Python Package that is compatible build backend used by Hatch, a modern, extensible Python project manager. It provides a standardized build system with reproducible builds by default, robust environment management with support for custom scripts, easy publishing to PyPI or other indexes, version management, and configurable project generation with sane defaults. Hatchling might support multiple programming languages and offer language-specific options for building projects in different languages. It could also provide customization and extensibility options, allowing you to incorporate plugins or scripts for tailored build processes.

{%- endif %}

Expand Down
14 changes: 9 additions & 5 deletions tests/smoke/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export PATH=$(echo $PATH| sed -E "s/[^:]+\/micromamba\/[^:]+//g")
export PATH=$(echo $PATH| sed -E "s/[^:]+\/anaconda3\/[^:]+//g")
export PATH="${CONDA_PREFIX}:${CONDA_PREFIX}/bin:$PATH"
echo "[II] included env conda to the PATH"

COMMAND_PREFIX=
if command -v poetry &> /dev/null; then
poetry install
elif command -v flit &> /dev/null; then
Expand All @@ -49,17 +49,21 @@ elif command -v meson &> /dev/null; then
pip install -e .
elif command -v pdm &> /dev/null; then
pdm install
elif command -v hatch &> /dev/null; then
COMMAND_PREFIX="hatch run"

else
# use setuptools
pip install --editable .
fi

ipython kernel install --name "python3" --user
$COMMAND_PREFIX ipython kernel install --name "python3" --user

$COMMAND_PREFIX pre-commit install

pre-commit install
pre-commit run --all-files --verbose
$COMMAND_PREFIX pre-commit run --all-files --verbose

make docs-build
$COMMAND_PREFIX make docs-build
make build

export PATH=${PATH_ORI}
Expand Down
1 change: 1 addition & 0 deletions tests/smoke/build-system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ SMOKE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
. ${SMOKE_DIR}/base.sh "build_system=mesonpy"
. ${SMOKE_DIR}/base.sh "build_system=setuptools"
. ${SMOKE_DIR}/base.sh "build_system=pdm"
. ${SMOKE_DIR}/base.sh "build_system=hatch"

0 comments on commit 32704a5

Please sign in to comment.