Skip to content

Commit

Permalink
Merge pull request #39 from ssciwr/optional-setuptools-scm
Browse files Browse the repository at this point in the history
Make the use of setuptools_scm optional
  • Loading branch information
dokempf authored Apr 4, 2024
2 parents 9435e13 + 6128449 commit da6f525
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"gitlab_ci": ["Yes", "No"],
"notebooks": ["Yes", "No"],
"commandlineinterface": ["No", "Yes"],
"version_management": ["manually", "setuptools_scm"],
"_extensions": [
"local_extensions.PrecommitExtension",
"local_extensions.ShortcutExtension",
Expand Down
4 changes: 3 additions & 1 deletion tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ def test_with_remote(cookies):
@pytest.mark.local
@pytest.mark.parametrize("cli", ("Yes", "No"))
@pytest.mark.parametrize("notebooks", ("Yes", "No"))
def test_pytest_run(cookies, virtualenv, cli, notebooks):
@pytest.mark.parametrize("version_management", ("manually", "setuptools_scm"))
def test_pytest_run(cookies, virtualenv, cli, notebooks, version_management):
# Bake the project
bake = cookies.bake(
extra_context={
'project_slug': 'test_project',
'commandlineinterface': cli,
'notebooks': notebooks,
'version_management': version_management
}
)

Expand Down
6 changes: 4 additions & 2 deletions {{cookiecutter.project_slug}}/.github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ jobs:

steps:
- uses: actions/checkout@v4
{%- if cookiecutter.version_management == "setuptools_scm" %}
with:
# setuptools_scm requires a non-shallow clone of the repository
fetch-depth: 0
# setuptools_scm requires a non-shallow clone of the repository
fetch-depth: 0
{%- endif %}

- uses: actions/setup-python@v5
name: Install Python
Expand Down
3 changes: 2 additions & 1 deletion {{cookiecutter.project_slug}}/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{%- if cookiecutter.version_management == "setuptools_scm" %}
# Ignore setuptools_scm generated version file
{{ cookiecutter|modname }}/_version.py

{%- endif %}
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
8 changes: 8 additions & 0 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
[build-system]
requires = [
"setuptools >=61",
{%- if cookiecutter.version_management == "setuptools_scm" %}
"setuptools_scm >=7",
{%- endif %}
]
build-backend = "setuptools.build_meta"

Expand All @@ -18,7 +20,11 @@ readme = "README.md"
maintainers = [
{ name = "{{ cookiecutter.full_name}}", email = "[email protected]" },
]
{%- if cookiecutter.version_management == "setuptools_scm" %}
dynamic = ["version"]
{%- else %}
version = "0.0.1"
{%- endif %}
requires-python = ">=3.8"
{%- if cookiecutter.license != "None" %}
license = { text = "{{ cookiecutter.license }}" }
Expand Down Expand Up @@ -75,6 +81,7 @@ docs = [
packages = [
"{{ cookiecutter|modname }}",
]
{%- if cookiecutter.version_management == "setuptools_scm" %}

# Configure setuptools_scm, which extracts the version number from
# the version control system. For more information see its documentation:
Expand All @@ -83,6 +90,7 @@ packages = [
version_scheme = "post-release"
local_scheme = "node-and-date"
write_to = "{{ cookiecutter|modname }}/_version.py"
{%- endif %}

# The following is the configuration for the pytest test suite
[tool.pytest.ini_options]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{%- if cookiecutter.version_management == "setuptools_scm" %}
# The version file is generated automatically by setuptools_scm
from {{ cookiecutter|modname }}._version import version as __version__
{%- else %}
from importlib import metadata

__version__ = metadata.version(__package__)
del metadata
{%- endif %}

def add_one(x: int):
"""An example function that increases a number
Expand Down

0 comments on commit da6f525

Please sign in to comment.