brightway-lca / cookiecutter-brightwaylib

A cookiecutter based project template for brightway libraries.
MIT License
1 stars 3 forks source link

PEP 440 error when building with default version #12

Closed cmutel closed 1 year ago

cmutel commented 1 year ago

I don't understand why, but when I run

pip install build
python -m build

I get the following error for compliance with PEP 440:

* Building wheel from sdist
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools>=61.0)
* Getting build dependencies for wheel...
/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/config/expand.py:144: UserWarning: File '/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-via-sdist-4_hsox66/fenrir-0.1/fenrir/VERSION' cannot be found
  warnings.warn(f"File {path!r} cannot be found")
Traceback (most recent call last):
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/config/setupcfg.py", line 592, in _parse_version
    Version(version)
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/_vendor/packaging/version.py", line 266, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
setuptools.extern.packaging.version.InvalidVersion: Invalid version: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/chrismutel/virtualenvs/cookiecutter/lib/python3.9/site-packages/pep517/in_process/_in_process.py", line 351, in <module>
    main()
  File "/Users/chrismutel/virtualenvs/cookiecutter/lib/python3.9/site-packages/pep517/in_process/_in_process.py", line 333, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/Users/chrismutel/virtualenvs/cookiecutter/lib/python3.9/site-packages/pep517/in_process/_in_process.py", line 118, in get_requires_for_build_wheel
    return hook(config_settings)
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/build_meta.py", line 338, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=['wheel'])
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires
    self.run_setup()
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/build_meta.py", line 335, in run_setup
    exec(code, locals())
  File "<string>", line 1, in <module>
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/__init__.py", line 87, in setup
    return distutils.core.setup(**attrs)
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 159, in setup
    dist.parse_config_files()
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/dist.py", line 863, in parse_config_files
    setupcfg.parse_configuration(
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/config/setupcfg.py", line 174, in parse_configuration
    meta.parse()
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/config/setupcfg.py", line 496, in parse
    section_parser_method(section_options)
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/config/setupcfg.py", line 470, in parse_section
    self[name] = value
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/config/setupcfg.py", line 278, in __setitem__
    value = parser(value)
  File "/private/var/folders/v8/25tc8p9s3bqbpjxfwbn6g64m0000gn/T/build-env-8ohoepp5/lib/python3.9/site-packages/setuptools/config/setupcfg.py", line 598, in _parse_version
    raise DistutilsOptionError(tmpl.format(**locals()))
distutils.errors.DistutilsOptionError: Version loaded from file: fenrir/VERSION does not comply with PEP 440:

I am 99% sure this isn't a whitespace problem, I have checked multiple times. But also switching to 0.1 doesn't seem to fix it.

@tngTUDOR Any ideas?

tngTUDOR commented 1 year ago

As used in the github action:

python -m build -s -w

The default behavior of the build backend is failing, but if we specify that we want source distribution and wheel to be built, this works fine.

tngTUDOR commented 1 year ago

* Building wheel from sdist <- that is the reason why the build doesn't pass, unless you specify "python -m build -s -w"

I think that if we later build conda packages from the built source distributions, this issue might come up again. In that case, we might need to add the code from PR #11

cmutel commented 1 year ago

According to the build documentation:

A simple, correct PEP 517 build frontend. By default, a source distribution (sdist) 
is built from {srcdir} and a binary distribution (wheel) is built from the sdist. This 
is recommended as it will ensure the sdist can be used to build wheels. Pass 
-s/–sdist and/or -w/–wheel to build a specific distribution. If you do this, the default 
behavior will be disabled, and all artifacts will be built from {srcdir} (even if you 
combine -w/–wheel with -s/–sdist, the wheel will be built from {srcdir}).

Can you help me understand why we are producing sdists which then can't be used to make wheels without raising errors? Just passing -s -w seems like avoiding instead of fixing the problem...

tngTUDOR commented 1 year ago

You're absolutely right, the default approach for build should work (invoking python -m build).

The error is that the version doesn't end up having the "VERSION" file. According to setuptools documentation, if we don't use setuptools_scm, and we want a non python file to be included in the distribution, we must include it in the MANIFEST.in

branch issue-12 contains a fix for this.

tngTUDOR commented 1 year ago

version 0.1.1 has a fix for this.