Example 3. Create a package with branded namespace import at Level 5
In Example 2, we demonstrated how a package called montypy
, containing the sub-package grail, was created and maintained by Sir Lancelot and Sir Robin in the group
of King Arthur. Now, hypothetically, King Arthur is interested in creating another sub-
package called meaning in the montypy package. To prevent a single package from becoming too bloated, King Arthur has decided that each module should be maintained in a
separate repository as a separate package. King Arthur uses the full benefit of scikit-package with namespace imports, where each package can be developed and imported
as <namespace-name>.<package-name>
. In this case, the package containing the grail
module can be named montypy.grail
, and the package for the meaning
module can be
named montypy.meaning
. Sir Lancelot continues to be the maintainer in the group. In
Example 3, we show how to create two separate packages, each hosted in its own GitHub
repository and managed with a separate local Git database, while still sharing the common
namespace montypy
.
In a conda environment where scikit-package is installed, Sir Lancelot enters the following responses to the scikit-package prompts:
$ package create public
[1/16] maintainer_name (Simon Billinge): Sir Lancelot
[2/16] maintainer_email (sb2896@columbia.edu): sirlancelotbrave@montpy.com
[3/16] maintainer_github_username (sbillinge): sirlancelotbrave
[4/16] contributors (Sangjoon Lee, Simon Billinge, Billinge Group members):
Sir Lancelot, King Arthur,
[5/16] license_holders (The Trustees of Columbia University in the City of New
York): The Knights of the Round Table
[6/16] project_name (diffpy.my-project): montypy.grail
[7/16] github_username_or_orgname (diffpy): kot-roundtable
[8/16] github_repo_name (montypy.grail):
[9/16] conda_pypi_package_dist_name (montypy.grail):
[10/16] package_dir_name (montypy.grail):
The other inputs are the same as those shown in Example 2
...
In the prompts above, once Sir Lancelot has entered the value of project name of
montypy.grail
to get the correct namespace structure. After that, he used the default
values generated by scikit-package based on his first response by pressing the “Enter”
key for github_repo_name
, conda_pypi_package_dist_name
, and package_dir_name
.
Sir Lancelot then runs scikit-package
again with the following prompt responses:
$ package create public
[1/16] maintainer_name (Simon Billinge): Sir Lancelot
[2/16] maintainer_email (sb2896@columbia.edu): sirlancelotbrave@montpy.com
[3/16] maintainer_github_username (sbillinge): sirlancelotbrave
[4/16] contributors (Sangjoon Lee, Simon Billinge, Billinge Group members):
Sir Lancelot, Sir Robin, King Arthur,→
[5/16] license_holders (The Trustees of Columbia University in the City of New
York): The Knights of the Round Table,→
[6/16] project_name (diffpy.my-project): montypy.meaning
[7/16] github_username_or_orgname (diffpy): kot-roundtable
[8/16] github_repo_name (montypy.meaning):
[9/16] conda_pypi_package_dist_name (montypy.meaning):
[10/16] package_dir_name (montypy.meaning):
The other inputs are the same as shown in Example 2
...
After moving over existing code, this resulted in the following folder structure for montypy.grail
,
~/dev/
montypy.grail
|-- src
|-- montypy
|-- __init__.py
|-- utils.py
|-- grail
|-- __init__.py
|-- bridge_of_death.py
|-- black_knight.py
|-- ...
and this for montypy.meaning:
~/dev/
montypy.meaning
|-- src
|-- montypy
|-- __init__.py
|-- utils.py
|-- meaning
|-- __init__.py
|-- mr_creosote.py
|-- the_bucket.py
|-- ...
These can be put under Git control and linked to GitHub repositories, worked on and ultimately released. Now, anyone can install and use these two packages independently. They can be imported into a Python script as shown below:
from montypy.grail import bridge_of_death
from montypy.meaning import mr_creosote
bridge_of_death.sword()
mr_creosote.better()
Each project is hosted on GitHub in separate repositories at https://github.com/kot-roundtable/montypy.grai and https://github.com/kot-roundtable/montypy.meaning. Each project also has access to the benefits available to a Level 5 public
package shown in Example 2.
Currently, a common utils.py module exists in both montypy.grail
and montypy.meaning
. As a useful next step, it would be beneficial to create another package called montypy.utils
so that this module can be shared across all projects maintained by the kot-roundtable GitHub organization, led by King Arthur. This is described in Example 4. Migrate an existing package to Level 5.