seddonym / import-linter

Import Linter allows you to define and enforce rules for the internal and external imports within your Python project.
https://import-linter.readthedocs.io/
BSD 2-Clause "Simplified" License
679 stars 48 forks source link

Publish whl package #166

Closed POD666 closed 1 year ago

POD666 commented 1 year ago

Hi,

In shot, this fails:

$ pip install import-linter --only-binary=:all: 
ERROR: Could not find a version that satisfies the requirement import-linter (from versions: none)
ERROR: No matching distribution found for import-linter

I need to build requirements constraints for a platform that is different from one used in CI and my script fails at import-linter.

More details I'm using `pip-compile` in CI with linux image and I want to build dev.requirements.txt for developers who use darwin: ``` $ pip-compile -v dev.requirements.in -o dev.requirements.txt --allow-unsafe --pip-args "--platform darwin --only-binary=:all: --target $${VIRTUAL_ENV}-darwin" ... pip._internal.exceptions.DistributionNotFound: No matching distribution found for import-linter[toml]==1.2.7 (from -r dev.requirements.in (line 11)) ``` More specific command to reproduce is: ``` $ pip install import-linter[toml]==1.2.7 --platform darwin --only-binary=:all: --target ${VIRTUAL_ENV}-darwin ERROR: Could not find a version that satisfies the requirement import-linter[toml]==1.2.7 (from versions: none) ERROR: No matching distribution found for import-linter[toml]==1.2.7 ```

Could you publish whl to pypi?

seddonym commented 1 year ago

Thanks for the issue.

We switched the dependency from toml to tomli in 1.2.7, I imagine that's what's causing this.

Could the issue be solved just by removing the reference to [toml] in your requirements file?

POD666 commented 1 year ago

Nope, the issue persists.

I can reproduce it with any version

$ pip install import-linter==1.8.0 --only-binary=:all:
ERROR: Could not find a version that satisfies the requirement import-linter==1.8.0 (from versions: none)
ERROR: No matching distribution found for import-linter==1.8.0

PS: only reproducible if the specified version is not yet installed, otherwise Requirement already satisfied ... is printed.

POD666 commented 1 year ago

I commented out import-linter from my dev.requirements.in file and pip-compile succeded without issues.

So only import-linter leads to the issue.

Without import-linter in dev.requirements.in everything works except pre-commit.

We have a bit custom version of it to discover all packages but that is another story.

Custom pre-commit (JFYI, let's not focus on it) ``` - repo: local hooks: - id: import-linter name: import-linter # add test_web to sys path to make it discovarable by import-linter # pip install import linter here because we have to exclude it from dev.requirements.in # https://github.com/seddonym/import-linter/issues/166 entry: bash -c "pip install import-linter==1.2.7 && export PYTHONPATH=$PYTHONPATH:$PWD/modules/web/ && /Users/$(whoami)/.pyenv/shims/lint-imports" language: system verbose: true require_serial: true exclude: core files: \.py$ pass_filenames: false ``` Using `- repo: https://github.com/seddonym/import-linter` doesn't work because it doesn't see our packages in venv.

If you could publish whl, that would be perfect 🙏

seddonym commented 1 year ago

Thanks.

To be honest, it's the first time I've encountered --only-binary=:all:, and haven't before considered distributing wheels, since Import Linter is pure Python, so I'm straying outside my area of knowledge here. So I'd definitely consider distributing wheels, but there is some learning I'll need to do first.

I'm guessing the source of the problem might be something to do with the way the new dependency tomli is distributed?

Interested to hear more about why you use --only-binary=:all:, and if you have any other insights as to why this has started breaking.

POD666 commented 1 year ago

I don't think it's related to tomli. --only-binary=:all: is looking for whl in pypi and you didn't publish any.

I want to use pip with --platform flag and it requires using --only-binary=:all: too.

Why this has started breaking

It didn't start breaking. It was never working and I never had a need to use --only-binary=:all:.

Something new I'm trying to implement is generating requirements constraints for developers in CI: in CI linux is used but developers use darwin. When packages have platform-specific requirements it leads to issues (different constraints generated locally and in CI). That is why I'm trying to use pip ... --platform and that is why I'm forced to use --only-binary=:all:.

Building whl should be pretty easy, we have the following script (it's used for each module separately):

echo "Building '${MODULE}'..." ;
# Build *.tar.gz and *.whl packages:
(cd ${MODULE} && python setup.py sdist bdist_wheel);
mv ${MODULE}/dist/* dist-python/;

Then publishing to pypi looks like this (we use twine):

twine upload --verbose ${TWINE_EXTRA_ARGS} -r pypi dist-python/*;

Hope it helps 🙂

seddonym commented 1 year ago

Thanks for the clarification - I want to think about it more, but I imagine I will publish wheels at some point.

seddonym commented 1 year ago

I have just published a wheel for 1.8.0. Could you let me know if this resolves your problem, and I will continue to do it for future releases?

astrojuanlu commented 1 year ago

pip install import-linter is instantaneous now ✨

seddonym commented 1 year ago

Great!