Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with setuptools_scm 7 #8

Closed
frenzymadness opened this issue Jun 30, 2022 · 5 comments · Fixed by #9
Closed

Compatibility with setuptools_scm 7 #8

frenzymadness opened this issue Jun 30, 2022 · 5 comments · Fixed by #9
Labels
bug Something isn't working

Comments

@frenzymadness
Copy link
Contributor

I'm testing hatch-vcs with the latest setuptools_scm and one test fails:

============================= test session starts ==============================
platform linux -- Python 3.11.0b3, pytest-7.1.2, pluggy-1.0.0
rootdir: /builddir/build/BUILD/hatch_vcs-0.2.0
collected 16 items

tests/test_build.py .F.                                                  [ 18%]
tests/test_build_config.py ......                                        [ 56%]
tests/test_version_config.py .......                                     [100%]

=================================== FAILURES ===================================
__________________________________ test_write __________________________________

new_project_write = '/tmp/tmpbb8uz4_h/my-app'

    def test_write(new_project_write):
        build_project('-t', 'wheel')
    
        build_dir = os.path.join(new_project_write, 'dist')
        assert os.path.isdir(build_dir)
    
        artifacts = os.listdir(build_dir)
        assert len(artifacts) == 1
        wheel_file = artifacts[0]
    
        assert wheel_file == 'my_app-1.2.3-py2.py3-none-any.whl'
    
        extraction_directory = os.path.join(os.path.dirname(new_project_write), '_archive')
        os.mkdir(extraction_directory)
    
        with zipfile.ZipFile(os.path.join(build_dir, wheel_file), 'r') as zip_archive:
            zip_archive.extractall(extraction_directory)
    
        metadata_directory = os.path.join(extraction_directory, 'my_app-1.2.3.dist-info')
        assert os.path.isdir(metadata_directory)
    
        package_directory = os.path.join(extraction_directory, 'my_app')
        assert os.path.isdir(package_directory)
        assert len(os.listdir(package_directory)) == 5
    
        assert os.path.isfile(os.path.join(package_directory, '__init__.py'))
        assert os.path.isfile(os.path.join(package_directory, 'foo.py'))
        assert os.path.isfile(os.path.join(package_directory, 'bar.py'))
        assert os.path.isfile(os.path.join(package_directory, 'baz.py'))
    
        version_file = os.path.join(package_directory, '_version.py')
        assert os.path.isfile(version_file)
    
        lines = read_file(version_file).splitlines()
>       assert lines[3] == "version = '1.2.3'"
E       assert "__version__ ...ion = '1.2.3'" == "version = '1.2.3'"
E         - version = '1.2.3'
E         + __version__ = version = '1.2.3'

/builddir/build/BUILD/hatch_vcs-0.2.0/tests/test_build.py:78: AssertionError
=========================== short test summary info ============================
FAILED tests/test_build.py::test_write - assert "__version__ ...ion = '1.2.3'...
========================= 1 failed, 15 passed in 0.87s =========================
@RonnyPfannschmidt RonnyPfannschmidt added the bug Something isn't working label Jun 30, 2022
@frenzymadness
Copy link
Contributor Author

The failure is caused by this change: pypa/setuptools-scm@b45e19f#diff-bdefa0298003efada7c465428643cc6d9c129168afb3eb5c551b40fcc77feac1

We can either check that the line[3] ends with version = '1.2.3' or we can check the exact content of the line for setuptools_scm <7 and >=7. But I'm not sure that there is an easy way to get the version of setuptools_scm itself so we might need to use importlib_metadata for this and it might not be perfect.

What do you prefer?

@frenzymadness
Copy link
Contributor Author

@RonnyPfannschmidt is there any simple way to get the version of setuptools_scm? Something like setuptools_scm.__version__.

@RonnyPfannschmidt
Copy link
Collaborator

@frenzymadness asking importlib metadata is the intended way at the moment,

i think i should add a version attribute thats lazily computed

@musicinmybrain
Copy link
Contributor

@frenzymadness, thank you for diagnosing and fixing this. I will go ahead and apply your PR in the Fedora package for now to unblock your setuptools_scm testing.

@ofek, do you prefer the approach in #9, or do you prefer to write something like

assert lines[3].endswith("version = '1.2.3'")

to accommodate both older and newer setuptools_scm versions?

@ofek
Copy link
Owner

ofek commented Jun 30, 2022

I prefer ^ quick fix b/c I plan to switch to https://hatch.pypa.io/dev/plugins/build-hook/version/

@ofek ofek closed this as completed in #9 Jul 21, 2022
musicinmybrain added a commit to musicinmybrain/hatch-vcs that referenced this issue Dec 20, 2022
Make test_write less brittle (see also ofek#8, ofek#9) so that it works with
_version.py files generated by at least setuptools_scm 7.1, 7.0, and
6.x.
musicinmybrain added a commit to musicinmybrain/hatch-vcs that referenced this issue Dec 20, 2022
Make test_write less brittle (see also ofek#8, ofek#9) so that it works with
_version.py files generated by at least setuptools_scm 7.1, 7.0, and
6.x.
ofek pushed a commit that referenced this issue Jan 5, 2023
Make test_write less brittle (see also #8, #9) so that it works with
_version.py files generated by at least setuptools_scm 7.1, 7.0, and
6.x.
musicinmybrain added a commit to musicinmybrain/hatch-vcs that referenced this issue Sep 22, 2023
Make test_write even less brittle (see also ofek#8, ofek#9, ofek#25) so that it
works with _version.py files generated by at least setuptools_scm 8.0,
7.1, 7.0, and 6.4.

This is required because setuptools_scm 8.0 added a type-checking
comment at the end of the version line.
musicinmybrain added a commit to musicinmybrain/hatch-vcs that referenced this issue Sep 22, 2023
Make test_write even less brittle (see also ofek#8, ofek#9, ofek#25) so that it
works with _version.py files generated by at least setuptools_scm 8.0,
7.1, 7.0, and 6.4.

This is required because setuptools_scm 8.0 added a type-checking
comment at the end of the version line.

Based on:

https://src.fedoraproject.org/fork/lbalhar/rpms/python-hatch-vcs/c/ca6e8a95dbe50da64ba98c4e0829ae00ccd8025a
ofek pushed a commit that referenced this issue Sep 22, 2023
Make test_write even less brittle (see also #8, #9, #25) so that it
works with _version.py files generated by at least setuptools_scm 8.0,
7.1, 7.0, and 6.4.

This is required because setuptools_scm 8.0 added a type-checking
comment at the end of the version line.

Based on:

https://src.fedoraproject.org/fork/lbalhar/rpms/python-hatch-vcs/c/ca6e8a95dbe50da64ba98c4e0829ae00ccd8025a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants