diff --git a/.cirrus.yml b/.cirrus.yml index be291b990..d7026c453 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -9,7 +9,7 @@ prep_stuff_template: &PREP_STUFF_TEMPLATE bitcoind_installation_cache: folder: ./tests/bitcoin fingerprint_script: - - cat pytest.ini | grep "addopts = " | cut -d'=' -f2 | sed 's/--/+/g' | tr '+' '\n' | grep bitcoin | cut -d' ' -f2 + - cat pyproject.toml | grep "addopts = " | cut -d'=' -f2 | sed 's/--/+/g' | tr '+' '\n' | grep bitcoin | cut -d' ' -f2 - cat tests/bitcoin_gitrev_pinned 2> /dev/null || true - cat /etc/os-release | grep VERSION - cat ./tests/install_noded.sh @@ -18,7 +18,7 @@ prep_stuff_template: &PREP_STUFF_TEMPLATE elementsd_installation_cache: folder: ./tests/elements fingerprint_script: - - cat pytest.ini | grep "addopts = " | cut -d'=' -f2 | sed 's/--/+/g' | tr '+' '\n' | grep elements | cut -d' ' -f2 + - cat pyproject.toml | grep "addopts = " | cut -d'=' -f2 | sed 's/--/+/g' | tr '+' '\n' | grep elements | cut -d' ' -f2 - cat tests/elements_gitrev_pinned 2> /dev/null || true - cat /etc/os-release | grep VERSION - cat ./tests/install_noded.sh @@ -44,11 +44,11 @@ prep_stuff_template: &PREP_STUFF_TEMPLATE pip_script: #folder: /tmp/cirrus-ci-build/.env - #fingerprint_script: echo muh && cat requirements.txt && cat test_requirements.txt + #fingerprint_script: echo muh && cat requirements.txt #populate_script: - virtualenv --python=python .env - source ./.env/bin/activate - - pip3 install -r requirements.txt --require-hashes && pip3 install -r test_requirements.txt + - pip3 install -r requirements.txt --require-hashes && pip3 install -e ".[test]" install_script: - source ./.env/bin/activate - pip3 install -e . diff --git a/.gitignore b/.gitignore index 397814d9b..38597243e 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ tests/bitcoin* tests/elements* token.sh src/cryptoadvance/specter/translations/**/messages.mo +src/cryptoadvance/specter/_version.py tests/elements signing_dir site diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5d2c4af77..ae732b289 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,6 @@ cache: - key: files: - ./requirements.txt - - ./test_requirements.txt prefix: "$CI_JOB_NAME" paths: - .cache/pip @@ -57,7 +56,7 @@ check: script: - pip3 install -r requirements.txt - pip3 install -e . - - pip3 install -r test_requirements.txt + - pip3 install -e ".[test]" - python3 setup.py install # compiles babel stuff as well (might make pip install obsolete) - py.test --cov-report term --cov cryptoadvance @@ -67,7 +66,7 @@ check: script: # start the server in the background - pip3 install -e . - - pip3 install -r test_requirements.txt + - pip3 install -e ".[test]" - python3 setup.py install # compiles babel stuff as well (might make pip install obsolete) - npm i - ./utils/test-cypress.sh --docker --debug run @@ -84,16 +83,11 @@ release_pip: only: - tags script: - - pip3 install setuptools wheel twine - - pip3 install -r test_requirements.txt - - python3 setup.py install - # verifying the version number follows vx.y.z (e.g. "v1.2.3") - - if ! [[ $CI_COMMIT_TAG =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-pre(0|[1-9][0-9]*))? ]]; then exit 1; fi - # set version number in setup.py - - echo Releasing $CI_COMMIT_TAG - - sed -i "s/version=\".*/version=\"$CI_COMMIT_TAG\",/" setup.py - - cat setup.py - - python3 setup.py sdist bdist_wheel + - pip3 install -e . + - pip3 install -e ".[test]" + - pip3 install . + - pip3 install build==0.10.0 twine + - python3 -m build - ls -l dist # twine reads the password from the env-var TWINE_PASSWORD # Either testing it or doing the real thing depending on which gitlab-project we're running: @@ -126,17 +120,7 @@ release_binary_windows: - pip install virtualenv - virtualenv --python=python3 .env - .\.env\Scripts\activate - - pip install -r test_requirements.txt || echo "why the heck does this fail with:" - # Collecting distlib<1,>=0.3.6 - # Downloading distlib-0.3.6-py2.py3-none-any.whl (468 kB) - # ------------------------------------- 468.5/468.5 kB 30.6 MB/s eta 0:00:00 - # ERROR: To modify pip, please run the following command: - # C:\gitlab-runner\builds\xPkLDUk2\0\k9ert\specter-desktop\.env\Scripts\python.exe -m pip install -r test_requirements.txt - # Uploading artifacts for failed job - - # That error message above doesn't even help a bit - # However it seems that if you do that yet another time, it doesn't fail! - - pip install -r test_requirements.txt -vv + - pip3 install -e ".[test]" script: # This script won't execute if the script before that fails @@ -167,7 +151,7 @@ release_electron_linux_windows: stage: releasing only: - tags - dependencies: + needs: - release_binary_windows before_script: - python3 -V # Print out python version for debugging @@ -177,7 +161,7 @@ release_electron_linux_windows: # Only difference to default befor_script: (ToDo fix this) - python3 -m virtualenv --python=python3 .env - source .env/bin/activate - - pip3 install -r test_requirements.txt + - pip3 install -e ".[test]" script: - echo "Releasing for ${CI_PROJECT_ROOT_NAMESPACE}" - export CI_PROJECT_ROOT_NAMESPACE # needed in the build-script to download the right windows-binary @@ -227,7 +211,7 @@ release_signatures: - pip3 install --upgrade virtualenv - virtualenv --python=python3 .env - source .env/bin/activate - - pip3 install -r test_requirements.txt + - pip3 install -e ".[test]" - ./utils/artifact_signer.sh init # prepare .gnupg script: - python3 -m utils.release-helper download # downloads the job-artifacts from gitlab diff --git a/MANIFEST.in b/MANIFEST.in index f98b9fb69..9c7af8dd3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -9,3 +9,13 @@ recursive-include src/cryptoadvance/specter/services/*/static * recursive-include src/cryptoadvance/specter/translations/*/LC_MESSAGES *.mo recursive-include src/cryptoadvance/specter/translations/*/LC_MESSAGES *.po include requirements.txt + +# just by using using `setuptools_scm` it modifies the way files are added to the sdist. +# This was a cause of major headache in order to avoid large binaries e.g. in +# `pyinstaller/bitcoind` to not be added. See also this +# [chapter](https://github.com/pypa/setuptools_scm/#file-finders-hook-makes-most-of-manifestin-unnecessary) +# ... which might make the above not necessary but the below very needed: +exclude .gitattributes .gitignore pyinstaller .pre-commit.config.yaml +prune pyinstaller/bitcoind +prune pyinstaller/torbrowser +prune .github \ No newline at end of file diff --git a/docker/python-bitcoind/Readme.md b/docker/python-bitcoind/Readme.md index 806120ad4..eddd85b93 100644 --- a/docker/python-bitcoind/Readme.md +++ b/docker/python-bitcoind/Readme.md @@ -6,7 +6,7 @@ docker push registry.gitlab.com/cryptoadvance/specter-desktop/python-bitcoind:v2 ``` Here the version is v23.0 but that's just an example. This folder just explains how the image is created. Which image is USED is specified: -* In the case of tests in pytest.ini in the addopts-line (MIGHT be different in different branches) +* In the case of tests in pyproject.toml in the addopts-line (MIGHT be different in different branches) * in the case of running ``` diff --git a/docs/development.md b/docs/development.md index 3102798df..741fd0c4e 100644 --- a/docs/development.md +++ b/docs/development.md @@ -146,7 +146,7 @@ If you're not interested in elements, you can skip the liquid specific tests as Set up the dependencies: ```sh -pip3 install -r test_requirements.txt +pip3 install -e ".[test]" pip3 install -e . ``` diff --git a/pyinstaller/build-win-ci.bat b/pyinstaller/build-win-ci.bat index 762dbc391..d411d98a8 100755 --- a/pyinstaller/build-win-ci.bat +++ b/pyinstaller/build-win-ci.bat @@ -12,7 +12,7 @@ echo " --> Activating virtualenv" call .\.buildenv\Scripts\activate echo " --> Installing test-requirement" -pip3 install -r test_requirements.txt +pip3 install -e ".[test]" echo " --> Setting version in setup.py" python .\utils\release-helper.py set_setup_py_version %1% diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..58e0fd834 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,87 @@ +[build-system] +requires = [ + "setuptools<=65.7.0", + "setuptools_scm[toml]>=6.2", + "babel", + "build==0.10.0", + "wheel", + "twine" +] +build-backend = "setuptools.build_meta" + +[project] +name = "cryptoadvance.specter" + +authors = [ + { name="Stepan Snigirev"}, + { name="k9ert"}, +] +description = "A GUI for Bitcoin Core & Electrum optimised to work with airgapped hardware wallets" + +urls = { Homepage = "https://github.com/cryptoadvance/spectrum" } +readme = "README.md" +license = {file = "LICENSE"} + + +requires-python = ">=3.7,<4.0" + +dynamic = ["dependencies", "version"] + +classifiers =[ + 'Programming Language :: Python :: 3', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Framework :: Flask', +] + +[project.scripts] +specter="cryptoadvance.specter.cli:entry_point" + +[tool.setuptools_scm] +write_to = "src/cryptoadvance/specter/_version.py" +version_scheme = "python-simplified-semver" + +[tool.pytest.ini_options] +norecursedirs = "tests/bitcoin* tests/elements* tests/xtestdata_testextensions" + +log_format = "[%(levelname)8s] %(message)s %(name)s (%(filename)s:%(lineno)s)" +addopts = "--bitcoind-version v22.0.0 --elementsd-version v0.21.0.2" +markers = [ + "slow: mark test as slow.", + "elm: mark test as elementsd dependent", + "bottleneck: mark a test as so ressource intensive that it can create a bottleneck where the test just fails due to a lack of ressources", + "threading: test needs threading to work" +] + +filterwarnings = [ + "ignore::DeprecationWarning:bitbox02[.*]" +] + +[tool.setuptools] +#include-package-data = false +package-dir = {'' = 'src'} + +[tool.setuptools.packages.find] +where = ["src"] +include = ["cryptoadvance.*"] + +[tool.setuptools.exclude-package-data] +mypkg = ["pyinstaller"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.in"]} + +[project.optional-dependencies] +test = [ + "black==22.3.0", + "pre-commit==2.13.0", + "pip-tools==5.5.0", + "pytest==7.1.2", + "PySocks==1.7.1", + "pytest-cov==2.10.1", + "mock==4.0.2", + "babel==2.10.3", + "python-gitlab==2.10.1", + # requirements for stuff in ./utils + "requests==2.26.0", +] \ No newline at end of file diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 0e5a06a59..000000000 --- a/pytest.ini +++ /dev/null @@ -1,17 +0,0 @@ -[pytest] -norecursedirs = tests/bitcoin* tests/elements* tests/xtestdata_testextensions -log_format = [%(levelname)8s] %(message)s %(name)s (%(filename)s:%(lineno)s) -addopts = --bitcoind-version v22.0.0 --elementsd-version v0.21.0.2 -markers = - slow: mark test as slow. - elm: mark test as elementsd dependent - bottleneck: mark a test as so ressource intensive that it can create a bottleneck where the test just fails due to a lack of ressources - threading: test needs threading to work - -# If you need live logging to debug, uncomment the next line -# log_cli = True -# Then set the desired logging level on the command line, for example: -# pytest --log-cli-level INFO - -filterwarnings = - ignore::DeprecationWarning:bitbox02[.*] diff --git a/requirements.in b/requirements.in index 6ee2e3800..c883bd249 100644 --- a/requirements.in +++ b/requirements.in @@ -9,7 +9,6 @@ Flask-Login==0.5.0 Flask-RESTful==0.3.9 Flask-HTTPAuth==4.4.0 hwi==2.1.1 -importlib_metadata==4.8.1 python-dotenv==0.13.0 requests==2.26.0 pysocks==1.7.1 diff --git a/requirements.txt b/requirements.txt index f99334dc9..301f66a7e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -321,10 +321,6 @@ idna==3.4 \ --hash=sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4 \ --hash=sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2 # via requests -importlib_metadata==4.8.1 \ - --hash=sha256:b618b6d2d5ffa2f16add5697cf57a46c76a56229b0ed1c438322e4e95645bd15 \ - --hash=sha256:f284b3e11256ad1e5d03ab86bb2ccd6f5339688ff17a4d797a0fe7df326f23b1 - # via -r requirements.in itsdangerous==2.1.2 \ --hash=sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44 \ --hash=sha256:5dbbc68b317e5e42f327f9021763545dc3fc3bfe22e6deb96aaf1fc38874156a @@ -686,9 +682,9 @@ specterext-exfund==0.1.7 \ specterext-faucet==0.1.2 \ --hash=sha256:86db78a6c41688152cfeec14efafd6d06c97e6edd9735461ee897495f90cb2e8 # via -r requirements.in -specterext-stacktrack==0.3.0 \ - --hash=sha256:14f96f1f552f57ba017b8bc642f07343edbb1abafe09e03bbaae179d78d7ce23 \ - --hash=sha256:9e2946185730aab377951e83a27d8791a34e0f031e44f15991212b6b85722ca0 +specterext-stacktrack==0.2.1 \ + --hash=sha256:28729d1a981d8c061902b3d26baefc723d286aecea4d203ed729d1c89a9de267 \ + --hash=sha256:34a5e9da8a3cb7a4c8b7bc4e0a417a043150e608a7261e56d84fbfba9af15b8a # via -r requirements.in sqlalchemy==1.4.42 \ --hash=sha256:04f2598c70ea4a29b12d429a80fad3a5202d56dce19dd4916cc46a965a5ca2e9 \ @@ -775,10 +771,6 @@ wtforms==3.0.1 \ --hash=sha256:6b351bbb12dd58af57ffef05bc78425d08d1914e0fd68ee14143b7ade023c5bc \ --hash=sha256:837f2f0e0ca79481b92884962b914eba4e72b7a2daaf1f939c890ed0124b834b # via flask-wtf -zipp==3.10.0 \ - --hash=sha256:4fcb6f278987a6605757302a6e40e896257570d11c51628968ccb2a47e80c6c1 \ - --hash=sha256:7a7262fd930bd3e36c50b9a64897aec3fafff3dfdeec9623ae22b40e93f99bb8 - # via importlib-metadata # WARNING: The following packages were not pinned, but pip requires them to be # pinned when the requirements file includes hashes. Consider using the --allow-unsafe flag. diff --git a/setup.py b/setup.py index 0c437f6a8..0f17403df 100755 --- a/setup.py +++ b/setup.py @@ -32,36 +32,14 @@ for req in install_reqs: continue reqs.append(str(req).rstrip(" \\")) - -with open("README.md", "r") as fh: - long_description = fh.read() - setup( - name="cryptoadvance.specter", - version="vx.y.z-get-replaced-by-release-script", - author="Stepan Snigirev, Kim Neunert", - author_email="snigirev.stepan@gmail.com, kim.neunert@gmail.com", - description="A GUI for Bitcoin Core optimised to work with airgapped hardware wallets", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/cryptoadvance/specter-desktop", - packages=find_namespace_packages("src", include=["cryptoadvance.*"]), - package_dir={"": "src"}, package_data={ "": [ "translations/*/LC_MESSAGES/messages.mo", ] }, # take METADATA.in into account, include that stuff as well (static/templates) - include_package_data=True, install_requires=reqs, - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Framework :: Flask", - ], - python_requires=">=3.7,<4.0", cmdclass={ "install": InstallWithBabelCompile, # The rest is convenience but not strictly necessary for the automation: @@ -70,8 +48,4 @@ setup( "init_catalog": babel.init_catalog, "update_catalog": babel.update_catalog, }, - entry_points=""" - [console_scripts] - specter=cryptoadvance.specter.cli:entry_point - """, ) diff --git a/src/cryptoadvance/specter/util/shell.py b/src/cryptoadvance/specter/util/shell.py index d44a99700..b24113e70 100644 --- a/src/cryptoadvance/specter/util/shell.py +++ b/src/cryptoadvance/specter/util/shell.py @@ -68,6 +68,6 @@ def grep(file_location, search_line): """returns true if any like in that file endswith search_line""" with open(file_location, "r") as the_file: for line in the_file.readlines(): - if line.strip().endswith(search_line): + if line.strip().__contains__(search_line): return True return False diff --git a/src/cryptoadvance/specter/util/version.py b/src/cryptoadvance/specter/util/version.py index a65d2f63f..60956cb45 100644 --- a/src/cryptoadvance/specter/util/version.py +++ b/src/cryptoadvance/specter/util/version.py @@ -10,7 +10,6 @@ from urllib.error import HTTPError import requests from requests.exceptions import ConnectionError from urllib3.exceptions import NewConnectionError -import importlib_metadata from cryptoadvance.specter.specter_error import SpecterError @@ -60,18 +59,6 @@ class VersionChecker: ) time.sleep(dt) - def _get_current_version(self): - current = "unknown" - if self.installation_type == "app": - current = VersionChecker._version_txt_content() - else: - current = importlib_metadata.version(self.name) - if current == None: - current = "custom" - if current == "vx.y.z-get-replaced-by-release-script": - current = "custom" - return current - def _get_binary_version(self): """ Get binary version: current, latest. @@ -172,12 +159,15 @@ class VersionChecker: return latest @classmethod - def _version_txt_content(cls): - version_file = "version.txt" - if getattr(sys, "frozen", False): - version_file = os.path.join(sys._MEIPASS, "version.txt") - with open(version_file) as f: - return f.read().strip() + def _get_current_version(self): + """Returns the version found in cryptoadvance.specter._version or "unknown" + if that doesn't exist + """ + try: + from cryptoadvance.specter._version import version + except ModuleNotFoundError: + return "unknown" + return "v" + version def compare(version1: str, version2: str) -> int: @@ -223,20 +213,34 @@ def compare(version1: str, version2: str) -> int: def _parse_version(version: str) -> dict: - """Parses version-strings like v1.5.6-pre5 and returns a dict""" - if version[0] == "v": - version = version[1:] - version = version.replace("rc", "-pre") - version_ar = version.split(".") - if len(version_ar) != 3: - raise SpecterError(f"version {version} does not have 3 separated digits") - postfix = "" - if "-" in version_ar[2]: - postfix = version_ar[2].split("-")[1] - version_ar[2] = version_ar[2].split("-")[0] - return { - "major": int(version_ar[0]), - "minor": int(version_ar[1]), - "patch": int(version_ar[2]), - "postfix": postfix, - } + """Parses version-strings like v1.5.6-pre5 and returns a dict + This also parses something like: + 2.0.0rc20.dev0+ga99ede2a.d20230215 + but ignores the stuff behind the postfix (which is good enough for our use cases) + see also: https://github.com/pypa/setuptools_scm/#default-versioning-scheme + """ + try: + + if version[0] == "v": + version = version[1:] + version = version.replace("rc", "-pre") + version_ar = version.split(".") + if len(version_ar) == 5 or len(version_ar) == 4: + version_ar = version_ar[0:3] + if len(version_ar) != 3: + raise SpecterError( + f"version {version} does not have 3 separated digits but {len(version_ar)}" + ) + postfix = "" + if "-" in version_ar[2]: + postfix = version_ar[2].split("-")[1] + version_ar[2] = version_ar[2].split("-")[0] + return { + "major": int(version_ar[0]), + "minor": int(version_ar[1]), + "patch": int(version_ar[2]), + "postfix": postfix, + } + except Exception as e: + logger.error(f"{str(e)} parsing version {version} ") + raise e diff --git a/test_requirements.txt b/test_requirements.txt deleted file mode 100644 index 0f58978fc..000000000 --- a/test_requirements.txt +++ /dev/null @@ -1,12 +0,0 @@ -# requirements for testing -black==22.3.0 -pre-commit==2.13.0 -pip-tools==5.5.0 -pytest==7.1.2 -PySocks==1.7.1 -pytest-cov==2.10.1 -mock==4.0.2 -babel==2.10.3 -python-gitlab==2.10.1 -# requirements for stuff in ./utils -requests==2.26.0 diff --git a/tests/conftest.py b/tests/conftest.py index b5082a2a9..60a33be82 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -131,7 +131,7 @@ def instantiate_bitcoind_controller( running_version = bitcoind_controller.version() requested_version = request.config.getoption("--bitcoind-version") assert running_version == requested_version, ( - "Please make sure that the Bitcoind-version (%s) matches with the version in pytest.ini (%s)" + "Please make sure that the Bitcoind-version (%s) matches with the version in pyproject.toml (%s)" % (running_version, requested_version) ) return bitcoind_controller @@ -157,7 +157,7 @@ def instantiate_elementsd_controller(request, rpcport=18643, extra_args=[]): running_version = elementsd_controller.version() requested_version = request.config.getoption("--elementsd-version") assert running_version == requested_version, ( - "Please make sure that the elementsd-version (%s) matches with the version in pytest.ini (%s)" + "Please make sure that the elementsd-version (%s) matches with the version in pyproject.toml (%s)" % (running_version, requested_version) ) return elementsd_controller diff --git a/tests/install_noded.sh b/tests/install_noded.sh index 471725d25..46b1a4d19 100755 --- a/tests/install_noded.sh +++ b/tests/install_noded.sh @@ -32,17 +32,17 @@ function maybe_update { # Determine if we need to pull. From https://stackoverflow.com/a/3278427 UPSTREAM=origin/master LOCAL=$(git describe --all | sed 's/heads\///' | sed 's/tags\///') # gives either a tag or "master" - if cat ../../pytest.ini | grep "addopts = --${node_impl}d-version" ; then + if cat ../../pyproject.toml | grep "addopts = --${node_impl}d-version" ; then # in this case, we use the expected version from the test also as the tag to be checked out # i admit that this is REALLY ugly. Happy for any recommendations to do that more easy - PINNED=$(cat ../../pytest.ini | grep "addopts = " | cut -d'=' -f2 | sed 's/--/+/g' | tr '+' '\n' | grep ${node_impl} | cut -d' ' -f2) + PINNED=$(cat ../../pyproject.toml | grep "addopts = " | cut -d'=' -f2 | sed 's/--/+/g' | tr '+' '\n' | grep ${node_impl} | cut -d' ' -f2) if [ "$node_impl" = "elements" ]; then # in the case of elements, the tags have a "elements-" prefix PINNED=$(echo "$PINNED" | sed 's/v//' | sed 's/^/elements-/') fi fi - # the version in pytest.ini is (also) used to check the version via getnetworkinfo()["subversion"] + # the version in pyproject.toml is (also) used to check the version via getnetworkinfo()["subversion"] # However, this might not be a valid git rev. So we need another way to specify the git-rev used # as we want to be able to test against specific commits if [ -f ../${node_impl}_gitrev_pinned ]; then @@ -78,14 +78,14 @@ function maybe_update { function calc_pytestinit_nodeimpl_version { - # returns the version of $node_impl from pytest.ini from a line which looks like: + # returns the version of $node_impl from pyproject.toml from a line which looks like: # addopts = --bitcoind-version v22.0 --elementsd-version v0.20.99 # special treatments for bitcoin and elements necessary, see below local node_impl=$1 - if cat ../pytest.ini | grep -q "${node_impl}d-version" ; then + if cat ../pyproject.toml | grep -q "${node_impl}d-version" ; then # in this case, we use the expected version from the test also as the tag to be checked out # i admit that this is REALLY ugly. Happy for any recommendations to do that more easy - PINNED=$(cat ../pytest.ini | grep "addopts = " | cut -d'=' -f2 | sed 's/--/+/g' | tr '+' '\n' | grep ${node_impl} | cut -d' ' -f2) + PINNED=$(cat ../pyproject.toml | grep "addopts = " | grep -oP "${node_impl}d-version \K\S+" | cut -d'"' -f1) if [ "$node_impl" = "elements" ]; then # in the case of elements, the tags have a "elements-" prefix diff --git a/tests/test_cli_server.py b/tests/test_cli_server.py index b47f4da7e..653e8f593 100644 --- a/tests/test_cli_server.py +++ b/tests/test_cli_server.py @@ -28,7 +28,7 @@ mock_config_dict = { @patch("cryptoadvance.specter.cli.cli_server.create_app") @patch("cryptoadvance.specter.cli.cli_server.init_app") def test_server_host_and_port(init_app, create_app, caplog): - """This test will fail if you have turned on live-logging in pytest.ini (log_cli = 1 )""" + """This test will fail if you have turned on live-logging in pyproject.toml (log_cli = 1 )""" caplog.set_level(logging.DEBUG) mock_app = MagicMock() mock_app.config = MagicMock() @@ -53,7 +53,7 @@ def test_server_host_and_port(init_app, create_app, caplog): @patch("cryptoadvance.specter.cli.cli_server.create_app") @patch("cryptoadvance.specter.cli.cli_server.init_app") def test_server_host_and_port(init_app, create_app, caplog): - """This test will fail if you have turned on live-logging in pytest.ini (log_cli = 1 )""" + """This test will fail if you have turned on live-logging in pyproject.toml (log_cli = 1 )""" caplog.set_level(logging.DEBUG) mock_app = MagicMock() mock_app.config = MagicMock() @@ -93,7 +93,7 @@ def test_server_host_and_port(init_app, create_app, caplog): @patch("cryptoadvance.specter.cli.cli_server.create_app") @patch("cryptoadvance.specter.cli.cli_server.init_app") def test_server_debug(init_app, create_app, caplog): - """This test will fail if you have turned on live-logging in pytest.ini (log_cli = 1 )""" + """This test will fail if you have turned on live-logging in pyproject.toml (log_cli = 1 )""" caplog.set_level(logging.DEBUG) runner = CliRunner() result = runner.invoke(server, ["--debug", "--no-filelog"]) @@ -109,7 +109,7 @@ def test_server_debug(init_app, create_app, caplog): @patch("cryptoadvance.specter.cli.cli_server.create_app") @patch("cryptoadvance.specter.cli.cli_server.init_app") def test_server_datafolder(init_app, create_app, caplog): - """This test will fail if you have turned on live-logging in pytest.ini (log_cli = 1 )""" + """This test will fail if you have turned on live-logging in pyproject.toml (log_cli = 1 )""" caplog.set_level(logging.DEBUG) mock_app = MagicMock() mock_app.config = MagicMock() @@ -135,7 +135,7 @@ def test_server_datafolder(init_app, create_app, caplog): @patch("cryptoadvance.specter.cli.cli_server.create_app") @patch("cryptoadvance.specter.cli.cli_server.init_app") def test_server_config(init_app, create_app, caplog): - """This test will fail if you have turned on live-logging in pytest.ini (log_cli = 1 )""" + """This test will fail if you have turned on live-logging in pyproject.toml (log_cli = 1 )""" caplog.set_level(logging.DEBUG) mock_app = MagicMock() mock_app.config = MagicMock() diff --git a/tests/test_util_shell.py b/tests/test_util_shell.py index 575b86db2..9b08b078e 100644 --- a/tests/test_util_shell.py +++ b/tests/test_util_shell.py @@ -26,4 +26,4 @@ def test_last_lines(caplog): def test_grep(): from cryptoadvance.specter.util.shell import grep - assert grep("./setup.py", 'name="cryptoadvance.specter",') + assert grep("./pyproject.toml", 'name = "cryptoadvance.specter"') diff --git a/tests/test_util_version.py b/tests/test_util_version.py index 1d8f87079..af5fe3606 100644 --- a/tests/test_util_version.py +++ b/tests/test_util_version.py @@ -13,19 +13,16 @@ from mock import Mock, patch, PropertyMock "cryptoadvance.specter.util.version.VersionChecker.installation_type", new_callable=PropertyMock, ) -@patch("cryptoadvance.specter.util.version.importlib_metadata.version") -@patch("cryptoadvance.specter.util.version.VersionChecker._version_txt_content") +@patch("cryptoadvance.specter.util.version.VersionChecker._get_current_version") def test_VersionChecker( - VersionChecker_version_txt_content, - imp_lib_mock, + mock_get_current_version, mock_installation_type, mock_latest, caplog, ): mock_latest.return_value = "v9.10.21" - imp_lib_mock.return_value = "1.2.3" - VersionChecker_version_txt_content.return_value = "2.3.4" mock_installation_type.return_value = "pip" + mock_get_current_version.return_value = "1.2.3" # We're mocking cryptoadvance by another package because that package is installed but not cryptoadvance.specter vc = VersionChecker(name="joke") @@ -37,18 +34,17 @@ def test_VersionChecker( assert vc._get_binary_version() == ( "1.2.3", "v9.10.21", - ) # will break with a new release - # assert vc._get_pip_version() == ("1.2.3", "v5.3.0") # Might break anytime - # assert vc.info == "h" + ) + # Same tests with "app" mock_installation_type.return_value = "app" vc = VersionChecker(name="joke") assert vc.installation_type == "app" - assert vc._get_current_version() == "2.3.4" - assert vc.current == "2.3.4" + assert vc._get_current_version() == "1.2.3" + assert vc.current == "1.2.3" assert vc._get_binary_version() == ( - "2.3.4", + "1.2.3", "v9.10.21", ) @@ -58,11 +54,7 @@ def test_VersionChecker( "cryptoadvance.specter.util.version.VersionChecker.installation_type", new_callable=PropertyMock, ) -@patch("cryptoadvance.specter.util.version.importlib_metadata.version") -@patch("cryptoadvance.specter.util.version.VersionChecker._version_txt_content") def test_VersionChecker_get_binary_version( - VersionChecker_version_txt_content, - imp_lib_mock, mock_installation_type, mock_requests_session: MagicMock, caplog, @@ -105,6 +97,18 @@ def test_parse_version(): "patch": 5, "postfix": "pre12", } + assert _parse_version("2.0.0rc20.dev0+ga99ede2a.d20230215") == { + "major": 2, + "minor": 0, + "patch": 0, + "postfix": "pre20", + } + assert _parse_version("2.0.0.dev1897+gcccf4a9") == { + "major": 2, + "minor": 0, + "patch": 0, + "postfix": "", + } def test_compare(): diff --git a/tests/xtestdata_testextensions/ext_root_adhoc_1/tests/conftest.py b/tests/xtestdata_testextensions/ext_root_adhoc_1/tests/conftest.py index e8e8cd251..d715ba276 100644 --- a/tests/xtestdata_testextensions/ext_root_adhoc_1/tests/conftest.py +++ b/tests/xtestdata_testextensions/ext_root_adhoc_1/tests/conftest.py @@ -120,7 +120,7 @@ def instantiate_bitcoind_controller(request, rpcport=18543, extra_args=[]): running_version = bitcoind_controller.version() requested_version = request.config.getoption("--bitcoind-version") assert running_version == requested_version, ( - "Please make sure that the Bitcoind-version (%s) matches with the version in pytest.ini (%s)" + "Please make sure that the Bitcoind-version (%s) matches with the version in pyproject.toml (%s)" % (running_version, requested_version) ) return bitcoind_controller @@ -146,7 +146,7 @@ def instantiate_elementsd_controller(request, rpcport=18643, extra_args=[]): running_version = elementsd_controller.version() requested_version = request.config.getoption("--elementsd-version") assert running_version == requested_version, ( - "Please make sure that the elementsd-version (%s) matches with the version in pytest.ini (%s)" + "Please make sure that the elementsd-version (%s) matches with the version in pyproject.toml (%s)" % (running_version, requested_version) ) return elementsd_controller diff --git a/tests/xtestdata_testextensions/ext_root_fully_qualified_1/tests/conftest.py b/tests/xtestdata_testextensions/ext_root_fully_qualified_1/tests/conftest.py index 533ec8b01..fb2f4fbee 100644 --- a/tests/xtestdata_testextensions/ext_root_fully_qualified_1/tests/conftest.py +++ b/tests/xtestdata_testextensions/ext_root_fully_qualified_1/tests/conftest.py @@ -117,7 +117,7 @@ def instantiate_bitcoind_controller(request, rpcport=18543, extra_args=[]): running_version = bitcoind_controller.version() requested_version = request.config.getoption("--bitcoind-version") assert running_version == requested_version, ( - "Please make sure that the Bitcoind-version (%s) matches with the version in pytest.ini (%s)" + "Please make sure that the Bitcoind-version (%s) matches with the version in pyproject.toml (%s)" % (running_version, requested_version) ) return bitcoind_controller @@ -143,7 +143,7 @@ def instantiate_elementsd_controller(request, rpcport=18643, extra_args=[]): running_version = elementsd_controller.version() requested_version = request.config.getoption("--elementsd-version") assert running_version == requested_version, ( - "Please make sure that the elementsd-version (%s) matches with the version in pytest.ini (%s)" + "Please make sure that the elementsd-version (%s) matches with the version in pyproject.toml (%s)" % (running_version, requested_version) ) return elementsd_controller diff --git a/tests/xtestdata_testextensions/ext_root_fully_qualified_2/tests/conftest.py b/tests/xtestdata_testextensions/ext_root_fully_qualified_2/tests/conftest.py index f64afe0b6..6b32da2ac 100644 --- a/tests/xtestdata_testextensions/ext_root_fully_qualified_2/tests/conftest.py +++ b/tests/xtestdata_testextensions/ext_root_fully_qualified_2/tests/conftest.py @@ -116,7 +116,7 @@ def instantiate_bitcoind_controller(docker, request, rpcport=18543, extra_args=[ running_version = bitcoind_controller.version() requested_version = request.config.getoption("--bitcoind-version") assert running_version == requested_version, ( - "Please make sure that the Bitcoind-version (%s) matches with the version in pytest.ini (%s)" + "Please make sure that the Bitcoind-version (%s) matches with the version in pyproject.toml (%s)" % (running_version, requested_version) ) return bitcoind_controller @@ -142,7 +142,7 @@ def instantiate_elementsd_controller(request, rpcport=18643, extra_args=[]): running_version = elementsd_controller.version() requested_version = request.config.getoption("--elementsd-version") assert running_version == requested_version, ( - "Please make sure that the elementsd-version (%s) matches with the version in pytest.ini (%s)" + "Please make sure that the elementsd-version (%s) matches with the version in pyproject.toml (%s)" % (running_version, requested_version) ) return elementsd_controller diff --git a/utils/build-common.sh b/utils/build-common.sh index 266744b7b..9795cba49 100644 --- a/utils/build-common.sh +++ b/utils/build-common.sh @@ -13,7 +13,7 @@ function create_virtualenv_for_pyinstaller { fi virtualenv --python=python3 .buildenv source .buildenv/bin/activate - pip3 install -r test_requirements.txt + pip3 install -e ".[test]" } function build_pypi_pckgs_and_install { @@ -26,12 +26,9 @@ function build_pypi_pckgs_and_install { if [[ "$OSTYPE" == "darwin"* ]]; then SML_ADD="\"\"" fi - sed -i $SML_ADD "s|version=\".*|version=\"$version\",|" setup.py - cat setup.py - python3 setup.py sdist bdist_wheel - git checkout setup.py - pypi_comp_version=$(echo $version | sed 's/^v//' | sed 's/-pre/rc/' ) - pip3 install ./dist/cryptoadvance.specter-${pypi_comp_version}-py3-none-any.whl + pip3 install build==0.10.0 + python3 -m build + pip3 install ./dist/cryptoadvance.specter-*.whl } function specify_app_name { diff --git a/utils/build-osx.sh b/utils/build-osx.sh index a3c423c0b..292629111 100755 --- a/utils/build-osx.sh +++ b/utils/build-osx.sh @@ -18,7 +18,7 @@ function create_virtualenv_for_pyinstaller { # we do: virtualenv --python=/usr/local/bin/python3 .buildenv source .buildenv/bin/activate - pip3 install -r test_requirements.txt + pip3 install -e ".[test]" } diff --git a/utils/test-all-linux.sh b/utils/test-all-linux.sh index 704cd8680..4fb2d04b5 100755 --- a/utils/test-all-linux.sh +++ b/utils/test-all-linux.sh @@ -11,7 +11,7 @@ pip3 install -r requirements.txt --require-hashes pip3 install -e . # this does not compile the babel translation-files -pip3 install -r test_requirements.txt +pip3 install -e ".[test]" ./tests/install_noded.sh --bitcoin binary ./tests/install_noded.sh --elements binary