GithubHelp home page GithubHelp logo

ucl-arc / python-tooling Goto Github PK

View Code? Open in Web Editor NEW
22.0 17.0 2.0 430 KB

Python package template for new research software projects

Home Page: http://github-pages.arc.ucl.ac.uk/python-tooling/

License: MIT License

Python 100.00%
cookiecutter python python-template python-templates python3 research-software research-software-engineering ucl

python-tooling's Introduction

UCL ARC Python tooling logo

UCL ARC Python Recommendations

This repository collects the UCL ARC recommendations for a research software project in Python. It contains a template for new Python packages and a website documenting our recommendations. We've turned on discussions for this repo, and we welcome questions there or in the #helpme channel on the UCL research programming hub Slack.

๐Ÿช Our template is a cookiecutter template which automatically creates new Python packages with our recommended tooling set up and ready to go.

Note If you're making a package within a community that has an existing package template (e.g., scikit-hep), we recommend using their template instead of this one.

Using this template

  1. Install cookiecutter in a Conda or venv environment (commented lines for Conda example).

    # conda create --channel conda-forge --name new-env-name
    # conda activate new-env-name
    # conda install pip
    pip install cookiecutter
    
  2. Run cookiecutter in the desired directory

    cookiecutter gh:ucl-arc/python-tooling
    

    If you have this repo locally (this may be the case if you are developing), you can run the following:

    cookiecutter /path/to/your/checkout/of/python-tooling
    
  3. A series of questions will pop up to configure the project. Type the answer or hit return to use the default option (shown in square brackets).

    Note that these project variables are defined in the cookiecutter.json file.

  4. This will create a specific directory structure.

    For example, for a project with the following variables:

    project_name [Python Template]: PROJECT_NAME
    project_slug [python-template]: PROJECT_SLUG
    

    we will get a project folder named PROJECT_SLUG, structured like this:

    PROJECT_SLUG
    โ”œโ”€โ”€ ...
    โ”œโ”€โ”€ README.md
    โ”œโ”€โ”€ pyproject.toml
    โ”œโ”€โ”€ src
    โ”‚   โ””โ”€โ”€ PROJECT_SLUG
    โ”‚       โ””โ”€โ”€ PROJECT_SLUG.py
    โ””โ”€โ”€ tests
        โ””โ”€โ”€ test_dummy.py
    

    And the PROJECT_NAME will appear in the README.md as the human-readable name of the project.

    cat PROJECT_SLUG/README.md
    # PROJECT_NAME
    ...
    
  5. To work on your project, initialise a git repository and install it in editable mode.

    cd PROJECT_SLUG
    git init
    python -m pip install -e ".[dev]"
    
  6. Build your package

    python -m build
    

Notes for developers

Click to expand...

First, clone repository

  • (Optional) Generate your SSH keys as suggested here
  • (Optional) GitHub CLI as suggested here
  • Clone the repository by typing (or copying) the following line in a terminal at your selected path in your machine:
git clone [email protected]:UCL-ARC/python-tooling.git
cd python-tooling

Developing the cookiecutter template

  • To create and remove your virtual environment

    conda create -n ptoolingVE pip -c conda-forge
    conda activate ptoolingVE
    conda deactivate ptoolingVE
    conda remove -n ptoolingVE --all
    
  • To run template in the same path of this repo. We do a test cookiecut of a dummy package and install it to ensure the template setup works.

    cookiecutter .
    cd python-template
    git init
    python -m pip install -e ".[dev]"
    
  • To run cookiecutter using a specific branch of the template:

    cookiecutter https://github.com/UCL-ARC/python-tooling --checkout <branch-name>
    
  • To run the tests locally:

    pytest -s
    

Developing the recommended tooling pages

Pages all live in the docs/pages sub-directory, and are written in markdown.

To build the webpage locally (for testing)

  1. Install jekyll
  2. Run bundle install from the docs/ directory of this repository to install dependencies.
  3. Run bundle exec jekyll serve from the root directory of this repository. This should fire up a local web server and tell you its address. By default the server will automatically refresh the HTML pages if any changes are made to the markdown sources.

See the jekyll docs for more info.

python-tooling's People

Contributors

dstansby avatar giordano avatar katiebuntic avatar matt-graham avatar mxochicale avatar p-j-smith avatar paddyroddy avatar pre-commit-ci[bot] avatar renovate[bot] avatar robertvi avatar ruaridhg avatar samcunliffe avatar sfmig avatar yidilozdemir avatar

Stargazers

 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

python-tooling's Issues

Review existing content

Would be good for someone who isn't me to proof read and suggest improvements to the initial content on the site.

Can we specify a list of python versions and loop through them?

The combination of https://github.com/UCL-ARC/python-template/blob/49898d88e6f46e0e214b0d4eecee2d07c19cad82/cookiecutter.json#L9 and https://github.com/UCL-ARC/python-template/blob/49898d88e6f46e0e214b0d4eecee2d07c19cad82/%7B%7Bcookiecutter.project_slug%7D%7D/pyproject.toml#L109-L129 doesn't work at the moment. What I think would be good would be specifying either a list of python versions to support or a min and/or max version and do something clever.

README adding git remote

Should we maybe add a quick note about creating an empty remote repo and then following the instructions on github.com to link the local repo with the remote one?

Add CITATION.cff

Should be able to split cookiecutter.full_name to grab the first name and surname for CITATION.cff.
Introduced in the history of #3 but that was broken.

  • Can we have multiple authors in cookie-cutter templates?
  • Remove citation section from README?

Add our ๐ŸŸข tools.

Here's a list of our ๐ŸŸข ๐Ÿšฆ from the webpage.

  • pyinstrument

  • snakeviz

  • asv

  • github actions

  • codecov

  • sphinx

  • sphinx-gallery

  • (binder)

  • pre-commit

  • black

  • toml

  • isort

  • (ruff? autoflake)

  • mypy

  • build

  • setuptools

  • cibuildwheel

  • pytest

  • tox

  • pytest-cov

  • pytest-mock

  • mamba

Clarify some (obvious to us) best practices about repo organisation etc.

We probably want somewhere to write down, i.e. one package per repo. And link to package vs module distinction (probably somewhere in the official python docs).

These kinds of things are obvious to us, but likely not to new python developers.

Not really sure where this should go. But probably should be somewhere here.

Relates to

tox configuration requires tox version 4

While using this template for https://github.com/UCL/dxh (thanks all for the work in getting this set up ๐Ÿ˜) I found that the default legacy_tox_ini in the [tool.tox] section of the generated pyproject.toml

https://github.com/UCL-ARC/python-template/blob/ddf6cc2f8388efa9b9b2c8873f2ea5e837247b01/%7B%7Bcookiecutter.project_slug%7D%7D/pyproject.toml#L144-L169

needed a few tweaks before I could get tox running locally with the version I had installed (v3.24.5)

Might be worth documenting this and/or pinning the tox version in the dev list to tox>=4 in optional-dependencies . Potentially may also be worth adding version pin when tox is installed in Actions workflows though not sure if it is likely that a previous version will get installed on Actions runners in practice.

Start Licensing page

Which licence, how to avoid unnecessary bloat and best practices on maintaining and licensing a library might be part of this page.

Some pointers:

Start Planning page

The Python Template might come with a doc/requirements.rst file which is a good place to write up initial thoughts on what the library will or won't do. There are various planning elements and good practices for users to consider. Here some pointed that can be added in the planning page:

How to integrate `setuptools-scm`?

Ideally, we'd have something like the following included in the pyproject.toml.

[build-system]
requires = [
    "setuptools-scm",
]

[project]
dynamic = [
    "version",
]

[tool.setuptools_scm]

This has the advantage that all files tracked by git are included in the build - avoiding the need for MANIFEST.in etc. Also, we can do dynamic versioning.

If we have this, I run into issues as the templated generated code isn't a git repo. How can we get this to work nicely?

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.