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

Proper package_data management #196

Merged
merged 6 commits into from Dec 14, 2022
Merged

Proper package_data management #196

merged 6 commits into from Dec 14, 2022

Conversation

vishwin
Copy link
Contributor

@vishwin vishwin commented Dec 7, 2022

Turns out data_files was deprecated; PyPA et al recommend that data files be included in the package(s) themselves, in this case, under chirp. Using importlib_resources allows obviating pkg_path() and other hacks about included data files, as they are now fully guaranteed to be present (even in the extremely unlikely load-from-ZIP-file scenario).

(This may be a precursor to full PEP-517 compliance later on)

@kk7ds
Copy link
Owner

kk7ds commented Dec 7, 2022

Yeah, so this is what I was trying to avoid until we can drop support for the master branch. I initially started with package_resources until I realized that it wasn't going to behave properly until the files are moved. I don't want to move any more files than I have to until we're no longer trying to keep the branches in sync.

As a compromise, what if we made setup.py copy the files into the package before setup() so that we can convince it to put them in the right place (in the package) for just the sdist target?

version=CHIRP_VERSION,
url='https://chirp.danplanet.com',
python_requires=">=3.3,<4",
install_required=['wxPython', 'serial', 'six', 'future'],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may have been a helpful typo. The reason the test jobs are failing with missing attrdict3 is a known problem with wxPython on Linux only:

wxWidgets/Phoenix#2225

That's why I have the version pins in requirements.txt. My understanding is that you're not supposed to specify versions in install_requires, and only use package names. However, issues like this show how that will never work.

But, even without that problem, it will make us try to compile wxwidgets itself during test environment setup on linux, which would be supremely unfortunate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wxPython issue applies to all Unix-like systems (including FreeBSD that I'm using) that did not apply wxWidgets/Phoenix#2224. Versions can absolutely be specified in install_requires, but proceed with caution from a practical point of view.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know it's possible. I'm referring to this recommendation against it:

https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/#install-requires-vs-requirements-files

It is not considered best practice to use install_requires to pin dependencies to specific versions, or to specify sub-dependencies (i.e. dependencies of your dependencies). This is overly-restrictive, and prevents the user from gaining the benefit of dependency upgrades.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, even without that problem, it will make us try to compile wxwidgets itself during test environment setup on linux, which would be supremely unfortunate.

The current wxPython versions, ie those not available in the Ubuntu 22.04 LTS Jammy repositories, require wxGTK 3.2, also not available in the repositories. Later versions are only available in Focal. That's the supreme unfortunate part.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean...I have this running locally on jammy (and focal) using distro packages for wxpython.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jammy (and even Kinetic) only has wxPython 4.0.7, which uses wxWidgets/wxGTK 3.0. wxPython 4.1 uses wx 3.1 (which became 3.2); wxPython 4.2 uses wx 3.2. wxWidgets releases are not API/ABI compatible between one another.

@vishwin
Copy link
Contributor Author

vishwin commented Dec 7, 2022

Both pkg_resources and even setup.py are deprecated. grafting arbitrary files/directories into sdists are supported but not for wheel-based bdists, so data files used in the program have to be in the package hierarchy.

tox.ini Outdated Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
@vishwin vishwin force-pushed the py3-package_data branch 2 times, most recently from 8e11369 to 3482454 Compare December 7, 2022 15:24
Copy link
Owner

@kk7ds kk7ds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess using extras to separate wxpython is reasonable, although it's a bit of an abuse of the "optional functionality" intent.

99% of chirp users consume the bundled builds, and this will break that, so I'll have to spend some time making changes to that stuff and testing it against this.

In the meantime, can you please squash this down to just commits that make logical changes? I'm not a fan of the github-inspired practice of dumping 21 "maybe this will work" commits into the history :) If you're unwilling, I'll do it for you, but I'd appreciate it if you could do it.

I think this is probably two logical changes: 1. Moving the files and 2. changing the requirements stuff.

.github/actions/py3-tox/action.yaml Outdated Show resolved Hide resolved
MANIFEST.in Outdated Show resolved Hide resolved
in importlib_resources.files('chirp.stock_configs').iterdir()
if conf.is_file()
]
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate black formatting. I just wanted you to know :)

requirements.txt Outdated Show resolved Hide resolved
version=CHIRP_VERSION,
url='https://chirp.danplanet.com',
python_requires=">=3.3,<4",
install_required=['wxPython', 'serial', 'six', 'future'],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean...I have this running locally on jammy (and focal) using distro packages for wxpython.

tox.ini Outdated Show resolved Hide resolved
@@ -31,7 +32,6 @@ commands =

[testenv:style]
basepython = python3
sitepackages = False
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this? I suspect that we can flip sitepackages=False at the top right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to allow the test to use the Ubuntu-provided wxPython, which would not be in the tox-created virtualenv otherwise.

entry_points={
'console_scripts': ["chirp=chirp.wxui:chirpmain"],
},
scripts=['chirpw'],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed, and the chirpw from manifest. It "works" in that it loads from time to time but things break, I don't want to support it, and plan to remove it from the tree, again, once we're no longer keeping the py2 and py3 branches in sync. Last I checked it didn't even start due to changes sync'd from master. It confuses people having both and I want to avoid that. That also means the gtk extras target can go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using that since the last commit in the py3 branch in mercurial with only Python syntax changes, using PyGObject3. Even under that (and GTK 3), it is significantly lighter than and has working multi-select and copy-paste functionality compared to the wxPython interface.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's massively slower in my experience, I'm shocked that you find it faster. There's been over a year of development on the wx ui since the last commit on the mercurial branch. There are still some gaps, but I'm working to close them. If you find any not on the list I sent to the mailing list, feel free to bring them up.

On Windows and macos, wx provides a far superior experience for people (and native widgets), which again, represent 99% of the users :)

MANIFEST.in Outdated Show resolved Hide resolved
@vishwin
Copy link
Contributor Author

vishwin commented Dec 7, 2022

Squashing is going to happen eventually, all the separate commits were only for kicking CI and having revert points.

@kk7ds
Copy link
Owner

kk7ds commented Dec 7, 2022

Squashing is going to happen eventually, all the separate commits were only for kicking CI and having revert points.

Excellent, thanks, I wasn't sure.

@vishwin vishwin force-pushed the py3-package_data branch 4 times, most recently from eac62d9 to 93b085e Compare December 8, 2022 01:12
@kk7ds
Copy link
Owner

kk7ds commented Dec 8, 2022

FYI, I'm sorting the locale stuff before getting into this, since that's important (for users) and this is cleanup, but will start on build testing with this soon.

But I'm wondering: do you not want to just go forward with pyproject.toml here instead of fixing setup.py?

@vishwin
Copy link
Contributor Author

vishwin commented Dec 9, 2022

PEP-517 compliance is a much bigger beast than just updating setup.py, not least because you will have to majorly change your own later-stage packaging/bundling procedures and documentation (unless you're already having to put more effort in this regard). Was thinking of this as a stopgap before going there.

@kk7ds
Copy link
Owner

kk7ds commented Dec 9, 2022

PEP-517 compliance is a much bigger beast than just updating setup.py, not least because you will have to majorly change your own later-stage packaging/bundling procedures and documentation (unless you're already having to put more effort in this regard). Was thinking of this as a stopgap before going there.

Yeah, I don't care about PEP-517 I just thought maybe it made sense as setup.py is (for the py3 branch) only used for sdist and that maybe it made sense.

This definitely breaks the packaging stuff, but I'm still working through it and am hopeful I'll be able to get it to work. I just rebased this, included locale in the move, importlib-resources in requirements.txt and will keep working on getting the builds to work based on this.

@kk7ds kk7ds force-pushed the py3-package_data branch 3 times, most recently from 7351d2a to 928932c Compare December 9, 2022 22:14
@kk7ds
Copy link
Owner

kk7ds commented Dec 9, 2022

@vishwin Okay, I have the bundled builds working with this with the changes I've pushed up here. It's very laborious (windows is slow) to validate, so I'm hoping you're okay with the changes I've made here. Please confirm.

This also doesn't include chirp.locale in the sdist build even though share and stock_configs are, but I'm not sure why and I haven't tried to figure it out. I'm about out of steam today, so maybe you can take a look. If it's only changes to setup.py, I won't have to reverify the other platforms.

If you can confirm this looks okay to you I can merge and get another build generated for the end of the week here. The sdist locale issue probably need not hold us up.

@kk7ds
Copy link
Owner

kk7ds commented Dec 13, 2022

If you can confirm this looks okay to you I can merge and get another build generated for the end of the week here. The sdist locale issue probably need not hold us up.

@vishwin ?

vishwin and others added 6 commits December 14, 2022 11:13
Data files outside the package are not installed in binary distributions, so move them inside. Use importlib_resources to load icon and stock configs.
- use only the newer files(), as_files() and namespace APIs introduced in Python 3.10
- use the importlib_resources package if Python < 3.10
- remove obviated pkg_path()
- bump minimum Python version to 3.7

Fix test paths to account for the move
YesNoDialog does not have set_alternative_button_order
setup.py was intentionally typoed to not specify dependencies, but breaks metadata.
wxPython is unnecessary for the automated test suite. Additionally, the GTK interface still works under PyGObject in GTK 3, so re-expose that.
This is required if we're generating a bundled app that uses an
executable name that is different than what we want to show up.
Specifically for macos, but might apply elsewhere.
@kk7ds
Copy link
Owner

kk7ds commented Dec 14, 2022

Okay, well, I did a bunch of work to the build system to accommodate this and have been holding up further builds waiting for confirmation. Without that, I'm just going to have to merge this and hope for the best. Not sure the hassle has been worth it in the long run, but hopefully this doesn't cause more trouble.

@kk7ds kk7ds merged commit bcfe5cc into kk7ds:py3 Dec 14, 2022
kk7ds added a commit that referenced this pull request Dec 15, 2022
The default_dir() needs to return a string, but #196 made it return
a PosixPath. This manifested as new users unable to open files, but
established users could, because last_dir was pulled from the config
instead of the platform module.
kk7ds added a commit that referenced this pull request Dec 15, 2022
The default_dir() needs to return a string, but #196 made it return
a PosixPath. This manifested as new users unable to open files, but
established users could, because last_dir was pulled from the config
instead of the platform module.
@vishwin vishwin deleted the py3-package_data branch December 27, 2022 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants