Skip to content

[ENH] Use hatch - #1553

Merged
martindurant merged 18 commits into
fsspec:masterfrom
fleming79:hatch
Apr 4, 2024
Merged

martindurant merged 18 commits into
fsspec:masterfrom
fleming79:hatch

Conversation

@fleming79

Copy link
Copy Markdown
Contributor

For consideration: Switch to using hatchling as the build backend. This PR removes the setup.py file and maintains versioneer as the vcs.

Why hatch: https://hatch.pypa.io/latest/why/

Feel free to modify as you wish or reject if it doesn't suit.

@martindurant

Copy link
Copy Markdown
Member

I am not opposed, but I am not familiar with hatch. Moving to pyproject is definitely worthwhile, but other projects I work on (dask-awkward aside) use setuptools_scm (no longer versioneer, which should certainly be removed). Is there anything in particular I need to know.

@martindurant

Copy link
Copy Markdown
Member

(if someone would like to implement retries throughout the flaky SMB implementation and tests, I would be grateful)

Comment thread pyproject.toml
dev = [ "black", "pre-commit"]
test = ["pytest", "pytest-cov", 'numpy', "pytest-mock", "requests", "aiohttp !=4.0.0a0, !=4.0.0a1", 'urllib3 <=1.26.18', 'tqdm']
dropbox = ["dropbox", "dropboxdrivefs", "requests"]
entrypoints = []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do something with setuptools a while back, but couldn't figure out how to avoid replicating 'full' list pyproject properly.

What advantage does hatchling have over setuptools btw?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also had some trouble getting versioneer to play nicely with it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(happy to ditch versioneer. It used to be the only solution, but not any more)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What advantage does hatchling have over setuptools btw?

Personally I find Hatch easy to use. see also: https://hatch.pypa.io/latest/why/#build-backend.

The default settings in Hatch mean that editable installs normally just work (including type hints). I find it makes it easier to editable install multiple packages into the same Python environment.

@fleming79

Copy link
Copy Markdown
Contributor Author

I am not opposed, but I am not familiar with hatch. Moving to pyproject is definitely worthwhile, but other projects I work on (dask-awkward aside) use setuptools_scm (no longer versioneer, which should certainly be removed). Is there anything in particular I need to know.

I think hatch-vcs is compatible with setuptools-scm.
see also:
https://hatch.pypa.io/latest/plugins/version-source/reference/#known-third-party

@martindurant

Copy link
Copy Markdown
Member

Yes, I certainly expect VCS versioning to work, I've just never done it with hatch

@martindurant

Copy link
Copy Markdown
Member

So, an appropriate test run would be to build and install the wheel, and check that the installed version and __version__ agree and are reasonable?

@martindurant

Copy link
Copy Markdown
Member

Did you see the CI error, which I would imagine is indeed due to the new build backend:

ConftestImportFailure: ImportPathMismatchError: ('dask.conftest', '/home/runner/work/filesystem_spec/filesystem_spec/dask/conftest.py', PosixPath('/home/runner/work/filesystem_spec/filesystem_spec/dask/dask/conftest.py')) (from /home/runner/work/filesystem_spec/filesystem_spec/dask/dask/conftest.py)

@fleming79

Copy link
Copy Markdown
Contributor Author

changes:

  • Versioneer has been replaced with Hatch vcs (setuptools_scm), currently this means fsspec should be installed (editable mode) to run the tests due to _version.py not existing until it fsspec has been built/installed.
  • ci tests install fsspec in editable mode prior to running tests

The downstream test is still failing at Dask. Will investigate this later.

@martindurant

Copy link
Copy Markdown
Member

You might need to download and -e install dask in a different directory not under fsspec to prevent pytest from getting confused.

@fleming79

fleming79 commented Mar 25, 2024 •

Copy link
Copy Markdown
Contributor Author

Changes

  • Env files dependencies moved to optional dependencies in pyproject.toml. This allows optional dependencies to be installed using pip rather than needing to use an env file.
  • Modified smb tests.
  • Pre-commit updated and switch to using ruff linter in place of black, isort and flake8
  • pytest-vcr (inactive) replaced with pytest-recording (dbfs tests need re-recording for python>3.9)

Workflows

  • updated to use almost exclusively pip install of dependencies.
  • Added Python 3.12.
  • actions/checkout@v3 -> actions/checkout@v4
  • build tool changed to hatch

Tests

  • separate 'test' and 'test_full' dependencies.
    • 'test': Base tests with minimal dependencies.
      • 1298 tests on posix.
      • 1170 tests on Windows -> now used as the windows workflow.
    • 'test_full' - full tests except for downstream -> now used as Python worflows (3.8-3.12).
    • ~1648 tests when run locally on posix.
    • ~1661 tests when run in posix workflow.
    • Test full for windows (run locally) has 19 test failures vs 1496 passed tests.
      • Failed tests are likely legitimate issues not previously tested on windows:
        • 17 in TestAnyArchive.
        • 1 in test_git->test_url.
        • 1 in test_libarchive->test_cache.

s3fs

s3fs depends on a specific version eg 2024.3.2 of fsspec which is a problem to list it as dependency in fsspec (circular).

In fsspec, when installing as editable, the version number is something like the latest tag plus a diff eg: 2024.3.2.dev16+g5e76562.d20240324, but if you install s3fs as a dependency pip will instead (rightly) install fsspec with the version specified 2024.3.2 . Having multiple versions of fsspec available could result in inconsistent results depending on the path, so it is better to only have the development version installed.

The current workaround is to:

  • install s3fs first (to install it with its dependencies).
  • uninstall s3fs.
  • install fsspec in editable mode.
  • install s3fs with no dependencies.

This ensures the tests are being run against the dev version of fsspec. It'd be better if the 3sfs tests are moved to s3fs. They can still be run as a downstream test.

Downstream

The downstream tests import from s3fs tests, for some reason the tests can't be access correctly using a standard install and require the source to be installed.

It'd be better if the s3fs could be less strict on fsspec version. eg: fsspec>2024.3.*. or fsspec~=2024.3 ref
Or even better if the tests are moved to s3fs.

Dask

Previously the dask repo was cloned and the bleeding edge tests run. Now Dask is installed as a module and the tests run directly in the module.

          dask_test_path=$(python -c "import dask.bytes;print(dask.bytes.__path__[0])")
          pytest -v $dask_test_path

All downstream tests could be run this way. This would mean that a released version of the tests are run rather than an unknown version.

@martindurant

Copy link
Copy Markdown
Member

Thanks! There's a lot of work here, so it will take me some time to look through it.

@martindurant

Copy link
Copy Markdown
Member

On the whole this looks very reasonable.

Since we have a question on VCS integration, we should have a specific check that the dev install of fsspec has a version (both in importlib.metadata and in .__version__) which is >= the latest on pypi (like this ?).

It'd be better if the s3fs could be less strict on fsspec version. eg: fsspec>2024.3.*. or fsspec~=2024.3

This is not possible, the two must always be released together and match versions, as they are so closely linked. However, the version could be like ~=2024.3.0, which would evaluate like >=2024.3.0,<2024.3.1 and allow for the dev version. I don't really see a problem with the install-and-uninstall pattern, however.

Or even better if the tests are moved to s3fs.

To be sure, which tests are we talking about? s3fs's own tests are run both in its own repo (to see if a change in s3fs broke anything) and here (to see if a change in fsspec broe s3fs); but are there also s3fs tests within fsspec's test suite??

Previously the dask repo was cloned and the bleeding edge tests run. Now Dask is installed as a module and the tests run directly in the module.

This may be OK, since dask should not merge PRs which break their own tests; but it's not uncommon to want to test the current "dev" versions of releated packages against each other. Also note that I haven't explicitly checked that dask includes all the test code in its release (there's not really a reason that it should!).

@fleming79

Copy link
Copy Markdown
Contributor Author

Since we have a question on VCS integration, we should have a specific check that the dev install of fsspec has a version (both in importlib.metadata and in .__version__) which is >= the latest on pypi (like this ?).

Sorry I don't understand what you mean.

This is not possible, the two must always be released together and match versions, as they are so closely linked. However, the version could be like ~=2024.3.0, which would evaluate like >=2024.3.0,<2024.3.1 and allow for the dev version.

I think I tried doing ~=2024.3.0, but it didn't seem to work, perhaps due to 'dev' appearing in the version number.

I don't really see a problem with the install-and-uninstall pattern, however.

In that case, we can just leave it as is.

Or even better if the tests are moved to s3fs.

To be sure, which tests are we talking about? s3fs's own tests are run both in its own repo (to see if a change in s3fs broke anything) and here (to see if a change in fsspec broe s3fs); but are there also s3fs tests within fsspec's test suite??

Specifically the downstream tests, that currently require the s3fs repo to be cloned:

try:
    from s3fs.tests.test_s3fs import (  # noqa: E402,F401
        endpoint_uri,
        s3,
        s3_base,
        test_bucket_name,
    )
except ImportError:
    pytest.skip("s3 tests not available.")

so = {"anon": False, "client_kwargs": {"endpoint_url": endpoint_uri}}


def test_pandas(s3):
    pd = pytest.importorskip("pandas")
    df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
    df.to_csv(f"s3://{test_bucket_name}/a.csv", storage_options=so)
    df2 = pd.read_csv(f"s3://{test_bucket_name}/a.csv", storage_options=so)

    assert df.a.equals(df2.a)


def test_xarray_zarr(s3):
    xr = pytest.importorskip("xarray")
    pytest.importorskip("zarr")
    import numpy as np

    x = np.arange(5)
    xarr = xr.DataArray(x)
    ds = xr.Dataset({"x": xarr})
    ds.to_zarr(f"s3://{test_bucket_name}/a.zarr", storage_options=so)

    ds2 = xr.open_zarr(f"s3://{test_bucket_name}/a.zarr", storage_options=so)

    assert (ds.x == ds2.x).all()

If the tests are moved (or the tests accessible from a normal install) then we'd no longer need to clone s3fs to run the tests.

This may be OK, since dask should not merge PRs which break their own tests; but it's not uncommon to want to test the current "dev" versions of releated packages against each other. Also note that I haven't explicitly checked that dask includes all the test code in its release (there's not really a reason that it should!).

The original issue was that we were having was that Dask (and s3fs) were cloned as a sub-folder inside fsspec. I didn't look deeply into fixing because I thought it better to test against a known version rather than a potentially dynamic version downstream.

Happy for you push any further changes you wish to make.

@martindurant

Copy link
Copy Markdown
Member

Since we have a question on VCS integration, we should have a specific check that the dev install of fsspec has a version (both in importlib.metadata and in .version) which is >= the latest on pypi (like this ?).

Sorry I don't understand what you mean.

Essentially I verified this locally by going through the build-install-import flow.

If the tests are moved (or the tests accessible from a normal install) then we'd no longer need to clone s3fs to run the tests.

There's a pretty good argument that these belong here, since they are not actually testing s3 functionality. They could use any fsspec backend, but in practice s3 is the most likely storage for these third-party libraries to want to use.

The original issue was that we were having was that Dask (and s3fs) were cloned as a sub-folder inside fsspec. I didn't look deeply into fixing because I thought it better to test against a known version rather than a potentially dynamic version downstream.

I'll try to make some time to do a little experimentation. As it is, the install step downloads a whole load of dependencies, and it seems to be risky to reply on pip getting this right (although there were no problems) compared to conda. You could reasonably say that the test set of deps is simply too big ...

@fleming79

Copy link
Copy Markdown
Contributor Author

Looks good to me.

Regarding the number optional dependencies installed: They've almost entirely been shifted from the environment-38.yml file to the [test_full] optional dependency with some extra optional dependencies added to maximize the number of test performed rather than skipped.

The advantage in using pip install is that it works 'everywhere'.

I agree that the optional dependencies could be rationalized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants