Giter Club home page Giter Club logo

python-template's Introduction

Netherlands eScience Center Python Template

Spend less time setting up and configuring your new Python packages and comply with the Netherlands eScience Center Software Development Guide from the start.

Use this Cookiecutter template to generate an empty Python package. Features include:

Badges

fair-software.nl recommendations
(1/5) code repository github repo badge
(2/5) license github license badge
(3/5) community registry RSD
(4/5) citation DOI
(5/5) checklist  
overall fair-software badge
Other best practices  
   
GitHub Actions  
Citation metadata consistency cffconvert
MarkDown link checker markdown-link-check
Tests tests

How to use

Step 1/3: Install cookiecutter

We recommend installing cookiecutter in user space as per cookiecutter's instructions. This way, you don't have to install cookiecutter for every new project.

python -m pip install --user --upgrade cookiecutter

Step 2/3: Generate the files and directory structure

Run cookiecutter with the template:

# Notes:
#   1. See table below for explanation of each question
#   2. The files will be generated in a new directory
cookiecutter https://github.com/nlesc/python-template.git
Name Default value Explanation
directory_name my-python-project Name of the directory that contains the package. Avoid using spaces or uppercase letters for the best experience across operating systems. To get an impression of what will be generated, see the directory tree below
package_name my_python_package Name of the package. Avoid using spaces, dashes, or uppercase letters for the best experience across operating systems.
package_short_description Short description of package The information that you enter here will end up in the README, documentation, license, and pyproject.toml, so it may be a good idea to prepare something in advance.
keyword1 keyword1 A term that describes your package.
keyword2 keyword2 Another term that describes your package.
version 0.1.0  
github_organization <my-github-organization> GitHub organization that will contain this project's repository. This can also be your GitHub user name.
license Apache Software License 2.0 The software license under which the code is made available.
full_name Jane Smith Your full name, e.g. Jane Smith.
email [email protected] Your (work) email address.
copyright_holder Netherlands eScience Center Name(s) of the organization(s) or person(s) who hold the copyright of the software.
code_of_conduct_email [email protected] Email address of the person who should be contacted in case of violations of the Code of Conduct.

Once the project files have been generated, follow the steps outlined in {{cookiecutter.directory_name}}/next_steps.md.

Step 3/3: Read about what was just generated

Good job! You have now generated the skeleton for your package:

my-python-project/
├── CHANGELOG.md
├── CITATION.cff
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── docs
│   ├── conf.py
│   ├── index.rst
│   ├── make.bat
│   ├── Makefile
│   ├── _static
│   │   └── theme_overrides.css
│   └── _templates
│       └── .gitignore
├── .editorconfig
├── .githooks
│   └── pre-commit
├── .github
│   ├── next_steps
│   │   ├── 01_sonarcloud_integration.md
│   │   ├── 02_citation.md
│   │   ├── 03_readthedocs.md
│   │   ├── 04_zenodo_integration.md
│   │   └── 05_linting.md
│   └── workflows
│       ├── build.yml
│       ├── cffconvert.yml
│       ├── lint.yml
│       ├── markdown-link-check.yml
│       ├── next_steps.yml
│       └── sonarcloud.yml
├── .gitignore
├── LICENSE
├── MANIFEST.in
├── .mlc-config.json
├── my_python_package
│   ├── __init__.py
│   ├── my_module.py
│   └── __version__.py
├── next_steps.md
├── NOTICE
├── project_setup.md
├── .pylintrc
├── pyproject.toml
├── README.dev.md
├── README.md
├── sonar-project.properties
└── tests
    ├── __init__.py
    └── test_my_module.py

For an explanation of what's there, read on in the project_setup.md file. There are also instructions on how to apply the template to an existing Python package.

Examples

Many developers have gone before you in using this template to get started quickly. Check out their projects in the list below:

  1. Cerise: https://github.com/MD-Studio/cerise
  2. cerulean: https://github.com/MD-Studio/cerulean
  3. cffconvert: https://github.com/citation-file-format/cff-converter-python
  4. fairtally: https://github.com/fair-software/fairtally
  5. howfairis: https://github.com/fair-software/howfairis
  6. matchms: https://github.com/matchms/matchms
  7. MUSCLE 3: https://github.com/multiscale/muscle3
  8. pycff: https://github.com/citation-file-format/pycff
  9. spec2vec: https://github.com/iomega/spec2vec
  10. yatiml: https://github.com/yatiml/yatiml
  11. ... And many more (see this discussion). Make a PR to add your project here, or simply ping us in an issue!

How to contribute

Suggestions/improvements/edits are most welcome. Please read the contribution guidelines before creating an issue or a pull request.

python-template's People

Contributors

abelsiqueira avatar apalha avatar benvanwerkhoven avatar bouweandela avatar bvreede avatar cunlianggeng avatar cwmeijer avatar egpbos avatar eriktks avatar evertrol avatar f-hafner avatar fdiblen avatar jspaaks avatar lourensveen avatar sjvrijn avatar sverhoeven avatar tbkkr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-template's Issues

Generated README contains badges for cffconvert

For most of the badges, putting in the user's slug is going to be correct or at least a much better approximation of the correct value than having cff-converter-python in there. That's exactly why we're using cookiecutter!

.rst or .md for documentation?

Sphinx can be configured to use markdown for documentation instead of (or in addition to) .rst. I always find it a bit schizophrenic to have a README.md and then use .rst for the documentation. Also, markdown is easier to use (I guess this depends on what you are used to).

So, what do we recommend?

Use PyTest?

I really like PyTest, and the guide says it's preferred over plain unittest and nose. Do we all agree on that? If so, I can submit a pull request for a port of the example test case to PyTest.

Distinguish between Python 2 and 3 support

The template should ask whether the user wants Python 2 and Python 3 support (both should be possible). As more libraries are dropping Python 2 support (e.g., pylint), requirements, etc. should be adapted based on Python version.

The readme you get after running cookiecutter should use git clone over https instead of git

GitHub recommends using the https url for cloning. So instead of:

https://github.com/NLeSC/python-template/blame/a34b25535bd9b98d52fc581ce393fd1a6bbecb76/%7B%7Bcookiecutter.project_slug%7D%7D/README.rst#L140

git clone [email protected]:{{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}.git

we should do

git clone https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}.git

I can't say I really understand/remember the reason, but if I use the first option, I always get a "Permission denied (publickey)." error.

test_lint is a hack

The generated repository contains a tests/test_lint.py file which calls a linter. A nicer solution that was probably not available when this was first made is to use the PyTest plugins pytest-codestyle and pytest-docstyle. Note that the main directory must be added to the testpaths in setup.cfg for them to check the source of the program, rather than only the tests.

Shouldn't cookiecutter be installed in user space?

We could change the text of the README to something like

Install cookiecutter in user space (make sure that ~/.local/bin is on the path)

pip3 install --user cookiecutter

Not sure it should say pip or pip3, on my Ubuntu based system I still get Python2 if I do pip...

I would then put it as the first step.

Rename repository

The empty nlesc Python project could have a better name.

Ideas:

  • nlesc-python

Suggestions are welcome!

Encoding tags are obsolete

The generated Python files contain an encoding tag which sets the source encoding to UTF-8. In Python 2, this is useful, as the default is 7-bit ASCII, but in Python 3 the default is already UTF-8, so the tags are superfluous. And since Python 2 is deprecated, they can be removed.

Add install_requires to setup.py

To specify which dependencies your package has install_requires=['mydep'] in setup.py should be used.

Now the setup.py does not contain that key, making it hard to find how to specify package dependencies.

Add pytest-mypy

We have mypy configuration in setup.cfg, but mypy isn't run automatically. There's a mypy plug-in for pytest that runs mypy automatically as part of the test suite.

I like it, but I guess there are quite a few people who don't use type annotations yet. Then again, they can always remove it. So should the default be to run mypy as part of the tests, using pytest-mypy?

Choose code quality/coverage tool?

The guide specifies three code quality/coverage tools: codacy, Scrutinizer, and Landscape, but does not make a recommendation.

Do we recommend one? If so, which one? I have only used codacy, so I can't really recommend anything else...

Git ignore more

Added the following items to .gitignore file:

  • coverage.xml
  • docs/apidocs (doc/apidoc is already ignored, but shpinx is configured to write to docs/apidocs)
  • IDE config files

This will reduce accidental git adds.

Show external usage on RSD

To show impact of the template, it would be nice if we could link to external software for which the template was used. Maybe we can stimulate external users to report usage and/or have an automated process that does this.

Installing development tools

The current set-up has the development tools listed in setup.py, and has you install them via python setup.py .[dev]. This command does two things: it installs your package and its dependencies into your local environment, and it installs the development tools into your local environment.

Next, if you run python setup.py test, setuptools will create a separate environment, install your package in it and any dependencies that aren't already in your local environment, and then run your tests. They pass, you push, and your CI fails, because it runs python setup.py test in a clean environment (not having done python setup.py .[dev] some time ago) and so ends up with a newer version of a library that breaks your code. Locally, it works because it's using the stale dependency that was installed when you installed the development tools.

So I don't like having my package and especially its dependencies installed in my working environment, because it makes my environment less similar to the one on the CI. But the way things are now set up, I can't have that unless I either manually install the development tools, or install them using setup.py and then manually uninstall my own package.

So I'd propose using a requirements-dev.txt instead with a list of development tools, so that you can pip install -r requirements-dev.txt them. But this stuff is complicated, and I'm probably missing some considerations. Comments welcome :-).

Matrix not defined

I found the following error while trying to create a new project:

Error message: 'matrix' is undefined

Here is the full output:

project_name [My Python Project]:  
project_slug [my_python_project]: 
project_short_description []: 
version [0.1.0]: 
github_organization []: 
Select open_source_license:
1 - Apache Software License 2.0
2 - MIT license
3 - BSD license
4 - ISC license
5 - GNU General Public License v3 or later
6 - Not open source
Choose from 1, 2, 3, 4, 5, 6 [1]: 
Select apidoc:
1 - no
2 - yes
Choose from 1, 2 [1]: 
pypi_user [no_pypi_travis_deployment]: 
full_name [John Smith]: 
email [[email protected]]: 
copyright_holder []: 
code_of_conduct_email [[email protected]]: 
Unable to create file '.github/workflows/build.yml'
Error message: 'matrix' is undefined
Context: {
    "cookiecutter": {
        "_template": "https://github.com/nlesc/python-template.git",
        "apidoc": "no",
        "code_of_conduct_email": "[email protected]",
        "copyright_holder": "",
        "email": "[email protected]",
        "full_name": "John Smith",
        "github_organization": "",
        "open_source_license": "Apache Software License 2.0",
        "project_name": "My Python Project",
        "project_short_description": "",
        "project_slug": "my_python_project",
        "pypi_user": "no_pypi_travis_deployment",
        "version": "0.1.0"
    }
}

Add instructions for generating additional cff files

They should probably go in the generated readme, under project setup.

pip install cffconvert
cffconvert --validate
cffconvert --outfile .zenodo.json -ig --outputformat zenodo
cffconvert --outfile codemeta.json -ig --outputformat codemeta

Switch to readthedocs theme?

The Sphinx configuration uses the alabaster theme, which IMHO is not so nice as the readthedocs theme. Should we switch the default?

Dashes in repository names propagate into package name

If you have a dash in your repository name (e.g. 'python-template' :)), then the Python package will also have a dash in its name, which is invalid Python. Is there any way of converting dashes to underscores here?

Add conftest.py

Having a conftest.py (even an empty one) in your top code directory makes PyTest add that path to the PYTHONPATH, so that you can import your code from your test cases using absolute imports. I took me a long time to figure that out (and Ben's template, which I was using before, used a hack instead). It would be nice to have such a file in here, ideally with a comment explaining why it's there.

(I'll submit a pull request if you think it's a good idea.)

Example tests fail to run

Two of the 3 example tests fail to run with an error message:

fixture 'my_project' not found

and there is an unused fixture deffined. Also the example test class inherits from object which is considered bad style in python 3.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.