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 8 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": ["GitLab", "Github", "None"],
jcierocki marked this conversation as resolved.
Show resolved Hide resolved
"jupytext": ["No", "Yes"],
"docs": ["Sphinx", "No docs"],
"versioning": ["Bumpversion", "Python Semantic Release", "None"],
"python_package_name": "{{ cookiecutter.__project_name_slug.replace('-', '_') }}",
"__package_name": "{{ cookiecutter.python_package_name }}",
jcierocki marked this conversation as resolved.
Show resolved Hide resolved
"_copy_without_render": [".github/workflows/*.yml"]
}
45 changes: 35 additions & 10 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,58 @@

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"
]

SEMANTIC_RELEASE_FILES = [
".github/workflows/check_future_version.yml",
]

{% 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 %}

{% if cookiecutter.versioning != "Python Semantic Release" %}
files_to_be_removed.extend(SEMANTIC_RELEASE_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 +69,4 @@
for path in Path("").rglob("*.sh"):
path.chmod(path.stat().st_mode | stat.S_IXUSR)

print("DONE 🎆")
print("DONE 🎆")
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check New Version

on: workflow_dispatch

jobs:
release:
runs-on: ubuntu-latest
concurrency: release
permissions:
id-token: write
contents: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Python Semantic Release
uses: python-semantic-release/python-semantic-release@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
root_options: "-v --noop"
jcierocki marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 7 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 Down Expand Up @@ -236,6 +234,7 @@ tests:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

{% if cookiecutter.docs != "No docs" %}
jcierocki marked this conversation as resolved.
Show resolved Hide resolved
##############################################

# Job to build Sphinx docs and host it on GitLab Pages
Expand All @@ -249,6 +248,7 @@ pages:
- ./build_docs.sh
artifacts:
paths:
- public
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
{% endif %}
143 changes: 105 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,85 @@ 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"]

{%- if cookiecutter.versioning == "Python Semantic Release" %}
[tool.semantic_release]
assets = []
commit_message = "{version}\n\nAutomatically generated by python-semantic-release"
commit_parser = "angular"
logging_use_named_masks = false
major_on_zero = false
allow_zero_version = true
tag_format = "v{version}"
version_variables = [
"src/{{ cookiecutter.__package_name }}/__version__.py:__version__",
]
build_command = "pip install build && python -m build"

[tool.semantic_release.branches.main]
match = "(main|master)"
prerelease_token = "rc"
prerelease = false

[tool.semantic_release.changelog]
template_dir = "templates"
changelog_file = "CHANGELOG.md"
exclude_commit_patterns = []

{%- raw %}
[tool.semantic_release.changelog.environment]
block_start_string = "{%"
block_end_string = "%}"
variable_start_string = "{{"
variable_end_string = "}}"
comment_start_string = "{#"
comment_end_string = "#}"
trim_blocks = false
lstrip_blocks = false
newline_sequence = "\n"
keep_trailing_newline = false
extensions = []
autoescape = true
{% endraw -%}

[tool.semantic_release.commit_author]
env = "GIT_COMMIT_AUTHOR"
default = "semantic-release <semantic-release>"

[tool.semantic_release.commit_parser_options]
allowed_tags = [
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"style",
"refactor",
"test",
]
minor_tags = ["feat"]
patch_tags = ["fix", "perf"]
default_bump_level = 0

[tool.semantic_release.remote]
name = "origin"
type = "github"
ignore_token_for_push = false
insecure = false

[tool.semantic_release.publish]
dist_glob_patterns = ["dist/*"]
upload_to_vcs_release = true
{% endif -%}
Loading