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

Update packaging to use more modern python practices #87

Merged
merged 14 commits into from
Aug 16, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.6, 3.7, 3.8]
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions {{cookiecutter.github_project_name}}/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include {{ cookiecutter.npm_package_name }}.json

include LICENSE
include setup.py
include setup.cfg
include pyproject.toml
include install.json

Expand Down
6 changes: 2 additions & 4 deletions {{cookiecutter.github_project_name}}/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{{ cookiecutter.github_project_name }}
===============================
# {{ cookiecutter.github_project_name }}

{{ cookiecutter.project_short_description }}

Installation
------------
## Installation

To install use pip:

Expand Down
64 changes: 47 additions & 17 deletions {{cookiecutter.github_project_name}}/RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
- To release a new version of {{ cookiecutter.python_package_name }} on PyPI:
# Release

Update _version.py (set release version, remove 'dev')
git add the _version.py file and git commit
`python setup.py sdist upload`
`python setup.py bdist_wheel upload`
`git tag -a X.X.X -m 'comment'`
Update _version.py (add 'dev' and increment minor)
git add and git commit
git push
git push --tags
Before doing a release, check to see if there are any outstanding changes or untracked files:

- To release a new version of {{ cookiecutter.npm_package_name }} on NPM:
```
git status
git clean -fdxn
```

Update `js/package.json` with new npm package version
Commit changes, and make sure that any untracked files can be deleted. Then clean the repository:

```
# clean out the `dist` and `node_modules` directories
git clean -fdx
yarn
yarn build:prod
yarn publish
git clean -fdx # actually delete untracked files
```

## Javascript release

To release a new version of {{ cookiecutter.npm_package_name }} on NPM, first register for an NPM account [here](https://www.npmjs.com/), then log in with `yarn login`. Then:

1. Update `js/package.json` with the new npm package version
2. Build and publish the npm package inside the `js/` directory:

```
cd js/
yarn install
yarn publish
cd ..
```

## Python release

To release a new version of {{ cookiecutter.python_package_name }} on PyPI, first make sure that the `build` package is installed: `pip install build`.

1. Update `{{ cookiecutter.python_package_name }}/_version.py`:
- Update `__version__`
- Update `NPM_PACKAGE_RANGE` if necessary
2. Commit changes to `_version.py` and tag the release
```
git add {{ cookiecutter.python_package_name }}/_version.py
git tag -a X.X.X -m 'comment'
```
3. Generate Python packages and upload to PyPI:
```
python -m build
twine check dist/*
twine upload dist/*
```
4. Update `_version.py` (add 'dev' and increment minor)
```
git commit -a -m 'Back to dev'
git push
git push --tags
```
3 changes: 2 additions & 1 deletion {{cookiecutter.github_project_name}}/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "{{ cookiecutter.npm_package_version }}",
"description": "{{ cookiecutter.project_short_description }}",
"author": "{{ cookiecutter.author_name }}",
"license": "BSD-3-Clause",
"main": "lib/index.js",
"repository": {
"type": "git",
Expand Down Expand Up @@ -35,7 +36,7 @@
"rimraf": "^2.6.1"
},
"dependencies": {
"@jupyter-widgets/base": "^1.1 || ^2 || ^3 || ^4",
"@jupyter-widgets/base": "^1.1 || ^2 || ^3 || ^4 || ^6",
"lodash": "^4.17.4"
},
"jupyterlab": {
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.github_project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["jupyter_packaging~=0.7.9", "jupyterlab>=3.0.0,==3.*", "setuptools>=40.8.0", "wheel"]
requires = ["jupyter_packaging~=0.7.9", "jupyterlab~=3.0", "setuptools>=40.8.0", "wheel"]
build-backend = "setuptools.build_meta"
37 changes: 35 additions & 2 deletions {{cookiecutter.github_project_name}}/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
[bdist_wheel]
universal=1
[metadata]
name = {{ cookiecutter.python_package_name }}
author = {{ cookiecutter.author_name }}
author_email={{ cookiecutter.author_email }}
version = attr: {{ cookiecutter.python_package_name }}._version.__version__
description = {{ cookiecutter.project_short_description }}
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/{{ cookiecutter.github_organization_name }}/{{ cookiecutter.github_project_name }}
keywords = ipython, widgets, Jupyter, JupyterLab, JupyterLab3
license = BSD 3-Clause License
classifiers =
License :: OSI Approved :: BSD License
Development Status :: 4 - Beta
Framework :: IPython
Intended Audience :: Developers
Intended Audience :: Science/Research
Programming Language :: Python
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Framework :: Jupyter
Framework :: Jupyter :: JupyterLab
Framework :: Jupyter :: JupyterLab :: 3
Framework :: Jupyter :: JupyterLab :: Extensions
Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt

[options]
zip_safe = False
include_package_data = True
packages = find:
install_requires =
ipywidgets>=7.6.0,<9
python_requires = >=3.7
62 changes: 8 additions & 54 deletions {{cookiecutter.github_project_name}}/setup.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
from __future__ import print_function
from setuptools import setup, find_packages
import os
from os.path import join as pjoin
from distutils import log
from setuptools import setup
from pathlib import Path

from jupyter_packaging import (
create_cmdclass,
install_npm,
ensure_targets,
combine_commands,
get_version,
)


here = os.path.dirname(os.path.abspath(__file__))

name = '{{ cookiecutter.python_package_name }}'
LONG_DESCRIPTION = '{{ cookiecutter.project_short_description }}'

# Get {{ cookiecutter.python_package_name }} version
version = get_version(pjoin(name, '_version.py'))

js_dir = pjoin(here, 'js')
JS_DIR = Path(__file__).resolve().parent / 'js'

# Representative files that should exist after a successful build
jstargets = [
pjoin(js_dir, 'dist', 'index.js'),
]
jstargets = [JS_DIR / 'dist' / 'index.js']

data_files_spec = [
('share/jupyter/nbextensions/{{ cookiecutter.npm_package_name }}', '{{ cookiecutter.python_package_name }}/nbextension', '*.*'),
Expand All @@ -37,40 +22,9 @@

cmdclass = create_cmdclass('jsdeps', data_files_spec=data_files_spec)
cmdclass['jsdeps'] = combine_commands(
install_npm(js_dir, npm=['yarn'], build_cmd='build:prod'), ensure_targets(jstargets),
)

setup_args = dict(
name=name,
version=version,
description='{{ cookiecutter.project_short_description }}',
long_description=LONG_DESCRIPTION,
include_package_data=True,
install_requires=[
'ipywidgets>=7.6.0',
],
packages=find_packages(),
zip_safe=False,
cmdclass=cmdclass,
author='{{ cookiecutter.author_name }}',
author_email='{{ cookiecutter.author_email }}',
url='https://github.com/{{ cookiecutter.github_organization_name }}/{{ cookiecutter.github_project_name }}',
keywords=[
'ipython',
'jupyter',
'widgets',
],
classifiers=[
'Development Status :: 4 - Beta',
'Framework :: IPython',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Topic :: Multimedia :: Graphics',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
install_npm(JS_DIR, npm=['yarn'], build_cmd='build:prod'),
ensure_targets(jstargets),
)

setup(**setup_args)
# See setup.cfg for other parameters
setup(cmdclass=cmdclass)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._version import version_info, __version__
from ._version import __version__

from .example import *

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# Module version
version_info = (0, 1, 0, 'alpha', 0)
__version__ = '0.1.0a0'

# Module version stage suffix map
_specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}

# Module version accessible using {{ cookiecutter.python_package_name }}.__version__
__version__ = '%s.%s.%s%s'%(version_info[0], version_info[1], version_info[2],
'' if version_info[3]=='final' else _specifier_[version_info[3]]+str(version_info[4]))
NPM_PACKAGE_RANGE='^{{ cookiecutter.npm_package_version }}'
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ipywidgets as widgets
from traitlets import Unicode
from ._version import NPM_PACKAGE_RANGE

# See js/lib/example.js for the frontend counterpart to this file.

Expand All @@ -20,9 +21,9 @@ class HelloWorld(widgets.DOMWidget):
_model_module = Unicode('{{ cookiecutter.npm_package_name }}').tag(sync=True)

# Version of the front-end module containing widget view
_view_module_version = Unicode('^{{ cookiecutter.npm_package_version }}').tag(sync=True)
_view_module_version = Unicode(NPM_PACKAGE_RANGE).tag(sync=True)
# Version of the front-end module containing widget model
_model_module_version = Unicode('^{{ cookiecutter.npm_package_version }}').tag(sync=True)
_model_module_version = Unicode(NPM_PACKAGE_RANGE).tag(sync=True)

# Widget specific property.
# Widget properties are defined as traitlets. Any property tagged with `sync=True`
Expand Down