diff --git a/.isort.cfg b/.isort.cfg index 7e77f039..91032d23 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -1,11 +1,3 @@ [settings] -line_length=88 -indent=' ' -skip=.tox,.venv,build,dist -known_standard_library=setuptools,pkg_resources -known_test=pytest -known_first_party=otoole -sections=FUTURE,STDLIB,COMPAT,TEST,THIRDPARTY,FIRSTPARTY,LOCALFOLDER -default_section=THIRDPARTY -multi_line_output=3 -include_trailing_comma=True +profile = black +known_first_party = otoole diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 65bec4e0..cbce4d08 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,14 +1,8 @@ exclude: '^docs/conf.py' repos: -- repo: https://github.com/psf/black - rev: 22.6.0 - hooks: - - id: black - language_version: python3.9 - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.2.3 + rev: v4.3.0 hooks: - id: trailing-whitespace - id: check-added-large-files @@ -21,15 +15,43 @@ repos: - id: end-of-file-fixer - id: requirements-txt-fixer - id: mixed-line-ending - args: ['--fix=no'] - - id: flake8 - args: ['--max-line-length=88','--extend-ignore=E203'] # default of Black + args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows + +## If you want to avoid flake8 errors due to unused vars or imports: +# - repo: https://github.com/myint/autoflake +# rev: v1.4 +# hooks: +# - id: autoflake +# args: [ +# --in-place, +# --remove-all-unused-imports, +# --remove-unused-variables, +# ] -- repo: https://github.com/pre-commit/mirrors-isort - rev: v5.10.1 +- repo: https://github.com/pycqa/isort + rev: 5.10.1 hooks: - id: isort +- repo: https://github.com/psf/black + rev: 22.6.0 + hooks: + - id: black + language_version: python3 + +## If like to embrace black styles even in the docs: +# - repo: https://github.com/asottile/blacken-docs +# rev: v1.12.0 +# hooks: +# - id: blacken-docs +# additional_dependencies: [black] + +- repo: https://github.com/PyCQA/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + ## You can add flake8 plugins via `additional_dependencies`: + # additional_dependencies: [flake8-bugbear] - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.961 # Use the sha / tag you want to point at hooks: diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 00000000..21b08145 --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,23 @@ +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Build documentation in the docs/ directory with Sphinx +sphinx: + configuration: docs/conf.py + +# Build documentation with MkDocs +#mkdocs: +# configuration: mkdocs.yml + +# Optionally build your docs in additional formats such as PDF +formats: + - pdf + +python: + version: 3.8 + install: + - requirements: docs/requirements.txt + - {path: ., method: pip} diff --git a/.travis.yml b/.travis.yml index 1805b88d..465dd88f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,48 +1,62 @@ +# Travis configuration file using the build matrix feature +# Read more under http://docs.travis-ci.com/user/build-configuration/ +# THIS SCRIPT IS SUPPOSED TO BE AN EXAMPLE. MODIFY IT ACCORDING TO YOUR NEEDS! + language: python -os: linux -dist: xenial +git: + depth: false +env: + - PRE_COMMIT_HOME=$HOME/.cache/pre-commit virtualenv: system_site_packages: false jobs: fast_finish: true include: - - env: DISTRIB="conda" PYTHON_VERSION="3.7" COVERAGE="false" - - env: DISTRIB="conda" PYTHON_VERSION="3.8" COVERAGE="false" - - env: DISTRIB="conda" PYTHON_VERSION="3.9" COVERAGE="true" - - stage: deploy - script: skip - deploy: - edge: true - provider: pypi - username: willu47 - password: - secure: b+jIvSEU2My0Bpgsv0/tZqbmZsrLPEOkLymxu5uCOWFfaLk8ALSW+R+J3xRJkB02UYOqYuf5E0tXMeAEzM5weCLgJ42kB+AeXrdDXU2n7Fkm61SimTz50wzpv3WenhRMW0A9CqFJHS7kQY7gGcRGcBbDnqg9yssnay8visCNYNGCskiKAwvJjv7mrill2/pJVpautqbvtZRJ3+AeV9UEJSvP88TvHH8lC5p/MnzhebO4IZ8C6MymIUXaKqfQAtpM2Co+ftlMEcHktRx4jUmd1SGQci8A86sITTsUDwQzWJrbR8RiqaUfasCl3gtdL3QQty1lkvoHEzDRVV9512q2qRsjEvbP0p3cFjjXrzZXA8URGrhFyh2Kdm/kvPw6J3yi0OgHtnnoRHRAQuYhGnJ4CGYDtoTSyBMmx7rPzyG1pYcFvUH8MxGOSo0wcfUKAmmWAhxHNmVvTvlBbdlm1A+Z1s0dVU1ePVEmUKacXVaq72f3nUjHAfa6tteVE6MOig6ljXcpuZRnnCJZlT9WEFtMGgMfNJBeWSVO0XXXR+tn1bJw5kDMO6quqKHAGCIWI2uZCBdroCMCrmXjc7upAmy3NhnbuHAudTRRXTPCoWssyu5hOkMfnobJBXDM+7KIwhWbFHQnuP2la7S1r9FrAnN2Rn/B0n1stGLX7UGqUgsuDac= - on: - tags: true - all_branches: false - cleanup: false - + - python: 3.6 + env: DISTRIB="ubuntu" TOX_PYTHON_VERSION="py36" COVERAGE="true" + - python: 3.7 + env: DISTRIB="ubuntu" TOX_PYTHON_VERSION="py37" COVERAGE="false" + - python: 3.8 + env: DISTRIB="ubuntu" TOX_PYTHON_VERSION="py38" COVERAGE="false" + - python: 3.9 + env: DISTRIB="ubuntu" TOX_PYTHON_VERSION="py39" COVERAGE="false" + - env: DISTRIB="conda" PYTHON_VERSION="3.8" COVERAGE="false" + - stage: deploy + script: skip + deploy: + edge: true + provider: pypi + username: willu47 + password: + secure: b+jIvSEU2My0Bpgsv0/tZqbmZsrLPEOkLymxu5uCOWFfaLk8ALSW+R+J3xRJkB02UYOqYuf5E0tXMeAEzM5weCLgJ42kB+AeXrdDXU2n7Fkm61SimTz50wzpv3WenhRMW0A9CqFJHS7kQY7gGcRGcBbDnqg9yssnay8visCNYNGCskiKAwvJjv7mrill2/pJVpautqbvtZRJ3+AeV9UEJSvP88TvHH8lC5p/MnzhebO4IZ8C6MymIUXaKqfQAtpM2Co+ftlMEcHktRx4jUmd1SGQci8A86sITTsUDwQzWJrbR8RiqaUfasCl3gtdL3QQty1lkvoHEzDRVV9512q2qRsjEvbP0p3cFjjXrzZXA8URGrhFyh2Kdm/kvPw6J3yi0OgHtnnoRHRAQuYhGnJ4CGYDtoTSyBMmx7rPzyG1pYcFvUH8MxGOSo0wcfUKAmmWAhxHNmVvTvlBbdlm1A+Z1s0dVU1ePVEmUKacXVaq72f3nUjHAfa6tteVE6MOig6ljXcpuZRnnCJZlT9WEFtMGgMfNJBeWSVO0XXXR+tn1bJw5kDMO6quqKHAGCIWI2uZCBdroCMCrmXjc7upAmy3NhnbuHAudTRRXTPCoWssyu5hOkMfnobJBXDM+7KIwhWbFHQnuP2la7S1r9FrAnN2Rn/B0n1stGLX7UGqUgsuDac= + on: + tags: true + all_branches: false + cleanup: false install: -- source tests/travis_install.sh + - source tests/travis_install.sh before_script: -- git config --global user.email "wusher@kth.com" -- git config --global user.name "Will Usher" + - git config --global user.email "wusher@kth.com" + - git config --global user.name "Will Usher" + # Useful information in case of debug + - if [[ "$DISTRIB" == "conda" ]]; then conda info -a; fi + - which tox script: -- pip install -r requirements.txt -- python setup.py develop -- pytest -- | - if [[ "$COVERAGE" == "true" ]]; then - pre-commit install - pre-commit run --files src - fi + - tox -e build + - tox + - | + if [[ "$COVERAGE" == "true" ]]; then + pre-commit install + pre-commit run --all-files + fi after_success: -- if [[ "$COVERAGE" == "true" ]]; then coveralls || echo "failed"; fi + - if [[ "$COVERAGE" == "true" ]]; then coveralls || echo "failed"; fi after_script: -- travis-cleanup + - travis-cleanup cache: pip: true directories: - - "$HOME/miniconda" + - $HOME/miniconda + - $HOME/.cache/pre-commit notifications: email: false diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 03276adb..f367e4e6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,13 +1,15 @@ ========= Changelog ========= -Version 2.0 +Version 1.0 =========== - Requires explicit provision of a user-defined configuration file for otoole to workbook +- Reads in a model configuration from a datapackage - Fixed issue #114 so that conversion to Excel workbooks is now operating +- Bumped pyscaffold to 4.2 Version 0.9 -========== +=========== - Adds support for processing Gurobi solution files - Better handling of datatypes when converting datapackages - Fixing bugs on Windows where empty lines were written out during conversion to datapackage diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 00000000..c04e829d --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,322 @@ +============ +Contributing +============ + +Welcome to ``otoole`` contributor's guide. + +This document focuses on getting any potential contributor familiarized +with the development processes, but `other kinds of contributions`_ are also +appreciated. + +If you are new to using git_ or have never collaborated in a project previously, +please have a look at `contribution-guide.org`_. Other resources are also +listed in the excellent `guide created by FreeCodeCamp`_ [#contrib1]_. + +Please notice, all users and contributors are expected to be **open, +considerate, reasonable, and respectful**. When in doubt, `Python Software +Foundation's Code of Conduct`_ is a good reference in terms of behavior +guidelines. + + +Issue Reports +============= + +If you experience bugs or general issues with ``otoole``, please have a look +on the `issue tracker`_. If you don't see anything useful there, please feel +free to fire an issue report. + +.. tip:: + Please don't forget to include the closed issues in your search. + Sometimes a solution was already reported, and the problem is considered + **solved**. + +New issue reports should include information about your programming environment +(e.g., operating system, Python version) and steps to reproduce the problem. +Please try also to simplify the reproduction steps to a very minimal example +that still illustrates the problem you are facing. By removing other factors, +you help us to identify the root cause of the issue. + + +Documentation Improvements +========================== + +You can help improve ``otoole`` docs by making them more readable and coherent, or +by adding missing information and correcting mistakes. + +``otoole`` documentation uses Sphinx_ as its main documentation compiler. +This means that the docs are kept in the same repository as the project code, and +that any documentation update is done in the same way was a code contribution. + +Our documentation is written in reStructuredText_. + + .. tip:: + Please notice that the `GitHub web interface`_ provides a quick way of + propose changes in ``otoole``'s files. While this mechanism can + be tricky for normal code contributions, it works perfectly fine for + contributing to the docs, and can be quite handy. + + If you are interested in trying this method out, please navigate to + the ``docs`` folder in the source repository_, find which file you + would like to propose changes and click in the little pencil icon at the + top, to open `GitHub's code editor`_. Once you finish editing the file, + please write a message in the form at the bottom of the page describing + which changes have you made and what are the motivations behind them and + submit your proposal. + +When working on documentation changes in your local machine, you can +compile them using |tox|_:: + + tox -e docs + +and use Python's built-in web server for a preview in your web browser +(``http://localhost:8000``):: + + python3 -m http.server --directory 'docs/_build/html' + + +Code Contributions +================== + +``otoole`` is built around a command line tool which is written +using the Python argparse library. The otoole.cli module is a useful +place to start when trying to understand how each command works. + +The ``otoole convert`` and ``otoole results`` commands both +use classes which inherit the otoole.Strategy class. +An ``otoole.ReadStrategy`` implements functionality which returns a +dictionary of pandas.DataFrame objects. +An ``otoole.WriteStrategy`` takes a dictionary of pandas.DataFrames +as an argument and writes out the target file format. + +Comprehensive unit tests in the ``tests`` folder provide another way to +understand what each of the components does. + +Submit an issue +--------------- + +Before you work on any non-trivial code contribution it's best to first create +a report in the `issue tracker`_ to start a discussion on the subject. +This often provides additional considerations and avoids unnecessary work. + +Create an environment +--------------------- + +Before you start coding, we recommend creating an isolated `virtual +environment`_ to avoid any problems with your installed Python packages. +This can easily be done via either |virtualenv|_:: + + virtualenv + source /bin/activate + +or Miniconda_:: + + conda create -n otoole python=3 six virtualenv pytest pytest-cov + conda activate otoole + +Clone the repository +-------------------- + +#. Create an user account on |the repository service| if you do not already have one. +#. Fork the project repository_: click on the *Fork* button near the top of the + page. This creates a copy of the code under your account on |the repository service|. +#. Clone this copy to your local disk:: + + git clone git@github.com:YourLogin/otoole.git + cd otoole + +#. You should run:: + + pip install -U pip setuptools -e . + + to be able to import the package under development in the Python REPL. + +#. Install |pre-commit|_:: + + pip install pre-commit + pre-commit install + + ``otoole`` comes with a lot of hooks configured to automatically help the + developer to check the code being written. + +Implement your changes +---------------------- + +#. Create a branch to hold your changes:: + + git checkout -b my-feature + + and start making changes. Never work on the main branch! + +#. Start your work on this branch. Don't forget to add docstrings_ to new + functions, modules and classes, especially if they are part of public APIs. + +#. Add yourself to the list of contributors in ``AUTHORS.rst``. + +#. When you’re done editing, do:: + + git add + git commit + + to record your changes in git_. + + Please make sure to see the validation messages from |pre-commit|_ and fix + any eventual issues. + This should automatically use flake8_/black_ to check/fix the code style + in a way that is compatible with the project. + + .. important:: Don't forget to add unit tests and documentation in case your + contribution adds an additional feature and is not just a bugfix. + + Moreover, writing a `descriptive commit message`_ is highly recommended. + In case of doubt, you can check the commit history with:: + + git log --graph --decorate --pretty=oneline --abbrev-commit --all + + to look for recurring communication patterns. + +#. Please check that your changes don't break any unit tests with:: + + tox + + (after having installed |tox|_ with ``pip install tox`` or ``pipx``). + + You can also use |tox|_ to run several other pre-configured tasks in the + repository. Try ``tox -av`` to see a list of the available checks. + +Submit your contribution +------------------------ + +#. If everything works fine, push your local branch to |the repository service| with:: + + git push -u origin my-feature + +#. Go to the web page of your fork and click |contribute button| + to send your changes for review. + +Find more detailed information in `creating a PR`_. You might also want to open +the PR as a draft first and mark it as ready for review after the feedbacks +from the continuous integration (CI) system or any required fixes. + + +Troubleshooting +--------------- + +The following tips can be used when facing problems to build or test the +package: + +#. Make sure to fetch all the tags from the upstream repository_. + The command ``git describe --abbrev=0 --tags`` should return the version you + are expecting. If you are trying to run CI scripts in a fork repository, + make sure to push all the tags. + You can also try to remove all the egg files or the complete egg folder, i.e., + ``.eggs``, as well as the ``*.egg-info`` folders in the ``src`` folder or + potentially in the root of your project. + +#. Sometimes |tox|_ misses out when new dependencies are added, especially to + ``setup.cfg`` and ``docs/requirements.txt``. If you find any problems with + missing dependencies when running a command with |tox|_, try to recreate the + ``tox`` environment using the ``-r`` flag. For example, instead of:: + + tox -e docs + + Try running:: + + tox -r -e docs + +#. Make sure to have a reliable |tox|_ installation that uses the correct + Python version (e.g., 3.7+). When in doubt you can run:: + + tox --version + # OR + which tox + + If you have trouble and are seeing weird errors upon running |tox|_, you can + also try to create a dedicated `virtual environment`_ with a |tox|_ binary + freshly installed. For example:: + + virtualenv .venv + source .venv/bin/activate + .venv/bin/pip install tox + .venv/bin/tox -e all + +#. `Pytest can drop you`_ in an interactive session in the case an error occurs. + In order to do that you need to pass a ``--pdb`` option (for example by + running ``tox -- -k --pdb``). + You can also setup breakpoints manually instead of using the ``--pdb`` option. + + +Maintainer tasks +================ + +Releases +-------- + + If instead you are using a different/private package index, please update + the instructions accordingly. + +If you are part of the group of maintainers and have correct user permissions +on PyPI_, the following steps can be used to release a new version for +``otoole``: + +#. Make sure all unit tests are successful. +#. Tag the current commit on the main branch with a release tag, e.g., ``v1.2.3``. +#. Push the new tag to the upstream repository_, e.g., ``git push upstream v1.2.3`` +#. Clean up the ``dist`` and ``build`` folders with ``tox -e clean`` + (or ``rm -rf dist build``) + to avoid confusion with old builds and Sphinx docs. +#. Run ``tox -e build`` and check that the files in ``dist`` have + the correct version (no ``.dirty`` or git_ hash) according to the git_ tag. + Also check the sizes of the distributions, if they are too big (e.g., > + 500KB), unwanted clutter may have been accidentally included. +#. Run ``tox -e publish -- --repository pypi`` and check that everything was + uploaded to PyPI_ correctly. + + + +.. [#contrib1] Even though, these resources focus on open source projects and + communities, the general ideas behind collaborating with other developers + to collectively create software are general and can be applied to all sorts + of environments, including private companies and proprietary code bases. + + +.. <-- strart --> +.. |the repository service| replace:: GitHub +.. |contribute button| replace:: "Create pull request" + +.. _repository: https://github.com/OSeMOSYS/otoole +.. _issue tracker: https://github.com/OSeMOSYS/otoole/issues +.. <-- end --> + + +.. |virtualenv| replace:: ``virtualenv`` +.. |pre-commit| replace:: ``pre-commit`` +.. |tox| replace:: ``tox`` + + +.. _black: https://pypi.org/project/black/ +.. _CommonMark: https://commonmark.org/ +.. _contribution-guide.org: https://www.contribution-guide.org/ +.. _creating a PR: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request +.. _descriptive commit message: https://chris.beams.io/posts/git-commit +.. _docstrings: https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html +.. _first-contributions tutorial: https://github.com/firstcontributions/first-contributions +.. _flake8: https://flake8.pycqa.org/en/stable/ +.. _git: https://git-scm.com +.. _GitHub's fork and pull request workflow: https://guides.github.com/activities/forking/ +.. _guide created by FreeCodeCamp: https://github.com/FreeCodeCamp/how-to-contribute-to-open-source +.. _Miniconda: https://docs.conda.io/en/latest/miniconda.html +.. _MyST: https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html +.. _other kinds of contributions: https://opensource.guide/how-to-contribute +.. _pre-commit: https://pre-commit.com/ +.. _PyPI: https://pypi.org/ +.. _PyScaffold's contributor's guide: https://pyscaffold.org/en/stable/contributing.html +.. _Pytest can drop you: https://docs.pytest.org/en/stable/how-to/failures.html#using-python-library-pdb-with-pytest +.. _Python Software Foundation's Code of Conduct: https://www.python.org/psf/conduct/ +.. _reStructuredText: https://www.sphinx-doc.org/en/master/usage/restructuredtext/ +.. _Sphinx: https://www.sphinx-doc.org/en/master/ +.. _tox: https://tox.wiki/en/stable/ +.. _virtual environment: https://realpython.com/python-virtual-environments-a-primer/ +.. _virtualenv: https://virtualenv.pypa.io/en/stable/ + +.. _GitHub web interface: https://docs.github.com/en/repositories/working-with-files/managing-files/editing-files +.. _GitHub's code editor: https://docs.github.com/en/repositories/working-with-files/managing-files/editing-files diff --git a/LICENSE.txt b/LICENSE.txt index 6d6c2e2e..16473086 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 Will Usher +Copyright (c) 2022 Will Usher Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/docs/Makefile b/docs/Makefile index 33642fcb..31655dd9 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,193 +1,29 @@ # Makefile for Sphinx documentation # -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -PAPER = -BUILDDIR = ../build/sphinx/ +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build AUTODOCDIR = api -AUTODOCBUILD = sphinx-apidoc -PROJECT = otoole -MODULEDIR = ../src/otoole # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $?), 1) -$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +$(error "The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from https://sphinx-doc.org/") endif -# Internal variables. -PAPEROPT_a4 = -D latex_paper_size=a4 -PAPEROPT_letter = -D latex_paper_size=letter -ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . -# the i18n builder cannot share the environment and doctrees with the others -I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . - -.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext doc-requirements +.PHONY: help clean Makefile +# Put it first so that "make" without argument is like "make help". help: - @echo "Please use \`make ' where is one of" - @echo " html to make standalone HTML files" - @echo " dirhtml to make HTML files named index.html in directories" - @echo " singlehtml to make a single large HTML file" - @echo " pickle to make pickle files" - @echo " json to make JSON files" - @echo " htmlhelp to make HTML files and a HTML help project" - @echo " qthelp to make HTML files and a qthelp project" - @echo " devhelp to make HTML files and a Devhelp project" - @echo " epub to make an epub" - @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" - @echo " latexpdf to make LaTeX files and run them through pdflatex" - @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" - @echo " text to make text files" - @echo " man to make manual pages" - @echo " texinfo to make Texinfo files" - @echo " info to make Texinfo files and run them through makeinfo" - @echo " gettext to make PO message catalogs" - @echo " changes to make an overview of all changed/added/deprecated items" - @echo " xml to make Docutils-native XML files" - @echo " pseudoxml to make pseudoxml-XML files for display purposes" - @echo " linkcheck to check all external links for integrity" - @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) clean: rm -rf $(BUILDDIR)/* $(AUTODOCDIR) -$(AUTODOCDIR): $(MODULEDIR) - mkdir -p $@ - $(AUTODOCBUILD) -f -o $@ $^ - -doc-requirements: $(AUTODOCDIR) - -html: doc-requirements - $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." - -dirhtml: doc-requirements - $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." - -singlehtml: doc-requirements - $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml - @echo - @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." - -pickle: doc-requirements - $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle - @echo - @echo "Build finished; now you can process the pickle files." - -json: doc-requirements - $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json - @echo - @echo "Build finished; now you can process the JSON files." - -htmlhelp: doc-requirements - $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp - @echo - @echo "Build finished; now you can run HTML Help Workshop with the" \ - ".hhp project file in $(BUILDDIR)/htmlhelp." - -qthelp: doc-requirements - $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp - @echo - @echo "Build finished; now you can run "qcollectiongenerator" with the" \ - ".qhcp project file in $(BUILDDIR)/qthelp, like this:" - @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/$(PROJECT).qhcp" - @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/$(PROJECT).qhc" - -devhelp: doc-requirements - $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp - @echo - @echo "Build finished." - @echo "To view the help file:" - @echo "# mkdir -p $HOME/.local/share/devhelp/$(PROJECT)" - @echo "# ln -s $(BUILDDIR)/devhelp $HOME/.local/share/devhelp/$(PROJEC)" - @echo "# devhelp" - -epub: doc-requirements - $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub - @echo - @echo "Build finished. The epub file is in $(BUILDDIR)/epub." - -patch-latex: - find _build/latex -iname "*.tex" | xargs -- \ - sed -i'' 's~includegraphics{~includegraphics\[keepaspectratio,max size={\\textwidth}{\\textheight}\]{~g' - -latex: doc-requirements - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - $(MAKE) patch-latex - @echo - @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." - @echo "Run \`make' in that directory to run these through (pdf)latex" \ - "(use \`make latexpdf' here to do that automatically)." - -latexpdf: doc-requirements - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - $(MAKE) patch-latex - @echo "Running LaTeX files through pdflatex..." - $(MAKE) -C $(BUILDDIR)/latex all-pdf - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -latexpdfja: doc-requirements - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo "Running LaTeX files through platex and dvipdfmx..." - $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -text: doc-requirements - $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text - @echo - @echo "Build finished. The text files are in $(BUILDDIR)/text." - -man: doc-requirements - $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man - @echo - @echo "Build finished. The manual pages are in $(BUILDDIR)/man." - -texinfo: doc-requirements - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo - @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." - @echo "Run \`make' in that directory to run these through makeinfo" \ - "(use \`make info' here to do that automatically)." - -info: doc-requirements - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo "Running Texinfo files through makeinfo..." - make -C $(BUILDDIR)/texinfo info - @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." - -gettext: doc-requirements - $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale - @echo - @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." - -changes: doc-requirements - $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes - @echo - @echo "The overview file is in $(BUILDDIR)/changes." - -linkcheck: doc-requirements - $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck - @echo - @echo "Link check complete; look for any errors in the above output " \ - "or in $(BUILDDIR)/linkcheck/output.txt." - -doctest: doc-requirements - $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest - @echo "Testing of doctests in the sources finished, look at the " \ - "results in $(BUILDDIR)/doctest/output.txt." - -xml: doc-requirements - $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml - @echo - @echo "Build finished. The XML files are in $(BUILDDIR)/xml." - -pseudoxml: doc-requirements - $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml - @echo - @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/conf.py b/docs/conf.py index 1975db2b..8d65459c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,30 +1,29 @@ -# -*- coding: utf-8 -*- -# # This file is execfile()d with the current directory set to its containing dir. # -# Note that not all possible configuration values are present in this -# autogenerated file. +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html # # All configuration values have a default; values that are commented out # serve to show the default. import os import sys -import inspect import shutil -__location__ = os.path.join(os.getcwd(), os.path.dirname( - inspect.getfile(inspect.currentframe()))) +# -- Path setup -------------------------------------------------------------- + +__location__ = os.path.dirname(__file__) # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.join(__location__, '../src')) +sys.path.insert(0, os.path.join(__location__, "../src")) -# -- Run sphinx-apidoc ------------------------------------------------------ +# -- Run sphinx-apidoc ------------------------------------------------------- # This hack is necessary since RTD does not issue `sphinx-apidoc` before running # `sphinx-build -b html . _build/html`. See Issue: -# https://github.com/rtfd/readthedocs.org/issues/1139 +# https://github.com/readthedocs/readthedocs.org/issues/1139 # DON'T FORGET: Check the box "Install your project inside a virtualenv using # setup.py install" in the RTD Advanced Settings. # Additionally it helps us to avoid running apidoc manually @@ -43,55 +42,71 @@ try: import sphinx - from pkg_resources import parse_version - cmd_line_template = "sphinx-apidoc -f -o {outputdir} {moduledir}" - cmd_line = cmd_line_template.format(outputdir=output_dir, moduledir=module_dir) + cmd_line = f"sphinx-apidoc --implicit-namespaces -f -o {output_dir} {module_dir}" args = cmd_line.split(" ") - if parse_version(sphinx.__version__) >= parse_version('1.7'): + if tuple(sphinx.__version__.split(".")) >= ("1", "7"): + # This is a rudimentary parse_version to avoid external dependencies args = args[1:] apidoc.main(args) except Exception as e: print("Running `sphinx-apidoc` failed!\n{}".format(e)) -# -- General configuration ----------------------------------------------------- +# -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', - 'sphinx.ext.autosummary', 'sphinx.ext.viewcode', 'sphinx.ext.coverage', - 'sphinx.ext.doctest', 'sphinx.ext.ifconfig', 'sphinx.ext.mathjax', - 'sphinx.ext.napoleon'] +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.todo", + "sphinx.ext.autosummary", + "sphinx.ext.viewcode", + "sphinx.ext.coverage", + "sphinx.ext.doctest", + "sphinx.ext.ifconfig", + "sphinx.ext.mathjax", + "sphinx.ext.napoleon", +] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. # source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'otoole' -copyright = u'2019, Will Usher' +project = "otoole" +copyright = "2022, Will Usher" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # -# The short X.Y version. -version = '' # Is set by calling `setup.py docs` -# The full version, including alpha/beta/rc tags. -release = '' # Is set by calling `setup.py docs` +# version: The short X.Y version. +# release: The full version, including alpha/beta/rc tags. +# If you don’t need the separation provided between version and release, +# just set them both to the same value. +try: + from otoole import __version__ as version +except ImportError: + version = "" + +if not version or version.lower() == "unknown": + version = os.getenv("READTHEDOCS_VERSION", "unknown") # automatically set by RTD + +release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -105,7 +120,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".venv"] # The reST default role (used for this markup: `text`) to use for all documents. # default_role = None @@ -122,7 +137,7 @@ # show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. # modindex_common_prefix = [] @@ -130,19 +145,22 @@ # If true, keep warnings as "system message" paragraphs in the built documents. # keep_warnings = False +# If this is True, todo emits a warning for each TODO entries. The default is False. +todo_emit_warnings = True -# -- Options for HTML output --------------------------------------------------- + +# -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'alabaster' +html_theme = "alabaster" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. html_theme_options = { - 'sidebar_width': '300px', - 'page_width': '1200px' + "sidebar_width": "300px", + "page_width": "1200px" } # Add any paths that contain custom themes here, relative to this directory. @@ -150,12 +168,7 @@ # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -try: - from otoole import __version__ as version -except ImportError: - pass -else: - release = version +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. # html_short_title = None @@ -172,7 +185,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. @@ -216,27 +229,24 @@ # html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'otoole-doc' +htmlhelp_basename = "otoole-doc" -# -- Options for LaTeX output -------------------------------------------------- +# -- Options for LaTeX output ------------------------------------------------ latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -# 'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -# 'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -# 'preamble': '', + # The paper size ("letterpaper" or "a4paper"). + # "papersize": "letterpaper", + # The font size ("10pt", "11pt" or "12pt"). + # "pointsize": "10pt", + # Additional stuff for the LaTeX preamble. + # "preamble": "", } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'user_guide.tex', u'otoole Documentation', - u'Will Usher', 'manual'), + ("index", "user_guide.tex", "otoole Documentation", "Will Usher", "manual") ] # The name of an image file (relative to this directory) to place at the top of @@ -259,14 +269,18 @@ # If false, no module index is generated. # latex_domain_indices = True -# -- External mapping ------------------------------------------------------------ -python_version = '.'.join(map(str, sys.version_info[0:2])) +# -- External mapping -------------------------------------------------------- +python_version = ".".join(map(str, sys.version_info[0:2])) intersphinx_mapping = { - 'sphinx': ('http://www.sphinx-doc.org/en/stable', None), - 'python': ('https://docs.python.org/' + python_version, None), - 'matplotlib': ('https://matplotlib.org', None), - 'numpy': ('https://docs.scipy.org/doc/numpy', None), - 'sklearn': ('http://scikit-learn.org/stable', None), - 'pandas': ('http://pandas.pydata.org/pandas-docs/stable', None), - 'scipy': ('https://docs.scipy.org/doc/scipy/reference', None), + "sphinx": ("https://www.sphinx-doc.org/en/master", None), + "python": ("https://docs.python.org/" + python_version, None), + "matplotlib": ("https://matplotlib.org", None), + "numpy": ("https://numpy.org/doc/stable", None), + "sklearn": ("https://scikit-learn.org/stable", None), + "pandas": ("https://pandas.pydata.org/pandas-docs/stable", None), + "scipy": ("https://docs.scipy.org/doc/scipy/reference", None), + "setuptools": ("https://setuptools.pypa.io/en/stable/", None), + "pyscaffold": ("https://pyscaffold.org/en/stable", None), } + +print(f"loading configurations for {project} {version} ...", file=sys.stderr) diff --git a/docs/contributing.rst b/docs/contributing.rst new file mode 100644 index 00000000..e582053e --- /dev/null +++ b/docs/contributing.rst @@ -0,0 +1 @@ +.. include:: ../CONTRIBUTING.rst diff --git a/docs/index.rst b/docs/index.rst index f8610d58..870dc739 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -41,6 +41,7 @@ Contents License Authors Changelog + Contributing Module Reference diff --git a/pyproject.toml b/pyproject.toml index 9505d8f3..f6935d6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,29 +1,9 @@ -# Example configuration for Black. +[build-system] +# AVOID CHANGING REQUIRES: IT WILL BE UPDATED BY PYSCAFFOLD! +requires = ["setuptools>=46.1.0", "setuptools_scm[toml]>=5", "wheel"] +build-backend = "setuptools.build_meta" -# NOTE: you have to use single-quoted strings in TOML for regular expressions. -# It's the equivalent of r-strings in Python. Multiline strings are treated as -# verbose regular expressions by Black. Use [ ] to denote a significant space -# character. - -[tool.black] -line-length = 88 -target-version = ['py36', 'py37', 'py38'] -include = '\.pyi?$' -exclude = ''' -/( - \.eggs - | \.git - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - # The following are specific to Black, you probably don't want those. - | blib2to3 - | tests/data - | profiling -)/ -''' +[tool.setuptools_scm] +# For smarter version schemes and other configuration options, +# check out https://github.com/pypa/setuptools_scm +version_scheme = "no-guess-dev" diff --git a/requirements.txt b/requirements.txt index 8fbfc04a..aa8909d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ amply datapackage flatten_dict +frictionless importlib_resources; python_version<'3.7' networkx openpyxl diff --git a/setup.cfg b/setup.cfg index 3785daaf..f0c357ea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,35 +1,46 @@ # This file is used to configure your project. # Read more about the various options under: -# http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files +# https://setuptools.pypa.io/en/latest/userguide/declarative_config.html +# https://setuptools.pypa.io/en/latest/references/keywords.html [metadata] name = otoole description = A Python toolkit to support use of OSeMOSYS author = Will Usher author_email = wusher@kth.se -license = mit +license = MIT +license_files = LICENSE.txt long_description = file: README.rst long_description_content_type = text/x-rst; charset=UTF-8 url = https://github.com/OSeMOSYS/otoole +# Add here related links, for example: project_urls = Documentation = https://otoole.readthedocs.io/en/latest/?badge=latest + # Change if running only on Windows, Mac or Linux (comma-separated) platforms = any + # Add here all kinds of additional classifiers as defined under -# https://pypi.python.org/pypi?%3Aaction=list_classifiers +# https://pypi.org/classifiers/ classifiers = Development Status :: 4 - Beta Programming Language :: Python + [options] zip_safe = False -packages = find: +packages = find_namespace: include_package_data = True package_dir = =src -# DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD! -setup_requires = pyscaffold>=3.2a0,<3.3a0 -# Add here dependencies of your project (semicolon/line-separated), e.g. + +# Require a min/specific Python version (comma-separated conditions) +python_requires = >=3.7 + +# Add here dependencies of your project (line-separated), e.g. requests>=2.2,<3.0. +# Version specifiers like >=2.2,<3.0 avoid problems due to API changes in +# new major versions. This works if the required packages follow Semantic Versioning. +# For more information, check out https://semver.org/. install_requires = xlrd pyyaml @@ -40,13 +51,9 @@ install_requires = amply>=0.1.4 networkx flatten_dict + frictionless pandas_datapackage_reader openpyxl -# The usage of test_requires is discouraged, see `Dependency Management` docs -# tests_require = pytest; pytest-cov -# Require a specific Python version, e.g. Python 2.7 or >= 3.4 -python_requires = >=3.7 - [options.packages.find] where = src exclude = @@ -56,8 +63,10 @@ exclude = # Add here additional requirements for extra features, to install with: # `pip install otoole[PDF]` like: # PDF = ReportLab; RXP + # Add here test requirements (semicolon/line-separated) testing = + setuptools pytest pytest-cov @@ -72,16 +81,12 @@ console_scripts = # pyscaffold.cli = # awesome = pyscaffoldext.awesome.extension:AwesomeExtension -[test] -# py.test options when running `python setup.py test` -# addopts = --verbose -extras = True - [tool:pytest] -# Options for py.test: -# Specify command line options as you would do when invoking py.test directly. +# Specify command line options as you would do when invoking pytest directly. # e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml # in order to write a coverage file that can be read by Jenkins. +# CAUTION: --cov flags may prohibit setting breakpoints while debugging. +# Comment those flags to avoid this pytest issue. addopts = --cov otoole --cov-report html --verbose @@ -92,26 +97,23 @@ norecursedirs = build .tox testpaths = tests - -[aliases] -dists = bdist_wheel - -[bdist_wheel] -# Use this option if your package is pure-python -universal = 1 - -[build_sphinx] -source_dir = docs -build_dir = build/sphinx +# Use pytest markers to select/deselect specific tests +# markers = +# slow: mark tests as slow (deselect with '-m "not slow"') +# system: mark end-to-end system tests [devpi:upload] # Options for the devpi: PyPI server and packaging tool # VCS export must be deactivated since we are using setuptools-scm -no-vcs = 1 +no_vcs = 1 formats = bdist_wheel [flake8] # Some sane defaults for the code style checker flake8 +max_line_length = 88 +extend_ignore = E203, W503 +# ^ Black-compatible +# E203 and W503 have edge cases handled by black exclude = .tox build @@ -126,7 +128,7 @@ follow_imports = silent [pyscaffold] # PyScaffold's parameters when the project was created. # This will be used when updating. Do not change! -version = 3.2.2 +version = 4.2.3 package = otoole extensions = pre_commit diff --git a/setup.py b/setup.py index 9112198b..0c14f115 100644 --- a/setup.py +++ b/setup.py @@ -1,22 +1,21 @@ -# -*- coding: utf-8 -*- """ Setup file for otoole. Use setup.cfg to configure your project. - This file was generated with PyScaffold 3.2.2. + This file was generated with PyScaffold 4.2.3. PyScaffold helps you to put up the scaffold of your new Python project. Learn more under: https://pyscaffold.org/ """ -import sys -from pkg_resources import VersionConflict, require from setuptools import setup -try: - require('setuptools>=38.3') -except VersionConflict: - print("Error: version of setuptools is too old (<38.3)!") - sys.exit(1) - - if __name__ == "__main__": - setup(use_pyscaffold=True) + try: + setup(use_scm_version={"version_scheme": "no-guess-dev"}) + except: # noqa + print( + "\n\nAn error occurred while building the project, " + "please ensure you have the most updated version of setuptools, " + "setuptools_scm and wheel with:\n" + " pip install -U setuptools setuptools_scm wheel\n\n" + ) + raise diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..33822dfc --- /dev/null +++ b/tox.ini @@ -0,0 +1,84 @@ +# Tox configuration file +# Read more under https://tox.wiki/ +# THIS SCRIPT IS SUPPOSED TO BE AN EXAMPLE. MODIFY IT ACCORDING TO YOUR NEEDS! + +[tox] +minversion = 3.24 +envlist = default +isolated_build = True + + +[testenv] +description = Invoke pytest to run automated tests +setenv = + TOXINIDIR = {toxinidir} +passenv = + HOME +extras = + testing +commands = + pytest {posargs} + + +# To run `tox -e lint` you need to make sure you have a +# `.pre-commit-config.yaml` file. See https://pre-commit.com +[testenv:lint] +description = Perform static analysis and style checks +skip_install = True +deps = pre-commit +passenv = + HOMEPATH + PROGRAMDATA +commands = + pre-commit run --all-files {posargs:--show-diff-on-failure} + + +[testenv:{build,clean}] +description = + build: Build the package in isolation according to PEP517, see https://github.com/pypa/build + clean: Remove old distribution files and temporary build artifacts (./build and ./dist) +# https://setuptools.pypa.io/en/stable/build_meta.html#how-to-use-it +skip_install = True +changedir = {toxinidir} +deps = + build: build[virtualenv] +commands = + clean: python -c 'import shutil; [shutil.rmtree(p, True) for p in ("build", "dist", "docs/_build")]' + clean: python -c 'import pathlib, shutil; [shutil.rmtree(p, True) for p in pathlib.Path("src").glob("*.egg-info")]' + build: python -m build {posargs} + + +[testenv:{docs,doctests,linkcheck}] +description = + docs: Invoke sphinx-build to build the docs + doctests: Invoke sphinx-build to run doctests + linkcheck: Check for broken links in the documentation +setenv = + DOCSDIR = {toxinidir}/docs + BUILDDIR = {toxinidir}/docs/_build + docs: BUILD = html + doctests: BUILD = doctest + linkcheck: BUILD = linkcheck +deps = + -r {toxinidir}/docs/requirements.txt + # ^ requirements.txt shared with Read The Docs +commands = + sphinx-build --color -b {env:BUILD} -d "{env:BUILDDIR}/doctrees" "{env:DOCSDIR}" "{env:BUILDDIR}/{env:BUILD}" {posargs} + + +[testenv:publish] +description = + Publish the package you have been developing to a package index server. + By default, it uses testpypi. If you really want to publish your package + to be publicly accessible in PyPI, use the `-- --repository pypi` option. +skip_install = True +changedir = {toxinidir} +passenv = + # See: https://twine.readthedocs.io/en/latest/ + TWINE_USERNAME + TWINE_PASSWORD + TWINE_REPOSITORY +deps = twine +commands = + python -m twine check dist/* + python -m twine upload {posargs:--repository {env:TWINE_REPOSITORY:testpypi}} dist/*