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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version checking with importlib and versioneer config update #1048

Merged
merged 9 commits into from Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
@@ -1 +1 @@
neptune/_version.py export-subst
src/neptune/_version.py export-subst
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
### Fixes
- Update jsonschema requirement with explicit `format` specifier ([#1010](https://github.com/neptune-ai/neptune-client/pull/1010))
- Escape inputs to SQL in Artifact LocalFileHashStorage ([#1034](https://github.com/neptune-ai/neptune-client/pull/1034))
- Version checking with importlib and versioneer config update ([#1048](https://github.com/neptune-ai/neptune-client/pull/1048))

### Changes
- More consistent and strict way of git repository, source files and entrypoint detection ([#1007](https://github.com/neptune-ai/neptune-client/pull/1007))
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -17,3 +17,4 @@ dataclasses>=0.6; python_version<"3.7"
swagger-spec-validator>=2.7.4
psutil
jsonschema[format]<4.0.0
importlib-metadata<4; python_version<"3.8.0"
4 changes: 1 addition & 3 deletions src/neptune/__init__.py
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from neptune._version import get_versions
from neptune.legacy import (
ANONYMOUS,
ANONYMOUS_API_TOKEN,
Expand Down Expand Up @@ -46,5 +45,4 @@
set_property,
stop,
)

__version__ = get_versions()["version"]
from neptune.version import __version__
3 changes: 2 additions & 1 deletion src/neptune/_version.py
Expand Up @@ -44,7 +44,8 @@ def get_config():
cfg.style = "pep440"
cfg.tag_prefix = ""
cfg.parentdir_prefix = ""
cfg.versionfile_source = "neptune/_version.py"
cfg.versionfile_source = "src/neptune/_version.py"
cfg.versionfile_build = "neptune/_version.py"
cfg.verbose = False
return cfg

Expand Down
7 changes: 3 additions & 4 deletions src/neptune/new/version.py
Expand Up @@ -13,9 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from packaging import version
from packaging.version import parse

from neptune._version import get_versions
from neptune.version import __version__

version = version.parse(get_versions()["version"])
del get_versions
version = parse(__version__)
33 changes: 33 additions & 0 deletions src/neptune/version.py
@@ -0,0 +1,33 @@
#
# Copyright (c) 2022, Neptune Labs Sp. z o.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys

if sys.version_info >= (3, 8):
from importlib.metadata import (
PackageNotFoundError,
version,
)
else:
from importlib_metadata import (
PackageNotFoundError,
version,
)

try:
__version__ = version("neptune-client")
except PackageNotFoundError:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is possible catch PackageNotFoundError when python has the src/neptune/version.py in path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

importlib.metdata.version("something") works similarly to pip list | grep something instead of checking the current namespace.
For instance typing is a proper builtin package but:

>>> import typing
>>> importlib.metadata.version("typing")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/neptune/.conda/envs/neptune-client/lib/python3.10/importlib/metadata/__init__.py", line 984, in version
    return distribution(distribution_name).version
  File "/Users/neptune/.conda/envs/neptune-client/lib/python3.10/importlib/metadata/__init__.py", line 957, in distribution
    return Distribution.from_name(distribution_name)
  File "/Users/neptune/.conda/envs/neptune-client/lib/python3.10/importlib/metadata/__init__.py", line 548, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for typing

so I think that nothing will impact it except pip install neptune-client or pip install -e . or pip install . (including direct call to python setup.py install)

# package is not installed
pass