Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing version issue #90

Merged
merged 6 commits into from
Aug 14, 2024
Merged

fixing version issue #90

merged 6 commits into from
Aug 14, 2024

Conversation

polinabinder1
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@jstjohn jstjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion. If it doesn't work then I'll back off. This seems like the wrong way to do it, and deserves a comment explaining why it needs to happen this way at least. Thanks!

import tomli


def get_version_from_pyproject():
"""Get the code version from pyproject.toml file."""
with open("pyproject.toml", "rb") as f:
relative_path = Path(__file__).parents[4] / "pyproject.toml"
Copy link
Collaborator

@jstjohn jstjohn Aug 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the version in the pyproject installed into the package itself? This seems like not the right way to get the version. Chat gpt says you can do this:

import importlib.metadata

def get_package_version(package_name: str) -> str:
return importlib.metadata.version(package_name)

Example usage

package_name = "bionemo.scdl"
version = get_package_version(package_name)
print(f"The installed version of {package_name} is {version}")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that seems like a legit suggestion from chatgpt. Prob the ideal way to do this. If it doesn't work for sub packages then document that in a comment and go ahead with the your current approach. Thanks again! https://docs.python.org/3/library/importlib.metadata.html

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on this suggestion. What do we need a version tag for? It would be ideal to move away from hard-coded versions anywhere in the package, and use setuptools-scm to pull the version from github tags.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pstjohn that's cool. Let's plan that out later though for the auto-versioning. For now I think the focus of this PR should just be on using the correct mechanism (looking in package metadata) for the version. Your solution should also put the version in the metadata so I think if she goes with the importlib.metadata route it will work for getting version info regardless of how it's populated.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for this use case, getting the version is for logging purposes and stored into the metadata of the processed dataset as far as I can tell. This tells us what version of the tool was used to make the dataset. Sorry not sure if that's what you were asking or not @pstjohn.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed the fix.

@polinabinder1
Copy link
Collaborator Author

/build-ci

Copy link
Collaborator

@jstjohn jstjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@polinabinder1 polinabinder1 requested review from pstjohn and removed request for skothenhill-nv August 13, 2024 18:25
@@ -13,11 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import tomli
import importlib.metadata


def get_version_from_pyproject():
Copy link
Collaborator

@jstjohn jstjohn Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have to update this anyways, we could move this to a general place, like bionemo-core/src/bionemo/core/utils/version_utils.py and make the package_name a required arg, like def get_version_from_package(package_name:str) -> str and just have it be the one liner return importlib.metadata.version(package_name) that you have now. Then you could delete this file, and change the place it's used to import/call that thing. This a smaller suggestion for sure, I'm happy with it either way.

Copy link
Collaborator

@pstjohn pstjohn Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a one-liner anyways. Why not just call importlib.metadata.version(package_name) anywhere you need the version, and delete this file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@pstjohn
Copy link
Collaborator

pstjohn commented Aug 13, 2024

i'd rather you just importlib.metadata.version('bionemo.scdl') anywhere you need the version tag

@polinabinder1
Copy link
Collaborator Author

/build-ci

@polinabinder1 polinabinder1 enabled auto-merge (squash) August 14, 2024 18:28
@polinabinder1
Copy link
Collaborator Author

/build-ci

@polinabinder1 polinabinder1 merged commit f7dabbe into v2-main Aug 14, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants