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

propagate configuration from paste.ini #156

Merged
merged 3 commits into from Feb 21, 2017

Conversation

luismsgomes
Copy link
Contributor

Here's an example paste.ini:

[composite:main]
use = egg:Paste#urlmap
/pypi/ = pypiserver

[app:pypiserver]
use = egg:pypiserver#main
root = %(here)s/packages
authenticated = list update download
redirect_to_fallback = False
password_file = %(here)s/htpasswd.txt
log_file = %(here)s/log.txt
verbosity = 2

[server:main]
use = egg:gunicorn#main
host = 127.0.0.1
port = 8001
workers = 4
accesslog = %(here)s/accesslog.txt

The following configuration keywords were not being propagated into the app:

authenticated = list update download
password_file = %(here)s/htpasswd.txt
log_file = %(here)s/log.txt
verbosity = 2

Now it works.
Hope you like the code.
I tried to keep same style.

@luismsgomes luismsgomes mentioned this pull request Jun 30, 2016
@ankostis ankostis force-pushed the master branch 2 times, most recently from bf450bc to 117a61e Compare July 2, 2016 23:44
def upd_conf_with_list_item(conf, attr, sdict, sep=' ', parse=str_strip):
values = sdict.pop(attr, None)
if values:
conf[attr] = list(filter(None, map(parse, values.split(sep))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: use list comprehension here, as it is easier to read:

conf[attr] = [parse(v) for v in values.split(sep) if v]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is easier to read but your list comprehension is not exactly equivalent to the code it replaces.
To make it equivalent, we must call parse() twice for each value:

conf[attr] = [parse(v) for v in values.split(sep) if parse(v)]

That's why I opted for the list/map/filter combination.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Please let me know if you prefer the list comprehension with the two parse() calls)

@mplanchard
Copy link
Contributor

Thanks for the contribution! I made a few comments throughout the code, and I'd also like to see a test for this before merging. If you're comfortable with py.test, feel free to contribute a test. If not, let me know, and I will write one.

@mplanchard mplanchard self-assigned this Jul 14, 2016
@luismsgomes
Copy link
Contributor Author

Sorry, I'm not familiar with py.test yet (or other testing frameworks for Python). That is something I want to learn, but haven't find the time, yet. I'm leaning towards unittest for my own projects (because it is part of the standard library more than anything else).

@mplanchard mplanchard mentioned this pull request Jul 17, 2016
@mplanchard
Copy link
Contributor

@luismsgomes, would you mind rebasing onto master and pushing this branch so we can verify whether the test failures are due to new things or issues that have already been resolved?

@luismsgomes
Copy link
Contributor Author

Hi, I will try my best. I'm not yet familiar with git rebase (my primary versioning system is mercurial).

@ankostis
Copy link
Member

Dear @luismsgomes qnother option is to gradually cherry-pick your commits on top of master,
so that you can resolve any conflicts more relaxed:

git checkout -b  proppaste  origin/master

git cherry-pick ed0985f
git cherry-pick a4229f2
git cherry-pick 4adfd62

git branch master -f

git push <your-remote> master

Tip: in general, when creating PRs, it is better to create a separate branch (i.e. proppaste), and push that branch, instead of your master. Otherwise, you have bound you master for this PR only, and cannot have it follow the upstream evolution.
Note that if you decide this time to push proppaste instead of master, then you have to open a new GitHub PR, close this one, and add a comment to the new one referring to the discussion here.
I hope I did not confused you further :-)

@luismsgomes
Copy link
Contributor Author

Dear @ankostis, I might have messed things because I don't quite know how git rebase or cherry-pick works... I did a pull from your master repository and git said it was replaying my changes on top of it. It didn't ask me to merge anything. I did a push and now github says my fork is 22 commits ahead and 22 commits behind, which I don't understand at all.
Please forgive if I have messed things. I really want to learn git, but right now I have a pressing deadline to deliver my phd thesis and thus I can't take my time to learn git now.
Hope you understand.

@ankostis
Copy link
Member

No prob, I have fixed it for you.

Assuming you are on your master and have no un-committed changes in your working dir,
just execute the following commands:

git remote add ankostis https://luismsgomes@github.com/ankostis/pypiserver.git
git fetch ankostis
git reset --hard ankostis/proppaste
git log -1

And now your master should point in this commit:

git log -1
commit 86cbda1719c4aebc7579179542e8dd487c37da04
Author: Luís Gomes <luismsgomes@gmail.com>
Date:   Thu Jul 14 09:51:32 2016 +0100

    minor refactoring; removed extraneous print()

Then just git push <your-remote> master -f.

@@ -15,7 +15,7 @@ pytest>=2.3
webtest; python_version != '2.5'
mock; python_version <= '3.2'
gevent>=1.1b4; python_version >= '3'
twine>=1.6.1
twine>=1.7,<=1.7.4
Copy link
Member

Choose a reason for hiding this comment

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

Why is this pinning?

Copy link
Contributor

Choose a reason for hiding this comment

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

So, this shouldn't be registering as a change, and I don't think it would be with a proper rebase. This is from PR #158, which has already been merged. It was originally added because twine 1.8 breaks our test_server tests due to a new call signature.

@ankostis
Copy link
Member

ankostis commented Feb 15, 2017

Dear @mplanchard I've just finished my 6-month effort to "release" my daily work, so I haven't fully recovered my slices of free time for this project:-)
Can you make sense out of this PR?
Take my 86cbda1 commit if it helps you.

@mplanchard
Copy link
Contributor

Sure thing @ankostis! I have been busy at work as well (we're migrating an old, huge PHP website to Python and a new infrastructure), but I will find time tonight to do a proper rebase and get this in.

@luismsgomes
Copy link
Contributor Author

luismsgomes commented Feb 15, 2017 via email

@mplanchard
Copy link
Contributor

@luismsgomes, could you verify that my rebased PR #169 contains the all the changes you would expect?

I pulled in master's history by running

git checkout master && git pull
git checkout luismsgomes-master
git rebase -i master

Otherwise, it is an exact copy of your changes

@ankostis ankostis merged commit 86cbda1 into pypiserver:master Feb 21, 2017
ankostis added a commit that referenced this pull request Feb 21, 2017
Fix #169 & #156: some configuration keywords were not being propagated into the app: 

authenticated, password_file, log_file, verbosity
mplanchard added a commit to mplanchard/pypiserver that referenced this pull request Nov 30, 2017
The ability to propagate configuration values from a paste config
file was introduced in pypiserver#156. However, as pointed out in pypiserver#125
by @redbaron4, the string strip method introduced in pypiserver#156 was
problematic in Python 2.

This resolves that issue while also creating a test that fails
on the current master and passes with updates, demonstrating the
issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants