Skip to content

Commit

Permalink
Move from setup.py to pyproject.toml for creation of zcbor packages
Browse files Browse the repository at this point in the history
setup.py is deprecated.

This involved restructuring a bit to also avoid the data_files
feature which was used to include the src and include directories,
but which is discouraged/deprecated, and needed lots of resolving
logic in zcbor to locate in different types of installations.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
  • Loading branch information
oyvindronningstad committed Dec 11, 2023
1 parent 89a9d0f commit 5c49b75
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 171 deletions.
8 changes: 4 additions & 4 deletions .github/actions/install_zcbor/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ runs:
shell: sh
run: |
pip3 install -U pip
pip3 install -U setuptools
pip3 install -U build
pip3 install -U -r scripts/requirements.txt
- name: Install zcbor package
if: ${{ inputs.zcbor_package == 'bdist_wheel' }}
shell: sh
run: |
python3 setup.py sdist bdist_wheel
python3 -m build
pip3 install dist/zcbor-*.tar.gz
pip3 uninstall -y zcbor
pip3 install dist/zcbor-*.whl
Expand All @@ -27,10 +27,10 @@ runs:
if: ${{ inputs.zcbor_package == 'setup_install' }}
shell: sh
run: |
python3 setup.py install
pip3 install .
- name: Install zcbor package
if: ${{ inputs.zcbor_package == 'setup_develop' }}
shell: sh
run: |
python3 setup.py develop
pip3 install -e .
5 changes: 2 additions & 3 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ jobs:
- name: Install west and dependencies
run: |
pip install -U pip
pip install -U setuptools
pip install -U wheel
pip install -U build
pip install -U -r scripts/requirements.txt
- name: Generate and install zcbor package
run: |
python setup.py bdist_wheel
python build bdist_wheel
pip install dist/zcbor-0.7.99-py3-none-any.whl
pip uninstall -y zcbor
pip install -e .
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ options:
-c CDDL, --cddl CDDL Path to one or more input CDDL file(s). Passing
multiple files is equivalent to concatenating them.
--no-prelude Exclude the standard CDDL prelude from the build. The
prelude can be viewed at zcbor/cddl/prelude.cddl in
the repo, or together with the script.
prelude can be viewed at zcbor/prelude.cddl in the
repo, or together with the script.
-v, --verbose Print more information while parsing CDDL and
generating code.
--default-max-qty DEFAULT_MAX_QTY, --dq DEFAULT_MAX_QTY
Expand Down Expand Up @@ -540,8 +540,8 @@ options:
-c CDDL, --cddl CDDL Path to one or more input CDDL file(s). Passing
multiple files is equivalent to concatenating them.
--no-prelude Exclude the standard CDDL prelude from the build. The
prelude can be viewed at zcbor/cddl/prelude.cddl in
the repo, or together with the script.
prelude can be viewed at zcbor/prelude.cddl in the
repo, or together with the script.
-v, --verbose Print more information while parsing CDDL and
generating code.
-i INPUT, --input INPUT
Expand Down Expand Up @@ -593,8 +593,8 @@ options:
-c CDDL, --cddl CDDL Path to one or more input CDDL file(s). Passing
multiple files is equivalent to concatenating them.
--no-prelude Exclude the standard CDDL prelude from the build. The
prelude can be viewed at zcbor/cddl/prelude.cddl in
the repo, or together with the script.
prelude can be viewed at zcbor/prelude.cddl in the
repo, or together with the script.
-v, --verbose Print more information while parsing CDDL and
generating code.
-i INPUT, --input INPUT
Expand Down
14 changes: 14 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python3
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#

from pathlib import Path

from .zcbor.zcbor import (
CddlValidationError,
DataTranslator,
main
)
46 changes: 46 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#

[build-system]
requires = ['setuptools']
build-backend = 'setuptools.build_meta'

[project]
name = 'zcbor'
description = 'Code generation and validation using CDDL schemas'
readme = 'README.md'
license = {text = 'Apache'}
requires-python = ">=3.8"
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3',
'Programming Language :: C',
'Topic :: File Formats :: JSON :: JSON Schema',
'Topic :: Software Development :: Build Tools',
'Topic :: Software Development :: Code Generators',
]
authors = [{name = 'Nordic Semiconductor ASA'}]
maintainers = [{name = 'Øyvind Rønningstad', email = 'oyvind.ronningstad@nordicsemi.no'}]
dynamic = ['dependencies', 'version']

[project.urls]
Homepage = 'https://github.com/NordicSemiconductor/zcbor'

[project.scripts]
zcbor = 'zcbor:main'

[tool.setuptools]
packages = ['zcbor', 'zcbor.src', 'zcbor.include', 'zcbor.zcbor']
package-dir = {zcbor = '.'}

[tool.setuptools.package-data]
zcbor = ['src/*', 'include/*', 'zcbor/*']

[tool.setuptools.dynamic]
version = {file = 'zcbor/VERSION'}
dependencies = {file = ['scripts/requirements-base.txt']}
2 changes: 1 addition & 1 deletion add_helptext.py → scripts/add_helptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pathlib import Path
from sys import argv

p_root = Path(__file__).absolute().parents[0]
p_root = Path(__file__).absolute().parents[1]
p_README = Path(p_root, 'README.md')

pattern = r"""
Expand Down
91 changes: 0 additions & 91 deletions setup.py

This file was deleted.

7 changes: 3 additions & 4 deletions tests/scripts/test_repo_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
p_readme = p_root / "README.md"
p_architecture = p_root / "ARCHITECTURE.md"
p_release_notes = p_root / "RELEASE_NOTES.md"
p_init_py = p_root / 'zcbor' / '__init__.py'
p_init_py = p_root / '__init__.py'
p_zcbor_py = p_root / 'zcbor' / 'zcbor.py'
p_setup_py = p_root / 'setup.py'
p_add_helptext = p_root / 'add_helptext.py'
p_add_helptext = p_root / 'scripts' / 'add_helptext.py'
p_test_zcbor_py = p_tests / 'scripts' / 'test_zcbor.py'
p_test_versions_py = p_tests / 'scripts' / 'test_versions.py'
p_test_repo_files_py = p_tests / 'scripts' / 'test_repo_files.py'
Expand All @@ -51,7 +50,7 @@ def do_codestyle(self, files, **kwargs):

def test_codestyle(self):
"""Run codestyle tests on all Python scripts in the repo."""
self.do_codestyle([p_init_py, p_setup_py, p_test_versions_py, p_test_repo_files_py])
self.do_codestyle([p_init_py, p_test_versions_py, p_test_repo_files_py, p_add_helptext])
self.do_codestyle([p_zcbor_py], ignore=['W191', 'E101', 'W503'])
self.do_codestyle([p_test_zcbor_py], ignore=['E402', 'E501', 'W503'])

Expand Down
4 changes: 2 additions & 2 deletions tests/scripts/test_zcbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
except ImportError:
print("""
The zcbor package must be installed to run these tests.
During development, install with `python3 setup.py develop` to install in a way
During development, install with `pip3 install -e .` to install in a way
that picks up changes in the files without having to reinstall.
""")
exit(1)
Expand All @@ -48,7 +48,7 @@
p_yaml_compat_cddl = Path(p_tests, 'cases', 'yaml_compatibility.cddl')
p_yaml_compat_yaml = Path(p_tests, 'cases', 'yaml_compatibility.yaml')
p_README = Path(p_root, 'README.md')
p_prelude = Path(p_root, 'zcbor', 'cddl', 'prelude.cddl')
p_prelude = Path(p_root, 'zcbor', 'prelude.cddl')


class TestManifest(TestCase):
Expand Down
19 changes: 0 additions & 19 deletions zcbor/__init__.py

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 5c49b75

Please sign in to comment.