Skip to content

Commit

Permalink
feat(template): Adding flit as a build-system option (#136)
Browse files Browse the repository at this point in the history
* Activate option in TUI to poetry and flit.
* Adding documentation about flit and poetry.
* Adding flit as a build-system:
* Creating a flit-pyproject.toml
* Editing post_gen_project.py
* Creating a smoke test (build-system.sh)
* Editing cookicutter.json
  • Loading branch information
Anavelyz authored Jun 27, 2023
1 parent 9d9fcdb commit 44ecccf
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 3 deletions.
1 change: 1 addition & 0 deletions .makim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ groups:
./tests/smoke/coc.sh
./tests/smoke/governance.sh
./tests/smoke/roadmap.sh
./tests/smoke/build-system.sh
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ 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/) or [Flit](https://flit.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
importable into a subdirectory. This subdirectory is typically named
Expand Down
30 changes: 30 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
# Guide

## Build System

There are several build system options available to development of Python
packages. SciCookie support the following:

- [**Poetry**](https://python-poetry.org/) (default): It's a Python package
manager that streamlines dependency management and package distribution. It
provides a simple and intuitive syntax for defining project dependencies and
allows you to easily create and manage virtual environments for your projects.
With Poetry, you can easily install, update, and remove dependencies, and it
automatically handles conflicts and resolution between packages. Additionally,
Poetry provides a comprehensive toolset for packaging and publishing your
projects to PyPI, including support for building source distributions and
wheel packages, as well as generating and uploading documentation. Overall,
Poetry simplifies the development and distribution of Python projects, making
it a popular tool for many Python developers.

- [**Flit**](https://flit.pypa.io): It's a Python package and a lightweight tool
for creating and distributing Python packages. It automates the processes
involved in packaging and submitting a project to PyPI, and provides a
straightforward interface for managing a project's dependencies. With just a
few commands, you can use Flit to quickly create source distributions and
wheel packages and submit them 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
suggestion as a issue at
https://github.com/osl-incubator/scicookie/issues/new/choose.
3 changes: 2 additions & 1 deletion src/scicookie/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"pytorch-ignite-roadmap"
],
"build_system": [
"poetry"
"poetry",
"flit"
],
"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 @@ -52,6 +52,8 @@
{%- endif %}
{% if cookiecutter.build_system == "poetry" -%}
BUILD_SYSTEM = "poetry"
{% elif cookiecutter.build_system == "flit" -%}
BUILD_SYSTEM = "flit"
{%- else %}
BUILD_SYSTEM = None
{%- endif %}
Expand Down Expand Up @@ -148,6 +150,11 @@ def clean_up_build_system():
build_system_dir / "poetry-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
elif BUILD_SYSTEM == "flit":
shutil.move(
build_system_dir / "flit-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
else:
shutil.move(
build_system_dir / "base-pyproject.toml",
Expand Down
9 changes: 9 additions & 0 deletions src/scicookie/profiles/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ project_layout:
- flat
enabled: false

build_system:
message: Select the build system
help: ""
type: single-choice
choices:
- poetry
- flit
enabled: false

command_line_interface:
message: Select the Command Line Interface (CLI)
help: ""
Expand Down
3 changes: 3 additions & 0 deletions src/scicookie/profiles/osl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ governance_document:
roadmap_document:
enabled: true

build_system:
enabled: true

use_tools:
enabled: true

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
[build-system]
requires = ["flit_core >=3.4"]
build-backend = "flit_core.buildapi"


[project]
name = "{{ cookiecutter.project_name }}"
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",
]
dynamic = ["version"]
requires-python = ">=3.8.1"
dependencies = [
"urllib3 =< 2",
{# 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_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"

{% 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 @@ -6,6 +6,8 @@ dependencies:
- python <3.11
{%- if cookiecutter.build_system == 'poetry' %}
- poetry
{%- else %}
- flit
{%- endif %}
- nodejs # used by semantic-release
- shellcheck
Expand Down
23 changes: 21 additions & 2 deletions src/scicookie/{{cookiecutter.project_slug}}/docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,27 @@ at `./{{ cookiecutter.package_slug }}`.
For my information, check the official documentation:
https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/

Contributions are welcome, and they are greatly appreciated! Every
little bit helps, and credit will always be given.
{% if cookiecutter.build_system == "poetry" -%}
In addition, you should know that to build our package we use
[Poetry](https://python-poetry.org/), it's a Python package management tool that
simplifies the process of building and publishing Python packages. It allows us
to easily manage dependencies, virtual environments and package versions. Poetry
also includes features such as dependency resolution, lock files and publishing
to PyPI. Overall, Poetry streamlines the process of managing Python packages,
making it easier for us to create and share our code with others.
{%- elif cookiecutter.build_system == "flit" -%}
In addition, you should know that to build our package we use
[Flit](https://flit.pypa.io), it's a Python package that simplifies the process
of publishing Python packages. It allows us to easily create and publish our
packages to PyPI. Flit handles the packaging, distribution, and installation of
Python packages, making it easier for us to share our code with others. It also
includes features such as dependency management, versioning, and metadata
management.

{%- endif %}

Contributions are welcome, and they are greatly appreciated! Every little bit
helps, and credit will always be given.

You can contribute in many ways:

Expand Down
6 changes: 6 additions & 0 deletions tests/smoke/build-system.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

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"

0 comments on commit 44ecccf

Please sign in to comment.