A skeleton of a Python package with CLI and test suite included. Taken from pyskel and modified slightly for quickstarting British Columbia python packages as per BC's guide.
To use pyskel_bc as the start of a new project, do the following, preferably in a virtual environment.
-
Clone the repo:
git clone https://github.com/smnorris/pyskel_bc myproject cd myproject
-
Replace all occurrences of 'pyskel_bc' with the name of your own project. (Note: the commands below require bash, find, and sed and are yet tested only on OS X.)
if [ -d pyskel_bc ]; then find . -not -path './.git*' -type f -exec sed -i '' -e 's/pyskel_bc/myproject/g' {} + ; fi mv pyskel_bc myproject
-
Install in locally editable (
-e
) mode and run the tests:pip install -e .[test] py.test
-
Give the command line program a try:
myproject --help myproject 4
-
Test with tox if you are supporting multiple versions of Python:
tox
To help prevent uncustomized forks of pyskel_bc from being uploaded to PyPI, the setup's upload command is configured to dry run. Make sure to remove this configuration from setup.cfg when you customize pyskel_bc.
A post on the Mapbox blog has more information about this project.
-
Open a windows command prompt and ensure that ArcGIS Python and scripts are inlcuded in the PATH. If a 64bit ArcGIS Python is available, use it:
set PATH="E:\sw_nt\Python27\ArcGISx6410.3";"E:\sw_nt\Python27\ArcGISx6410.3\Scripts";%PATH%
-
Ensure pip is available, install if it is not (to your workspace, not the system Python).
-
Create and enable a virtualenv for testing/development so we don't have to worry about conflicting with system installed python packages:
pip install --user virtualenv # (if necessary) mkdir myproject_env virtualenv myproject_env myproject_env\Scripts\activate
-
If ArcGIS/arcpy is required by the module, ensure we can reach the arcpy module from the virtualenv (based on this USGS guide) by creating a file
Lib\site-packages\ArcGIS.pth
within the virtual environment folder. Include these lines (or similar, check for required 32 bit paths by starting ArcMap and typingimport sys; print sys.path
into the python window):# ArcGIS.pth # Path to ArcGIS arcpy modules # Place in folder ...\<path to your virtual environment>\lib\site-packages\ E:\\sw_nt\\Python27\\ArcGISx6410.3 E:\\sw_nt\\Python27\\ArcGISx6410.3\\Lib E:\\sw_nt\\Python27\\ArcGISx6410.3\\DLLs E:\\sw_nt\\Python27\\ArcGISx6410.3\\Lib\\lib-tk E:\\sw_nt\\Python27\\ArcGISx6410.3\\lib\\site-packages E:\\sw_nt\\Python27\\ArcGISx6410.3\\lib\\site-packages\\win32 E:\\sw_nt\\Python27\\ArcGISx6410.3\\lib\\site-packages\\win32\\lib E:\\sw_nt\\Python27\\ArcGISx6410.3\\lib\\site-packages\\Pythonwin E:\\sw_nt\\ArcGIS\\Desktop10.3\\bin64 E:\\sw_nt\\ArcGIS\\Desktop10.3\\ArcPy E:\\sw_nt\\ArcGIS\\Desktop10.3\\ArcToolBox\\Scripts
-
Clone the repository using your tool of choice:
git clone https://github.com/smnorris/pyskel_bc.git
-
Replace all occurrences of 'pyskel_bc' with the name of your own project using your tool of choice. See quick start above for a bash command.
-
Back at the windows command prompt, within the virtual environment:
cd myproject pip install -e .[test]
-
Give the command line program a try:
myproject --help myproject 4
-
If required, activate the virtualenv within an ArcGIS session by issuing this command from the ArcGIS python window (as per this question on StackOverflow):
execfile(r'<path_to_env>\Scripts\activate_this.py', {'__file__': r'<path_to_env>\Scripts\activate_this.py'}) import myproject
Here are a few other tools for initializing Python projects:
- Paste Script's paster create
- cookiecutter-pypackage is a Cookiecutter template for a Python package. Cookiecutter supports many languages, includes Travis configuration and much more.
Copyright 2018 Province of British Columbia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.