canonical / jhack

Chock-full of Juju hackery.
Apache License 2.0
48 stars 23 forks source link

jenv only works when installed with '-e' #80

Closed dstathis closed 1 year ago

dstathis commented 1 year ago

jenv reports the jhack version by reading pyproject.toml. In a normal installation, the file does not exist.

A solution that should work would be to add a MANIFEST.in file. See cos-alerter for an example. Never mind this doesn't work because the file is outside the package directory.

dstathis commented 1 year ago

Problem still exists in main branch.

(venv) dylan@protostar:~/repos/jhack$ jhack jenv
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/dylan/repos/jhack/venv/lib/python3.10/site-packages/jhack/utils/print_env.py:103 in        │
│ print_env                                                                                        │
│                                                                                                  │
│   100 │                                                                                          │
│   101 │   multipass_version = get_multipass_version()                                            │
│   102 │   data = {                                                                               │
│ ❱ 103 │   │   "jhack": get_jhack_version(),                                                      │
│   104 │   │   "python": python_version,                                                          │
│   105 │   │   "juju-* snaps": _gather_juju_snaps_versions(format=format),                        │
│   106 │   │   "microk8s": get_output("microk8s version") or NOT_INSTALLED,                       │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │            format = <Format.auto: 'auto'>                                                    │ │
│ │ multipass_version = {}                                                                       │ │
│ │          python_v = sys.version_info(major=3, minor=10, micro=6, releaselevel='final',       │ │
│ │                     serial=0)                                                                │ │
│ │    python_version = '3.10.6 (/home/dylan/repos/jhack/venv/bin/python3)'                      │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /home/dylan/repos/jhack/venv/lib/python3.10/site-packages/jhack/utils/print_env.py:73 in         │
│ get_jhack_version                                                                                │
│                                                                                                  │
│    70 │   │   pyproject_toml = (                                                                 │
│    71 │   │   │   Path(__file__).parent.parent.parent.absolute().joinpath("pyproject.toml")      │
│    72 │   │   )                                                                                  │
│ ❱  73 │   │   return toml.loads(pyproject_toml.read_text())["project"]["version"]                │
│    74                                                                                            │
│    75                                                                                            │
│    76 def get_multipass_version():                                                               │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ pyproject_toml = PosixPath('/home/dylan/repos/jhack/venv/lib/python3.10/site-packages/pypro… │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /usr/lib/python3.10/pathlib.py:1134 in read_text                                                 │
│                                                                                                  │
│   1131 │   │   Open the file in text mode, read it, and close the file.                          │
│   1132 │   │   """                                                                               │
│   1133 │   │   encoding = io.text_encoding(encoding)                                             │
│ ❱ 1134 │   │   with self.open(mode='r', encoding=encoding, errors=errors) as f:                  │
│   1135 │   │   │   return f.read()                                                               │
│   1136 │                                                                                         │
│   1137 │   def write_bytes(self, data):                                                          │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ encoding = 'locale'                                                                          │ │
│ │   errors = None                                                                              │ │
│ │     self = PosixPath('/home/dylan/repos/jhack/venv/lib/python3.10/site-packages/pyproject.t… │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /usr/lib/python3.10/pathlib.py:1119 in open                                                      │
│                                                                                                  │
│   1116 │   │   """                                                                               │
│   1117 │   │   if "b" not in mode:                                                               │
│   1118 │   │   │   encoding = io.text_encoding(encoding)                                         │
│ ❱ 1119 │   │   return self._accessor.open(self, mode, buffering, encoding, errors,               │
│   1120 │   │   │   │   │   │   │   │      newline)                                               │
│   1121 │                                                                                         │
│   1122 │   def read_bytes(self):                                                                 │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ buffering = -1                                                                               │ │
│ │  encoding = 'locale'                                                                         │ │
│ │    errors = None                                                                             │ │
│ │      mode = 'r'                                                                              │ │
│ │   newline = None                                                                             │ │
│ │      self = PosixPath('/home/dylan/repos/jhack/venv/lib/python3.10/site-packages/pyproject.… │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
FileNotFoundError: [Errno 2] No such file or directory: 
'/home/dylan/repos/jhack/venv/lib/python3.10/site-packages/pyproject.toml'