Skip to content

Commit c1d4c29

Browse files
authored
Refactor - better underscore / hyphenated handling, pypi publish workflow (#17)
1 parent a3d0f81 commit c1d4c29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+796
-205
lines changed

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 120

.pre-commit-config.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,8 @@ ci:
33
autofix_commit_msg: "style: pre-commit fixes"
44

55
repos:
6-
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.1.0
8-
hooks:
9-
- id: check-added-large-files
10-
- id: check-case-conflict
11-
- id: check-merge-conflict
12-
- id: check-symlinks
13-
- id: end-of-file-fixer
14-
- id: mixed-line-ending
15-
- id: requirements-txt-fixer
16-
- id: trailing-whitespace
17-
186
- repo: https://github.com/mgedmin/check-manifest
19-
rev: "0.47"
7+
rev: "0.49"
208
hooks:
219
- id: check-manifest
2210
stages: [manual]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ bake:
99
cookiecutter $(BAKE_OPTIONS) . --overwrite-if-exists
1010

1111
watch: bake
12-
watchmedo shell-command -p '*.*' -c 'make bake -e BAKE_OPTIONS=$(BAKE_OPTIONS)' -W -R -D \{{cookiecutter.project_slug}}/
12+
watchmedo shell-command -p '*.*' -c 'make bake -e BAKE_OPTIONS=$(BAKE_OPTIONS)' -W -R -D \{{cookiecutter.underscored}}/
1313

1414
replay: BAKE_OPTIONS=--replay
1515
replay: watch

cookiecutter.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"plugin_name": "ACL",
33
"project_name": "NetBox {{ cookiecutter.plugin_name }} Plugin",
4-
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
4+
"hyphenated": "{{ '-'.join(cookiecutter['project_name'].lower().split()).replace('_', '-') }}",
5+
"underscored": "{{ cookiecutter.hyphenated.replace('-', '_') }}",
56
"project_short_description": "NetBox plugin for {{ cookiecutter.plugin_name }}.",
67
"__model_name": "{{ cookiecutter.plugin_name.replace(' ', '').replace('-', '') }}",
78
"__model_url": "{{ cookiecutter.plugin_name.lower().replace(' ', '-').replace('_', '-') }}",
89
"__model_url_name": "{{ cookiecutter.plugin_name.lower().replace(' ', '').replace('_', '').replace('-', '') }}",
9-
"full_name": "Arthur Hanson",
10-
"email": "[email protected]",
11-
"github_username": "arthanson",
10+
"full_name": "John Doe",
11+
"email": "",
12+
"github_username": "",
1213
"version": "0.1.0",
1314
"open_source_license": ["Apache-2.0", "MIT", "BSD", "ISC", "GPL-3.0-only", "Not open source"],
1415
"_copy_without_render": ["docs/changelog.md", "docs/contributing.md", "docs/index.md", ".github/workflows/*.yml"]

docs/prompts.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ to initialize most of the other settings.</dd>
2020
<dd>The name of your new Python package project. This is used in
2121
documentation, so spaces and any characters are fine here.</dd>
2222

23-
<dt>project_slug</dt>
23+
<dt>hyphenated</dt>
2424
<dd>The name of your Python package for PyPI, also as the repository name of GitHub.
2525
Typically, it is the slugified version of project_name.</dd>
2626

27+
<dt>underscored</dt>
28+
<dd>The name of the python module and directory in the project.</dd>
29+
2730
<dt>project_short_description</dt>
2831
<dd>A 1-sentence description of what your Python package does.</dd>
2932

docs/tutorial.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cookiecutter https://github.com/netbox-community/cookiecutter-netbox-plugin.git
3030
```
3131

3232
Finally, a new folder will be created under current folder, the name is the answer you
33-
provided to `project_slug`.
33+
provided to `hyphenated`.
3434

3535
Go to this generated folder, the project layout should look like:
3636

@@ -94,7 +94,7 @@ At this point you can run tests and make sure everything is working properly.
9494
## Step 5: Create a GitHub Repo
9595

9696
Go to your GitHub account and create a new repo named `netbox-healthcheck-plugin`, where
97-
`netbox-healthcheck-plugin` matches the `project_slug` from your answers to running
97+
`netbox-healthcheck-plugin` matches the `hyphenated` from your answers to running
9898
cookiecutter.
9999

100100
Then go to repo > settings > secrets, click on 'New repository secret', add the following
@@ -106,7 +106,7 @@ Then go to repo > settings > secrets, click on 'New repository secret', add the
106106

107107
## Step 6: Upload code to GitHub
108108

109-
Back to your develop environment, find the folder named after the `project_slug`.
109+
Back to your develop environment, find the folder named after the `hyphenated`.
110110
Move into this folder, and then setup git to use your GitHub repo and upload the
111111
code:
112112

@@ -140,7 +140,7 @@ click on actions link, you should find screen like this:
140140
![](http://images.jieyu.ai/images/202104/20210419170304.png)
141141

142142
There should be some workflows running. After they finished, go to [TestPyPI], check if a
143-
new artifact is published under the name `project_slug`.
143+
new artifact is published under the name `hyphenated`.
144144

145145
## Step 7. Check documentation
146146

hooks/pre_gen_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
MODULE_REGEX = r"^[_a-zA-Z][_a-zA-Z0-9]+$"
77

8-
module_name = "{{ cookiecutter.project_slug}}"
8+
module_name = "{{ cookiecutter.underscored}}"
99

1010
if not re.match(MODULE_REGEX, module_name):
1111
print(

pyproject.toml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
# https://www.python.org/dev/peps/pep-0518/
33

44
[build-system]
5-
requires = ["setuptools>=63.2.0", "wheel"]
5+
requires = ["setuptools"]
6+
build-backend = "setuptools.build_meta"
67

78
[project]
89
name = "cookiecutter-netbox-plugin"
10+
version = "0.1.0"
911
authors = [
1012
{name = "Arthur Hanson", email = "[email protected]"},
1113
]
@@ -17,24 +19,22 @@ classifiers=[
1719
'Intended Audience :: Developers',
1820
'Natural Language :: English',
1921
"Programming Language :: Python :: 3 :: Only",
20-
'Programming Language :: Python :: 3.8',
2122
'Programming Language :: Python :: 3.9',
2223
'Programming Language :: Python :: 3.10',
2324
'Programming Language :: Python :: 3.11',
25+
'Programming Language :: Python :: 3.12',
2426
]
2527

2628
requires-python = ">=3.8"
27-
dynamic = ["version"]
2829

2930
[project.optional-dependencies]
3031
test = [
31-
"black==23.3.0",
32+
"black==24.3.0",
3233
"check-manifest==0.49",
33-
"pre-commit==3.3.1",
34-
"pylint==2.17.4",
35-
"pytest-mock<3.10.1",
36-
"pytest-runner",
37-
"pytest==7.3.1",
34+
"pre-commit==3.7.0",
35+
"pytest==8.1.1",
36+
"flake8",
37+
"flake8-pyproject",
3838
"pytest-github-actions-annotate-failures",
3939
]
4040

@@ -45,10 +45,4 @@ Tracker = "https://github.com/netbox-community/cookiecutter-netbox-plugin/issues
4545

4646
[tool.black]
4747
line-length = 120
48-
target_version = ['py38', 'py39', 'py310', 'py311']
49-
50-
[tool.isort]
51-
profile = "black"
52-
53-
[tool.pylint]
54-
max-line-length = 120
48+
target-version = ['py312']

requirements_dev.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
black==23.9.1
2-
bump2version==1.0.1
3-
cookiecutter>=2.3.1
4-
isort==5.12.0
5-
pytest==5.3.1
6-
pytest-cookies==0.5.1
1+
black==24.3.0
2+
flake8==7.0.0
3+
pip==24.0
4+
check-manifest==0.49
5+
pytest==8.1.1
6+
pytest-cookies==0.7.0

tests/test_bake_project.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
from __future__ import annotations
22

33
import datetime
4-
import importlib
54
import os
65
import shlex
76
import subprocess
87
import sys
98
from contextlib import contextmanager
109

11-
import pytest
12-
import yaml
13-
from click.testing import CliRunner
1410
from cookiecutter.utils import rmtree
1511

1612

@@ -94,9 +90,7 @@ def test_bake_and_run_tests(cookies):
9490

9591
def test_bake_withspecialchars_and_run_tests(cookies):
9692
"""Ensure that a `full_name` with double quotes does not break setup.py"""
97-
with bake_in_temp_dir(
98-
cookies, extra_context={"full_name": 'name "quote" name'}
99-
) as result:
93+
with bake_in_temp_dir(cookies, extra_context={"full_name": 'name "quote" name'}) as result:
10094
assert result.project.isdir()
10195
run_inside_dir("python setup.py test", str(result.project)) == 0
10296

@@ -119,24 +113,19 @@ def test_make_help(cookies):
119113
def test_bake_selecting_license(cookies):
120114
license_strings = {
121115
"MIT license": "MIT ",
122-
"BSD license": "Redistributions of source code must retain the "
123-
+ "above copyright notice, this",
116+
"BSD license": "Redistributions of source code must retain the " + "above copyright notice, this",
124117
"ISC license": "ISC License",
125118
"Apache Software License 2.0": "Licensed under the Apache License, Version 2.0",
126119
"GNU General Public License v3": "GNU GENERAL PUBLIC LICENSE",
127120
}
128121
for license, target_string in license_strings.items():
129-
with bake_in_temp_dir(
130-
cookies, extra_context={"open_source_license": license}
131-
) as result:
122+
with bake_in_temp_dir(cookies, extra_context={"open_source_license": license}) as result:
132123
assert target_string in result.project.join("LICENSE").read()
133124
assert license in result.project.join("setup.py").read()
134125

135126

136127
def test_bake_not_open_source(cookies):
137-
with bake_in_temp_dir(
138-
cookies, extra_context={"open_source_license": "Not open source"}
139-
) as result:
128+
with bake_in_temp_dir(cookies, extra_context={"open_source_license": "Not open source"}) as result:
140129
found_toplevel_files = [f.basename for f in result.project.listdir()]
141130
assert "setup.py" in found_toplevel_files
142131
assert "LICENSE" not in found_toplevel_files

0 commit comments

Comments
 (0)