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

ISO code registry #248

Merged
merged 11 commits into from Sep 29, 2017
Merged

ISO code registry #248

merged 11 commits into from Sep 29, 2017

Conversation

roxel
Copy link
Contributor

@roxel roxel commented Sep 8, 2017

I needed a feature to load calendars based on countries and regions. I implemented it based on ISO codes. Such an enhancement was mentioned in #13.

I used decorators. This provides easily understandable solution, I think. Initially I started by using metaclasses, but it caused me problems with circular imports.

setup.py Outdated
@@ -24,7 +24,7 @@ def read_relative_file(filename):
'pyCalverter',
'setuptools>=1.0',
]
version = '2.4.0.dev0'
version = '2.4.0.1'
Copy link
Contributor

@Natim Natim Sep 8, 2017

Choose a reason for hiding this comment

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

Please remove this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, right. I'll delete it.



@iso_register('AT')
Copy link
Contributor

Choose a reason for hiding this comment

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

👍



@iso_register('DE')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why uppercase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everywhere that I see ISO codes mentioned they are upper case. I thought it's a standard

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok fair enough :)

Choose a reason for hiding this comment

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

ISO standard de_DE, where DE is Germany (country) and de is German (language)

country codes always upper case, and language codes always lower case

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes but because we are speaking only of countries here, we don't need the language code.

Choose a reason for hiding this comment

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

Forgot to mention, the ISO standard (ISO-3166-1) have 3 options, ALPHA-2 (DE), ALPHA-3 (DEU), and Numerical (276), regional codes are ISO-3166-2 and 3166-3

List of ISO-3166-1 codes

Choose a reason for hiding this comment

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

Since it is valid to combine any language with any country code, and i18n is handled differently and have little to nothing with looking up in calendars, lower case language code can safely be ignored.

Though it should be possible to look up ISO codes for each calendar with all three standards (ALPHA-2, ALPHA-3, Numerical)

Copy link
Contributor Author

@roxel roxel Sep 28, 2017

Choose a reason for hiding this comment

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

I propose to use two letter codes (ALPHA-2) for countries and specific ISO-3166-2: 1 (e.g. BO-L), 2 (e.g.DE-NW) or 3 letters (e.g. GB-WOR). And I suggest to keep in documentation list of supported regions along with their iso codes.
Current implementation only requires to have codes in format XX or XX-YY ((\w)+(-\w+)?)

@Natim
Copy link
Contributor

Natim commented Sep 8, 2017

Really good, do you mind fixing the flake8 issues? Mainly unused import in the registry.

class Austria(WesternCalendar, ChristianMixin):
"Austria"
name = 'Austria'
Copy link
Contributor

@Natim Natim Sep 8, 2017

Choose a reason for hiding this comment

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

Do you mind creating a name property that return the docstring rather than changing all calendar to remove the docstring and adding a name property?

@property
def name(self):
    return self.__doc__

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 think class variable is a better place for things you want to use in your code rather than calling __doc__. Docstrings are for comments and docs. Besides, add a character and everything breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For me name is needed as I have helper class implemented in my Django app to display translated form choices and I use name attribute for translations. I could do without name, only with ISO code, but I think it's good idea to have such a variable on every Calendar instance.

@roxel
Copy link
Contributor Author

roxel commented Sep 8, 2017

@Natim

Really good, do you mind fixing the flake8 issues? Mainly unused import in the registry.

you mean: from workalendar.europe import * # nopep8 ?
you need it to be able to just do from workalendar.registry import registry. it imports all calendars and adds them to the registry

@Natim
Copy link
Contributor

Natim commented Sep 8, 2017



# right now only european countries are supported in the ISO registry
from workalendar.europe import * # nopep8
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are using flake8, I believe it should be # NoQA instead of # nopep8

@Natim
Copy link
Contributor

Natim commented Sep 8, 2017

For the line too long errors, we could probably accept longer lines.

See: https://github.com/Kinto/kinto/blob/master/tox.ini#L46-L47

There are still some unused imports: https://travis-ci.org/novafloss/workalendar/jobs/273238912#L548-L567

@roxel
Copy link
Contributor Author

roxel commented Sep 18, 2017

I fixed for the warnings about imports and line lengths.

@brunobord
Copy link
Member

brunobord commented Sep 20, 2017

For some reasons, travis refuses to install the Python 3.3 & Python 3.5 interpreter, which causes those tests to fail.
Please rebase your branch from master in order to fix these jobs.

@viciu
Copy link

viciu commented Sep 20, 2017

👍

@roxel
Copy link
Contributor Author

roxel commented Sep 25, 2017

@brunobord rebased. travis green :)

@brunobord
Copy link
Member

right. I'll merge this into master, and will try to schedule similar work on the other continents.

there will probably be a bit of work on the documentation, in order to make sure that future contributions will follow the pattern-to-be.

@brunobord brunobord merged commit 56c3b07 into workalendar:master Sep 29, 2017
@brunobord brunobord mentioned this pull request Mar 28, 2018
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

Successfully merging this pull request may close these issues.

None yet

5 participants