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

Move versionstring from sydent/snapse to common #22

Merged
merged 10 commits into from
Feb 11, 2022
10 changes: 2 additions & 8 deletions matrix_common/versionstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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 functools
import logging
import subprocess
from typing import Dict
Expand All @@ -29,6 +29,7 @@
version_cache: Dict[str, str] = {}


@functools.lru_cache
clokep marked this conversation as resolved.
Show resolved Hide resolved
def get_distribution_version_string(distribution_name: str) -> str:
"""Calculate a git-aware version string for a distribution package.

Expand All @@ -54,11 +55,6 @@ def get_distribution_version_string(distribution_name: str) -> str:
The module version, possibly with git version information included.
"""

# TODO: let's just replace this with @functools.lrucache.
cached_version = version_cache.get(distribution_name)
if cached_version is not None:
return cached_version

distribution = Distribution.from_name(distribution_name)
clokep marked this conversation as resolved.
Show resolved Hide resolved
version_string = distribution.version
cwd = distribution.locate_file(".")
Copy link
Member

Choose a reason for hiding this comment

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

Is locate_file documented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in the stdlib docs (which are surprisingly terse?). It is listed in the backport's API reference though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I'm not even sure if it is a backport. Maybe it's a bit like pip --- an external package later vendored into the stdlib?

Expand Down Expand Up @@ -97,6 +93,4 @@ def _run_git_command(prefix: str, *params: str) -> str:
except Exception as e:
logger.info("Failed to check for git repository: %s", e)

version_cache[distribution_name] = version_string

return version_string