diff --git a/.coveragerc b/.coveragerc index a3f3e02e..b3c2823f 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,6 +1,8 @@ [run] dynamic_context = test_function -omit = fortls/__init__.py +omit = + fortls/__init__.py + fortls/version.py [report] exclude_lines = diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 078f82d5..586900f3 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -5,9 +5,10 @@ jobs: docs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: ammaraskar/sphinx-action@master + - uses: actions/checkout@v2 + - uses: sphinx-toolbox/sphinx-action@master with: + pre-build-command: "pip install .[docs]" docs-folder: "docs/" - name: Deploy uses: peaceiris/actions-gh-pages@v3 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3772445b..f827909a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: architecture: x64 - name: Setup - run: pip install -r test_requirements.txt + run: pip install .[dev] - name: Unittests run: pytest -v @@ -41,7 +41,7 @@ jobs: - name: Coverage report run: | - pip install -r test_requirements.txt + pip install .[dev] pytest --cov=fortls --cov-report=xml - name: Upload coverage to Codecov diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 7b5b6fe8..92cc64dc 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -18,18 +18,6 @@ jobs: steps: - uses: actions/checkout@v2 - - # # This is a temporary workaround until GitHub Actions start natively - # # supporting signed commits like they should - # - name: Import GPG key - # id: import_gpg - # uses: crazy-max/ghaction-import-gpg@v4 - # with: - # gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - # passphrase: ${{ secrets.PASSPHRASE }} - # git_user_signingkey: true - # git_commit_gpgsign: true - - name: Set up Python uses: actions/setup-python@v2 with: @@ -40,37 +28,6 @@ jobs: python -m pip install --upgrade pip pip install build - # see: https://github.community/t/how-to-get-just-the-tag-name/16241/7 - - name: Get the version - id: get_version - shell: bash - run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} - - - name: Set global variables - shell: bash - run: | - echo "VERSION=${{ steps.get_version.outputs.VERSION }}" >> $GITHUB_ENV - - - name: Set __version__ - shell: bash - run: sed -i "s@\".*\"@\"${VERSION}\"@g" "fortls/_version.py" - - # Disabled the workflow because it messes up with the Releases on GitHub - # releases that use tags through force-push are marked as drafts - # will have to manually update the versions in _version.py - # - name: Commit the new version to dev - # shell: bash - # run: | - # git config --global user.name 'gnikit' - # git config --global user.email 'giannis.nikiteas@gmail.com' - # git fetch origin - # git switch dev - # git commit -S fortls/_version.py -m "Auto-Update version" -v - # git push - # git tag -f "${VERSION}" - # git push --delete origin "${VERSION}" - # git push origin "${VERSION}" - - name: Build package run: python -m build diff --git a/.gitignore b/.gitignore index b523599a..241dc003 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,10 @@ .vscode *.egg-info dist/ +build/ docs/_build/ docs/fortls_changes.md +fortls/_version.py .idea diff --git a/CHANGELOG.md b/CHANGELOG.md index b1bf1be8..c4771a1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # CHANGELONG +## 2.2.0 + +### Added + +- Added semantic versioning with `setuptools_scm` + ([gnikit/fortls#34](https://github.com/gnikit/fortls/issues/34)) + +### Changed + +- Changes from `setup.py` to `setup.toml` and `pyproject.toml` + ([gnikit/fortls#33](https://github.com/gnikit/fortls/issues/33)) +- Changed documentation CI to up to date action +- Formatted Python imports with `isort` + ## 2.1.2 ### Fixed diff --git a/README.md b/README.md index 5d17ed54..9f2ae2ee 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,16 @@ potentially subject to change. pip install fortls ``` +>**Warning**: it is not recommended having `fortls` and `fortran-language-server` +>simultaneously installed, since they use the same binary name. If you are having trouble +>getting `fortls` to work try uninstalling `fortran-language-server` and reinstalling `fortls`. +> +>```sh +>pip uninstall fortran-language-server +>pip install fortls --upgrade +>``` + + ## Settings `fortls` can be configured through both the command line e.g. diff --git a/docs/conf.py b/docs/conf.py index 93f16986..b9829596 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,7 +15,7 @@ sys.path.insert(0, os.path.abspath("..")) -from fortls._version import __version__ # noqa: E402 +from fortls import __version__ # noqa: E402 # Generate the agglomerated changes (from the CHANGELOG) between fortls # and the fortran-language-server project diff --git a/docs/fortls.rst b/docs/fortls.rst index 7db02e75..abce150e 100644 --- a/docs/fortls.rst +++ b/docs/fortls.rst @@ -76,6 +76,14 @@ fortls.regex\_patterns module :undoc-members: :show-inheritance: +fortls.version module +--------------------- + +.. automodule:: fortls.version + :members: + :undoc-members: + :show-inheritance: + Module contents --------------- diff --git a/docs/index.rst b/docs/index.rst index 418af573..75188632 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -3,7 +3,7 @@ You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. -fortls +fortls -- Fortran Language Server ================================== .. toctree:: diff --git a/docs/requirements.txt b/docs/requirements.txt deleted file mode 100644 index fd39737a..00000000 --- a/docs/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -docutils -myst-parser -sphinx -sphinx_autodoc_typehints -sphinx_rtd_theme -sphinxprettysearchresults -sphinx-argparse \ No newline at end of file diff --git a/fortls/__init__.py b/fortls/__init__.py index daa8a3ca..e7b646c9 100644 --- a/fortls/__init__.py +++ b/fortls/__init__.py @@ -6,12 +6,14 @@ import sys from multiprocessing import freeze_support -from ._version import __version__ -from .helper_functions import resolve_globs, only_dirs +from .helper_functions import only_dirs, resolve_globs +from .interface import commandline_args from .jsonrpc import JSONRPC2Connection, ReadWriter, path_from_uri from .langserver import LangServer from .parse_fortran import fortran_file, process_file -from .interface import commandline_args +from .version import __version__ + +__all__ = ["__version__"] def error_exit(error_str: str): diff --git a/fortls/_version.py b/fortls/_version.py deleted file mode 100644 index 46982ba7..00000000 --- a/fortls/_version.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "v2.1.2" diff --git a/fortls/constants.py b/fortls/constants.py index dd5666c5..df0cbfa5 100644 --- a/fortls/constants.py +++ b/fortls/constants.py @@ -1,5 +1,5 @@ -import sys import logging +import sys PY3K = sys.version_info >= (3, 0) diff --git a/fortls/interface.py b/fortls/interface.py index cb589137..87fd0626 100644 --- a/fortls/interface.py +++ b/fortls/interface.py @@ -4,7 +4,7 @@ import json import sys -from ._version import __version__ +from fortls.version import __version__ class SetAction(argparse.Action): diff --git a/fortls/langserver.py b/fortls/langserver.py index 9fd424f0..a6a477a5 100644 --- a/fortls/langserver.py +++ b/fortls/langserver.py @@ -11,7 +11,6 @@ from typing import Pattern # Local modules -from fortls._version import __version__ from fortls.constants import ( CLASS_TYPE_ID, FORTRAN_LITERAL, @@ -56,6 +55,7 @@ SQ_STRING_REGEX, src_file_exts, ) +from fortls.version import __version__ # Global regexes # TODO: I think this can be replaced by fortls.regex_patterns type & class diff --git a/fortls/objects.py b/fortls/objects.py index b9178195..cada90b2 100644 --- a/fortls/objects.py +++ b/fortls/objects.py @@ -3,8 +3,8 @@ import copy import os import re -from typing import Dict, NamedTuple, List, Set, Pattern from dataclasses import dataclass +from typing import Dict, List, NamedTuple, Pattern, Set from fortls.constants import ( ASSOC_TYPE_ID, diff --git a/fortls/version.py b/fortls/version.py new file mode 100644 index 00000000..53f90758 --- /dev/null +++ b/fortls/version.py @@ -0,0 +1,10 @@ +try: + from importlib.metadata import PackageNotFoundError, version +except ModuleNotFoundError: + from importlib_metadata import PackageNotFoundError, version +try: + __version__ = version(__package__) +except PackageNotFoundError: + from setuptools_scm import get_version + + __version__ = get_version(root="..", relative_to=__file__) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..4aa5b93d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[build-system] +requires = [ + "setuptools >= 45", + "wheel", + "setuptools_scm[toml] >= 6.2", + "setuptools_scm_git_archive", +] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "fortls/_version.py" diff --git a/setup.cfg b/setup.cfg index 16a12eae..5ba20e0b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,59 @@ +[metadata] +name = fortls +url = https://github.com/gnikit/fortls +author = Giannis Nikiteas +author_email = giannis.nikiteas@gmail.com +description = fortls - Fortran Language Server +long_description = file: README.md +long_description_content_type = text/markdown +license = MIT +classifiers = + Development Status :: 4 - Beta + Intended Audience :: Developers + Intended Audience :: Science/Research + License :: OSI Approved :: MIT License + Natural Language :: English + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Fortran + Operating System :: Microsoft :: Windows + Operating System :: POSIX + Operating System :: Unix + Operating System :: MacOS +project_urls = + Source = https://github.com/gnikit/fortls + Tracker = https://github.com/gnikit/fortls/issues + +[options] +packages = find: +python_requires = >= 3.7 +install_requires = + importlib-metadata; python_version < "3.8" + +[options.package_data] +fortls = *.json + +[options.entry_points] +console_scripts = + fortls = fortls.__init__:main + +[options.extras_require] +dev = + pytest >= 5.4.3 + pytest-cov >= 2.12.1 + black + isort +docs = + sphinx ~= 4.0.0 + sphinx_rtd_theme + sphinx-argparse + sphinx-autodoc-typehints + myst-parser + [flake8] max-line-length = 88 -extend-ignore = E203,E722 \ No newline at end of file +extend-ignore = E203, E722 diff --git a/setup.py b/setup.py index f7f3c06a..7add2b17 100644 --- a/setup.py +++ b/setup.py @@ -2,63 +2,6 @@ """Builds the Fortran Language Server - dev """ -import pathlib +import setuptools -from setuptools import find_packages, setup - -from fortls import __version__ - -# The directory containing this file -HERE = pathlib.Path(__file__).resolve().parent - -# The text of the README file is used as a description -README = (HERE / "README.md").read_text() - -NAME = "fortls" - -setup( - name=NAME, - version=__version__, - url="https://github.com/gnikit/fortran-language-server", - author="Giannis Nikiteas", - author_email="giannis.nikiteas@gmail.com", - description="fortls - Fortran Language Server", - long_description=README, - long_description_content_type="text/markdown", - license="MIT", - classifiers=[ - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: MIT License", - "Natural Language :: English", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Fortran", - "Operating System :: Microsoft :: Windows", - "Operating System :: POSIX", - "Operating System :: Unix", - "Operating System :: MacOS", - ], - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - packages=find_packages(exclude=["contrib", "docs", "test"]), - package_data={"fortls": ["*.json"]}, - # https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/ - install_requires=[ - 'future; python_version < "3"', - 'argparse; python_version < "2.7" or python_version in "3.0, 3.1"', - ], - # To provide executable scripts, use entry points in preference to the - # "scripts" keyword. Entry points provide cross-platform support and allow - # pip to create the appropriate form of executable for the target platform. - entry_points={ - "console_scripts": [ - "fortls = fortls.__init__:main", - ] - }, -) +setuptools.setup() diff --git a/test/setup_tests.py b/test/setup_tests.py index ca896afb..2efca3ce 100644 --- a/test/setup_tests.py +++ b/test/setup_tests.py @@ -9,12 +9,11 @@ root_dir = Path(__file__).parent.parent.resolve() sys.path.insert(0, root_dir) -from fortls.jsonrpc import ( # noqa: E402, F401 - path_to_uri, - read_rpc_messages, - write_rpc_notification, - write_rpc_request, -) +# Compromise since isort does not respect noqa +from fortls.jsonrpc import path_to_uri # noqa: E402, F401 +from fortls.jsonrpc import read_rpc_messages # noqa: E402 +from fortls.jsonrpc import write_rpc_notification # noqa: E402, F401 +from fortls.jsonrpc import write_rpc_request # noqa: E402, F401 test_dir = root_dir / "test" / "test_source" diff --git a/test/test_preproc.py b/test/test_preproc.py index 0d893355..f1472b4b 100644 --- a/test/test_preproc.py +++ b/test/test_preproc.py @@ -1,12 +1,6 @@ from __future__ import annotations -from setup_tests import ( - run_request, - # path_to_uri, - # write_rpc_notification, - write_rpc_request, - test_dir, -) +from setup_tests import run_request, test_dir, write_rpc_request def test_hover(): diff --git a/test_requirements.txt b/test_requirements.txt deleted file mode 100644 index da2350ca..00000000 --- a/test_requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -black -pytest -pytest-cov