Generator for bootstrapping a Python library.
Homepage Repository npm Download
npm install generator-python-lib@5.0.13
Generator for bootstrapping a Python library.
generator-python-library
scaffolds a basic Python 3 library, including build and test support, and example source files, using your responses to a series of command line prompts.
.pylintrc
for checking code quality.To install generator-python-library
please run the following command:
yarn global add @hutson/generator-python-library
Make sure you have the Yeoman CLI tool, yo
, installed globally. You can install Yeoman via the following command:
yarn global add yo
You will also need to have Python installed on your system to work with your scaffolded Python library.
Create a new directory to host your project and navigate into it:
mkdir my-new-library && cd my-new-library
Then run the generator to scaffold your project:
yo @hutson/python-library
You will be prompted for input that will be used to bootstrap your project. Keep in mind that your responses, and the resulting file contents, can be changed at a later date by re-running the generator.
Once your Python library has been scaffolded you will need to install Pipenv, the preferred package manager:
pip install --no-cache-dir pipenv==2018.11.26
Next, create a virtual environment to house all the development tools needed by your project:
pipenv install --dev --python python
To run a tool inside of the virtual environment:
pipenv run [TOOL]
For example, to check for code quality, run the following:
pipenv run python setup.py lint
To run the project's unit tests against the version of Python installed inside of the virtual environment:
pipenv run python setup.py test
To run your tests against multiple Python interpreters, and check for code quality, we use a tool called tox
. Tox allows you to run your library's unit tests against all versions of Python installed on your system as configured in the tox.ini
file.
pipenv run tox
To generate a code coverage report run the following:
pipenv run python setup.py coverage
A full line-by-line coverage report can be viewed by navigating into the coverage/
directory and opening index.html
in your browser.
For a full list of tasks available from your project's setup.py
file, run the following:
pipenv run python setup.py --help-commands
The development dependencies of the newly scaffolded Python library includes Sphinx, a great tool for building documentation.
Though generator-python-library
includes Sphinx as a development dependency, we do not actually setup a documentation folder, or scaffold documentation files. Sphinx already has an excellent tool for setting up a project's documentation, and we defer to that tool, and the workflow it supports.
To get started with setting up your project's documentation please go through Sphinx's tutorial. You may skip the Install Sphinx section as you've already installed Sphinx by installing the scaffolded project's development dependencies.
If you run the setup script, sphinx-quickstart
, in the root of your project, you'll probably want to set the Root path for the documentation to docs
.
Regarding the questions asked by sphinx-quickstart
, I believe selecting y
, or yes, is a good idea for the following:
Please read through the Basic Usage of Pipenv to better understand how dependencies should be managed.
When declaring a runtime dependency, the dependency should also be included in the install_requires
list of your project's setup.py
file. Furthermore, the dependency should include upper and lower version bounds (though not a specific version).
generator-python-library
may be integrated into other Yeoman generators through Yeoman's composability feature.
First off you will need to add generator-python-library
to your generator's dependencies
:
yarn add @hutson/generator-python-library
To invoke generator-python-library
add the following code to any method in your generator:
this.composeWith(`@hutson/python-library`, {
options: {}
});
If passing options to the generator:
this.composeWith(`@hutson/python-library`, {
options: {
'skip-welcome-message': true
}
});
generator-python-library
supports several options; their default values are listed below.
Options may be provided on the command line, such as passing --projectName=my-project-name
when calling generator-python-library
directly, or via the options argument passed to composeWith
.
When the value for an option is fetched from the working directory's .yo-rc.json
file, or passed as a command line argument, this yeoman generator will not prompt you for the value.
Default: UNDEFINED
Should the generator's welcome message be skipped (suppressed)?
Default: [Name of project folder]
Used as the module name for your Python library.
Default: Previously defined value in .yo-rc.json file or UNDEFINED
Short project description.
Default: Previously defined value in .yo-rc.json file or UNDEFINED
Your full name.
Default: Previously defined value in .yo-rc.json file or UNDEFINED
Contact e-mail for those trying to reach you as the author of the library.
Default: Previously defined value in .yo-rc.json file or UNDEFINED
Your GitLab username.
Default: Previously defined value in .yo-rc.json file or UNDEFINED
URL for the project's homepage.
Default: Previously defined value in .yo-rc.json file or UNDEFINED
Continuous Integration provider, such as Circle CI (option value of Circle CI
).
To assist users of generator-python-library
with debugging the behavior of this module we use the debug utility package to print information about the publish process to the console. To enable debug message printing, the environment variable DEBUG
, which is the variable used by the debug
package, must be set to a value configured by the package containing the debug messages to be printed.
To print debug messages on a unix system set the environment variable DEBUG
with the name of this package prior to executing generator-python-library
:
DEBUG=generator-python-library yo @hutson/python-library
On the Windows command line you may do:
set DEBUG=generator-python-library
yo @hutson/python-library
We only support Long-Term Support versions of Node.
We specifically limit our support to LTS versions of Node, not because this package won't work on other versions, but because we have a limited amount of time, and supporting LTS offers the greatest return on that investment.
It's possible this package will work correctly on newer versions of Node. It may even be possible to use this package on older versions of Node, though that's more unlikely as we'll make every effort to take advantage of features available in the oldest LTS version we support.
As each Node LTS version reaches its end-of-life we will remove that version from the node
engines
property of our package's package.json
file. Removing a Node version is considered a breaking change and will entail the publishing of a new major version of this package. We will not accept any requests to support an end-of-life version of Node. Any merge requests or issues supporting an end-of-life version of Node will be closed.
We will accept code that allows this package to run on newer, non-LTS, versions of Node. Furthermore, we will attempt to ensure our own changes work on the latest version of Node. To help in that commitment, our continuous integration setup runs against all LTS versions of Node in addition the most recent Node release; called current.
JavaScript package managers should allow you to install this package with any version of Node, with, at most, a warning if your version of Node does not fall within the range specified by our node
engines
property. If you encounter issues installing this package, please report the issue to your package manager.
Please read our contributing guide on how you can help improve this project.