georgemarshall/django-cryptography

Cannot install from git

TheBlusky opened this issue · 2 comments

When trygin to install django-cryptography using poetry :

poetry add git+https://github.com/georgemarshall/django-cryptography

django-cryptography seems to be installed properly, however, when imported/used, I have the following error:

  File "/usr/local/lib/python3.12/site-packages/django_cryptography/fields.py", line 25, in <module>
    from django_cryptography.core.signing import SignatureExpired
ModuleNotFoundError: No module named 'django_cryptography.core'

When inspecting what's installed, not all files are installed on site-package:

# cd /usr/local/lib/python3.12/site-packages/django_cryptography/
# ls
__init__.py  __pycache__  conf.py  fields.py  py.typed  typing.py

(core and utils directories are missing)

(Same with pip)

I guess it's because poetry uses the pyproject.toml file and not setup.cfg, but I have no idea how to fix it.

nymous commented

I think the issue comes from setuptools not including subpackages when a package is defined (as in packages = django_cryptography). I saw an error at some point telling this but I am not sure how to reliably reproduce it.

Error message
/tmp/build-env-2pw2j2qz/lib/python3.11/site-packages/setuptools/command/build_py.py:207: _Warning: Package 'django_cryptography.core' is absent from the `packages` configuration.
!!

        ********************************************************************************
        ############################
        # Package would be ignored #
        ############################
        Python recognizes 'django_cryptography.core' as an importable package[^1],
        but it is absent from setuptools' `packages` configuration.

        This leads to an ambiguous overall configuration. If you want to distribute this
        package, please make sure that 'django_cryptography.core' is explicitly added
        to the `packages` configuration field.

        Alternatively, you can also rely on setuptools' discovery methods
        (for example by using `find_namespace_packages(...)`/`find_namespace:`
        instead of `find_packages(...)`/`find:`).

        You can read more about "package discovery" on setuptools documentation page:

        - https://setuptools.pypa.io/en/latest/userguide/package_discovery.html

        If you don't want 'django_cryptography.core' to be distributed and are
        already explicitly excluding 'django_cryptography.core' via
        `find_namespace_packages(...)/find_namespace` or `find_packages(...)/find`,
        you can try to use `exclude_package_data`, or `include-package-data=False` in
        combination with a more fine grained `package-data` configuration.

        You can read more about "package data files" on setuptools documentation page:

        - https://setuptools.pypa.io/en/latest/userguide/datafiles.html


        [^1]: For Python, any directory (with suitable naming) can be imported,
              even if it does not contain any `.py` files.
              On the other hand, currently there is no concept of package data
              directory, all directories are treated like packages.
        ********************************************************************************

!!
  check.warn(importable)
/tmp/build-env-2pw2j2qz/lib/python3.11/site-packages/setuptools/command/build_py.py:207: _Warning: Package 'django_cryptography.utils' is absent from the `packages` configuration.
!!

        ********************************************************************************
        ############################
        # Package would be ignored #
        ############################
        Python recognizes 'django_cryptography.utils' as an importable package[^1],
        but it is absent from setuptools' `packages` configuration.

        This leads to an ambiguous overall configuration. If you want to distribute this
        package, please make sure that 'django_cryptography.utils' is explicitly added
        to the `packages` configuration field.

        Alternatively, you can also rely on setuptools' discovery methods
        (for example by using `find_namespace_packages(...)`/`find_namespace:`
        instead of `find_packages(...)`/`find:`).

        You can read more about "package discovery" on setuptools documentation page:

        - https://setuptools.pypa.io/en/latest/userguide/package_discovery.html

        If you don't want 'django_cryptography.utils' to be distributed and are
        already explicitly excluding 'django_cryptography.utils' via
        `find_namespace_packages(...)/find_namespace` or `find_packages(...)/find`,
        you can try to use `exclude_package_data`, or `include-package-data=False` in
        combination with a more fine grained `package-data` configuration.

        You can read more about "package data files" on setuptools documentation page:

        - https://setuptools.pypa.io/en/latest/userguide/datafiles.html


        [^1]: For Python, any directory (with suitable naming) can be imported,
              even if it does not contain any `.py` files.
              On the other hand, currently there is no concept of package data
              directory, all directories are treated like packages.
        ********************************************************************************

I found 2 ways to fix it by changing setup.cfg.

  1. Specify all packages, including all subpackages. This has the drawback of needing to update this every time a new subpackage is created.
 [options]
-packages = django_cryptography
+packages =
+    django_cryptography
+    django_cryptography.core
+    django_cryptography.utils
 python_requires = >=3.7
  1. Use the find: package discovery method from setuptools. This also requires an exclude configuration, to avoid including the tests and docs in the wheel.
 [options]
-packages = django_cryptography
+packages = find:
 python_requires = >=3.7
 include_package_data = True
 install_requires =
     Django>=2.2
     cryptography>=3.4.4
     django-appconf
     typing-extensions>=3.7.4.3

+[options.packages.find]
+exclude =
+    docs*
+    tests*
nymous commented

Also I would rename the issue to "Cannot install from git", because all dependency tools will use the build backend from pyproject.toml and have the same issue.