From 5f488df4cc04cadb64949301c4d15edc87cfbf9a Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Thu, 21 Oct 2021 14:43:38 +1300 Subject: [PATCH] refactor(setup): prefer setup.cfg for package metadata, and other changes * Assign one author and one maintainer, which is expected by PyPI * Expand a few classifiers, add keywords and project URLs * Use python_requires, auto-find packages, and set zip_safe=False * Add pyproject.toml with black configuration, with default "-l 79" * Remove pypandoc dependency, specify 'text/markdown' content type * Change default sdist format to zip --- .flake8 | 36 ----------------- .github/workflows/ci.yml | 4 +- CONTRIBUTING.md | 2 +- docs/make_release.md | 10 ++--- flopy/mf6/modflow/mfgwf.py | 4 +- flopy/mf6/modflow/mfgwt.py | 4 +- pyproject.toml | 8 ++++ setup.cfg | 80 ++++++++++++++++++++++++++++++++++++++ setup.py | 56 +------------------------- 9 files changed, 100 insertions(+), 104 deletions(-) delete mode 100644 .flake8 create mode 100644 pyproject.toml create mode 100644 setup.cfg diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 5e64c1b19c..0000000000 --- a/.flake8 +++ /dev/null @@ -1,36 +0,0 @@ -[flake8] -exclude = - .git, - __pycache__, - build, - dist, - examples, - autotest -ignore = - # https://flake8.pycqa.org/en/latest/user/error-codes.html - F401, # 'module' imported but unused - # https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes - E121, # continuation line under-indented for hanging indent - E122, # continuation line missing indentation or outdented - E126, # continuation line over-indented for hanging indent - E127, # continuation line over-indented for visual indent - E128, # continuation line under-indented for visual indent - E203, # whitespace before - E221, # multiple spaces before operator - E222, # multiple spaces after operator - E226, # missing whitespace around arithmetic operator - E231, # missing whitespace after ',' - E241, # multiple spaces after ',' - E402, # module level import not at top of file - E501, # line too long (> 79 characters) - E502, # backslash is redundant between brackets - E722, # do not use bare 'except' - E741, # ambiguous variable name - W291, # trailing whitespace - W292, # no newline at end of file - W293, # blank line contains whitespace - W391, # blank line at end of file - W503, # line break before binary operator - W504 # line break after binary operator - -statistics = True diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fd08d66e4..17810577db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,9 +82,9 @@ jobs: - name: Run black run: | echo "if black check fails run" - echo " black --line-length 79 ./flopy" + echo " black ./flopy" echo "and then commit the changes." - black --check --line-length 79 ./flopy + black --check ./flopy - name: Run flake8 run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f0ce6a1dd7..0b5bd4d8c2 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,7 +58,7 @@ Before you submit your Pull Request (PR) consider the following guidelines: 1. Run the [black formatter](https://github.com/psf/black) on Flopy source files from the git repository root directory using: ```shell - black -l 79 ./flopy + black ./flopy ``` Note: Pull Requests must pass black format checks run on the [GitHub actions](https://github.com/modflowpy/flopy/actions) (*linting*) before they will be accepted. The black formatter can be installed using [`pip`](https://pypi.org/project/black/) and [`conda`](https://anaconda.org/conda-forge/black). diff --git a/docs/make_release.md b/docs/make_release.md index 16a83392a3..9bff67067d 100644 --- a/docs/make_release.md +++ b/docs/make_release.md @@ -23,7 +23,7 @@ Instructions for making a FloPy release 5. Run `black` on the updated MODFLOW 6 package classes by running the following from the root directory: ``` - black -l 79 flopy/mf6 + black flopy/mf6 ``` @@ -120,26 +120,24 @@ Use `run_notebooks.py` in the `release` directory to rerun all of the notebooks ## Update PyPi -1. Make sure `pypandoc` and `twine` are installed using: +1. Make sure `twine` is installed using: ``` - conda search pypandoc conda search twine ``` -2. If they are not installed, install one or both using using: +2. If it is not installed, install using using: ``` - conda install pypandoc conda install twine ``` 3. Create the source zip file in a terminal using: ``` - python setup.py sdist --format=zip + python setup.py sdist ``` 4. Upload the release to PyPi using (*make sure* `twine` *is installed using conda*): diff --git a/flopy/mf6/modflow/mfgwf.py b/flopy/mf6/modflow/mfgwf.py index ac62815649..0df73b03f4 100644 --- a/flopy/mf6/modflow/mfgwf.py +++ b/flopy/mf6/modflow/mfgwf.py @@ -91,7 +91,7 @@ def __init__( save_flows=None, newtonoptions=None, packages=None, - **kwargs + **kwargs, ): super().__init__( simulation, @@ -101,7 +101,7 @@ def __init__( version=version, exe_name=exe_name, model_rel_path=model_rel_path, - **kwargs + **kwargs, ) self.name_file.list.set_data(list) diff --git a/flopy/mf6/modflow/mfgwt.py b/flopy/mf6/modflow/mfgwt.py index 90ace90b82..a38b73e554 100644 --- a/flopy/mf6/modflow/mfgwt.py +++ b/flopy/mf6/modflow/mfgwt.py @@ -85,7 +85,7 @@ def __init__( print_flows=None, save_flows=None, packages=None, - **kwargs + **kwargs, ): super().__init__( simulation, @@ -95,7 +95,7 @@ def __init__( version=version, exe_name=exe_name, model_rel_path=model_rel_path, - **kwargs + **kwargs, ) self.name_file.list.set_data(list) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..dbb4477760 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[build-system] +# Minimum requirements for the build system to execute +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.black] +line-length = 79 +target_version = ["py37"] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000..60913fc62e --- /dev/null +++ b/setup.cfg @@ -0,0 +1,80 @@ +[metadata] +name = flopy +version = attr: flopy.version.__version__ +description = FloPy is a Python package to create, run, and post-process MODFLOW-based models +long_description = file: docs/PyPi_release.md +long_description_content_type = text/markdown +author = FloPy Team +author_email = modflow@usgs.gov +maintainer = Joseph D. Hughes +maintainer_email = jdhughes@usgs.gov +license = CC0 +license_files = LICENSE, LICENSE.md +platform = Windows, Mac OS-X, Linux +keywords = MODFLOW, groundwater, hydrogeology +classifiers = + Development Status :: 5 - Production/Stable + Intended Audience :: Science/Research + License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication + Programming Language :: Python + Programming Language :: Python :: 3 :: Only + Topic :: Scientific/Engineering :: Hydrology +url = https://github.com/modflowpy/flopy +download_url = https://pypi.org/project/flopy +project_urls = + Documentation = https://flopy.readthedocs.io + Release Notes = https://github.com/modflowpy/flopy/blob/develop/docs/version_changes.md + Bug Tracker = https://github.com/modflowpy/flopy/issues + Source Code = https://github.com/modflowpy/flopy + +[options] +include_package_data = True # includes files listed in MANIFEST.in +zip_safe = False +packages = find: +python_requires = >=3.7 +install_requires = + numpy >= 1.15.0 + matplotlib >= 1.4.0 + +[options.package_data] +flopy.mf6.data = dfn/*.dfn +flopy.plot = mplstyle/*.mplstyle + +[sdist] +formats = zip + +[flake8] +exclude = + .git + __pycache__ + build + dist + examples + autotest +ignore = + # https://flake8.pycqa.org/en/latest/user/error-codes.html + F401 # 'module' imported but unused + # https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes + E121 # continuation line under-indented for hanging indent + E122 # continuation line missing indentation or outdented + E126 # continuation line over-indented for hanging indent + E127 # continuation line over-indented for visual indent + E128 # continuation line under-indented for visual indent + E203 # whitespace before + E221 # multiple spaces before operator + E222 # multiple spaces after operator + E226 # missing whitespace around arithmetic operator + E231 # missing whitespace after ',' + E241 # multiple spaces after ',' + E402 # module level import not at top of file + E501 # line too long (> 79 characters) + E502 # backslash is redundant between brackets + E722 # do not use bare 'except' + E741 # ambiguous variable name + W291 # trailing whitespace + W292 # no newline at end of file + W293 # blank line contains whitespace + W391 # blank line at end of file + W503 # line break before binary operator + W504 # line break after binary operator +statistics = True diff --git a/setup.py b/setup.py index 7580eec8e5..b024da80e9 100644 --- a/setup.py +++ b/setup.py @@ -1,58 +1,4 @@ -import os -import sys from setuptools import setup -# ensure minimum version of Python is running -if sys.version_info[0:2] < (3, 7): - raise RuntimeError("Flopy requires Python >= 3.7") -# local import of package variables in flopy/version.py -# imports __version__, __pakname__, __author__, __author_email__ -exec(open(os.path.join("flopy", "version.py")).read()) - -try: - import pypandoc - - fpth = os.path.join("docs", "PyPi_release.md") - long_description = pypandoc.convert(fpth, "rst") -except ImportError: - long_description = "" - -setup( - name=__pakname__, - description="FloPy is a Python package to create, run, and " - + "post-process MODFLOW-based models.", - long_description=long_description, - author=__author__, - author_email=__author_email__, - url="https://github.com/modflowpy/flopy/", - license="CC0", - platforms="Windows, Mac OS-X, Linux", - install_requires=[ - "numpy>=1.15.0", - "matplotlib>=1.4.0", - ], - packages=[ - "flopy", - "flopy.modflow", - "flopy.modflowlgr", - "flopy.mfusg", - "flopy.modpath", - "flopy.mt3d", - "flopy.seawat", - "flopy.utils", - "flopy.plot", - "flopy.pest", - "flopy.export", - "flopy.discretization", - "flopy.mf6", - "flopy.mf6.coordinates", - "flopy.mf6.data", - "flopy.mf6.modflow", - "flopy.mf6.utils", - ], - include_package_data=True, # includes files listed in MANIFEST.in - # use this version ID if .svn data cannot be found - version=__version__, - classifiers=["Topic :: Scientific/Engineering :: Hydrology"], -) +setup()