Skip to content

Commit b41ddc5

Browse files
authored
Merge pull request #96 from statisticsnorway/formatting-tools
Add formatting tools
2 parents b037cdd + 342ad47 commit b41ddc5

File tree

13 files changed

+670
-307
lines changed

13 files changed

+670
-307
lines changed

{{cookiecutter.project_name}}/.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jobs:
4343
4444
- name: SonarCloud Scan
4545
env:
46-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
47-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
46+
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }} # Needed to get PR information, if any
47+
SONAR_TOKEN: {{ "${{ secrets.SONAR_TOKEN }}" }}
4848
# No need to run SonarCloud analysis if dependabot update or token not defined
4949
if: env.SONAR_TOKEN != '' && (github.actor != 'dependabot[bot]')
5050
uses: SonarSource/sonarcloud-github-action@v2.1.1

{{cookiecutter.project_name}}/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*.xlsx
1616
*.zip
1717

18+
# Notebooks shall be stored in .py or .R-format.
19+
# See https://adr.ssb.no/0020-lagringsformat-for-jupyter-notebooks/
20+
*.ipynb
21+
22+
1823
# The section below is from the GitHub .gitignore template for Python:
1924
# https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore
2025

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
# General file checkers
5+
- id: check-added-large-files
6+
name: Check for added large files
7+
entry: check-added-large-files
8+
language: system
9+
- id: check-merge-conflict
10+
name: Check for merge conflict strings
11+
entry: check-merge-conflict
12+
language: system
13+
- id: check-case-conflict
14+
name: Check for problematic file names
15+
entry: check-case-conflict
16+
language: system
17+
18+
# General text checkers
19+
- id: end-of-file-fixer
20+
name: Fix End of Files
21+
entry: end-of-file-fixer
22+
language: system
23+
types: [text]
24+
stages: [commit, push, manual]
25+
- id: trailing-whitespace
26+
name: Trim Trailing Whitespace
27+
entry: trailing-whitespace-fixer
28+
language: system
29+
types: [text]
30+
stages: [commit, push, manual]
31+
- id: mixed-line-ending
32+
name: Mixed Line Ending
33+
entry: mixed-line-ending
34+
language: system
35+
types: [text]
36+
stages: [commit, push, manual]
37+
38+
# Serialization format checkers
39+
- id: check-yaml
40+
name: Check Yaml
41+
entry: check-yaml
42+
language: system
43+
types: [yaml]
44+
- id: check-json
45+
name: Check JSON
46+
entry: check-json
47+
language: system
48+
types: [json]
49+
- id: check-toml
50+
name: Check Toml
51+
entry: check-toml
52+
language: system
53+
types: [toml]
54+
55+
# Python tools
56+
- id: check-ast
57+
name: Check Python syntax
58+
entry: check-ast
59+
language: system
60+
types: [python]
61+
- id: isort
62+
name: isort
63+
entry: isort
64+
require_serial: true
65+
language: system
66+
types_or: [cython, pyi, python]
67+
args: ["--filter-files"]
68+
- id: black
69+
name: black
70+
entry: black
71+
language: system
72+
types_or: [python, jupyter]
73+
require_serial: true

{{cookiecutter.project_name}}/SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Security Policy
22

3-
SSB takes the security of our software products and services seriously, which
3+
SSB takes the security of our software products and services seriously, which
44
includes all source code repositories managed through our GitHub organization.
55

66
We believe that responsible disclosure of security vulnerabilities helps us ensure

{{cookiecutter.project_name}}/poetry.lock

Lines changed: 511 additions & 208 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,28 @@ ipykernel = ">=6.15.3"
1515
[tool.poetry.group.dev.dependencies]
1616
pytest = ">=7.1.3"
1717
pytest-cov = ">=5.0.0"
18+
black = {extras = ["jupyter"], version = ">=24.4.2"}
19+
isort = ">=5.12.0"
20+
pre-commit = ">=3.3.1"
21+
pre-commit-hooks = ">=4.4.0"
1822

1923
[build-system]
2024
requires = ["poetry-core>=1.0.0"]
2125
build-backend = "poetry.core.masonry.api"
2226

27+
[tool.isort]
28+
profile = "black"
29+
force_single_line = true
30+
skip_gitignore = true
31+
lines_after_imports = 2
32+
# The line below is needed for jupyter notebooks stored as .py in percent format.
33+
# See https://github.com/PyCQA/isort/issues/1338 for details
34+
treat_comments_as_code = ["# %%"]
35+
2336
[tool.jupytext]
2437
formats = "ipynb,auto:percent"
2538
notebook_metadata_filter = "jupytext.text_representation,-jupytext.text_representation.jupytext_version,-widgets,-varInspector"
2639
cell_metadata_filter = "-papermill,tags"
2740

2841
[tool.pytest.ini_options]
2942
pythonpath = ["src"]
30-
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# This file is required to do local imports of the functions within this folder
1+
# This file is required to do local imports of the functions within this folder
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
#!/usr/bin/python3
22

3-
def fizz(x:int) -> str:
4-
if x%3 == 0:
3+
4+
def fizz(x: int) -> str:
5+
if x % 3 == 0:
56
return "fizz"
67
return ""
78

8-
def buzz(x:int) -> str:
9-
if x%5 == 0:
9+
10+
def buzz(x: int) -> str:
11+
if x % 5 == 0:
1012
return "buzz"
1113
return ""
12-
13-
def fizzbuzz(x:list) -> list:
14+
15+
16+
def fizzbuzz(x: list) -> list:
1417
result = []
1518
for y in x:
1619
r = ""
1720
r = fizz(y) + buzz(y)
1821
if not r:
1922
r = y
2023
result.append(r)
21-
return result
24+
return result

{{cookiecutter.project_name}}/src/notebooks/00_imports.ipynb

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Organisering av notebooks
22

3-
### Om datatilstandene i SSB og reflektering av de i mappestrukturen
3+
### Om datatilstandene i SSB og reflektering av de i mappestrukturen

0 commit comments

Comments
 (0)