Skip to content

Commit 095381a

Browse files
authored
Merge pull request #458 from telamonian/fix-unipython-build-release
Prep for release of unibundle to Pypi: removed redundant files and eliminated redundant rebuilds
2 parents a78cac8 + 977caab commit 095381a

File tree

6 files changed

+147
-64
lines changed

6 files changed

+147
-64
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ before_install:
99
- nvm install 10
1010
install: pip install pytest "jupyterlab~=1.1"
1111
script:
12+
# Build the sdist (identical to what will be uploaded to eg pypi on release)
1213
- python setup.py sdist
13-
# Install the extension ensuring the cache is unused
14+
# Install the extension from the sdist ensuring the cache is unused
1415
- pip install jupyterlab_git[test] --pre --no-index --find-links=dist --no-deps --no-cache-dir -v
15-
# Install the extension dependencies
16+
# Install the extension dependencies based on the current setup.py
1617
- pip install jupyterlab_git[test]
1718
- jupyter labextension list
1819
- jupyter lab build

MANIFEST.in

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,6 @@ include README.md
33

44
include setupbase.py
55

6-
include package.json
7-
include *.config.js
8-
include setupJest.js
9-
include ts*.json
10-
include jupyterlab_git/labextension/*.tgz
11-
12-
# Tests
13-
graft tests
14-
prune tests/build
15-
16-
# Javascript files
17-
graft schema
18-
graft src
19-
graft style
20-
prune **/node_modules
21-
prune lib
22-
236
# Patterns to exclude from any directory
247
global-exclude *~
258
global-exclude *.pyc

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ pip install --upgrade jupyterlab-git
2424
jupyter lab build
2525
```
2626

27+
### Troubleshooting
28+
29+
- When you run JupyterLab, if you can see the Git sidepanel UI but you cannot get it to work, you may need to explicitly enable the serverextension by running:
30+
31+
```bash
32+
jupyter serverextension enable --py jupyterlab_git
33+
```
34+
2735
## Development
2836

2937
### Contributing
@@ -55,17 +63,19 @@ If you would like to be listed, please submit a pull request with your informati
5563
Requires node 4+ and npm 4+
5664

5765
```bash
66+
# Install new-ish JupyterLab
67+
pip install -U jupyterlab
68+
5869
# Clone the repo to your local environment
5970
git clone https://github.com/jupyterlab/jupyterlab-git.git
6071
cd jupyterlab-git
61-
# Install JupyterLab
62-
pip install jupyterlab
63-
# Install Javascript dependencies
64-
jlpm install
65-
# Install the server extension in development mode
72+
73+
# Install the server extension in development mode and enable it
6674
pip install -e .[test]
6775
jupyter serverextension enable --py jupyterlab_git
68-
# Link your development version of the extension with JupyterLab
76+
77+
# Build the labextension and dev-mode link it to jlab
78+
jlpm build
6979
jupyter labextension link .
7080
```
7181

@@ -81,4 +91,4 @@ To execute the tests
8191
```bash
8292
pytest jupyterlab_git
8393
jlpm run test
84-
```
94+
```

package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
"jupyterlab-extension"
1313
],
1414
"scripts": {
15-
"build": "jlpm run build:lib",
16-
"build:labextension": "cd jupyterlab_git && rimraf labextension && mkdirp labextension && cd labextension && npm pack ../..",
17-
"build:lib": "tsc",
18-
"build:all": "jlpm run build:labextension",
19-
"clean": "jlpm run clean:lib",
20-
"clean:lib": "rimraf lib && rimraf tsconfig.tsbuildinfo",
15+
"build": "jlpm install && tsc",
16+
"build:labextension": "jlpm build && jlpm clean:labextension && mkdirp jupyterlab_git/labextension && cd jupyterlab_git/labextension && npm pack ../..",
17+
"clean": "rimraf lib tsconfig.tsbuildinfo",
18+
"clean:more": "jlpm clean && rimraf build dist MANIFEST",
2119
"clean:labextension": "rimraf jupyterlab_git/labextension",
22-
"clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
23-
"prepare": "jlpm run clean && jlpm run build",
20+
"clean:slate": "jlpm clean:more && jlpm clean:labextension && rimraf node_modules",
2421
"watch": "tsc -w",
2522
"test": "jest",
2623
"lint": "tslint --project .",

release.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python
2+
import argparse as argpar
3+
import json
4+
import subprocess
5+
6+
from setupbase import get_version
7+
8+
VERSION_PY = 'jupyterlab_git/_version.py'
9+
10+
def prepLabextensionBundle():
11+
subprocess.run(['jlpm', 'clean:slate'])
12+
13+
def tag(version, dryrun=False, kind=None):
14+
"""git tagging
15+
"""
16+
kw = {'version': version, 'kind': kind}
17+
tag = '{kind}_v{version}'.format(**kw) if kind else 'v{version}'.format(**kw)
18+
19+
if dryrun:
20+
print("Would tag: {}".format(tag))
21+
else:
22+
subprocess.run(['git', 'tag', tag])
23+
subprocess.run(['git', 'push', 'origin', tag])
24+
25+
def pypi(wheel=True, test=False):
26+
"""release on pypi
27+
"""
28+
if wheel:
29+
# build the source (sdist) and binary wheel (bdist_wheel) releases
30+
subprocess.run(['python', 'setup.py', 'sdist', 'bdist_wheel'])
31+
else:
32+
# build just the source release
33+
subprocess.run(['python', 'setup.py', 'sdist'])
34+
35+
if test:
36+
# release to the test server
37+
subprocess.run(['twine', 'upload', '--repository-url', 'https://test.pypi.org/legacy/', 'dist/*'])
38+
else:
39+
# release to the production server
40+
subprocess.run(['twine', 'upload', 'dist/*'])
41+
42+
def npmjs(dryrun=False):
43+
"""release on npmjs
44+
"""
45+
if dryrun:
46+
# dry run build and release
47+
subprocess.run(['npm', 'publish', '--access', 'public', '--dry-run'])
48+
else:
49+
# build and release
50+
subprocess.run(['npm', 'publish', '--access', 'public'])
51+
52+
def labExtensionVersion(dryrun=False, version=None):
53+
if version:
54+
force_ver_cmd = ['npm', '--no-git-tag-version', 'version', version, '--force', '--allow-same-version']
55+
if dryrun:
56+
print("Would force npm version with: {}".format(' '.join(force_ver_cmd)))
57+
else:
58+
# force the labextension version to match the supplied version
59+
subprocess.run(force_ver_cmd)
60+
else:
61+
# get single source of truth from the Typescript labextension
62+
with open('package.json') as f:
63+
info = json.load(f)
64+
65+
version = info['version']
66+
67+
return version
68+
69+
def serverExtensionVersion():
70+
# get single source of truth from the Python serverextension
71+
return get_version(VERSION_PY)
72+
73+
def doRelease(test=False):
74+
# prep the build area for the labextension bundle
75+
prepLabextensionBundle()
76+
77+
# treat the serverextension version as the "real" single source of truth
78+
version = serverExtensionVersion()
79+
# force the labextension version to agree with the serverextension version
80+
labExtensionVersion(dryrun=test, version=version)
81+
82+
# tag with version and push the tag
83+
tag(dryrun=test, version=version)
84+
85+
# release to pypi and npmjs
86+
pypi(test=test)
87+
npmjs(dryrun=test)
88+
89+
def main():
90+
parser = argpar.ArgumentParser()
91+
92+
parser.add_argument('--test', action='store_true',
93+
help='Release to Pypi test server; performs a dryrun of all other release actions')
94+
95+
parsed = vars(parser.parse_args())
96+
97+
doRelease(test=parsed['test'])
98+
99+
if __name__=='__main__':
100+
main()

setup.py

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
"""Setup Module to setup Python serverextension for the jupyterlab git
2+
extension. For non-dev installs, will also automatically
3+
build (if package.json is present) and install (if the labextension exists,
4+
eg the build succeeded) the corresponding labextension.
15
"""
2-
Setup Module to setup Python Handlers (Git Handlers) for the Git Plugin.
3-
"""
4-
from os.path import join as pjoin
6+
from pathlib import Path
7+
from subprocess import CalledProcessError
58

69
from setupbase import (
7-
create_cmdclass, install_npm, ensure_targets,
8-
combine_commands, ensure_python, get_version,
9-
HERE
10+
command_for_func, create_cmdclass, ensure_python,
11+
get_version, HERE, run
1012
)
1113

1214
import setuptools
@@ -18,36 +20,27 @@
1820
ensure_python('>=3.5')
1921

2022
# Get our version
21-
version = get_version(pjoin(name, '_version.py'))
22-
23-
lab_path = pjoin(HERE, name, 'labextension')
24-
25-
# Representative files that should exist after a successful build
26-
jstargets = [
27-
pjoin(HERE, 'lib', 'git.js'),
28-
]
23+
version = get_version(str(Path(name) / '_version.py'))
2924

30-
package_data_spec = {
31-
name: [
32-
'*'
33-
]
34-
}
25+
lab_path = Path(HERE) / name / 'labextension'
3526

3627
data_files_spec = [
37-
('share/jupyter/lab/extensions', lab_path, '*.tgz'),
28+
('share/jupyter/lab/extensions', str(lab_path), '*.tgz'),
3829
('etc/jupyter/jupyter_notebook_config.d',
3930
'jupyter-config/jupyter_notebook_config.d', 'jupyterlab_git.json'),
4031
]
4132

42-
cmdclass = create_cmdclass('jsdeps',
43-
package_data_spec=package_data_spec,
44-
data_files_spec=data_files_spec
45-
)
33+
def runPackLabextension():
34+
if Path('package.json').is_file():
35+
try:
36+
run(['jlpm', 'build:labextension'])
37+
except CalledProcessError:
38+
pass
39+
pack_labext = command_for_func(runPackLabextension)
4640

47-
cmdclass['jsdeps'] = combine_commands(
48-
install_npm(HERE, build_cmd='build:all', npm='jlpm'),
49-
ensure_targets(jstargets),
50-
)
41+
cmdclass = create_cmdclass('pack_labext', data_files_spec=data_files_spec)
42+
cmdclass['pack_labext'] = pack_labext
43+
cmdclass.pop('develop')
5144

5245
with open("README.md", "r") as fh:
5346
long_description = fh.read()
@@ -76,7 +69,6 @@
7669
'Programming Language :: Python :: 3.7',
7770
'Framework :: Jupyter',
7871
],
79-
include_package_data = True,
8072
install_requires = [
8173
'notebook',
8274
'nbdime >= 1.1.0',
@@ -85,7 +77,7 @@
8577
extras_require = {
8678
'test': [
8779
'pytest',
88-
'jupyterlab~=1.0',
80+
'jupyterlab~=1.1',
8981
],
9082
},
9183
)

0 commit comments

Comments
 (0)