Skip to content

Commit

Permalink
fix: failing to find version when packaged without pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
meramsey committed Apr 16, 2022
1 parent aac4216 commit a6160f6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
5 changes: 2 additions & 3 deletions src/wizardwebssh/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from tornado.options import define

from wizardwebssh.policy import check_policy_setting, get_policy_class, load_host_keys
from wizardwebssh.utils import get_app_version, is_valid_encoding, parse_origin_from_url, to_ip_address

version = get_app_version()
from wizardwebssh.utils import is_valid_encoding, parse_origin_from_url, to_ip_address
from importlib_metadata import version


def print_version(flag):
Expand Down
19 changes: 0 additions & 19 deletions src/wizardwebssh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,3 @@ def parse_origin_from_url(url):
netloc = parsed.netloc

return "{}://{}".format(scheme, netloc)


def _get_project_meta():
pyproject_path = os.path.join(
os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), "pyproject.toml"
)
with open(pyproject_path) as pyproject:
file_contents = pyproject.read()

return tomlkit.parse(file_contents)["tool"]["poetry"]


def get_app_version():
pkg_meta = _get_project_meta()
pkg_name = str(pkg_meta["name"])
# The short X.Y version
pkg_version = str(pkg_meta["version"])

return pkg_version
5 changes: 2 additions & 3 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import paramiko
import tornado.options as options

from importlib_metadata import version
from tests.utils import make_tests_data_path
from wizardwebssh.policy import load_host_keys
from wizardwebssh.settings import (
Expand All @@ -20,7 +20,6 @@
get_ssl_context,
get_trusted_downstream,
print_version,
version,
)
from wizardwebssh.utils import UnicodeType

Expand All @@ -35,7 +34,7 @@ def test_print_version(self):

with self.assertRaises(SystemExit):
self.assertEqual(print_version(True), None)
self.assertEqual(sys.stdout.getvalue(), version + "\n")
self.assertEqual(sys.stdout.getvalue(), str(version) + "\n")

sys.stdout = sys_stdout

Expand Down

0 comments on commit a6160f6

Please sign in to comment.