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

Add dependency badge for Pipenv applications [GithubPipenv] #4096

Merged
merged 12 commits into from
Oct 2, 2019

Conversation

paulmelnikow
Copy link
Member

@paulmelnikow paulmelnikow commented Sep 27, 2019

I recently published https://github.com/metabolize/rq-dashboard-on-heroku and want to add badges to show the locked version of Python and rq-dashboard, the main dependency it’s wrapping.

This is along the lines of #2259, which was for package.json-based applications, and also included some discussion of a Python application that used requirements.txt. It’s useful for showing the pinned version of any dependency in a Python application that uses a lockfile.

In the future, as an alternative to reading Pipfile.lock, I could see expanding this to read Pipfile. However for my purposes I prefer to show the locked dependency, since that’s the version that a user of my package would actually get if they ran it on Heroku.

I recently published https://github.com/metabolize/rq-dashboard-on-heroku and want to add badges to show the locked version of Python and rq-dashboard, the main dependency it’s wrapping.

This is along the lines of #2259, which was for package.json-based applications, and also included some discussion of a Python application that used `requirements.txt`. It’s useful for show the pinned version of any dependency in a Python application that uses a lockfile.

In the future, as an alternative to reading Pipfile.lock, I could see expanding this to read Pipefile. However for my purposes I prefer to show the locked dependency, since that’s the version that a user of my package would actually get if they ran it on Heroku.
@paulmelnikow paulmelnikow added the service-badge Accepted and actionable changes, features, and bugs label Sep 27, 2019
@shields-cd shields-cd temporarily deployed to shields-staging-pr-4096 September 27, 2019 17:25 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-4096 September 27, 2019 17:25 Inactive
@shields-ci
Copy link

shields-ci commented Sep 27, 2019

Messages
📖 ✨ Thanks for your contribution to Shields, @paulmelnikow!

Generated by 🚫 dangerJS against af576df

serviceInstance,
{ schema, user, repo, branch = 'master', filename }
{ user, repo, branch = 'master', filename }
Copy link
Member Author

Choose a reason for hiding this comment

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

I hadn't realized that Pipfile is TOML but Pipfile.lock is JSON, so I unnecessarily refactored this. However it'd help with #3960 and #4068 (comment) so seems worth keeping.

Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@@ -3,7 +3,6 @@
const Joi = require('@hapi/joi')
const t = (module.exports = require('../tester').createServiceTester())

// These regexes are the same, but declared separately for clarity.
Copy link
Member Author

Choose a reason for hiding this comment

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

This probably referred to isPipeSeparatedDjangoVersions but these are no longer in the same file.

@paulmelnikow paulmelnikow marked this pull request as ready for review September 27, 2019 17:41
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-4096 September 27, 2019 17:41 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-4096 September 27, 2019 20:06 Inactive
Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

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

🐍

services/pipenv-helpers.js Outdated Show resolved Hide resolved
} else if (kind === 'prod') {
dependenciesOfKind = lockfileData.default
} else {
throw Error(`Not very kind: ${kind}`)
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a bit of an odd error. I'd be confused by it if it popped up in Sentry 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Heh. Copy-pasted from package-json-helpers. There was some chat about it then; basically it's an assertion failure which is unlikely ever to happen. Can change it to something more specific though.

Copy link
Member

@calebcartwright calebcartwright Sep 28, 2019

Choose a reason for hiding this comment

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

This would only happen in the event of a programming error, correct? For example a developer doing something wholly unexpected like

getDepenencyVersion({ kind: 'magic' })

services/pipenv-helpers.js Show resolved Hide resolved
services/pipenv-helpers.js Outdated Show resolved Hide resolved
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-4096 September 27, 2019 23:02 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-4096 September 27, 2019 23:03 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-4096 September 28, 2019 15:29 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-4096 September 28, 2019 15:31 Inactive
repo: 'rq-dashboard-on-heroku',
},
staticPreview: this.render({ version: '3.7' }),
documentation,
Copy link
Member

Choose a reason for hiding this comment

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

Will it be evident to end users (either from the locked word in the example and/or route) that this is will only work with a lockfile? Would it be helpful to include some additional text in documentation to convey that?

I've never worked with Pipenv so not sure whether that additional info would helpful or just duplicative clutter

Copy link
Member

Choose a reason for hiding this comment

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

I reckon it will probably be OK, but we could change from "GitHub Pipenv locked Python version" to "GitHub Pipenv Python version from Pipfile.lock" (etc) just to be super clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, agreed, I approached this badge more from a developers perspective than usual and was thinking documentation would be helpful.

In the long run some explanatory documentation could be useful on all our badges.

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up not adding Pipfile.lock to the title, rather writing some pretty extensive docs of what the badge is for, designed for people who don't necessarily have any context.

chris48s
chris48s previously approved these changes Sep 28, 2019
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-4096 September 29, 2019 15:27 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-4096 September 29, 2019 15:29 Inactive
Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

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

👍

@h1nk
Copy link

h1nk commented Oct 2, 2019

It seems like if the default branch name is not master than the badge option with no branch specified fails. I'm assuming that's why there is a second option with the branch name, but is there a simple way to make it so the default branch is used on the badge with no branch name specified? For example I have this repository with a default branch name of stable and the badge errors like so: https://shields-staging-pr-4096.herokuapp.com/github/pipenv/locked/python-version/h1nk/django-recipes

If this is the default behavior for all the badges that rely on GitHub repository content than disregard this comment, I'm just curious.

@paulmelnikow
Copy link
Member Author

Hi @h1nk, thanks for the question. I just dug into this for a minute and while I think we can fetch repo contents from the default branch using the API, those queries are only used when you self-host with your own GitHub credentials. On the production server we fetch repo contents using raw.githubusercontent.com URLs which as far as I can tell need the branch hard-coded (i.e. you can't ask for the default branch).

We do have a lot of API quota at our disposal so if pulling content from the default branch seems important, we could drop this quota optimization and always use the API. It'd also simplify the code which is a plus.

@h1nk
Copy link

h1nk commented Oct 2, 2019

I think the badges that already have options to specify branch names explicitly should probably be kept for user who wish to use them, but it would definitely be great to see automatic default branch detection for the badges with no branch name specified if it doesn't incur a significant API quota penalty and isn't too problematic to change in the codebase.

I'd love to hear some input from others about whether this would be a good or bad addition. :)

@paulmelnikow
Copy link
Member Author

Probably not blocking this, and it's not the only badge affected. Would you mind opening a new issue to discuss it?

I left this open for a few days in case @chris48s wanted to take another pass but I think I'll go ahead and merge.

@shields-deployment
Copy link

This pull request was merged to master branch. This change is now waiting for deployment, which will usually happen within a few days. Stay tuned by joining our #ops channel on Discord!

After deployment, changes are copied to gh-pages branch:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge Accepted and actionable changes, features, and bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants