Repository: biopython/biopython

Issue:
Biopython is not installable as a git repository with Poetry
### Setup

I am reporting a problem with Biopython version, Python version, and operating
system as follows:

```shell
❯ python -c 'import sys; print(sys.version)'
3.10.9 (main, Dec  7 2022, 01:12:00) [GCC 9.4.0]
```

```shell
❯ python -c 'import platform; print(platform.python_implementation()); print(platform.platform())'
CPython
Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
```

(This is an install issue, so certainly no install)
```shell
❯ python -c 'import Bio; print(Bio.__version__)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'Bio'
```

### Expected behaviour

With the following in `pyproject.toml` under `[tool.poetry.dependencies]`:

```toml
biopython = { git = "https://github.com/biopython/biopython", rev="ca64586b1c6f6c8439c88e576fed091c923ad8f1" }
```

running `poetry lock` should update with the relevant biopython package.

### Actual behaviour

```shell
❯ poetry lock
Updating dependencies
Resolving dependencies... (0.0s)

Invalid version 'Undefined' on package biopython
```

### Steps to reproduce

Follow the above steps.

### Suggested Remediation

- Option A: Add a `setup.cfg` with version information as [here](https://packaging.python.org/en/latest/guides/single-sourcing-package-version/)
- Option B: Move to [PEP 518 pyproject.toml](https://peps.python.org/pep-0518/) 


Discussion:
So poetry is failing here, perhaps it just parses ``setup.py`` rather than executing it:

https://github.com/biopython/biopython/blob/ca64586b1c6f6c8439c88e576fed091c923ad8f1/setup.py#L206

I take it the revision ca64586b1c6f6c8439c88e576fed091c923ad8f1 in your example is because you need something more recent than the currently release (Biopython 1.81), in which case an easier option for us is:

* Option C: Release Biopython 1.82

If you wanted to work on updating our build system, that'd be welcome. Last time I tried this on a moderately complex project it was not straightforward so I'm wary.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -25,6 +25,7 @@
 
 import sys
 import os
+import ast
 
 try:
     from setuptools import setup
@@ -200,13 +201,16 @@ def can_import(module_name):
     Extension("Bio.SeqIO._twoBitIO", ["Bio/SeqIO/_twoBitIO.c"]),
 ]
 
-# We now define the Biopython version number in Bio/__init__.py
-# Here we can't use "import Bio" then "Bio.__version__" as that would
-# tell us the version of Biopython already installed (if any).
-__version__ = "Undefined"
-for line in open("Bio/__init__.py"):
-    if line.startswith("__version__"):
-        exec(line.strip())
+
+def get_version():
+    """Get version number from __init__.py."""
+    for line in open("Bio/__init__.py"):
+        if line.startswith("__version__ = "):
+            return ast.literal_eval(line.split("=")[1].strip())
+    return "Undefined"
+
+
+__version__ = get_version()
 
 # We now load in our reStructuredText README.rst file to pass explicitly in the
 # metadata, since at time of writing PyPI did not do this for us.


Test patch: