Skip to content

Commit

Permalink
Fixing ordering dependency importing version number
Browse files Browse the repository at this point in the history
Addressing problem caused by pypa/setuptools#1724
Accessing the version attribute could cause odd dependencies on import
statement ordering as to whether importing succeeded or failed
  • Loading branch information
GardenTools committed Apr 9, 2021
1 parent b05ce84 commit 29e6a36
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 21 deletions.
4 changes: 1 addition & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
include CHANGES.rst
include LICENSE
include README.rst
include VERSION.txt
include tox.ini
include dev-requirements.in
include dev-requirements.txt
include requirements.in
include requirements.txt
include .pylintrc
include .travis.yml

recursive-include examples *
recursive-include src/crcengine/templates *
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ install: clean ## install the package to the active Python's site-packages

UPDATE_REQS=pip-compile -q -U --output-file=requirements.txt requirements.in

.PHONY: update-requirements
update-requirements: ## Update dependencies in requirements.txt
.PHONY: update-deps
update-deps: ## Update dependencies in requirements.txt
$(call UPDATE_REQS)

requirements.txt: requirements.in
Expand Down
1 change: 1 addition & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.3.2a1
2 changes: 2 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
wheel>=0.26
build
importlib-metadata
jinja2
packaging
pip-tools
Pygments # needed for the docs
pytest>=3
Expand Down
20 changes: 17 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ idna==2.10
# via requests
imagesize==1.2.0
# via sphinx
importlib-metadata==3.10.0
importlib-metadata==3.6.0
# via
# -r requirements.in
# build
# keyring
# pep517
# pluggy
# pytest
# tox
# twine
# virtualenv
iniconfig==1.1.1
# via pytest
isort==5.8.0
Expand All @@ -71,6 +78,7 @@ mccabe==0.6.1
# via pylint
packaging==20.9
# via
# -r requirements.in
# bleach
# build
# pytest
Expand Down Expand Up @@ -153,10 +161,14 @@ toml==0.10.2
# tox
tox==3.23.0
# via -r requirements.in
tqdm==4.59.0
tqdm==4.60.0
# via twine
twine==3.4.1
# via -r requirements.in
typed-ast==1.4.2
# via astroid
typing-extensions==3.7.4.3
# via importlib-metadata
urllib3==1.26.4
# via requests
virtualenv==20.4.3
Expand All @@ -168,7 +180,9 @@ wheel==0.36.2
wrapt==1.12.1
# via astroid
zipp==3.4.1
# via importlib-metadata
# via
# importlib-metadata
# pep517

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ long_description = file: README.rst
long_description_content_type = text/x-rst
keywords = crcengine crc cyclic redundancy check checksum code-generation Castagnoli CRC32 CRC16-CCITT
url = https://github.com/GardenTools/crcengine
version = attr: crcengine.version.__version__
version = file: VERSION.txt
project_urls =
Changelog = https://github.com/GardenTools/CrcEngine/blob/master/CHANGES.rst
Documentation = https://crcengine.readthedocs.io/en/latest/
Expand All @@ -37,6 +37,7 @@ package_dir =
packages =
crcengine
install_requires =
importlib-metadata>=3.6
jinja2>=2.7

[options.entry_points]
Expand Down
7 changes: 5 additions & 2 deletions src/crcengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# You should have received a copy of the GNU General Public License
# along with crcengine. If not, see <https://www.gnu.org/licenses/>.

import importlib_metadata

__version__ = importlib_metadata.version('crcengine')

from .algorithms import (
AlgorithmNotFoundError,
Expand All @@ -36,5 +39,5 @@
get_bits_max_value,
new,
)
from .codegen import generate_code, generate_test
from .version import __version__
from crcengine.codegen import generate_code, generate_test

2 changes: 1 addition & 1 deletion src/crcengine/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from .algorithms import get_algorithm_params
from .calc import create_lsb_table, create_msb_table
from .version import __version__ as crcengine_version
from crcengine import __version__ as crcengine_version

# Generated file information
_GenFile = namedtuple("GenFile", ["template", "output"])
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def pytest_configure(config):
def pytest_collection_modifyitems(config, items):
# If a test has the needs_ceedling marker and no-ceedling has been specified
# mark it as a skipped test
print("beep")
if config.getoption("--no-ceedling"):
print("no ceedling")
skip_ceedling = pytest.mark.skip(reason="--no-ceedling specified")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_crcengine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Unit tests for the crcengine module"""
"""Unit tests for the calc module"""
# This file is part of crcengine.
#
# crcengine is free software: you can redistribute it an d /or modify
Expand Down Expand Up @@ -210,3 +210,4 @@ def test_custom_algorithm():
assert "mycrc8" not in crcengine.algorithms_available()
with pytest.raises(crcengine.AlgorithmNotFoundError):
crcengine.get_algorithm_params("mycrc8")

19 changes: 12 additions & 7 deletions src/crcengine/version.py → tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"""
CrcEngine package version number definition
"""
# This file is part of CrcEngine, a python library for CRC calculation
#
# Copyright 2021 Garden Tools software
"""Unit tests for version number reporting"""
# This file is part of crcengine.
#
# crcengine is free software: you can redistribute it an d /or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -18,4 +14,13 @@
# You should have received a copy of the GNU General Public License
# along with crcengine. If not, see <https://www.gnu.org/licenses/>.

__version__ = "0.3.2a1"
import packaging.version

import crcengine

def test_version():
pkg_ver = packaging.version.parse(crcengine.__version__)
ref_ver = packaging.version.parse("0.3.0")
print(pkg_ver)
print(ref_ver)
assert pkg_ver > ref_ver

0 comments on commit 29e6a36

Please sign in to comment.