Skip to content

Commit

Permalink
feat(template): Adding setuptools as a build-system option (#140)
Browse files Browse the repository at this point in the history
- Adding documentation about _**setuptools**_.
- Enable option in TUI for _**setuptools**_.
- Adding _**setuptools**_ as a build-system:
  - Creating a `setuptools-pyproject.toml`.
  - Editing `post_gen_project.py`.
  - Editing cookiecutter.json.
  - Editing Makefile of the template.
  - Adding _**setuptools**_ in conda/dev.yaml.
  - Adding _**setuptools**_ to build-system.sh
  - Adding code to base.sh to check if the _**setuptools**_ command is available in the system.
- Standardize the use of literal strings within the template  with double quotes.
- Adding `noqa` in profile.py to ignore ruff warnings

Solve #53
  • Loading branch information
Anavelyz authored Jul 4, 2023
1 parent c05dc79 commit 4cd11c0
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 152 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ for a Python package.
- Support to pre-commit
- CI with github actions
- Release workflow with semantic release and github actions
- Flexible build system selection: Choose between popular build
systems like [Poetry](https://python-poetry.org/),
[Flit](https://flit.pypa.io) or
[meson-python](https://meson-python.readthedocs.io/en/latest/index.html)
based on your preference.
- Flexible build system selection: Choose between popular build systems like
[Poetry](https://python-poetry.org/), [Flit](https://flit.pypa.io),
[meson-python](https://meson-python.readthedocs.io/en/latest/index.html) or
[Setuptools](https://setuptools.pypa.io/en/latest/) 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
importable into a subdirectory. This subdirectory is typically named
Expand Down
10 changes: 10 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ packages. SciCookie support the following:
ease of use compared to other build systems. It is designed to be fast
and scalable, making it suitable for both small and large projects.

- [Setuptools](https://setuptools.pypa.io/en/latest/): It's a package that
facilitates the distribution and installation of Python packages. Setuptools
provides a way to define metadata about your project, such as its name,
version, dependencies, and other details. It also provides functionality for
building and distributing packages, creating distribution archives, and
installing packages with their dependencies. _"It helps developers to easily
share reusable code (in the form of a library) and programs (e.g., CLI/GUI
tools implemented in Python), that can be installed with pip and uploaded to
PyPI."_

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
274 changes: 137 additions & 137 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/scicookie/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"build_system": [
"poetry",
"flit",
"mesonpy"
"mesonpy",
"setuptools"
],
"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 @@ -56,6 +56,8 @@
BUILD_SYSTEM = "flit"
{% elif cookiecutter.build_system == "mesonpy" -%}
BUILD_SYSTEM = "mesonpy"
{% elif cookiecutter.build_system == "setuptools" -%}
BUILD_SYSTEM = "setuptools"
{%- else %}
BUILD_SYSTEM = None
{%- endif %}
Expand Down Expand Up @@ -166,6 +168,11 @@ def clean_up_build_system():
build_system_dir / "meson.build",
PROJECT_DIRECTORY / 'meson.build'
)
elif BUILD_SYSTEM == "setuptools":
shutil.move(
build_system_dir / "setuptools-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
else:
shutil.move(
build_system_dir / "base-pyproject.toml",
Expand Down
4 changes: 2 additions & 2 deletions src/scicookie/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Profile:
"""Profile class that handles profiles defined in the .yaml files."""

profile_name: str = ""
config: dict = {}
profiles_available: list = []
config: dict = {} # noqa: RUF012
profiles_available: list = [] # noqa: RUF012

def __init__(self, profile_name: str):
self._load_profiles_available()
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 @@ -84,6 +84,7 @@ build_system:
- poetry
- flit
- mesonpy
- setuptools
enabled: false

command_line_interface:
Expand Down
8 changes: 5 additions & 3 deletions src/scicookie/{{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ docs-preview: docs-build

.PHONY:build
build:
{%- if cookiecutter.build_system == 'poetry' %}
{%- if cookiecutter.build_system == "poetry" %}
poetry build
{%- elif cookiecutter.build_system == 'flit' %}
{%- elif cookiecutter.build_system == "flit" %}
flit build
{%- elif cookiecutter.build_system == 'mesonpy' %}
{%- elif cookiecutter.build_system == "mesonpy" %}
meson build
{%- elif cookiecutter.build_system == "setuptools" %}
python -m build
{%- endif %}

.PHONY:release-ci
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"


[project]
name = "{{ cookiecutter.project_slug }}"
authors = [
{ name = "{{ cookiecutter.author_full_name }}", email = "{{ cookiecutter.author_email }}" },
]
description = "{{ cookiecutter.project_short_description }}"
readme = "README.md"
classifiers = [
{%- 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 %}
"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",
]
dynamic = ["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 %}
"ipython < 8",
"ipykernel >= 6.0.0",
{%- 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"

{% include "build-system/base-pyproject.toml" %}
{#- keep this line at the end of the file -#}
11 changes: 7 additions & 4 deletions src/scicookie/{{cookiecutter.project_slug}}/conda/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ channels:
- conda-forge
dependencies:
- python <3.11
{%- if cookiecutter.build_system == 'poetry' %}
{%- if cookiecutter.build_system == "poetry" %}
- poetry
{%- elif cookiecutter.build_system == 'flit' %}
{%- elif cookiecutter.build_system == "flit" %}
- flit
{%- elif cookiecutter.build_system == 'mesonpy' %}
{%- elif cookiecutter.build_system == "mesonpy" %}
- meson-python
{%- elif cookiecutter.build_system == "setuptools" %}
- setuptools
- build
{%- endif %}
- nodejs # used by semantic-release
- shellcheck
{%- if cookiecutter.documentation_engine == 'sphinx' %}
{%- if cookiecutter.documentation_engine == "sphinx" %}
- pandoc
{%- endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ projects written in the Python programming language. It is based on the
the build process of a project. It allows you to easily define project
dependencies, specify build options, generate configuration files and
build scripts, among other tasks related to building software.
{%- elif cookiecutter.build_system == "setuptools" -%}
In addition, you should know that to build our package we use
[Setuptools](https://setuptools.pypa.io/en/latest/), it's a package to easily
define the package structure, manage dependencies and convert our project into a
distributable package. Also, setuptools automates tasks such as packaging
and installation, saving time and effort for both our team and end-users.

{%- endif %}

Expand Down
3 changes: 3 additions & 0 deletions tests/smoke/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ elif command -v flit &> /dev/null; then
flit install
elif command -v meson &> /dev/null; then
pip install -e .
else
# use setuptools
pip install --editable .
fi

ipython kernel install --name "python3" --user
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 @@ -5,3 +5,4 @@ SMOKE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
. ${SMOKE_DIR}/base.sh "build_system=poetry"
. ${SMOKE_DIR}/base.sh "build_system=flit"
. ${SMOKE_DIR}/base.sh "build_system=mesonpy"
. ${SMOKE_DIR}/base.sh "build_system=setuptools"

0 comments on commit 4cd11c0

Please sign in to comment.