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

Fix for #921: unifies versioning between JS and Python libraries #923

Merged
merged 4 commits into from
Feb 20, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@
"fix_python": "node scripts/lint_python.js --fix",
"fix": "npm-run-all --silent fix:*",
"toggle_puppeteer": "node scripts/toggle_puppeteer.js",
"version": "node scripts/version_python.js"
"version": "python3 python/perspective/scripts/write_version.py && git add python/perspective/perspective/core/_version.py"
}
}
19 changes: 0 additions & 19 deletions python/perspective/.bumpversion.cfg

This file was deleted.

6 changes: 1 addition & 5 deletions python/perspective/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ prune docs/build
prune docs/gh-pages
prune docs/dist

# Webapp files
# Use package.json for versioning
include package.json
include webpack.config.js
graft dist/src
graft style
graft js

# C++ build
graft dist/cmake
Expand Down
12 changes: 5 additions & 7 deletions python/perspective/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))


# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down Expand Up @@ -56,17 +55,16 @@
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
_version_py = os.path.join('..', 'perspective', 'core', '_version.py')
version_ns = {}
_version_py = os.path.join('..', 'perspective', 'core', '_version.py')
version_ns = {}

with open(_version_py, mode='r') as version_file:
with open(_version_py, mode='r') as version_file:
exec(version_file.read(), version_ns)

# The short X.Y version.
version = '%i.%i' % version_ns['version_info'][:2]
version = version_ns["__version__"]
# The full version, including alpha/beta/rc tags.
release = version_ns['__version__']
release = version

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
32 changes: 2 additions & 30 deletions python/perspective/perspective/core/_version.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,2 @@
################################################################################
#
# Copyright (c) 2019, the Perspective Authors.
#
# This file is part of the Perspective library, distributed under the terms of
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

from collections import namedtuple

VersionInfo = namedtuple('VersionInfo', [
'major',
'minor',
'micro',
'releaselevel',
'serial'
])

# DO NOT EDIT THIS DIRECTLY! It is managed by bumpversion
version_info = VersionInfo(0, 4, 2, 'final', 0)

_specifier_ = {'alpha': 'alpha', 'beta': 'beta', 'rc': 'rc', 'final': ''}

__version__ = '{}.{}.{}{}'.format(
version_info.major,
version_info.minor,
version_info.micro,
(''
if version_info.releaselevel == 'final'
else _specifier_[version_info.releaselevel] + "." + str(version_info.serial)))
__version__ = "0.4.3"
major_minor_version = "0.4"
5 changes: 3 additions & 2 deletions python/perspective/perspective/widget/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ..core.exception import PerspectiveError
from ..libpsp import is_libpsp
from ..viewer import PerspectiveViewer
from ..core._version import major_minor_version


def _type_to_string(t):
Expand Down Expand Up @@ -141,10 +142,10 @@ class PerspectiveWidget(Widget, PerspectiveViewer):
# Required by ipywidgets for proper registration of the backend
_model_name = Unicode('PerspectiveModel').tag(sync=True)
_model_module = Unicode('@finos/perspective-jupyterlab').tag(sync=True)
_model_module_version = Unicode('^0.4.0-rc.2').tag(sync=True)
_model_module_version = Unicode("~{}".format(major_minor_version)).tag(sync=True)
_view_name = Unicode('PerspectiveView').tag(sync=True)
_view_module = Unicode('@finos/perspective-jupyterlab').tag(sync=True)
_view_module_version = Unicode('^0.4.0-rc.2').tag(sync=True)
_view_module_version = Unicode("~{}".format(major_minor_version)).tag(sync=True)

def __init__(self,
table_or_data,
Expand Down
53 changes: 53 additions & 0 deletions python/perspective/scripts/write_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
################################################################################
#
# Copyright (c) 2019, the Perspective Authors.
#
# This file is part of the Perspective library, distributed under the terms of
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

import os
import json
import logging

logging.basicConfig(level=logging.INFO)


def truncate_patch_version(version):
"""Return just the major and minor versions from `version`."""
split_version = version.split(".")
return "{}.{}".format(split_version[0], split_version[1])


def write_version():
"""Retrieves the version string from `package.json` managed by Lerna,
and writes it into `_version.py`. This script is run as part of Lerna's
"version" task, which ensures that changes are made `after` the version
has been updated, but `before` the changes made as part of `lerna version`
are committed."""
logging.info("Updating Python `__version__` from `package.json`")

here = os.path.abspath(os.path.dirname(__file__))
package_json_path = os.path.join(here, "..", "package.json")
version = None

with open(os.path.realpath(package_json_path), "r") as f:
version = json.load(f)["version"]

logging.info("Updating `perspective-python` to version `{}`".format(version))

version_py_path = os.path.join(here, "..", "perspective", "core", "_version.py")

# PerspectiveWidget uses the major and minor versions for semver only.
truncated = truncate_patch_version(version)

with open(os.path.realpath(version_py_path), "w") as f:
f.write('__version__ = "{}"\n'.format(version))
f.write('major_minor_version = "{}"\n'.format(truncated))

logging.info("`perspective-python` updated to version `{}`".format(version))
logging.info("`PerspectiveWidget` now requires `perspective-jupyterlab` version `~{}`".format(truncated))


if __name__ == "__main__":
write_version()
6 changes: 1 addition & 5 deletions scripts/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ const {execute} = require("./script_utils.js");
try {
execute`mkdirp docs/build docs/obj`;
const project = process.env.PSP_PROJECT;
if (!project || project === "js") {
if (!project || project === "js" || project === "python") {
Copy link
Member

Choose a reason for hiding this comment

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

prob don't need js anymore here either due to #912

execute`lerna run docs --silent --stream --scope=${process.env.PACKAGE}`;
}

if (!project || project === "python") {
execute`lerna run docs --silent --stream --scope=perspective-python.node`;
}
} catch (e) {
console.log(e.message);
process.exit(1);
Expand Down
56 changes: 0 additions & 56 deletions scripts/version_python.js

This file was deleted.