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

package on pypi #50

Closed
raylu opened this issue Sep 20, 2023 · 15 comments
Closed

package on pypi #50

raylu opened this issue Sep 20, 2023 · 15 comments

Comments

@raylu
Copy link
Contributor

raylu commented Sep 20, 2023

SUMMARY

make dool installable via pip install dool

ISSUE TYPE
  • Feature Idea

see also: #4


the structure of the code is a bit... inconducive to python packaging. dool isn't importable, so it's hard to set it up as a console script. I made a symlink dool.pydool, but the structure is still pretty odd. it relies on some globals to be set, so after moving the __main__ block into a _main() function, I added some globals. I don't really understand what the else block is for (how can __name__ ever not be __main__?) so I deleted it

diff --git c/dool i/dool
index 8c645b7..7910aa4 100755
--- c/dool
+++ i/dool
@@ -51,6 +53,24 @@ pluginpath = [
     '/usr/local/share/dool/',
 ]
 
+def _main():
+    global op, theme
+    try:
+        initterm()
+        op = Options(os.getenv('DOOL_OPTS','').split() + sys.argv[1:])
+        theme = set_theme()
+        if op.profile:
+            import profile
+            if os.path.exists(op.profile):
+                os.remove(op.profile)
+            profile.run('main()', op.profile)
+        else:
+            main()
+    except KeyboardInterrupt as e:
+        if op.update:
+            sys.stdout.write('\n')
+    exit(0)
+
 class Options:
     def __init__(self, args):
         self.args         = args
@@ -2825,23 +2845,6 @@ def kd(obj):
 
 ### Main entrance
 if __name__ == '__main__':
-    try:
-        initterm()
-        op = Options(os.getenv('DOOL_OPTS','').split() + sys.argv[1:])
-        theme = set_theme()
-        if op.profile:
-            import profile
-            if os.path.exists(op.profile):
-                os.remove(op.profile)
-            profile.run('main()', op.profile)
-        else:
-            main()
-    except KeyboardInterrupt as e:
-        if op.update:
-            sys.stdout.write('\n')
-    exit(0)
-else:
-    op = Options('')
-    step = 1
+    _main()
 
 # vim: tabstop=4 shiftwidth=4 expandtab autoindent softtabstop=4

with a few other minor tweaks and the pyproject.toml below, flit install works

[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "dool"
authors = [{name = "Scott Baker", email = "[email protected]"}]
readme = "README.md"
license = {file = "LICENSE"}
classifiers = ["License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)"]
dynamic = ["version", "description"]

[project.urls]
Home = "https://github.com/scottchiefbaker/dool"

[project.scripts]
dool = "dool:_main"

[tool.flit.sdist]
exclude = [".github/*", ".gitignore", "docs/*", "examples/*", "install.py", "packaging/*", "Makefile"]

the main problem, though, is plugins/. it can't find any after installing

I doubt we want the package to be importable after installation as plugins, so we probably want to instead have a src/ or dool/ with a __main__.py and make plugins/ a subdir of that. that'd require a minor change to pluginpath and updating the rpm and snap packaging code

@scottchiefbaker
Copy link
Owner

Dool is 100% functional with just the dool script. The plugins are nice, but not required. If it's simpler we could just install dool and leave installing the plugins as an optional thing that can be done later?

@scottchiefbaker
Copy link
Owner

scottchiefbaker commented Apr 21, 2024

Where do we stand on this? I'm not 100% familiar with the startup code (I inherited this code). Your solution above looks clean to me, I would be fine moving towards that. I doubt the else does anything.

If you want to submit a PR to rework that startup code I'll test it.

@scottchiefbaker
Copy link
Owner

I re-worked and documented the startup in 5874a3e3. Hopefully it's an improvement, and it's easier to read.

@raylu
Copy link
Contributor Author

raylu commented Apr 25, 2024

5874a3e

nice. though I don't think the __main will work since you can't access double underscore prefixed symbols usually

do you wanna package it up for pypi?

@scottchiefbaker
Copy link
Owner

Can you elaborate on "you can't access double underscore prefixed symbols"?

I have zero experience packaging for pypi, I was hoping someone in the community would take that project on so we can spread the dool love.

@raylu
Copy link
Contributor Author

raylu commented Apr 25, 2024

oh, apparently double underscore only applies to class members. it works fine, disregard me

as for how to package, just add my pyproject.toml from the first comment, change "dool:_main" to "dool:__main", and then (pip install flit and) run flit install or flit build to make sure it works the way you want

once you're happy with it, make an account on https://test.pypi.org and publish there (https://flit.pypa.io/en/stable/upload.html). once you're happy with that, make an account on real pypi and publish!

@scottchiefbaker
Copy link
Owner

@raylu is that something that I need to do, or is it that something someone in the community is able to do? Are their security restrictions that require me personally to do it? I'm not a Python expert, I inherited this project, and I'm certainly NOT a Python ecosystem expert. I'm not really looking to take on adding a package on PyPi onto my plate.

Other projects I have been involved in (Perl and Javascript) the community was able to take the code I wrote and get it packaged up. That freed up my time to focus on the code and the release team would handle getting it pushed to various repositories.

@raylu
Copy link
Contributor Author

raylu commented Apr 25, 2024

you can do it yourself. there is no special list of trusted packagers for pypi. anyone can make a new package on pypi

it is... conventional for the package maintainer to claim the package on pypi. I can do it for you if you want, but I'd at least want to add you as a maintainer if I made the package

@scottchiefbaker
Copy link
Owner

@raylu if you have experience making packages then please, by all means, make dool a package and add me as a maintainer. I'll gladly give you credit in the readme.

@raylu
Copy link
Contributor Author

raylu commented Apr 26, 2024

I just remembered that pypi now has a whole fancy trusted publishers thing https://docs.pypi.org/trusted-publishers/
that lets you publish from a GH action https://github.com/marketplace/actions/pypi-publish

so I made next...raylu:dool:next
which ran https://github.com/raylu/dool/actions/runs/8842864700
which created https://test.pypi.org/project/dool

you can follow the pip install instructions on that last page to install it and see if it's to your liking. assuming you do, I'll send you a PR that publishes to actual pypi

@scottchiefbaker
Copy link
Owner

OMG that is amazing. You are a gentlemen and a scholar.

Yes I am definitely interested, please send a PR.

@raylu raylu mentioned this issue Apr 26, 2024
@rbavery
Copy link

rbavery commented May 8, 2024

thanks for this! can a release be created so it is published to pypi rather than test.pypi?

@scottchiefbaker
Copy link
Owner

@rbavery done and done!

https://github.com/scottchiefbaker/dool/releases/tag/v1.3.2

@raylu
Copy link
Contributor Author

raylu commented May 8, 2024

oh nice! I was gonna manually publish 1.3.1, but that works too. also glad to see my thing actually worked, heh

now that the package is created, do you want to make a pypi account and I'll add you as a mainatiner?

@scottchiefbaker
Copy link
Owner

@raylu I created an account: scottchiefbaker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants