News for hackers. Stuff that matters.
Re:How to make a Python package in 2021 by zomglings on Wednesday April 07, 2021 @10:41PM (#26734503)
The number of extra tools used in this article boggles my mind.

Are you writing a simple library? Create a setup.py. Copy paste an existing setup.py and modify it to suit your purposes. Now you have a working, pip installable python package.

Want to publish to PyPI? Use twine. It's standard and it's simple.

You don't need complicated tooling for simple projects.

Re:How to make a Python package in 2021 by vonwoodson on Thursday April 08, 2021 @07:42AM (#26737570)
Comments on this reply seem to have forgotten two key things about python.

1) It’s batteries included. The standard library is a core feature, and it is extensive in order to reduce the number 3rd party library dependencies.

2) “There should be one— and preferably only one —obvious way to do it. Although that way may not be obvious at first unless you're Dutch.” The Pythonic way is to use the standard library, setup.py, pypi, and so on. Python is not Rust, or Node, or Clojure, or anything else. Do it Pythonicly and good things will happen.

In the history of Python, it’s only because of the Zen’s guiding principles and the “come join us” attitude of the community that Python accidentally became “enterprise grade”. It succeeded in spite of the lack of Cargo or NPM, or (shudder) Mavin[, or CI/CD, or 3D game engines, or easy binary package productization, or everything else Python is obviously bad at]; almost precisely because it’s not those things. Python encourages me to get my task done, and all it asks is that I leave the flame wars at the door and embrace it for what it is.

It saddens me to see so many people jump down zomglings throat for making the daring suggestion that Pythonistas use the language as designed. Because, he is absolutely right about this: “Complex is better than complicated.”

Re:How to make a Python package in 2021 by patagonia on Thursday April 08, 2021 @09:19AM (#26738336)
Unpopular opinion: Python is bait and switch. Naive, aspiring programmers are told to learn Python because it’s the perfect beginner language, only to quickly hit a brick wall of complication they are unable to foresee (because they’re completely new to all this) and ill-equipped navigate.

Like it or not Python is now “enterprise grade”. The sooner it either grows up and figures out packages, ci/cd, binaries etc, or it looses its reputation at a great beginner and general programming language to something like Julia or Crystal, the better.

Re:How to make a Python package in 2021 by cixinlui on Thursday April 08, 2021 @09:21AM (#26738368)
The thing is that using setuptools is neither standard nor Pythonic. It isn't part of the standard library. It's a way of doing things that is broken, and has been specifically called out by the Python developer community as something that people should stop doing.
Re:How to make a Python package in 2021 by darthrupert on Thursday April 08, 2021 @01:52AM (#26735506)
I actually think one should do the exact opposite to what you're suggesting. I've experienced modern package management through Cargo and anything below that level now seems like returning to stone age.

In the python ecosystem, poorly defined packages is a wide problem. You never know what you get in the next version upgrade.

So my suggestion: burn all the "simple" python packaging tools in a big fire and move eveything to Poetry today. It will be painful at start but will increase the quality of the ecosystem by a huge margin if just 50% of the projects do this.

Re:How to make a Python package in 2021 by hardwaresofton on Thursday April 08, 2021 @03:52AM (#26736161)
Bit of a side note but remember cargo learned a lot from generations of package managers, across languages. It essentially represents some of the best that package managers have to offer. You only get that kind of result by starting from scratch every few years (as in, rust started from scratch when the Node/NPM ecosystem had been around for years to steal ideas from, Haskell had been around for years to steal language design from, etc.).

Rust is incredibly lucky to have been created when it was because it benefits immensely from these things (I think it's the best new-to-middle-aged production-usable systems language out there today).

I agree with the idea but languages like Python and their ecosystems are really hard to move (remember python 2->3? is that even over?) -- it's a herculean and often impossible task.

Re:How to make a Python package in 2021 by lmm on Thursday April 08, 2021 @06:44AM (#26737202)
Cargo is not hugely different from Maven which has been working fine for over a decade. Yes, it takes some polished ideas from other systems, but Python has had more packaging tools come and go than several other ecosystems put together.
Re:How to make a Python package in 2021 by oblio on Thursday April 08, 2021 @07:19AM (#26737407)
+1 from Maven. And Maven was launched in 2004, 17 (!) years ago. It's almost old enough to vote.

A lot of ecosystems put on some solid horse blinders in order to avoid Java at all costs (Javascript/Node/NPM being another example). They've avoided good ideas from Java for more than a decade.

Re:How to make a Python package in 2021 by afarrell on Thursday April 08, 2021 @04:45AM (#26736499)
Migrating python2 -> python3 is hard because it requires rewriting code and because you can't really run python3 code if you depend upon python2.

If poetry create consume non-poetry packages and create packages which other package management systems can consume? If so, then:

1. Projects can move more effectively independently.

2. Projects can re-package as a single task rather than a massive rewrite effort.

Re:How to make a Python package in 2021 by say_it_as_it_is on Thursday April 08, 2021 @06:03AM (#26736977)
I was hoping to see this blog post highlight poetry usage. Any good resource for this? I've already seen the official page.
Re:How to make a Python package in 2021 by raphar on Thursday April 08, 2021 @03:08PM (#26742508)
I learned with this article. And it teaches how to combine Poetry with Pyenv effectively.

https://blog.jayway.com/2019/12/28/pyenv-poetry-saviours-in-...

Re:How to make a Python package in 2021 by alexgmcm on Thursday April 08, 2021 @10:55AM (#26739511)
I quite liked the series of blog posts called Hypermodern Python: https://cjolowicz.github.io/posts/hypermodern-python-01-setu...
Re:How to make a Python package in 2021 by schnitzelstoat on Thursday April 08, 2021 @10:54AM (#26739489)
Like the other commenter, I was also expecting them to use Poetry.

It's the best one I've tried so far.

Re:How to make a Python package in 2021 by avhception on Thursday April 08, 2021 @11:53AM (#26740295)
Came here to about how it would be better to use poetry, thanks for spelling it out for me.
Re:How to make a Python package in 2021 by BerislavLopac on Thursday April 08, 2021 @04:43AM (#26736484)
Using setup.py does not mean "not using extra tools". It depends on setuptools, which is an "extra tools" just like flit (used in the article) or any other tool. In fact, with using only setuptools one will need a whole additional set of tools to manage things like:

    * virtual environments (granted, venv is now part of the stdlib, but it's still an "extra tool")
    * publishing to PyPI or another index (twine)
    * dependency management (both for development and actual dependencies)
Plus the tools that are needed anyway, to manage common development actions like:

    * unit tests (pytests)
    * static typing (mypy)
    * linting (flake8, pylint)
    * styling (black)
The article is correct in using pyproject.toml, which has become the standard way to specify build mechanism for your package [0]. Even setuptools supports it in the latest versions [1], meaning that setup.py is becoming obsolete, or at least unnecessary.

Finally, tools like Poetry [2] offer a whole set of functionalities in one place (dependency management, virtual environments, publishing), which means that they need fewer "extra tools" than just setuptools.

[0] https://www.python.org/dev/peps/pep-0518/

[1] https://setuptools.readthedocs.io/en/latest/build_meta.html

[2] https://python-poetry.org/

Re:How to make a Python package in 2021 by say_it_as_it_is on Thursday April 08, 2021 @06:06AM (#26736985)
Where is there a comprehensive poetry packaging tutorial?
Re:How to make a Python package in 2021 by BerislavLopac on Thursday April 08, 2021 @11:30AM (#26740045)
Right here:

    poetry build -f wheel
    poetry publish
You asked for packaging, and that is pretty much it. Of course, setting up a project and its dependencies take a bit more work; the basic intro for that is here: https://python-poetry.org/docs/basic-usage/
Re:How to make a Python package in 2021 by say_it_as_it_is on Sunday April 11, 2021 @01:30PM (#26771961)
That is fantastic.
Re:How to make a Python package in 2021 by neolog on Wednesday April 07, 2021 @10:59PM (#26734623)
How do you handle version pinning? hash checking? CI? testing on multiple platforms? multiple python versions? deployment? credential management? package data? version bumps?

Sure, experts know how to do all these things because they spent many days learning them, but I'd rather outsource to a tool.

Re:How to make a Python package in 2021 by zomglings on Wednesday April 07, 2021 @11:07PM (#26734665)
Iteratively. You don't need to solve all those problems at once.

Version pinning can be done in setup.py using the same syntax you would see in a requirements.txt file. You should be very conservative when pinning versions in a library, though.

You can lean on your ci tool (eg. Github actions) to handle testing, hash checking, credential management, etc. But I recommend all of this start as a bunch of locally runnable scripts.

I typically bump version directly in a version file and move on with my life.

This stuff usually builds up iteratively and at least for me has never been the starting point. Starting point should be a library worth sharing. It is not the end of the world of you release the first few versions manually.

Re:How to make a Python package in 2021 by staticassertion on Wednesday April 07, 2021 @11:20PM (#26734747)
TBH as someone trying to use Python professionally it is extremely frustrating that basic things with regards to package management are something you have to iterate towards, as opposed to just being obvious and default.
Re:How to make a Python package in 2021 by TylerE on Wednesday April 07, 2021 @11:30PM (#26734817)
One thing that has become clear to me, from playing around a bit with go, rust, and nim, is that it is astonishingly better when the language has exactly one set of tools, that everyone uses.

Even if that set of tools is kinda crappy (Glances at go), it's just so nice to not have all the bikeshedding and just get on with it.

Re:How to make a Python package in 2021 by CraigJPerry on Thursday April 08, 2021 @05:07AM (#26736641)
I’m not familiar enough with Go but at first glance the go mod stuff seemed pretty decent.

E.g. more flexible than Cargo in that you could have a large codebase with two different versions of a dependency isolated to their compile units allowing you to gradually adopt a breaking change dependency in a large code base. I was kinda bowled over with that feature (the isolation part is key).

For python I’m finding poetry much more ergonomic than pipenv, it’s not just the speed difference it’s the convenience of one tool which aligns with what you’re saying although the existence of poetry doesn’t delete historical aberrations in Python’s long history.

Re:How to make a Python package in 2021 by zomglings on Wednesday April 07, 2021 @11:25PM (#26734788)
I sympathize. It is unfortunate that the python community never settled around a tool like leiningen for clojure or cargo for rust or npm for node.

What we saw with npm was the entire community iterating towards a feature set and everyone reaping the benefits automatically with npm updates. package-lock.json is a good example of this.

Re:How to make a Python package in 2021 by brundolf on Wednesday April 07, 2021 @11:51PM (#26734923)
Worth noting is that cargo and npm weren't "settled around"; they were developed and presented, from the beginning, alongside the relevant compiler and runtime. There was never a question; the batteries were included.

Leiningen is the weird one where people did actually settle fairly well around an unofficial solution in the absence of an official one. I think the norm with languages that forego official tooling is closer to what we've seen in Python.

Re:How to make a Python package in 2021 by xapata on Thursday April 08, 2021 @12:29AM (#26735098)
The Python community has considered an "official" packaging tool in the past, but in those conversations found that the community had too many preferences to find a good compromise. That's the trouble with having a highly diverse set of uses and integrations, and lots of legacy.

If you're curious, the email threads about Conda and defining wheels are interesting.

Re:How to make a Python package in 2021 by staticassertion on Thursday April 08, 2021 @12:42AM (#26735157)
I feel like the entire point of a BDFL is that they can just ignore this sort of thing and make the hard call, but it never happened.
Re:How to make a Python package in 2021 by divbzero on Thursday April 08, 2021 @01:05AM (#26735267)
Maybe it could still happen? It seems like a super high value challenge that the BDFL could take on: build out the official set of tools (setup.py, twine, virtualenv, pip) to support features that make people seek out alternatives (pyproject.toml, poetry, flit, conda, pyenv, pipenv).
Re:How to make a Python package in 2021 by jolux on Thursday April 08, 2021 @01:49AM (#26735486)
I realize this is controversial but from reading the docs I really thought Pipenv was the official solution. Took me a while to realize this wasn't the case.
Re:How to make a Python package in 2021 by divbzero on Thursday April 08, 2021 @02:01AM (#26735553)
I went through the same progression, thinking pipenv was the official solution before deciding it wasn’t. Then, just now, I realized that pipenv [1] is currently owned by the Python Packaging Authority (PyPA) who also owns pip [2] and virtualenv [3]. I don’t know the right answer but this illustrates the confusion of not coalescing around an official solution.

[1]: https://github.com/pypa/pipenv

[2]: https://github.com/pypa/pip

[3]: https://github.com/pypa/virtualenv

Re:How to make a Python package in 2021 by toyg on Thursday April 08, 2021 @05:11AM (#26736670)
What happened was that Kenneth Reitz socially-engineered his way into the PyPA to get his tool blessed. The community lashed out (since the tool had obvious shortcomings and a somewhat dubious development process) and recommendations were softened. Eventually the PyPA had to take over pipenv when Reitz had other issues, and they are now forever burdened with what is a bit of a dud.
Re:How to make a Python package in 2021 by xapata on Thursday April 08, 2021 @02:08AM (#26735600)
As I understand it, that was to prevent bad behavior rather than to signal approval.
Re:How to make a Python package in 2021 by staticassertion on Thursday April 08, 2021 @01:46AM (#26735464)
I think the time has passed, both in terms of there no longer being a BDFL, as well as Python passing a point where the call can be made.
Re:How to make a Python package in 2021 by divbzero on Thursday April 08, 2021 @01:52AM (#26735503)
Sadly I bet you’re right on this. My small sliver of hope is that Guido van Rossum’s ideas to “make using Python better” [1] include better packaging.

[1]: https://news.ycombinator.com/item?id=25071847

Re:How to make a Python package in 2021 by takluyver on Thursday April 08, 2021 @04:31AM (#26736412)
There are quite a lot of people working on better packaging (look at the Python discourse forum, for instance), but this is not really a topic that Guido has got involved in, at least in the time I've been paying attention.

But with or without a BDFL, one packaging tool to rule them all is a pretty tall order. The needs of a package like scipy, which incorporates C & Fortran code, are pretty different from something like requests. And different communities using Python have their own entrenched tools and techniques. It takes more than someone saying "Foo is officially blessed" to shift that, even if everyone respects the person saying that.

Re:How to make a Python package in 2021 by arthurcolle on Thursday April 08, 2021 @02:00AM (#26735550)
Is there a new BDFL? I remember reading this half a year ago or so https://hub.packtpub.com/why-guido-van-rossum-quit/
Re:How to make a Python package in 2021 by xapata on Thursday April 08, 2021 @12:55AM (#26735225)
On the whole, Guido's career as a BDFL was astoundingly effective. Maybe he made the right call. It'd have been a terrible idea to alienate the science community just when data science was taking off as a field.
Re:How to make a Python package in 2021 by staticassertion on Thursday April 08, 2021 @01:51AM (#26735500)
I'm not disagreeing, but I am curious if you have anything specific you would point to with regards to Guido's role being successful. I'm just ignorant really, it's not intended to be a leading question at all.
Re:How to make a Python package in 2021 by xapata on Thursday April 08, 2021 @02:01AM (#26735557)
Too many things to answer here. The easiest is to point to the popularity of the language. He's made decisions I disagree with, but I can't argue with success.
Re:How to make a Python package in 2021 by neolog on Thursday April 08, 2021 @02:04AM (#26735573)
I don't know how much the original author had to do with Python's success in the last 20 years. The success of Python in data science is because of NumPy/Scipy/Pandas. Things like packaging that needed leadership never got any.
Re:How to make a Python package in 2021 by xapata on Thursday April 08, 2021 @02:09AM (#26735609)
The leadership was that the science community would benefit from a science-specific tool, like Conda, and that making one ring to rule them all would be too difficult.

Also, yes, Guido and many other early contributers have been been active for 30ish years.

Re:How to make a Python package in 2021 by neolog on Thursday April 08, 2021 @08:55PM (#26745637)
Conda isn't really science specific, just like pip isn't webdev specific.
Re:How to make a Python package in 2021 by xapata on Friday April 09, 2021 @11:46AM (#26752046)
The result isn't, but the motivation was. And have you noticed who is using which tool?
Re:How to make a Python package in 2021 by toyg on Thursday April 08, 2021 @04:57AM (#26736588)
> The success of Python in data science is because of NumPy/Scipy/Pandas.

And NumPy/Scipy/Pandas exist (and are successful) because...? /s

Re:How to make a Python package in 2021 by regularfry on Thursday April 08, 2021 @10:32AM (#26739185)
Rubygems, and then Bundler, followed the same pattern. Neither was batteries-included, both were unofficial community efforts. Bundler directly influenced cargo.
Re:How to make a Python package in 2021 by CraigJPerry on Thursday April 08, 2021 @05:10AM (#26736663)
Yarn / npm are still in competition today i think?

The js tooling is particularly immature, e.g. fake packages along with typo squatting is rife. Compare with boring old maven where that’s not been an issue in >10 years at this point.

Re:How to make a Python package in 2021 by staticassertion on Wednesday April 07, 2021 @11:28PM (#26734803)
I completely agree. Elsewhere we see sanity by default, in Python there's still open questions and hopeful but early stage projects.
Re:How to make a Python package in 2021 by marcinzm on Wednesday April 07, 2021 @11:32PM (#26734829)
The issue is that every time the community settles on a tool a new tool is made to fix the issues with the old tool rather than just refactoring the old tool.
Re:How to make a Python package in 2021 by mrweasel on Thursday April 08, 2021 @01:54AM (#26735512)
I think the Python community have largely settled on pip, just like the JavaScript community have mostly opted for npm.

Personally I much prefer pip over npm, it feels much more polished.

Re:How to make a Python package in 2021 by type0 on Friday April 09, 2021 @12:34PM (#26752656)
but pip isn't enough and not exactly user friendly
Re:How to make a Python package in 2021 by cixinlui on Thursday April 08, 2021 @05:10AM (#26736665)
I know Python much better than I do rust or node, but I think the Python design decision was decent here: you can use different tools, but all of them should put the configuration in pyproject.toml. That file has fields which are universal and others which can depend on the exact tooling used. So build tools, repos and so on can get the info they need and at least potentially, do the right thing for code packages with different tools.
Re:How to make a Python package in 2021 by blondin on Wednesday April 07, 2021 @11:53PM (#26734934)
yea, it is. but it's a sane thing to do. recommending poetry for a beginner is a bad idea. (nothing against that package).

python is a mature, old, software system. three times older than go or rust. way older than zig. these modern languages have learned from the field as a whole and implemented tools that people are taking for granted nowadays.

as with any mature software system, people & companies have established their preferred ways of doing things. it's going to be hard to have the language council dictate ways of doing things.

i would recommend going simple and using the standard set of modules until poetry or whatever gets into it.

Re:How to make a Python package in 2021 by feu on Thursday April 08, 2021 @05:26AM (#26736765)
Recommending the standard set of modules is the opposite of "going simple." Poetry removes a lot of the complexity and user-unfriendliness inherent in the previous set of standard modules. For any Python beginner coming from another popular language Poetry is likely going to be very similar to the dependency and package management in the language they're coming from. Python's standard set of modules sticks out like a sore thumb when compared to the tools in other popular languages.
Re:How to make a Python package in 2021 by staticassertion on Thursday April 08, 2021 @12:43AM (#26735165)
Well, Python did set up a standard - pyproject.toml. And it's what poetry uses. It's just, uh, "light".
Re:How to make a Python package in 2021 by goerz on Thursday April 08, 2021 @01:11AM (#26735287)
It's also not ready yet, missing critical features like editable installs. Right now, you still need a shim setup.py. Until pyproject.toml can actually replace setupy.py, I see little incentive to start using it: It's just one more file to add. The one exception is if the package actually has build requirements, e.g. for Cython modules.
Re:How to make a Python package in 2021 by zo1 on Thursday April 08, 2021 @02:36AM (#26735774)
The only reason we use pyproject.toml is because of the stupid black formatter that refuses to support setup.cfg, which every other python tool under the sun supports.
Re:How to make a Python package in 2021 by goerz on Thursday April 08, 2021 @02:52PM (#26742347)
Yeah, it's annoying. But Black has so little configuration that I'm ok with hardcoding command-line parameters in my Makefile/tox.ini/precommit hooks (`--skip-string-normalization --line-length 79`)
Re:How to make a Python package in 2021 by mixmastamyk on Thursday April 08, 2021 @04:22AM (#26736349)
There are other formatters, some may even be better.
Re:How to make a Python package in 2021 by cixinlui on Thursday April 08, 2021 @05:12AM (#26736682)
I don't recognize this. I use poetry all the time, without setup.py and the local installs are editable. I have published half a dozen packages which don't have a setup.py and they all work fine.
Re:How to make a Python package in 2021 by neolog on Thursday April 08, 2021 @08:01PM (#26745274)
You can't install a poetry package editably into another environment. It's really a missing feature in the pyproject spec. There's an open issue about it under one of the pypa repos. Someone just needs to do the work of implementing it in pip/setuptools.
Re:How to make a Python package in 2021 by neolog on Thursday April 08, 2021 @05:40PM (#26744106)
> recommending poetry for a beginner is a bad idea.

Strongly disagree. There are so many footguns with low-level tools like pip that I can't recommend it to anybody but an expert (but an expert doesn't need my recommendation anyway).

Re:How to make a Python package in 2021 by ehsankia on Wednesday April 07, 2021 @11:17PM (#26734732)
To be fair, while this is a single article, if you only look at step 1, 2 and 3, you get a fully published package with only one tool used (flit) and not much extra.

It's the succeeding sections (A, B, C, D, E) that get more advanced, but they're all optional. You should definitely do A, but the rest I'd say it's a lot more opinionated and definitely not needed.

Re:How to make a Python package in 2021 by zomglings on Wednesday April 07, 2021 @11:27PM (#26734794)
Fair point. I wouldn't recommend this article to someone just starting out with python, though. It's often good to understand generation n-1's way of doing things but not too be married to it.
Re:How to make a Python package in 2021 by dagenix on Thursday April 08, 2021 @12:37AM (#26735132)
> Version pinning can be done in setup.py using the same syntax you would see in a requirements.txt file

The problem with this approach is that it doesn't handle transitive dependencies well. Say you depend on version 1.4.6 of a particular library. And then that library depends on version >= 2 of some other library. When you install your package, you know that you'll get version 1.4.6 of the first library but have no idea what version you'll get of the second library. You can of course pin all the transitive dependencies - except that clutters up the setup.py and is a massive pain to keep up to date as you bump individual dependency versions.

Re:How to make a Python package in 2021 by knome on Thursday April 08, 2021 @01:23AM (#26735347)
Seems like a solid argument for a switch to use go's minimal version selection

the version selected during a build is the one with the most minimal version that satisfies all other constraints. this means if you have libA that needs dep>=1.1 and libB that needs dep>=1.3, you get dep=1.3 even if dep1.9 is out. your build never changes because of a new version release, as long as they release with proper semantic versioning. if you later include libC that needs dep>=1.8, you'll get that version. but because you changed your immediate dependencies, not due to a surprise down the dependency line.

https://research.swtch.com/vgo-principles

Re:How to make a Python package in 2021 by dagenix on Thursday April 08, 2021 @02:37AM (#26735775)
Its at least consistent - which, IMO, is better than just getting a random version. I do, however, think it's a bit unfortunate that it prevents picking up bug / security fixes in transitive dependencies.

Imagine that you depend on library A of a particular version which itself depends on library B. With minimal version selection, as long you don't bump you dependency on library A (or some other library that depends on library B), you'll continue to get that same version of library B. But, then library B releases a critical security fix. With minimal version selection, there isn't a great way to pick up that fix. You can _hope_ that library A releases a new version that requires the fix - but that may or may not happen and could take a while. Or, you could add an explicit dependency on the new version of library B - which is unfortunate, since, your main package doesn't depend on library B directly.

Lock files solve this problem. You can depend on whatever version of library A that you need and lock the transitive dependencies. And once library B releases its fix, you can update your lock file without having up bump the version of library A.

Tools like poetry providing the features to automate this workflow.

Re:How to make a Python package in 2021 by BerislavLopac on Thursday April 08, 2021 @04:58AM (#26736594)
> You should be very conservative when pinning versions in a library, though

No; you should be very conservative when pinning versions in an application, not in a library. Check this article for the explanation: https://caremad.io/posts/2013/07/setup-vs-requirement/

Re:How to make a Python package in 2021 by toyg on Thursday April 08, 2021 @05:21AM (#26736747)
Anybody familiar with the history of requests knows this is bad advice.
Re:How to make a Python package in 2021 by BerislavLopac on Thursday April 08, 2021 @11:33AM (#26740081)
requests is definitely not a good example here. :/
Re:How to make a Python package in 2021 by neolog on Wednesday April 07, 2021 @11:16PM (#26734727)
> You don't need to solve all those problems at once.

Why spend time tweaking the setup when you can just get it right in the first place with less work?

Re:How to make a Python package in 2021 by zomglings on Wednesday April 07, 2021 @11:21PM (#26734753)
Do you recommend poetry?

I've been meaning to try it but haven't had the time to migrate an existing project to poetry.

Re:How to make a Python package in 2021 by atoav on Thursday April 08, 2021 @03:31AM (#26736058)
I used poetry for multiple projects already and I quite like it because it makes version management really straightforward and you can just go like

  poetry new foo
And it will setup all the basic stuff for you right away. Having all the project dependecies and Metadata in pyproject.toml makes sense and reduces cognitive overload. Having poetry manage your venvs autmagically is a good extra.

There is still room for improvement, e.g. I had some trouble with their install script at times (python vs python3)

Re:How to make a Python package in 2021 by neolog on Wednesday April 07, 2021 @11:28PM (#26734804)
Yeah it's pretty good. There are plenty of problems and holes of course, but for most pure-Python packages it does a nice job most of the time.

If you're an expert, you can do it with setup.py or setup.cfg, but I don't think it's normally worth the trouble.

Re:How to make a Python package in 2021 by 1337shadow on Thursday April 08, 2021 @03:12AM (#26735961)
I usually don't pin, I'd rather deal with upstream BC breaks as they are published instead of accumulating tech debt. I call this "continuously integrating upstream code", because Continuous Integration is a practice, not a tool.
Re:How to make a Python package in 2021 by globular-toast on Thursday April 08, 2021 @03:23AM (#26736016)
You don't pin anything for a package. I'm not aware of any "standard" CI that a package tool could set up. I guess you mean testing on multiple versions, in which case tox will help. Deployment for a package is handled by twine. Package data? What about it? Version bumps should always be manual but I recommend setuptools-scm.

You seem to be confusing packages with "apps". It's very important to understand the clear distinction between these.

Re:How to make a Python package in 2021 by neolog on Thursday April 08, 2021 @03:46PM (#26742924)
> You seem to be confusing packages with "apps".

I'm not confusing libraries with applications. Pinning dependency versions enables a repeatable test environment.

Re:How to make a Python package in 2021 by asdf123wtf on Thursday April 08, 2021 @10:33AM (#26739204)
I generally reach for pip-tools, when I need to pin versions in a requirements for a deployable app, like an api.

It's by far the simplest option I've found.

If your project is a library, just use setup.py and express your deps abstractly (min, max or version range). Don't pin to specific versions at all, if you can help it.

Re:How to make a Python package in 2021 by cixinlui on Thursday April 08, 2021 @05:06AM (#26736636)
This is bad advice. Do not create a setup.py for a new package. (Keeping setup.py for an old package can be okay.)

The author is correct that you want a tool such as flit or poetry which will work with pyproject.toml. Setting up a basic package will be no harder than using setuptools, and it is much more future-proof. You won't have to copy-paste some other crufty setup config either.

It is fair that you don't need all the external tools in this tutorial. In particular, using make is very silly since you can configure different linting and testing workflows directly in pyproject.toml, rather than pull in a whole other system which only works decently on *nix. Poetry also removes the need for tox.

Re:How to make a Python package in 2021 by remram on Thursday April 08, 2021 @10:36AM (#26739234)
Future-proof... Poetry 1.1 broke compatibility with 1.0. 1.1 lockfiles would crash Poetry 1.0, and 1.0 lockfiles would be thrown away by Poetry 1.1.

It does not correctly verify hashes (if at all) [1]. You can't add packages without updating all your dependencies. Monorepos are not supported. PEP-508-compliant Git dependencies cause the tool to crash with TypeError [2].

I think Poetry is the right direction, I use it for everything, but it's not the silver bullet you're painting it to be (yet). It's definitely not on par with Cargo, or maybe even npm.

[1]: https://github.com/python-poetry/poetry/issues/3765 [2]: https://github.com/python-poetry/poetry/issues/3425

Re:How to make a Python package in 2021 by cixinlui on Thursday April 08, 2021 @10:59AM (#26739584)
I didn't say it was a silver bullet... I said "Don't Use setup.py".
Re:How to make a Python package in 2021 by remram on Thursday April 08, 2021 @12:01PM (#26740403)
Fair enough. I saw many mentions of Poetry and merged them in my head when I finally replied. Apologies.
Re:How to make a Python package in 2021 by clawlor on Thursday April 08, 2021 @05:16PM (#26743858)
Unfortunately, the pyproject.toml format still doesn't support editable installs. So, setup.py is still required if you need this feature.
Re:How to make a Python package in 2021 by 1337shadow on Thursday April 08, 2021 @07:12AM (#26737351)
And why exactly do you think setup.py is deprecated?
Re:How to make a Python package in 2021 by cixinlui on Thursday April 08, 2021 @09:00AM (#26738158)
Because of PEP 518.
Re:How to make a Python package in 2021 by someoldguy on Wednesday April 07, 2021 @10:46PM (#26734535)
I would probably recommend just following https://packaging.python.org/tutorials/packaging-projects/ instead.
Re:How to make a Python package in 2021 by zomglings on Wednesday April 07, 2021 @11:08PM (#26734670)
Ah I'm stuck in the dark ages.
Re:How to make a Python package in 2021 by fctorial on Thursday April 08, 2021 @05:35AM (#26736815)
For all the hate nodejs gets, it solved the software packaging problem. That is the sole reason npm ecosystem is so big.

I have to say that it probably isn't a fare comparison because python is much older than nodejs. Python package management might very well have been state of the art in 1995.

Re:How to make a Python package in 2021 by chriswarbo on Thursday April 08, 2021 @06:23AM (#26737082)
My impression was that npm does little more than fetch code from the Web and stick it in a 'node_modules' directory. I've even seen npm used for things that aren't even JS, just bunch of files.

This approach ends up with multiple, potentially-incompatible versions of the same package in a project. True that's less of a problem in JS, since it's interpreted (deferring imports to runtime) and un(i)typed (no need to check if interfaces match up). Yet even that has lead to replacements/complements like yarn.

Re:How to make a Python package in 2021 by oefrha on Thursday April 08, 2021 @08:59AM (#26738151)
> My impression was that npm does little more than fetch code from the Web and stick it in a 'node_modules' directory.

Yes. There's hardly even a standard directory structure, let alone a standard way to convert source code to published code. Every slightly non-trivial repo basically has an ad hoc build system of its own. Ever tried to fix a bug in a package, and realized that using git://github.com/user/repo#branch doesn't work, because npm only downloads the source code, which bears no resemblance to the built products? I fixed two bugs in two third party packages within the past week, had to deal with this twice. Ran into the Node 12+ and Gulp 3.x incompatibility issue twice in the past month (with totally modern, actively developed packages), too.

npm has more sophisticated dependency resolution and locking than pip, sure. Python packaging is more consistent in basically every other regard.

Re:How to make a Python package in 2021 by fctorial on Thursday April 08, 2021 @07:19AM (#26737415)
> This approach ends up with multiple, potentially-incompatible versions of the same package in a project.

If data generated by one version of a library is being consumed by another version, that's a bug in the code that moves data between them.

Re:How to make a Python package in 2021 by geraneum on Thursday April 08, 2021 @04:16AM (#26736312)
Maybe the reason that the library itself is simple in the article is that that’s just an example and the author wants to show how to do it properly, end to end.
Re:How to make a Python package in 2021 by kkirsche on Thursday April 08, 2021 @07:41AM (#26737563)
Re:How to make a Python package in 2021 by da39a3ee on Wednesday April 07, 2021 @11:13PM (#26734703)
You seem to have missed the point. The project in the article was simple because that is best for exposition. The article would hardly have been more helpful with the code for a realistic python package dumped into it, would it?