Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More build options: docs, versioning #19

Merged
merged 22 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0308157
docs template generation made optional
ds-jakub-cierocki Jul 8, 2024
4d72023
removed docs generation from CI/CD if disabled during project setup
ds-jakub-cierocki Jul 8, 2024
72c4341
refacotred post-gen hooks
ds-jakub-cierocki Jul 9, 2024
35f381f
python-semantic-release partial support: pyproject.toml + GitHub CI
ds-jakub-cierocki Jul 9, 2024
2972384
jinja2 typo fix
ds-jakub-cierocki Jul 23, 2024
1548f5b
fix: escpaed semantic-relase controls including jinja2 reserved syntax
ds-jakub-cierocki Jul 23, 2024
f7ba881
refactor: better var naming in hooks
ds-jakub-cierocki Jul 23, 2024
cee6968
skipping docs fix
ds-jakub-cierocki Jul 23, 2024
2daf1f3
fix: missing contents read permission in GH actions (#18)
mhordynski Jul 9, 2024
9a3f742
chore: add issue templates (#20)
mhordynski Jul 23, 2024
838df60
versioning fixes
ds-jakub-cierocki Jul 24, 2024
e5031ac
removed remaninings of PyPI publishing from GitHub CI/CD
ds-jakub-cierocki Jul 24, 2024
938d960
removed package building from pyproject.toml
ds-jakub-cierocki Jul 24, 2024
516387b
added Semantic Release part + made docs and bumpversion optional
ds-jakub-cierocki Jul 24, 2024
8593552
added validation to ensure it's not possible to build project with Gi…
ds-jakub-cierocki Jul 24, 2024
aa5030b
added TODO to make installing bump2version optional in Gitlab CI
ds-jakub-cierocki Jul 24, 2024
7def7e6
implemented code review suggestions regarding cookiecutter.json config
ds-jakub-cierocki Jul 25, 2024
21ffd22
code review fixes: made GitLab CI docs generation conditional using G…
ds-jakub-cierocki Jul 29, 2024
00f362a
code review fixes - removed Python Semantic Release (it will be provi…
ds-jakub-cierocki Jul 29, 2024
f036ca3
Merge branch 'main' into jc/more-build-options
Sahcim Jul 30, 2024
a326651
Remove Python Semantic Versioning from readme
Sahcim Jul 30, 2024
b91a046
Remove build docs step in gitlab ci when is set to True
Jul 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
{
"client_name": "ds",
"project_name": "default",
"__project_name_slug": "{{cookiecutter.project_name | slugify}}",
"__client_name_slug": "{{cookiecutter.client_name | slugify}}",
"repo_name": "{{cookiecutter.__client_name_slug}}-{{cookiecutter.__project_name_slug}}",
"ci": [
"GitLab",
"Github",
"None"
],
"jupytext": [
"No",
"Yes"
],
"python_package_name": "{{ cookiecutter.__project_name_slug.replace('-', '_') }}",
"__package_name": "{{ cookiecutter.python_package_name }}",
"_copy_without_render": [
".github/workflows/*.yml"
]
}
"client_name": "ds",
"project_name": "default",
"__project_name_slug": "{{cookiecutter.project_name | slugify}}",
"__client_name_slug": "{{cookiecutter.client_name | slugify}}",
"repo_name": "{{cookiecutter.__client_name_slug}}-{{cookiecutter.__project_name_slug}}",
"ci": ["Github", "GitLab", "None"],
jcierocki marked this conversation as resolved.
Show resolved Hide resolved
"jupytext": ["No", "Yes"],
"docs": ["Sphinx", "No docs"],
"versioning": ["Bumpversion", "None"],
"python_package_name": "{{ cookiecutter.__project_name_slug.replace('-', '_') }}",
"__package_name": "{{ cookiecutter.python_package_name }}",
"_copy_without_render": [".github/workflows/*.yml", ".github/workflows/*.yaml"]
}
37 changes: 27 additions & 10 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,50 @@

print("Running post generation...")

ci = "{{ cookiecutter.ci }}"
files_to_be_removed = []
Sahcim marked this conversation as resolved.
Show resolved Hide resolved

REMOVE_PATHS = []

gitlab_files = [
GITLAB_FILES = [
".gitlab-ci.yml",
"docker/precommit"
]

github_files = [
GITHUB_FILES = [
".github/",
]

DOCS_FILES = [
"docs/",
"build_docs.sh",
".github/workflows/documentation.yml"
]

BUMPVERSION_FILES = [
".bumpversion.cfg",
"bump_version.sh"
]

{% if cookiecutter.ci != "GitLab" %}
REMOVE_PATHS.extend(gitlab_files)
files_to_be_removed.extend(GITLAB_FILES)
{% endif %}

{% if cookiecutter.ci != "Github" %}
REMOVE_PATHS.extend(github_files)
files_to_be_removed.extend(GITHUB_FILES)
{% endif %}

{% if cookiecutter.jupytext != "Yes" %}
REMOVE_PATHS.extend(["notebooks/example.py"])
files_to_be_removed.append("notebooks/example.py")
{% endif %}

{% if cookiecutter.docs == "No docs" %}
files_to_be_removed.extend(DOCS_FILES)
{% endif %}

{% if cookiecutter.versioning != "Bumpversion" %}
files_to_be_removed.extend(BUMPVERSION_FILES)
{% endif %}

print("Cleaning files... 🌀")
for path in REMOVE_PATHS:
for path in files_to_be_removed:
path = Path(path)
if path.exists() and path.is_file():
print(f"Clean up file: '{path}'")
Expand All @@ -44,4 +61,4 @@
for path in Path("").rglob("*.sh"):
path.chmod(path.stat().st_mode | stat.S_IXUSR)

print("DONE 🎆")
print("DONE 🎆")
4 changes: 3 additions & 1 deletion {{ cookiecutter.repo_name }}/.bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ values =
dev
prod

[bumpversion:file:./src/{{cookiecutter.__package_name}}/VERSION]
[bumpversion:file:./src/{{cookiecutter.__package_name}}/__version__.py]
search = __version__ = '{current_version}'
replace = __version__ = '{new_version}'
17 changes: 10 additions & 7 deletions {{ cookiecutter.repo_name }}/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ variables:
DOCKER_REGISTRY: $CI_REGISTRY/$CI_PROJECT_PATH
PRECOMMIT_IMAGE: $DOCKER_REGISTRY/precommit


# run CI on default branch or MR only
workflow:
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: '$CI_MERGE_REQUEST_IID'
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
- if: "$CI_MERGE_REQUEST_IID"

stages:
- preparation
Expand Down Expand Up @@ -58,7 +57,7 @@ stages:
stage: preparation
image: docker:23
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
changes:
- docker/precommit/Dockerfile
- .pre-commit-config.yaml
Expand Down Expand Up @@ -87,7 +86,6 @@ stages:
# Consider to use stable commit SHA from main branch instead
# and manual changes to reduce surprises.


# To overcome issue that latest might not be present
# and assume that this either new project / done in
# atomic merge request and is not main branch
Expand Down Expand Up @@ -120,7 +118,7 @@ lint-precommit-changed:
- docker/precommit/Dockerfile
- .pre-commit-config.yaml
when: always
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
when: never

#############################################
Expand All @@ -140,6 +138,7 @@ lint-precommit-changed:
###########################################

# Job to run pytest with code coverage + license check
# TODO make installing bump2version below conditional on cookiecutter parameter choice
tests:
image: $PYTHON_DOCKER_IMAGE
stage: tests
Expand Down Expand Up @@ -236,6 +235,8 @@ tests:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH


{%- if cookiecutter.docs != "No docs" %}
##############################################

# Job to build Sphinx docs and host it on GitLab Pages
Expand All @@ -249,6 +250,8 @@ pages:
- ./build_docs.sh
artifacts:
paths:
- public
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

{% endif -%}
4 changes: 4 additions & 0 deletions {{ cookiecutter.repo_name }}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Read more about different modes in [documentation](https://ipython.org/ipython-d
All code should be in `src/` to make reusability and review straightforward, keep notebooks simple for exploratory data analysis.
See also [Cookiecutter Data Science opinion](https://drivendata.github.io/cookiecutter-data-science/#notebooks-are-for-exploration-and-communication).

{%- if cookiecutter.docs != "No docs" %}
# Project documentation

In `docs/` directory are Sphinx RST/Markdown files.
Expand All @@ -62,6 +63,7 @@ $ ./build_docs.sh
Then open `public/index.html` file.

Please read the official [Sphinx documentation](https://www.sphinx-doc.org/en/master/) for more details.
{% endif -%}

{% if cookiecutter.ci == "GitLab" %}

Expand Down Expand Up @@ -104,6 +106,7 @@ Treat them as read-only files and edit only notebooks.

{%- endif -%}

{%- if cookiecutter.versioning == "Bumpversion" %}
# Semantic version bump

To bump version of the library please use `bump2version` which will update all version strings.
Expand All @@ -123,6 +126,7 @@ $ ./bump_version.sh --dry-run major
Script updates **VERSION** file and setup.cfg automatically uses that version.

You can configure it to update version string in other files as well - please check out the bump2version configuration file.
{% endif -%}

{% if cookiecutter.ci == "GitLab" %}

Expand Down
71 changes: 33 additions & 38 deletions {{ cookiecutter.repo_name }}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
[build-system]
requires = [
"setuptools >= 40.9.0",
"wheel",
]
requires = ["setuptools >= 40.9.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.isort]
multi_line_output=3
line_length=120
multi_line_output = 3
line_length = 120
include_trailing_comma = true
known_first_party=[
'{{ cookiecutter.__package_name }}'
]
known_third_party=[ # Most popular libraries. Extend if necessary.
known_first_party = ['{{ cookiecutter.__package_name }}']
known_third_party = [ # Most popular libraries. Extend if necessary.
'IPython',
'PIL',
'cv2',
Expand Down Expand Up @@ -47,13 +42,13 @@ known_third_party=[ # Most popular libraries. Extend if necessary.
'tqdm',
'typer',
]
skip_gitignore=true
skip_gitignore = true

[tool.black]
line_length=120
line_length = 120

[tool.pytest]
norecursedirs=[
norecursedirs = [
'.git',
'.tox',
'.env',
Expand Down Expand Up @@ -88,42 +83,42 @@ warn_unused_ignores = false
show_error_codes = true
check_untyped_defs = true
no_implicit_optional = true
mypy_path=['src']
mypy_path = ['src']

[[tool.mypy.overrides]]
module = "{{ cookiecutter.__package_name }}.*"
ignore_missing_imports = false
disallow_untyped_defs = true

[tool.pylint.basic]
good-names="i,j,x,y,z,x1,y1,z1,x2,y2,z2,cv,df,dx,dy,dz,w,h,c,b,g,qa,q,a"
max-args=8
good-names = "i,j,x,y,z,x1,y1,z1,x2,y2,z2,cv,df,dx,dy,dz,w,h,c,b,g,qa,q,a"
max-args = 8

[tool.pylint.main]
load-plugins=["pylint.extensions.docparams"]
load-plugins = ["pylint.extensions.docparams"]

[tool.pylint.messages_control]
disable=[
"suppressed-message",
# therefore we wouldn't have to install full dependency set in order to lint
"import-error",
# sometimes we create a dataclass or Pydantic module and just don't need public methods
"too-few-public-methods",
# below is handled by pycln
"unused-import",
# below is handled by isort
"wrong-import-order",
# too restrictive
"too-many-instance-attributes",
# not necessary nor useful in our projects
"missing-module-docstring"
]
disable = [
"suppressed-message",
# therefore we wouldn't have to install full dependency set in order to lint
"import-error",
# sometimes we create a dataclass or Pydantic module and just don't need public methods
"too-few-public-methods",
# below is handled by pycln
"unused-import",
# below is handled by isort
"wrong-import-order",
# too restrictive
"too-many-instance-attributes",
# not necessary nor useful in our projects
"missing-module-docstring",
]

[tool.pylint.format]
max-line-length=120
max-line-length = 120

[tool.pylint.miscellaneous]
notes=["XXX"]
notes = ["XXX"]

[tool.pylint.parameter_documentation]
accept-no-param-doc = false
Expand All @@ -133,13 +128,13 @@ accept-no-yields-doc = false
default-docstring-type = "google"

[tool.pylint.design]
max-locals=20
max-locals = 20

[tool.pylint.similarities]
min-similarity-lines=10
min-similarity-lines = 10

[tool.bandit]
exclude_dirs = ["venv",]
exclude_dirs = ["venv"]
# B101 disables errors for asserts in the code
# remember to not use asserts for security and control flows
skips = ["B101"]
skips = ["B101"]
2 changes: 1 addition & 1 deletion {{ cookiecutter.repo_name }}/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
name = {{ cookiecutter.__package_name }}
# do not change version by hand: use bump_version.sh
version = file: src/{{ cookiecutter.__package_name }}/VERSION
version = attr: {{ cookiecutter.__package_name }}.__version__.__version__
description = "deepsense.ai project"
author = deepsense.ai
author_email = [email protected]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""Version information."""
from pathlib import Path

version_file = Path(__file__).absolute().parents[0] / "VERSION"
__version__ = version_file.read_text(encoding="utf-8").strip()
__version__ = "0.0.1"
Loading