-
-
Notifications
You must be signed in to change notification settings - Fork 17
Packaging for Nix #391
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
base: main
Are you sure you want to change the base?
Packaging for Nix #391
Conversation
Signed-off-by: Chin Yeung Li <tli@nexb.com>
Signed-off-by: Chin Yeung Li <tli@nexb.com>
Signed-off-by: Chin Yeung Li <tli@nexb.com>
Signed-off-by: Chin Yeung Li <tli@nexb.com>
- Added --generate and --test options - Updated code structure/comments Signed-off-by: Chin Yeung Li <tli@nexb.com>
|
@chinyeungli |
tdruez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ python build_nix_docker.py
nix-prefetch-url is NOT installed.
The nix-prefetch-url requirement is not documented.
Also, you can remove all references to funcparserlib.
|
Yes. I am on it. For some reasons, it's not building at the moment and I am working on it. |
- Updated documentation for the installation process - Added special handling for "python_ldap", which requires specific dependencies when building from source - Refactored and updated helper functions Signed-off-by: Chin Yeung Li <tli@nexb.com>
|
@tdruez script updated. |
tdruez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to use the script to generate the Nix package.
Could you add a short section in the script doc on how to run the app from this build?
|
@tdruez but it only shows the CLI Should the binary be designed to launch the web server automatically when executed? Similar to what |
|
@chinyeungli I should be able to run the test suite to validate the package. |
…at runtime #339 Signed-off-by: Chin Yeung Li <tli@nexb.com>
|
@tdruez I've updated the script and able to run the test with the following steps Create and configure a PostgreSQL user named dejacodeSets up environment variables and runs a test
|
Signed-off-by: Chin Yeung Li <tli@nexb.com>
etc/scripts/build_nix_docker.py
Outdated
| if component.get("packagetype") == "bdist_wheel": | ||
| whl_url = component.get("url") | ||
| if ( | ||
| ("cp313" not in whl_url and "py3" not in whl_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to look at https://github.com/aboutcode-org/python-inspector/blob/2a9f1287f33790cefa9f3e9599861f67b5305c85/src/python_inspector/utils_pypi.py#L1118 for tag matching ....
…lity #339 Signed-off-by: Chin Yeung Li <tli@nexb.com>
Signed-off-by: Chin Yeung Li <tli@nexb.com>
etc/scripts/build_nix_docker.py
Outdated
| ) | ||
| nix_content += " };\n" | ||
| nix_content += " };\n" | ||
| elif name == "python_ldap" and version == "3.4.5": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would looks like a pain to maintain, what happens when python_ldap version is updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored the code at e1a8ba9
Signed-off-by: Chin Yeung Li <tli@nexb.com>
tdruez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still getting the psycopg2 module error on Ubuntu 22.04.5 LTS:
Traceback (most recent call last):
File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/db/backends/postgresql/psycopg_any.py", line 5, in <module>
from psycopg import ClientCursor, IsolationLevel, adapt, adapters, errors, sql
File "/nix/store/ykw9fd32pnfpsri98145wacqi2qlwhn2-python3.13-psycopg-3.2.10/lib/python3.13/site-packages/psycopg/__init__.py", line 9, in <module>
from . import pq # noqa: F401 import early to stabilize side effects
^^^^^^^^^^^^^^^^
File "/nix/store/ykw9fd32pnfpsri98145wacqi2qlwhn2-python3.13-psycopg-3.2.10/lib/python3.13/site-packages/psycopg/pq/__init__.py", line 116, in <module>
import_from_libpq()
~~~~~~~~~~~~~~~~~^^
File "/nix/store/ykw9fd32pnfpsri98145wacqi2qlwhn2-python3.13-psycopg-3.2.10/lib/python3.13/site-packages/psycopg/pq/__init__.py", line 108, in import_from_libpq
raise ImportError(
...<4 lines>...
)
ImportError: no pq wrapper available.
Attempts made:
- couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
- couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary'
- couldn't import psycopg 'python' implementation: libpq library not found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/nix/store/dzjq5n06jjk826yjxjgvlhxzs36vnwf7-dejacode/bin/.dejacode-wrapped", line 9, in <module>
sys.exit(command_line())
~~~~~~~~~~~~^^
File "/nix/store/dzjq5n06jjk826yjxjgvlhxzs36vnwf7-dejacode/lib/python3.13/site-packages/dejacode/__init__.py", line 83, in command_line
execute_from_command_line(sys.argv)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
~~~~~~~~~~~~~~~^^
File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/core/management/__init__.py", line 416, in execute
django.setup()
~~~~~~~~~~~~^^
File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/apps/config.py", line 123, in create
mod = import_module(mod_path)
File "/nix/store/cfapjd2rvqrpry4grb0kljnp8bvnvfxz-python3-3.13.8/lib/python3.13/importlib/__init__.py", line 88, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 1027, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/contrib/postgres/apps.py", line 4, in <module>
from django.db.backends.postgresql.psycopg_any import RANGE_TYPES
File "/nix/store/qpc72vbqazyciaa9ia81gg5d961r2ir3-python3.13-Django-5.2.7/lib/python3.13/site-packages/django/db/backends/postgresql/psycopg_any.py", line 77, in <module>
from psycopg2 import errors, extensions, sql # NOQA
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'psycopg2'
etc/scripts/build_nix_docker.py
Outdated
| if "cp313" in url: | ||
| tags.add("cp313") | ||
| if "py3" in url: | ||
| tags.add("py3") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Python version should be extracted from the pyproject.toml
In general, everything that is currently hardcoded should be extracted from there so the script keeps working after upgrading the Python version or any dependency version.
| # Parse arguments | ||
| args = parser.parse_args() | ||
|
|
||
| if args.generate or not Path("default.nix").exists(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path("default.nix").exists()
Report a clear error message because if you re-run the script, you get no feedback and are left to figure out why.
- Better error handling - Reduce the hardcoded code Signed-off-by: Chin Yeung Li <tli@nexb.com>
Signed-off-by: Chin Yeung Li <tli@nexb.com>
…339 Signed-off-by: Chin Yeung Li <tli@nexb.com>
|
@tdruez The script no longer requires setting PYTHONPATH to run tests. However, you still need to initialize the database user with: Then run the tests using: Make sure to replace "your_password" with the actual password for the dejacode user. |
Fixes #339
Generates a Nix expression (default.nix) from the pyproject.toml file that is used to build the Python package for NixOS.
Once the default.nix is generated, one can build/install the package by
using:
Build the package
The above command will create a symlink named
resultin the currentdirectory pointing to the build output in the Nix store.
Run the binary directly
Signed-off-by: Chin Yeung Li tli@nexb.com